Bläddra i källkod

科室损益计算

ljx 4 år sedan
förälder
incheckning
98ec7ba83d

+ 2 - 2
src/main/java/com/imed/costaccount/model/vo/DepartmentProfitFileVO.java

@@ -18,11 +18,11 @@ public class DepartmentProfitFileVO {
     /**
      * 年份
      */
-    private Integer year;
+    private Integer dateYear;
     /**
      * 月份
      */
-    private Integer month;
+    private Integer dateMonth;
     /**
      * 报表类型:0.损益表、1.完全成本法表、2.变动成本表、3.全院损益表、4.全成本报表
      */

+ 43 - 0
src/main/java/com/imed/costaccount/model/vo/FileRecordDepartmentVO.java

@@ -0,0 +1,43 @@
+package com.imed.costaccount.model.vo;
+
+import io.swagger.annotations.ApiOperation;
+import lombok.Data;
+
+/**
+ * @author 李加喜
+ * @Package com.imed.costaccount.model.vo
+ * @date 2021-09-01 17:58
+ */
+@Data
+@ApiOperation("科室损益记录数据")
+public class FileRecordDepartmentVO {
+    private Long id;
+    /**
+     * 年
+     */
+    private Integer dateYear;
+    /**
+     * 月
+     */
+    private Integer dateMonth;
+    /**
+     * 文件类型
+     */
+    private String fileType;
+    /**
+     * 文件名称
+     */
+    private String fileName;
+    /**
+     * 文件上传路径
+     */
+    private String fileUrl;
+    /**
+     * 创建时间13位时间戳
+     */
+    private Long createTime;
+    /**
+     * 更新时间
+     */
+    private String updateTime;
+}

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

@@ -6,6 +6,8 @@ import com.imed.costaccount.common.util.PageUtils;
 import com.imed.costaccount.model.CostDepartmentProfit;
 import org.apache.poi.ss.usermodel.Sheet;
 
+import javax.servlet.http.HttpServletResponse;
+
 /**
  * 科室损益计算
  *
@@ -39,5 +41,13 @@ public interface CostDepartmentProfitService extends IService<CostDepartmentProf
      * @param date
      */
     void getDepartmentProfit(ExcelWriter writer, Sheet sheet, String date);
+
+    /**
+     * 科室损益计算导出
+     * @param date
+     * @param hospId
+     * @param response
+     */
+    void getDepartProfitReport(String date, Long hospId, HttpServletResponse response);
 }
 

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

@@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.date.DateTime;
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.util.StrUtil;
+import cn.hutool.poi.excel.ExcelUtil;
 import cn.hutool.poi.excel.ExcelWriter;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -21,10 +22,13 @@ import com.imed.costaccount.model.vo.AllocationQueryReportVO;
 import com.imed.costaccount.model.vo.CostDepartmentProfitVO;
 import com.imed.costaccount.service.*;
 import org.apache.poi.ss.usermodel.Sheet;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Propagation;
 import org.springframework.transaction.annotation.Transactional;
 
+import javax.servlet.http.HttpServletResponse;
+import java.io.File;
 import java.math.BigDecimal;
 import java.util.*;
 import java.util.concurrent.atomic.AtomicReference;
@@ -34,6 +38,12 @@ import java.util.stream.Collectors;
 @Service("costDepartmentProfitService")
 public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentProfitMapper, CostDepartmentProfit> implements CostDepartmentProfitService {
 
+    @Value("${file.filelocal}")
+    private String hospProfitReportUrl;
+
+    @Value("${file.serverUrl}")
+    private String serverUrl;
+
     private final ReportFormService reportFormService;
 
     private final IncomeCollectionService incomeCollectionService;
@@ -48,8 +58,9 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
 
     private final AllocationQueryService allocationQueryService;
 
+    private final FileRecordService fileRecordService;
 
-    public CostDepartmentProfitServiceImpl(ReportFormService reportFormService, IncomeCollectionService incomeCollectionService, CostShareLevelService costShareLevelService, ResponsibilityService responsibilityService, ReportRelationService reportRelationService, AllocationService allocationService, AllocationQueryService allocationQueryService) {
+    public CostDepartmentProfitServiceImpl(ReportFormService reportFormService, IncomeCollectionService incomeCollectionService, CostShareLevelService costShareLevelService, ResponsibilityService responsibilityService, ReportRelationService reportRelationService, AllocationService allocationService, AllocationQueryService allocationQueryService, FileRecordService fileRecordService) {
         this.reportFormService = reportFormService;
         this.incomeCollectionService = incomeCollectionService;
         this.costShareLevelService = costShareLevelService;
@@ -57,6 +68,7 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
         this.reportRelationService = reportRelationService;
         this.allocationService = allocationService;
         this.allocationQueryService = allocationQueryService;
+        this.fileRecordService = fileRecordService;
     }
 
     /**
@@ -387,6 +399,30 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
         }
     }
 
+    /**
+     * 科室损益计算导出
+     *
+     * @param date
+     * @param hospId
+     * @param response
+     */
+    @Override
+    public void getDepartProfitReport(String date, Long hospId, HttpServletResponse response) {
+        DateTime dateTime = DateUtil.parse(date);
+        int year = DateUtil.year(dateTime);
+        int month = DateUtil.month(dateTime)+1;
+        String time = DateUtil.format(DateUtil.date(), "yyyy年MM月dd日HH时mm分ss秒");
+        String fileName = hospProfitReportUrl + File.separator + hospId + File.separator + "hospReport" + File.separator + "科室损益" + time + ".xlsx";
+        ExcelWriter writer = ExcelUtil.getWriter(fileName);
+        Sheet sheet = writer.getSheet();
+        getDepartmentProfit(writer,sheet,date);
+        FileRecord fileRecord = new FileRecord();
+        fileRecord.setFileName("科室损益" + time + ".xlsx").setFileSource(2).setFileType("科室损益").setFileUrl(serverUrl + hospId + File.separator + "hospReport" + File.separator + "科室损益" + time + ".xlsx").setHospId(hospId)
+                .setDateYear(year).setDateMonth(month)
+                .setCreateTime(System.currentTimeMillis());
+        fileRecordService.save(fileRecord);
+    }
+
     /**
      * 按照会计科目进行计算
      *

+ 15 - 7
src/main/java/com/imed/costaccount/service/impl/DepartmentProfitFileServiceImpl.java

@@ -8,10 +8,13 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.imed.costaccount.common.util.BeanUtil;
 import com.imed.costaccount.common.util.PageUtils;
+import com.imed.costaccount.constants.NumberConstant;
 import com.imed.costaccount.mapper.DepartmentProfitFileMapper;
 import com.imed.costaccount.model.DepartmentProfitFile;
-import com.imed.costaccount.model.vo.DepartmentProfitFileVO;
+import com.imed.costaccount.model.FileRecord;
+import com.imed.costaccount.model.vo.FileRecordDepartmentVO;
 import com.imed.costaccount.service.DepartmentProfitFileService;
+import com.imed.costaccount.service.FileRecordService;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Propagation;
 import org.springframework.transaction.annotation.Transactional;
@@ -22,6 +25,11 @@ import java.util.List;
 @Service("departmentProfitFileService")
 public class DepartmentProfitFileServiceImpl extends ServiceImpl<DepartmentProfitFileMapper, DepartmentProfitFile> implements DepartmentProfitFileService {
 
+    private final FileRecordService fileRecordService;
+
+    public DepartmentProfitFileServiceImpl(FileRecordService fileRecordService) {
+        this.fileRecordService = fileRecordService;
+    }
 
     /**
      * 分页查询进行报表记录
@@ -43,13 +51,13 @@ public class DepartmentProfitFileServiceImpl extends ServiceImpl<DepartmentProfi
             dateYear = DateUtil.year(dateTime);
             month=DateUtil.month(dateTime)+1;
         }
-        Page<DepartmentProfitFile> profitFilePage = new Page<>(current, pageSize);
-        Page<DepartmentProfitFile> pages = this.page(profitFilePage, new QueryWrapper<DepartmentProfitFile>()
+        Page<FileRecord> profitFilePage = new Page<>(current, pageSize);
+        Page<FileRecord> pages = fileRecordService.page(profitFilePage, new QueryWrapper<FileRecord>()
                 .lambda()
-                .eq(DepartmentProfitFile::getHospId, hospId).like(StrUtil.isNotBlank(reportName), DepartmentProfitFile::getReportName, reportName)
-                .eq(StrUtil.isNotBlank(date), DepartmentProfitFile::getYear, dateYear).eq(StrUtil.isNotBlank(date), DepartmentProfitFile::getMonth, month));
-        List<DepartmentProfitFile> records = pages.getRecords();
-        List<DepartmentProfitFileVO> departmentProfitFileVOList = BeanUtil.convertList(records, DepartmentProfitFileVO.class);
+                .eq(FileRecord::getHospId, hospId).eq(FileRecord::getFileSource, NumberConstant.TWO)
+                .eq(StrUtil.isNotBlank(date), FileRecord::getDateYear, dateYear).eq(StrUtil.isNotBlank(date), FileRecord::getDateMonth, month));
+        List<FileRecord> records = pages.getRecords();
+        List<FileRecordDepartmentVO> departmentProfitFileVOList = BeanUtil.convertList(records, FileRecordDepartmentVO.class);
         departmentProfitFileVOList.forEach(i->{
             i.setUpdateTime(DateUtil.format(DateUtil.date(i.getCreateTime()),"yyyy-MM-dd HH:mm:ss"));
         });

+ 18 - 0
src/main/java/com/imed/costaccount/web/CostDepartmentProfitController.java

@@ -1,5 +1,6 @@
 package com.imed.costaccount.web;
 
+import com.imed.costaccount.common.exception.CostException;
 import com.imed.costaccount.common.util.PageUtils;
 import com.imed.costaccount.common.util.Result;
 import com.imed.costaccount.common.util.UserContext;
@@ -9,6 +10,7 @@ import io.swagger.annotations.*;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import javax.servlet.http.HttpServletResponse;
 import java.util.Arrays;
 
 
@@ -46,6 +48,22 @@ public class CostDepartmentProfitController {
         return Result.ok(pageUtils);
     }
 
+    /**
+     * 科室损益计算导出
+     */
+    @ApiOperation("科室损益计算输出")
+    @PostMapping("/getDepartProfitReport")
+    public Result getDepartProfitReport(@RequestParam String date, HttpServletResponse response) {
+        try {
+            Long hospId = UserContext.getHospId();
+            costDepartmentProfitService.getDepartProfitReport(date,hospId,response);
+        } catch (Exception e) {
+            throw new CostException(500,"生成错误");
+        }
+
+        return Result.ok();
+    }
+
     /**
      * 科室损益计算
      */

+ 11 - 3
src/main/java/com/imed/costaccount/web/ExcelController.java

@@ -1,6 +1,7 @@
 package com.imed.costaccount.web;
 
 import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.io.FileUtil;
 import cn.hutool.core.io.IoUtil;
 import cn.hutool.poi.excel.ExcelReader;
@@ -24,6 +25,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.shiro.SecurityUtils;
 import org.jetbrains.annotations.NotNull;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.util.CollectionUtils;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
@@ -44,6 +46,12 @@ import java.util.stream.Collectors;
 @RestController
 @RequestMapping("/costAccount/excel")
 public class ExcelController extends AbstractController{
+
+    @Value("${file.filelocal}")
+    private String hospProfitReportUrl;
+
+    @Value("${file.serverUrl}")
+    private String serverUrl;
     private final JwtUtil jwtUtil;
     private final UserService userService;
 
@@ -472,9 +480,9 @@ public class ExcelController extends AbstractController{
         }
         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);
+        String time = DateUtil.format(DateUtil.date(), "yyyy年MM月dd日HH时mm分ss秒");
+        String fileName = hospProfitReportUrl + "全院损益" + time + ".xlsx";
+        ExcelWriter writer = ExcelUtil.getWriter(fileName);
         Sheet sheet = writer.getSheet();
         costDepartmentProfitService.getDepartmentProfit(writer,sheet,date);
         response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");

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

@@ -1,6 +1,6 @@
 package com.imed.costaccount.web;
 
-import com.baomidou.mybatisplus.extension.api.R;
+import com.imed.costaccount.common.exception.CostException;
 import com.imed.costaccount.common.util.PageUtils;
 import com.imed.costaccount.common.util.Result;
 import com.imed.costaccount.service.HospProfitAndLossService;
@@ -46,7 +46,7 @@ public class HospProfitAndLossController extends AbstractController {
         try {
             hospProfitAndLossService.hospProfitReport(date,getHospId(),response);
         } catch (Exception e) {
-            e.printStackTrace();
+            throw new CostException(500,"生成错误");
         }
 
         return Result.ok();