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