ShareParamValueServiceImpl.java 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. package com.imed.costaccount.service.impl;
  2. import cn.hutool.core.collection.CollUtil;
  3. import cn.hutool.core.date.DateTime;
  4. import cn.hutool.core.date.DateUtil;
  5. import cn.hutool.core.util.StrUtil;
  6. import com.alibaba.druid.util.StringUtils;
  7. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  8. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  9. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  10. import com.imed.costaccount.common.exception.CostException;
  11. import com.imed.costaccount.common.util.*;
  12. import com.imed.costaccount.constants.NumberConstant;
  13. import com.imed.costaccount.enums.DateStyleEnum;
  14. import com.imed.costaccount.mapper.ShareParamValueMapper;
  15. import com.imed.costaccount.model.*;
  16. import com.imed.costaccount.model.dto.CopyShareParamValueDTO;
  17. import com.imed.costaccount.model.dto.ShareParamValueEditDTO;
  18. import com.imed.costaccount.model.dto.ShareParamValueSaveDTO;
  19. import com.imed.costaccount.model.dto.ShareParamValueVO;
  20. import com.imed.costaccount.model.vo.IncomeErrorMessage;
  21. import com.imed.costaccount.service.*;
  22. import org.springframework.stereotype.Service;
  23. import org.springframework.transaction.annotation.Propagation;
  24. import org.springframework.transaction.annotation.Transactional;
  25. import org.springframework.util.CollectionUtils;
  26. import org.springframework.web.multipart.MultipartFile;
  27. import java.math.BigDecimal;
  28. import java.util.*;
  29. import java.util.concurrent.ConcurrentHashMap;
  30. import java.util.stream.Collectors;
  31. import static cn.hutool.core.date.DatePattern.PURE_DATE_PATTERN;
  32. @Service("shareParamValueService")
  33. public class ShareParamValueServiceImpl extends ServiceImpl<ShareParamValueMapper, ShareParamValue> implements ShareParamValueService {
  34. private final CostIncomeGroupServiceImpl costIncomeGroupService;
  35. private final CostShareParamService costShareParamService;
  36. private final CostIncomeFileService costIncomeFileService;
  37. private final ResponsibilityService responsibilityService;
  38. private final IncomeCollectionService incomeCollectionService;
  39. public ShareParamValueServiceImpl(CostIncomeGroupServiceImpl costIncomeGroupService,
  40. CostShareParamService costShareParamService,
  41. CostIncomeFileService costIncomeFileService,
  42. ResponsibilityService responsibilityService, IncomeCollectionService incomeCollectionService) {
  43. this.costIncomeGroupService = costIncomeGroupService;
  44. this.costShareParamService = costShareParamService;
  45. this.costIncomeFileService = costIncomeFileService;
  46. this.responsibilityService = responsibilityService;
  47. this.incomeCollectionService = incomeCollectionService;
  48. }
  49. /**
  50. * 添加分摊参数值
  51. *
  52. * @param shareParamValueSaveDTO {@link ShareParamValueSaveDTO}
  53. * @param hospId 医院id
  54. */
  55. @Override
  56. @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
  57. public void addData(ShareParamValueSaveDTO shareParamValueSaveDTO, Long hospId) {
  58. ShareParamValue paramValue = BeanUtil.convertObj(shareParamValueSaveDTO, ShareParamValue.class);
  59. DateTime dateTime = DateUtil.parse(shareParamValueSaveDTO.getDate(), PURE_DATE_PATTERN);
  60. // 校验是否唯一
  61. Boolean flag = checkUniq(shareParamValueSaveDTO.getShareParamCode(), shareParamValueSaveDTO.getResponsibilityCode(), hospId, dateTime);
  62. if (flag) {
  63. throw new CostException("本月已存在对应责任中心和分摊参数中心,请直接修改");
  64. }
  65. // 校验两个code是否存在
  66. checkCodeIsExist(shareParamValueSaveDTO.getShareParamCode(), shareParamValueSaveDTO.getResponsibilityCode(), hospId);
  67. paramValue.setCreateTime(System.currentTimeMillis())
  68. .setDateYear(DateUtil.year(dateTime))
  69. .setDateMonth(DateUtil.month(dateTime) + 1)
  70. .setHospId(hospId)
  71. .setDataSourceType(0);
  72. this.save(paramValue);
  73. }
  74. /**
  75. * 校验两个code是否存在
  76. *
  77. * @param shareParamCode 成本分摊参数code
  78. * @param responsibilityCode 责任中心代码
  79. * @param hospId 医院id
  80. */
  81. @Transactional(rollbackFor = Throwable.class, propagation = Propagation.REQUIRED)
  82. public void checkCodeIsExist(String shareParamCode, String responsibilityCode, Long hospId) {
  83. List<CostShareParam> shareParams = costShareParamService.list(new LambdaQueryWrapper<CostShareParam>().select(CostShareParam::getId)
  84. .eq(CostShareParam::getShareParamCode, shareParamCode).eq(CostShareParam::getHospId, hospId));
  85. if (shareParams.isEmpty()) {
  86. throw new CostException("分摊参数code非法");
  87. }
  88. List<Responsibility> responsibilities = responsibilityService.list(
  89. new LambdaQueryWrapper<Responsibility>().select(Responsibility::getId)
  90. .eq(Responsibility::getResponsibilityCode, responsibilityCode).eq(Responsibility::getHospId, hospId)
  91. );
  92. if (responsibilities.isEmpty()) {
  93. throw new CostException("责任中心code非法");
  94. }
  95. }
  96. /**
  97. * 校验是否已存在
  98. *
  99. * @param shareParamCode 分摊参数代码
  100. * @param responsibilityCode 责任中心代码
  101. * @param hospId 医院id
  102. * @param date 时间
  103. */
  104. private Boolean checkUniq(String shareParamCode, String responsibilityCode, Long hospId, DateTime date) {
  105. List<ShareParamValue> list = this.list(
  106. new LambdaQueryWrapper<ShareParamValue>()
  107. .eq(ShareParamValue::getHospId, hospId)
  108. .eq(ShareParamValue::getShareParamCode, shareParamCode)
  109. .eq(ShareParamValue::getResponsibilityCode, responsibilityCode)
  110. .eq(ShareParamValue::getDateYear, DateUtil.year(date))
  111. .eq(ShareParamValue::getDateMonth, DateUtil.month(date) + 1)
  112. );
  113. return !list.isEmpty();
  114. }
  115. /**
  116. * 分摊参数值列表
  117. *
  118. * @param current 当前页
  119. * @param pageSize 每页数据量大小
  120. * @param date 日期
  121. * @param shareParamCode 分摊参数代码
  122. * @param responsibilityCode 责任中心代码
  123. * @param hospId 医院id
  124. * @return {@link PageUtils} 分页对象
  125. */
  126. @Override
  127. public PageUtils selectList(Integer current, Integer pageSize, String date, String shareParamCode, String responsibilityCode, Long hospId) {
  128. Integer startIndex = (current - 1) * pageSize;
  129. if (startIndex < 0) {
  130. startIndex = 0;
  131. }
  132. List<ShareParamValueVO> list = baseMapper.getValues(startIndex, pageSize, date, shareParamCode, responsibilityCode, hospId);
  133. int count = baseMapper.getValuesCount(startIndex, pageSize, date, shareParamCode, responsibilityCode, hospId);
  134. return new PageUtils(list, count, pageSize, current);
  135. }
  136. /**
  137. * 复制数据从某年月到某年月
  138. *
  139. * @param copyShareParamValueDTO {@link CopyShareParamValueDTO}
  140. * @param hospId 医院id
  141. */
  142. @Override
  143. @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
  144. public void copyData(CopyShareParamValueDTO copyShareParamValueDTO, Long hospId) {
  145. // TODO 复制数据 多个医院同时使用的情况下启用线程池处理
  146. String fromDate = copyShareParamValueDTO.getFromDate();
  147. String toDate = copyShareParamValueDTO.getToDate();
  148. Integer dataSourceType = copyShareParamValueDTO.getDataSourceType();
  149. LambdaQueryWrapper<ShareParamValue> wrapper = new LambdaQueryWrapper<ShareParamValue>()
  150. .eq(ShareParamValue::getDateYear, DateUtil.year(DateUtil.parse(fromDate, PURE_DATE_PATTERN)))
  151. .eq(ShareParamValue::getDateMonth, DateUtil.month(DateUtil.parse(fromDate, PURE_DATE_PATTERN)) + 1);
  152. if (dataSourceType == 0) {
  153. wrapper.eq(ShareParamValue::getDataSourceType, 0);
  154. } else if (dataSourceType == 1) {
  155. wrapper.eq(ShareParamValue::getDataSourceType, 1);
  156. } else {
  157. wrapper.in(ShareParamValue::getDataSourceType, CollUtil.newArrayList(0, 1));
  158. }
  159. // 拿到复制的数据
  160. List<ShareParamValue> list = this.list(wrapper);
  161. if (list.isEmpty()) {
  162. throw new CostException("复制日期" + fromDate + "数据不存在");
  163. }
  164. DateTime toDateTime = DateUtil.parse(toDate, PURE_DATE_PATTERN);
  165. int year = DateUtil.year(toDateTime);
  166. int month = DateUtil.month(toDateTime) + 1;
  167. // 删除之前的数据
  168. wrapper.clear();
  169. this.remove(
  170. wrapper.eq(ShareParamValue::getDateYear, year)
  171. .eq(ShareParamValue::getDateMonth, month)
  172. .eq(ShareParamValue::getHospId, hospId)
  173. );
  174. list.forEach(i -> {
  175. i.setId(null);
  176. i.setCreateTime(System.currentTimeMillis());
  177. i.setHospId(hospId);
  178. i.setDateYear(year);
  179. i.setDateMonth(month);
  180. });
  181. this.saveBatch(list);
  182. }
  183. /**
  184. * 编辑某条数据
  185. *
  186. * @param shareParamValueEditDTO {@link ShareParamValueEditDTO}
  187. * @param hospId 医院id
  188. */
  189. @Override
  190. @Transactional(rollbackFor = Throwable.class, propagation = Propagation.REQUIRED)
  191. public void editParamValue(ShareParamValueEditDTO shareParamValueEditDTO, Long hospId) {
  192. Long id = shareParamValueEditDTO.getId();
  193. this.removeById(id);
  194. DateTime dateTime = DateUtil.parse(shareParamValueEditDTO.getDate(), PURE_DATE_PATTERN);
  195. Boolean flag = checkUniq(shareParamValueEditDTO.getShareParamCode(), shareParamValueEditDTO.getResponsibilityCode(), hospId, dateTime);
  196. if (flag) {
  197. throw new CostException("本月已存在对应责任中心和分摊参数中心,请直接修改");
  198. }
  199. checkCodeIsExist(shareParamValueEditDTO.getShareParamCode(), shareParamValueEditDTO.getResponsibilityCode(), hospId);
  200. ShareParamValue shareParamValue = BeanUtil.convertObj(shareParamValueEditDTO, ShareParamValue.class);
  201. shareParamValue
  202. .setId(null)
  203. .setCreateTime(System.currentTimeMillis())
  204. .setDateYear(DateUtil.year(DateUtil.parse(shareParamValueEditDTO.getDate(), PURE_DATE_PATTERN)))
  205. .setDateMonth(DateUtil.month(DateUtil.parse(shareParamValueEditDTO.getDate(), PURE_DATE_PATTERN)) + 1)
  206. .setHospId(hospId)
  207. .setDataSourceType(0);
  208. this.save(shareParamValue);
  209. }
  210. /**
  211. * 成本分摊参数导入
  212. *
  213. * @param list
  214. * @param user
  215. * @param file
  216. * @param dateTime
  217. * @param fileType
  218. * @return
  219. */
  220. @Override
  221. @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
  222. public Result importShareParamGroup(List<List<Object>> list, User user, MultipartFile file, String dateTime, Integer fileType) {
  223. // 先检验当前年月是否存在数据
  224. int year = 0;
  225. int month = 0;
  226. Date date = DateUtils.StringToDate(dateTime, DateStyleEnum.YYYY_MM);
  227. if (StrUtil.isNotBlank(dateTime)) {
  228. year = DateUtil.year(date);
  229. month = DateUtil.month(date) + 1;
  230. }
  231. Long hospId = user.getHospId();
  232. List<ShareParamValue> groups = this.list(new QueryWrapper<ShareParamValue>().lambda().eq(ShareParamValue::getHospId, hospId)
  233. .eq(ShareParamValue::getDateYear, year).eq(ShareParamValue::getDateMonth, month));
  234. if (!CollectionUtils.isEmpty(groups)) {
  235. throw new CostException(500, year + "年" + month + "月数据已存在");
  236. }
  237. for (int i = list.size() - 1; i >= 0; i--) {
  238. if (i == NumberConstant.ZERO || i == NumberConstant.ONE || i == NumberConstant.TWO || i == NumberConstant.THREE) {
  239. list.remove(list.get(i));
  240. }
  241. }
  242. List<IncomeErrorMessage> incomeErrorMessageList = new ArrayList<>();
  243. Map<String, Department> departmentMap = costIncomeGroupService.getDepartmentByCodeNameMap(hospId);
  244. Map<Long, Responsibility> responsibilityMap = costIncomeGroupService.getResponsibilityIdResponsibilityMap(hospId);
  245. List<ResponsibilityDepartment> responsibilityDepartmentList = costIncomeGroupService.getResponsibilityDepartments(hospId);
  246. if (CollectionUtils.isEmpty(responsibilityDepartmentList)) {
  247. throw new CostException(500, "没有科室责任中心对照数据");
  248. }
  249. Map<Long, Long> responsibilityDepMap = costIncomeGroupService.getDepartmentIdResponsibilityIdMap(responsibilityDepartmentList);
  250. Map<String, CostShareParam> shareParamMap = costShareParamService.list(new QueryWrapper<CostShareParam>().lambda().eq(CostShareParam::getHospId, hospId)).stream().collect(Collectors.toMap(k -> k.getShareParamCode() + k.getShareParamName(), synOe -> synOe));
  251. // 要保存的数据
  252. List<ShareParamValue> shareParamValues = new LinkedList<>();
  253. // List<CostShareParamGroup> costShareParamGroupList = new LinkedList<>();
  254. List<Object> departmentCodes = list.get(0);
  255. List<Object> departmentNames = list.get(1);
  256. //检验数据是否准确 list包含了科室Code行与Name行 所以要从list的第三行开始
  257. checkShareParamGroupData(list, year, month, incomeErrorMessageList, departmentMap, responsibilityMap, responsibilityDepMap, shareParamMap, shareParamValues, departmentCodes, departmentNames);
  258. // 文件上传
  259. String uploadFile = costIncomeGroupService.uploadFile(file, UserContext.getCurrentUser());
  260. // 上传记录保存
  261. if (StrUtil.isBlank(uploadFile)) {
  262. throw new CostException(500, "文件上传异常");
  263. }
  264. // 记录文件上传记录
  265. CostIncomeFile costIncomeFile = costIncomeFileService.saveCostIncomeFile(list, user, file, hospId, incomeErrorMessageList, uploadFile, fileType, year, month);
  266. Long id = costIncomeFile.getId();
  267. shareParamValues.forEach(i -> {
  268. // 设置文件Id
  269. i.setFileId(id);
  270. i.setDataSourceType(1);
  271. });
  272. // 保存数据的唯一性
  273. Map<String, List<ShareParamValue>> map = shareParamValues.stream().collect(Collectors.groupingBy(k -> k.getShareParamCode().trim() + "code" + k.getResponsibilityCode().trim() + k.getDateYear().toString().trim() + "code" + k.getDateMonth().toString().trim()
  274. ));
  275. LinkedList<ShareParamValue> realList = new LinkedList<>();
  276. Set<String> strings = map.keySet();
  277. for (String str : strings) {
  278. List<ShareParamValue> shareParamValuesList = map.get(str);
  279. if (CollUtil.isNotEmpty(shareParamValuesList)) {
  280. BigDecimal reduce = shareParamValuesList.stream().map(ShareParamValue::getValueNum).reduce(BigDecimal.ZERO, BigDecimal::add);
  281. ShareParamValue shareParamValue = shareParamValuesList.get(0);
  282. shareParamValue.setValueNum(reduce);
  283. realList.add(shareParamValue);
  284. }
  285. }
  286. if (CollectionUtils.isEmpty(incomeErrorMessageList)) {
  287. this.saveBatch(realList);
  288. return Result.build(200, "数据导入成功", null);
  289. } else {
  290. return Result.build(200, "数据未成功导入", null);
  291. }
  292. }
  293. private void checkShareParamGroupData(List<List<Object>> list, int year, int month,
  294. List<IncomeErrorMessage> incomeErrorMessageList, Map<String, Department> departmentMap,
  295. Map<Long, Responsibility> responsibilityMap, Map<Long, Long> responsibilityDepMap,
  296. Map<String, CostShareParam> shareParamMap, List<ShareParamValue> shareParamValues,
  297. List<Object> departmentCodes, List<Object> departmentNames) {
  298. for (int i = 2; i < list.size(); i++) {
  299. int row = i + 4;
  300. List<Object> data = list.get(i);
  301. // 检验成本分摊参数是否正确
  302. ShareParamValue shareParamValueRequest = new ShareParamValue();
  303. String shareParamCode = data.get(0).toString().trim();
  304. String shareParamName = data.get(1).toString().trim();
  305. CostShareParam costShareParam = shareParamMap.get(shareParamCode + shareParamName);
  306. if (Objects.nonNull(costShareParam)) {
  307. shareParamValueRequest.setShareParamCode(shareParamCode);
  308. } else {
  309. IncomeErrorMessage incomeErrorMessage = new IncomeErrorMessage();
  310. incomeErrorMessage.setTotal(i);
  311. incomeErrorMessage.setErrMessage("成本分摊代码:" + shareParamCode + " 名称" + shareParamName + "不存在");
  312. incomeErrorMessageList.add(incomeErrorMessage);
  313. }
  314. for (int j = 2; j < departmentCodes.size(); j++) {
  315. int column = j + 1;
  316. if (data.size() > j) {
  317. if (Objects.isNull(data.get(j))) {
  318. data.set(j, NumberConstant.ZERO);
  319. } else if (data.get(j).toString().contains("-") || !StringUtils.isNumber(data.get(j).toString())) {
  320. IncomeErrorMessage incomeErrorMessage = new IncomeErrorMessage();
  321. incomeErrorMessage.setTotal(row);
  322. incomeErrorMessage.setErrMessage("第" + row + "行 第" + column + "列数据不符合规范");
  323. incomeErrorMessageList.add(incomeErrorMessage);
  324. } else {
  325. data.set(j, Double.parseDouble(data.get(j).toString()));
  326. }
  327. } else {
  328. data.add(NumberConstant.ZERO);
  329. }
  330. }
  331. if (CollectionUtils.isEmpty(incomeErrorMessageList)) {
  332. incomeErrorMessageList = new ArrayList<>();
  333. // 检验数据是否全为0
  334. int zeroStatus = 0;
  335. for (int j = 2; j < data.size(); j++) {
  336. if (!NumberConstant.ZERO.equals(data.get(j))) {
  337. zeroStatus = 1;
  338. break;
  339. }
  340. }
  341. if (NumberConstant.ONE.equals(zeroStatus)) {
  342. for (int j = 2; j < data.size(); j++) {
  343. ShareParamValue shareParamValue = BeanUtil.convertObj(shareParamValueRequest, ShareParamValue.class);
  344. // 检验科室信息是否准确
  345. String departmentCode = departmentCodes.get(j).toString();
  346. String departmentName = departmentNames.get(j).toString();
  347. Department department = departmentMap.get(departmentCode + departmentName);
  348. if (Objects.nonNull(department)) {
  349. // 检测责任中心是否存在
  350. Long id = department.getId();
  351. Long responsibilityId = responsibilityDepMap.get(id);
  352. if (Objects.nonNull(responsibilityId)) {
  353. Responsibility responsibility = responsibilityMap.get(responsibilityId);
  354. if (Objects.nonNull(responsibility)) {
  355. shareParamValue.setResponsibilityCode(responsibility.getResponsibilityCode());
  356. } else {
  357. IncomeErrorMessage incomeErrorMessage = new IncomeErrorMessage();
  358. incomeErrorMessage.setTotal(j);
  359. incomeErrorMessage.setErrMessage("第" + j + "列科室信息对应的责任中心不存在");
  360. incomeErrorMessageList.add(incomeErrorMessage);
  361. }
  362. } else {
  363. IncomeErrorMessage incomeErrorMessage = new IncomeErrorMessage();
  364. incomeErrorMessage.setTotal(j);
  365. incomeErrorMessage.setErrMessage("第" + j + "列科室信息不存在对应的责任中心");
  366. incomeErrorMessageList.add(incomeErrorMessage);
  367. }
  368. } else {
  369. IncomeErrorMessage incomeErrorMessage = new IncomeErrorMessage();
  370. incomeErrorMessage.setTotal(j);
  371. incomeErrorMessage.setErrMessage("第" + j + "列科室信息不存在");
  372. incomeErrorMessageList.add(incomeErrorMessage);
  373. }
  374. shareParamValue.setValueNum(BigDecimal.valueOf(Double.parseDouble(("0".equals(data.get(j).toString()) || StrUtil.isBlank(data.get(j).toString())) ? "0.00" : data.get(j).toString())));
  375. shareParamValue.setHospId(UserContext.getHospId());
  376. shareParamValue.setCreateTime(System.currentTimeMillis());
  377. shareParamValue.setDateYear(year);
  378. shareParamValue.setDateMonth(month);
  379. shareParamValues.add(shareParamValue);
  380. }
  381. }
  382. }
  383. }
  384. }
  385. /**
  386. * 计算数值
  387. *
  388. * @param date 日期 yyyyMM
  389. * @param hospId 医院id
  390. */
  391. @Override
  392. @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
  393. public void calcData(String date, Long hospId) {
  394. DateTime parse = DateUtil.parse(date, PURE_DATE_PATTERN);
  395. int year = DateUtil.year(parse);
  396. int month = DateUtil.month(parse) + 1;
  397. // 拿到这些年月的数据
  398. List<ShareParamValue> list = this.list(
  399. new LambdaQueryWrapper<ShareParamValue>()
  400. .eq(ShareParamValue::getDateYear, year).eq(ShareParamValue::getDateMonth, month).eq(ShareParamValue::getHospId, hospId)
  401. );
  402. if (list.isEmpty()){
  403. throw new CostException(500,parse+"数据未录入");
  404. }
  405. // 得到这些责任中心代码
  406. List<String> responsibilityCodes = list.stream().map(ShareParamValue::getResponsibilityCode).distinct().collect(Collectors.toList());
  407. List<IncomeCollection> incomeCollections = incomeCollectionService.list(
  408. new LambdaQueryWrapper<IncomeCollection>()
  409. .eq(IncomeCollection::getYear, year)
  410. .eq(IncomeCollection::getMonth, month)
  411. .eq(IncomeCollection::getHospId, hospId)
  412. .in(IncomeCollection::getResponsibilityCode, responsibilityCodes)
  413. );
  414. if (incomeCollections.isEmpty()) {
  415. throw new CostException("本月未归集数据,请先归集数据");
  416. }
  417. Map<String, List<IncomeCollection>> collectMap = incomeCollections.stream().collect(Collectors.groupingBy(IncomeCollection::getResponsibilityCode));
  418. Set<String> strings = collectMap.keySet();
  419. Map<String,BigDecimal> map = new ConcurrentHashMap<>();
  420. for (String str : strings) {
  421. List<IncomeCollection> collections = collectMap.get(str);
  422. if (CollUtil.isNotEmpty(collections)) {
  423. BigDecimal reduce = incomeCollections.stream().map(IncomeCollection::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
  424. IncomeCollection incomeCollection = incomeCollections.get(0);
  425. incomeCollection.setAmount(reduce);
  426. map.put(str, reduce);
  427. }
  428. }
  429. list.forEach(i -> {
  430. // TODO: 2021/8/19
  431. BigDecimal bigDecimal = map.get(i.getResponsibilityCode());
  432. if (Objects.nonNull(bigDecimal)) {
  433. i.setValueNum(bigDecimal);
  434. }
  435. });
  436. this.updateBatchById(list);
  437. }
  438. }