hsh 2 rokov pred
rodič
commit
02d67961d3

+ 59 - 0
src/main/java/cn/hnthyy/thmz/controller/bb/ReportStaticController.java

@@ -0,0 +1,59 @@
+package cn.hnthyy.thmz.controller.bb;
+
+import cn.hnthyy.thmz.Utils.TokenUtil;
+import cn.hnthyy.thmz.comment.UserLoginToken;
+import cn.hnthyy.thmz.entity.thmz.User;
+import cn.hnthyy.thmz.service.his.bb.ReportStaticService;
+import cn.hnthyy.thmz.vo.ReportVo;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @Description: 报表统计Controller
+ * @Author: hsh
+ * @CreateTime: 2023-08-14  15:50
+ * @Version: 1.0
+ */
+@RestController
+@Slf4j
+public class ReportStaticController {
+
+    @Autowired
+    private ReportStaticService reportStaticService;
+
+    @UserLoginToken
+    @RequestMapping(value = "/selectDoctorIndexData", method = {RequestMethod.GET, RequestMethod.POST})
+    public Map<String, Object> selectDoctorIndexData(@RequestBody ReportVo vo, HttpServletRequest httpServletRequest) {
+        Map<String, Object> resultMap = new HashMap<>();
+        try {
+            if (StringUtils.isEmpty(vo.getReportId()) && vo.getReportIds() == null) {
+                resultMap.put("code", -1);
+                resultMap.put("message", "报表id为空,查询报表数据失败");
+                return resultMap;
+            }
+            User user = TokenUtil.getUser(httpServletRequest);
+            vo.setDoctorId(user.getUserIdCode());
+            Map<String, Object> map = reportStaticService.selectDoctorIndexData(vo);
+            resultMap.put("code", 0);
+            resultMap.put("message", "查询报表数据成功");
+            resultMap.put("data", map);
+            return resultMap;
+        } catch (Exception e) {
+            log.error("查询报表数据,错误信息{}", e);
+            resultMap.put("code", -1);
+            resultMap.put("message", "查询报表数据失败");
+            return resultMap;
+        }
+    }
+}

+ 68 - 0
src/main/java/cn/hnthyy/thmz/entity/his/bb/ReportBaseInfo.java

@@ -0,0 +1,68 @@
+package cn.hnthyy.thmz.entity.his.bb;
+
+import cn.hnthyy.thmz.annotation.NotColumn;
+import lombok.Data;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @Description: 报表基本信息表实体
+ * @Author: hsh
+ * @CreateTime: 2023-08-14  17:18
+ * @Version: 1.0
+ */
+@Data
+public class ReportBaseInfo {
+
+    private String reportId;
+    private String reportName;
+    /**
+     * 报表类型(zy:在院,cy:出院,mz:门诊,qt:其他)
+     **/
+    private String reportType;
+    private String unit;
+    /**
+     * 质控等级(1.正常,2.一般,3.中度,4.严重) 或者展示分组条件(例如group_ks:以科室为首分组,走科室-医生-病人路线)
+     **/
+    private String level;
+    private String gatherSql;
+    private String baseSql;
+    /**
+     * 展示类型(mx:明细,qst:趋势图,fbt:分布图包括柱状图或者饼状图)
+     **/
+    private String displayType;
+    private String flag;
+    private String menuId;
+    /**
+     * 面板排序
+     **/
+    private Integer sort;
+    /**
+     * 报表默认排序
+     **/
+    private String reportSort;
+    /**
+     * 是否是财务报表指标
+     **/
+    private String isCw;
+    /**
+     * 是否是医技报表指标
+     **/
+    private String isYj;
+    /**
+     * 指标计算-分子
+     **/
+    private String calcChild;
+    /**
+     * 指标计算-分母
+     **/
+    private String calcMom;
+    /**
+     * 页面查询的数据结果
+     **/
+    @NotColumn
+    private List<Map<String, Object>> dataList;
+
+
+}

+ 33 - 0
src/main/java/cn/hnthyy/thmz/mapper/his/bb/ReportStaticMapper.java

@@ -0,0 +1,33 @@
+package cn.hnthyy.thmz.mapper.his.bb;
+
+import cn.hnthyy.thmz.entity.his.bb.ReportBaseInfo;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
+
+import java.util.List;
+import java.util.Map;
+
+public interface ReportStaticMapper {
+
+    @Select("<script> " +
+            " select * from report_base_info where flag = 'Y' " +
+            " <if test=\"reportId != null and reportId != '' \"> " +
+            " and report_id = #{reportId} " +
+            " </if> " +
+            " <if test=\"reportType != null and reportType != '' \"> " +
+            " and report_type = #{reportType} " +
+            " </if> " +
+            " <if test=\"menuId != null and menuId != '' \"> " +
+            " and menu_id = #{menuId} " +
+            " </if> " +
+            " order by sort " +
+            "</script> ")
+    ReportBaseInfo selectReportBaseInfo(@Param("reportId") String reportId, @Param("reportType") String reportType, @Param("menuId") String menuId);
+
+    @Select("<script> ${sql} </script>")
+    String selectReportTotal(@Param("sql") String sql);
+
+    @Select("<script> ${sql} </script>")
+    List<Map<String, Object>> selectReportRegList(@Param("sql") String sql);
+
+}

+ 19 - 0
src/main/java/cn/hnthyy/thmz/service/his/bb/ReportStaticService.java

@@ -0,0 +1,19 @@
+package cn.hnthyy.thmz.service.his.bb;
+
+import cn.hnthyy.thmz.vo.ReportVo;
+
+import java.util.List;
+import java.util.Map;
+
+public interface ReportStaticService {
+
+    /**
+     * @description: 查询医生首页报表数据
+     * @author: hsh
+     * @date: 2023/8/14 16:54
+     * @param: [vo]
+     * @return: Map<String,Object>
+     **/
+    Map<String, Object> selectDoctorIndexData(ReportVo vo);
+
+}

+ 170 - 0
src/main/java/cn/hnthyy/thmz/service/impl/his/bb/ReportStaticServiceImpl.java

@@ -0,0 +1,170 @@
+package cn.hnthyy.thmz.service.impl.his.bb;
+
+import cn.hnthyy.thmz.Utils.DateUtil;
+import cn.hnthyy.thmz.entity.his.bb.ReportBaseInfo;
+import cn.hnthyy.thmz.mapper.his.bb.ReportStaticMapper;
+import cn.hnthyy.thmz.service.his.bb.ReportStaticService;
+import cn.hnthyy.thmz.vo.ReportVo;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @Description: 报表统计实现类
+ * @Author: hsh
+ * @CreateTime: 2023-08-14  16:51
+ * @Version: 1.0
+ */
+@Service
+public class ReportStaticServiceImpl implements ReportStaticService {
+
+    private static final String START_TIME = ":startTime";
+    private static final String END_TIME = ":endTime";
+    /**
+     * 科室(下拉选查询使用)
+     **/
+    private static final String DEPT = "dept";
+    /**
+     * 医生(下拉选查询使用)
+     **/
+    private static final String DOCTOR = "doctor";
+    /**
+     * 科室id
+     **/
+    private static final String DEPT_ID = "deptId";
+    /**
+     * 医生id
+     **/
+    private static final String DOCTOR_ID = "doctorId";
+    /**
+     * 诊断(模糊查询使用)
+     **/
+    private static final String DIAGN = "diagn";
+
+    /**
+     * 住院号
+     **/
+    private static final String ZYH = "zyh";
+    /**
+     * 姓名(模糊查询使用)
+     **/
+    private static final String XM = "xm";
+    /**
+     * 号别(下拉选查询使用)
+     **/
+    private static final String REG_LEVEL = "regLevel";
+
+    private static final String OTHER_PARAM = "其他";
+
+    @SuppressWarnings("all")
+    @Autowired
+    private ReportStaticMapper reportStaticMapper;
+
+    @Override
+    public Map<String, Object> selectDoctorIndexData(ReportVo vo) {
+
+        Map<String, Object> resultMap = new HashMap<>();
+        String reportId = vo.getReportId();
+        String type = vo.getType();
+        List<String> reportIds = vo.getReportIds();
+        if(reportIds != null && reportIds.size() > 0){
+            List<Map<String, Object>> list = new ArrayList<>();
+            for (String id: reportIds) {
+                Map<String, Object> map = new HashMap<>();
+                ReportBaseInfo info = reportStaticMapper.selectReportBaseInfo(id, vo.getReportType(), null);
+                if("1".equals(type)){
+                    String sql = callSqlFormat(vo, info.getBaseSql(), info.getGatherSql(), "", info.getReportSort());
+                    String result = reportStaticMapper.selectReportTotal(sql);
+                    resultMap.put(info.getReportName(), result);
+                } else if("2".equals(type)) {
+                    String gatherSql = info.getGatherSql() + " as num,  t." + vo.getGroupColumn() + " ";
+                    String sql = callSqlFormat(vo, info.getBaseSql(), gatherSql, vo.getGroupColumn(), info.getReportSort());
+                    List<Map<String, Object>> l = reportStaticMapper.selectReportRegList(sql);
+                    resultMap.put(info.getReportName(), l);
+                }
+            }
+        } else {
+            ReportBaseInfo info = reportStaticMapper.selectReportBaseInfo(reportId, vo.getReportType(), null);
+            if("1".equals(type)) {
+                String sql = callSqlFormat(vo, info.getBaseSql(), info.getGatherSql(), "", info.getReportSort());
+                String result = reportStaticMapper.selectReportTotal(sql);
+                resultMap.put(info.getReportName(), result);
+            } else if("2".equals(type)) {
+                String gatherSql = info.getGatherSql() + " as num,  t." + vo.getGroupColumn() + " ";
+                String sql = callSqlFormat(vo, info.getBaseSql(), gatherSql, vo.getGroupColumn(), info.getReportSort());
+                List<Map<String, Object>> l = reportStaticMapper.selectReportRegList(sql);
+                resultMap.put(info.getReportName(), l);
+            }
+        }
+        return resultMap;
+    }
+
+    /**
+     * @description:
+     * @author: hsh
+     * @date: 2023/8/14 17:39
+     * @param: [vo, baseSql, gatherSql, groupColumn, reportSort] vo 参数实体类;baseSql:基础sql;gatherSql:聚合sql;groupColumn:分组;reportSort:排序;
+     * @return: String
+     **/
+    private String callSqlFormat(ReportVo dto, String baseSql, String gatherSql, String groupColumn, String reportSort) {
+
+        // 查询必填字段(包括开始时间,结束时间,钻取科室,医生等sql用:拼接的字符)替换
+        if(baseSql.contains(START_TIME)){
+            if(StringUtils.isNotEmpty(dto.getStartTime())){
+                baseSql = baseSql.replaceAll(START_TIME, "'" + dto.getStartTime() + "'");
+            } else {
+                baseSql = baseSql.replaceAll(START_TIME,"'2012-01-01 00:00:00'");
+            }
+        }
+        if(baseSql.contains(END_TIME)){
+            if(StringUtils.isNotEmpty(dto.getEndTime())){
+                baseSql = baseSql.replaceAll(END_TIME, "'" + dto.getEndTime() + "'");
+            } else {
+                baseSql = baseSql.replaceAll(END_TIME, DateUtil.fomart(DateUtil.getLastSecond(new Date()), "yyyy-MM-dd HH:mm:ss"));
+            }
+        }
+        // 查询非必填字段(一般是下拉选险种,模糊查询科室、诊断等sql用_拼接的字符)
+        StringBuilder sql = new StringBuilder();
+        sql.append(" select ").append(gatherSql).append(" from (").append(baseSql).append(") t where 1 = 1 ");
+        if(baseSql.contains(DEPT_ID) && StringUtils.isNotEmpty(dto.getDeptId())){
+            sql.append(" and t.deptId = '").append(dto.getDeptId()).append("' ");
+        }
+        if(baseSql.contains(DOCTOR_ID) && StringUtils.isNotEmpty(dto.getDoctorId())){
+            sql.append(" and t.doctorId = '").append(dto.getDoctorId()).append("' ");
+        }
+        if(baseSql.contains(DEPT) && StringUtils.isNotEmpty(dto.getDept())){
+            sql.append(" and t.dept = '").append(dto.getDept()).append("' ");
+        }
+        if(baseSql.contains(DOCTOR) && StringUtils.isNotEmpty(dto.getDoctor())){
+            sql.append(" and t.doctor = '").append(dto.getDoctor()).append("' ");
+        }
+        if(baseSql.contains(REG_LEVEL) && StringUtils.isNotEmpty(dto.getRegLevel())){
+            sql.append(" and t.regLevel = '").append(dto.getRegLevel()).append("' ");
+        }
+        if(baseSql.contains(DIAGN) && StringUtils.isNotEmpty(dto.getDiagn())){
+            sql.append(" and t.diagn like '%").append(dto.getDiagn()).append("%' ");
+        }
+        if(baseSql.contains(ZYH) && StringUtils.isNotEmpty(dto.getZyh())){
+            sql.append(" and t.zyh = '").append(dto.getZyh()).append("' ");
+        }
+        if(baseSql.contains(XM) && StringUtils.isNotEmpty(dto.getXm())){
+            sql.append(" and t.xm like '%").append(dto.getXm()).append("%' ");
+        }
+        // 如果存在分组情况,需要添加分组sql字段
+        if(StringUtils.isNotEmpty(groupColumn)){
+            sql.append(" group by t.").append(groupColumn);
+        }
+        // 如果存在默认排序,需要添加排序sql
+        if(StringUtils.isNotEmpty(reportSort)){
+            sql.append(" order by t.").append(reportSort);
+        }
+        return sql.toString();
+    }
+
+}

+ 66 - 0
src/main/java/cn/hnthyy/thmz/vo/ReportVo.java

@@ -0,0 +1,66 @@
+package cn.hnthyy.thmz.vo;
+
+import lombok.Data;
+
+import java.util.List;
+
+/**
+ * @Description: 报表查询参数实体类
+ * @Author: hsh
+ * @CreateTime: 2023-08-14  16:11
+ * @Version: 1.0
+ */
+@Data
+public class ReportVo {
+
+    private String startTime;
+    private String endTime;
+    private String reportId;
+    private String reportType;
+    private String menuId;
+    /**
+     * 报表id集合
+     **/
+    private List<String> reportIds;
+    /**
+     * 报表数据展示方式:1 求总和; 2 根据时间段求和 3 其他。。。
+     **/
+    private String type;
+    /**
+     * 科室
+     **/
+    private String dept;
+    /**
+     * 医生
+     **/
+    private String doctor;
+    /**
+     * 科室id
+     **/
+    private String deptId;
+    /**
+     * 医生id
+     **/
+    private String doctorId;
+    /**
+     * 诊断
+     **/
+    private String diagn;
+    /**
+     * 住院号
+     **/
+    private String zyh;
+    /**
+     * 姓名
+     **/
+    private String xm;
+    /**
+     * 号别
+     **/
+    private String regLevel;
+    /**
+     * 分组标识字段
+     **/
+    private String groupColumn;
+
+}