CostIncomeGroupServiceImpl.java 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. package com.imed.costaccount.service.impl;
  2. import cn.hutool.core.util.StrUtil;
  3. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  4. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  5. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  6. import com.imed.costaccount.common.util.BeanUtil;
  7. import com.imed.costaccount.common.util.DateUtils;
  8. import com.imed.costaccount.common.util.PageUtils;
  9. import com.imed.costaccount.mapper.CostIncomeGroupMapper;
  10. import com.imed.costaccount.model.*;
  11. import com.imed.costaccount.model.vo.CostIncomeGroupAllAmountVO;
  12. import com.imed.costaccount.model.vo.CostIncomeGroupBeforeVO;
  13. import com.imed.costaccount.service.*;
  14. import org.springframework.stereotype.Service;
  15. import org.springframework.util.StringUtils;
  16. import java.math.BigDecimal;
  17. import java.util.Arrays;
  18. import java.util.List;
  19. import java.util.Map;
  20. import java.util.stream.Collectors;
  21. @Service("costIncomeGroupService")
  22. public class CostIncomeGroupServiceImpl extends ServiceImpl<CostIncomeGroupMapper, CostIncomeGroup> implements CostIncomeGroupService {
  23. private final DepartmentService departmentService;
  24. private final ResponsibilityService responsibilityService;
  25. private final ProductService productService;
  26. private final AccountingService accountingService;
  27. public CostIncomeGroupServiceImpl(DepartmentService departmentService, ResponsibilityService responsibilityService, ProductService productService, AccountingService accountingService) {
  28. this.departmentService = departmentService;
  29. this.responsibilityService = responsibilityService;
  30. this.productService = productService;
  31. this.accountingService = accountingService;
  32. }
  33. /**
  34. * 分页查询收入归集前的数据
  35. *
  36. * @param current 当前页
  37. * @param pageSize 当前页大小
  38. * @param dateTime 年月
  39. * @param responsibilityCode 责任中心代码
  40. * @param accountCode 会计科目的Code
  41. * @param hospId 医院Id
  42. * @return
  43. */
  44. @Override
  45. public PageUtils queryList(Integer current, Integer pageSize, String dateTime, String responsibilityCode, String accountCode, Long hospId) {
  46. int year = DateUtils.getYear(dateTime);
  47. int month=DateUtils.getMonth(dateTime);
  48. Page<CostIncomeGroup> costIncomeGroupPage = new Page<>(current, pageSize);
  49. QueryWrapper<CostIncomeGroup> wrapper = new QueryWrapper<>();
  50. wrapper.eq("hosp_id",hospId);
  51. wrapper.eq("date_year",year);
  52. wrapper.eq("date_month",month);
  53. wrapper.like(!StringUtils.isEmpty(responsibilityCode),"open_responsibility_code",responsibilityCode)
  54. .or()
  55. .like(!StringUtils.isEmpty(responsibilityCode),"start_responsibility_code",responsibilityCode);
  56. wrapper.eq(!StringUtils.isEmpty(accountCode),"account_code",accountCode);
  57. Page<CostIncomeGroup> pages = this.page(costIncomeGroupPage, wrapper);
  58. List<CostIncomeGroup> records = pages.getRecords();
  59. List<CostIncomeGroupBeforeVO> costIncomeGroupBeforeVOList = BeanUtil.convertList(records, CostIncomeGroupBeforeVO.class);
  60. // 查询所有的责任中心 科室 会计科目 成本项目的数据 处理名字
  61. setCodeName(hospId, costIncomeGroupBeforeVOList);
  62. // 进行金额合并
  63. List<CostIncomeGroupAllAmountVO> costIncomeGroupAllAmountVoS =baseMapper.countMoney(costIncomeGroupBeforeVOList);
  64. // 对,的金额进行合并
  65. costIncomeGroupAllAmountVoS.forEach(i->{
  66. String allMoney = i.getAllMoney();
  67. if (allMoney.contains(StrUtil.COMMA)){
  68. // 存在,在进行求和
  69. long sum;
  70. List<Long> list = Arrays.stream(allMoney.split(StrUtil.COMMA)).map(Long::valueOf).collect(Collectors.toList());
  71. sum = list.stream().mapToLong(m -> m).sum();
  72. i.setAmount(BigDecimal.valueOf(sum));
  73. }
  74. });
  75. PageUtils pageUtils = new PageUtils(pages);
  76. pageUtils.setList(costIncomeGroupAllAmountVoS);
  77. return pageUtils;
  78. }
  79. /**
  80. * 设置相关名称
  81. * @param hospId
  82. * @param costIncomeGroupBeforeVOList
  83. */
  84. private void setCodeName(Long hospId, List<CostIncomeGroupBeforeVO> costIncomeGroupBeforeVOList) {
  85. List<Responsibility> responsibilityList = responsibilityService.list(new QueryWrapper<Responsibility>().lambda().eq(Responsibility::getHospId, hospId));
  86. Map<String, String> responsibilityMap = responsibilityList.stream().collect(Collectors.toMap(Responsibility::getResponsibilityCode,Responsibility::getResponsibilityName));
  87. List<Department> departmentList = departmentService.list(new QueryWrapper<Department>().lambda().eq(Department::getHospId, hospId));
  88. Map<String, String> departmentMap = departmentList.stream().collect(Collectors.toMap(Department::getDepartmentCode,Department::getDepartmentName));
  89. List<Product> productList = productService.list(new QueryWrapper<Product>().lambda().eq(Product::getHospId, hospId));
  90. Map<String, String> productMap = productList.stream().collect(Collectors.toMap(Product::getProductCode,Product::getProductName));
  91. List<Accounting> accountingList = accountingService.list(new QueryWrapper<Accounting>().lambda().eq(Accounting::getHospId, hospId));
  92. Map<String, String> accountMap = accountingList.stream().collect(Collectors.toMap(Accounting::getAccountingCode,Accounting::getAccountingName));
  93. costIncomeGroupBeforeVOList.forEach(i->{
  94. // 以为这里的数据导入的 在导入的时候进行数据校验
  95. // 设置开单科室名称 执行科室名称 开单责任中心名称 执行责任中心名称 成本项目的名称 会计科目名称
  96. i.setOpenDepartmentCodeName("["+i.getOpenDepartmentCode()+"]"+departmentMap.get(i.getOpenDepartmentCode()));
  97. i.setOpenResponsibilityCodeName("["+i.getOpenResponsibilityCode()+"]"+responsibilityMap.get(i.getOpenResponsibilityCode()));
  98. i.setStartDepartmentCodeName("["+i.getStartDepartmentCode()+"]"+departmentMap.get(i.getStartDepartmentCode()));
  99. i.setStartResponsibilityCodeName("["+i.getStartResponsibilityCode()+"]"+responsibilityMap.get(i.getStartResponsibilityCode()));
  100. i.setProductCodeName("["+i.getProductCode()+"]"+productMap.get(i.getProductCode()));
  101. i.setAccountCodeName("["+i.getAccountCode()+"]"+accountMap.get(i.getAccountCode()));
  102. });
  103. }
  104. /**
  105. * 收入归集数据的计算规则
  106. */
  107. }