2
0

ExcelController.java 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. package com.imed.costaccount.web;
  2. import cn.hutool.core.collection.CollUtil;
  3. import cn.hutool.core.io.FileUtil;
  4. import cn.hutool.core.io.IoUtil;
  5. import cn.hutool.poi.excel.ExcelReader;
  6. import cn.hutool.poi.excel.ExcelUtil;
  7. import cn.hutool.poi.excel.ExcelWriter;
  8. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  9. import com.imed.costaccount.common.exception.CostException;
  10. import com.imed.costaccount.common.token.JwtUtil;
  11. import com.imed.costaccount.common.util.Result;
  12. import com.imed.costaccount.common.util.UserContext;
  13. import com.imed.costaccount.constants.NumberConstant;
  14. import com.imed.costaccount.model.*;
  15. import com.imed.costaccount.service.*;
  16. import com.imed.costaccount.service.impl.DepartmentServiceImpl;
  17. import com.imed.costaccount.service.impl.ProductServiceImpl;
  18. import io.swagger.annotations.Api;
  19. import io.swagger.annotations.ApiImplicitParam;
  20. import io.swagger.annotations.ApiImplicitParams;
  21. import io.swagger.annotations.ApiOperation;
  22. import lombok.extern.slf4j.Slf4j;
  23. import org.apache.poi.ss.usermodel.Sheet;
  24. import org.apache.shiro.SecurityUtils;
  25. import org.jetbrains.annotations.NotNull;
  26. import org.springframework.util.CollectionUtils;
  27. import org.springframework.web.bind.annotation.*;
  28. import org.springframework.web.multipart.MultipartFile;
  29. import javax.servlet.ServletOutputStream;
  30. import javax.servlet.http.HttpServletResponse;
  31. import java.io.File;
  32. import java.io.IOException;
  33. import java.io.InputStream;
  34. import java.util.*;
  35. import java.util.stream.Collectors;
  36. /**
  37. * 相关导入导出操作
  38. */
  39. @Slf4j
  40. @Api(tags = "excel导入导出")
  41. @RestController
  42. @RequestMapping("/costAccount/excel")
  43. public class ExcelController extends AbstractController{
  44. private final JwtUtil jwtUtil;
  45. private final UserService userService;
  46. private final DepartmentServiceImpl departmentService;
  47. private final ProductServiceImpl productService;
  48. private final AccountingService accountingService;
  49. private final AccountingProductService accountingProductService;
  50. private final ResponsibilityDepartmentService responsibilityDepartmentService;
  51. private final CostShareParamService costShareParamService;
  52. private final CostIncomeGroupService costIncomeGroupService;
  53. private final CostCostingGroupService costCostingGroupService;
  54. private final ShareParamValueService shareParamValueService;
  55. private final CostCostingCollectionService costCostingCollectionService;
  56. private final AllocationService allocationServicel;
  57. public ExcelController(UserService userService, DepartmentServiceImpl departmentService, ProductServiceImpl productService,
  58. AccountingService accountingService, AccountingProductService accountingProductService,
  59. ResponsibilityDepartmentService responsibilityDepartmentService,
  60. CostShareParamService costShareParamService, CostIncomeGroupService costIncomeGroupService, JwtUtil jwtUtil,
  61. CostCostingGroupService costCostingGroupService, ShareParamValueService shareParamValueService, CostCostingCollectionService costCostingCollectionService, AllocationService allocationServicel) {
  62. this.userService = userService;
  63. this.departmentService = departmentService;
  64. this.productService = productService;
  65. this.accountingService = accountingService;
  66. this.accountingProductService = accountingProductService;
  67. this.responsibilityDepartmentService = responsibilityDepartmentService;
  68. this.costShareParamService = costShareParamService;
  69. this.costIncomeGroupService = costIncomeGroupService;
  70. this.jwtUtil = jwtUtil;
  71. this.costCostingGroupService = costCostingGroupService;
  72. this.shareParamValueService = shareParamValueService;
  73. this.costCostingCollectionService = costCostingCollectionService;
  74. this.allocationServicel = allocationServicel;
  75. }
  76. @ApiOperation("用户导出模板设置")
  77. @GetMapping("/getcurrentTemplate")
  78. public void getImportUserTemplate(HttpServletResponse response) throws IOException {
  79. // TODO: 2021/7/26 暂时没有登录
  80. String uuid = UUID.randomUUID().toString();
  81. String url = System.getProperty("java.io.tmpdir") + File.separator + uuid + File.separator + uuid + ".xls";
  82. FileUtil.del(FileUtil.file(url));
  83. ExcelWriter writer = new ExcelWriter(url);
  84. // 样式
  85. Sheet sheet = writer.getSheet();
  86. // 内容
  87. writer.merge(0, 1, 0, 4, "为了保证成功导入,请勿修改模板格式", false);
  88. writer.passCurrentRow();
  89. writer.passCurrentRow();
  90. writer.merge(2, 2, 0, 4, "测试医院用户导入", false);
  91. writer.passCurrentRow();
  92. writer.writeRow(Arrays.asList("院区", "姓名", "工号", "密码", "手机号码"));
  93. // 写入响应
  94. response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
  95. response.setHeader("Content-Disposition", "attachment;filename=" + uuid + ".xls");
  96. ServletOutputStream out = null;
  97. out = response.getOutputStream();
  98. writer.flush(out, true);
  99. writer.close();
  100. IoUtil.close(out);
  101. }
  102. @PostMapping("/importUser")
  103. @ApiOperation("导入用户")
  104. public Result importUser(@RequestParam("file") MultipartFile file) {
  105. InputStream in;
  106. try {
  107. in = file.getInputStream();
  108. ExcelReader reader = ExcelUtil.getReader(in);
  109. List<List<Object>> read = reader.read();
  110. log.info("最开始:read={}", read);
  111. log.info("-------------------------------假装我是个分割线------------------------------------");
  112. User user = (User) SecurityUtils.getSubject().getPrincipal();
  113. return userService.importUser(read, user);
  114. } catch (IOException e) {
  115. e.printStackTrace();
  116. throw new CostException(500, "导入失败");
  117. }
  118. }
  119. /**
  120. * 科室模板导出功能设置
  121. */
  122. @ApiOperation("科室导出模板设置")
  123. @GetMapping("/getDepartmentTemplate")
  124. public void getImportDepartmentTemplate(HttpServletResponse response) throws IOException {
  125. User user = getUser();
  126. String uuid = UUID.randomUUID().toString();
  127. String url = System.getProperty("java.io.tmpdir") + File.separator + uuid + File.separator + uuid + ".xls";
  128. FileUtil.del(FileUtil.file(url));
  129. ExcelWriter writer = new ExcelWriter(url);
  130. // 样式
  131. Sheet sheet = writer.getSheet();
  132. // 内容
  133. writer.merge(0, 1, 0, 2, "为了保证成功导入,请勿修改模板格式", false);
  134. writer.passCurrentRow();
  135. writer.passCurrentRow();
  136. writer.merge(2, 2, 0, 2, "医院科室批量导入", false);
  137. writer.passCurrentRow();
  138. writer.setColumnWidth(0, 20);
  139. writer.setColumnWidth(1, 15);
  140. writer.setColumnWidth(2, 15);
  141. writer.writeRow(Arrays.asList("院区", "科室名称", "科室代码"));
  142. // 写入响应
  143. response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
  144. response.setHeader("Content-Disposition", "attachment;filename=" + uuid + ".xls");
  145. ServletOutputStream out = null;
  146. out = response.getOutputStream();
  147. writer.flush(out, true);
  148. writer.close();
  149. IoUtil.close(out);
  150. }
  151. /**
  152. * 批量导入科室信息
  153. */
  154. @PostMapping("/importDepartment")
  155. @ApiOperation("导入科室信息")
  156. public Result importDepartment(@RequestParam("file") MultipartFile file) {
  157. InputStream in;
  158. try {
  159. in = file.getInputStream();
  160. ExcelReader reader = ExcelUtil.getReader(in);
  161. List<List<Object>> read = reader.read();
  162. log.info("最开始:read={}", read);
  163. log.info("-------------------------------------------------------------------");
  164. User user = getUser();
  165. Long hospId = user.getHospId();
  166. return departmentService.importDepartment(read, hospId);
  167. } catch (IOException e) {
  168. e.printStackTrace();
  169. ;
  170. throw new CostException(500, "导入失败");
  171. }
  172. }
  173. /**
  174. * 收入成本项目批量导入模板
  175. */
  176. @ApiOperation("成本项目导出模板设置")
  177. @GetMapping("/getImportProductTemplate")
  178. public void getImportProductTemplate(HttpServletResponse response) throws IOException {
  179. User user = getUser();
  180. String uuid = UUID.randomUUID().toString();
  181. String url = System.getProperty("java.io.tmpdir") + File.separator + uuid + File.separator + uuid + ".xls";
  182. FileUtil.del(FileUtil.file(url));
  183. ExcelWriter writer = new ExcelWriter(url);
  184. // 样式
  185. Sheet sheet = writer.getSheet();
  186. // 内容
  187. writer.merge(0, 1, 0, 2, "为了保证成功导入,请勿修改模板格式", false);
  188. writer.passCurrentRow();
  189. writer.passCurrentRow();
  190. writer.merge(2, 2, 0, 2, "医院成本收入批量导入", false);
  191. writer.passCurrentRow();
  192. writer.setColumnWidth(0, 20);
  193. writer.setColumnWidth(1, 15);
  194. writer.setColumnWidth(2, 15);
  195. writer.writeRow(Arrays.asList("院区", "成本项目名", "成本项目编号"));
  196. // 写入响应
  197. response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
  198. response.setHeader("Content-Disposition", "attachment;filename=" + uuid + ".xls");
  199. ServletOutputStream out = null;
  200. out = response.getOutputStream();
  201. writer.flush(out, true);
  202. writer.close();
  203. IoUtil.close(out);
  204. }
  205. /**
  206. * 收入成本项目批量导入
  207. */
  208. @PostMapping("/importProduct")
  209. @ApiOperation("批量导入成本项目信息")
  210. public Result importProduct(@RequestParam("file") MultipartFile file) {
  211. InputStream in;
  212. try {
  213. in = file.getInputStream();
  214. ExcelReader reader = ExcelUtil.getReader(in);
  215. List<List<Object>> read = reader.read();
  216. log.info("最开始:read={}", read);
  217. log.info("-------------------------------------------------------------------");
  218. User user = getUser();
  219. Long hospId = user.getHospId();
  220. return productService.importProduct(read, hospId);
  221. } catch (IOException e) {
  222. e.printStackTrace();
  223. ;
  224. throw new CostException(500, "导入失败");
  225. }
  226. }
  227. /**
  228. * 收入成本数据导出模板
  229. */
  230. @ApiOperation("收入数据导出模板设置")
  231. @GetMapping("/getImportIncomeProductAccountTemplate")
  232. public void getImportProductAccountTemplate(HttpServletResponse response,String token) throws IOException {
  233. int userId = jwtUtil.getUserId(token);
  234. User user = userService.getById(userId);
  235. if (Objects.isNull(user)){
  236. throw new CostException(500,"用户不存在");
  237. }
  238. Long hospId = user.getHospId();
  239. String uuid = UUID.randomUUID().toString();
  240. String url = System.getProperty("java.io.tmpdir") + File.separator + uuid + File.separator + uuid + ".xls";
  241. FileUtil.del(FileUtil.file(url));
  242. ExcelWriter writer = new ExcelWriter(url);
  243. // 样式
  244. Sheet sheet = writer.getSheet();
  245. // 内容
  246. writer.merge(0, 1, 0, 16, "为了保证成功导入,请勿修改模板格式", false);
  247. writer.passCurrentRow();
  248. writer.passCurrentRow();
  249. writer.merge(2, 2, 0, 16, "医院收入数据批量导入", false);
  250. writer.passCurrentRow();
  251. // 冻结前四行
  252. writer.setFreezePane(4);
  253. writer.writeRow(Arrays.asList("成本项目代码", "成本项目名称", "开单科室", "开单科室代码", "执行科室", "执行科室代码", "医生编码","开单医生",
  254. "病人ID", "住院号/门诊号", "患者姓名", "病人费别", "收据费别", "数量", "单位", "金额", "费用发生时间"));
  255. int accountType = NumberConstant.ONE;
  256. int column = NumberConstant.FOUR;
  257. getProductByAccountType(hospId, writer, accountType, column);
  258. writer.setColumnWidth(0, 20);
  259. writer.setColumnWidth(1, 20);
  260. writer.setColumnWidth(2, 10);
  261. writer.setColumnWidth(3, 13);
  262. writer.setColumnWidth(4, 10);
  263. writer.setColumnWidth(5, 13);
  264. writer.setColumnWidth(6, 10);
  265. writer.setColumnWidth(7, 10);
  266. writer.setColumnWidth(8, 10);
  267. writer.setColumnWidth(9, 15);
  268. writer.setColumnWidth(10, 10);
  269. writer.setColumnWidth(11, 10);
  270. writer.setColumnWidth(12, 10);
  271. writer.setColumnWidth(13, 10);
  272. writer.setColumnWidth(14, 10);
  273. writer.setColumnWidth(15, 10);
  274. writer.setColumnWidth(16, 15);
  275. response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
  276. response.setHeader("Content-Disposition", "attachment;filename=" + uuid + ".xls");
  277. ServletOutputStream out = null;
  278. out = response.getOutputStream();
  279. writer.flush(out, true);
  280. writer.close();
  281. IoUtil.close(out);
  282. }
  283. /**
  284. * 成本数据导出模板
  285. */
  286. @GetMapping("/getImportCostProductAccountTemplate")
  287. @ApiOperation("成本数据导出模板设置")
  288. public void getImportCostProductAccountTemplate(HttpServletResponse response,String token) throws IOException {
  289. int userId = jwtUtil.getUserId(token);
  290. User user = userService.getById(userId);
  291. if (Objects.isNull(user)){
  292. throw new CostException(500,"用户不存在");
  293. }
  294. Long hospId = user.getHospId();
  295. String uuid = UUID.randomUUID().toString();
  296. String url = System.getProperty("java.io.tmpdir") + File.separator + uuid + File.separator + uuid + ".xls";
  297. FileUtil.del(FileUtil.file(url));
  298. ExcelWriter writer = new ExcelWriter(url);
  299. // 样式
  300. // 所有科室里面对应存在责任中心对应的科室
  301. List<Department> departmentLinkedList = getDepartments(hospId);
  302. // 设置科室的代码集合
  303. List<String> departmentCodeList = departmentLinkedList.stream().map(Department::getDepartmentCode).collect(Collectors.toList());
  304. List<String> departmentNameList = departmentLinkedList.stream().map(Department::getDepartmentName).collect(Collectors.toList());
  305. Sheet sheet = writer.getSheet();
  306. writer.merge(0, 1, 0, departmentCodeList.size()==0?3:departmentCodeList.size()+2, "为了保证成功导入,请勿修改模板格式", false);
  307. writer.passCurrentRow();
  308. writer.passCurrentRow();
  309. writer.merge(2, 2, 0, departmentCodeList.size()==0?3:departmentCodeList.size()+2, "医院成本数据批量导入", false);
  310. writer.passCurrentRow();
  311. writer.merge(3,3,2,departmentCodeList.size()==0?3:departmentCodeList.size()+2,"科室",false);
  312. writer.passCurrentRow();
  313. departmentCodeList.add(0, null);
  314. departmentCodeList.add(1, null);
  315. departmentCodeList.add("-1");
  316. writer.writeRow(departmentCodeList);
  317. departmentNameList.add(0, "成本项目代码");
  318. departmentNameList.add(1, "成本项目名称");
  319. departmentNameList.add("总计");
  320. writer.writeRow(departmentNameList);
  321. // 设置科室名称的集合
  322. writer.setFreezePane(5);
  323. int accountType = NumberConstant.TWO;
  324. int column = NumberConstant.SIX;
  325. getProductByAccountType(hospId, writer, accountType, column);
  326. writer.setColumnWidth(0, 15);
  327. writer.setColumnWidth(1, 15);
  328. response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
  329. response.setHeader("Content-Disposition", "attachment;filename=" + uuid + ".xls");
  330. ServletOutputStream out = null;
  331. out = response.getOutputStream();
  332. writer.flush(out, true);
  333. writer.close();
  334. IoUtil.close(out);
  335. }
  336. /**
  337. * 测试模板数据导出
  338. */
  339. @ApiOperation("分摊报表输出")
  340. @GetMapping("/getShareReportTemplateTwo")
  341. public void getShareReportTemplateTwo(HttpServletResponse response,Integer shareNumber,String token) throws IOException {
  342. int userId = jwtUtil.getUserId(token);
  343. User user = userService.getById(userId);
  344. if (Objects.isNull(user)){
  345. throw new CostException(500,"用户不存在");
  346. }
  347. Long hospId = user.getHospId();
  348. String uuid = UUID.randomUUID().toString();
  349. String url = System.getProperty("java.io.tmpdir") + File.separator + uuid + File.separator + uuid + ".xls";
  350. FileUtil.del(FileUtil.file(url));
  351. ExcelWriter writer = new ExcelWriter(url);
  352. Sheet sheet = writer.getSheet();
  353. // 第几次分摊
  354. writer= costCostingCollectionService.getShareReportTemplate(writer,shareNumber,sheet);
  355. response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
  356. response.setHeader("Content-Disposition", "attachment;filename=" + uuid + ".xls");
  357. ServletOutputStream out = null;
  358. out = response.getOutputStream();
  359. writer.flush(out, true);
  360. writer.close();
  361. IoUtil.close(out);
  362. }
  363. @ApiOperation("分摊报表输出2.0")
  364. @GetMapping("/getShareReportTemplate")
  365. public void getTemplate(HttpServletResponse response,Integer levelSort,String token,Integer year,Integer month) throws IOException {
  366. int userId = jwtUtil.getUserId(token);
  367. User user = userService.getById(userId);
  368. if (Objects.isNull(user)){
  369. throw new CostException(500,"用户不存在");
  370. }
  371. Long hospId = user.getHospId();
  372. String uuid = UUID.randomUUID().toString();
  373. String url = System.getProperty("java.io.tmpdir") + File.separator + uuid + File.separator + uuid + ".xls";
  374. FileUtil.del(FileUtil.file(url));
  375. ExcelWriter writer = new ExcelWriter(url);
  376. Sheet sheet = writer.getSheet();
  377. // 第几次分摊
  378. writer= allocationServicel.getShareReportTemplate(writer,levelSort,sheet,year,month);
  379. response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
  380. response.setHeader("Content-Disposition", "attachment;filename=" + uuid + ".xls");
  381. ServletOutputStream out = null;
  382. out = response.getOutputStream();
  383. writer.flush(out, true);
  384. writer.close();
  385. IoUtil.close(out);
  386. }
  387. /**
  388. * 获取执行类型的成本项目
  389. *
  390. * @param hospId 医院Id
  391. * @param writer 操作流
  392. * @param accountType 会计科目类型 1 收入 2支出(成本)
  393. * @param column 控制第几列
  394. */
  395. private void getProductByAccountType(Long hospId, ExcelWriter writer, Integer accountType, Integer column) {
  396. // 所有的成本项目
  397. List<Product> productList = productService.list(new QueryWrapper<Product>().lambda().eq(Product::getHospId, hospId));
  398. // 所有成本会计对照数据
  399. List<AccountingProduct> accountingProductList = accountingProductService.list(new QueryWrapper<AccountingProduct>().lambda().eq(AccountingProduct::getHospId, hospId));
  400. // 所有会计科目列表数据
  401. List<Accounting> accountingList = accountingService.list(new QueryWrapper<Accounting>().lambda().eq(Accounting::getHospId, hospId));
  402. List<Product> products = new ArrayList<>();
  403. Map<Long, List<AccountingProduct>> accountProductMap = accountingProductList.stream().collect(Collectors.groupingBy(AccountingProduct::getProductId));
  404. Map<Long, List<Accounting>> accountMap = accountingList.stream().collect(Collectors.groupingBy(Accounting::getId));
  405. productList.forEach(i -> {
  406. Long productId = i.getId();
  407. List<AccountingProduct> accountingProducts = accountProductMap.get(productId);
  408. if (CollUtil.isNotEmpty(accountingProducts)) {
  409. Long accountingId = accountingProducts.get(0).getAccountingId();
  410. List<Accounting> accountings = accountMap.get(accountingId);
  411. if (CollUtil.isNotEmpty(accountings) && accountType.equals(accountings.get(0).getAccountingType())) {
  412. products.add(i);
  413. }
  414. }
  415. });
  416. // 写入响应第二列 第三列的数据
  417. for (int j = 0; j < products.size(); j++) {
  418. writer.writeCellValue(0, j + column, products.get(j).getProductCode());
  419. writer.writeCellValue(1, j + column, products.get(j).getProductName());
  420. }
  421. }
  422. /**
  423. * 成本分摊参数导出模板
  424. */
  425. @GetMapping("/getShareParamTemplate")
  426. @ApiOperation("成本分摊参数值导出模板")
  427. public void getShareParamTemplate(HttpServletResponse response,String token) throws IOException {
  428. int userId = jwtUtil.getUserId(token);
  429. User user = userService.getById(userId);
  430. if (Objects.isNull(user)){
  431. throw new CostException(500,"用户不存在");
  432. }
  433. Long hospId = user.getHospId();
  434. String uuid = UUID.randomUUID().toString();
  435. String url = System.getProperty("java.io.tmpdir") + File.separator + uuid + File.separator + uuid + ".xls";
  436. FileUtil.del(FileUtil.file(url));
  437. ExcelWriter writer = new ExcelWriter(url);
  438. // 样式
  439. // 所有科室里面对应存在责任中心对应的科室进行显示
  440. List<Department> departmentLinkedList = getDepartments(hospId);
  441. // 设置科室的代码集合
  442. List<String> departmentCodeList = departmentLinkedList.stream().map(Department::getDepartmentCode).collect(Collectors.toList());
  443. List<String> departmentNameList = departmentLinkedList.stream().map(Department::getDepartmentName).collect(Collectors.toList());
  444. List<CostShareParam> costShareParamList = costShareParamService.list(new QueryWrapper<CostShareParam>().lambda().eq(CostShareParam::getHospId, hospId));
  445. Sheet sheet = writer.getSheet();
  446. writer.merge(0, 1, 0, departmentCodeList.size()==0?3:departmentCodeList.size()+1, "为了保证成功导入,请勿修改模板格式", false);
  447. writer.passCurrentRow();
  448. writer.passCurrentRow();
  449. writer.merge(2, 2, 0, departmentCodeList.size()==0?3:departmentCodeList.size()+1, "医院成本分摊参数数据批量导入", false);
  450. writer.passCurrentRow();
  451. writer.merge(3,3,2,departmentCodeList.size()==0?3:departmentCodeList.size()+1,"科室",false);
  452. writer.passCurrentRow();
  453. departmentCodeList.add(0, null);
  454. departmentCodeList.add(1, null);
  455. writer.writeRow(departmentCodeList);
  456. departmentNameList.add(0, "成本分摊参数代码");
  457. departmentNameList.add(1, "成本分摊参数名称");
  458. writer.writeRow(departmentNameList);
  459. // 设置科室名称的集合
  460. writer.setFreezePane(5);
  461. // 为第一列和第二列设置成本分摊参数的列表数据
  462. for (int j = 0; j < costShareParamList.size(); j++) {
  463. writer.writeCellValue(0, j + 6, costShareParamList.get(j).getShareParamCode());
  464. writer.writeCellValue(1, j + 6, costShareParamList.get(j).getShareParamName());
  465. }
  466. writer.setColumnWidth(0, 15);
  467. writer.setColumnWidth(1, 22);
  468. response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
  469. response.setHeader("Content-Disposition", "attachment;filename=" + uuid + ".xls");
  470. ServletOutputStream out = null;
  471. out = response.getOutputStream();
  472. writer.flush(out, true);
  473. writer.close();
  474. IoUtil.close(out);
  475. }
  476. @NotNull
  477. private List<Department> getDepartments(Long hospId) {
  478. List<Department> departmentLinkedList = new LinkedList<>();
  479. List<Department> departmentList = departmentService.list(new QueryWrapper<Department>().lambda().eq(Department::getHospId, hospId).orderByDesc(Department::getCreateTime));
  480. List<ResponsibilityDepartment> responsibilityDepartmentList = responsibilityDepartmentService.list(new QueryWrapper<ResponsibilityDepartment>().lambda()
  481. .eq(ResponsibilityDepartment::getHospId, hospId));
  482. Map<Long, List<ResponsibilityDepartment>> responsibilityDepartmentMap = responsibilityDepartmentList.stream().collect(Collectors.groupingBy(ResponsibilityDepartment::getDepartmentId));
  483. departmentList.forEach(i -> {
  484. Long id = i.getId();
  485. if (!CollectionUtils.isEmpty(responsibilityDepartmentMap.get(id))) {
  486. // TODO 暂时先不考虑关联的责任中心是否存在
  487. departmentLinkedList.add(i);
  488. }
  489. });
  490. return departmentLinkedList;
  491. }
  492. /**
  493. * 导入 收入数据导入
  494. *
  495. * @param
  496. */
  497. @PostMapping("/importDataByFileType")
  498. @ApiOperation("收入数据导入")
  499. @ApiImplicitParams({
  500. @ApiImplicitParam(name = "fileType", value = "文件类型 1 成本分摊参数值 2收入 3成本数据"),
  501. @ApiImplicitParam(name = "dateTime", value = "年月yyyy-MM")}
  502. )
  503. public Result importProductAccount(@RequestParam("file") MultipartFile file ,Integer fileType,String dateTime) {
  504. if (Objects.isNull(file)) {
  505. throw new CostException(500, "请选择文件");
  506. }
  507. InputStream in;
  508. // 导入的是收入数据
  509. try {
  510. in = file.getInputStream();
  511. ExcelReader reader = ExcelUtil.getReader(in);
  512. List<List<Object>> read = reader.read();
  513. log.info("最开始:read={}", read);
  514. log.info("-------------------------------------------------------------------");
  515. User user = UserContext.getCurrentUser();
  516. return costIncomeGroupService.importIncomeGroup(read, user, file, dateTime,fileType);
  517. } catch (IOException e) {
  518. e.printStackTrace();
  519. ;
  520. throw new CostException(500, "导入失败");
  521. }
  522. }
  523. @PostMapping("/importCostingGroup")
  524. @ApiOperation("成本数据导入")
  525. @ApiImplicitParams({
  526. @ApiImplicitParam(name = "fileType", value = "文件类型 1 成本分摊参数值 2收入 3成本数据"),
  527. @ApiImplicitParam(name = "dateTime", value = "年月yyyy-MM")}
  528. )
  529. public Result importCostingGroup(@RequestParam("file") MultipartFile file ,Integer fileType,String dateTime) {
  530. if (Objects.isNull(file)) {
  531. throw new CostException(500, "请选择文件");
  532. }
  533. InputStream in;
  534. // 导入的是收入数据
  535. try {
  536. in = file.getInputStream();
  537. ExcelReader reader = ExcelUtil.getReader(in);
  538. List<List<Object>> read = reader.read();
  539. log.info("最开始:read={}", read);
  540. log.info("-------------------------------------------------------------------");
  541. User user = UserContext.getCurrentUser();
  542. return costCostingGroupService.importCostingGroup(read, user, file, dateTime,fileType);
  543. } catch (IOException e) {
  544. e.printStackTrace();
  545. ;
  546. throw new CostException(500, "导入失败");
  547. }
  548. }
  549. @PostMapping("/importShareParamGroup")
  550. @ApiOperation("成本分摊参数值导入")
  551. @ApiImplicitParams({
  552. @ApiImplicitParam(name = "fileType", value = "文件类型 1 成本分摊参数值 2收入 3成本数据"),
  553. @ApiImplicitParam(name = "dateTime", value = "年月yyyy-MM")}
  554. )
  555. public Result importShareParamGroup(@RequestParam("file") MultipartFile file ,Integer fileType,String dateTime){
  556. if (Objects.isNull(file)) {
  557. throw new CostException(500, "请选择文件");
  558. }
  559. InputStream in;
  560. // 导入的是收入数据
  561. try {
  562. in = file.getInputStream();
  563. ExcelReader reader = ExcelUtil.getReader(in);
  564. List<List<Object>> read = reader.read();
  565. log.info("最开始:read={}", read);
  566. log.info("-------------------------------------------------------------------");
  567. User user = UserContext.getCurrentUser();
  568. return shareParamValueService.importShareParamGroup(read, user, file, dateTime,fileType);
  569. } catch (IOException e) {
  570. e.printStackTrace();
  571. ;
  572. throw new CostException(500, "导入失败");
  573. }
  574. }
  575. }