StandardReportServiceImpl.java 111 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279
  1. package com.kcim.service.impl;
  2. import com.kcim.common.constants.Constant;
  3. import com.kcim.common.constants.NumberConstant;
  4. import com.kcim.common.constants.ParameterConstant;
  5. import com.kcim.common.constants.SplitConstant;
  6. import com.kcim.common.exception.CostException;
  7. import com.kcim.common.util.BeanUtil;
  8. import com.kcim.common.util.ComputeDateUtils;
  9. import com.kcim.common.util.UserContext;
  10. import com.kcim.dao.model.*;
  11. import com.kcim.dao.repository.*;
  12. import com.kcim.service.AllocationQueryService;
  13. import com.kcim.service.CenterService;
  14. import com.kcim.service.IncomeCollectionService;
  15. import com.kcim.service.StandardReportService;
  16. import com.kcim.vo.*;
  17. import com.kcim.web.reponse.ComputeProfitCollectResponse;
  18. import lombok.AllArgsConstructor;
  19. import lombok.extern.slf4j.Slf4j;
  20. import org.springframework.stereotype.Service;
  21. import org.springframework.util.CollectionUtils;
  22. import org.springframework.util.ObjectUtils;
  23. import org.springframework.util.StringUtils;
  24. import java.lang.reflect.Field;
  25. import java.math.BigDecimal;
  26. import java.math.RoundingMode;
  27. import java.util.*;
  28. import java.util.stream.Collectors;
  29. /**
  30. * @program: CostAccount
  31. * @description:
  32. * @author: Wang.YS
  33. * @create: 2024-03-19 11:10
  34. **/
  35. @Service("StandardReportService")
  36. @Slf4j
  37. @AllArgsConstructor
  38. public class StandardReportServiceImpl implements StandardReportService {
  39. private static final String AMOUNT_FIELD = "amount";
  40. private static final String PERCENT_FIELD = "percent" ;
  41. ResponsibilityRepository responsibilityRepository;
  42. AllocationQueryService allocationQueryService;
  43. CenterService centerService;
  44. AccountingRepository accountingRepository;
  45. IncomeCollectionService incomeCollectionService;
  46. ShareParamValueRepository shareParamValueRepository;
  47. StandItemRepository standItemRepository;
  48. ItemRepository itemRepository;
  49. ComputeProjectCostAccountRepository computeProjectCostAccountRepository;
  50. ComputePatientCostAccountRepository computePatientCostAccountRepository;
  51. /**
  52. * 科室直接成本表(医疗成本)
  53. * @param computeDate 核算年月
  54. * @return
  55. */
  56. @Override
  57. public List<DeptDirectMedicalCostVO> getDeptDirectMedicalCost(String computeDate) {
  58. Integer year = ComputeDateUtils.getComputeYear(computeDate);
  59. Integer month = ComputeDateUtils.getComputeMonth(computeDate);
  60. //获取科室直接成本
  61. List<AllocationQuery> allocationQueryList = allocationQueryService.getCostByDate(UserContext.getCurrentLoginHospId(), year, month, NumberConstant.ONE);
  62. if(CollectionUtils.isEmpty(allocationQueryList)){
  63. return new ArrayList<>();
  64. }
  65. //获取所有的标准字典数据
  66. StandCostDictMapVO standCostDictMaps = getStandCostDictMaps();
  67. // 处理 allocationQueryList 数据
  68. Map<String ,DeptDirectMedicalCostVO> deptDirectMedicalCostMap = new HashMap<>();
  69. //转换为DeptDirectMedicalCostVO(一个责任中心只一条记录)
  70. for (AllocationQuery allocationQuery : allocationQueryList) {
  71. addDeptDirectMedicalCostVO(deptDirectMedicalCostMap,allocationQuery, standCostDictMaps);
  72. }
  73. // 转成List便于处理
  74. List<DeptDirectMedicalCostVO> deptDirectMedicalCostList = deptDirectMedicalCostMap.values().stream().collect(Collectors.toList());
  75. //创建医疗业务成本合计
  76. DeptDirectMedicalCostVO medicalBusinessTotal = createSubtotalVo(deptDirectMedicalCostList.get(NumberConstant.ZERO), "医疗业务成本合计", DeptDirectMedicalCostVO.class);
  77. //创建总计
  78. DeptDirectMedicalCostVO grandTotal = createSubtotalVo(deptDirectMedicalCostList.get(NumberConstant.ZERO), "总计", DeptDirectMedicalCostVO.class);
  79. //按responsibilitySort正序排序
  80. deptDirectMedicalCostList.sort(Comparator.comparing(DeptDirectMedicalCostVO::getResponsibilitySort,
  81. Comparator.nullsLast(Comparator.naturalOrder())));
  82. // 按标准分级分组
  83. Map<String, List<DeptDirectMedicalCostVO>> shareLevelGroup = deptDirectMedicalCostList.stream().collect(Collectors.groupingBy(DeptDirectMedicalCostVO::getStandardShareLevel));
  84. // 科室标准分级按顺序号倒序排序
  85. List<DictDataVo> standardShareLevelList = standCostDictMaps.getStandardShareLevelDict();
  86. standardShareLevelList.sort(Comparator.comparing(DictDataVo::getSort,Comparator.nullsLast(Comparator.reverseOrder())));
  87. // 创建各层级小计并按正确顺序插入
  88. List<DeptDirectMedicalCostVO> result = new ArrayList<>();
  89. for (DictDataVo shareLevel : standardShareLevelList) {
  90. List<DeptDirectMedicalCostVO> deptDirectMedicalCostVOS = shareLevelGroup.get(shareLevel.getCode());
  91. if(CollectionUtils.isEmpty(deptDirectMedicalCostVOS)){
  92. continue;
  93. }
  94. // 添加该分类下的所有记录
  95. result.addAll(deptDirectMedicalCostVOS);
  96. // 创建小计对象
  97. DeptDirectMedicalCostVO subtotalVo = createSubtotalVo(deptDirectMedicalCostVOS.get(NumberConstant.ZERO),String.format("%s小计", shareLevel.getName()), DeptDirectMedicalCostVO.class);
  98. //将科室的金额加到小计对象中
  99. deptDirectMedicalCostVOS.forEach(item -> addBigDecimalFields(item, subtotalVo));
  100. // 如果属于医疗业务成本的科室,则小计的金额加到医疗业务成本
  101. if(NumberConstant.ONE_S.equals(shareLevel.getValue())){
  102. addBigDecimalFields(subtotalVo, medicalBusinessTotal);
  103. }
  104. // 小计的金额加到总计
  105. addBigDecimalFields(subtotalVo, grandTotal);
  106. // 添加小计行
  107. result.add(subtotalVo);
  108. // 医疗业务成本加入到医疗辅助类小计后面
  109. if(NumberConstant.TWO_S.equals(shareLevel.getCode())){
  110. result.add(medicalBusinessTotal);
  111. }
  112. }
  113. // 总计加到列表最后面
  114. result.add(grandTotal);
  115. return result;
  116. }
  117. /**
  118. * 科室直接成本表(全成本)
  119. * @param computeDate 核算年月
  120. * @return 报表数据
  121. */
  122. @Override
  123. public List<DeptFullDirectCostVO> getDeptFullDirectCost(String computeDate) {
  124. Integer year = ComputeDateUtils.getComputeYear(computeDate);
  125. Integer month = ComputeDateUtils.getComputeMonth(computeDate);
  126. // 获取科室直接成本
  127. List<AllocationQuery> allocationQueryList = allocationQueryService.getCostByDate(UserContext.getCurrentLoginHospId(), year, month, NumberConstant.ONE);
  128. if (CollectionUtils.isEmpty(allocationQueryList)) {
  129. return new ArrayList<>();
  130. }
  131. // 获取所有的标准字典数据
  132. StandCostDictMapVO standCostDictMaps = getStandCostDictMaps();
  133. // 处理 allocationQueryList 数据
  134. Map<String, DeptFullDirectCostVO> reportMap = new HashMap<>();
  135. // 转换为DeptDirectAllCostVO(一个责任中心只一条记录)
  136. for (AllocationQuery allocationQuery : allocationQueryList) {
  137. addDeptDirectAllCostVO(reportMap, allocationQuery, standCostDictMaps);
  138. }
  139. // 转成List便于处理
  140. List<DeptFullDirectCostVO> reportList = reportMap.values().stream().collect(Collectors.toList());
  141. // 按responsibilitySort正序排序
  142. reportList.sort(Comparator.comparing(DeptFullDirectCostVO::getResponsibilitySort, Comparator.nullsLast(Comparator.naturalOrder())));
  143. // 按标准分级分组
  144. Map<String, List<DeptFullDirectCostVO>> shareLevelGroup = reportList.stream().collect(Collectors.groupingBy(DeptFullDirectCostVO::getStandardShareLevel));
  145. // 科室标准分级按顺序号倒序排序
  146. List<DictDataVo> standardShareLevelList = standCostDictMaps.getStandardShareLevelDict();
  147. standardShareLevelList.sort(Comparator.comparing(DictDataVo::getSort, Comparator.nullsLast(Comparator.reverseOrder())));
  148. //创建医疗业务成本合计
  149. DeptFullDirectCostVO medicalBusinessTotal = createSubtotalVo(reportList.get(NumberConstant.ZERO), "医疗业务成本合计", DeptFullDirectCostVO.class);
  150. //创建总计
  151. DeptFullDirectCostVO grandTotal = createSubtotalVo(reportList.get(NumberConstant.ZERO), "总计", DeptFullDirectCostVO.class);
  152. // 创建各层级小计并按正确顺序插入
  153. List<DeptFullDirectCostVO> result = new ArrayList<>();
  154. for (DictDataVo shareLevel : standardShareLevelList) {
  155. List<DeptFullDirectCostVO> reportVOS = shareLevelGroup.get(shareLevel.getCode());
  156. if (CollectionUtils.isEmpty(reportVOS)) {
  157. continue;
  158. }
  159. // 添加该分类下的所有记录
  160. result.addAll(reportVOS);
  161. // 创建小计对象
  162. DeptFullDirectCostVO subtotalVo = createSubtotalVo(reportVOS.get(NumberConstant.ZERO),String.format("%s小计", shareLevel.getName()), DeptFullDirectCostVO.class);
  163. //将科室的金额加到小计对象中
  164. reportVOS.forEach(item -> addBigDecimalFields(item, subtotalVo));
  165. // 如果属于医疗业务成本的科室,则小计的金额加到医疗业务成本
  166. if(NumberConstant.ONE_S.equals(shareLevel.getValue())){
  167. addBigDecimalFields(subtotalVo, medicalBusinessTotal);
  168. }
  169. // 小计的金额加到总计
  170. addBigDecimalFields(subtotalVo, grandTotal);
  171. // 添加小计行
  172. result.add(subtotalVo);
  173. // 医疗业务成本加入到医疗辅助类小计后面
  174. if(NumberConstant.TWO_S.equals(shareLevel.getCode())){
  175. result.add(medicalBusinessTotal);
  176. }
  177. }
  178. // 总计加到列表最后面
  179. result.add(grandTotal);
  180. return result;
  181. }
  182. /**
  183. * 获取科室成本明细数据
  184. * @param computeDate 核算年月
  185. * @return
  186. */
  187. @Override
  188. public List<ClinicalDeptMedicalCostVO> getClinicalDeptMedicalCost(String computeDate) {
  189. Integer year = ComputeDateUtils.getComputeYear(computeDate);
  190. Integer month = ComputeDateUtils.getComputeMonth(computeDate);
  191. // 获取科室直接成本
  192. List<AllocationQuery> allocationQueryList = allocationQueryService.getAllByDate(UserContext.getCurrentLoginHospId(), year, month);
  193. if (CollectionUtils.isEmpty(allocationQueryList)) {
  194. return new ArrayList<>();
  195. }
  196. // 获取所有的标准字典数据
  197. StandCostDictMapVO standCostDictMaps = getStandCostDictMaps();
  198. // 处理 allocationQueryList 数据
  199. Map<String, ClinicalDeptMedicalCostVO> reportMap = new HashMap<>();
  200. // 添加科室成本明细(一个责任中心只一条记录)
  201. for (AllocationQuery allocationQuery : allocationQueryList) {
  202. addDeptCostDetailVO(reportMap, allocationQuery, standCostDictMaps);
  203. }
  204. // 转成List便于处理
  205. List<ClinicalDeptMedicalCostVO> reportList = reportMap.values().stream().collect(Collectors.toList());
  206. // 创建合计对象
  207. ClinicalDeptMedicalCostVO subtotalVo = createSubtotalVo(reportList.get(NumberConstant.ZERO),"科室全成本合计",ClinicalDeptMedicalCostVO.class);
  208. //将科室的金额加到合计对象中
  209. reportList.forEach(item -> addBigDecimalFields(item, subtotalVo));
  210. // 合计加到列表最后面
  211. reportList.add(subtotalVo);
  212. return reportList;
  213. }
  214. /**
  215. * 获取临床服务类科室全成本报表数据
  216. * @param computeDate 核算年月
  217. * @return 报表数据
  218. */
  219. @Override
  220. public List<ClinicalDeptFullCostVO> getClinicalDeptFullCost(String computeDate) {
  221. Integer year = ComputeDateUtils.getComputeYear(computeDate);
  222. Integer month = ComputeDateUtils.getComputeMonth(computeDate);
  223. // 获取科室直接成本
  224. List<AllocationQuery> allocationQueryList = allocationQueryService.getAllByDate(UserContext.getCurrentLoginHospId(), year, month);
  225. if (CollectionUtils.isEmpty(allocationQueryList)) {
  226. return new ArrayList<>();
  227. }
  228. // 获取所有的标准字典数据
  229. StandCostDictMapVO standCostDictMaps = getStandCostDictMaps();
  230. // 处理 allocationQueryList 数据
  231. Map<String, ClinicalDeptFullCostVO> reportMap = new HashMap<>();
  232. // 转换为ClinicalDeptFullCostVO(一个责任中心只一条记录)
  233. for (AllocationQuery allocationQuery : allocationQueryList) {
  234. addClinicalDeptFullCostVO(reportMap, allocationQuery, standCostDictMaps);
  235. }
  236. // 转成List便于处理
  237. List<ClinicalDeptFullCostVO> reportList = reportMap.values().stream().collect(Collectors.toList());
  238. // 创建合计对象
  239. ClinicalDeptFullCostVO subtotalVo = createSubtotalVo(reportList.get(NumberConstant.ZERO), "科室全成本合计", ClinicalDeptFullCostVO.class);
  240. // 将科室的金额加到合计对象中
  241. reportList.forEach(item -> addBigDecimalFields(item, subtotalVo));
  242. // 合计加到列表最后面
  243. reportList.add(subtotalVo);
  244. return reportList;
  245. }
  246. /**
  247. * 获取医院临床服务类科室全成本构成分析表数据
  248. * @param computeDate 核算年月
  249. * @return 报表数据
  250. */
  251. @Override
  252. public ComputeProfitCollectResponse getClinicalDeptFullCostAnalysis(String computeDate) {
  253. Integer year = ComputeDateUtils.getComputeYear(computeDate);
  254. Integer month = ComputeDateUtils.getComputeMonth(computeDate);
  255. // 获取科室成本
  256. List<AllocationQuery> allocationQueryList = allocationQueryService.getAllByDate(UserContext.getCurrentLoginHospId(), year, month);
  257. if (CollectionUtils.isEmpty(allocationQueryList)) {
  258. throw new CostException("医院未分摊本月数据");
  259. }
  260. //获取科室收入
  261. List<IncomeCollection> responsibilityIncomeList = incomeCollectionService.getResponsibilitiesAccounts(year, month, UserContext.getCurrentLoginHospId());
  262. if (CollectionUtils.isEmpty(responsibilityIncomeList)) {
  263. throw new CostException("医院未归集本月收入数据");
  264. }
  265. Map<String, BigDecimal> responsibilityIncomeMap = responsibilityIncomeList.stream().collect(Collectors.toMap(IncomeCollection::getResponsibilityCode, IncomeCollection::getAmount));
  266. //获取分摊参数
  267. List<ShareParamValue> shareParamValueList = shareParamValueRepository.getList(computeDate);
  268. if (CollectionUtils.isEmpty(shareParamValueList)) {
  269. throw new CostException("未获取医院本月分摊参数数据");
  270. }
  271. Map<String, List<ShareParamValue>> responsibilityParamValueMap = shareParamValueList.stream().collect(Collectors.groupingBy(ShareParamValue::getResponsibilityCode));
  272. //获取诊次床日分摊参数代码
  273. String[] visitsBedDaysParamCode = getVisitsBedDaysParamCode();
  274. // 获取所有的标准字典数据
  275. StandCostDictMapVO standCostDictMaps = getStandCostDictMaps();
  276. // 处理 allocationQueryList 数据
  277. Map<String ,DeptDirectMedicalCostVO> deptDirectMedicalCostMap = new HashMap<>();
  278. //转换为DeptDirectMedicalCostVO(一个责任中心只一条记录)
  279. for (AllocationQuery allocationQuery : allocationQueryList) {
  280. addDeptDirectMedicalCostVO(deptDirectMedicalCostMap,allocationQuery, standCostDictMaps);
  281. }
  282. // 转成List便于处理
  283. List<DeptDirectMedicalCostVO> reportList = deptDirectMedicalCostMap.values().stream().collect(Collectors.toList());
  284. // 创建合计对象
  285. DeptDirectMedicalCostVO subtotalVo = createSubtotalVo(reportList.get(NumberConstant.ZERO), "科室合计", DeptDirectMedicalCostVO.class);
  286. subtotalVo.setResponsibilityCode("deptSubtotal");
  287. for (DeptDirectMedicalCostVO item : reportList) {
  288. //计算科室的收入及损益+床日成本及诊次成本
  289. calcDeptExpandCost(item, responsibilityIncomeMap, responsibilityParamValueMap, visitsBedDaysParamCode);
  290. // 将科室的金额加到合计对象中
  291. addBigDecimalFields(item, subtotalVo);
  292. }
  293. // 合计加到列表最后面
  294. reportList.add(subtotalVo);
  295. // 创建成本项目列表
  296. List<String> costItems = Arrays.asList(
  297. "人员经费", "卫生材料费", "药品费", "固定资产折旧费", "无形资产摊销费",
  298. "提取医疗风险基金", "其他医疗费用", "科室全成本合计","科室收入","收入-成本","床日成本","诊次成本"
  299. );
  300. //不要计算占比的项目列表
  301. List<String> noPercentCostItems = Arrays.asList(
  302. "科室收入","收入-成本","床日成本","诊次成本"
  303. );
  304. // 创建结果列表
  305. List<ReportFormCustomVo> resultData = new ArrayList<>();
  306. List<CommonResponsibilityReportVo> titleList = new ArrayList<>();
  307. // 提取科室名称作为列标题
  308. for (DeptDirectMedicalCostVO dept : reportList) {
  309. CommonResponsibilityReportVo title = new CommonResponsibilityReportVo();
  310. title.setResponsibilityName(dept.getResponsibilityName());
  311. title.setResponsibilityCode(dept.getResponsibilityCode());
  312. title.setSort(dept.getResponsibilitySort());
  313. //添加子级标题
  314. addCommonResponsibilityChild(title);
  315. titleList.add(title);
  316. }
  317. // 遍历每个成本项目(列转行)
  318. for (String costItem : costItems) {
  319. ReportFormCustomVo itemVo = new ReportFormCustomVo();
  320. itemVo.setReportName(costItem);
  321. itemVo.setData(new ArrayList<>());
  322. // 遍历每个科室
  323. for (DeptDirectMedicalCostVO dept : reportList) {
  324. //金额对象
  325. ReportVo amountReportVo = new ReportVo();
  326. amountReportVo.setCode(getResponsibilityAmountCode(dept.getResponsibilityCode()));
  327. //占比对象
  328. ReportVo percentReportVo = new ReportVo();
  329. percentReportVo.setCode(getResponsibilityPercentCode(dept.getResponsibilityCode()));
  330. //获取金额
  331. BigDecimal deptAmount = getDeptAmount(dept, costItem);
  332. // 设置金额和百分比
  333. amountReportVo.setValue(deptAmount);
  334. //要显示占比的字段才计算占比
  335. if(!noPercentCostItems.contains(costItem)){
  336. //计算百分比
  337. BigDecimal percent = getPercent(deptAmount, dept.getTotal());
  338. percentReportVo.setValue(percent);
  339. }
  340. // 添加金额和百分比
  341. itemVo.getData().add(amountReportVo);
  342. itemVo.getData().add(percentReportVo);
  343. }
  344. resultData.add(itemVo);
  345. }
  346. ComputeProfitCollectResponse response = new ComputeProfitCollectResponse();
  347. response.setTitle(titleList);
  348. response.setData(resultData);
  349. return response;
  350. }
  351. /**
  352. * 获取医院科室成本分摊汇总表数据
  353. * @param computeDate 核算年月
  354. * @return 报表数据
  355. */
  356. @Override
  357. public List<HospitalDeptCostAllocationVO> getHospitalDeptCostAllocation(String computeDate) {
  358. Integer year = ComputeDateUtils.getComputeYear(computeDate);
  359. Integer month = ComputeDateUtils.getComputeMonth(computeDate);
  360. // 获取科室成本
  361. List<AllocationQuery> allocationQueryList = allocationQueryService.getAllByDate(UserContext.getCurrentLoginHospId(), year, month);
  362. if (CollectionUtils.isEmpty(allocationQueryList)) {
  363. throw new CostException("医院未分摊本月数据");
  364. }
  365. // 获取所有的标准字典数据
  366. StandCostDictMapVO standCostDictMaps = getStandCostDictMaps();
  367. // 处理 allocationQueryList 数据
  368. Map<String, HospitalDeptCostAllocationVO> deptCostAllocationMap = new HashMap<>();
  369. // 转换为HospitalDeptCostAllocationVO(一个责任中心只一条记录)
  370. for (AllocationQuery allocationQuery : allocationQueryList) {
  371. addHospitalDeptCostAllocationVO(deptCostAllocationMap, allocationQuery, standCostDictMaps);
  372. }
  373. // 转成List便于处理
  374. List<HospitalDeptCostAllocationVO> reportList = new ArrayList<>(deptCostAllocationMap.values());
  375. //创建总计
  376. HospitalDeptCostAllocationVO grandTotal = createSubtotalVo(reportList.get(NumberConstant.ZERO), "总计", HospitalDeptCostAllocationVO.class);
  377. // 按responsibilitySort正序排序
  378. reportList.sort(Comparator.comparing(HospitalDeptCostAllocationVO::getResponsibilitySort,
  379. Comparator.nullsLast(Comparator.naturalOrder())));
  380. // 按标准分级分组
  381. Map<String, List<HospitalDeptCostAllocationVO>> shareLevelGroup = reportList.stream()
  382. .collect(Collectors.groupingBy(HospitalDeptCostAllocationVO::getStandardShareLevel));
  383. // 科室标准分级按顺序号倒序排序
  384. List<DictDataVo> standardShareLevelList = standCostDictMaps.getStandardShareLevelDict();
  385. standardShareLevelList.sort(Comparator.comparing(DictDataVo::getSort, Comparator.nullsLast(Comparator.reverseOrder())));
  386. // 创建各层级小计并按正确顺序插入
  387. List<HospitalDeptCostAllocationVO> result = new ArrayList<>();
  388. for (DictDataVo shareLevel : standardShareLevelList) {
  389. List<HospitalDeptCostAllocationVO> deptCostAllocationVOS = shareLevelGroup.get(shareLevel.getCode());
  390. if (CollectionUtils.isEmpty(deptCostAllocationVOS)) {
  391. continue;
  392. }
  393. // 添加该分类下的所有记录
  394. result.addAll(deptCostAllocationVOS);
  395. // 创建小计对象
  396. HospitalDeptCostAllocationVO subtotalVo = createSubtotalVo(deptCostAllocationVOS.get(NumberConstant.ZERO), String.format("%s小计", shareLevel.getName()), HospitalDeptCostAllocationVO.class);
  397. //将科室的金额加到小计对象中
  398. deptCostAllocationVOS.forEach(item -> addBigDecimalFields(item, subtotalVo));
  399. // 小计的金额加到总计
  400. addBigDecimalFields(subtotalVo, grandTotal);
  401. // 添加小计行
  402. result.add(subtotalVo);
  403. }
  404. // 总计加到列表最后面
  405. result.add(grandTotal);
  406. return result;
  407. }
  408. /**
  409. * 获取医院诊次成本构成表数据
  410. * @param computeDate 核算年月
  411. * @return 报表数据
  412. */
  413. @Override
  414. public List<HospitalVisitCostCompositionVO> getHospitalVisitCostComposition(String computeDate) {
  415. Integer year = ComputeDateUtils.getComputeYear(computeDate);
  416. Integer month = ComputeDateUtils.getComputeMonth(computeDate);
  417. // 获取科室成本
  418. List<AllocationQuery> allocationQueryList = allocationQueryService.getAcountAccounts(UserContext.getCurrentLoginHospId(), year, month);
  419. if (CollectionUtils.isEmpty(allocationQueryList)) {
  420. throw new CostException("医院未分摊本月数据");
  421. }
  422. //获取分摊参数
  423. List<ShareParamValue> shareParamValueList = shareParamValueRepository.getList(computeDate);
  424. if (CollectionUtils.isEmpty(shareParamValueList)) {
  425. throw new CostException("未获取医院本月分摊参数数据");
  426. }
  427. // 获取所有的标准字典数据
  428. StandCostDictMapVO standCostDictMaps = getStandCostDictMaps();
  429. //获取成本会计科目字典
  430. List<DictDataVo> accountingTypeDict = standCostDictMaps.getAccountingTypeDict();
  431. List<DictDataVo> costAccountingTypeDict = accountingTypeDict.stream().filter(dictDataVo -> NumberConstant.TWO_S.equals(dictDataVo.getValue())).collect(Collectors.toList());
  432. // 初始化成本项目映射
  433. Map<String, HospitalVisitCostCompositionVO> costItemMap =createHospitalVisitCostCompositionVO(costAccountingTypeDict);
  434. // 处理分配查询数据
  435. for (AllocationQuery allocationQuery : allocationQueryList) {
  436. String accountingCode = allocationQuery.getAccountingCode();
  437. Accounting account = standCostDictMaps.getAccountingMap().get(accountingCode);
  438. if (account == null) {
  439. continue;
  440. }
  441. DictDataVo costType = standCostDictMaps.getCostTypeMap().get(String.valueOf(account.getCostType()));
  442. HospitalVisitCostCompositionVO vo = costItemMap.get(account.getType());
  443. // 医疗成本
  444. if ("1".equals(costType.getExpandOne())) {
  445. vo.setMedicalCost(vo.getMedicalCost().add(allocationQuery.getAmount()));
  446. }
  447. // 医疗全成本
  448. if (!"3".equals(costType.getExpandOne())) {
  449. vo.setMedicalFullCost(vo.getMedicalFullCost().add(allocationQuery.getAmount()));
  450. }
  451. // 医院全成本
  452. vo.setHospitalFullCost(vo.getHospitalFullCost().add(allocationQuery.getAmount()));
  453. }
  454. //获取诊次床日分摊参数代码
  455. String[] visitsBedDaysParamCode = getVisitsBedDaysParamCode();
  456. // 诊次分摊参数值
  457. BigDecimal visitParamValue = getParamValue(shareParamValueList, visitsBedDaysParamCode[NumberConstant.ZERO]);
  458. // // 床日分摊参数值
  459. // BigDecimal bedDaysParamValue = getParamValue(shareParamValueList, visitsBedDaysParamCode[NumberConstant.ONE]);
  460. //处理总计和药品小计
  461. HospitalVisitCostCompositionVO totalVo = new HospitalVisitCostCompositionVO();
  462. totalVo.setCostItem("总计");
  463. HospitalVisitCostCompositionVO drugTotalVo = new HospitalVisitCostCompositionVO();
  464. drugTotalVo.setCostItem("药品费");
  465. drugTotalVo.setChildren(new ArrayList<>());
  466. // 转成List便于处理
  467. List<HospitalVisitCostCompositionVO> reportList = costItemMap.values().stream().collect(Collectors.toList());
  468. for (HospitalVisitCostCompositionVO item : reportList) {
  469. //计算每诊次的医疗成本
  470. item.setMedicalCost(getPercent(item.getMedicalCost(),visitParamValue));
  471. //计算每诊次的医疗全成本
  472. item.setMedicalFullCost(getPercent(item.getMedicalFullCost(),visitParamValue));
  473. //计算每诊次的医院全成本
  474. item.setHospitalFullCost(getPercent(item.getHospitalFullCost(),visitParamValue));
  475. // 将金额加到总计对象中
  476. addBigDecimalFields(item, totalVo);
  477. /// 将金额加到药品对象中
  478. if(NumberConstant.THREE_S.equals(item.getCostType())){
  479. addBigDecimalFields(item, drugTotalVo);
  480. drugTotalVo.getChildren().add(item);
  481. }
  482. }
  483. drugTotalVo.getChildren().forEach(item -> reportList.remove(item));
  484. //添加到列表的指定位置
  485. reportList.add(NumberConstant.TWO,drugTotalVo);
  486. reportList.add(NumberConstant.ZERO,totalVo);
  487. return reportList;
  488. }
  489. /**
  490. * 获取医院科室诊次成本表数据
  491. * @param computeDate 核算年月
  492. * @return 报表数据
  493. */
  494. @Override
  495. public List<HospitalVisitCostCompositionVO> getHospitalDeptVisitCost(String computeDate) {
  496. Integer year = ComputeDateUtils.getComputeYear(computeDate);
  497. Integer month = ComputeDateUtils.getComputeMonth(computeDate);
  498. // 获取科室成本
  499. List<AllocationQuery> allocationQueryList = allocationQueryService.getRespAcountAccounts(UserContext.getCurrentLoginHospId(), year, month);
  500. if (CollectionUtils.isEmpty(allocationQueryList)) {
  501. throw new CostException("医院未分摊本月数据");
  502. }
  503. // 获取所有的标准字典数据
  504. StandCostDictMapVO standCostDictMaps = getStandCostDictMaps();
  505. // 获取分摊参数
  506. List<ShareParamValue> shareParamValueList = shareParamValueRepository.getList(computeDate);
  507. if (CollectionUtils.isEmpty(shareParamValueList)) {
  508. throw new CostException("未获取医院本月分摊参数数据");
  509. }
  510. // 获取诊次床日分摊参数代码
  511. String[] visitsBedDaysParamCode = getVisitsBedDaysParamCode();
  512. BigDecimal visitParamValue = getParamValue(shareParamValueList, visitsBedDaysParamCode[NumberConstant.ZERO]);
  513. Map<String, List<ShareParamValue>> respParamValueList = shareParamValueList.stream()
  514. .collect(Collectors.groupingBy(item -> item.getResponsibilityCode()));
  515. // 处理 allocationQueryList 数据
  516. Map<String, HospitalVisitCostCompositionVO> deptVisitCostMap = new HashMap<>();
  517. for (AllocationQuery allocationQuery : allocationQueryList) {
  518. String responsibilityCode = allocationQuery.getResponsibilityCode();
  519. Responsibility responsibility = standCostDictMaps.getResponsibilityMap().get(responsibilityCode);
  520. if (responsibility == null) {
  521. continue;
  522. }
  523. String accountingCode = allocationQuery.getAccountingCode();
  524. Accounting account = standCostDictMaps.getAccountingMap().get(accountingCode);
  525. if (account == null) {
  526. continue;
  527. }
  528. //只处理临床科室
  529. if(NumberConstant.FOUR.equals(responsibility.getStandardShareLevel())){
  530. continue;
  531. }
  532. HospitalVisitCostCompositionVO vo = new HospitalVisitCostCompositionVO();
  533. if (deptVisitCostMap.containsKey(responsibilityCode)) {
  534. vo = deptVisitCostMap.get(responsibilityCode);
  535. } else {
  536. // 初始化科室信息
  537. vo.setResponsibilityCode(responsibility.getResponsibilityCode());
  538. vo.setResponsibilityName(responsibility.getResponsibilityName());
  539. vo.setResponsibilitySort(responsibility.getSort());
  540. // 初始化所有费用字段为0
  541. BeanUtil.initBigDecimalFieldsToZero(vo);
  542. deptVisitCostMap.put(responsibilityCode, vo);
  543. }
  544. DictDataVo costType = standCostDictMaps.getCostTypeMap().get(String.valueOf(account.getCostType()));
  545. // 医疗成本
  546. if ("1".equals(costType.getExpandOne())) {
  547. vo.setMedicalCost(vo.getMedicalCost().add(allocationQuery.getAmount()));
  548. }
  549. // 医疗全成本
  550. if (!"3".equals(costType.getExpandOne())) {
  551. vo.setMedicalFullCost(vo.getMedicalFullCost().add(allocationQuery.getAmount()));
  552. }
  553. // 医院全成本
  554. vo.setHospitalFullCost(vo.getHospitalFullCost().add(allocationQuery.getAmount()));
  555. }
  556. // 转成List便于处理
  557. List<HospitalVisitCostCompositionVO> reportList = new ArrayList<>(deptVisitCostMap.values());
  558. // 创建总计对象
  559. HospitalVisitCostCompositionVO grandTotal = createSubtotalVo(reportList.get(NumberConstant.ZERO), "总计", HospitalVisitCostCompositionVO.class);
  560. // 计算每诊次成本
  561. for (HospitalVisitCostCompositionVO item : reportList) {
  562. List<ShareParamValue> respShareParamValues = respParamValueList.get(item.getResponsibilityCode());
  563. if(CollectionUtils.isEmpty(respShareParamValues)){
  564. item.setServiceCount(BigDecimal.ZERO);
  565. item.setMedicalCost(BigDecimal.ZERO);
  566. item.setMedicalFullCost(BigDecimal.ZERO);
  567. item.setHospitalFullCost(BigDecimal.ZERO);
  568. continue;
  569. }
  570. BigDecimal respParamValue = getParamValue(respShareParamValues, visitsBedDaysParamCode[NumberConstant.ZERO]);
  571. item.setServiceCount(respParamValue);
  572. //计算每诊次的医疗成本
  573. item.setMedicalCost(getPercent(item.getMedicalCost(),respParamValue));
  574. //计算每诊次的医疗全成本
  575. item.setMedicalFullCost(getPercent(item.getMedicalFullCost(),respParamValue));
  576. //计算每诊次的医院全成本
  577. item.setHospitalFullCost(getPercent(item.getHospitalFullCost(),respParamValue));
  578. // 将各科室金额累加到总计对象
  579. addBigDecimalFields(item, grandTotal);
  580. }
  581. // 按responsibilitySort正序排序
  582. reportList.sort(Comparator.comparing(HospitalVisitCostCompositionVO::getResponsibilitySort,
  583. Comparator.nullsLast(Comparator.naturalOrder())));
  584. // 添加总计行
  585. // reportList.add(NumberConstant.ZERO,grandTotal);
  586. return reportList;
  587. }
  588. /**
  589. * 获取医院床日成本构成表数据
  590. * @param computeDate 核算年月
  591. * @return 报表数据
  592. */
  593. @Override
  594. public List<HospitalVisitCostCompositionVO> getHospitalBedDayCostComposition(String computeDate) {
  595. Integer year = ComputeDateUtils.getComputeYear(computeDate);
  596. Integer month = ComputeDateUtils.getComputeMonth(computeDate);
  597. // 获取科室成本
  598. List<AllocationQuery> allocationQueryList = allocationQueryService.getAcountAccounts(UserContext.getCurrentLoginHospId(), year, month);
  599. if (CollectionUtils.isEmpty(allocationQueryList)) {
  600. throw new CostException("医院未分摊本月数据");
  601. }
  602. //获取分摊参数
  603. List<ShareParamValue> shareParamValueList = shareParamValueRepository.getList(computeDate);
  604. if (CollectionUtils.isEmpty(shareParamValueList)) {
  605. throw new CostException("未获取医院本月分摊参数数据");
  606. }
  607. // 获取所有的标准字典数据
  608. StandCostDictMapVO standCostDictMaps = getStandCostDictMaps();
  609. //获取成本会计科目字典
  610. List<DictDataVo> accountingTypeDict = standCostDictMaps.getAccountingTypeDict();
  611. List<DictDataVo> costAccountingTypeDict = accountingTypeDict.stream().filter(dictDataVo -> NumberConstant.TWO_S.equals(dictDataVo.getValue())).collect(Collectors.toList());
  612. // 初始化成本项目映射
  613. Map<String, HospitalVisitCostCompositionVO> costItemMap =createHospitalVisitCostCompositionVO(costAccountingTypeDict);
  614. // 处理分配查询数据
  615. for (AllocationQuery allocationQuery : allocationQueryList) {
  616. String accountingCode = allocationQuery.getAccountingCode();
  617. Accounting account = standCostDictMaps.getAccountingMap().get(accountingCode);
  618. if (account == null) {
  619. continue;
  620. }
  621. DictDataVo costType = standCostDictMaps.getCostTypeMap().get(String.valueOf(account.getCostType()));
  622. HospitalVisitCostCompositionVO vo = costItemMap.get(account.getType());
  623. // 医疗成本
  624. if ("1".equals(costType.getExpandOne())) {
  625. vo.setMedicalCost(vo.getMedicalCost().add(allocationQuery.getAmount()));
  626. }
  627. // 医疗全成本
  628. if (!"3".equals(costType.getExpandOne())) {
  629. vo.setMedicalFullCost(vo.getMedicalFullCost().add(allocationQuery.getAmount()));
  630. }
  631. // 医院全成本
  632. vo.setHospitalFullCost(vo.getHospitalFullCost().add(allocationQuery.getAmount()));
  633. }
  634. //获取诊次床日分摊参数代码
  635. String[] visitsBedDaysParamCode = getVisitsBedDaysParamCode();
  636. // 床日分摊参数值
  637. BigDecimal bedDaysParamValue = getParamValue(shareParamValueList, visitsBedDaysParamCode[NumberConstant.ONE]);
  638. //处理总计和药品小计
  639. HospitalVisitCostCompositionVO totalVo = new HospitalVisitCostCompositionVO();
  640. totalVo.setCostItem("总计");
  641. HospitalVisitCostCompositionVO drugTotalVo = new HospitalVisitCostCompositionVO();
  642. drugTotalVo.setCostItem("药品费");
  643. drugTotalVo.setChildren(new ArrayList<>());
  644. // 转成List便于处理
  645. List<HospitalVisitCostCompositionVO> reportList = costItemMap.values().stream().collect(Collectors.toList());
  646. for (HospitalVisitCostCompositionVO item : reportList) {
  647. //计算每诊次的医疗成本
  648. item.setMedicalCost(getPercent(item.getMedicalCost(),bedDaysParamValue));
  649. //计算每诊次的医疗全成本
  650. item.setMedicalFullCost(getPercent(item.getMedicalFullCost(),bedDaysParamValue));
  651. //计算每诊次的医院全成本
  652. item.setHospitalFullCost(getPercent(item.getHospitalFullCost(),bedDaysParamValue));
  653. // 将金额加到总计对象中
  654. addBigDecimalFields(item, totalVo);
  655. /// 将金额加到药品对象中
  656. if(NumberConstant.THREE_S.equals(item.getCostType())){
  657. addBigDecimalFields(item, drugTotalVo);
  658. drugTotalVo.getChildren().add(item);
  659. }
  660. }
  661. //移除掉药品费(避免重复)
  662. drugTotalVo.getChildren().forEach(item -> reportList.remove(item));
  663. //添加到列表的指定位置
  664. reportList.add(NumberConstant.TWO,drugTotalVo);
  665. reportList.add(NumberConstant.ZERO,totalVo);
  666. return reportList;
  667. }
  668. /**
  669. * 获取医院科室床日成本表数据
  670. * @param computeDate 核算年月
  671. * @return 报表数据
  672. */
  673. @Override
  674. public List<HospitalVisitCostCompositionVO> getHospitalDeptBedDayCost(String computeDate) {
  675. Integer year = ComputeDateUtils.getComputeYear(computeDate);
  676. Integer month = ComputeDateUtils.getComputeMonth(computeDate);
  677. // 获取科室成本
  678. List<AllocationQuery> allocationQueryList = allocationQueryService.getRespAcountAccounts(UserContext.getCurrentLoginHospId(), year, month);
  679. if (CollectionUtils.isEmpty(allocationQueryList)) {
  680. throw new CostException("医院未分摊本月数据");
  681. }
  682. // 获取所有的标准字典数据
  683. StandCostDictMapVO standCostDictMaps = getStandCostDictMaps();
  684. // 获取分摊参数
  685. List<ShareParamValue> shareParamValueList = shareParamValueRepository.getList(computeDate);
  686. if (CollectionUtils.isEmpty(shareParamValueList)) {
  687. throw new CostException("未获取医院本月分摊参数数据");
  688. }
  689. // 处理 allocationQueryList 数据
  690. Map<String, HospitalVisitCostCompositionVO> deptVisitCostMap = new HashMap<>();
  691. for (AllocationQuery allocationQuery : allocationQueryList) {
  692. String responsibilityCode = allocationQuery.getResponsibilityCode();
  693. Responsibility responsibility = standCostDictMaps.getResponsibilityMap().get(responsibilityCode);
  694. if (responsibility == null) {
  695. continue;
  696. }
  697. String accountingCode = allocationQuery.getAccountingCode();
  698. Accounting account = standCostDictMaps.getAccountingMap().get(accountingCode);
  699. if (account == null) {
  700. continue;
  701. }
  702. //只处理临床科室
  703. if(NumberConstant.FOUR.equals(responsibility.getStandardShareLevel())){
  704. continue;
  705. }
  706. HospitalVisitCostCompositionVO vo = new HospitalVisitCostCompositionVO();
  707. if (deptVisitCostMap.containsKey(responsibilityCode)) {
  708. vo = deptVisitCostMap.get(responsibilityCode);
  709. } else {
  710. // 初始化科室信息
  711. vo.setResponsibilityCode(responsibility.getResponsibilityCode());
  712. vo.setResponsibilityName(responsibility.getResponsibilityName());
  713. vo.setResponsibilitySort(responsibility.getSort());
  714. // 初始化所有费用字段为0
  715. BeanUtil.initBigDecimalFieldsToZero(vo);
  716. deptVisitCostMap.put(responsibilityCode, vo);
  717. }
  718. DictDataVo costType = standCostDictMaps.getCostTypeMap().get(String.valueOf(account.getCostType()));
  719. // 医疗成本
  720. if ("1".equals(costType.getExpandOne())) {
  721. vo.setMedicalCost(vo.getMedicalCost().add(allocationQuery.getAmount()));
  722. }
  723. // 医疗全成本
  724. if (!"3".equals(costType.getExpandOne())) {
  725. vo.setMedicalFullCost(vo.getMedicalFullCost().add(allocationQuery.getAmount()));
  726. }
  727. // 医院全成本
  728. vo.setHospitalFullCost(vo.getHospitalFullCost().add(allocationQuery.getAmount()));
  729. }
  730. // 转成List便于处理
  731. List<HospitalVisitCostCompositionVO> reportList = new ArrayList<>(deptVisitCostMap.values());
  732. // 获取诊次床日分摊参数代码
  733. String[] visitsBedDaysParamCode = getVisitsBedDaysParamCode();
  734. BigDecimal bedDaysParamValue = getParamValue(shareParamValueList, visitsBedDaysParamCode[NumberConstant.ONE]);
  735. Map<String, List<ShareParamValue>> respParamValueList = shareParamValueList.stream()
  736. .collect(Collectors.groupingBy(item -> item.getResponsibilityCode()));
  737. // 创建总计对象
  738. HospitalVisitCostCompositionVO grandTotal = createSubtotalVo(reportList.get(NumberConstant.ZERO), "总计", HospitalVisitCostCompositionVO.class);
  739. // 计算每诊次成本
  740. for (HospitalVisitCostCompositionVO item : reportList) {
  741. List<ShareParamValue> respShareParamValues = respParamValueList.get(item.getResponsibilityCode());
  742. if(CollectionUtils.isEmpty(respShareParamValues)){
  743. item.setServiceCount(BigDecimal.ZERO);
  744. item.setMedicalCost(BigDecimal.ZERO);
  745. item.setMedicalFullCost(BigDecimal.ZERO);
  746. item.setHospitalFullCost(BigDecimal.ZERO);
  747. continue;
  748. }
  749. BigDecimal respParamValue = getParamValue(respShareParamValues, visitsBedDaysParamCode[NumberConstant.ZERO]);
  750. item.setServiceCount(respParamValue);
  751. //计算每诊次的医疗成本
  752. item.setMedicalCost(getPercent(item.getMedicalCost(),bedDaysParamValue));
  753. //计算每诊次的医疗全成本
  754. item.setMedicalFullCost(getPercent(item.getMedicalFullCost(),bedDaysParamValue));
  755. //计算每诊次的医院全成本
  756. item.setHospitalFullCost(getPercent(item.getHospitalFullCost(),bedDaysParamValue));
  757. // 将各科室金额累加到总计对象
  758. addBigDecimalFields(item, grandTotal);
  759. }
  760. // 按responsibilitySort正序排序
  761. reportList.sort(Comparator.comparing(HospitalVisitCostCompositionVO::getResponsibilitySort,
  762. Comparator.nullsLast(Comparator.naturalOrder())));
  763. // 添加总计行
  764. reportList.add(NumberConstant.ZERO,grandTotal);
  765. return reportList;
  766. }
  767. /**
  768. * 获取医院医疗服务项目成本汇总表数据
  769. * @param computeDate 核算年月
  770. * @return 报表数据
  771. */
  772. @Override
  773. public List<HospitalServiceProjectCostVO> getHospitalServiceProjectCost(String computeDate) {
  774. List<StandItem> standItemList = standItemRepository.getList();
  775. if(CollectionUtils.isEmpty(standItemList)){
  776. throw new CostException("标准医疗服务项目未维护,请先添加标准医疗服务项目");
  777. }
  778. List<Item> itemList = itemRepository.getList();
  779. if(CollectionUtils.isEmpty(itemList)){
  780. throw new CostException("医疗服务项目未维护,请先添加医疗服务项目");
  781. }
  782. List<ComputeProjectCostAccount> projectCostAccountList = computeProjectCostAccountRepository.getList(computeDate);
  783. if(CollectionUtils.isEmpty(projectCostAccountList)){
  784. throw new CostException("请先计算项目成本");
  785. }
  786. List<Map<String, StandItem>> standItemMapDict = getStandItemMapDict(standItemList);
  787. // 记录项目类别对象
  788. Map<String, HospitalServiceProjectCostVO> projectCostMap = new HashMap<>();
  789. for (ComputeProjectCostAccount projectCostAccount : projectCostAccountList) {
  790. // 获取项目归属的项目类型
  791. StandItem projectItemType = getProjectItemType(projectCostAccount.getStandItemCode(),standItemMapDict);
  792. if(ObjectUtils.isEmpty(projectItemType)){
  793. continue;
  794. }
  795. //按项目类型累加数据
  796. String costType = projectCostAccount.getCostType();
  797. HospitalServiceProjectCostVO vo ;
  798. //已有的项目类别
  799. if (projectCostMap.containsKey(projectItemType.getCode())) {
  800. vo = projectCostMap.get(projectItemType.getCode());
  801. } else {
  802. //新建一个项目类别对象
  803. vo = convertToHospitalServiceProjectCostVO(projectItemType);
  804. projectCostMap.put(projectItemType.getCode(), vo);
  805. }
  806. //没有数据时跳过
  807. if(ObjectUtils.isEmpty(projectCostAccount.getComputeResult())){
  808. continue;
  809. }
  810. // 医疗成本
  811. if ("1".equals(costType)) {
  812. vo.setMedicalCost(vo.getMedicalCost().add(projectCostAccount.getComputeResult()));
  813. }
  814. // 医疗全成本
  815. if (!"3".equals(costType)) {
  816. vo.setMedicalFullCost(vo.getMedicalFullCost().add(projectCostAccount.getComputeResult()));
  817. }
  818. // 医院全成本
  819. vo.setHospitalFullCost(vo.getHospitalFullCost().add(projectCostAccount.getComputeResult()));
  820. }
  821. // 创建项目类别对象并组装层级
  822. List<HospitalServiceProjectCostVO> reportList = createProjectCategory(standItemMapDict,projectCostMap);
  823. return reportList;
  824. }
  825. /**
  826. * 获取医院医疗服务项目成本明细表数据
  827. *
  828. * @return 医疗服务项目成本明细列表
  829. */
  830. @Override
  831. public List<HospitalServiceProjectCostVO> getMedicalServiceCostDetail(String computeDate) {
  832. List<HospitalServiceProjectCostVO> projectCostAccountList = computeProjectCostAccountRepository.getMedicalServiceCostDetailList(computeDate);
  833. if(CollectionUtils.isEmpty(projectCostAccountList)){
  834. throw new CostException("请先计算项目成本");
  835. }
  836. // 记录项目类别对象
  837. Map<String, HospitalServiceProjectCostVO> projectCostMap = new HashMap<>();
  838. for (HospitalServiceProjectCostVO projectCostAccount : projectCostAccountList) {
  839. //按项目类型累加数据
  840. String costType = projectCostAccount.getCostTypeCode();
  841. HospitalServiceProjectCostVO vo = new HospitalServiceProjectCostVO();
  842. //已有的项目类别
  843. if (projectCostMap.containsKey(projectCostAccount.getItemCode())) {
  844. vo = projectCostMap.get(projectCostAccount.getItemCode());
  845. } else {
  846. //新建一个项目类别对象
  847. vo = BeanUtil.convertObj(projectCostAccount, HospitalServiceProjectCostVO.class) ;
  848. // 初始化所有费用字段为0
  849. BeanUtil.initBigDecimalFieldsToZero(vo);
  850. projectCostMap.put(projectCostAccount.getItemCode(), vo);
  851. }
  852. //没有数据时跳过
  853. if(ObjectUtils.isEmpty(projectCostAccount.getHospitalFullCost())){
  854. continue;
  855. }
  856. // 医疗成本
  857. if ("1".equals(costType)) {
  858. vo.setMedicalCost(vo.getMedicalCost().add(projectCostAccount.getHospitalFullCost()));
  859. }
  860. // 医疗全成本
  861. if (!"3".equals(costType)) {
  862. vo.setMedicalFullCost(vo.getMedicalFullCost().add(projectCostAccount.getHospitalFullCost()));
  863. }
  864. // 医院全成本
  865. vo.setHospitalFullCost(vo.getHospitalFullCost().add(projectCostAccount.getHospitalFullCost()));
  866. //服务量
  867. if(!ObjectUtils.isEmpty(projectCostAccount.getServiceVolume())){
  868. vo.setServiceVolume(projectCostAccount.getServiceVolume());
  869. }
  870. }
  871. List<HospitalServiceProjectCostVO> medServiceCostDetailList =new ArrayList<>(projectCostMap.values());
  872. // 计算每项目成本
  873. for (HospitalServiceProjectCostVO item : medServiceCostDetailList) {
  874. BigDecimal serviceVolume = item.getServiceVolume();
  875. if(ObjectUtils.isEmpty(serviceVolume)){
  876. item.setMedicalCost(BigDecimal.ZERO);
  877. item.setMedicalFullCost(BigDecimal.ZERO);
  878. item.setHospitalFullCost(BigDecimal.ZERO);
  879. continue;
  880. }
  881. //计算每项目的医疗成本
  882. item.setMedicalCost(getPercent(item.getMedicalCost(),serviceVolume));
  883. //计算每项目的医疗全成本
  884. item.setMedicalFullCost(getPercent(item.getMedicalFullCost(),serviceVolume));
  885. //计算每项目的医院全成本
  886. item.setHospitalFullCost(getPercent(item.getHospitalFullCost(),serviceVolume));
  887. }
  888. return medServiceCostDetailList;
  889. }
  890. /**
  891. * 获取医院病种成本明细表数据
  892. *
  893. * @return 病种成本明细列表
  894. */
  895. @Override
  896. public List<DiseaseCostDetailVO> getDiseaseCostDetail(String computeDate) {
  897. List<DiseaseCostDetailVO> projectCostAccountList = computePatientCostAccountRepository.getDiseaseCostDetailList(computeDate);
  898. if(CollectionUtils.isEmpty(projectCostAccountList)){
  899. throw new CostException("请先计算患者成本");
  900. }
  901. // 获取所有的标准字典数据
  902. StandCostDictMapVO standCostDictMaps = getStandCostDictMaps();
  903. // 记录项目类别对象
  904. Map<String, DiseaseCostDetailVO> diseaseCostMap = new HashMap<>();
  905. for (DiseaseCostDetailVO projectCostAccount : projectCostAccountList) {
  906. //按项目类型累加数据
  907. DictDataVo costType = standCostDictMaps.getCostTypeMap().get(projectCostAccount.getCostTypeCode());
  908. DiseaseCostDetailVO vo = new DiseaseCostDetailVO();
  909. //已有的项目类别
  910. if (diseaseCostMap.containsKey(projectCostAccount.getItemCode())) {
  911. vo = diseaseCostMap.get(projectCostAccount.getItemCode());
  912. } else {
  913. vo= BeanUtil.convertObj(projectCostAccount, DiseaseCostDetailVO.class) ;
  914. BeanUtil.initBigDecimalFieldsToZero(vo);
  915. //新建一个项目类别对象
  916. diseaseCostMap.put(projectCostAccount.getItemCode(), vo);
  917. }
  918. //没有数据时跳过
  919. if(ObjectUtils.isEmpty(projectCostAccount.getHospitalFullCost())){
  920. continue;
  921. }
  922. // 医疗成本
  923. if ("1".equals(costType.getExpandOne())) {
  924. vo.setMedicalCost(vo.getMedicalCost().add(projectCostAccount.getHospitalFullCost()));
  925. }
  926. // 医疗全成本
  927. if (!"3".equals(costType.getExpandOne())) {
  928. vo.setMedicalFullCost(vo.getMedicalFullCost().add(projectCostAccount.getHospitalFullCost()));
  929. }
  930. // 医院全成本
  931. vo.setHospitalFullCost(vo.getHospitalFullCost().add(projectCostAccount.getHospitalFullCost()));
  932. if(!ObjectUtils.isEmpty(projectCostAccount.getServiceVolume())){
  933. // 服务量
  934. vo.setServiceVolume(projectCostAccount.getServiceVolume());
  935. }
  936. }
  937. List<DiseaseCostDetailVO> medServiceCostDetailList =new ArrayList<>(diseaseCostMap.values());
  938. try {
  939. //计算单个病种的成本
  940. medServiceCostDetailList.forEach(vo -> {
  941. vo.setMedicalCost(getPercent(vo.getServiceVolume(),vo.getMedicalCost()));
  942. vo.setMedicalFullCost(getPercent(vo.getServiceVolume(),vo.getMedicalFullCost()));
  943. vo.setHospitalFullCost(getPercent(vo.getServiceVolume(),vo.getHospitalFullCost()));
  944. });
  945. }catch (Exception e){
  946. log.error("计算病种成本时发生异常",e);
  947. }
  948. return medServiceCostDetailList;
  949. }
  950. /**
  951. * 获取病种成本构成明细表数据
  952. *
  953. * @return 病种成本明细列表,包含各病种的成本明细及总计行
  954. */
  955. @Override
  956. public List<DiseaseCostDetailVO> getDiseaseCostCompositionDetail(String computeDate) {
  957. List<DiseaseCostDetailVO> projectCostAccountList = computePatientCostAccountRepository.getDiseaseCostCompositionDetail(computeDate);
  958. if(CollectionUtils.isEmpty(projectCostAccountList)){
  959. throw new CostException("请先计算患者成本");
  960. }
  961. // 记录项目类别对象
  962. Map<String, DiseaseCostDetailVO> diseaseCostMap = new HashMap<>();
  963. for (DiseaseCostDetailVO projectCostAccount : projectCostAccountList) {
  964. //按项目类型累加数据
  965. String accountType = projectCostAccount.getCostTypeCode();
  966. DiseaseCostDetailVO vo ;
  967. //已有的项目类别
  968. if (diseaseCostMap.containsKey(projectCostAccount.getItemCode())) {
  969. vo = diseaseCostMap.get(projectCostAccount.getItemCode());
  970. } else {
  971. vo = new DiseaseCostDetailVO();
  972. vo.setItemCode(projectCostAccount.getItemCode());
  973. vo.setItemName(projectCostAccount.getItemName());
  974. BeanUtil.initBigDecimalFieldsToZero(vo);
  975. //新建一个项目类别对象
  976. diseaseCostMap.put(projectCostAccount.getItemCode(), vo);
  977. }
  978. //按会计科目类型累加费用
  979. addAccountTypeExpense(accountType, projectCostAccount.getHospitalFullCost(), vo);
  980. //累加数量
  981. vo.setServiceVolume(vo.getServiceVolume().add(projectCostAccount.getServiceVolume()));
  982. }
  983. List<DiseaseCostDetailVO> diseaseCostDetailList =new ArrayList<>(diseaseCostMap.values());
  984. //按会计科目类型计算占比
  985. diseaseCostDetailList.forEach(vo -> setAccountTypeExpenseRatio(vo));
  986. return diseaseCostDetailList;
  987. }
  988. /**
  989. * 获取服务单元病种成本构成明细表数据
  990. * @param computeDate
  991. * @return
  992. */
  993. @Override
  994. public ComputeProfitCollectResponse getDeptDiseaseCostCompositionDetail(String computeDate) {
  995. List<DiseaseCostDetailVO> projectCostAccountList = computePatientCostAccountRepository.getDeptDiseaseCostCompositionDetail(computeDate);
  996. if(CollectionUtils.isEmpty(projectCostAccountList)){
  997. throw new CostException("请先计算患者成本");
  998. }
  999. // 获取所有的标准字典数据
  1000. StandCostDictMapVO standCostDictMaps = getStandCostDictMaps();
  1001. List<CommonResponsibilityReportVo> titleList = new ArrayList<>();
  1002. // 提取科室名称作为列标题
  1003. for (Responsibility dept : standCostDictMaps.getResponsibilityDict()) {
  1004. CommonResponsibilityReportVo title = new CommonResponsibilityReportVo();
  1005. title.setResponsibilityName(dept.getResponsibilityName());
  1006. title.setResponsibilityCode(dept.getResponsibilityCode());
  1007. title.setSort(dept.getSort());
  1008. //添加子级标题
  1009. addCommonResponsibilityChild(title);
  1010. titleList.add(title);
  1011. }
  1012. // 记录项目类别对象
  1013. Map<String, ReportFormCustomVo> diseaseCostMap = new HashMap<>();
  1014. // 遍历每个项目生成科室金额
  1015. for (DiseaseCostDetailVO costItem : projectCostAccountList) {
  1016. ReportFormCustomVo itemVo ;
  1017. if(diseaseCostMap.containsKey(costItem.getItemCode())){
  1018. itemVo=diseaseCostMap.get(costItem.getItemCode());
  1019. }else{
  1020. itemVo = new ReportFormCustomVo();
  1021. itemVo.setReportName(costItem.getItemName());
  1022. itemVo.setReportCode(costItem.getItemCode());
  1023. itemVo.setData(new ArrayList<>());
  1024. itemVo.setTotalValue(BigDecimal.ZERO);
  1025. diseaseCostMap.put(costItem.getItemCode(),itemVo);
  1026. }
  1027. //金额对象
  1028. ReportVo amountReportVo = new ReportVo();
  1029. amountReportVo.setCode(getResponsibilityAmountCode(costItem.getDepartmentCode()));
  1030. // 设置金额
  1031. amountReportVo.setValue(costItem.getHospitalFullCost());
  1032. // 添加金额
  1033. itemVo.getData().add(amountReportVo);
  1034. //计算总额
  1035. itemVo.setTotalValue(itemVo.getTotalValue().add(costItem.getHospitalFullCost()));
  1036. }
  1037. List<ReportFormCustomVo> diseaseCostDetailList =new ArrayList<>(diseaseCostMap.values());
  1038. // 遍历每个成本项目(列转行)
  1039. for (ReportFormCustomVo costItem : diseaseCostDetailList) {
  1040. if(CollectionUtils.isEmpty(costItem.getData())){
  1041. continue;
  1042. }
  1043. List<ReportVo> dataList =new ArrayList<>();
  1044. dataList.addAll(costItem.getData());
  1045. for (ReportVo amountReportVo : dataList) {
  1046. //占比对象
  1047. ReportVo percentReportVo = new ReportVo();
  1048. percentReportVo.setCode(amountReportVo.getCode());
  1049. //计算百分比
  1050. BigDecimal percent = getPercent((BigDecimal)amountReportVo.getValue() , costItem.getTotalValue());
  1051. percentReportVo.setValue(percent);
  1052. // 添加百分比
  1053. costItem.getData().add(percentReportVo);
  1054. }
  1055. }
  1056. ComputeProfitCollectResponse response = new ComputeProfitCollectResponse();
  1057. response.setTitle(titleList);
  1058. response.setData(diseaseCostDetailList);
  1059. return response;
  1060. }
  1061. /**
  1062. * 获取医院DRG成本明细表数据
  1063. *
  1064. * @param computeDate 核算年月
  1065. * @return DRG成本明细列表
  1066. */
  1067. @Override
  1068. public List<DiseaseCostDetailVO> getDrgCostDetail(String computeDate) {
  1069. List<DiseaseCostDetailVO> projectCostAccountList = computePatientCostAccountRepository.getDrgCostDetailList(computeDate);
  1070. if(CollectionUtils.isEmpty(projectCostAccountList)){
  1071. throw new CostException("请先计算患者成本");
  1072. }
  1073. // 获取所有的标准字典数据
  1074. StandCostDictMapVO standCostDictMaps = getStandCostDictMaps();
  1075. // 记录项目类别对象
  1076. Map<String, DiseaseCostDetailVO> drgeCostMap = new HashMap<>();
  1077. for (DiseaseCostDetailVO projectCostAccount : projectCostAccountList) {
  1078. //按项目类型累加数据
  1079. DictDataVo costType = standCostDictMaps.getCostTypeMap().get(projectCostAccount.getCostTypeCode());
  1080. DiseaseCostDetailVO vo ;
  1081. //已有的项目类别
  1082. if (drgeCostMap.containsKey(projectCostAccount.getItemCode())) {
  1083. vo = drgeCostMap.get(projectCostAccount.getItemCode());
  1084. } else {
  1085. vo=BeanUtil.convertObj(projectCostAccount,DiseaseCostDetailVO.class);
  1086. BeanUtil.initBigDecimalFieldsToZero(vo);
  1087. //新建一个项目类别对象
  1088. drgeCostMap.put(projectCostAccount.getItemCode(), vo);
  1089. }
  1090. //没有数据时跳过
  1091. if(ObjectUtils.isEmpty(projectCostAccount.getHospitalFullCost())){
  1092. continue;
  1093. }
  1094. // 医疗成本
  1095. if ("1".equals(costType.getExpandOne())) {
  1096. vo.setMedicalCost(vo.getMedicalCost().add(projectCostAccount.getHospitalFullCost()));
  1097. }
  1098. // 医疗全成本
  1099. if (!"3".equals(costType.getExpandOne())) {
  1100. vo.setMedicalFullCost(vo.getMedicalFullCost().add(projectCostAccount.getHospitalFullCost()));
  1101. }
  1102. // 医院全成本
  1103. vo.setHospitalFullCost(vo.getHospitalFullCost().add(projectCostAccount.getHospitalFullCost()));
  1104. // 服务量
  1105. vo.setServiceVolume(projectCostAccount.getServiceVolume());
  1106. }
  1107. List<DiseaseCostDetailVO> drgeCostDetailList = new ArrayList<>(drgeCostMap.values());
  1108. //计算单个DRG的成本
  1109. drgeCostDetailList.forEach(vo -> {
  1110. vo.setMedicalCost(getPercent( vo.getMedicalCost(),vo.getServiceVolume()));
  1111. vo.setMedicalFullCost(getPercent(vo.getMedicalFullCost(),vo.getServiceVolume()));
  1112. vo.setHospitalFullCost(getPercent(vo.getHospitalFullCost(),vo.getServiceVolume()));
  1113. });
  1114. return drgeCostDetailList;
  1115. }
  1116. /**
  1117. * 获取DRG成本构成明细表数据
  1118. * @param computeDate
  1119. * @return
  1120. */
  1121. @Override
  1122. public List<DiseaseCostDetailVO> getDrgCostCompositionDetail(String computeDate) {
  1123. List<DiseaseCostDetailVO> projectCostAccountList = computePatientCostAccountRepository.getDrgCostCompositionDetail(computeDate);
  1124. if(CollectionUtils.isEmpty(projectCostAccountList)){
  1125. throw new CostException("请先计算患者成本");
  1126. }
  1127. // 记录项目类别对象
  1128. Map<String, DiseaseCostDetailVO> diseaseCostMap = new HashMap<>();
  1129. for (DiseaseCostDetailVO projectCostAccount : projectCostAccountList) {
  1130. //按项目类型累加数据
  1131. String accountType = projectCostAccount.getCostTypeCode();
  1132. DiseaseCostDetailVO vo ;
  1133. //已有的项目类别
  1134. if (diseaseCostMap.containsKey(projectCostAccount.getItemCode())) {
  1135. vo = diseaseCostMap.get(projectCostAccount.getItemCode());
  1136. } else {
  1137. vo = new DiseaseCostDetailVO();
  1138. vo.setItemCode(projectCostAccount.getItemCode());
  1139. vo.setItemName(projectCostAccount.getItemName());
  1140. BeanUtil.initBigDecimalFieldsToZero(vo);
  1141. //新建一个项目类别对象
  1142. diseaseCostMap.put(projectCostAccount.getItemCode(), vo);
  1143. }
  1144. //按会计科目类型累加费用
  1145. addAccountTypeExpense(accountType, projectCostAccount.getHospitalFullCost(), vo);
  1146. //累加数量
  1147. vo.setServiceVolume(vo.getServiceVolume().add(projectCostAccount.getServiceVolume()));
  1148. }
  1149. List<DiseaseCostDetailVO> diseaseCostDetailList =new ArrayList<>(diseaseCostMap.values());
  1150. //按会计科目类型计算占比
  1151. diseaseCostDetailList.forEach(vo -> setAccountTypeExpenseRatio(vo));
  1152. return diseaseCostDetailList;
  1153. }
  1154. /**
  1155. * 获取科室DRG成本构成明细表数据
  1156. * @param computeDate
  1157. * @return
  1158. */
  1159. @Override
  1160. public ComputeProfitCollectResponse getDeptDrgCostCompositionDetail(String computeDate) {
  1161. List<DiseaseCostDetailVO> projectCostAccountList = computePatientCostAccountRepository.getDeptDrgCostCompositionDetail(computeDate);
  1162. if(CollectionUtils.isEmpty(projectCostAccountList)){
  1163. throw new CostException("请先计算患者成本");
  1164. }
  1165. // 获取所有的标准字典数据
  1166. StandCostDictMapVO standCostDictMaps = getStandCostDictMaps();
  1167. List<CommonResponsibilityReportVo> titleList = new ArrayList<>();
  1168. // 提取科室名称作为列标题
  1169. for (Responsibility dept : standCostDictMaps.getResponsibilityDict()) {
  1170. CommonResponsibilityReportVo title = new CommonResponsibilityReportVo();
  1171. title.setResponsibilityName(dept.getResponsibilityName());
  1172. title.setResponsibilityCode(dept.getResponsibilityCode());
  1173. title.setSort(dept.getSort());
  1174. //添加子级标题
  1175. addCommonResponsibilityChild(title);
  1176. titleList.add(title);
  1177. }
  1178. // 记录项目类别对象
  1179. Map<String, ReportFormCustomVo> diseaseCostMap = new HashMap<>();
  1180. // 遍历每个项目生成科室金额
  1181. for (DiseaseCostDetailVO costItem : projectCostAccountList) {
  1182. ReportFormCustomVo itemVo ;
  1183. if(diseaseCostMap.containsKey(costItem.getItemCode())){
  1184. itemVo=diseaseCostMap.get(costItem.getItemCode());
  1185. }else{
  1186. itemVo = new ReportFormCustomVo();
  1187. itemVo.setReportName(costItem.getItemName());
  1188. itemVo.setReportCode(costItem.getItemCode());
  1189. itemVo.setData(new ArrayList<>());
  1190. itemVo.setTotalValue(BigDecimal.ZERO);
  1191. diseaseCostMap.put(costItem.getItemCode(), itemVo);
  1192. }
  1193. //金额对象
  1194. ReportVo amountReportVo = new ReportVo();
  1195. amountReportVo.setCode(getResponsibilityAmountCode(costItem.getDepartmentCode()));
  1196. // 设置金额
  1197. amountReportVo.setValue(costItem.getHospitalFullCost());
  1198. // 添加金额
  1199. itemVo.getData().add(amountReportVo);
  1200. //计算总额
  1201. itemVo.setTotalValue(itemVo.getTotalValue().add(costItem.getHospitalFullCost()));
  1202. }
  1203. List<ReportFormCustomVo> diseaseCostDetailList =new ArrayList<>(diseaseCostMap.values());
  1204. // 遍历每个成本项目(列转行)
  1205. for (ReportFormCustomVo costItem : diseaseCostDetailList) {
  1206. if(CollectionUtils.isEmpty(costItem.getData())){
  1207. continue;
  1208. }
  1209. List<ReportVo> dataList =new ArrayList<>();
  1210. dataList.addAll(costItem.getData());
  1211. for (ReportVo amountReportVo :dataList) {
  1212. //占比对象
  1213. ReportVo percentReportVo = new ReportVo();
  1214. percentReportVo.setCode(amountReportVo.getCode());
  1215. //计算百分比
  1216. BigDecimal percent = getPercent((BigDecimal)amountReportVo.getValue() , costItem.getTotalValue());
  1217. percentReportVo.setValue(percent);
  1218. // 添加百分比
  1219. costItem.getData().add(percentReportVo);
  1220. }
  1221. }
  1222. ComputeProfitCollectResponse response = new ComputeProfitCollectResponse();
  1223. response.setTitle(titleList);
  1224. response.setData(diseaseCostDetailList);
  1225. return response;
  1226. }
  1227. /**
  1228. * 按会计科目类型计算占比
  1229. * @param vo
  1230. */
  1231. public void setAccountTypeExpenseRatio(DiseaseCostDetailVO vo){
  1232. vo.setPersonnelExpenseRatio(getPercent(vo.getPersonnelExpense(),vo.getTotalCost()));
  1233. vo.setDrugExpenseRatio(getPercent(vo.getDrugExpense(),vo.getTotalCost()));
  1234. vo.setMedicalMaterialExpenseRatio(getPercent(vo.getMedicalMaterialExpense(),vo.getTotalCost()));
  1235. vo.setFixedAssetDepreciationRatio(getPercent(vo.getFixedAssetDepreciation(),vo.getTotalCost()));
  1236. vo.setIntangibleAssetAmortizationRatio(getPercent(vo.getIntangibleAssetAmortization(),vo.getTotalCost()));
  1237. vo.setMedicalRiskFundRatio(getPercent(vo.getMedicalRiskFund(),vo.getTotalCost()));
  1238. vo.setOtherMedicalExpensesRatio(getPercent(vo.getOtherMedicalExpenses(),vo.getTotalCost()));
  1239. }
  1240. /**
  1241. * 按会计科目类型累加费用
  1242. * @param accountType
  1243. * @param expense
  1244. * @param vo
  1245. */
  1246. public void addAccountTypeExpense(String accountType, BigDecimal expense,DiseaseCostDetailVO vo) {
  1247. // 根据费用类型累加到对应字段
  1248. switch (accountType) {
  1249. case "1":
  1250. vo.setPersonnelExpense(vo.getPersonnelExpense().add(expense));
  1251. break;
  1252. case "2":
  1253. vo.setMedicalMaterialExpense(vo.getMedicalMaterialExpense().add(expense));
  1254. break;
  1255. case "3":
  1256. vo.setDrugExpense(vo.getDrugExpense().add(expense));
  1257. break;
  1258. case "4":
  1259. vo.setFixedAssetDepreciation(vo.getFixedAssetDepreciation().add(expense));
  1260. break;
  1261. case "5":
  1262. vo.setIntangibleAssetAmortization(vo.getIntangibleAssetAmortization().add(expense));
  1263. break;
  1264. case "6":
  1265. vo.setMedicalRiskFund(vo.getMedicalRiskFund().add(expense));
  1266. break;
  1267. case "7":
  1268. vo.setOtherMedicalExpenses(vo.getOtherMedicalExpenses().add(expense));
  1269. break;
  1270. default:
  1271. break;
  1272. }
  1273. vo.setTotalCost(vo.getTotalCost().add(expense));
  1274. }
  1275. /**
  1276. * 获取项目归属的项目类型
  1277. * @param standItemCode
  1278. * @param standItemMapDict
  1279. * @return
  1280. */
  1281. public StandItem getProjectItemType(String standItemCode,List<Map<String, StandItem>> standItemMapDict) {
  1282. //不在完整字典里 返回null
  1283. if(!standItemMapDict.get(NumberConstant.ZERO).containsKey(standItemCode)){
  1284. return null;
  1285. }
  1286. //第一层的项目
  1287. if(standItemMapDict.get(NumberConstant.ONE).containsKey(standItemCode)){
  1288. return standItemMapDict.get(NumberConstant.ONE).get(standItemCode);
  1289. }
  1290. //第二层的项目
  1291. if(standItemMapDict.get(NumberConstant.TWO).containsKey(standItemCode)){
  1292. return standItemMapDict.get(NumberConstant.TWO).get(standItemCode);
  1293. }
  1294. //其他层的项目需要递归找到所属的第二层
  1295. StandItem standItem = standItemMapDict.get(NumberConstant.ZERO).get(standItemCode);
  1296. return getProjectItemType(standItem.getParentCode(),standItemMapDict);
  1297. }
  1298. /**
  1299. * 生成完整字典、第一层、第二层的code映射字典
  1300. * @param standItemList
  1301. * @return
  1302. */
  1303. public List<Map<String,StandItem>> getStandItemMapDict(List<StandItem> standItemList) {
  1304. List<Map<String,StandItem>> mapList=new ArrayList<>();
  1305. if(CollectionUtils.isEmpty(standItemList)){
  1306. Map<String,StandItem> map = new HashMap<>();
  1307. Map<String,StandItem> firstMap = new HashMap<>();
  1308. Map<String,StandItem> secondMap = new HashMap<>();
  1309. mapList.add(map);
  1310. mapList.add(firstMap);
  1311. mapList.add(secondMap);
  1312. return mapList;
  1313. }
  1314. // 构建完整字典code到StandItem的映射
  1315. Map<String, StandItem> standItemMap = standItemList.stream()
  1316. .collect(Collectors.toMap(StandItem::getCode, item -> item));
  1317. mapList.add(standItemMap);
  1318. List<StandItem> firstLevel = standItemList.stream().filter(item -> NumberConstant.ZERO_S.equals(item.getParentCode())).collect(Collectors.toList());
  1319. if(CollectionUtils.isEmpty(firstLevel)){
  1320. Map<String,StandItem> firstMap = new HashMap<>();
  1321. Map<String,StandItem> secondMap = new HashMap<>();
  1322. mapList.add(firstMap);
  1323. mapList.add(secondMap);
  1324. return mapList;
  1325. }
  1326. // 构建第一层code到StandItem的映射
  1327. Map<String, StandItem> firstLevelMap = firstLevel.stream()
  1328. .collect(Collectors.toMap(StandItem::getCode, item -> item));
  1329. mapList.add(firstLevelMap);
  1330. List<StandItem> secondLevel= standItemList.stream().filter(item -> firstLevelMap.containsKey(item.getParentCode())).collect(Collectors.toList());
  1331. if(CollectionUtils.isEmpty(secondLevel)){
  1332. Map<String,StandItem> secondMap = new HashMap<>();
  1333. mapList.add(secondMap);
  1334. return mapList;
  1335. }
  1336. // 构建第二层code到StandItem的映射
  1337. Map<String, StandItem> secondLevelMap = secondLevel.stream()
  1338. .collect(Collectors.toMap(StandItem::getCode, item -> item));
  1339. mapList.add(secondLevelMap);
  1340. return mapList;
  1341. }
  1342. /**
  1343. * 根据标准项目字典创建项目类别
  1344. * @param standItemMapDict 标准项目字典
  1345. * @return 项目类别
  1346. */
  1347. private List<HospitalServiceProjectCostVO> createProjectCategory(List<Map<String, StandItem>> standItemMapDict,Map<String, HospitalServiceProjectCostVO> projectCostMap ) {
  1348. if(CollectionUtils.isEmpty(standItemMapDict.get(NumberConstant.ONE))){
  1349. return new ArrayList<>();
  1350. }
  1351. List<StandItem> sencodLevel=new ArrayList<>(standItemMapDict.get(NumberConstant.TWO).values());
  1352. List<StandItem> firstLevel =new ArrayList<>(standItemMapDict.get(NumberConstant.ONE).values());
  1353. //按序号排序
  1354. firstLevel.sort(Comparator.comparing(StandItem::getSort));
  1355. List<HospitalServiceProjectCostVO> hospitalServiceProjectCostVOS =firstLevel.stream().map( item->convertToHospitalServiceProjectCostVO(item)).collect(Collectors.toList());
  1356. for (HospitalServiceProjectCostVO item : hospitalServiceProjectCostVOS) {
  1357. //先加自己的
  1358. if(projectCostMap.containsKey(item.getItemCode())){
  1359. addBigDecimalFields(projectCostMap.get(item.getItemCode()), item);
  1360. }
  1361. if(CollectionUtils.isEmpty(sencodLevel)){
  1362. continue;
  1363. }
  1364. //第一层对应的第二层数据
  1365. List<StandItem> children = sencodLevel.stream().filter(child -> item.getItemCode().equals(child.getParentCode())).collect(Collectors.toList());
  1366. if(CollectionUtils.isEmpty( children)){
  1367. continue;
  1368. }
  1369. //按序号排序
  1370. children.sort(Comparator.comparing(StandItem::getSort));
  1371. item.setChildren(new ArrayList<>());
  1372. for (StandItem child : children) {
  1373. HospitalServiceProjectCostVO childProject ;
  1374. //优先取已有的数据
  1375. if(projectCostMap.containsKey(child.getCode())){
  1376. childProject=projectCostMap.get(child.getCode());
  1377. }else{
  1378. childProject = convertToHospitalServiceProjectCostVO(child);
  1379. }
  1380. //加给第一层
  1381. addBigDecimalFields(childProject, item);
  1382. item.getChildren().add(childProject);
  1383. }
  1384. }
  1385. return hospitalServiceProjectCostVOS;
  1386. }
  1387. public HospitalServiceProjectCostVO convertToHospitalServiceProjectCostVO(StandItem standItem){
  1388. HospitalServiceProjectCostVO vo = new HospitalServiceProjectCostVO();
  1389. vo.setItemCode(standItem.getCode());
  1390. vo.setItemName(standItem.getName());
  1391. // 初始化所有费用字段为0
  1392. BeanUtil.initBigDecimalFieldsToZero(vo);
  1393. return vo;
  1394. }
  1395. /**
  1396. * 获取可是指定项目的金额
  1397. * @param dept
  1398. * @param costItem
  1399. * @return
  1400. */
  1401. public BigDecimal getDeptAmount(DeptDirectMedicalCostVO dept,String costItem) {
  1402. BigDecimal amount = BigDecimal.ZERO;
  1403. switch (costItem) {
  1404. case "人员经费":
  1405. amount = dept.getPersonnelExpense();
  1406. break;
  1407. case "卫生材料费":
  1408. amount = dept.getHealthMaterialFee();
  1409. break;
  1410. case "药品费":
  1411. amount = dept.getDrugFee();
  1412. break;
  1413. case "固定资产折旧费":
  1414. amount =dept.getFixedAssetDepreciation();
  1415. break;
  1416. case "无形资产摊销费":
  1417. amount = dept.getIntangibleAssetAmortization();
  1418. break;
  1419. case "提取医疗风险基金":
  1420. amount = dept.getMedicalRiskFundExtraction();
  1421. break;
  1422. case "其他医疗费用":
  1423. amount = dept.getOtherMedicalExpenses();
  1424. break;
  1425. case "科室全成本合计":
  1426. amount = dept.getTotal();
  1427. break;
  1428. case "科室收入":
  1429. amount = dept.getIncome();
  1430. break;
  1431. case "收入-成本":
  1432. amount = dept.getProfit();
  1433. break;
  1434. case "诊次成本":
  1435. amount = dept.getVisitsCost();
  1436. break;
  1437. case "床日成本":
  1438. amount = dept.getBedDaysCost();
  1439. break;
  1440. default:
  1441. break;
  1442. }
  1443. return amount;
  1444. }
  1445. /**
  1446. * 计算科室的收入及损益+床日成本及诊次成本
  1447. * @param item
  1448. * @param responsibilityIncomeMap
  1449. * @param responsibilityParamValueMap
  1450. * @param visitsBedDaysParamCode
  1451. */
  1452. private void calcDeptExpandCost(DeptDirectMedicalCostVO item,
  1453. Map<String, BigDecimal> responsibilityIncomeMap,
  1454. Map<String, List<ShareParamValue>> responsibilityParamValueMap,
  1455. String[] visitsBedDaysParamCode) {
  1456. //计算科室的收入及损益
  1457. if(responsibilityIncomeMap.containsKey(item.getResponsibilityCode())){
  1458. item.setIncome(responsibilityIncomeMap.get(item.getResponsibilityCode()));
  1459. item.setProfit(item.getIncome().subtract(item.getTotal()));
  1460. }else{
  1461. item.setIncome(BigDecimal.ZERO);
  1462. item.setProfit(BigDecimal.ZERO);
  1463. }
  1464. //计算科室的床日成本及诊次成本
  1465. if(responsibilityParamValueMap.containsKey(item.getResponsibilityCode())){
  1466. List<ShareParamValue> shareParamValues = responsibilityParamValueMap.get(item.getResponsibilityCode());
  1467. // 诊次分摊参数值
  1468. BigDecimal visitParamValue = getParamValue(shareParamValues, visitsBedDaysParamCode[NumberConstant.ZERO]);
  1469. // 床日分摊参数值
  1470. BigDecimal bedDaysParamValue = getParamValue(shareParamValues, visitsBedDaysParamCode[NumberConstant.ONE]);
  1471. // 计算诊次成本及床日成本
  1472. item.setVisitsCost(getPercent(item.getTotal(),visitParamValue));
  1473. item.setBedDaysCost(getPercent(item.getTotal(),bedDaysParamValue));
  1474. }else{
  1475. item.setBedDaysCost(BigDecimal.ZERO);
  1476. item.setVisitsCost(BigDecimal.ZERO);
  1477. }
  1478. }
  1479. /**
  1480. * 获取百分比
  1481. * @param amount
  1482. * @param total
  1483. * @return
  1484. */
  1485. public BigDecimal getPercent(BigDecimal amount,BigDecimal total){
  1486. if(total.compareTo(BigDecimal.ZERO.setScale(4, RoundingMode.HALF_UP)) == 0){
  1487. return BigDecimal.ZERO;
  1488. }
  1489. return amount.divide(total,4, RoundingMode.HALF_UP);
  1490. }
  1491. /**
  1492. * 获取责任中心金额字段
  1493. * @param responsibilityCode
  1494. * @return
  1495. */
  1496. public String getResponsibilityAmountCode(String responsibilityCode){
  1497. return String.format("%s_%s", responsibilityCode, AMOUNT_FIELD);
  1498. }
  1499. /**
  1500. * 获取责任中心占比字段
  1501. * @param responsibilityCode
  1502. * @return
  1503. */
  1504. public String getResponsibilityPercentCode(String responsibilityCode){
  1505. return String.format("%s_%s", responsibilityCode, PERCENT_FIELD);
  1506. }
  1507. /**
  1508. * 添加全成本构成表标题的子级标题
  1509. * @param commonResponsibility
  1510. */
  1511. public void addCommonResponsibilityChild(CommonResponsibilityReportVo commonResponsibility) {
  1512. commonResponsibility.setChild(new ArrayList<>());
  1513. CommonResponsibilityReportVo amount=new CommonResponsibilityReportVo();
  1514. amount.setResponsibilityCode(getResponsibilityAmountCode(commonResponsibility.getResponsibilityCode() ));
  1515. amount.setResponsibilityName("金额");
  1516. amount.setSort(NumberConstant.ZERO);
  1517. commonResponsibility.getChild().add( amount);
  1518. CommonResponsibilityReportVo percent=new CommonResponsibilityReportVo();
  1519. percent.setResponsibilityCode(getResponsibilityPercentCode(commonResponsibility.getResponsibilityCode()));
  1520. percent.setResponsibilityName("占比");
  1521. percent.setSort(NumberConstant.ONE);
  1522. commonResponsibility.getChild().add( percent);
  1523. }
  1524. /**
  1525. * 添加临床服务类科室全成本明细
  1526. * @param reportMap
  1527. * @param allocationQuery
  1528. * @param standCostDictMaps
  1529. */
  1530. private void addClinicalDeptFullCostVO(Map<String, ClinicalDeptFullCostVO> reportMap, AllocationQuery allocationQuery, StandCostDictMapVO standCostDictMaps) {
  1531. String responsibilityCode = allocationQuery.getTargetResponsibilityCode();
  1532. Responsibility responsibility = standCostDictMaps.getResponsibilityMap().get(responsibilityCode);
  1533. if (responsibility == null) {
  1534. return; // 添加 null 检查
  1535. }
  1536. String accountingCode = allocationQuery.getAccountingCode();
  1537. Accounting account = standCostDictMaps.getAccountingMap().get(accountingCode);
  1538. if (account == null) {
  1539. return; // 添加 null 检查
  1540. }
  1541. DictDataVo accountType = standCostDictMaps.getAccountingTypeMap().get(account.getType());
  1542. if (accountType == null) {
  1543. return; // 添加 null 检查
  1544. }
  1545. DictDataVo costType = standCostDictMaps.getCostTypeMap().get(String.valueOf(account.getCostType()));
  1546. DictDataVo standardShareLevel = standCostDictMaps.getStandardShareLevelMap().get(responsibility.getStandardShareLevel());
  1547. ClinicalDeptFullCostVO reportVO = new ClinicalDeptFullCostVO();
  1548. if (reportMap.containsKey(allocationQuery.getResponsibilityCode())) {
  1549. reportVO = reportMap.get(allocationQuery.getResponsibilityCode());
  1550. } else {
  1551. // 生成科室成本报表信息
  1552. initDeptCostReport(reportVO, responsibility, accountType, costType, standardShareLevel);
  1553. // 初始化所有费用字段为0
  1554. BeanUtil.initBigDecimalFieldsToZero(reportVO);
  1555. reportMap.put(allocationQuery.getResponsibilityCode(), reportVO);
  1556. }
  1557. // 根据费用类型累加到对应字段
  1558. switch (costType.getValue()) {
  1559. case "1":
  1560. if (NumberConstant.ONE.equals(allocationQuery.getOriginType().intValue())) {
  1561. reportVO.setMedicalCostTotalDirect(reportVO.getMedicalCostTotalDirect().add(allocationQuery.getAmount()));
  1562. } else {
  1563. reportVO.setMedicalCostTotalIndirect(reportVO.getMedicalCostTotalIndirect().add(allocationQuery.getAmount()));
  1564. }
  1565. reportVO.setMedicalCostTotal(reportVO.getMedicalCostTotal().add(allocationQuery.getAmount()));
  1566. break;
  1567. case "2":
  1568. if (NumberConstant.ONE.equals(allocationQuery.getOriginType().intValue())) {
  1569. reportVO.setFinancialProjectFundsDirect(reportVO.getFinancialProjectFundsDirect().add(allocationQuery.getAmount()));
  1570. } else {
  1571. reportVO.setFinancialProjectFundsIndirect(reportVO.getFinancialProjectFundsIndirect().add(allocationQuery.getAmount()));
  1572. }
  1573. reportVO.setFinancialProjectFunds(reportVO.getFinancialProjectFunds().add(allocationQuery.getAmount()));
  1574. break;
  1575. case "3":
  1576. if (NumberConstant.ONE.equals(allocationQuery.getOriginType().intValue())) {
  1577. reportVO.setNonPeerFinancialFundsDirect(reportVO.getNonPeerFinancialFundsDirect().add(allocationQuery.getAmount()));
  1578. } else {
  1579. reportVO.setNonPeerFinancialFundsIndirect(reportVO.getNonPeerFinancialFundsIndirect().add(allocationQuery.getAmount()));
  1580. }
  1581. reportVO.setNonPeerFinancialFunds(reportVO.getNonPeerFinancialFunds().add(allocationQuery.getAmount()));
  1582. break;
  1583. case "4":
  1584. if (NumberConstant.ONE.equals(allocationQuery.getOriginType().intValue())) {
  1585. reportVO.setEducationalExpensesDirect(reportVO.getEducationalExpensesDirect().add(allocationQuery.getAmount()));
  1586. } else {
  1587. reportVO.setEducationalExpensesIndirect(reportVO.getEducationalExpensesIndirect().add(allocationQuery.getAmount()));
  1588. }
  1589. reportVO.setEducationalExpenses(reportVO.getEducationalExpenses().add(allocationQuery.getAmount()));
  1590. break;
  1591. case "5":
  1592. if (NumberConstant.ONE.equals(allocationQuery.getOriginType().intValue())) {
  1593. reportVO.setAssetDisposalFeesDirect(reportVO.getAssetDisposalFeesDirect().add(allocationQuery.getAmount()));
  1594. } else {
  1595. reportVO.setAssetDisposalFeesIndirect(reportVO.getAssetDisposalFeesIndirect().add(allocationQuery.getAmount()));
  1596. }
  1597. reportVO.setAssetDisposalFees(reportVO.getAssetDisposalFees().add(allocationQuery.getAmount()));
  1598. break;
  1599. default:
  1600. break;
  1601. }
  1602. // 不是医院全成本的都是医疗全成本
  1603. if (!NumberConstant.THREE_S.equals(costType.getExpandOne())) {
  1604. if (NumberConstant.ONE.equals(allocationQuery.getOriginType().intValue())) {
  1605. reportVO.setMedicalTotalCostDirect(reportVO.getMedicalTotalCostDirect().add(allocationQuery.getAmount()));
  1606. } else {
  1607. reportVO.setMedicalTotalCostIndirect(reportVO.getMedicalTotalCostIndirect().add(allocationQuery.getAmount()));
  1608. }
  1609. reportVO.setMedicalTotalCost(reportVO.getMedicalTotalCost().add(allocationQuery.getAmount()));
  1610. }
  1611. // 医院全成本合计
  1612. if (NumberConstant.ONE.equals(allocationQuery.getOriginType().intValue())) {
  1613. reportVO.setHospitalTotalCostDirect(reportVO.getHospitalTotalCostDirect().add(allocationQuery.getAmount()));
  1614. } else {
  1615. reportVO.setHospitalTotalCostIndirect(reportVO.getHospitalTotalCostIndirect().add(allocationQuery.getAmount()));
  1616. }
  1617. reportVO.setHospitalTotalCost(reportVO.getHospitalTotalCost().add(allocationQuery.getAmount()));
  1618. }
  1619. /**
  1620. * 添加科室成本明细
  1621. * @param reportMap
  1622. * @param allocationQuery
  1623. * @param standCostDictMaps
  1624. */
  1625. private void addDeptCostDetailVO(Map<String, ClinicalDeptMedicalCostVO> reportMap, AllocationQuery allocationQuery, StandCostDictMapVO standCostDictMaps) {
  1626. String responsibilityCode = allocationQuery.getTargetResponsibilityCode();
  1627. Responsibility responsibility = standCostDictMaps.getResponsibilityMap().get(responsibilityCode);
  1628. if (responsibility == null) {
  1629. return; // 添加 null 检查
  1630. }
  1631. String accountingCode = allocationQuery.getAccountingCode();
  1632. Accounting account = standCostDictMaps.getAccountingMap().get(accountingCode);
  1633. if (account == null) {
  1634. return; // 添加 null 检查
  1635. }
  1636. DictDataVo accountType = standCostDictMaps.getAccountingTypeMap().get(account.getType());
  1637. if (accountType == null) {
  1638. return; // 添加 null 检查
  1639. }
  1640. DictDataVo costType = standCostDictMaps.getCostTypeMap().get(String.valueOf(account.getCostType()));
  1641. DictDataVo standardShareLevel = standCostDictMaps.getStandardShareLevelMap().get(responsibility.getStandardShareLevel());
  1642. ClinicalDeptMedicalCostVO reportVO = new ClinicalDeptMedicalCostVO();
  1643. if (reportMap.containsKey(allocationQuery.getResponsibilityCode())) {
  1644. reportVO = reportMap.get(allocationQuery.getResponsibilityCode());
  1645. } else {
  1646. //生成科室成本报表信息
  1647. initDeptCostReport(reportVO, responsibility, accountType, costType, standardShareLevel);
  1648. // 初始化所有费用字段为0
  1649. BeanUtil.initBigDecimalFieldsToZero(reportVO);
  1650. reportMap.put(allocationQuery.getResponsibilityCode(), reportVO);
  1651. }
  1652. // 根据费用类型累加到对应字段
  1653. switch (accountType.getExpandOne()) {
  1654. case "1":
  1655. if(NumberConstant.ONE.equals(allocationQuery.getOriginType().intValue())){
  1656. reportVO.setPersonnelDirectCost(reportVO.getPersonnelDirectCost().add(allocationQuery.getAmount()));
  1657. }else{
  1658. reportVO.setPersonnelIndirectCost(reportVO.getPersonnelIndirectCost().add(allocationQuery.getAmount()));
  1659. }
  1660. reportVO.setPersonnelTotalCost(reportVO.getPersonnelTotalCost().add(allocationQuery.getAmount()));
  1661. break;
  1662. case "2":
  1663. if(NumberConstant.ONE.equals(allocationQuery.getOriginType().intValue())){
  1664. reportVO.setHealthMaterialDirectCost(reportVO.getHealthMaterialDirectCost().add(allocationQuery.getAmount()));
  1665. }else{
  1666. reportVO.setHealthMaterialIndirectCost(reportVO.getHealthMaterialIndirectCost().add(allocationQuery.getAmount()));
  1667. }
  1668. reportVO.setHealthMaterialTotalCost(reportVO.getHealthMaterialTotalCost().add(allocationQuery.getAmount()));
  1669. break;
  1670. case "3":
  1671. if(NumberConstant.ONE.equals(allocationQuery.getOriginType().intValue())){
  1672. reportVO.setMedicineDirectCost(reportVO.getMedicineDirectCost().add(allocationQuery.getAmount()));
  1673. }else{
  1674. reportVO.setMedicineIndirectCost(reportVO.getMedicineIndirectCost().add(allocationQuery.getAmount()));
  1675. }
  1676. reportVO.setMedicineTotalCost(reportVO.getMedicineTotalCost().add(allocationQuery.getAmount()));
  1677. break;
  1678. case "4":
  1679. if(NumberConstant.ONE.equals(allocationQuery.getOriginType().intValue())){
  1680. reportVO.setFixedAssetDepreciationDirectCost(reportVO.getFixedAssetDepreciationDirectCost().add(allocationQuery.getAmount()));
  1681. }else{
  1682. reportVO.setFixedAssetDepreciationIndirectCost(reportVO.getFixedAssetDepreciationIndirectCost().add(allocationQuery.getAmount()));
  1683. }
  1684. reportVO.setFixedAssetDepreciationTotalCost(reportVO.getFixedAssetDepreciationTotalCost().add(allocationQuery.getAmount()));
  1685. break;
  1686. case "5":
  1687. if(NumberConstant.ONE.equals(allocationQuery.getOriginType().intValue())){
  1688. reportVO.setIntangibleAssetAmortizationDirectCost(reportVO.getIntangibleAssetAmortizationDirectCost().add(allocationQuery.getAmount()));
  1689. }else{
  1690. reportVO.setIntangibleAssetAmortizationIndirectCost(reportVO.getIntangibleAssetAmortizationIndirectCost().add(allocationQuery.getAmount()));
  1691. }
  1692. reportVO.setIntangibleAssetAmortizationTotalCost(reportVO.getIntangibleAssetAmortizationTotalCost().add(allocationQuery.getAmount()));
  1693. break;
  1694. case "6":
  1695. if(NumberConstant.ONE.equals(allocationQuery.getOriginType().intValue())){
  1696. reportVO.setMedicalRiskReserveDirectCost(reportVO.getMedicalRiskReserveDirectCost().add(allocationQuery.getAmount()));
  1697. }else{
  1698. reportVO.setMedicalRiskReserveIndirectCost(reportVO.getMedicalRiskReserveIndirectCost().add(allocationQuery.getAmount()));
  1699. }
  1700. reportVO.setMedicalRiskReserveTotalCost(reportVO.getMedicalRiskReserveTotalCost().add(allocationQuery.getAmount()));
  1701. break;
  1702. case "7":
  1703. if(NumberConstant.ONE.equals(allocationQuery.getOriginType().intValue())){
  1704. reportVO.setOtherMedicalExpensesDirectCost(reportVO.getOtherMedicalExpensesDirectCost().add(allocationQuery.getAmount()));
  1705. }else{
  1706. reportVO.setOtherMedicalExpensesIndirectCost(reportVO.getOtherMedicalExpensesIndirectCost().add(allocationQuery.getAmount()));
  1707. }
  1708. reportVO.setOtherMedicalExpensesTotalCost(reportVO.getOtherMedicalExpensesTotalCost().add(allocationQuery.getAmount()));
  1709. break;
  1710. default:
  1711. break;
  1712. }
  1713. //添加合计
  1714. if(NumberConstant.ONE.equals(allocationQuery.getOriginType().intValue())){
  1715. reportVO.setTotalDirectCost(reportVO.getTotalDirectCost().add(allocationQuery.getAmount()));
  1716. }else{
  1717. reportVO.setTotalIndirectCost(reportVO.getTotalIndirectCost().add(allocationQuery.getAmount()));
  1718. }
  1719. reportVO.setTotalCost(reportVO.getTotalCost().add(allocationQuery.getAmount()));
  1720. }
  1721. /**
  1722. * 生成科室成本报表信息
  1723. * @param reportVO
  1724. * @param responsibility
  1725. * @param accountType
  1726. * @param costType
  1727. * @param standardShareLevel
  1728. */
  1729. private void initDeptCostReport(BaseDeptCostReportVO reportVO,
  1730. Responsibility responsibility,
  1731. DictDataVo accountType,
  1732. DictDataVo costType,
  1733. DictDataVo standardShareLevel) {
  1734. reportVO.setStandardShareLevel(responsibility.getStandardShareLevel());
  1735. reportVO.setResponsibilityName(responsibility.getResponsibilityName());
  1736. reportVO.setResponsibilityCode(responsibility.getResponsibilityCode());
  1737. reportVO.setResponsibilitySort(responsibility.getSort());
  1738. reportVO.setCostType(costType.getCode());
  1739. reportVO.setStandCostType(costType.getExpandOne());
  1740. reportVO.setAccountType(accountType.getCode());
  1741. reportVO.setStandAccountType(accountType.getExpandOne());
  1742. reportVO.setShareLevelSort(standardShareLevel.getSort());
  1743. }
  1744. /**
  1745. * 获取所有的标准字典数据并转换所有需要的映射数据
  1746. * @return 包含所有映射数据的DTO对象
  1747. */
  1748. private StandCostDictMapVO getStandCostDictMaps() {
  1749. StandCostDictMapVO dataMaps = new StandCostDictMapVO();
  1750. List<Responsibility> responsibilityList = responsibilityRepository.getList(UserContext.getCurrentLoginHospId());
  1751. DictDataVo accountingTypeDict = centerService.getDict(Constant.ACCOUNTING_TYPE);
  1752. DictDataVo costTypeDict = centerService.getDict(Constant.STANDARD_COST_CATEGORIES);
  1753. DictDataVo standardShareLevelDict = centerService.getDict(Constant.STANDARD_SHARE_LEVEL);
  1754. List<Accounting> allCostAccounting = accountingRepository.getAllCostAccounting();
  1755. // 添加 null 检查
  1756. if (responsibilityList == null) {
  1757. responsibilityList = new ArrayList<>();
  1758. }
  1759. if (allCostAccounting == null) {
  1760. allCostAccounting = new ArrayList<>();
  1761. }
  1762. // 创建一个映射,用于快速查找责任中心的科室类型,过滤掉 null 对象,过滤掉 responsibilityCode 为 null 的对象
  1763. Map<String, Responsibility> responsibilityMap = responsibilityList.stream()
  1764. .filter(Objects::nonNull)
  1765. .filter(r -> r.getResponsibilityCode() != null)
  1766. .collect(Collectors.toMap(Responsibility::getResponsibilityCode, o -> o));
  1767. // 创建一个映射,用于快速查找会计科目的类型,过滤掉 null 对象,过滤掉 accountingCode 为 null 的对象
  1768. Map<String, Accounting> accountingMap = allCostAccounting.stream()
  1769. .filter(Objects::nonNull)
  1770. .filter(a -> a.getAccountingCode() != null)
  1771. .collect(Collectors.toMap(Accounting::getAccountingCode, o -> o));
  1772. // 添加 null 检查并创建映射
  1773. List<DictDataVo> accountingTypeDictList = (accountingTypeDict != null && accountingTypeDict.getDataVoList() != null)
  1774. ? accountingTypeDict.getDataVoList() : new ArrayList<>();
  1775. List<DictDataVo> costTypeDictList = (costTypeDict != null && costTypeDict.getDataVoList() != null)
  1776. ? costTypeDict.getDataVoList() : new ArrayList<>();
  1777. List<DictDataVo> standardShareLevelDictList = (standardShareLevelDict != null && standardShareLevelDict.getDataVoList() != null)
  1778. ? standardShareLevelDict.getDataVoList() : new ArrayList<>();
  1779. // 创建一个映射,用于快速查找会计科目类型的扩展字段,过滤掉 null 对象,过滤掉 code 为 null 的对象
  1780. Map<String, DictDataVo> accountingTypeMap = accountingTypeDictList.stream()
  1781. .filter(Objects::nonNull)
  1782. .filter(d -> d.getCode() != null)
  1783. .collect(Collectors.toMap(DictDataVo::getCode, o -> o));
  1784. // 创建一个映射,用于快速查找会计科目类型的扩展字段,过滤掉 null 对象,过滤掉 code 为 null 的对象
  1785. Map<String, DictDataVo> costTypeMap = costTypeDictList.stream()
  1786. .filter(Objects::nonNull)
  1787. .filter(d -> d.getCode() != null)
  1788. .collect(Collectors.toMap(DictDataVo::getCode, o -> o));
  1789. // 创建一个映射,用于快速查找会计科目类型的扩展字段,过滤掉 null 对象,过滤掉 code 为 null 的对象
  1790. Map<String, DictDataVo> standardShareLevelMap = standardShareLevelDictList.stream()
  1791. .filter(Objects::nonNull)
  1792. .filter(d -> d.getCode() != null)
  1793. .collect(Collectors.toMap(DictDataVo::getCode, o -> o));
  1794. dataMaps.setResponsibilityDict(responsibilityList);
  1795. dataMaps.setCostAccountingDict(allCostAccounting);
  1796. dataMaps.setCostTypeDict(costTypeDictList);
  1797. dataMaps.setAccountingTypeDict(accountingTypeDictList);
  1798. dataMaps.setStandardShareLevelDict(standardShareLevelDictList);
  1799. dataMaps.setAccountingMap(accountingMap);
  1800. dataMaps.setCostTypeMap(costTypeMap);
  1801. dataMaps.setResponsibilityMap(responsibilityMap);
  1802. dataMaps.setStandardShareLevelMap(standardShareLevelMap);
  1803. dataMaps.setAccountingTypeMap(accountingTypeMap);
  1804. return dataMaps;
  1805. }
  1806. /**
  1807. * 转换为DeptDirectMedicalCostVO(一个责任中心只一条记录)
  1808. * @param allocationQuery
  1809. * @param standCostDictMaps
  1810. * @return
  1811. */
  1812. public void addDeptDirectMedicalCostVO(Map<String ,DeptDirectMedicalCostVO> deptDirectMedicalCostMap,
  1813. AllocationQuery allocationQuery,
  1814. StandCostDictMapVO standCostDictMaps) {
  1815. String responsibilityCode = allocationQuery.getTargetResponsibilityCode();
  1816. Responsibility responsibility = standCostDictMaps.getResponsibilityMap().get(responsibilityCode);
  1817. if (responsibility == null) {
  1818. return; // 添加 null 检查
  1819. }
  1820. String accountingCode = allocationQuery.getAccountingCode();
  1821. Accounting account = standCostDictMaps.getAccountingMap().get(accountingCode);
  1822. if (account == null) {
  1823. return; // 添加 null 检查
  1824. }
  1825. DictDataVo accountType = standCostDictMaps.getAccountingTypeMap().get(account.getType());
  1826. if (accountType == null) {
  1827. return; // 添加 null 检查
  1828. }
  1829. //只处理医疗成本
  1830. if(!NumberConstant.ONE_S.equals(accountType.getExpandOne()) ){
  1831. return;
  1832. }
  1833. DictDataVo costType = standCostDictMaps.getCostTypeMap().get(String.valueOf(account.getCostType()));
  1834. DictDataVo standardShareLevel = standCostDictMaps.getStandardShareLevelMap().get(responsibility.getStandardShareLevel());
  1835. DeptDirectMedicalCostVO deptDirectMedicalCostVO= new DeptDirectMedicalCostVO();
  1836. if(deptDirectMedicalCostMap.containsKey(allocationQuery.getResponsibilityCode())){
  1837. deptDirectMedicalCostVO=deptDirectMedicalCostMap.get(allocationQuery.getResponsibilityCode());
  1838. }else{
  1839. initDeptCostReport(deptDirectMedicalCostVO, responsibility,accountType, costType,standardShareLevel);
  1840. // 初始化所有费用字段为0
  1841. BeanUtil.initBigDecimalFieldsToZero(deptDirectMedicalCostVO);
  1842. deptDirectMedicalCostMap.put(allocationQuery.getResponsibilityCode(),deptDirectMedicalCostVO);
  1843. }
  1844. // 根据费用类型累加到对应字段
  1845. switch (accountType.getExpandOne()) {
  1846. case "1":
  1847. deptDirectMedicalCostVO.setPersonnelExpense(deptDirectMedicalCostVO.getPersonnelExpense().add((allocationQuery.getAmount())));
  1848. break;
  1849. case "2":
  1850. deptDirectMedicalCostVO.setHealthMaterialFee(deptDirectMedicalCostVO.getHealthMaterialFee().add((allocationQuery.getAmount())));
  1851. break;
  1852. case "3":
  1853. deptDirectMedicalCostVO.setDrugFee(deptDirectMedicalCostVO.getDrugFee().add((allocationQuery.getAmount())));
  1854. break;
  1855. case "4":
  1856. deptDirectMedicalCostVO.setFixedAssetDepreciation(deptDirectMedicalCostVO.getFixedAssetDepreciation().add((allocationQuery.getAmount())));
  1857. break;
  1858. case "5":
  1859. deptDirectMedicalCostVO.setIntangibleAssetAmortization(deptDirectMedicalCostVO.getIntangibleAssetAmortization().add((allocationQuery.getAmount())));
  1860. break;
  1861. case "6":
  1862. deptDirectMedicalCostVO.setMedicalRiskFundExtraction(deptDirectMedicalCostVO.getMedicalRiskFundExtraction().add((allocationQuery.getAmount())));
  1863. break;
  1864. case "7":
  1865. deptDirectMedicalCostVO.setOtherMedicalExpenses(deptDirectMedicalCostVO.getOtherMedicalExpenses().add((allocationQuery.getAmount())));
  1866. break;
  1867. default:
  1868. break;
  1869. }
  1870. // 更新总计
  1871. deptDirectMedicalCostVO.setTotal(deptDirectMedicalCostVO.getTotal().add(allocationQuery.getAmount()));
  1872. }
  1873. /**
  1874. * 转换为DeptDirectAllCostVO(一个责任中心只一条记录)
  1875. * @param reportMap
  1876. * @param allocationQuery
  1877. * @param standCostDictMaps
  1878. */
  1879. private void addDeptDirectAllCostVO(Map<String, DeptFullDirectCostVO> reportMap, AllocationQuery allocationQuery, StandCostDictMapVO standCostDictMaps) {
  1880. String responsibilityCode = allocationQuery.getTargetResponsibilityCode();
  1881. Responsibility responsibility = standCostDictMaps.getResponsibilityMap().get(responsibilityCode);
  1882. if (responsibility == null) {
  1883. return; // 添加 null 检查
  1884. }
  1885. String accountingCode = allocationQuery.getAccountingCode();
  1886. Accounting account = standCostDictMaps.getAccountingMap().get(accountingCode);
  1887. if (account == null) {
  1888. return; // 添加 null 检查
  1889. }
  1890. DictDataVo accountType = standCostDictMaps.getAccountingTypeMap().get(account.getType());
  1891. if (accountType == null) {
  1892. return; // 添加 null 检查
  1893. }
  1894. DictDataVo costType = standCostDictMaps.getCostTypeMap().get(String.valueOf(account.getCostType()));
  1895. DictDataVo standardShareLevel = standCostDictMaps.getStandardShareLevelMap().get(responsibility.getStandardShareLevel());
  1896. DeptFullDirectCostVO reportVO = new DeptFullDirectCostVO();
  1897. if (reportMap.containsKey(allocationQuery.getResponsibilityCode())) {
  1898. reportVO = reportMap.get(allocationQuery.getResponsibilityCode());
  1899. } else {
  1900. initDeptCostReport(reportVO, responsibility,accountType, costType,standardShareLevel);
  1901. // 初始化所有费用字段为0
  1902. BeanUtil.initBigDecimalFieldsToZero(reportVO);
  1903. reportMap.put(allocationQuery.getResponsibilityCode(),reportVO);
  1904. }
  1905. // 根据费用类型累加到对应字段
  1906. switch (costType.getValue()) {
  1907. case "1":
  1908. reportVO.setMedicalCostTotal(reportVO.getMedicalCostTotal().add(allocationQuery.getAmount()));
  1909. break;
  1910. case "2":
  1911. reportVO.setFinancialProjectFunds(reportVO.getFinancialProjectFunds().add(allocationQuery.getAmount()));
  1912. break;
  1913. case "3":
  1914. reportVO.setNonPeerFinancialFunds(reportVO.getNonPeerFinancialFunds().add(allocationQuery.getAmount()));
  1915. break;
  1916. case "4":
  1917. reportVO.setEducationalExpenses(reportVO.getEducationalExpenses().add(allocationQuery.getAmount()));
  1918. break;
  1919. case "5":
  1920. reportVO.setAssetDisposalFees(reportVO.getAssetDisposalFees().add(allocationQuery.getAmount()));
  1921. break;
  1922. default:
  1923. break;
  1924. }
  1925. //不是医院全成本的都是医疗全成本
  1926. if(!NumberConstant.THREE_S.equals(costType.getExpandOne())){
  1927. // 医疗全成本合计
  1928. reportVO.setMedicalTotalCost(reportVO.getMedicalTotalCost().add(allocationQuery.getAmount()));
  1929. }
  1930. // 医院全成本合计
  1931. reportVO.setHospitalTotalCost(reportVO.getHospitalTotalCost().add(allocationQuery.getAmount()));
  1932. }
  1933. /**
  1934. * 合并两个科室成本
  1935. * @param source 源对象
  1936. * @param target 目标对象
  1937. */
  1938. public <T> void addBigDecimalFields(T source, T target) {
  1939. if (source == null || target == null) {
  1940. return;
  1941. }
  1942. Class<?> clazz = target.getClass();
  1943. Field[] fields = clazz.getDeclaredFields();
  1944. for (Field field : fields) {
  1945. if (field.getType().equals(BigDecimal.class)) {
  1946. field.setAccessible(true);
  1947. try {
  1948. BigDecimal sourceValue = (BigDecimal) field.get(source);
  1949. BigDecimal targetValue = (BigDecimal) field.get(target);
  1950. BigDecimal result = (targetValue == null ? BigDecimal.ZERO : targetValue)
  1951. .add(sourceValue == null ? BigDecimal.ZERO : sourceValue);
  1952. field.set(target, result);
  1953. } catch (IllegalAccessException e) {
  1954. log.error("合并科室成本时发生错误", e);
  1955. }
  1956. }
  1957. }
  1958. }
  1959. /**
  1960. * 通用创建小计对象方法
  1961. * @param source 源对象
  1962. * @param totalName 小计名称
  1963. * @param clazz 目标类类型
  1964. * @return 小计对象
  1965. */
  1966. public <T> T createSubtotalVo(T source, String totalName, Class<T> clazz) {
  1967. if (source == null) {
  1968. return null;
  1969. }
  1970. T target = BeanUtil.convertObj(source, clazz);
  1971. // 使用反射设置责任代码和名称
  1972. try {
  1973. clazz.getMethod("setResponsibilityCode", String.class).invoke(target, totalName);
  1974. clazz.getMethod("setResponsibilityName", String.class).invoke(target, totalName);
  1975. } catch (Exception e) {
  1976. log.error("设置责任代码和名称时发生错误", e);
  1977. }
  1978. // 初始化所有费用字段为0
  1979. BeanUtil.initBigDecimalFieldsToZero(target);
  1980. return target;
  1981. }
  1982. // 新增方法,用于设置科室金额
  1983. private void putDepartmentAmount(ClinicalDeptFullCostVO vo, String deptName, BigDecimal amount) {
  1984. try {
  1985. Field field = vo.getClass().getDeclaredField(deptName);
  1986. field.setAccessible(true);
  1987. field.set(vo, amount);
  1988. } catch (NoSuchFieldException | IllegalAccessException e) {
  1989. log.error("设置科室金额时发生错误", e);
  1990. }
  1991. }
  1992. /**
  1993. * 获取诊次床日分摊参数代码
  1994. * @return
  1995. */
  1996. public String[] getVisitsBedDaysParamCode(){
  1997. String parameterValue = centerService.getParameterValue(ParameterConstant.VISITS_BED_DAYS_PARAM_CODE);
  1998. if(StringUtils.isEmpty(parameterValue)||Constant.EMPTY_STR.equals(parameterValue)){
  1999. throw new CostException("请配置诊次床日分摊参数代码");
  2000. }
  2001. String[] split = parameterValue.split(SplitConstant.SEPARATOR_VERTICALLINE);
  2002. if(!NumberConstant.TWO.equals(split.length)){
  2003. throw new CostException("配置的诊次床日分摊参数代码不正确");
  2004. }
  2005. return split;
  2006. }
  2007. /**
  2008. * 添加医院科室成本分摊数据
  2009. * @param deptCostAllocationMap 科室成本分摊Map
  2010. * @param allocationQuery 分摊查询对象
  2011. * @param standCostDictMaps 标准字典数据
  2012. */
  2013. private void addHospitalDeptCostAllocationVO(Map<String, HospitalDeptCostAllocationVO> deptCostAllocationMap,
  2014. AllocationQuery allocationQuery,
  2015. StandCostDictMapVO standCostDictMaps) {
  2016. String responsibilityCode = allocationQuery.getTargetResponsibilityCode();
  2017. String sourceResponsibilityCode = allocationQuery.getResponsibilityCode();
  2018. Responsibility responsibility = standCostDictMaps.getResponsibilityMap().get(responsibilityCode);
  2019. if (responsibility == null) {
  2020. return;
  2021. }
  2022. Responsibility sourceResponsibility = standCostDictMaps.getResponsibilityMap().get(sourceResponsibilityCode);
  2023. if (sourceResponsibility == null) {
  2024. return;
  2025. }
  2026. String accountingCode = allocationQuery.getAccountingCode();
  2027. Accounting account = standCostDictMaps.getAccountingMap().get(accountingCode);
  2028. if (account == null) {
  2029. return;
  2030. }
  2031. DictDataVo accountType = standCostDictMaps.getAccountingTypeMap().get(account.getType());
  2032. if (accountType == null) {
  2033. return;
  2034. }
  2035. HospitalDeptCostAllocationVO costAllocationVO = new HospitalDeptCostAllocationVO();
  2036. if (deptCostAllocationMap.containsKey(responsibilityCode)) {
  2037. costAllocationVO = deptCostAllocationMap.get(responsibilityCode);
  2038. } else {
  2039. // 初始化VO对象
  2040. costAllocationVO.setResponsibilityName(responsibility.getResponsibilityName());
  2041. costAllocationVO.setResponsibilityCode(responsibility.getResponsibilityCode());
  2042. costAllocationVO.setResponsibilitySort(responsibility.getSort());
  2043. costAllocationVO.setStandardShareLevel(responsibility.getStandardShareLevel());
  2044. // 初始化所有费用字段为0
  2045. BeanUtil.initBigDecimalFieldsToZero(costAllocationVO);
  2046. deptCostAllocationMap.put(responsibilityCode, costAllocationVO);
  2047. }
  2048. // 直接成本
  2049. if (NumberConstant.ONE.equals(allocationQuery.getOriginType().intValue())) {
  2050. costAllocationVO.setDirectCost(
  2051. (costAllocationVO.getDirectCost() == null ? BigDecimal.ZERO : costAllocationVO.getDirectCost())
  2052. .add(allocationQuery.getAmount()));
  2053. }else{
  2054. switch (sourceResponsibility.getStandardShareLevel())
  2055. {
  2056. case "1":
  2057. // 行政后勤类科室成本
  2058. costAllocationVO.setAllocatedAdminCost(
  2059. (costAllocationVO.getAllocatedAdminCost() == null ? BigDecimal.ZERO : costAllocationVO.getAllocatedAdminCost())
  2060. .add(allocationQuery.getAmount()));
  2061. case "2":
  2062. // 辅助支持类科室成本
  2063. costAllocationVO.setAllocatedSupportCost(
  2064. (costAllocationVO.getAllocatedSupportCost() == null ? BigDecimal.ZERO : costAllocationVO.getAllocatedSupportCost())
  2065. .add(allocationQuery.getAmount()));
  2066. case "3":
  2067. // 技术类科室成本
  2068. costAllocationVO.setAllocatedTechCost(
  2069. (costAllocationVO.getAllocatedTechCost() == null ? BigDecimal.ZERO : costAllocationVO.getAllocatedTechCost())
  2070. .add(allocationQuery.getAmount()));
  2071. break;
  2072. }
  2073. //小计
  2074. costAllocationVO.setSubtotal(
  2075. (costAllocationVO.getSubtotal() == null ? BigDecimal.ZERO : costAllocationVO.getSubtotal())
  2076. .add(allocationQuery.getAmount()));
  2077. }
  2078. // 医疗类科室成本
  2079. costAllocationVO.setMedicalCost(
  2080. (costAllocationVO.getMedicalCost() == null ? BigDecimal.ZERO : costAllocationVO.getMedicalCost())
  2081. .add(allocationQuery.getAmount()));
  2082. deptCostAllocationMap.put(responsibilityCode, costAllocationVO);
  2083. }
  2084. /**
  2085. * 获取指定分摊参数的数值
  2086. * @param shareParamValues
  2087. * @param paramCode
  2088. * @return
  2089. */
  2090. public BigDecimal getParamValue(List<ShareParamValue> shareParamValues, String paramCode){
  2091. BigDecimal sum = shareParamValues.stream()
  2092. .filter(shareParamValue -> shareParamValue.getShareParamCode().equals(paramCode))
  2093. .map(ShareParamValue::getValueNum)
  2094. .reduce(BigDecimal.ZERO, BigDecimal::add);
  2095. return sum;
  2096. }
  2097. /**
  2098. * 创建医院诊次成本构成表数据
  2099. * @param costAccountingTypeDict
  2100. * @return
  2101. */
  2102. public Map<String, HospitalVisitCostCompositionVO> createHospitalVisitCostCompositionVO(List<DictDataVo> costAccountingTypeDict) {
  2103. // 初始化成本项目映射
  2104. Map<String, HospitalVisitCostCompositionVO> costItemMap = new HashMap<>();
  2105. for (DictDataVo dictDataVo : costAccountingTypeDict) {
  2106. HospitalVisitCostCompositionVO vo = new HospitalVisitCostCompositionVO();
  2107. vo.setCostCode(dictDataVo.getCode());
  2108. vo.setCostItem(dictDataVo.getName());
  2109. vo.setCostType(dictDataVo.getExpandOne());
  2110. vo.setMedicalCost(BigDecimal.ZERO);
  2111. vo.setMedicalFullCost(BigDecimal.ZERO);
  2112. vo.setHospitalFullCost(BigDecimal.ZERO);
  2113. costItemMap.put(dictDataVo.getCode(), vo);
  2114. }
  2115. return costItemMap;
  2116. }
  2117. }