CostCostingGroupServiceImpl.java 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. package com.kcim.service.impl;
  2. import cn.hutool.core.date.DateTime;
  3. import cn.hutool.core.date.DateUtil;
  4. import cn.hutool.core.util.StrUtil;
  5. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  6. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  7. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  8. import com.kcim.common.constants.NumberConstant;
  9. import com.kcim.common.enums.DateStyleEnum;
  10. import com.kcim.common.exception.CostException;
  11. import com.kcim.common.util.*;
  12. import com.kcim.dao.mapper.AllocationMapper;
  13. import com.kcim.dao.mapper.AllocationQueryMapper;
  14. import com.kcim.dao.mapper.CostCostingGroupMapper;
  15. import com.kcim.dao.model.*;
  16. import com.kcim.service.*;
  17. import com.kcim.vo.AllocationVO;
  18. import com.kcim.vo.CommonDepartVo;
  19. import com.kcim.vo.CostingGroupStartVO;
  20. import com.kcim.vo.IncomeErrorMessage;
  21. import lombok.extern.slf4j.Slf4j;
  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.util.ObjectUtils;
  27. import org.springframework.web.multipart.MultipartFile;
  28. import java.math.BigDecimal;
  29. import java.util.*;
  30. import java.util.concurrent.ExecutorService;
  31. import java.util.concurrent.Executors;
  32. import java.util.stream.Collectors;
  33. @Service("costCostingGroupService")
  34. @Slf4j
  35. public class CostCostingGroupServiceImpl extends ServiceImpl<CostCostingGroupMapper, CostCostingGroup> implements CostCostingGroupService {
  36. private final CostIncomeGroupServiceImpl costIncomeGroupService;
  37. private final AccountingService accountingService;
  38. private final AccountingProductService accountingProductService;
  39. private final CostIncomeFileService costIncomeFileService;
  40. private final ResponsibilityService responsibilityService;
  41. private final AllocationMapper allocationMapper;
  42. private final AllocationQueryMapper allocationQueryMapper;
  43. public CostCostingGroupServiceImpl(CostIncomeGroupServiceImpl costIncomeGroupService,
  44. AccountingService accountingService,
  45. AccountingProductService accountingProductService,
  46. CostIncomeFileService costIncomeFileService,
  47. ResponsibilityService responsibilityService, AllocationMapper allocationMapper, AllocationQueryMapper allocationQueryMapper) {
  48. this.costIncomeGroupService = costIncomeGroupService;
  49. this.accountingService = accountingService;
  50. this.accountingProductService = accountingProductService;
  51. this.costIncomeFileService = costIncomeFileService;
  52. this.responsibilityService = responsibilityService;
  53. this.allocationMapper = allocationMapper;
  54. this.allocationQueryMapper = allocationQueryMapper;
  55. }
  56. /**
  57. * 分摊前查询
  58. *
  59. * @param current 当前页
  60. * @param pageSize 每页数据大小
  61. * @param responsibilityCode 责任中心代码
  62. * @param accountCode 会计中心代码
  63. * @param date 日期 yyyy-MM
  64. * @param hospId 医院id
  65. * @param departmentCode
  66. * @param filter
  67. * @return 分摊前查询列表
  68. */
  69. @Override
  70. public PageUtils queryStartAllocation(Integer current, Integer pageSize, String responsibilityCode, String accountCode, String date, Long hospId, String departmentCode, String filter) {
  71. Integer startIndex = (current - 1) * pageSize;
  72. int year = 0;
  73. int month = 0;
  74. if (StrUtil.isNotBlank(date)) {
  75. Date dateTime = DateUtils.StringToDate(date, DateStyleEnum.YYYY_MM);
  76. year = DateUtil.year(dateTime);
  77. month = DateUtil.month(dateTime) + 1;
  78. }
  79. // DateTime dateTime = DateUtil.parseDate(date);
  80. //
  81. // Integer year = DateUtil.year(dateTime);
  82. // Integer month = DateUtil.month(dateTime) + 1;
  83. List<CostingGroupStartVO> list = baseMapper.queryStartAllocation(startIndex, pageSize, responsibilityCode, accountCode, year, month, hospId, departmentCode, filter);
  84. int count = baseMapper.queryStartAllocationCount(responsibilityCode, accountCode, year, month, hospId, departmentCode, filter);
  85. BigDecimal totalAmount = baseMapper.queryStartAllocationTotalAmount(responsibilityCode, accountCode, year, month, hospId);
  86. BigDecimal departmentAmount = baseMapper.queryStartAllocationDepartmentAmount(responsibilityCode, accountCode, year, month, hospId, departmentCode, filter);
  87. return new PageUtils(list, count, pageSize, current, totalAmount, departmentAmount);
  88. }
  89. /**
  90. * 成本分摊列表
  91. *
  92. * @param current 当前页
  93. * @param pageSize 每页数据大小
  94. * @param date 日期 这里是 yyyy-MM-dd
  95. * @param hospId
  96. * @return 分页对象
  97. */
  98. @Override
  99. public PageUtils queryAllocation(Integer current, Integer pageSize, String date, Long hospId) {
  100. Integer year = null;
  101. Integer month = null;
  102. if (StrUtil.isNotBlank(date)) {
  103. DateTime dateTime = DateUtil.parseDate(date);
  104. year = DateUtil.year(dateTime);
  105. month = DateUtil.month(dateTime) + 1;
  106. }
  107. Integer startIndex = (current - 1) * pageSize;
  108. List<AllocationVO> list = baseMapper.queryAllocation(startIndex, pageSize, year, month, hospId);
  109. list.forEach(i -> {
  110. Allocation allocation = allocationMapper.selectOne(new LambdaQueryWrapper<Allocation>().eq(Allocation::getDateYear, i.getYear())
  111. .eq(Allocation::getDateMonth, i.getMonth())
  112. .eq(Allocation::getHospId, hospId)
  113. .last("LIMIT 1")
  114. );
  115. if (!ObjectUtils.isEmpty(allocation)) {
  116. i.setIsAllocation(true);
  117. }
  118. });
  119. int count = baseMapper.queryAllocationCount(year, month, hospId);
  120. return new PageUtils(list, count, pageSize, current);
  121. }
  122. /**
  123. * 通过code获取名称
  124. *
  125. * @param accountCode
  126. * @return
  127. */
  128. private Accounting getAccountByCode(String accountCode, Long hospId) {
  129. Accounting byCode = accountingService.getByCode(accountCode, hospId);
  130. if (Objects.isNull(byCode)) {
  131. throw new CostException("会计科目不存在");
  132. }
  133. return byCode;
  134. }
  135. /**
  136. * 是否固定成本
  137. *
  138. * @param hospId 医院id
  139. * @param i {@link CostCostingGroup}
  140. * @return 是否固定成本 0.不是,1.是(支出的时候才会存在)
  141. */
  142. private Integer getIsBaseCost(Long hospId, CostCostingGroup i) {
  143. String accountCode = i.getAccountCode();
  144. Accounting accounting = accountingService.getByCode(accountCode, hospId);
  145. if (Objects.isNull(accountCode)) {
  146. return null;
  147. }
  148. // 是否固定成本 0.不是,1.是(支出的时候才会存在) (成本数据)
  149. return accounting.getIsBaseCost();
  150. }
  151. /**
  152. * 批量导入成本数据
  153. *
  154. * @param list
  155. * @param file
  156. * @param dateTime
  157. * @param fileType
  158. * @return
  159. */
  160. @Override
  161. @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
  162. public Result importCostingGroup(List<List<Object>> list, MultipartFile file, String dateTime, Integer fileType) {
  163. // 先检验当前年月是否存在数据
  164. int year = 0;
  165. int month = 0;
  166. if (StrUtil.isNotBlank(dateTime)) {
  167. Date date = DateUtils.StringToDate(dateTime, DateStyleEnum.YYYY_MM);
  168. year = DateUtil.year(date);
  169. month = DateUtil.month(date) + 1;
  170. }
  171. Long hospId = UserContext.getCurrentLoginHospId();
  172. // List<CostCostingGroup> groups = this.list(new QueryWrapper<CostCostingGroup>().lambda().eq(CostCostingGroup::getHospId, hospId)
  173. // .eq(CostCostingGroup::getDateYear, year).eq(CostCostingGroup::getDateMonth, month));
  174. // if (!CollectionUtils.isEmpty(groups)) {
  175. // throw new CostException(500, year + "年" + month + "月数据已存在");
  176. // }
  177. // for (int i = list.size() - 1; i >= 0; i--) {
  178. // if (i == NumberConstant.ZERO || i == NumberConstant.ONE || i == NumberConstant.TWO || i == NumberConstant.THREE) {
  179. // }
  180. // }
  181. list.remove(list.get(0));
  182. List<IncomeErrorMessage> incomeErrorMessageList = new ArrayList<>();
  183. //获取所有的科室 成本项目 责任中心 会计科目
  184. Map<String, Department> departmentMap = costIncomeGroupService.getDepartmentByCodeNameMap(hospId);
  185. Map<String, Product> productMap = costIncomeGroupService.getProductByCodeNameMap(hospId);
  186. Map<Long, Responsibility> responsibilityMap = costIncomeGroupService.getResponsibilityIdResponsibilityMap(hospId);
  187. Map<Long, Accounting> accountingMap = costIncomeGroupService.getAccountIdAccountingMap(hospId);
  188. List<ResponsibilityDepartment> responsibilityDepartmentList = costIncomeGroupService.getResponsibilityDepartments(hospId);
  189. if (CollectionUtils.isEmpty(responsibilityDepartmentList)) {
  190. throw new CostException(500, "没有科室责任中心对照数据");
  191. }
  192. List<AccountingProduct> accountingProductList = accountingProductService.list(new QueryWrapper<AccountingProduct>().lambda().eq(AccountingProduct::getHospId, hospId));
  193. if (CollectionUtils.isEmpty(accountingProductList)) {
  194. throw new CostException(500, "没有成本会计对照数据");
  195. }
  196. Map<Long, Long> responsibilityDepMap = costIncomeGroupService.getDepartmentIdResponsibilityIdMap(responsibilityDepartmentList);
  197. Map<Long, Long> accountProMap = costIncomeGroupService.getProductIdAccountIdMap(accountingProductList);
  198. String endStatus = list.get(0).get(list.get(0).size() - 1).toString();
  199. // 判断最后科室代码的最后一个字符是否是-1
  200. if (!"-1".equals(endStatus)) {
  201. // 如果没有-1说明终结符
  202. IncomeErrorMessage incomeErrorMessage = new IncomeErrorMessage();
  203. incomeErrorMessage.setTotal(5);
  204. incomeErrorMessage.setErrMessage("科室代码末尾没有-1终结符");
  205. incomeErrorMessageList.add(incomeErrorMessage);
  206. // 文件上传
  207. String uploadFile = costIncomeGroupService.uploadFile(file);
  208. // 上传记录保存
  209. if (StrUtil.isBlank(uploadFile)) {
  210. throw new CostException(500, "文件上传异常");
  211. }
  212. // 记录文件上传记录
  213. CostIncomeFile costIncomeFile = costIncomeFileService.saveCostIncomeFile(list, file, hospId, incomeErrorMessageList, uploadFile, fileType, year, month);
  214. return Result.build(500, "数据未成功导入", null);
  215. }
  216. // 检验数据的合理性
  217. // 检验成本数据
  218. // 要保存的数据
  219. costCostingGroupArrayList = new ArrayList<>();
  220. checkCostData(list, incomeErrorMessageList, departmentMap, productMap, responsibilityMap, accountingMap, responsibilityDepMap, accountProMap, year, month);
  221. // 文件上传
  222. String uploadFile = costIncomeGroupService.uploadFile(file);
  223. // 上传记录保存
  224. if (StrUtil.isBlank(uploadFile)) {
  225. throw new CostException(500, "文件上传异常");
  226. }
  227. // 记录文件上传记录
  228. CostIncomeFile costIncomeFile = costIncomeFileService.saveCostIncomeFile(list, file, hospId, incomeErrorMessageList, uploadFile, fileType, year, month);
  229. Long id = costIncomeFile.getId();
  230. // 设置文件Id
  231. List<CostCostingGroup> removeList = new ArrayList<>();
  232. for (CostCostingGroup i : costCostingGroupArrayList) {
  233. if (Objects.nonNull(i)) {
  234. i.setFileId(id);
  235. } else {
  236. removeList.add(null);
  237. }
  238. }
  239. if (!CollectionUtils.isEmpty(removeList)) {
  240. costCostingGroupArrayList.removeAll(removeList);
  241. }
  242. if (CollectionUtils.isEmpty(incomeErrorMessageList)) {
  243. this.saveBatch(costCostingGroupArrayList);
  244. return Result.build(200, "数据导入成功", null);
  245. } else {
  246. return Result.build(200, "数据未成功导入", null);
  247. }
  248. }
  249. /**
  250. * 检验成本数据
  251. *
  252. * @param list
  253. * @param incomeErrorMessageList
  254. * @param departmentMap
  255. * @param productMap
  256. * @param responsibilityMap
  257. * @param accountingMap
  258. * @param responsibilityDepMap
  259. * @param accountProMap
  260. */
  261. private void checkCostData(List<List<Object>> list, List<IncomeErrorMessage> incomeErrorMessageList, Map<String, Department> departmentMap, Map<String, Product> productMap, Map<Long, Responsibility> responsibilityMap, Map<Long, Accounting> accountingMap, Map<Long, Long> responsibilityDepMap, Map<Long, Long> accountProMap, Integer year, Integer month) {
  262. // Pattern pattern = Pattern.compile("^\\d+(\\.\\d+)?$");
  263. List<Object> departmentCodes = list.get(0);
  264. List<Object> departmentNames = list.get(1);
  265. //检验数据是否准确
  266. Responsibility responsibilityServiceOne = responsibilityService.getOne(new QueryWrapper<Responsibility>().lambda().eq(Responsibility::getHospId, UserContext.getHospId()).eq(Responsibility::getIsDefault, NumberConstant.ONE));
  267. ExecutorService pool = Executors.newFixedThreadPool(10);
  268. for (int i = 2; i < list.size(); i++) {
  269. System.out.println("计算进度:" + i + "/" + list.size());
  270. // int row = i + 5;
  271. List<Object> data = list.get(i);
  272. if (CollectionUtils.isEmpty(incomeErrorMessageList)) {
  273. int emptyStatus = 0;
  274. //判断数据 是否全为0
  275. for (int j = 2; j < data.size() - 1; j++) {
  276. BigDecimal parseInt = new BigDecimal(data.get(j).toString());
  277. if (!BigDecimal.ZERO.equals(parseInt)) {
  278. emptyStatus = 1;
  279. break;
  280. }
  281. }
  282. //转换数据格式并将未维护的数据填充 0
  283. for (int j = 2; j < departmentCodes.size(); j++) {
  284. //转换数据格式
  285. if (data.size() > j) {
  286. if (Objects.isNull(data.get(j))) {
  287. data.set(j, NumberConstant.ZERO);
  288. } else {
  289. data.set(j, Double.parseDouble(data.get(j).toString()));
  290. }
  291. } else {
  292. data.add(NumberConstant.ZERO);
  293. }
  294. }
  295. // 检验成本项目是否正确
  296. CostCostingGroup costCostingGroupRequest = new CostCostingGroup();
  297. if (Objects.nonNull(data.get(0)) && Objects.nonNull(data.get(1))) {
  298. String productCode = data.get(0).toString();
  299. String productName = data.get(1).toString();
  300. Product product = productMap.get(productCode + productName);
  301. AfterCostGroup afterCostGroupRequest = new AfterCostGroup();
  302. if (Objects.nonNull(product)) {
  303. Long id = product.getId();
  304. Long accountTingId = accountProMap.get(id);
  305. if (Objects.nonNull(accountTingId)) {
  306. Accounting accounting = accountingMap.get(accountTingId);
  307. if (Objects.nonNull(accounting)) {
  308. costCostingGroupRequest.setProductCode(productCode);
  309. costCostingGroupRequest.setProductName(productName);
  310. costCostingGroupRequest.setAccountCode(accounting.getAccountingCode());
  311. costCostingGroupRequest.setAccountName(accounting.getAccountingName());
  312. afterCostGroupRequest.setProductCode(productCode);
  313. afterCostGroupRequest.setProductName(productName);
  314. afterCostGroupRequest.setAccountCode(accounting.getAccountingCode());
  315. afterCostGroupRequest.setAccountName(accounting.getAccountingName());
  316. } else {
  317. IncomeErrorMessage incomeErrorMessage = new IncomeErrorMessage();
  318. incomeErrorMessage.setTotal(1);
  319. incomeErrorMessage.setErrMessage("成本代码" + productCode + " 成本名称" + productName + " 不存在对应的会计科目不存在");
  320. if (incomeErrorMessageList != null) {
  321. incomeErrorMessageList.add(incomeErrorMessage);
  322. }
  323. }
  324. } else {
  325. IncomeErrorMessage incomeErrorMessage = new IncomeErrorMessage();
  326. incomeErrorMessage.setTotal(1);
  327. incomeErrorMessage.setErrMessage("成本代码" + productCode + " 成本名称" + productName + " 不存在对应的会计科目不存在");
  328. if (incomeErrorMessageList != null) {
  329. incomeErrorMessageList.add(incomeErrorMessage);
  330. }
  331. }
  332. } else {
  333. IncomeErrorMessage incomeErrorMessage = new IncomeErrorMessage();
  334. incomeErrorMessage.setTotal(1);
  335. incomeErrorMessage.setErrMessage("成本代码" + productCode + " 成本名称" + productName + "不存在");
  336. if (incomeErrorMessageList != null) {
  337. incomeErrorMessageList.add(incomeErrorMessage);
  338. }
  339. }
  340. // 0表示全为0 1表示不全为0 查看合计项
  341. BigDecimal combined = new BigDecimal(data.get(data.size() - 1).toString());
  342. if (!BigDecimal.ZERO.equals(combined) && NumberConstant.ZERO.equals(emptyStatus)) {
  343. // 这条数据是保存到其他责任中心的
  344. CostCostingGroup costCostingGroup = BeanUtil.convertObj(afterCostGroupRequest, CostCostingGroup.class);
  345. // AfterCostGroup afterCostGroup = BeanUtil.convertObj(afterCostGroupRequest, AfterCostGroup.class);
  346. // TODO 设置其他责任中心
  347. if (Objects.nonNull(responsibilityServiceOne)) {
  348. costCostingGroup.setResponsibilityCode(responsibilityServiceOne.getResponsibilityCode());
  349. costCostingGroup.setResponsibilityName(responsibilityServiceOne.getResponsibilityName());
  350. // 设置统计数据
  351. // afterCostGroup.setOtherResponsibilityCode(responsibilityServiceOne.getResponsibilityCode());
  352. // afterCostGroup.setOtherResponsibilityName(responsibilityServiceOne.getResponsibilityName());
  353. } else {
  354. IncomeErrorMessage incomeErrorMessage = new IncomeErrorMessage();
  355. incomeErrorMessage.setTotal(i);
  356. incomeErrorMessage.setErrMessage("不存在默认责任中心");
  357. if (incomeErrorMessageList != null) {
  358. incomeErrorMessageList.add(incomeErrorMessage);
  359. }
  360. }
  361. costCostingGroup.setProductCode(costCostingGroupRequest.getProductCode());
  362. costCostingGroup.setProductName(costCostingGroupRequest.getProductName());
  363. costCostingGroup.setAccountCode(costCostingGroupRequest.getAccountCode());
  364. costCostingGroup.setAccountName(costCostingGroupRequest.getAccountName());
  365. costCostingGroup.setAmount(combined);
  366. costCostingGroup.setHospId(UserContext.getHospId());
  367. costCostingGroup.setCreateTime(System.currentTimeMillis());
  368. costCostingGroup.setDateYear(year);
  369. costCostingGroup.setDateMonth(month);
  370. // afterCostGroup.setAmount(combined);
  371. // String s = -JsonUtil.toJSONString(afterCostGroup);
  372. String s = JacksonUtil.obj2Str(combined);
  373. costCostingGroup.setAfterCostGroup(s);
  374. increment(costCostingGroup);
  375. // costCostingGroupArrayList.add(costCostingGroup);
  376. } else {
  377. for (int j = 2; j < data.size() - 1; j++) {
  378. int finalJ = j;
  379. pool.execute(new Runnable() {
  380. @Override
  381. public void run() {
  382. AfterCostGroup afterCostGroup = BeanUtil.convertObj(afterCostGroupRequest, AfterCostGroup.class);
  383. CostCostingGroup costCostingGroup = BeanUtil.convertObj(costCostingGroupRequest, CostCostingGroup.class);
  384. // 检验科室信息是否准确
  385. String departmentCode = departmentCodes.get(finalJ).toString();
  386. String departmentName = departmentNames.get(finalJ).toString();
  387. Department department = departmentMap.get(departmentCode + departmentName);
  388. if (Objects.nonNull(department)) {
  389. // 检测责任中心是否存在
  390. Long id = department.getId();
  391. Long responsibilityId = responsibilityDepMap.get(id);
  392. if (Objects.nonNull(responsibilityId)) {
  393. Responsibility responsibility = responsibilityMap.get(responsibilityId);
  394. if (Objects.nonNull(responsibility)) {
  395. costCostingGroup.setDepartmentCode(departmentCode);
  396. costCostingGroup.setDepartmentName(departmentName);
  397. costCostingGroup.setResponsibilityCode(responsibility.getResponsibilityCode());
  398. costCostingGroup.setResponsibilityName(responsibility.getResponsibilityName());
  399. // afterCostGroup.setResponsibilityCode(responsibility.getResponsibilityCode());
  400. // afterCostGroup.setResponsibilityName(responsibility.getResponsibilityName());
  401. // afterCostGroup.setDepartmentCode(departmentCode);
  402. // afterCostGroup.setDepartmentName(departmentName);
  403. } else {
  404. IncomeErrorMessage incomeErrorMessage = new IncomeErrorMessage();
  405. incomeErrorMessage.setTotal(finalJ);
  406. incomeErrorMessage.setErrMessage("第" + finalJ + "列科室信息对应的责任中心不存在");
  407. if (incomeErrorMessageList != null) {
  408. incomeErrorMessageList.add(incomeErrorMessage);
  409. }
  410. }
  411. } else {
  412. IncomeErrorMessage incomeErrorMessage = new IncomeErrorMessage();
  413. incomeErrorMessage.setTotal(finalJ);
  414. incomeErrorMessage.setErrMessage("第" + finalJ + "列科室信息不存在对应的责任中心");
  415. if (incomeErrorMessageList != null) {
  416. incomeErrorMessageList.add(incomeErrorMessage);
  417. }
  418. }
  419. } else {
  420. IncomeErrorMessage incomeErrorMessage = new IncomeErrorMessage();
  421. incomeErrorMessage.setTotal(finalJ);
  422. incomeErrorMessage.setErrMessage("第" + finalJ + "列科室信息不存在");
  423. if (incomeErrorMessageList != null) {
  424. incomeErrorMessageList.add(incomeErrorMessage);
  425. }
  426. }
  427. costCostingGroup.setAmount(new BigDecimal((Objects.isNull(data.get(finalJ)) || "0".equals(data.get(finalJ).toString())) ? "0.00" : data.get(finalJ).toString()));
  428. costCostingGroup.setHospId(UserContext.getHospId());
  429. costCostingGroup.setCreateTime(System.currentTimeMillis());
  430. costCostingGroup.setDateYear(year);
  431. costCostingGroup.setDateMonth(month);
  432. afterCostGroup.setAmount(new BigDecimal((Objects.isNull(data.get(finalJ)) || "0".equals(data.get(finalJ).toString())) ? "0.00" : data.get(finalJ).toString()));
  433. // String s = JsonUtil.toJSONString(afterCostGroup);
  434. // String s = JacksonUtil.obj2Str(afterCostGroup);
  435. // costCostingGroup.setAfterCostGroup(s);
  436. increment(costCostingGroup);
  437. // costCostingGroupArrayList.add(costCostingGroup);
  438. }
  439. });
  440. // Runnable runnable = () -> {
  441. // };
  442. // pool.execute(runnable);
  443. }
  444. }
  445. }
  446. }
  447. }
  448. pool.shutdown();
  449. while (true) {
  450. if (pool.isTerminated()) {
  451. break;
  452. }
  453. }
  454. }
  455. static List<CostCostingGroup> costCostingGroupArrayList = new ArrayList<>();
  456. public static synchronized void increment(CostCostingGroup group) {
  457. costCostingGroupArrayList.add(group);
  458. }
  459. /**
  460. * 得到这个月的所有导入的成本数据
  461. *
  462. * @param year 年
  463. * @param month 月
  464. * @param hospId 医院id
  465. * @return List
  466. */
  467. @Override
  468. public List<CostCostingGroup> getByYearAndDate(Integer year, Integer month, Long hospId) {
  469. return this.list(
  470. new LambdaQueryWrapper<CostCostingGroup>()
  471. .eq(CostCostingGroup::getDateYear, year)
  472. .eq(CostCostingGroup::getDateMonth, month)
  473. .eq(CostCostingGroup::getHospId, hospId)
  474. );
  475. }
  476. /**
  477. * 撤销分摊
  478. *
  479. * @param year
  480. * @param month
  481. * @param hospId
  482. */
  483. @Override
  484. @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
  485. public void cancelAllocation(Integer year, Integer month, Long hospId) {
  486. allocationMapper.delete(
  487. new LambdaQueryWrapper<Allocation>()
  488. .eq(Allocation::getDateYear, year)
  489. .eq(Allocation::getDateMonth, month)
  490. .eq(Allocation::getHospId, hospId)
  491. );
  492. allocationQueryMapper.delete(
  493. new LambdaQueryWrapper<AllocationQuery>()
  494. .eq(AllocationQuery::getDateYear, year)
  495. .eq(AllocationQuery::getDateMonth, month)
  496. .eq(AllocationQuery::getHospId, hospId)
  497. );
  498. }
  499. @Override
  500. public List<CostCostingGroup> getRealData(List<Long> maxId, Long hospId, Integer year, Integer month) {
  501. if (!CollectionUtils.isEmpty(maxId)) {
  502. return baseMapper.getRealData(maxId, hospId, month, year);
  503. } else {
  504. return baseMapper.getAllRealData(hospId, month, year);
  505. }
  506. }
  507. /**
  508. * @param type
  509. * @param computeDate
  510. * @param departmentName
  511. * @return
  512. */
  513. @Override
  514. public List<CommonDepartVo> getDepartment(Integer type, String computeDate, String departmentName) {
  515. int year = 0;
  516. int month = 0;
  517. Date date = DateUtils.StringToDate(computeDate, DateStyleEnum.YYYY_MM);
  518. if (StrUtil.isNotBlank(computeDate)) {
  519. year = DateUtil.year(date);
  520. month = DateUtil.month(date) + 1;
  521. }
  522. return baseMapper.getDepartment(year, month, UserContext.getHospId(), departmentName);
  523. }
  524. /**
  525. * @param computeDate
  526. */
  527. @Override
  528. public void removeCost(String computeDate) {
  529. int year = 0;
  530. int month = 0;
  531. Date date = DateUtils.StringToDate(computeDate, DateStyleEnum.YYYY_MM);
  532. if (StrUtil.isNotBlank(computeDate)) {
  533. year = DateUtil.year(date);
  534. month = DateUtil.month(date) + 1;
  535. }
  536. LambdaQueryWrapper<CostCostingGroup> queryWrapper = new LambdaQueryWrapper<>();
  537. queryWrapper.eq(!NumberConstant.ZERO.equals(year), CostCostingGroup::getDateYear, year);
  538. queryWrapper.eq(!NumberConstant.ZERO.equals(month), CostCostingGroup::getDateMonth, month);
  539. queryWrapper.eq(CostCostingGroup::getHospId, UserContext.getHospId());
  540. List<CostCostingGroup> list = this.list(queryWrapper);
  541. if (!CollectionUtils.isEmpty(list)) {
  542. List<Long> collect = list.stream().map(CostCostingGroup::getId).collect(Collectors.toList());
  543. this.removeByIds(collect);
  544. }
  545. }
  546. }