فهرست منبع

09 01 01 全院损益计算

hr 4 سال پیش
والد
کامیت
da006d917d

+ 9 - 1
src/main/java/com/imed/costaccount/mapper/HospProfitAndLossMapper.java

@@ -3,6 +3,9 @@ package com.imed.costaccount.mapper;
 import com.imed.costaccount.model.HospProfitAndLoss;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
 
 /**
  * 全院损益表
@@ -12,5 +15,10 @@ import org.apache.ibatis.annotations.Mapper;
  */
 @Mapper
 public interface HospProfitAndLossMapper extends BaseMapper<HospProfitAndLoss> {
-	
+
+    List<HospProfitAndLoss> getPageList(@Param("startIndex") int startIndex, @Param("pageSize") Integer pageSize, @Param("year") int year, @Param("month") int month, @Param("hospId") Long hospId);
+
+
+    int getPageCount(@Param("year") int year, @Param("month") int month, @Param("hospId") Long hospId);
+
 }

+ 2 - 0
src/main/java/com/imed/costaccount/model/FileRecord.java

@@ -1,6 +1,7 @@
 package com.imed.costaccount.model;
 
 import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableLogic;
 import com.baomidou.mybatisplus.annotation.TableName;
 import lombok.AllArgsConstructor;
 import lombok.Data;
@@ -64,6 +65,7 @@ public class FileRecord implements Serializable {
 	/**
 	 * 删除时间,如果存在表示已删除13位时间戳
 	 */
+	@TableLogic(value = "0",delval = "UNIX_TIMESTAMP(NOW()) * 1000")
 	private Long deleteTime;
 
 }

+ 3 - 0
src/main/java/com/imed/costaccount/service/HospProfitAndLossService.java

@@ -48,5 +48,8 @@ public interface HospProfitAndLossService extends IService<HospProfitAndLoss> {
      * @param hospId
      */
     void calcByResponsibility(String date, Long hospId);
+
+    PageUtils hospProfitReports(Integer current, Integer pageSize, Long hospId);
+
 }
 

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

@@ -3,28 +3,22 @@ package com.imed.costaccount.service.impl;
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.date.DateTime;
 import cn.hutool.core.date.DateUtil;
-import cn.hutool.core.io.IoUtil;
 import cn.hutool.core.util.ReUtil;
 import cn.hutool.core.util.StrUtil;
 import cn.hutool.poi.excel.ExcelUtil;
 import cn.hutool.poi.excel.ExcelWriter;
-import cn.hutool.poi.excel.StyleSet;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.imed.costaccount.common.enums.CalcTypeEnum;
 import com.imed.costaccount.common.enums.ReportTypeEnum;
 import com.imed.costaccount.common.exception.CostException;
-import com.imed.costaccount.common.util.BeanUtil;
 import com.imed.costaccount.common.util.PageUtils;
 import com.imed.costaccount.model.*;
-import com.imed.costaccount.model.vo.HospProfitVO;
 import com.imed.costaccount.model.vo.RelationVO;
 import com.imed.costaccount.model.vo.ReportFormVO;
 import com.imed.costaccount.service.*;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.poi.hssf.usermodel.HSSFCellStyle;
-import org.apache.poi.ss.usermodel.*;
-import org.apache.poi.xssf.usermodel.XSSFCellStyle;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 
@@ -32,9 +26,7 @@ import com.imed.costaccount.mapper.HospProfitAndLossMapper;
 import org.springframework.transaction.annotation.Propagation;
 import org.springframework.transaction.annotation.Transactional;
 
-import javax.servlet.ServletOutputStream;
 import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
 import java.math.BigDecimal;
 import java.util.*;
 import java.util.concurrent.ConcurrentHashMap;
@@ -45,35 +37,40 @@ import java.util.stream.Collectors;
 @Service("hospProfitAndLossService")
 public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossMapper, HospProfitAndLoss> implements HospProfitAndLossService {
 
+    @Value("${file.filelocal}")
+    private String hospProfitReportUrl;
+
+    @Value("${file.serverUrl}")
+    private String serverUrl;
+
     private final ReportFormService reportFormService;
     private final IncomeCollectionService collectionService;
     private final AllocationQueryService allocationQueryService;
-    private final AllocationService allocationService;
 
     private final ReportRelationService reportRelationService;
     private final CostShareLevelService shareLevelService;
     private final CostOtherPaymentsDataService otherPaymentsDataService;
     private final ResponsibilityService responsibilityService;
     private final CostAccountShareService accountShareService;
+    private final FileRecordService fileRecordService;
 
     public HospProfitAndLossServiceImpl(ReportFormService reportFormService,
                                         IncomeCollectionService collectionService,
                                         AllocationQueryService allocationQueryService,
-                                        AllocationService allocationService,
                                         ReportRelationService reportRelationService,
                                         CostShareLevelService shareLevelService,
                                         CostOtherPaymentsDataService otherPaymentsDataService,
                                         ResponsibilityService responsibilityService,
-                                        CostAccountShareService accountShareService) {
+                                        CostAccountShareService accountShareService, FileRecordService fileRecordService) {
         this.reportFormService = reportFormService;
         this.collectionService = collectionService;
         this.allocationQueryService = allocationQueryService;
-        this.allocationService = allocationService;
         this.reportRelationService = reportRelationService;
         this.shareLevelService = shareLevelService;
         this.otherPaymentsDataService = otherPaymentsDataService;
         this.responsibilityService = responsibilityService;
         this.accountShareService = accountShareService;
+        this.fileRecordService = fileRecordService;
     }
 
 
@@ -363,19 +360,10 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
         DateTime parse = DateUtil.parse(date);
         int year = DateUtil.year(parse);
         int month = DateUtil.month(parse) + 1;
-        Page<HospProfitAndLoss> page = new Page<>(current, pageSize);
-        Page<HospProfitAndLoss> pages = this.page(
-                page,
-                new LambdaQueryWrapper<HospProfitAndLoss>()
-                        .eq(HospProfitAndLoss::getHospId, hospId)
-                        .eq(HospProfitAndLoss::getDateMonth, month)
-                        .eq(HospProfitAndLoss::getDateYear, year)
-        );
-        List<HospProfitAndLoss> records = pages.getRecords();
-        List<HospProfitVO> hospProfitVOS = BeanUtil.convertList(records, HospProfitVO.class);
-        PageUtils pageUtils = new PageUtils(pages);
-        pageUtils.setList(hospProfitVOS);
-        return pageUtils;
+        int startIndex = (current - 1) * pageSize;
+        List<HospProfitAndLoss> list = baseMapper.getPageList(startIndex, pageSize, year, month, hospId);
+        int totalCount = baseMapper.getPageCount(year, month, hospId);
+        return new PageUtils(list, totalCount, pageSize, current);
     }
 
     /**
@@ -395,7 +383,11 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
         List<Responsibility> leafResp = responsibilityService.getLeafResp(hospId);
 
         // 得到上一层的title子节点
-        ExcelWriter writer = ExcelUtil.getWriter();
+//        ExcelWriter writer = ExcelUtil.getWriter();
+        String time = DateUtil.format(DateUtil.date(), "yyyy年MM月dd日HH时mm分ss秒");
+        String fileName = hospProfitReportUrl + "全院损益" + time + ".xlsx";
+        ExcelWriter writer = ExcelUtil.getWriter(fileName);
+
         List<String> secondTitleListCode = leafResp.stream().map(Responsibility::getResponsibilityCode).collect(Collectors.toList());
         writer.merge(leafResp.size() + 1, "全院损益计算导出 \n" + "制表时间:" + DateUtil.now());
         // 得到两层结构
@@ -441,7 +433,6 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
         // 查询所有的全院损益数据  内存溢出问题
         List<HospProfitAndLoss> list = getAllDataByDate(year, month, hospId);
         int lastRow = 3;
-        Sheet sheet = writer.getSheet();
         for (int i = 0; i < allHospList.size(); i++) {
             ReportFormVO parentFormVO = allHospList.get(i);
             List<ReportFormVO> children = parentFormVO.getChildren();
@@ -470,28 +461,23 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
             }
             lastRow = lastRow + size;
         }
-
-        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
-        response.setHeader("Content-Disposition", "attachment;filename=" + "全院损益列表" + ".xls");
-        ServletOutputStream out = null;
-
-        try {
-            out = response.getOutputStream();
-        } catch (IOException e) {
-            e.printStackTrace();
-        }
-        writer.flush(out, true);
+        FileRecord fileRecord = new FileRecord();
+        fileRecord.setFileName("全院损益" + time + ".xlsx").setFileSource(1).setFileType("全院损益").setFileUrl(serverUrl + fileName).setHospId(hospId)
+                .setDateYear(year).setDateMonth(month)
+                .setCreateTime(System.currentTimeMillis());
+        fileRecordService.save(fileRecord);
         writer.close();
-        IoUtil.close(out);
-
-
     }
 
-//    private List<String> getLeafRespOnlyOne(Long hospId, List<Responsibility> leafResp) {
-//        List<Long> parentIds = leafResp.stream().map(Responsibility::getParentId).collect(Collectors.toList());
-//        responsibilityService.getById(pare)
-//
-//    }
+    @Override
+    public PageUtils hospProfitReports(Integer current, Integer pageSize, Long hospId) {
+        Page<FileRecord> page = new Page<>(current, pageSize);
+        Page<FileRecord> pageUtils = fileRecordService.page(page,
+                new LambdaQueryWrapper<FileRecord>()
+                        .eq(FileRecord::getHospId, hospId)
+        );
+        return new PageUtils(pageUtils);
+    }
 
     private List<HospProfitAndLoss> getAllDataByDate(int year, int month, Long hospId) {
         return this.list(

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

@@ -1,5 +1,6 @@
 package com.imed.costaccount.web;
 
+import com.baomidou.mybatisplus.extension.api.R;
 import com.imed.costaccount.common.util.PageUtils;
 import com.imed.costaccount.common.util.Result;
 import com.imed.costaccount.service.HospProfitAndLossService;
@@ -41,7 +42,21 @@ public class HospProfitAndLossController extends AbstractController {
 
     @ApiOperation("全院损益计算输出")
     @PostMapping("/report")
-    public void hospProfitReport(@RequestParam String date, HttpServletResponse response) {
-        hospProfitAndLossService.hospProfitReport(date,getHospId(),response);
+    public Result hospProfitReport(@RequestParam String date, HttpServletResponse response) {
+        try {
+            hospProfitAndLossService.hospProfitReport(date,getHospId(),response);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        return Result.ok();
+    }
+
+    @ApiOperation("全院经营报表列表")
+    @GetMapping("/hospReports")
+    public Result hospReports(@RequestParam(value = "current", defaultValue = "1") Integer current,
+                              @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
+        PageUtils pageUtils = hospProfitAndLossService.hospProfitReports(current,pageSize,getHospId());
+        return Result.ok(pageUtils);
     }
 }

+ 5 - 0
src/main/resources/application-dev.yml

@@ -69,3 +69,8 @@ file:
   #  serverUrl: http://112.124.59.133:8082//
   #linux
   serverUrl: http://112.124.59.133:8082/
+  ##全院损益计算的报表URL
+  #windows
+  hospProfitReportUrl: d:/
+  #linux
+  #  hospProfitReportUrl:

+ 31 - 0
src/main/resources/mapper/HospProfitAndLossMapper.xml

@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+
+<mapper namespace="com.imed.costaccount.mapper.HospProfitAndLossMapper">
+
+
+    <select id="getPageList" resultType="com.imed.costaccount.model.HospProfitAndLoss">
+        select id          as id,
+               date_year   as dateYear,
+               date_month  as dateMonth,
+               report_num  as reportNum,
+               report_name as reportName,
+               sum(amount) as amount
+        from cost_hosp_profit_and_loss
+        where date_year = #{year}
+          and date_month = #{month}
+          and hosp_id = #{hospId}
+        group by report_num
+            limit #{startIndex}, #{pageSize}
+    </select>
+    <select id="getPageCount" resultType="java.lang.Integer">
+        select count(*)
+        from (
+                 select *
+                 from cost_hosp_profit_and_loss
+                 where date_year = #{year}
+                   and date_month = #{month}
+                   and hosp_id = #{hospId}
+                 group by report_num) t
+    </select>
+</mapper>