Browse Source

Merge branch 'master' into 'master'

增加指标计算结果入库

See merge request lighter/web-server!49
huangshuhua 2 years ago
parent
commit
aebc8cf35d

+ 12 - 1
src/main/java/thyyxxk/webserver/controller/targetmanagement/TargetManagementController.java

@@ -11,6 +11,7 @@ import thyyxxk.webserver.entity.ResultVo;
 import thyyxxk.webserver.entity.highreport.HighReportDto;
 import thyyxxk.webserver.entity.highreport.ReportBaseInfo;
 import thyyxxk.webserver.entity.highreport.TableGroupInfo;
+import thyyxxk.webserver.entity.highreport.ZbReportResult;
 import thyyxxk.webserver.entity.highreport.ZdReportType;
 import thyyxxk.webserver.entity.targetmanagement.TargetDictTree;
 import thyyxxk.webserver.entity.targetmanagement.TargetManagement;
@@ -73,7 +74,7 @@ public class TargetManagementController {
     }
 
     @PostMapping("/targetSqlExecuteById")
-    public ResultVo<Map<String, Object>> targetSqlExecuteById(@RequestBody @Validated TargetManagement dto){
+    public ResultVo<List<Map<String, Object>>> targetSqlExecuteById(@RequestBody @Validated TargetManagement dto){
         return service.targetSqlExecuteById(dto);
     }
 
@@ -123,4 +124,14 @@ public class TargetManagementController {
         return service.selectReportLevel(dto);
     }
 
+    @PostMapping("/saveTargetReportResult")
+    public ResultVo<Map<String, Object>> saveTargetReportResult(@RequestBody List<ZbReportResult> list){
+        return service.saveTargetReportResult(list);
+    }
+
+    @PostMapping("/selectTargetReportResult")
+    public ResultVo<List<ZbReportResult>> selectTargetReportResult(@RequestBody @Validated TargetManagement dto){
+        return service.selectTargetReportResult(dto);
+    }
+
 }

+ 35 - 0
src/main/java/thyyxxk/webserver/dao/his/highreport/HighReportDao.java

@@ -1,5 +1,7 @@
 package thyyxxk.webserver.dao.his.highreport;
 
+import org.apache.ibatis.annotations.Delete;
+import org.apache.ibatis.annotations.Insert;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
@@ -9,6 +11,7 @@ import thyyxxk.webserver.entity.highreport.ReportBaseInfo;
 import thyyxxk.webserver.entity.highreport.TableDisplayInfo;
 import thyyxxk.webserver.entity.highreport.TableGroupInfo;
 import thyyxxk.webserver.entity.highreport.XYBean;
+import thyyxxk.webserver.entity.highreport.ZbReportResult;
 import thyyxxk.webserver.entity.highreport.ZdReportType;
 
 import java.util.List;
@@ -92,4 +95,36 @@ public interface HighReportDao {
     @Select(" select report_id as code, report_label as name from zd_report_type where flag = 'Y' order by sort ")
     List<ZdReportType> selectReportTypeZd();
 
+    @Select("<script>" +
+            " select * from zb_report_result zb " +
+            " where zb.id = #{id} " +
+            " and zb.pid = #{pid} " +
+            " and zb.year = #{year} " +
+            "</script>")
+    ZbReportResult selectReportResultByYear(@Param("id") String id, @Param("pid") String pid, @Param("year") String year);
+
+    @Select("<script>" +
+            " select * from zb_report_result zb " +
+            " where zb.id = #{id} " +
+            " and zb.pid = #{pid} " +
+            "</script>")
+    List<ZbReportResult> selectReportResultById(@Param("id") String id, @Param("pid") String pid);
+
+    @Delete("<script>" +
+            " delete zb from zb_report_result zb " +
+            " where zb.id = #{id} " +
+            " and zb.pid = #{pid} " +
+            " and zb.year = #{year} " +
+            "</script>")
+    int deleteReportResultById(@Param("id") String id, @Param("pid") String pid, @Param("year") String year);
+
+    @Insert("<script>" +
+    " insert into zb_report_result " +
+    " (id, pid, year, data_type, child_result, mom_result, calc_result, op, op_id, op_time) values " +
+    " (#{id},#{pid},#{year},#{dataType},#{childResult}, " +
+    " #{momResult},#{calcResult},#{op},#{opId},#{opTime} " +
+    " ) " +
+    "</script>")
+    int saveTargetReportResult(ZbReportResult result);
+
 }

+ 30 - 0
src/main/java/thyyxxk/webserver/entity/highreport/ZbReportResult.java

@@ -0,0 +1,30 @@
+package thyyxxk.webserver.entity.highreport;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+
+/**
+ * @Description: 指标报表结果表
+ * @Author: hsh
+ * @CreateTime: 2023-07-20  15:54
+ * @Version: 1.0
+ */
+@Data
+@TableName("zb_report_result")
+public class ZbReportResult {
+
+    private String id;
+    private String pid;
+    private String year;
+    /**
+     * 数据统计来源(1:sql计算 2:手动输入填写)
+     **/
+    private String dataType;
+    private String childResult;
+    private String momResult;
+    private String calcResult;
+    private String op;
+    private String opId;
+    private String opTime;
+
+}

+ 140 - 30
src/main/java/thyyxxk/webserver/service/targetmanagement/TargetManagementService.java

@@ -13,15 +13,20 @@ import thyyxxk.webserver.entity.highreport.HighReportDto;
 import thyyxxk.webserver.entity.highreport.ReportBaseInfo;
 import thyyxxk.webserver.entity.highreport.ReportType;
 import thyyxxk.webserver.entity.highreport.TableGroupInfo;
+import thyyxxk.webserver.entity.highreport.ZbReportResult;
 import thyyxxk.webserver.entity.highreport.ZdReportType;
+import thyyxxk.webserver.entity.login.UserInfo;
 import thyyxxk.webserver.entity.targetmanagement.TargetDictTree;
 import thyyxxk.webserver.entity.targetmanagement.TargetManagement;
 import thyyxxk.webserver.entity.targetmanagement.ZbZdBaseInfo;
+import thyyxxk.webserver.service.redislike.RedisLikeService;
+import thyyxxk.webserver.utils.DateUtil;
 import thyyxxk.webserver.utils.DecimalUtil;
 import thyyxxk.webserver.utils.ReportUtil;
 import thyyxxk.webserver.utils.ResultVoUtil;
 import thyyxxk.webserver.utils.StringUtil;
 import thyyxxk.webserver.utils.TargetDictTreeUtil;
+import thyyxxk.webserver.utils.TokenUtil;
 
 import java.math.BigDecimal;
 import java.util.ArrayList;
@@ -47,11 +52,14 @@ public class TargetManagementService {
 
     private final HighReportDao reportDao;
 
+    private final RedisLikeService redis;
+
     @Autowired
-    public TargetManagementService(TargetManagementDao dao, ZbZdBaseInfoDao zbZdDao, HighReportDao reportDao) {
+    public TargetManagementService(TargetManagementDao dao, ZbZdBaseInfoDao zbZdDao, HighReportDao reportDao, RedisLikeService redis) {
         this.dao = dao;
         this.zbZdDao = zbZdDao;
         this.reportDao = reportDao;
+        this.redis = redis;
     }
 
     /**
@@ -288,7 +296,7 @@ public class TargetManagementService {
      * @param: [dto]
      * @return: ResultVo<Map<String,Object>>
      **/
-    public ResultVo<Map<String, Object>> targetSqlExecuteById(TargetManagement dto) {
+    public ResultVo<List<Map<String, Object>>> targetSqlExecuteById(TargetManagement dto) {
         ReportBaseInfo reportChild = dao.selectReportBaseInfoByCalcId(dto.getChildId());
         ReportBaseInfo reportMom = dao.selectReportBaseInfoByCalcId(dto.getMomId());
 
@@ -296,38 +304,74 @@ public class TargetManagementService {
             return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, dto.getName() + "计算-分子或分母指标都不存在,请联系管理员!");
         }
 
-        HighReportDto d = ReportUtil.TargetManagementConvertHighReportDto(dto);
-
-        // 计算结果
-        Map<String, Object> resultMap = new HashMap<>();
-        String child = null;
-        String mom = null;
-        if(reportChild != null){
-            String childSql = ReportUtil.callSqlFormat(d, reportChild.getBaseSql(), reportChild.getGatherSql(), null, null, null);
-            child = dao.targetSqlExecute(childSql);
-        }
-        if(reportMom != null){
-            String momSql = ReportUtil.callSqlFormat(d, reportMom.getBaseSql(), reportMom.getGatherSql(), null, null, null);
-            mom = dao.targetSqlExecute(momSql);
+        if(null ==  dto.getStartTime() || null == dto.getEndTime()){
+            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, dto.getName() + "查询时间不存在,请检查!");
         }
 
-        if (StringUtil.notBlank(child)) {
-            resultMap.put("r1", child);
-        } else {
-            resultMap.put("r1", "无");
-        }
-        if (StringUtil.notBlank(mom)) {
-            resultMap.put("r2", mom);
-            resultMap.put("r3", DecimalUtil.divide(new BigDecimal(child), new BigDecimal(mom), 2));
-        } else {
-            resultMap.put("r2", "无");
+        // 处理时间(1.时间跨度需要一年一年查询结果; 2.查询时间格式为年月日时分秒: yyyy-MM-DD 24H:mm:ss)
+        int start = Integer.parseInt(dto.getStartTime());
+        int end = Integer.parseInt(dto.getEndTime());
+        // 超过4年只选择4年数据查询
+        int endIndex = start + 3;
+
+        List<Map<String, Object>> list = new ArrayList<>();
+        for(int i = start; i <= end; i++){
+            Map<String, Object> resultMap = new HashMap<>();
+            if(i > endIndex){
+                break;
+            }
+            int s = i - start + 1;
+
+            String ks = i + "-01-01 00:00:00";
+            String js = i + "-12-31 23:59:59";
+            dto.setStartTime(ks);
+            dto.setEndTime(js);
+            HighReportDto d = ReportUtil.TargetManagementConvertHighReportDto(dto);
+            // 计算结果
+            String child = null;
+            String mom = null;
+            if(reportChild != null){
+                String childSql = ReportUtil.callSqlFormat(d, reportChild.getBaseSql(), reportChild.getGatherSql(), null, null, null);
+                child = dao.targetSqlExecute(childSql);
+            }
+            if(reportMom != null){
+                String momSql = ReportUtil.callSqlFormat(d, reportMom.getBaseSql(), reportMom.getGatherSql(), null, null, null);
+                mom = dao.targetSqlExecute(momSql);
+            }
+
+            resultMap.put("id", dto.getId());
+            resultMap.put("pid", dto.getPid());
+            resultMap.put("index", s);
+            // 数据统计来源(1:sql统计;2:手动填写输入。)
+            resultMap.put("dataType", "1");
+            // 统计年份
+            resultMap.put("year", i);
+            resultMap.put("childLabel", i + "年分子结果");
+            resultMap.put("momLabel", i + "年分母结果");
+            resultMap.put("calcLabel", i + "年分子/分母的结果");
             if (StringUtil.notBlank(child)) {
-                resultMap.put("r3", child);
+                resultMap.put("childResult", child);
             } else {
-                resultMap.put("r3", "无");
+                resultMap.put("childResult", "无");
+            }
+            if (StringUtil.notBlank(mom)) {
+                resultMap.put("momResult", mom);
+                if(StringUtil.notBlank(child)){
+                    resultMap.put("calcResult", DecimalUtil.divide(new BigDecimal(child), new BigDecimal(mom), 2));
+                } else {
+                    resultMap.put("calcResult", "无");
+                }
+            } else {
+                resultMap.put("momResult", "无");
+                if (StringUtil.notBlank(child)) {
+                    resultMap.put("calcResult", child);
+                } else {
+                    resultMap.put("calcResult", "无");
+                }
             }
+            list.add(resultMap);
         }
-        return ResultVoUtil.success(resultMap);
+        return ResultVoUtil.success(list);
     }
 
     public ResultVo<Map<String, Object>> targetSqlSave(TargetManagement dto) {
@@ -602,16 +646,82 @@ public class TargetManagementService {
         return ResultVoUtil.success(resultMap);
     }
 
-
+    /**
+     * @description: 查询报表分组类型
+     * @author: hsh
+     * @date: 2023/7/19 15:25
+     * @param: [dto]
+     * @return: ResultVo<TableGroupInfo>
+     **/
     public ResultVo<TableGroupInfo> selectReportLevel(HighReportDto dto){
 
         TableGroupInfo info = reportDao.selectTableGroupInfoByLevel(dto.getReportId(), dto.getLevel());
         if(info == null){
-            // 查不到给他默认科室分组类型
+            // 查不到给他默认报表分组类型
             info = reportDao.selectTableGroupInfoByLevel(ReportType.GROUP_KS.getCode(), dto.getLevel());
         }
 
         return ResultVoUtil.success(info);
     }
 
+    /**
+     * @description: 保存指标结果
+     * @author: hsh
+     * @date: 2023/7/19 15:27
+     * @param: [list]
+     * @return: ResultVo<Map<String,Object>>
+     **/
+    public ResultVo<Map<String, Object>> saveTargetReportResult(List<ZbReportResult> list){
+        Map<String, Object> resultMap = new HashMap<>();
+
+        if(list == null || list.size() == 0){
+            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "指标结果记录不存在,请检查!");
+        }
+
+        UserInfo user = redis.getUserInfoByCode(TokenUtil.getTokenUserId());
+        for (ZbReportResult result : list) {
+            result.setOp(user.getName() != null ? user.getName().trim() : user.getName());
+            result.setOpId(user.getCodeRs());
+            result.setOpTime(DateUtil.now());
+
+            // 入库或更新操作
+            int n = updateAndSaveTargetReportResult(result);
+            if (n <= 0) {
+                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "保存指标结果失败!");
+            }
+        }
+        resultMap.put("cg", "保存指标结果成功");
+        return ResultVoUtil.success(resultMap);
+    }
+
+    /**
+     * @description: 先删后保存数据
+     * @author: hsh
+     * @date: 2023/7/21 10:06
+     * @param: [result]
+     * @return: int
+     **/
+    private int updateAndSaveTargetReportResult(ZbReportResult result) {
+        if(result == null){
+            return 0;
+        }
+        ZbReportResult r = reportDao.selectReportResultByYear(result.getId(), result.getPid(), result.getYear());
+        if(r != null){
+            reportDao.deleteReportResultById(result.getId(), result.getPid(), result.getYear());
+        }
+        return reportDao.saveTargetReportResult(result);
+    }
+
+    /**
+     * @description: 查询指标报表结果
+     * @author: hsh
+     * @date: 2023/7/21 11:21
+     * @param: [dto]
+     * @return: ResultVo<List<ZbReportResult>>
+     **/
+    public ResultVo<List<ZbReportResult>> selectTargetReportResult(TargetManagement dto) {
+        List<ZbReportResult> list = reportDao.selectReportResultById(dto.getId(), dto.getPid());
+        return ResultVoUtil.success(list);
+    }
+
 }

+ 7 - 1
src/main/java/thyyxxk/webserver/utils/ReportUtil.java

@@ -273,7 +273,13 @@ public class ReportUtil {
         return map;
     }
 
-
+    /**
+     * @description: 实体查询条件转换(历史条件原因)
+     * @author: hsh
+     * @date: 2023/7/17 16:43
+     * @param: [dto]
+     * @return: HighReportDto
+     **/
     public static HighReportDto TargetManagementConvertHighReportDto(TargetManagement dto){
         HighReportDto d = new HighReportDto();
         d.setStartTime(dto.getStartTime());