|
@@ -1,8 +1,6 @@
|
|
|
package com.imed.costaccount.web;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
-import cn.hutool.core.date.DateTime;
|
|
|
-import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
import cn.hutool.core.io.IoUtil;
|
|
|
import cn.hutool.poi.excel.ExcelReader;
|
|
@@ -62,8 +60,11 @@ public class ExcelController {
|
|
|
|
|
|
private final CostIncomeGroupService costIncomeGroupService;
|
|
|
|
|
|
+ private final CostCostingGroupService costCostingGroupService;
|
|
|
|
|
|
- public ExcelController(UserService userService, DepartmentServiceImpl departmentService, ProductServiceImpl productService, AccountingService accountingService, AccountingProductService accountingProductService, ResponsibilityDepartmentService responsibilityDepartmentService, CostShareParamService costShareParamService, CostIncomeGroupService costIncomeGroupService, RedisUtil redisUtil, JwtUtil jwtUtil) {
|
|
|
+ private final CostShareParamGroupService costShareParamGroupService;
|
|
|
+
|
|
|
+ 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) {
|
|
|
this.userService = userService;
|
|
|
this.departmentService = departmentService;
|
|
|
this.productService = productService;
|
|
@@ -73,6 +74,8 @@ public class ExcelController {
|
|
|
this.costShareParamService = costShareParamService;
|
|
|
this.costIncomeGroupService = costIncomeGroupService;
|
|
|
this.jwtUtil = jwtUtil;
|
|
|
+ this.costCostingGroupService = costCostingGroupService;
|
|
|
+ this.costShareParamGroupService = costShareParamGroupService;
|
|
|
}
|
|
|
|
|
|
@ApiOperation("用户导出模板设置")
|
|
@@ -309,35 +312,44 @@ public class ExcelController {
|
|
|
*/
|
|
|
@GetMapping("/getImportCostProductAccountTemplate")
|
|
|
@ApiOperation("成本数据导出模板设置")
|
|
|
- public void getImportCostProductAccountTemplate(HttpServletResponse response) throws IOException {
|
|
|
- Long hospId = UserContext.getHospId();
|
|
|
+ public void getImportCostProductAccountTemplate(HttpServletResponse response,String token) throws IOException {
|
|
|
+ int userId = jwtUtil.getUserId(token);
|
|
|
+ User user = userService.getById(userId);
|
|
|
+ if (Objects.isNull(user)){
|
|
|
+ throw new CostException(500,"用户不存在");
|
|
|
+ }
|
|
|
+ Long hospId = user.getHospId();
|
|
|
String uuid = UUID.randomUUID().toString();
|
|
|
String url = System.getProperty("java.io.tmpdir") + File.separator + uuid + File.separator + uuid + ".xls";
|
|
|
FileUtil.del(FileUtil.file(url));
|
|
|
|
|
|
ExcelWriter writer = new ExcelWriter(url);
|
|
|
// 样式
|
|
|
- Sheet sheet = writer.getSheet();
|
|
|
- writer.merge(0, 1, 0, 6, "为了保证成功导入,请勿修改模板格式", false);
|
|
|
- writer.passCurrentRow();
|
|
|
- writer.passCurrentRow();
|
|
|
- writer.merge(2, 2, 0, 6, "医院成本数据批量导入", false);
|
|
|
- writer.passCurrentRow();
|
|
|
// 所有科室里面对应存在责任中心对应的科室
|
|
|
List<Department> departmentLinkedList = getDepartments(hospId);
|
|
|
// 设置科室的代码集合
|
|
|
List<String> departmentCodeList = departmentLinkedList.stream().map(Department::getDepartmentCode).collect(Collectors.toList());
|
|
|
List<String> departmentNameList = departmentLinkedList.stream().map(Department::getDepartmentName).collect(Collectors.toList());
|
|
|
+ Sheet sheet = writer.getSheet();
|
|
|
+ writer.merge(0, 1, 0, departmentCodeList.size()==0?3:departmentCodeList.size()+2, "为了保证成功导入,请勿修改模板格式", false);
|
|
|
+ writer.passCurrentRow();
|
|
|
+ writer.passCurrentRow();
|
|
|
+ writer.merge(2, 2, 0, departmentCodeList.size()==0?3:departmentCodeList.size()+2, "医院成本数据批量导入", false);
|
|
|
+ writer.passCurrentRow();
|
|
|
+ writer.merge(3,3,2,departmentCodeList.size()==0?3:departmentCodeList.size()+2,"科室",false);
|
|
|
+ writer.passCurrentRow();
|
|
|
departmentCodeList.add(0, null);
|
|
|
departmentCodeList.add(1, null);
|
|
|
+ departmentCodeList.add("-1");
|
|
|
writer.writeRow(departmentCodeList);
|
|
|
departmentNameList.add(0, "成本项目代码");
|
|
|
departmentNameList.add(1, "成本项目名称");
|
|
|
+ departmentNameList.add("总计");
|
|
|
writer.writeRow(departmentNameList);
|
|
|
// 设置科室名称的集合
|
|
|
writer.setFreezePane(5);
|
|
|
int accountType = NumberConstant.TWO;
|
|
|
- int column = NumberConstant.FIVE;
|
|
|
+ int column = NumberConstant.SIX;
|
|
|
getProductByAccountType(hospId, writer, accountType, column);
|
|
|
writer.setColumnWidth(0, 15);
|
|
|
writer.setColumnWidth(1, 15);
|
|
@@ -379,10 +391,10 @@ public class ExcelController {
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
- // 写入响应第一列 第二列的数据
|
|
|
+ // 写入响应第二列 第三列的数据
|
|
|
for (int j = 0; j < products.size(); j++) {
|
|
|
- writer.writeCellValue(0, j + column, productList.get(j).getProductCode());
|
|
|
- writer.writeCellValue(1, j + column, productList.get(j).getProductName());
|
|
|
+ writer.writeCellValue(0, j + column, products.get(j).getProductCode());
|
|
|
+ writer.writeCellValue(1, j + column, products.get(j).getProductName());
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -391,25 +403,33 @@ public class ExcelController {
|
|
|
*/
|
|
|
@GetMapping("/getShareParamTemplate")
|
|
|
@ApiOperation("成本分摊参数导出模板")
|
|
|
- public void getShareParamTemplate(HttpServletResponse response) throws IOException {
|
|
|
- Long hospId = UserContext.getHospId();
|
|
|
+ public void getShareParamTemplate(HttpServletResponse response,String token) throws IOException {
|
|
|
+ int userId = jwtUtil.getUserId(token);
|
|
|
+ User user = userService.getById(userId);
|
|
|
+ if (Objects.isNull(user)){
|
|
|
+ throw new CostException(500,"用户不存在");
|
|
|
+ }
|
|
|
+ Long hospId = user.getHospId();
|
|
|
String uuid = UUID.randomUUID().toString();
|
|
|
String url = System.getProperty("java.io.tmpdir") + File.separator + uuid + File.separator + uuid + ".xls";
|
|
|
FileUtil.del(FileUtil.file(url));
|
|
|
|
|
|
ExcelWriter writer = new ExcelWriter(url);
|
|
|
// 样式
|
|
|
- Sheet sheet = writer.getSheet();
|
|
|
- writer.merge(0, 1, 0, 6, "为了保证成功导入,请勿修改模板格式", false);
|
|
|
- writer.passCurrentRow();
|
|
|
- writer.passCurrentRow();
|
|
|
- writer.merge(2, 2, 0, 6, "医院成本分摊参数数据批量导入", false);
|
|
|
- writer.passCurrentRow();
|
|
|
// 所有科室里面对应存在责任中心对应的科室进行显示
|
|
|
List<Department> departmentLinkedList = getDepartments(hospId);
|
|
|
// 设置科室的代码集合
|
|
|
List<String> departmentCodeList = departmentLinkedList.stream().map(Department::getDepartmentCode).collect(Collectors.toList());
|
|
|
List<String> departmentNameList = departmentLinkedList.stream().map(Department::getDepartmentName).collect(Collectors.toList());
|
|
|
+ List<CostShareParam> costShareParamList = costShareParamService.list(new QueryWrapper<CostShareParam>().lambda().eq(CostShareParam::getHospId, hospId));
|
|
|
+ Sheet sheet = writer.getSheet();
|
|
|
+ writer.merge(0, 1, 0, departmentCodeList.size()==0?3:departmentCodeList.size()+1, "为了保证成功导入,请勿修改模板格式", false);
|
|
|
+ writer.passCurrentRow();
|
|
|
+ writer.passCurrentRow();
|
|
|
+ writer.merge(2, 2, 0, departmentCodeList.size()==0?3:departmentCodeList.size()+1, "医院成本分摊参数数据批量导入", false);
|
|
|
+ writer.passCurrentRow();
|
|
|
+ writer.merge(3,3,2,departmentCodeList.size()==0?3:departmentCodeList.size()+1,"科室",false);
|
|
|
+ writer.passCurrentRow();
|
|
|
departmentCodeList.add(0, null);
|
|
|
departmentCodeList.add(1, null);
|
|
|
writer.writeRow(departmentCodeList);
|
|
@@ -419,13 +439,13 @@ public class ExcelController {
|
|
|
// 设置科室名称的集合
|
|
|
writer.setFreezePane(5);
|
|
|
// 为第一列和第二列设置成本分摊参数的列表数据
|
|
|
- List<CostShareParam> costShareParamList = costShareParamService.list(new QueryWrapper<CostShareParam>().lambda().eq(CostShareParam::getHospId, hospId));
|
|
|
+
|
|
|
for (int j = 0; j < costShareParamList.size(); j++) {
|
|
|
- writer.writeCellValue(0, j + 5, costShareParamList.get(j).getShareParamCode());
|
|
|
- writer.writeCellValue(1, j + 5, costShareParamList.get(j).getShareParamName());
|
|
|
+ writer.writeCellValue(0, j + 6, costShareParamList.get(j).getShareParamCode());
|
|
|
+ writer.writeCellValue(1, j + 6, costShareParamList.get(j).getShareParamName());
|
|
|
}
|
|
|
writer.setColumnWidth(0, 15);
|
|
|
- writer.setColumnWidth(1, 15);
|
|
|
+ writer.setColumnWidth(1, 22);
|
|
|
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
|
|
|
response.setHeader("Content-Disposition", "attachment;filename=" + uuid + ".xls");
|
|
|
ServletOutputStream out = null;
|
|
@@ -458,12 +478,11 @@ public class ExcelController {
|
|
|
* @param
|
|
|
*/
|
|
|
@PostMapping("/importDataByFileType")
|
|
|
- @ApiOperation("批量导入指定类型数据信息")
|
|
|
+ @ApiOperation("收入数据导入")
|
|
|
public Result importProductAccount(@RequestParam("file") MultipartFile file ,Integer fileType,String dateTime) {
|
|
|
if (Objects.isNull(file)) {
|
|
|
throw new CostException(500, "请选择文件");
|
|
|
}
|
|
|
-
|
|
|
InputStream in;
|
|
|
// 导入的是收入数据
|
|
|
try {
|
|
@@ -480,34 +499,49 @@ public class ExcelController {
|
|
|
throw new CostException(500, "导入失败");
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-// @ApiOperation("excel导入收入数据")
|
|
|
-// @PostMapping("/importDataByIncomeData")
|
|
|
-// public Result importDataByIncomeData(@RequestParam("file") MultipartFile file, Integer year, Integer month) {
|
|
|
-// if (Objects.isNull(year) || Objects.isNull(month)) {
|
|
|
-// DateTime dateTime = DateUtil.lastMonth();
|
|
|
-// year = DateUtil.year(dateTime);
|
|
|
-// month = DateUtil.month(dateTime);
|
|
|
-// }
|
|
|
-// if (Objects.isNull(file)) {
|
|
|
-// throw new CostException(500, "请选择文件");
|
|
|
-// }
|
|
|
-// InputStream in;
|
|
|
-// // 导入的是收入数据
|
|
|
-// try {
|
|
|
-// in = file.getInputStream();
|
|
|
-// ExcelReader reader = ExcelUtil.getReader(in);
|
|
|
-// List<List<Object>> read = reader.read();
|
|
|
-// log.info("最开始:read={}", read);
|
|
|
-// log.info("-------------------------------------------------------------------");
|
|
|
-// User user = UserContext.getCurrentUser();
|
|
|
-// return costIncomeGroupService.importDataByIncomeData(read, user, file, year, month);
|
|
|
-// } catch (IOException e) {
|
|
|
-// e.printStackTrace();
|
|
|
-// ;
|
|
|
-// throw new CostException(500, "导入失败");
|
|
|
-// }
|
|
|
-//
|
|
|
-// }
|
|
|
+ @PostMapping("/importCostingGroup")
|
|
|
+ @ApiOperation("成本数据导入")
|
|
|
+ public Result importCostingGroup(@RequestParam("file") MultipartFile file ,Integer fileType,String dateTime) {
|
|
|
+ if (Objects.isNull(file)) {
|
|
|
+ throw new CostException(500, "请选择文件");
|
|
|
+ }
|
|
|
+ InputStream in;
|
|
|
+ // 导入的是收入数据
|
|
|
+ try {
|
|
|
+ in = file.getInputStream();
|
|
|
+ ExcelReader reader = ExcelUtil.getReader(in);
|
|
|
+ List<List<Object>> read = reader.read();
|
|
|
+ log.info("最开始:read={}", read);
|
|
|
+ log.info("-------------------------------------------------------------------");
|
|
|
+ User user = UserContext.getCurrentUser();
|
|
|
+ return costCostingGroupService.importCostingGroup(read, user, file, dateTime,fileType);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ ;
|
|
|
+ throw new CostException(500, "导入失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ @PostMapping("/importShareParamGroup")
|
|
|
+ @ApiOperation("成本分摊参数导入")
|
|
|
+ public Result importShareParamGroup(@RequestParam("file") MultipartFile file ,Integer fileType,String dateTime){
|
|
|
+ if (Objects.isNull(file)) {
|
|
|
+ throw new CostException(500, "请选择文件");
|
|
|
+ }
|
|
|
+ InputStream in;
|
|
|
+ // 导入的是收入数据
|
|
|
+ try {
|
|
|
+ in = file.getInputStream();
|
|
|
+ ExcelReader reader = ExcelUtil.getReader(in);
|
|
|
+ List<List<Object>> read = reader.read();
|
|
|
+ log.info("最开始:read={}", read);
|
|
|
+ log.info("-------------------------------------------------------------------");
|
|
|
+ User user = UserContext.getCurrentUser();
|
|
|
+ return costShareParamGroupService.importShareParamGroup(read, user, file, dateTime,fileType);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ ;
|
|
|
+ throw new CostException(500, "导入失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
}
|