CostIncomeGroupServiceImpl.java 28 KB

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