ljx 4 years ago
parent
commit
943ec65ca0

+ 65 - 0
src/main/java/com/imed/costaccount/model/BASE64DecodedMultipartFile.java

@@ -0,0 +1,65 @@
+package com.imed.costaccount.model;
+
+import org.springframework.web.multipart.MultipartFile;
+
+import java.io.*;
+
+/**
+ * @author 李加喜
+ * @Package com.imed.costaccount.model
+ * @date 2021-08-27 18:54
+ */
+public class BASE64DecodedMultipartFile implements MultipartFile {
+
+    private final byte[] imgContent;
+    private final String header;
+
+    public BASE64DecodedMultipartFile(byte[] imgContent, String header) {
+        this.imgContent = imgContent;
+        this.header = header.split(";")[0];
+    }
+
+    @Override
+    public String getName() {
+        // TODO - implementation depends on your requirements
+        return System.currentTimeMillis() + Math.random() + "." + header.split("/")[1];
+    }
+
+    @Override
+    public String getOriginalFilename() {
+        // TODO - implementation depends on your requirements
+        return System.currentTimeMillis() + (int)Math.random() * 10000 + "." + header.split("/")[1];
+    }
+
+    @Override
+    public String getContentType() {
+        // TODO - implementation depends on your requirements
+        return header.split(":")[1];
+    }
+
+    @Override
+    public boolean isEmpty() {
+        return imgContent == null || imgContent.length == 0;
+    }
+
+    @Override
+    public long getSize() {
+        return imgContent.length;
+    }
+
+    @Override
+    public byte[] getBytes() throws IOException {
+        return imgContent;
+    }
+
+    @Override
+    public InputStream getInputStream() throws IOException {
+        return new ByteArrayInputStream(imgContent);
+    }
+
+    @Override
+    public void transferTo(File dest) throws IOException, IllegalStateException {
+        new FileOutputStream(dest).write(imgContent);
+    }
+}
+

+ 10 - 0
src/main/java/com/imed/costaccount/service/CostDepartmentProfitService.java

@@ -1,8 +1,10 @@
 package com.imed.costaccount.service;
 package com.imed.costaccount.service;
 
 
+import cn.hutool.poi.excel.ExcelWriter;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.imed.costaccount.common.util.PageUtils;
 import com.imed.costaccount.common.util.PageUtils;
 import com.imed.costaccount.model.CostDepartmentProfit;
 import com.imed.costaccount.model.CostDepartmentProfit;
+import org.apache.poi.ss.usermodel.Sheet;
 
 
 /**
 /**
  * 科室损益计算
  * 科室损益计算
@@ -29,5 +31,13 @@ public interface CostDepartmentProfitService extends IService<CostDepartmentProf
      * @param hospId
      * @param hospId
      */
      */
     void setDepartmentProfit(String date, Long hospId);
     void setDepartmentProfit(String date, Long hospId);
+
+    /**
+     * 科室损益计算导出
+     * @param writer
+     * @param sheet
+     * @param date
+     */
+    void getDepartmentProfit(ExcelWriter writer, Sheet sheet, String date);
 }
 }
 
 

+ 5 - 1
src/main/java/com/imed/costaccount/service/impl/AllocationServiceImpl.java

@@ -21,6 +21,7 @@ import com.imed.costaccount.model.vo.*;
 import com.imed.costaccount.service.*;
 import com.imed.costaccount.service.*;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.poi.ss.usermodel.Sheet;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Propagation;
 import org.springframework.transaction.annotation.Propagation;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.transaction.annotation.Transactional;
@@ -33,8 +34,11 @@ import java.util.stream.Collectors;
 @Slf4j
 @Slf4j
 @Service("allocationService")
 @Service("allocationService")
 public class AllocationServiceImpl extends ServiceImpl<AllocationMapper, Allocation> implements AllocationService {
 public class AllocationServiceImpl extends ServiceImpl<AllocationMapper, Allocation> implements AllocationService {
+    @Value("${file.serverPath}")
+    private String fileTempPath;
 
 
-    private final CostCostingGroupService costCostingGroupService;
+    @Value("${file.serverUrl}")
+    private String FILE_PATH;    private final CostCostingGroupService costCostingGroupService;
     private final CostShareLevelService shareLevelService;
     private final CostShareLevelService shareLevelService;
     private final ResponsibilityService responsibilityService;
     private final ResponsibilityService responsibilityService;
     private final CostAccountShareService accountShareService;
     private final CostAccountShareService accountShareService;

+ 32 - 0
src/main/java/com/imed/costaccount/service/impl/CostDepartmentProfitServiceImpl.java

@@ -22,6 +22,8 @@ import com.imed.costaccount.model.vo.CostDepartmentProfitVO;
 import com.imed.costaccount.service.*;
 import com.imed.costaccount.service.*;
 import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.poi.ss.usermodel.Sheet;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Propagation;
+import org.springframework.transaction.annotation.Transactional;
 
 
 import java.math.BigDecimal;
 import java.math.BigDecimal;
 import java.util.*;
 import java.util.*;
@@ -97,6 +99,7 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
      * @param hospId
      * @param hospId
      */
      */
     @Override
     @Override
+    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
     public void setDepartmentProfit(String date, Long hospId) {
     public void setDepartmentProfit(String date, Long hospId) {
         DateTime parse = DateUtil.parse(date);
         DateTime parse = DateUtil.parse(date);
         int year = DateUtil.year(parse);
         int year = DateUtil.year(parse);
@@ -204,6 +207,35 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
         this.saveBatch(costDepartmentProfits);
         this.saveBatch(costDepartmentProfits);
     }
     }
 
 
+    /**
+     * 科室损益计算导出
+     *
+     * @param writer
+     * @param sheet
+     * @param date
+     */
+    @Override
+    public void getDepartmentProfit(ExcelWriter writer, Sheet sheet, String date) {
+        int year = 0;
+        int month = 0;
+        if (StrUtil.isNotBlank(date)) {
+            Date dateTime = DateUtils.StringToDate(date, DateStyleEnum.YYYY_MM_DD);
+            year = DateUtil.year(dateTime);
+            month = DateUtil.month(dateTime) + 1;
+        }
+        Long hospId = UserContext.getHospId();
+        List<CostDepartmentProfit> costDepartmentProfitList = this.list(new QueryWrapper<CostDepartmentProfit>().lambda().eq(CostDepartmentProfit::getHospId, hospId).eq(StrUtil.isNotBlank(date), CostDepartmentProfit::getYear, year).eq(StrUtil.isNotBlank(date), CostDepartmentProfit::getMonth, month));
+        // 16个责任中心名称
+        List<String> responsibilityNameList = costDepartmentProfitList.stream().map(CostDepartmentProfit::getResponsibilityName).distinct().sorted().collect(Collectors.toList());
+        Map<String, List<CostDepartmentProfit>> responsibilityNameMap = costDepartmentProfitList.stream().collect(Collectors.groupingBy(CostDepartmentProfit::getResponsibilityName));
+        for (int i = 0; i < responsibilityNameList.size(); i++) {
+            String responsibilityName = responsibilityNameList.get(i);
+            List<CostDepartmentProfit> departmentProfits = responsibilityNameMap.get(responsibilityName);
+            writer.merge(0, 2, 0, departmentProfits.size() + 2, responsibilityName, false);
+        }
+        System.out.println(responsibilityNameList);
+    }
+
     /**
     /**
      * 按照会计科目进行计算
      * 按照会计科目进行计算
      *
      *

+ 1 - 1
src/main/java/com/imed/costaccount/service/impl/HospProfitAndLossServiceImpl.java

@@ -185,7 +185,7 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
         total.set(BigDecimal.ZERO);
         total.set(BigDecimal.ZERO);
         for (int x = 0; x < mapList.size(); x++) {
         for (int x = 0; x < mapList.size(); x++) {
             BigDecimal bigDecimal = map.get(x);
             BigDecimal bigDecimal = map.get(x);
-            if (expressionMap.get(x).equals("+")) {
+            if ("+".equals(expressionMap.get(x))) {
                 total.set(total.get().add(bigDecimal));
                 total.set(total.get().add(bigDecimal));
             } else {
             } else {
                 total.set(total.get().subtract(bigDecimal));
                 total.set(total.get().subtract(bigDecimal));

+ 2 - 5
src/main/java/com/imed/costaccount/web/CostDepartmentProfitController.java

@@ -5,10 +5,7 @@ import com.imed.costaccount.common.util.Result;
 import com.imed.costaccount.common.util.UserContext;
 import com.imed.costaccount.common.util.UserContext;
 import com.imed.costaccount.model.CostDepartmentProfit;
 import com.imed.costaccount.model.CostDepartmentProfit;
 import com.imed.costaccount.service.CostDepartmentProfitService;
 import com.imed.costaccount.service.CostDepartmentProfitService;
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiImplicitParam;
-import io.swagger.annotations.ApiImplicitParams;
-import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.*;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.bind.annotation.*;
 
 
@@ -54,7 +51,7 @@ public class CostDepartmentProfitController {
      */
      */
     @PostMapping("/setDepartmentProfit")
     @PostMapping("/setDepartmentProfit")
     @ApiOperation("进行科室损益计算")
     @ApiOperation("进行科室损益计算")
-    public Result setDepartmentProfit(@RequestBody String date){
+    public Result setDepartmentProfit(@RequestParam @ApiParam(name = "date", value = "yyyy-MM-dd") String date){
         Long hospId = UserContext.getHospId();
         Long hospId = UserContext.getHospId();
         costDepartmentProfitService.setDepartmentProfit(date,hospId);
         costDepartmentProfitService.setDepartmentProfit(date,hospId);
         return  Result.ok();
         return  Result.ok();

+ 60 - 29
src/main/java/com/imed/costaccount/web/ExcelController.java

@@ -69,11 +69,13 @@ public class ExcelController extends AbstractController{
 
 
     private final AllocationService allocationServicel;
     private final AllocationService allocationServicel;
 
 
+    private final CostDepartmentProfitService costDepartmentProfitService;
+
     public ExcelController(UserService userService, DepartmentServiceImpl departmentService, ProductServiceImpl productService,
     public ExcelController(UserService userService, DepartmentServiceImpl departmentService, ProductServiceImpl productService,
                            AccountingService accountingService, AccountingProductService accountingProductService,
                            AccountingService accountingService, AccountingProductService accountingProductService,
                            ResponsibilityDepartmentService responsibilityDepartmentService,
                            ResponsibilityDepartmentService responsibilityDepartmentService,
                            CostShareParamService costShareParamService, CostIncomeGroupService costIncomeGroupService, JwtUtil jwtUtil,
                            CostShareParamService costShareParamService, CostIncomeGroupService costIncomeGroupService, JwtUtil jwtUtil,
-                           CostCostingGroupService costCostingGroupService, ShareParamValueService shareParamValueService, CostCostingCollectionService costCostingCollectionService, AllocationService allocationServicel) {
+                           CostCostingGroupService costCostingGroupService, ShareParamValueService shareParamValueService, CostCostingCollectionService costCostingCollectionService, AllocationService allocationServicel, CostDepartmentProfitService costDepartmentProfitService) {
         this.userService = userService;
         this.userService = userService;
         this.departmentService = departmentService;
         this.departmentService = departmentService;
         this.productService = productService;
         this.productService = productService;
@@ -87,6 +89,7 @@ public class ExcelController extends AbstractController{
         this.shareParamValueService = shareParamValueService;
         this.shareParamValueService = shareParamValueService;
         this.costCostingCollectionService = costCostingCollectionService;
         this.costCostingCollectionService = costCostingCollectionService;
         this.allocationServicel = allocationServicel;
         this.allocationServicel = allocationServicel;
+        this.costDepartmentProfitService = costDepartmentProfitService;
     }
     }
 
 
     @ApiOperation("用户导出模板设置")
     @ApiOperation("用户导出模板设置")
@@ -367,34 +370,34 @@ public class ExcelController extends AbstractController{
         writer.close();
         writer.close();
         IoUtil.close(out);
         IoUtil.close(out);
     }
     }
-    /**
-     * 测试模板数据导出
-     */
-    @ApiOperation("分摊报表输出")
-    @GetMapping("/getShareReportTemplateTwo")
-    public void getShareReportTemplateTwo(HttpServletResponse response,Integer shareNumber,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= costCostingCollectionService.getShareReportTemplate(writer,shareNumber,sheet);
-        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
-        response.setHeader("Content-Disposition", "attachment;filename=" + uuid + ".xls");
-        ServletOutputStream out = null;
-        out = response.getOutputStream();
-        writer.flush(out, true);
-        writer.close();
-        IoUtil.close(out);
-
-    }
+//    /**
+//     * 测试模板数据导出
+//     */
+//    @ApiOperation("分摊报表输出")
+//    @GetMapping("/getShareReportTemplateTwo")
+//    public void getShareReportTemplateTwo(HttpServletResponse response,Integer shareNumber,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= costCostingCollectionService.getShareReportTemplate(writer,shareNumber,sheet);
+//        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
+//        response.setHeader("Content-Disposition", "attachment;filename=" + uuid + ".xls");
+//        ServletOutputStream out = null;
+//        out = response.getOutputStream();
+//        writer.flush(out, true);
+//        writer.close();
+//        IoUtil.close(out);
+//
+//    }
     @ApiOperation("分摊报表输出2.0")
     @ApiOperation("分摊报表输出2.0")
     @GetMapping("/getShareReportTemplate")
     @GetMapping("/getShareReportTemplate")
     public void getTemplate(HttpServletResponse response,Integer levelSort,String token,Integer year,Integer month) throws IOException {
     public void getTemplate(HttpServletResponse response,Integer levelSort,String token,Integer year,Integer month) throws IOException {
@@ -456,6 +459,33 @@ public class ExcelController extends AbstractController{
         }
         }
     }
     }
 
 
+    /**
+     * 成本分摊参数导出模板
+     */
+    @GetMapping("/getDepartmentProfit")
+    @ApiOperation("科室损益计算导出")
+    public void getDepartmentProfit(HttpServletResponse response,String token,String date) 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();
+        costDepartmentProfitService.getDepartmentProfit(writer,sheet,date);
+        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
+        response.setHeader("Content-Disposition", "attachment;filename=" + uuid + ".xls");
+        ServletOutputStream out = null;
+        out = response.getOutputStream();
+        writer.flush(out, true);
+        writer.close();
+        IoUtil.close(out);
+    }
+
     /**
     /**
      * 成本分摊参数导出模板
      * 成本分摊参数导出模板
      */
      */
@@ -614,4 +644,5 @@ public class ExcelController extends AbstractController{
         }
         }
     }
     }
 
 
+
 }
 }