|
|
@@ -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();
|
|
|
+ }
|
|
|
+
|
|
|
+}
|