浏览代码

08 10 03 add collect data codes

hr 4 年之前
父节点
当前提交
1ce43b755d

+ 11 - 0
src/main/java/com/imed/costaccount/service/CostIncomeGroupService.java

@@ -37,5 +37,16 @@ public interface CostIncomeGroupService extends IService<CostIncomeGroup> {
      * @return
      */
     Result importIncomeGroup(List<List<Object>> read, User user, MultipartFile file, Integer year, Integer month);
+
+    /**
+     * 导入收入数据
+     * @param read 读取到的初始数据
+     * @param user 当前登录用户
+     * @param file 导入的文件
+     * @param year 年
+     * @param month 月
+     * @return {@link Result}
+     */
+    Result importDataByIncomeData(List<List<Object>> read, User user, MultipartFile file, Integer year, Integer month);
 }
 

+ 32 - 5
src/main/java/com/imed/costaccount/service/impl/CostIncomeGroupServiceImpl.java

@@ -103,6 +103,7 @@ public class CostIncomeGroupServiceImpl extends ServiceImpl<CostIncomeGroupMappe
         AtomicReference<BigDecimal> totalAmount= null;
         costIncomeGroupAllAmountVoS.forEach(i -> {
             String allMoney = i.getAllMoney();
+
             if (allMoney.contains(StrUtil.COMMA)) {
                 // 存在,在进行求和
                 long sum;
@@ -131,11 +132,7 @@ public class CostIncomeGroupServiceImpl extends ServiceImpl<CostIncomeGroupMappe
     public Result importIncomeGroup(List<List<Object>> list, User user, MultipartFile file,Integer year,Integer month) {
         Long hospId = user.getHospId();
         // 移除前几行的抬头内容  list的大小对应的就是行数的大小
-        for (int i = list.size() - 1; i >= 0; i--) {
-            if (i == NumberConstant.ZERO || i == NumberConstant.ONE || i == NumberConstant.TWO || i == NumberConstant.THREE) {
-                list.remove(list.get(i));
-            }
-        }
+        this.removeTitle(list);
         log.info("读取的数据为:{}", list);
         List<IncomeErrorMessage> incomeErrorMessageList = new ArrayList<>();
         //获取所有的科室 成本项目 责任中心 会计科目
@@ -193,6 +190,14 @@ public class CostIncomeGroupServiceImpl extends ServiceImpl<CostIncomeGroupMappe
         return Result.ok();
     }
 
+    private void removeTitle(List<List<Object>> list) {
+        for (int i = list.size() - 1; i >= 0; i--) {
+            if (i == NumberConstant.ZERO || i == NumberConstant.ONE || i == NumberConstant.TWO || i == NumberConstant.THREE) {
+                list.remove(list.get(i));
+            }
+        }
+    }
+
     /**
      * 检验数据
      *  @param list                     表单数据
@@ -390,4 +395,26 @@ public class CostIncomeGroupServiceImpl extends ServiceImpl<CostIncomeGroupMappe
         }
         return FILE_PATH + hospId + StrUtil.SLASH + fileName;
     }
+
+
+    /**
+     * 导入收入数据
+     *
+     * @param read  读取到的初始数据
+     * @param user  当前登录用户
+     * @param file  导入的文件
+     * @param year  年
+     * @param month 月
+     * @return {@link Result}
+     */
+    @Override
+    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
+    public Result importDataByIncomeData(List<List<Object>> read, User user, MultipartFile file, Integer year, Integer month) {
+        // todo 文件上传
+
+        // 去掉头部的
+        this.removeTitle(read);
+
+        return null;
+    }
 }

+ 114 - 68
src/main/java/com/imed/costaccount/web/ExcelController.java

@@ -1,6 +1,8 @@
 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;
@@ -88,7 +90,7 @@ public class ExcelController {
         writer.passCurrentRow();
         writer.merge(2, 2, 0, 4, "测试医院用户导入", false);
         writer.passCurrentRow();
-        writer.writeRow(Arrays.asList("院区","姓名", "工号", "密码","手机号码"));
+        writer.writeRow(Arrays.asList("院区", "姓名", "工号", "密码", "手机号码"));
 
         // 写入响应
         response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
@@ -109,7 +111,7 @@ public class ExcelController {
             in = file.getInputStream();
             ExcelReader reader = ExcelUtil.getReader(in);
             List<List<Object>> read = reader.read();
-            log.info("最开始:read={}",read);
+            log.info("最开始:read={}", read);
             log.info("-------------------------------假装我是个分割线------------------------------------");
             User user = (User) SecurityUtils.getSubject().getPrincipal();
             return userService.importUser(read, user);
@@ -118,6 +120,7 @@ public class ExcelController {
             throw new CostException(500, "导入失败");
         }
     }
+
     /**
      * 科室模板导出功能设置
      */
@@ -138,10 +141,10 @@ public class ExcelController {
         writer.passCurrentRow();
         writer.merge(2, 2, 0, 2, "医院科室批量导入", false);
         writer.passCurrentRow();
-        writer.setColumnWidth(0,20);
-        writer.setColumnWidth(1,15);
-        writer.setColumnWidth(2,15);
-        writer.writeRow(Arrays.asList("院区","科室名称", "科室代码"));
+        writer.setColumnWidth(0, 20);
+        writer.setColumnWidth(1, 15);
+        writer.setColumnWidth(2, 15);
+        writer.writeRow(Arrays.asList("院区", "科室名称", "科室代码"));
 
         // 写入响应
         response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
@@ -153,29 +156,32 @@ public class ExcelController {
         writer.close();
         IoUtil.close(out);
     }
+
     /**
      * 批量导入科室信息
      */
     @PostMapping("/importDepartment")
     @ApiOperation("导入科室信息")
-    public Result importDepartment(@RequestParam("file") MultipartFile file){
+    public Result importDepartment(@RequestParam("file") MultipartFile file) {
         InputStream in;
         try {
             in = file.getInputStream();
             ExcelReader reader = ExcelUtil.getReader(in);
             List<List<Object>> read = reader.read();
-            log.info("最开始:read={}",read);
+            log.info("最开始:read={}", read);
             log.info("-------------------------------------------------------------------");
             User user = (User) SecurityUtils.getSubject().getPrincipal();
             Long hospId = user.getHospId();
             return departmentService.importDepartment(read, hospId);
-        }catch (IOException e){
-            e.printStackTrace();;
+        } catch (IOException e) {
+            e.printStackTrace();
+            ;
             throw new CostException(500, "导入失败");
         }
     }
+
     /**
-     *  收入成本项目批量导入模板
+     * 收入成本项目批量导入模板
      */
     @ApiOperation("成本项目导出模板设置")
     @GetMapping("/getImportProductTemplate")
@@ -194,10 +200,10 @@ public class ExcelController {
         writer.passCurrentRow();
         writer.merge(2, 2, 0, 2, "医院成本收入批量导入", false);
         writer.passCurrentRow();
-        writer.setColumnWidth(0,20);
-        writer.setColumnWidth(1,15);
-        writer.setColumnWidth(2,15);
-        writer.writeRow(Arrays.asList("院区","成本项目名", "成本项目编号"));
+        writer.setColumnWidth(0, 20);
+        writer.setColumnWidth(1, 15);
+        writer.setColumnWidth(2, 15);
+        writer.writeRow(Arrays.asList("院区", "成本项目名", "成本项目编号"));
 
         // 写入响应
         response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
@@ -209,27 +215,30 @@ public class ExcelController {
         writer.close();
         IoUtil.close(out);
     }
+
     /**
-     *  收入成本项目批量导入
+     * 收入成本项目批量导入
      */
     @PostMapping("/importProduct")
     @ApiOperation("批量导入成本项目信息")
-    public Result importProduct(@RequestParam("file") MultipartFile file){
+    public Result importProduct(@RequestParam("file") MultipartFile file) {
         InputStream in;
         try {
             in = file.getInputStream();
             ExcelReader reader = ExcelUtil.getReader(in);
             List<List<Object>> read = reader.read();
-            log.info("最开始:read={}",read);
+            log.info("最开始:read={}", read);
             log.info("-------------------------------------------------------------------");
             User user = (User) SecurityUtils.getSubject().getPrincipal();
             Long hospId = user.getHospId();
             return productService.importProduct(read, hospId);
-        }catch (IOException e){
-            e.printStackTrace();;
+        } catch (IOException e) {
+            e.printStackTrace();
+            ;
             throw new CostException(500, "导入失败");
         }
     }
+
     /**
      * 收入成本数据导出模板
      */
@@ -252,17 +261,17 @@ public class ExcelController {
         writer.passCurrentRow();
         // 冻结前四行
         writer.setFreezePane(4);
-        writer.writeRow(Arrays.asList("成本项目代码","成本项目名称","开单科室","开单科室代码", "执行科室","执行科室代码","金额"));
-        int accountType=NumberConstant.ONE;
-        int column=NumberConstant.FOUR;
-        getProductByAccountType(hospId, writer,accountType,column);
-        writer.setColumnWidth(0,20);
-        writer.setColumnWidth(1,20);
-        writer.setColumnWidth(2,20);
-        writer.setColumnWidth(3,20);
-        writer.setColumnWidth(4,20);
-        writer.setColumnWidth(5,20);
-        writer.setColumnWidth(6,20);
+        writer.writeRow(Arrays.asList("成本项目代码", "成本项目名称", "开单科室", "开单科室代码", "执行科室", "执行科室代码", "金额"));
+        int accountType = NumberConstant.ONE;
+        int column = NumberConstant.FOUR;
+        getProductByAccountType(hospId, writer, accountType, column);
+        writer.setColumnWidth(0, 20);
+        writer.setColumnWidth(1, 20);
+        writer.setColumnWidth(2, 20);
+        writer.setColumnWidth(3, 20);
+        writer.setColumnWidth(4, 20);
+        writer.setColumnWidth(5, 20);
+        writer.setColumnWidth(6, 20);
         response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
         response.setHeader("Content-Disposition", "attachment;filename=" + uuid + ".xls");
         ServletOutputStream out = null;
@@ -271,6 +280,7 @@ public class ExcelController {
         writer.close();
         IoUtil.close(out);
     }
+
     /**
      * 成本数据导出模板
      */
@@ -295,19 +305,19 @@ 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());
-        departmentCodeList.add(0,null);
-        departmentCodeList.add(1,null);
+        departmentCodeList.add(0, null);
+        departmentCodeList.add(1, null);
         writer.writeRow(departmentCodeList);
-        departmentNameList.add(0,"成本项目代码");
-        departmentNameList.add(1,"成本项目名称");
+        departmentNameList.add(0, "成本项目代码");
+        departmentNameList.add(1, "成本项目名称");
         writer.writeRow(departmentNameList);
         // 设置科室名称的集合
         writer.setFreezePane(5);
-        int accountType=NumberConstant.TWO;
-        int column=NumberConstant.FIVE;
-        getProductByAccountType(hospId, writer,accountType,column);
-        writer.setColumnWidth(0,15);
-        writer.setColumnWidth(1,15);
+        int accountType = NumberConstant.TWO;
+        int column = NumberConstant.FIVE;
+        getProductByAccountType(hospId, writer, accountType, column);
+        writer.setColumnWidth(0, 15);
+        writer.setColumnWidth(1, 15);
         response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
         response.setHeader("Content-Disposition", "attachment;filename=" + uuid + ".xls");
         ServletOutputStream out = null;
@@ -316,14 +326,16 @@ public class ExcelController {
         writer.close();
         IoUtil.close(out);
     }
+
     /**
      * 获取执行类型的成本项目
-     * @param hospId 医院Id
-     * @param writer 操作流
+     *
+     * @param hospId      医院Id
+     * @param writer      操作流
      * @param accountType 会计科目类型 1 收入  2支出(成本)
-     * @param column 控制第几列
+     * @param column      控制第几列
      */
-    private void 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));
         // 所有成本会计对照数据
@@ -333,29 +345,30 @@ public class ExcelController {
         List<Product> products = new ArrayList<>();
         Map<Long, List<AccountingProduct>> accountProductMap = accountingProductList.stream().collect(Collectors.groupingBy(AccountingProduct::getProductId));
         Map<Long, List<Accounting>> accountMap = accountingList.stream().collect(Collectors.groupingBy(Accounting::getId));
-        productList.forEach(i->{
+        productList.forEach(i -> {
             Long productId = i.getId();
             List<AccountingProduct> accountingProducts = accountProductMap.get(productId);
-            if (CollUtil.isNotEmpty(accountingProducts)){
+            if (CollUtil.isNotEmpty(accountingProducts)) {
                 Long accountingId = accountingProducts.get(0).getAccountingId();
                 List<Accounting> accountings = accountMap.get(accountingId);
-                if (CollUtil.isNotEmpty(accountings) && accountType.equals(accountings.get(0).getAccountingType())){
+                if (CollUtil.isNotEmpty(accountings) && accountType.equals(accountings.get(0).getAccountingType())) {
                     products.add(i);
                 }
             }
         });
         // 写入响应第一列 第二列的数据
-        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());
+        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());
         }
     }
+
     /**
      * 成本分摊参数导出模板
      */
     @GetMapping("/getShareParamTemplate")
     @ApiOperation("成本分摊参数导出模板")
-    public void getShareParamTemplate(HttpServletResponse response) throws IOException{
+    public void getShareParamTemplate(HttpServletResponse response) throws IOException {
         Long hospId = UserContext.getHospId();
         String uuid = UUID.randomUUID().toString();
         String url = System.getProperty("java.io.tmpdir") + File.separator + uuid + File.separator + uuid + ".xls";
@@ -374,22 +387,22 @@ 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());
-        departmentCodeList.add(0,null);
-        departmentCodeList.add(1,null);
+        departmentCodeList.add(0, null);
+        departmentCodeList.add(1, null);
         writer.writeRow(departmentCodeList);
-        departmentNameList.add(0,"成本分摊参数代码");
-        departmentNameList.add(1,"成本分摊参数名称");
+        departmentNameList.add(0, "成本分摊参数代码");
+        departmentNameList.add(1, "成本分摊参数名称");
         writer.writeRow(departmentNameList);
         // 设置科室名称的集合
         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());
+        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.setColumnWidth(0,15);
-        writer.setColumnWidth(1,15);
+        writer.setColumnWidth(0, 15);
+        writer.setColumnWidth(1, 15);
         response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
         response.setHeader("Content-Disposition", "attachment;filename=" + uuid + ".xls");
         ServletOutputStream out = null;
@@ -415,15 +428,17 @@ public class ExcelController {
         });
         return departmentLinkedList;
     }
+
     /**
-     *  导入 收入数据导入
+     * 导入 收入数据导入
+     *
      * @param file 导入的文件
      */
     @PostMapping("/importDataByFileType")
     @ApiOperation("批量导入指定类型数据信息")
-    public Result importProductAccount(@RequestParam("file") MultipartFile file,Integer year,Integer month){
-        if (Objects.isNull(file)){
-            throw new CostException(500,"请选择文件");
+    public Result importProductAccount(@RequestParam("file") MultipartFile file, Integer year, Integer month) {
+        if (Objects.isNull(file)) {
+            throw new CostException(500, "请选择文件");
         }
         InputStream in;
         // 导入的是收入数据
@@ -431,13 +446,44 @@ public class ExcelController {
             in = file.getInputStream();
             ExcelReader reader = ExcelUtil.getReader(in);
             List<List<Object>> read = reader.read();
-            log.info("最开始:read={}",read);
+            log.info("最开始:read={}", read);
             log.info("-------------------------------------------------------------------");
             User user = UserContext.getCurrentUser();
-            return costIncomeGroupService.importIncomeGroup(read, user,file,year,month);
-        }catch (IOException e){
-            e.printStackTrace();;
+            return costIncomeGroupService.importIncomeGroup(read, user, file, year, month);
+        } catch (IOException e) {
+            e.printStackTrace();
+            ;
             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, "导入失败");
+        }
+
+    }
+
 }