CostIncomeGroupServiceImpl.java 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  1. package com.imed.costaccount.service.impl;
  2. import cn.hutool.core.date.DateUtil;
  3. import cn.hutool.core.util.StrUtil;
  4. import com.alibaba.fastjson.JSON;
  5. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  6. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  7. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  8. import com.imed.costaccount.common.exception.CostException;
  9. import com.imed.costaccount.common.util.*;
  10. import com.imed.costaccount.constants.NumberConstant;
  11. import com.imed.costaccount.enums.DateStyleEnum;
  12. import com.imed.costaccount.enums.ErrorCodeEnum;
  13. import com.imed.costaccount.mapper.CostIncomeGroupMapper;
  14. import com.imed.costaccount.model.*;
  15. import com.imed.costaccount.model.vo.CostIncomeGroupAllAmountVO;
  16. import com.imed.costaccount.model.vo.CostIncomeGroupBeforeVO;
  17. import com.imed.costaccount.model.vo.IncomeErrorMessage;
  18. import com.imed.costaccount.service.*;
  19. import lombok.extern.slf4j.Slf4j;
  20. import org.jetbrains.annotations.NotNull;
  21. import org.springframework.beans.factory.annotation.Value;
  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.io.File;
  28. import java.io.IOException;
  29. import java.math.BigDecimal;
  30. import java.util.*;
  31. import java.util.concurrent.atomic.AtomicReference;
  32. import java.util.stream.Collectors;
  33. @Slf4j
  34. @Service("costIncomeGroupService")
  35. public class CostIncomeGroupServiceImpl extends ServiceImpl<CostIncomeGroupMapper, CostIncomeGroup> implements CostIncomeGroupService {
  36. @Value("${file.serverPath}")
  37. private String fileTempPath;
  38. @Value("${file.serverUrl}")
  39. private String FILE_PATH;
  40. private final DepartmentService departmentService;
  41. private final ResponsibilityService responsibilityService;
  42. private final ProductService productService;
  43. private final AccountingService accountingService;
  44. private final ResponsibilityDepartmentService responsibilityDepartmentService;
  45. private final AccountingProductService accountingProductService;
  46. private final CostIncomeFileService costIncomeFileService;
  47. private final CostIncomeGroupSetService costIncomeGroupSetService;
  48. public CostIncomeGroupServiceImpl(DepartmentService departmentService, ResponsibilityService responsibilityService, ProductService productService, AccountingService accountingService, ResponsibilityDepartmentService responsibilityDepartmentService, AccountingProductService accountingProductService, CostIncomeFileService costIncomeFileService, CostIncomeGroupSetService costIncomeGroupSetService) {
  49. this.departmentService = departmentService;
  50. this.responsibilityService = responsibilityService;
  51. this.productService = productService;
  52. this.accountingService = accountingService;
  53. this.responsibilityDepartmentService = responsibilityDepartmentService;
  54. this.accountingProductService = accountingProductService;
  55. this.costIncomeFileService = costIncomeFileService;
  56. this.costIncomeGroupSetService = costIncomeGroupSetService;
  57. }
  58. /**
  59. * 分页查询收入归集前的数据
  60. *
  61. * @param current 当前页
  62. * @param pageSize 当前页大小
  63. * @param dateTime 年月
  64. * @param responsibilityCode 责任中心代码
  65. * @param accountCode 会计科目的Code
  66. * @param hospId 医院Id
  67. * @return
  68. */
  69. @Override
  70. public PageUtils queryList(Integer current, Integer pageSize, String dateTime, String responsibilityCode, String accountCode, Long hospId) {
  71. // 先检验当前年月是否存在数据
  72. int year = 0;
  73. int month = 0;
  74. Date date = DateUtils.StringToDate(dateTime, DateStyleEnum.YYYY_MM);
  75. if (StrUtil.isNotBlank(dateTime)) {
  76. year = DateUtil.year(date);
  77. month = DateUtil.month(date) + 1;
  78. }
  79. Page<CostIncomeGroup> costIncomeGroupPage = new Page<>(current, pageSize);
  80. Page<CostIncomeGroup> pages = this.page(costIncomeGroupPage, new QueryWrapper<CostIncomeGroup>().lambda()
  81. .eq(Objects.nonNull(hospId), CostIncomeGroup::getHospId, hospId)
  82. .eq(!NumberConstant.ZERO.equals(year), CostIncomeGroup::getDateYear, year)
  83. .eq(!NumberConstant.ZERO.equals(month), CostIncomeGroup::getDateMonth, month)
  84. .and(StrUtil.isNotBlank(responsibilityCode), i -> i.like(CostIncomeGroup::getOpenResponsibilityCode, responsibilityCode)
  85. .or().like(CostIncomeGroup::getStartResponsibilityCode, responsibilityCode))
  86. .like(StrUtil.isNotBlank(accountCode), CostIncomeGroup::getAccountCode, accountCode));
  87. List<CostIncomeGroup> records = pages.getRecords();
  88. List<CostIncomeGroupBeforeVO> costIncomeGroupBeforeVOList = BeanUtil.convertList(records, CostIncomeGroupBeforeVO.class);
  89. if (CollectionUtils.isEmpty(costIncomeGroupBeforeVOList)){
  90. PageUtils pageUtils = new PageUtils(pages);
  91. pageUtils.setList(null);
  92. pageUtils.setTotalAmount(new BigDecimal(0.0000));
  93. return pageUtils;
  94. }
  95. // 进行金额合并
  96. List<Long> idList = costIncomeGroupBeforeVOList.stream().map(CostIncomeGroupBeforeVO::getId).collect(Collectors.toList());
  97. List<CostIncomeGroupAllAmountVO> costIncomeGroupAllAmountVoS = baseMapper.countMoney(idList);
  98. // 查询所有的责任中心 科室 会计科目 成本项目的数据 处理名字
  99. setCodeName(costIncomeGroupAllAmountVoS);
  100. // 对,的金额进行合并
  101. AtomicReference<BigDecimal> totalAmount = new AtomicReference<>(new BigDecimal("0.0000"));
  102. costIncomeGroupAllAmountVoS.forEach(i -> {
  103. String allMoney = i.getAllMoney();
  104. if (StrUtil.isNotBlank(allMoney) && allMoney.contains(StrUtil.COMMA)) {
  105. // 存在,在进行求和
  106. long sum;
  107. List<Long> list = Arrays.stream(allMoney.split(StrUtil.COMMA)).map(Long::valueOf).collect(Collectors.toList());
  108. sum = list.stream().mapToLong(m -> m).sum();
  109. i.setAmount(BigDecimal.valueOf(sum));
  110. }
  111. //TODO 统计总金额
  112. totalAmount.updateAndGet(v -> v.add(i.getAmount()));
  113. });
  114. PageUtils pageUtils = new PageUtils(pages);
  115. pageUtils.setList(costIncomeGroupAllAmountVoS);
  116. pageUtils.setTotalAmount(totalAmount.get());
  117. return pageUtils;
  118. }
  119. /**
  120. * 批量导入收入数据
  121. *
  122. * @param list 输入的文件
  123. * @param user 用户
  124. * @param file
  125. * @return
  126. */
  127. @Override
  128. @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
  129. public Result importIncomeGroup(List<List<Object>> list, User user, MultipartFile file, String dateTime, Integer fileType) {
  130. // 先检验当前年月是否存在数据
  131. int year = 0;
  132. int month = 0;
  133. Date date = DateUtils.StringToDate(dateTime, DateStyleEnum.YYYY_MM_DD);
  134. if (StrUtil.isNotBlank(dateTime)) {
  135. year = DateUtil.year(date);
  136. month = DateUtil.month(date) + 1;
  137. }
  138. Long hospId = user.getHospId();
  139. List<CostIncomeGroup> groups = this.list(new QueryWrapper<CostIncomeGroup>().lambda().eq(CostIncomeGroup::getHospId, hospId)
  140. .eq(CostIncomeGroup::getDateYear, year).eq(CostIncomeGroup::getDateMonth, month));
  141. if (!CollectionUtils.isEmpty(groups)) {
  142. throw new CostException(500, year + "年" + month + "月数据已存在");
  143. }
  144. // 移除前几行的抬头内容 list的大小对应的就是行数的大小
  145. removeTitle(list);
  146. log.info("读取的数据为:{}", list);
  147. List<IncomeErrorMessage> incomeErrorMessageList = new ArrayList<>();
  148. //获取所有的科室 成本项目 责任中心 会计科目
  149. //
  150. Map<String, Department> departmentMap = getDepartmentByCodeNameMap(hospId);
  151. Map<String, Product> productMap = getProductByCodeNameMap(hospId);
  152. Map<Long, Responsibility> responsibilityMap = getResponsibilityIdResponsibilityMap(hospId);
  153. Map<Long, Accounting> accountingMap = getAccountIdAccountingMap(hospId);
  154. List<ResponsibilityDepartment> responsibilityDepartmentList = getResponsibilityDepartments(hospId);
  155. if (CollectionUtils.isEmpty(responsibilityDepartmentList)) {
  156. throw new CostException(500, "没有科室责任中心对照数据");
  157. }
  158. List<AccountingProduct> accountingProductList = accountingProductService.list(new QueryWrapper<AccountingProduct>().lambda().eq(AccountingProduct::getHospId, hospId));
  159. if (CollectionUtils.isEmpty(accountingProductList)) {
  160. throw new CostException(500, "没有成本会计对照数据");
  161. }
  162. Map<Long, Long> responsibilityDepMap = getDepartmentIdResponsibilityIdMap(responsibilityDepartmentList);
  163. Map<Long, Long> accountProMap = getProductIdAccountIdMap(accountingProductList);
  164. List<CostIncomeGroup> costIncomeGroupArrayList = new ArrayList<>();
  165. // 检验数据
  166. checkImportData(list, incomeErrorMessageList, costIncomeGroupArrayList, departmentMap, productMap, responsibilityMap, accountingMap, responsibilityDepMap, accountProMap, hospId, year, month);
  167. // 文件上传
  168. String uploadFile = uploadFile(file, UserContext.getCurrentUser());
  169. // 上传记录保存
  170. if (StrUtil.isBlank(uploadFile)) {
  171. throw new CostException(500, "文件上传异常");
  172. }
  173. // 记录文件上传记录
  174. CostIncomeFile costIncomeFile = costIncomeFileService.saveCostIncomeFile(list, user, file, hospId, incomeErrorMessageList, uploadFile, fileType);
  175. Long id = costIncomeFile.getId();
  176. costIncomeGroupArrayList.forEach(i -> {
  177. // 设置文件Id
  178. i.setFileId(id);
  179. });
  180. if (CollectionUtils.isEmpty(incomeErrorMessageList)) {
  181. this.saveBatch(costIncomeGroupArrayList);
  182. return Result.build(200,"数据导入成功",null);
  183. }else {
  184. return Result.build(500, "数据未成功导入", null);
  185. }
  186. }
  187. private void removeTitle(List<List<Object>> list) {
  188. for (int i = list.size() - 1; i >= 0; i--) {
  189. if (i == NumberConstant.ZERO || i == NumberConstant.ONE || i == NumberConstant.TWO || i == NumberConstant.THREE) {
  190. list.remove(list.get(i));
  191. }
  192. }
  193. }
  194. /**
  195. * 返回成本会计对照数据 Key 成本项目Id Value 会计科目Id
  196. *
  197. * @param accountingProductList
  198. * @return
  199. */
  200. @NotNull
  201. private Map<Long, Long> getProductIdAccountIdMap(List<AccountingProduct> accountingProductList) {
  202. return accountingProductList.stream().collect(Collectors.toMap(AccountingProduct::getProductId, AccountingProduct::getAccountingId));
  203. }
  204. /**
  205. * Map类型
  206. * Key DepartmentId
  207. * Value ResponsibilityId
  208. *
  209. * @param responsibilityDepartmentList
  210. * @return
  211. */
  212. public Map<Long, Long> getDepartmentIdResponsibilityIdMap(List<ResponsibilityDepartment> responsibilityDepartmentList) {
  213. return responsibilityDepartmentList.stream().collect(Collectors.toMap(ResponsibilityDepartment::getDepartmentId, ResponsibilityDepartment::getResponsibilityId));
  214. }
  215. public List<ResponsibilityDepartment> getResponsibilityDepartments(Long hospId) {
  216. return responsibilityDepartmentService.list(new QueryWrapper<ResponsibilityDepartment>().lambda()
  217. .eq(ResponsibilityDepartment::getHospId, hospId));
  218. }
  219. /**
  220. * Key AccountId
  221. * Value Accounting对象
  222. *
  223. * @param hospId
  224. * @return
  225. */
  226. public Map<Long, Accounting> getAccountIdAccountingMap(Long hospId) {
  227. return accountingService.list(new QueryWrapper<Accounting>().lambda().eq(Accounting::getHospId, hospId)).stream().collect(Collectors.toMap(Accounting::getId, synOe -> synOe));
  228. }
  229. /**
  230. * Key responsibilityId 责任中心Id
  231. * Value Responsibility对象
  232. *
  233. * @param hospId
  234. * @return
  235. */
  236. public Map<Long, Responsibility> getResponsibilityIdResponsibilityMap(Long hospId) {
  237. return responsibilityService.list(new QueryWrapper<Responsibility>().lambda().eq(Responsibility::getHospId, hospId)).stream().collect(Collectors.toMap(Responsibility::getId, synOe -> synOe));
  238. }
  239. /**
  240. * Key 成本项目Code+Name
  241. * Value 成本项目对象
  242. *
  243. * @param hospId
  244. * @return
  245. */
  246. public Map<String, Product> getProductByCodeNameMap(Long hospId) {
  247. return productService.list(new QueryWrapper<Product>().lambda().eq(Product::getHospId, hospId)).stream().collect(Collectors.toMap(k -> k.getProductCode() + k.getProductName(), synOe -> synOe));
  248. }
  249. /**
  250. * Key 科室项目Code+Name
  251. * Value 科室对象
  252. *
  253. * @param hospId
  254. * @return
  255. */
  256. public Map<String, Department> getDepartmentByCodeNameMap(Long hospId) {
  257. return departmentService.list(new QueryWrapper<Department>().lambda().eq(Department::getHospId, hospId)).stream().collect(Collectors.toMap(k -> k.getDepartmentCode() + k.getDepartmentName(), synOe -> synOe));
  258. }
  259. /**
  260. * 导入收入数据
  261. *
  262. * @param read 读取到的初始数据
  263. * @param user 当前登录用户
  264. * @param file 导入的文件
  265. * @param year 年
  266. * @param month 月
  267. * @return {@link Result}
  268. */
  269. @Override
  270. public Result importDataByIncomeData(List<List<Object>> read, User user, MultipartFile file, Integer year, Integer month) {
  271. // 去头
  272. this.removeTitle(read);
  273. return null;
  274. }
  275. /**
  276. * 检验数据
  277. *
  278. * @param list 表单数据
  279. * @param incomeErrorMessageList 存储错误信息的集合
  280. * @param costIncomeGroupArrayList
  281. * @param departmentMap 科室Map
  282. * @param productMap 成本项目map
  283. * @param responsibilityMap 责任中心Map
  284. * @param accountingMap 会计科目Map
  285. * @param responsibilityDepMap 责任中心科室对照Map
  286. * @param accountProMap 责任中心Map
  287. * @param hospId
  288. */
  289. private void checkImportData(List<List<Object>> list, List<IncomeErrorMessage> incomeErrorMessageList, List<CostIncomeGroup> costIncomeGroupArrayList, Map<String, Department> departmentMap, Map<String, Product> productMap, Map<Long, Responsibility> responsibilityMap, Map<Long, Accounting> accountingMap, Map<Long, Long> responsibilityDepMap, Map<Long, Long> accountProMap, Long hospId, Integer year, Integer month) {
  290. for (int i = 0; i < list.size(); i++) {
  291. int row = i + 5;
  292. CostIncomeGroup costIncomeGroup = new CostIncomeGroup();
  293. AfterIncomegroup afterIncomegroup = new AfterIncomegroup();
  294. // 用来检验数据合理性的循环
  295. List<Object> data = list.get(i);
  296. log.info("用户输入的数据是{}", data);
  297. // 成本项目的代码和名称
  298. String productCode = data.get(0).toString();
  299. String productName = data.get(1).toString();
  300. // 开单科室 执行科室的代码和名称
  301. String openDepartmentName = data.get(2).toString();
  302. String openDepartmentCode = data.get(3).toString();
  303. String startDepartmentName = data.get(4).toString();
  304. String startDepartmentCode = data.get(5).toString();
  305. BigDecimal beforeMoney = BigDecimal.valueOf(Double.parseDouble(("0".equals(data.get(15).toString()) || StrUtil.isBlank(data.get(15).toString())) ?"0.00":data.get(15).toString()));
  306. boolean checkNull = StrUtil.isBlank(data.get(15).toString());
  307. boolean checkOne = "0".equals(data.get(15).toString());
  308. if (checkNull || checkOne) {
  309. // 要求这一行的数据必须全部填写
  310. for (int j = 0; j < data.size(); j++) {
  311. if (Objects.isNull(data.get(j))) {
  312. IncomeErrorMessage incomeErrorMessage = new IncomeErrorMessage();
  313. incomeErrorMessage.setTotal(i);
  314. int column = j + 1;
  315. incomeErrorMessage.setErrMessage("第{" + row + "}行第{" + column + "}列数据为空");
  316. incomeErrorMessageList.add(incomeErrorMessage);
  317. }
  318. }
  319. }
  320. // 检验收入成本项目数据是否存在
  321. Product product = productMap.get(productCode + productName);
  322. Department department = departmentMap.get(openDepartmentCode + openDepartmentName);
  323. Department department1 = departmentMap.get(startDepartmentCode + startDepartmentName);
  324. if (StrUtil.isNotBlank(productCode) && StrUtil.isNotBlank(productName)) {
  325. if (Objects.isNull(product)) {
  326. IncomeErrorMessage incomeErrorMessage = new IncomeErrorMessage();
  327. incomeErrorMessage.setTotal(row);
  328. incomeErrorMessage.setErrMessage("成本项目代码:" + productCode + " 名称:" + productName + "不存在");
  329. incomeErrorMessageList.add(incomeErrorMessage);
  330. } else {
  331. // 检验对应的会计科目是否存在
  332. Long id = product.getId();
  333. Long accountId = accountProMap.get(id);
  334. if (Objects.isNull(accountingMap.get(accountId))) {
  335. IncomeErrorMessage incomeErrorMessage = new IncomeErrorMessage();
  336. incomeErrorMessage.setTotal(row);
  337. incomeErrorMessage.setErrMessage("成本项目代码:" + productCode + " 名称:" + productName + "对应的会计科目不存在");
  338. incomeErrorMessageList.add(incomeErrorMessage);
  339. } else {
  340. costIncomeGroup.setProductCode(productCode);
  341. costIncomeGroup.setProductName(productName);
  342. costIncomeGroup.setAccountCode(accountingMap.get(accountId).getAccountingCode());
  343. costIncomeGroup.setAccountName(accountingMap.get(accountId).getAccountingName());
  344. }
  345. }
  346. } else {
  347. costIncomeGroup.setProductCode(null);
  348. costIncomeGroup.setProductName(null);
  349. costIncomeGroup.setAccountCode(null);
  350. costIncomeGroup.setAccountName(null);
  351. }
  352. // 检验开单科室
  353. if (StrUtil.isNotBlank(openDepartmentCode) && StrUtil.isNotBlank(openDepartmentName)) {
  354. // 开单科室
  355. if (Objects.isNull(department)) {
  356. IncomeErrorMessage incomeErrorMessage = new IncomeErrorMessage();
  357. incomeErrorMessage.setTotal(row);
  358. incomeErrorMessage.setErrMessage("开单科室代码:" + openDepartmentCode + " 科室名称:" + openDepartmentName + "不存在");
  359. incomeErrorMessageList.add(incomeErrorMessage);
  360. } else {
  361. Long id = department.getId();
  362. Long responsibilityId = responsibilityDepMap.get(id);
  363. if (Objects.isNull(responsibilityMap.get(responsibilityId))) {
  364. IncomeErrorMessage incomeErrorMessage = new IncomeErrorMessage();
  365. incomeErrorMessage.setTotal(row);
  366. incomeErrorMessage.setErrMessage("开单科室代码代码:" + openDepartmentCode + " 科室名称:" + openDepartmentName + "对应的责任中心不存在");
  367. incomeErrorMessageList.add(incomeErrorMessage);
  368. } else {
  369. Responsibility responsibility = responsibilityMap.get(responsibilityId);
  370. costIncomeGroup.setOpenDepartmentCode(openDepartmentCode);
  371. costIncomeGroup.setOpenDepartmentName(openDepartmentName);
  372. costIncomeGroup.setOpenResponsibilityCode(responsibility.getResponsibilityCode());
  373. costIncomeGroup.setOpenResponsibilityName(responsibility.getResponsibilityName());
  374. afterIncomegroup.setOpenDepartmentCode(openDepartmentCode);
  375. afterIncomegroup.setOpenDepartmentName(openDepartmentName);
  376. afterIncomegroup.setOpenDepartmentStatus(responsibility.getResponsibilityType());
  377. }
  378. }
  379. } else {
  380. costIncomeGroup.setOpenDepartmentCode(null);
  381. costIncomeGroup.setOpenDepartmentName(null);
  382. costIncomeGroup.setOpenResponsibilityCode(null);
  383. costIncomeGroup.setOpenResponsibilityName(null);
  384. }
  385. // 检验执行科室
  386. if (StrUtil.isNotBlank(startDepartmentCode) && StrUtil.isNotBlank(startDepartmentName)) {
  387. //执行科室
  388. if (Objects.isNull(department1)) {
  389. IncomeErrorMessage incomeErrorMessage = new IncomeErrorMessage();
  390. incomeErrorMessage.setTotal(row);
  391. incomeErrorMessage.setErrMessage("执行科室代码:" + startDepartmentCode + " 科室名称:" + startDepartmentName + "科室不存在");
  392. incomeErrorMessageList.add(incomeErrorMessage);
  393. } else {
  394. Long id = department1.getId();
  395. Long responsibilityId = responsibilityDepMap.get(id);
  396. if (Objects.isNull(responsibilityMap.get(responsibilityId))) {
  397. IncomeErrorMessage incomeErrorMessage = new IncomeErrorMessage();
  398. incomeErrorMessage.setTotal(row);
  399. incomeErrorMessage.setErrMessage("执行科室代码:" + openDepartmentCode + " 名称:" + openDepartmentName + "对应的责任中心不存在");
  400. incomeErrorMessageList.add(incomeErrorMessage);
  401. } else {
  402. Responsibility responsibility = responsibilityMap.get(responsibilityId);
  403. costIncomeGroup.setStartDepartmentCode(startDepartmentCode);
  404. costIncomeGroup.setStartDepartmentName(startDepartmentName);
  405. costIncomeGroup.setStartResponsibilityCode(responsibility.getResponsibilityCode());
  406. costIncomeGroup.setStartResponsibilityName(responsibility.getResponsibilityName());
  407. afterIncomegroup.setStartDepartmentCode(startDepartmentCode);
  408. afterIncomegroup.setStartDepartmentName(startDepartmentName);
  409. afterIncomegroup.setStartDepartmentStatus(responsibility.getResponsibilityType());
  410. }
  411. }
  412. } else {
  413. costIncomeGroup.setStartDepartmentCode(null);
  414. costIncomeGroup.setStartDepartmentName(null);
  415. costIncomeGroup.setStartResponsibilityCode(null);
  416. costIncomeGroup.setStartResponsibilityName(null);
  417. }
  418. costIncomeGroup.setDoctorNumber(Long.parseLong(data.get(6).toString())).setDoctorName(data.get(7).toString())
  419. .setPatientId(Long.parseLong(data.get(8).toString())).setOutpatientId(Long.parseLong(data.get(9).toString()))
  420. .setPatientName(data.get(10).toString()).setPatientFee(data.get(11).toString()).setReceiptFee(data.get(12).toString())
  421. .setTotalNumber(Integer.parseInt(data.get(13).toString())).setUnit(data.get(14).toString())
  422. .setFeeDatetime(DateUtils.StringToDate(data.get(16).toString(), DateStyleEnum.YYYY_MM_DD_HH_MM_SS));
  423. costIncomeGroup.setHospId(hospId);
  424. costIncomeGroup.setCreateTime(System.currentTimeMillis());
  425. costIncomeGroup.setDateYear(year);
  426. costIncomeGroup.setDateMonth(month);
  427. costIncomeGroup.setAmount(beforeMoney);
  428. // 检验数据
  429. getAfterData(hospId, costIncomeGroup, afterIncomegroup, beforeMoney);
  430. costIncomeGroupArrayList.add(costIncomeGroup);
  431. }
  432. }
  433. /**
  434. * 封装需要的数据
  435. * @param hospId
  436. * @param costIncomeGroup
  437. * @param afterIncomegroup
  438. * @param beforeMoney
  439. */
  440. private void getAfterData(Long hospId, CostIncomeGroup costIncomeGroup, AfterIncomegroup afterIncomegroup, BigDecimal beforeMoney) {
  441. Integer openDepartmentStatus = afterIncomegroup.getOpenDepartmentStatus();
  442. Integer startDepartmentStatus = afterIncomegroup.getStartDepartmentStatus();
  443. if (Objects.nonNull(openDepartmentStatus) && Objects.nonNull(startDepartmentStatus)) {
  444. Map<String, CostIncomeGroupSet> incomeGroupSetMap = costIncomeGroupSetService.list(new QueryWrapper<CostIncomeGroupSet>().lambda().eq(CostIncomeGroupSet::getHospId, hospId)).stream().collect(Collectors.toMap(k -> k.getOpenDepartmentStatus().toString() + k.getStartDepartmentStatus().toString(), synOe -> synOe));
  445. CostIncomeGroupSet costIncomeGroupSet = incomeGroupSetMap.get(openDepartmentStatus.toString() + startDepartmentStatus.toString());
  446. if (Objects.nonNull(costIncomeGroupSet)) {
  447. Map<String, Responsibility> map = responsibilityService.list(new QueryWrapper<Responsibility>().lambda().eq(Responsibility::getHospId, hospId)).stream().collect(Collectors.toMap(Responsibility::getResponsibilityCode, synOe -> synOe));
  448. // 开单科室比例
  449. BigDecimal openDepartmentProportion = new BigDecimal(costIncomeGroupSet.getOpenDepartmentProportion().toString());
  450. // 执行科室比例
  451. BigDecimal startDepartmentProportion = new BigDecimal(costIncomeGroupSet.getStartDepartmentProportion().toString());
  452. // beforeMoney
  453. afterIncomegroup.setOpenDepartmentDecimal(beforeMoney.multiply(openDepartmentProportion).divide(new BigDecimal(100), 4, BigDecimal.ROUND_HALF_UP));
  454. afterIncomegroup.setStartDepartmentDecimal(beforeMoney.multiply(startDepartmentProportion).divide(new BigDecimal(100), 4, BigDecimal.ROUND_HALF_UP));
  455. String responsibilityCodes = costIncomeGroupSet.getResponsibilityCodes();
  456. if (NumberConstant.TWO.equals(costIncomeGroupSet.getOpenDepartmentStatus()) && NumberConstant.TWO.equals(costIncomeGroupSet.getStartDepartmentStatus()) && StrUtil.isNotBlank(responsibilityCodes)) {
  457. // /拼接的
  458. afterIncomegroup.setDirectStatus(NumberConstant.TWO);
  459. String responsibilityCode = responsibilityCodes.split(StrUtil.SLASH)[responsibilityCodes.split(StrUtil.SLASH).length - 1];
  460. Responsibility responsibility = map.get(responsibilityCode);
  461. if (Objects.nonNull(responsibility)) {
  462. afterIncomegroup.setResponsibilityCode(responsibility.getResponsibilityCode());
  463. afterIncomegroup.setResponsibilityName(responsibility.getResponsibilityName());
  464. }
  465. costIncomeGroup.setAfterIncomeGroup(JSON.toJSONString(afterIncomegroup));
  466. }
  467. }
  468. }
  469. }
  470. /**
  471. * 设置相关名称
  472. *
  473. * @param costIncomeGroupAllAmountVOList
  474. */
  475. private void setCodeName(List<CostIncomeGroupAllAmountVO> costIncomeGroupAllAmountVOList) {
  476. // List<Responsibility> responsibilityList = responsibilityService.list(new QueryWrapper<Responsibility>().lambda().eq(Responsibility::getHospId, hospId));
  477. // Map<String, String> responsibilityMap = responsibilityList.stream().collect(Collectors.toMap(Responsibility::getResponsibilityCode, Responsibility::getResponsibilityName));
  478. // List<Department> departmentList = departmentService.list(new QueryWrapper<Department>().lambda().eq(Department::getHospId, hospId));
  479. // Map<String, String> departmentMap = departmentList.stream().collect(Collectors.toMap(Department::getDepartmentCode, Department::getDepartmentName));
  480. // List<Product> productList = productService.list(new QueryWrapper<Product>().lambda().eq(Product::getHospId, hospId));
  481. // Map<String, String> productMap = productList.stream().collect(Collectors.toMap(Product::getProductCode, Product::getProductName));
  482. // List<Accounting> accountingList = accountingService.list(new QueryWrapper<Accounting>().lambda().eq(Accounting::getHospId, hospId));
  483. // Map<String, String> accountMap = accountingList.stream().collect(Collectors.toMap(Accounting::getAccountingCode, Accounting::getAccountingName));
  484. costIncomeGroupAllAmountVOList.forEach(i -> {
  485. // 以为这里的数据导入的 在导入的时候进行数据校验
  486. // 设置开单科室名称 执行科室名称 开单责任中心名称 执行责任中心名称 成本项目的名称 会计科目名称
  487. i.setOpenDepartmentCodeName("[" + i.getOpenDepartmentCode() + "]" + i.getOpenDepartmentName());
  488. i.setOpenResponsibilityCodeName("[" + i.getOpenResponsibilityCode() + "]" + i.getOpenResponsibilityName());
  489. i.setStartDepartmentCodeName("[" + i.getStartDepartmentCode() + "]" + i.getStartDepartmentName());
  490. i.setStartResponsibilityCodeName("[" + i.getStartResponsibilityCode() + "]" + i.getStartResponsibilityName());
  491. i.setProductCodeName("[" + i.getProductCode() + "]" + i.getProductName());
  492. i.setAccountCodeName("[" + i.getAccountCode() + "]" + i.getAccountName());
  493. });
  494. }
  495. /**
  496. * 文件上传
  497. */
  498. public String uploadFile(MultipartFile file, User user) {
  499. Long hospId = user.getHospId();
  500. String fileName = file.getOriginalFilename().substring(0, file.getOriginalFilename().lastIndexOf(".")) + System.currentTimeMillis() + ".xsl";
  501. String localFilePath = fileTempPath + StrUtil.SLASH + hospId + StrUtil.SLASH;
  502. File tempFile = new File(localFilePath);
  503. if (!tempFile.exists()) {
  504. tempFile.mkdirs();
  505. }
  506. localFilePath = localFilePath + fileName;
  507. try {
  508. file.transferTo(new File(localFilePath));
  509. } catch (IOException e) {
  510. log.error("【文件上传至本地】失败,绝对路径:{}", e.getMessage());
  511. throw new CostException(ErrorCodeEnum.FILE_UPLOAD_ERROR);
  512. } finally {
  513. }
  514. return FILE_PATH + hospId + StrUtil.SLASH + fileName;
  515. }
  516. }