Browse Source

Merge branch 'master' into 'master'

新增指标月度得分

See merge request lighter/web-server!114
huangshuhua 9 months ago
parent
commit
3c2d7ba171

+ 21 - 0
src/main/java/thyyxxk/webserver/controller/targetmanagement/TargetManagementController.java

@@ -15,6 +15,7 @@ import thyyxxk.webserver.entity.highreport.TableDisplayInfo;
 import thyyxxk.webserver.entity.highreport.TableGroupInfo;
 import thyyxxk.webserver.entity.highreport.ZbReportCycle;
 import thyyxxk.webserver.entity.highreport.ZbReportCycleScore;
+import thyyxxk.webserver.entity.highreport.ZbReportMonthScore;
 import thyyxxk.webserver.entity.highreport.ZbReportResult;
 import thyyxxk.webserver.entity.highreport.ZbReportScoreDto;
 import thyyxxk.webserver.entity.highreport.ZdReportType;
@@ -206,4 +207,24 @@ public class TargetManagementController {
         return service.selectTargetTotalScoreInfo(dto);
     }
 
+    @PostMapping("/targetSqlExecuteMonthById")
+    public ResultVo<Map<String, Object>> targetSqlExecuteMonthById(@RequestBody @Validated TargetManagement dto){
+        return service.targetSqlExecuteMonthById(dto);
+    }
+
+    @PostMapping("/selectTargetReportResultByMonth")
+    public ResultVo<ZbReportMonthScore> selectTargetReportResultByMonth(@RequestBody @Validated ZbReportMonthScore dto){
+        return service.selectTargetReportResultByMonth(dto);
+    }
+
+    @PostMapping("/saveTargetReportMonthResult")
+    public ResultVo<Map<String, Object>> saveTargetReportMonthResult(@RequestBody ZbReportMonthScore monthScore){
+        return service.saveTargetReportMonthResult(monthScore);
+    }
+
+    @PostMapping("/selectTargetReportMonthScore")
+    public ResultVo<List<ZbReportMonthScore>> selectTargetReportMonthScore(@RequestBody @Validated TargetManagement dto){
+        return service.selectTargetReportMonthScore(dto);
+    }
+
 }

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

@@ -11,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.ZbReportMonthScore;
 import thyyxxk.webserver.entity.highreport.ZbReportResult;
 import thyyxxk.webserver.entity.highreport.ZdReportType;
 
@@ -175,4 +176,42 @@ public interface HighReportDao {
             "</script>")
     List<ZbReportResult> selectReportResultByPid(@Param("pid") String pid, @Param("startTime") String startTime, @Param("endTime") String endTime);
 
+    @Select("<script>" +
+            " select * from zb_report_month_score zb " +
+            " where zb.id = #{id} and zb.pid = #{pid} " +
+            " <if test=\"startTime != null and startTime != '' \"> " +
+            " and zb.month &gt;= #{startTime} " +
+            " </if> " +
+            " <if test=\"endTime != null and endTime != '' \"> " +
+            " and zb.month &lt;= #{endTime} " +
+            " </if> " +
+            "</script>")
+    List<ZbReportMonthScore> selectTargetReportMonthResultById(@Param("id") String id, @Param("pid") String pid, @Param("startTime") String startTime, @Param("endTime") String endTime);
+
+    @Select("<script>" +
+            " select * from zb_report_month_score zb " +
+            " where zb.id = #{id} " +
+            " and zb.pid = #{pid} " +
+            " and zb.month = #{month} " +
+            "</script>")
+    ZbReportMonthScore selectReportResultByMonth(@Param("id") String id, @Param("pid") String pid, @Param("month") String month);
+
+    @Delete("<script>" +
+            " delete zb from zb_report_month_score zb " +
+            " where zb.id = #{id} " +
+            " and zb.pid = #{pid} " +
+            " and zb.month = #{month} " +
+            "</script>")
+    void deleteReportResultMonthById(@Param("id") String id, @Param("pid") String pid, @Param("month") String month);
+
+    @Insert("<script>" +
+            " insert into zb_report_month_score " +
+            " (id, pid, month, name, child_result, mom_result, calc_result, data_type, child_id, mom_id, " +
+            "  dept_id, dept_name, author_id, author_name, score, create_time) values " +
+            " (#{id},#{pid},#{month},#{name},#{childResult},#{momResult},#{calcResult},#{dataType},#{childId},#{momId}, " +
+            " #{deptId},#{deptName},#{authorId},#{authorName},#{score},#{createTime} " +
+            " ) " +
+            "</script>")
+    int saveTargetReportMonthResult(ZbReportMonthScore score);
+
 }

+ 3 - 3
src/main/java/thyyxxk/webserver/dao/his/targetmanagement/ZbZdBaseInfoDao.java

@@ -43,15 +43,15 @@ public interface ZbZdBaseInfoDao {
     @Select("<script> " +
             " with zb_tree_view as " +
             "( " +
-            "select z1.id,z1.name,z1.pid,z1.sort,z1.score " +
+            "select z1.id,z1.name,z1.pid,z1.sort,z1.dept_code,z1.is_leaf " +
             "from zb_zd_base_info z1 " +
             "where z1.id = 'B' and z1.state = 'Y' " +
             "union all " +
-            "select z2.id,z2.name,z2.pid,z2.sort,z2.score " +
+            "select z2.id,z2.name,z2.pid,z2.sort,z2.dept_code,z2.is_leaf " +
             "from zb_zd_base_info z2, zb_tree_view " +
             "where z2.pid = zb_tree_view.id and z2.state = 'Y' " +
             ") " +
-            "select tree.id, tree.name as label, tree.pid, tree.sort, tree.score " +
+            "select tree.id, tree.name as label, tree.pid, tree.sort, tree.dept_code as deptCode,tree.is_leaf " +
             "from zb_tree_view tree " +
             "order by len(case when charindex('-', tree.sort) = 0 then tree.sort else substring(tree.sort,1,charindex('-',tree.sort)-1) end) " +
             "</script>")

+ 83 - 0
src/main/java/thyyxxk/webserver/entity/highreport/ZbReportMonthScore.java

@@ -0,0 +1,83 @@
+package thyyxxk.webserver.entity.highreport;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+
+/**
+ * @ClassName ZbReportMonthScore
+ * @Author hsh
+ * @Date 2024/11/20 15:43
+ * @Version 1.0
+ * @Description TODO
+ **/
+@Data
+@TableName("zb_report_month_score")
+public class ZbReportMonthScore {
+    /**
+     * 指标id
+     */
+    @TableId(value = "id", type = IdType.NONE)
+    private String id;
+    /**
+     * 指标父id
+     */
+    private String pid;
+    /**
+     * 指标年月
+     */
+    private String month;
+    /**
+     * 指标名称
+     */
+    private String name;
+    /**
+     * 指标分子结果
+     */
+    private String childResult;
+    /**
+     * 指标分母结果
+     */
+    private String momResult;
+    /**
+     * 指标计算结果
+     */
+    private String calcResult;
+    /**
+     * 指标计算类型(1:sql统计, 2:手动输入)
+     */
+    private String dataType;
+    /**
+     * 指标分子指标id
+     */
+    private String childId;
+    /**
+     * 指标分母指标id
+     */
+    private String momId;
+    /**
+     * 指标所属科室(权限科室以及填写人所在科室)id
+     */
+    private String deptId;
+    /**
+     * 指标所属科室(权限科室以及填写人所在科室)
+     */
+    private String deptName;
+    /**
+     * 操作人id
+     */
+    private String authorId;
+    /**
+     * 操作人姓名
+     */
+    private String authorName;
+    /**
+     * 得分
+     */
+    private String score;
+    /**
+     * 操作时间
+     */
+    private String createTime;
+}

+ 8 - 5
src/main/java/thyyxxk/webserver/entity/targetmanagement/TargetDictTree.java

@@ -2,7 +2,6 @@ package thyyxxk.webserver.entity.targetmanagement;
 
 import lombok.Data;
 
-import java.math.BigDecimal;
 import java.util.List;
 
 /**
@@ -26,18 +25,22 @@ public class TargetDictTree {
     /** 序号 */
     private String sort;
 
-    /** 总分 */
-    private BigDecimal score;
+    /** 科室id */
+    private String deptCode;
+
+    /** 是否叶子节点 */
+    private String isLeaf;
 
     /** 子节点 */
     private List<TargetDictTree> children;
 
-    public TargetDictTree(String id, String pid, String label, String sort, BigDecimal score) {
+    public TargetDictTree(String id, String pid, String label, String sort, String deptCode, String isLeaf) {
         this.id = id;
         this.pid = pid;
         this.label = label;
         this.sort = sort;
-        this.score = score;
+        this.deptCode = deptCode;
+        this.isLeaf = isLeaf;
     }
 
 }

+ 148 - 3
src/main/java/thyyxxk/webserver/service/targetmanagement/TargetManagementService.java

@@ -20,6 +20,7 @@ import thyyxxk.webserver.entity.highreport.TableDisplayInfo;
 import thyyxxk.webserver.entity.highreport.TableGroupInfo;
 import thyyxxk.webserver.entity.highreport.ZbReportCycle;
 import thyyxxk.webserver.entity.highreport.ZbReportCycleScore;
+import thyyxxk.webserver.entity.highreport.ZbReportMonthScore;
 import thyyxxk.webserver.entity.highreport.ZbReportResult;
 import thyyxxk.webserver.entity.highreport.ZbReportScoreDto;
 import thyyxxk.webserver.entity.highreport.ZdReportType;
@@ -37,6 +38,8 @@ import thyyxxk.webserver.utils.TargetDictTreeUtil;
 import thyyxxk.webserver.utils.TokenUtil;
 
 import java.math.BigDecimal;
+import java.time.LocalDate;
+import java.time.YearMonth;
 import java.util.ArrayList;
 import java.util.Comparator;
 import java.util.HashMap;
@@ -118,7 +121,7 @@ public class TargetManagementService {
     public ResultVo<List<TargetDictTree>> selectTargetDictTree(TargetManagement dto) {
         List<TargetDictTree> zbList = zbZdDao.selectTargetDictTree(dto);
         // 组装指标树
-        List<TargetDictTree> list = assemblyTargetDictTree(zbList);
+        List<TargetDictTree> list = assemblyTargetDictTree(zbList, dto.getDept());
         return ResultVoUtil.success(list);
     }
 
@@ -129,9 +132,9 @@ public class TargetManagementService {
      * @param: [list, zbList]
      * @return: void
      **/
-    private List<TargetDictTree> assemblyTargetDictTree(@NotNull List<TargetDictTree> zbList) {
+    private List<TargetDictTree> assemblyTargetDictTree(@NotNull List<TargetDictTree> zbList, String dept) {
         // 创建树形结构(数据集合作为参数)
-        TargetDictTreeUtil treeBuild = new TargetDictTreeUtil(zbList);
+        TargetDictTreeUtil treeBuild = new TargetDictTreeUtil(zbList, dept);
         // 原查询结果转换树形结构
         return treeBuild.buildTree();
     }
@@ -1103,4 +1106,146 @@ public class TargetManagementService {
         return ResultVoUtil.success(resultMap);
     }
 
+    /**
+     * @Description 根据月份查询指标得分想详细情况
+     * @Author hsh
+     * @param dto 指标参数
+     * @return map
+     * @Date 2024/11/20 11:02
+     */
+    public ResultVo<Map<String, Object>> targetSqlExecuteMonthById(TargetManagement dto) {
+        ReportBaseInfo reportChild = dao.selectReportBaseInfoByCalcId(dto.getChildId());
+        ReportBaseInfo reportMom = dao.selectReportBaseInfoByCalcId(dto.getMomId());
+
+        if(null ==  reportChild && null == reportMom){
+            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "【" + dto.getName() + "】指标-分子或分母指标都不存在,请联系管理员!");
+        }
+
+        if(null ==  dto.getStartTime() || null == dto.getEndTime()){
+            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "【" + dto.getName() + "】查询时间不存在,请检查!");
+        }
+
+        Map<String, Object> resultMap = new HashMap<>();
+        resultMap.put("id", dto.getId());
+        resultMap.put("pid", dto.getPid());
+        resultMap.put("name", dto.getName());
+        resultMap.put("childId", dto.getChildId());
+        resultMap.put("momId", dto.getMomId());
+        // 数据统计来源(1:sql统计;2:手动填写输入。)
+        resultMap.put("dataType", "1");
+        // 统计年月
+        resultMap.put("month", dto.getStartTime());
+
+        String d1 = dto.getStartTime().substring(0,4);
+        String d2 = dto.getStartTime().substring(4,6);
+        int year = Integer.parseInt(d1);
+        int month = Integer.parseInt(d2);
+        YearMonth ym = YearMonth.of(year, month);
+        LocalDate js = ym.atEndOfMonth();
+        dto.setStartTime(ym + "-01 23:59:59");
+        dto.setEndTime(js + " 23:59:59");
+        HighReportDto vo = ReportUtil.TargetManagementConvertHighReportDto(dto);
+        // 计算结果
+        String child = "";
+        String mom = "";
+        if(null != reportChild){
+            String childSql = ReportUtil.callSqlFormat(vo, reportChild.getBaseSql(), reportChild.getGatherSql(), null, null, null);
+            child = dao.targetSqlExecute(childSql);
+        } else {
+            child = "";
+        }
+        if(null != reportMom){
+            String momSql = ReportUtil.callSqlFormat(vo, reportMom.getBaseSql(), reportMom.getGatherSql(), null, null, null);
+            mom = dao.targetSqlExecute(momSql);
+        } else {
+            mom = "";
+        }
+
+        if (StringUtil.notBlank(child)) {
+            resultMap.put("childResult", child);
+        } else {
+            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), 4));
+            } else {
+                resultMap.put("calcResult", "");
+            }
+        } else {
+            resultMap.put("momResult", "");
+            if (StringUtil.notBlank(child)) {
+                resultMap.put("calcResult", child);
+            } else {
+                resultMap.put("calcResult", "");
+            }
+        }
+        return ResultVoUtil.success(resultMap);
+    }
+
+    /**
+     * @Description 根据月份查询指标月度结果以及得分情况
+     * @Author hsh
+     * @param dto 指标
+     * @return score 指标月度结果以及得分情况
+     * @Date 2024/11/20 17:15
+     */
+    public ResultVo<ZbReportMonthScore> selectTargetReportResultByMonth(ZbReportMonthScore dto) {
+        ZbReportMonthScore score = reportDao.selectReportResultByMonth(dto.getId(), dto.getPid(), dto.getMonth());
+        return ResultVoUtil.success(score);
+    }
+
+    /**
+     * @Description 保存指标计算结果以及得分情况
+     * @Author hsh
+     * @param monthScore 指标计算结果以及得分情况
+     * @return  map
+     * @Date 2024/11/20 17:16
+     */
+    public ResultVo<Map<String, Object>> saveTargetReportMonthResult(ZbReportMonthScore monthScore){
+        Map<String, Object> resultMap = new HashMap<>();
+        if(monthScore == null || null == monthScore.getId()){
+            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "指标id不存在,请检查!");
+        }
+
+        UserInfo user = redis.getUserInfoByCode(TokenUtil.getInstance().getTokenUserId());
+        monthScore.setAuthorName(user.getName() != null ? user.getName().trim() : null);
+        monthScore.setAuthorId(user.getCode());
+        monthScore.setDeptId(user.getDeptCode());
+        monthScore.setDeptName(user.getDeptName());
+        monthScore.setCreateTime(DateUtil.now());
+
+        // 入库或更新操作
+        int n = updateAndSaveTargetReportMonthResult(monthScore);
+        if (n <= 0) {
+            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "保存指标计算结果以及得分情况失败!");
+        }
+        resultMap.put("cg", "保存指标计算结果以及得分情况成功");
+        return ResultVoUtil.success(resultMap);
+    }
+
+    private int updateAndSaveTargetReportMonthResult(ZbReportMonthScore monthScore) {
+        if(monthScore == null){
+            return 0;
+        }
+        ZbReportMonthScore r = reportDao.selectReportResultByMonth(monthScore.getId(), monthScore.getPid(), monthScore.getMonth());
+        if(r != null){
+            reportDao.deleteReportResultMonthById(monthScore.getId(), monthScore.getPid(), monthScore.getMonth());
+        }
+        return reportDao.saveTargetReportMonthResult(monthScore);
+    }
+
+    /**
+     * @Description 根据月份,指标id查询指标得分详情
+     * @Author hsh
+     * @param dto 月份,指标id
+     * @return list
+     * @Date 2024/11/21 11:01
+     */
+    public ResultVo<List<ZbReportMonthScore>> selectTargetReportMonthScore(TargetManagement dto) {
+        List<ZbReportMonthScore> score = reportDao.selectTargetReportMonthResultById(dto.getId(), dto.getPid(), dto.getStartTime(), dto.getEndTime());
+        return ResultVoUtil.success(score);
+    }
+
 }

+ 28 - 5
src/main/java/thyyxxk/webserver/utils/TargetDictTreeUtil.java

@@ -15,15 +15,33 @@ public class TargetDictTreeUtil {
 
     // 保存参与构建树形的所有数据(通常数据库查询结果)
     public List<TargetDictTree> nodeList;
-
-    public static String TREE_ROOT_PID = "B0";
+    // 根节点的pid
+    public static final String TREE_ROOT_PID = "B0";
+    // 叶子节点示意(0: 不是叶子节点; 1:是叶子节点)
+    public static final String IS_LEAF_ZERO = "0";
+    public static final String IS_LEAF_ONE = "1";
 
     /**
      *  构造方法
      *  @param nodeList 将数据集合赋值给nodeList,即所有数据作为所有节点。
      */
-    public TargetDictTreeUtil(List<TargetDictTree> nodeList){
-        this.nodeList = nodeList;
+    public TargetDictTreeUtil(List<TargetDictTree> nodeList, String dept){
+        if(StringUtil.notBlank(dept)){
+            List<TargetDictTree> treeList = new ArrayList<>();
+            for(TargetDictTree tree : nodeList){
+                // 叶子节点才进行判断
+                if("1".equals(tree.getIsLeaf())){
+                    if(dept.equals(tree.getDeptCode())){
+                        treeList.add(tree);
+                    }
+                } else {
+                    treeList.add(tree);
+                }
+            }
+            this.nodeList = treeList;
+        } else {
+            this.nodeList = nodeList;
+        }
     }
 
     /**
@@ -73,7 +91,12 @@ public class TargetDictTreeUtil {
             // 判断当前节点的父节点ID是否等于根节点的ID,即当前节点为其下的子节点
             if (treeNode.getPid().equals(pNode.getId())) {
                 // 再递归进行判断当前节点的情况,调用自身方法
-                childTree.add(buildChildTree(treeNode));
+                TargetDictTree newTree = buildChildTree(treeNode);
+                if(!newTree.getChildren().isEmpty() && IS_LEAF_ZERO.equals(newTree.getIsLeaf())){
+                    childTree.add(newTree);
+                } else if(newTree.getChildren().isEmpty() && IS_LEAF_ONE.equals(newTree.getIsLeaf())){
+                    childTree.add(newTree);
+                }
             }
         }
         // for循环结束,即节点下没有任何节点,树形构建结束,设置树结果