CostIncomeGroupServiceImpl.java 25 KB

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