CostNumberBedSetServiceImpl.java 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. package com.imed.costaccount.service.impl;
  2. import cn.hutool.core.collection.CollUtil;
  3. import cn.hutool.core.util.StrUtil;
  4. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  5. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  6. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  7. import com.imed.costaccount.common.exception.CostException;
  8. import com.imed.costaccount.common.util.BeanUtil;
  9. import com.imed.costaccount.common.util.PageUtils;
  10. import com.imed.costaccount.common.util.UserContext;
  11. import com.imed.costaccount.constants.NumberConstant;
  12. import com.imed.costaccount.mapper.CostNumberBedSetMapper;
  13. import com.imed.costaccount.model.CostNumberBedSet;
  14. import com.imed.costaccount.model.CostShareParam;
  15. import com.imed.costaccount.model.ReportForm;
  16. import com.imed.costaccount.model.dto.CostNumberBedSetEditDto;
  17. import com.imed.costaccount.model.dto.CostNumberBedSetSaveDto;
  18. import com.imed.costaccount.model.vo.CheckShareParamStatusVO;
  19. import com.imed.costaccount.model.vo.CostNumberBedSetVO;
  20. import com.imed.costaccount.model.vo.ReportFormVO;
  21. import com.imed.costaccount.service.CostNumberBedSetService;
  22. import com.imed.costaccount.service.CostShareParamService;
  23. import com.imed.costaccount.service.ReportFormService;
  24. import org.springframework.stereotype.Service;
  25. import org.springframework.transaction.annotation.Propagation;
  26. import org.springframework.transaction.annotation.Transactional;
  27. import java.util.*;
  28. import java.util.stream.Collectors;
  29. @Service("costNumberBedSetService")
  30. public class CostNumberBedSetServiceImpl extends ServiceImpl<CostNumberBedSetMapper, CostNumberBedSet> implements CostNumberBedSetService {
  31. private final CostShareParamService costShareParamService;
  32. private final ReportFormService reportFormService;
  33. public CostNumberBedSetServiceImpl(CostShareParamService costShareParamService, ReportFormService reportFormService) {
  34. this.costShareParamService = costShareParamService;
  35. this.reportFormService = reportFormService;
  36. }
  37. /**
  38. * 分页查询诊次/床日设置
  39. *
  40. * @param current
  41. * @param pageSize
  42. * @param name
  43. * @param hospId
  44. * @return
  45. */
  46. @Override
  47. public PageUtils queryList(Integer current, Integer pageSize, String name, Long hospId) {
  48. Page<CostNumberBedSet> costNumberBedSetPage = new Page<>(current, pageSize);
  49. Page<CostNumberBedSet> pages = this.page(costNumberBedSetPage, new QueryWrapper<CostNumberBedSet>().lambda()
  50. .eq(CostNumberBedSet::getHospId, hospId)
  51. .like(StrUtil.isNotBlank(name),CostNumberBedSet::getIncomeFileName,name));
  52. List<CostNumberBedSet> records = pages.getRecords();
  53. List<CostNumberBedSetVO> costNumberBedSetVOList = BeanUtil.convertList(records, CostNumberBedSetVO.class);
  54. // 具体的名称根据Code Id 进行获取
  55. Map<String, String> costShareParamMap = costShareParamService.list(new QueryWrapper<CostShareParam>().lambda()
  56. .eq(CostShareParam::getHospId, hospId)).stream().collect(Collectors.toMap(CostShareParam::getShareParamCode, CostShareParam::getShareParamName));
  57. Map<Integer, ReportForm> reportFormMap = reportFormService.list(new QueryWrapper<ReportForm>().lambda().eq(ReportForm::getHospId, hospId)).stream().collect(Collectors.toMap(ReportForm::getNum, synOe -> synOe));
  58. costNumberBedSetVOList.forEach(i->{
  59. setName(costShareParamMap, reportFormMap, i);
  60. });
  61. PageUtils pageUtils = new PageUtils(pages);
  62. pageUtils.setList(costNumberBedSetVOList);
  63. return pageUtils;
  64. }
  65. /**
  66. * 设置成本分摊参数的名称 相关报表的名称
  67. * @param costShareParamMap
  68. * @param reportFormMap
  69. * @param i
  70. */
  71. private void setName(Map<String, String> costShareParamMap, Map<Integer, ReportForm> reportFormMap, CostNumberBedSetVO i) {
  72. String shareParamCode = i.getShareParamCode();
  73. String shareParamName = costShareParamMap.get(shareParamCode);
  74. if (StrUtil.isNotBlank(shareParamName)){
  75. i.setShareParamName(shareParamName);
  76. }
  77. Integer incomeFieldNum = i.getIncomeFieldNum();
  78. Integer costCorresponding = i.getCostCorresponding();
  79. ReportForm reportForm = reportFormMap.get(incomeFieldNum);
  80. ReportForm reportForm1 = reportFormMap.get(costCorresponding);
  81. if (Objects.nonNull(reportForm)){
  82. Integer reportType = reportForm.getReportType();
  83. String reportName = reportForm.getReportName();
  84. reportName = getString(reportType, reportName);
  85. i.setIncomeFileName(reportName);
  86. }
  87. if (Objects.nonNull(reportForm1)){
  88. Integer reportType = reportForm1.getReportType();
  89. String costCorrespondingName = reportForm1.getReportName();
  90. costCorrespondingName = getString(reportType, costCorrespondingName);
  91. i.setCostCorrespondingName(costCorrespondingName);
  92. }
  93. }
  94. /**
  95. * 根据Id获取诊次/床日设置的数据
  96. *
  97. * @param id
  98. * @return
  99. */
  100. @Override
  101. public CostNumberBedSetVO getByNumberBedId(Long id) {
  102. Long hospId = UserContext.getHospId();
  103. CostNumberBedSet costNumberBedSet = this.getById(id);
  104. // 具体的名称根据Code Id 进行获取
  105. Map<String, String> costShareParamMap = costShareParamService.list(new QueryWrapper<CostShareParam>().lambda()
  106. .eq(CostShareParam::getHospId, hospId)).stream().collect(Collectors.toMap(CostShareParam::getShareParamCode, CostShareParam::getShareParamName));
  107. Map<Integer, ReportForm> reportFormMap = reportFormService.list(new QueryWrapper<ReportForm>().lambda().eq(ReportForm::getHospId, hospId)).stream().collect(Collectors.toMap(ReportForm::getNum, synOe -> synOe));
  108. CostNumberBedSetVO costNumberBedSetVO = BeanUtil.convertObj(costNumberBedSet, CostNumberBedSetVO.class);
  109. if (Objects.nonNull(costNumberBedSet)){
  110. setName(costShareParamMap,reportFormMap,costNumberBedSetVO);
  111. return costNumberBedSetVO;
  112. }
  113. return null;
  114. }
  115. private String getString(Integer reportType, String reportName) {
  116. switch (reportType) {
  117. case 0:
  118. reportName = "损益表" + reportName;
  119. break;
  120. case 1:
  121. reportName = "完全成本法表" + reportName;
  122. break;
  123. case 2:
  124. reportName = "变动成本表" + reportName;
  125. break;
  126. case 3:
  127. reportName = "全院损益表" + reportName;
  128. break;
  129. case 4:
  130. reportName = "全成本报表" + reportName;
  131. break;
  132. default:
  133. reportName = "";
  134. }
  135. return reportName;
  136. }
  137. /**
  138. * 添加诊次/床日设置的数据
  139. * 后台要考虑支持多选
  140. * @param costNumberBedSetSaveDto
  141. * @param hospId
  142. */
  143. @Override
  144. @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
  145. public void addNumberBedSet(CostNumberBedSetSaveDto costNumberBedSetSaveDto, Long hospId) {
  146. String shareParamCodes = costNumberBedSetSaveDto.getShareParamCode();
  147. Integer incomeFieldNums = costNumberBedSetSaveDto.getIncomeFieldNum();
  148. CostNumberBedSet costNumberBedSet = this.getOne(new QueryWrapper<CostNumberBedSet>().lambda().eq(CostNumberBedSet::getHospId, hospId)
  149. .eq(CostNumberBedSet::getShareParamCode, shareParamCodes)
  150. .eq(CostNumberBedSet::getIncomeFieldNum, incomeFieldNums));
  151. if (Objects.nonNull(costNumberBedSet)){
  152. throw new CostException(500,"数据已经存在");
  153. }
  154. CostNumberBedSet costNumberBedSetRequest = BeanUtil.convertObj(costNumberBedSetSaveDto, CostNumberBedSet.class);
  155. costNumberBedSetRequest.setCreateTime(System.currentTimeMillis());
  156. costNumberBedSetRequest.setHospId(hospId);
  157. this.save(costNumberBedSetRequest);
  158. }
  159. /**
  160. * 修改诊次/床日的设置数据
  161. *
  162. * @param costNumberBedSetEditDto
  163. * @param hospId
  164. */
  165. @Override
  166. @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
  167. public void updateNumberBedById(CostNumberBedSetEditDto costNumberBedSetEditDto, Long hospId) {
  168. Long id = costNumberBedSetEditDto.getId();
  169. CostNumberBedSet costNumberBedSet = this.getById(id);
  170. if (Objects.isNull(costNumberBedSet)){
  171. throw new CostException(500,"原始数据不存在");
  172. }
  173. String shareParamCodes = costNumberBedSetEditDto.getShareParamCode();
  174. Integer incomeFieldNums = costNumberBedSetEditDto.getIncomeFieldNum();
  175. CostNumberBedSet costNumberBedSetResponse = this.getOne(new QueryWrapper<CostNumberBedSet>().lambda().eq(CostNumberBedSet::getHospId, hospId)
  176. .eq(CostNumberBedSet::getShareParamCode, shareParamCodes)
  177. .eq(CostNumberBedSet::getIncomeFieldNum, incomeFieldNums));
  178. if (Objects.nonNull(costNumberBedSetResponse)){
  179. throw new CostException(500,"数据已经存在");
  180. }
  181. this.removeById(id);
  182. CostNumberBedSet costNumberBedSetRequest = BeanUtil.convertObj(costNumberBedSetEditDto, CostNumberBedSet.class);
  183. costNumberBedSetRequest.setHospId(hospId);
  184. costNumberBedSetRequest.setCreateTime(System.currentTimeMillis());
  185. costNumberBedSetRequest.setId(null);
  186. this.save(costNumberBedSetRequest);
  187. }
  188. /**
  189. * 获取当前诊次/床日设置里面关联的成本分摊参数
  190. *
  191. * @param id
  192. * @param hospId
  193. * @return
  194. */
  195. @Override
  196. public List<CheckShareParamStatusVO> checkStatus(Long id, Long hospId) {
  197. List<CostShareParam> costShareParamList = costShareParamService.list(new QueryWrapper<CostShareParam>().lambda()
  198. .eq(CostShareParam::getHospId, hospId));
  199. CostNumberBedSet costNumberBedSet = this.getById(id);
  200. String shareParamCode=null;
  201. if (Objects.nonNull(costNumberBedSet)){
  202. shareParamCode = costNumberBedSet.getShareParamCode();
  203. }
  204. List<CheckShareParamStatusVO> checkShareParamStatusVOList = BeanUtil.convertList(costShareParamList, CheckShareParamStatusVO.class);
  205. String finalShareParamCode = shareParamCode;
  206. checkShareParamStatusVOList.forEach(i->{
  207. String code = i.getShareParamCode();
  208. if (code.equals(finalShareParamCode)){
  209. i.setShareParamNumberBedSetStatus(NumberConstant.ONE);
  210. }
  211. });
  212. return checkShareParamStatusVOList;
  213. }
  214. /**
  215. * 获取报表 显示报表被选中的状态
  216. *
  217. * @param reportType 报表类型
  218. * @param hospId 医院Id
  219. * @param id
  220. * @return
  221. */
  222. @Override
  223. @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
  224. public List<ReportFormVO> getReportNumberBedStatus(Integer reportType, Long hospId, Integer id) {
  225. List<ReportForm> list = reportFormService.list(new QueryWrapper<ReportForm>().lambda()
  226. .eq(ReportForm::getReportType, reportType)
  227. .eq(ReportForm::getHospId, hospId)
  228. .orderByAsc(ReportForm::getSort));
  229. if (CollUtil.isEmpty(list)) {
  230. return Collections.emptyList();
  231. }
  232. List<ReportFormVO> reportFormVOS = list.stream().map(i -> {
  233. ReportFormVO reportFormVO = BeanUtil.convertObj(i, ReportFormVO.class);
  234. if (i.getCalcType() == 1) {
  235. reportFormVO.setShowAddRelation(1);
  236. } else if (i.getCalcType() == 2) {
  237. reportFormVO.setShowAddRelation(2);
  238. }
  239. return reportFormVO;
  240. }).collect(Collectors.toList());
  241. if (Objects.nonNull(id)){
  242. CostNumberBedSet costNumberBedSet = this.getById(id);
  243. if (Objects.nonNull(costNumberBedSet)){
  244. Integer incomeFieldNum = costNumberBedSet.getIncomeFieldNum();
  245. Integer costCorresponding = costNumberBedSet.getCostCorresponding();
  246. reportFormVOS.forEach(i->{
  247. if (incomeFieldNum.equals(i.getNum()) && NumberConstant.ZERO.equals(reportType)){
  248. i.setReportNumberSetStatus(NumberConstant.ONE);
  249. }else if (costCorresponding.equals(i.getNum()) && NumberConstant.THREE.equals(reportType)){
  250. i.setReportNumberSetStatus(NumberConstant.ONE);
  251. }
  252. });
  253. }
  254. }
  255. List<ReportFormVO> roots = reportFormVOS.stream().filter(i -> i.getParentId() == 0L).collect(Collectors.toList());
  256. for (ReportFormVO root : roots) {
  257. List<ReportFormVO> children = root.getChildren();
  258. if (CollUtil.isEmpty(children)) {
  259. children = new ArrayList<>();
  260. }
  261. for (ReportFormVO reportFormVO : reportFormVOS) {
  262. if (reportFormVO.getParentId().equals(root.getId())) {
  263. children.add(reportFormVO);
  264. // this.setRelation(reportFormVO, user.getHospId());
  265. }
  266. }
  267. root.setChildren(children);
  268. }
  269. return roots;
  270. }
  271. }