ExcelController.java 25 KB

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