|
@@ -60,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;
|
|
@@ -71,6 +74,8 @@ public class ExcelController {
|
|
|
this.costShareParamService = costShareParamService;
|
|
|
this.costIncomeGroupService = costIncomeGroupService;
|
|
|
this.jwtUtil = jwtUtil;
|
|
|
+ this.costCostingGroupService = costCostingGroupService;
|
|
|
+ this.costShareParamGroupService = costShareParamGroupService;
|
|
|
}
|
|
|
|
|
|
@ApiOperation("用户导出模板设置")
|
|
@@ -307,8 +312,13 @@ 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));
|
|
@@ -321,29 +331,26 @@ public class ExcelController {
|
|
|
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, 6, "为了保证成功导入,请勿修改模板格式", false);
|
|
|
+ writer.merge(0, 1, 0, departmentCodeList.size()==0?3:departmentCodeList.size()+2, "为了保证成功导入,请勿修改模板格式", false);
|
|
|
writer.passCurrentRow();
|
|
|
writer.passCurrentRow();
|
|
|
- writer.merge(2, 2, 0, 6, "医院成本数据批量导入", false);
|
|
|
+ writer.merge(2, 2, 0, departmentCodeList.size()==0?3:departmentCodeList.size()+2, "医院成本数据批量导入", false);
|
|
|
writer.passCurrentRow();
|
|
|
- writer.merge(3,3,2,departmentCodeList.size(),"科室",false);
|
|
|
+ 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(2, null);
|
|
|
departmentCodeList.add("-1");
|
|
|
writer.writeRow(departmentCodeList);
|
|
|
- departmentNameList.add(0, null);
|
|
|
- departmentNameList.add(1, "成本项目代码");
|
|
|
- departmentNameList.add(2, "成本项目名称");
|
|
|
+ departmentNameList.add(0, "成本项目代码");
|
|
|
+ departmentNameList.add(1, "成本项目名称");
|
|
|
departmentNameList.add("总计");
|
|
|
writer.writeRow(departmentNameList);
|
|
|
// 设置科室名称的集合
|
|
|
writer.setFreezePane(5);
|
|
|
int accountType = NumberConstant.TWO;
|
|
|
- int column = NumberConstant.FIVE;
|
|
|
- List<Product> productList = getProductByAccountType(hospId, writer, accountType, column);
|
|
|
- writer.merge(6,productList.size(),0,0,"成本项目",false);
|
|
|
+ int column = NumberConstant.SIX;
|
|
|
+ getProductByAccountType(hospId, writer, accountType, column);
|
|
|
writer.setColumnWidth(0, 15);
|
|
|
writer.setColumnWidth(1, 15);
|
|
|
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
|
|
@@ -363,7 +370,7 @@ public class ExcelController {
|
|
|
* @param accountType 会计科目类型 1 收入 2支出(成本)
|
|
|
* @param column 控制第几列
|
|
|
*/
|
|
|
- private List<Product> getProductByAccountType(Long hospId, ExcelWriter writer, Integer accountType, Integer column) {
|
|
|
+ private void getProductByAccountType(Long hospId, ExcelWriter writer, Integer accountType, Integer column) {
|
|
|
// 所有的成本项目
|
|
|
List<Product> productList = productService.list(new QueryWrapper<Product>().lambda().eq(Product::getHospId, hospId));
|
|
|
// 所有成本会计对照数据
|
|
@@ -384,12 +391,11 @@ public class ExcelController {
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
- // 写入响应第一列 第二列的数据
|
|
|
+ // 写入响应第二列 第三列的数据
|
|
|
for (int j = 0; j < products.size(); j++) {
|
|
|
- writer.writeCellValue(1, j + column, productList.get(j).getProductCode());
|
|
|
- writer.writeCellValue(2, j + column, productList.get(j).getProductName());
|
|
|
+ writer.writeCellValue(0, j + column, products.get(j).getProductCode());
|
|
|
+ writer.writeCellValue(1, j + column, products.get(j).getProductName());
|
|
|
}
|
|
|
- return productList;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -397,8 +403,13 @@ 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));
|
|
@@ -412,32 +423,29 @@ public class ExcelController {
|
|
|
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, 6, "为了保证成功导入,请勿修改模板格式", false);
|
|
|
+ writer.merge(0, 1, 0, departmentCodeList.size()==0?3:departmentCodeList.size()+1, "为了保证成功导入,请勿修改模板格式", false);
|
|
|
writer.passCurrentRow();
|
|
|
writer.passCurrentRow();
|
|
|
- writer.merge(2, 2, 0, 6, "医院成本分摊参数数据批量导入", false);
|
|
|
+ writer.merge(2, 2, 0, departmentCodeList.size()==0?3:departmentCodeList.size()+1, "医院成本分摊参数数据批量导入", false);
|
|
|
writer.passCurrentRow();
|
|
|
- writer.merge(3,3,3,departmentCodeList.size(),"科室",false);
|
|
|
+ writer.merge(3,3,2,departmentCodeList.size()==0?3:departmentCodeList.size()+1,"科室",false);
|
|
|
writer.passCurrentRow();
|
|
|
- writer.merge(6,costShareParamList.size(),0,0,"成本分摊参数",false);
|
|
|
departmentCodeList.add(0, null);
|
|
|
departmentCodeList.add(1, null);
|
|
|
- departmentCodeList.add(2, null);
|
|
|
writer.writeRow(departmentCodeList);
|
|
|
- departmentNameList.add(0, null);
|
|
|
- departmentNameList.add(1, "成本分摊参数代码");
|
|
|
- departmentNameList.add(2, "成本分摊参数名称");
|
|
|
+ departmentNameList.add(0, "成本分摊参数代码");
|
|
|
+ departmentNameList.add(1, "成本分摊参数名称");
|
|
|
writer.writeRow(departmentNameList);
|
|
|
// 设置科室名称的集合
|
|
|
writer.setFreezePane(5);
|
|
|
// 为第一列和第二列设置成本分摊参数的列表数据
|
|
|
|
|
|
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;
|
|
@@ -506,11 +514,34 @@ public class ExcelController {
|
|
|
log.info("最开始:read={}", read);
|
|
|
log.info("-------------------------------------------------------------------");
|
|
|
User user = UserContext.getCurrentUser();
|
|
|
- return costIncomeGroupService.importIncomeGroup(read, user, file, dateTime,fileType);
|
|
|
+ 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, "导入失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|