Browse Source

增加配置化报表开发模式

hsh 2 years ago
parent
commit
84dbe8eeaf

+ 53 - 0
src/main/java/thyyxxk/webserver/controller/highreport/HighReportController.java

@@ -0,0 +1,53 @@
+package thyyxxk.webserver.controller.highreport;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+import thyyxxk.webserver.config.auth.PassToken;
+import thyyxxk.webserver.entity.ResultVo;
+import thyyxxk.webserver.entity.highreport.HighReportDto;
+import thyyxxk.webserver.entity.highreport.ReportBaseInfo;
+import thyyxxk.webserver.service.highreport.HighReportService;
+
+import javax.servlet.http.HttpServletResponse;
+import java.util.Map;
+
+/**
+ * @Description: 指控指标报表统一查询入口
+ * @Author: hsh
+ * @CreateTime: 2022-10-31  17:03
+ * @Version: 1.0
+ */
+@RestController
+@RequestMapping("/highReport")
+public class HighReportController {
+
+    private final HighReportService service;
+
+    @Autowired
+    public HighReportController(HighReportService service) {
+        this.service = service;
+    }
+
+    @PassToken
+    @PostMapping("/selectReportPortal")
+    public ResultVo<Map<String, Object>> selectReportPortal(@RequestBody @Validated HighReportDto dto){
+        return service.selectReportPortal(dto);
+    }
+
+    @PassToken
+    @PostMapping("/selectReportPortalMenu")
+    public ResultVo<ReportBaseInfo> selectReportPortalMenu(@RequestBody @Validated HighReportDto dto){
+        return service.selectReportPortalMenu(dto);
+    }
+
+    @PassToken
+    @PostMapping("/exportReportPortalData")
+    public void exportReportPortalData(HttpServletResponse response, @RequestBody @Validated HighReportDto dto){
+        service.exportReportPortalData(response, dto);
+    }
+
+}

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

@@ -0,0 +1,56 @@
+package thyyxxk.webserver.dao.his.highreport;
+
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
+import thyyxxk.webserver.entity.highreport.ReportBaseInfo;
+import thyyxxk.webserver.entity.highreport.TableDisplayInfo;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @description: 报表
+ * @author: hsh
+ * @date: 2022/11/2 10:32
+ **/
+@Mapper
+public interface HighReportDao {
+
+    @Select("<script> " +
+            " select * from report_base_info where flag = 'Y' " +
+            " <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> ")
+    List<ReportBaseInfo> selectReportPortal(@Param("reportType")String reportType, @Param("menuId")String menuId);
+
+    @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 selectReportPortalMenu(@Param("reportId") String reportId, @Param("menuId")String menuId, @Param("reportType")String reportType);
+
+    @Select(" select * from table_display_info where flag = 'Y' " +
+            " and report_id = #{reportId} " +
+            " order by sort ")
+    List<TableDisplayInfo> selectTableDisplayInfoByReportId(@Param("reportId") String reportId);
+
+    @Select("<script> ${sql} </script>")
+    List<Map<String, Object>> selectReportPortalData(@Param("reportId") String reportId, @Param("menuId")String menuId,
+                                                     @Param("reportType")String reportType, @Param("sql")String sql);
+
+}

+ 38 - 0
src/main/java/thyyxxk/webserver/entity/highreport/HighReportDto.java

@@ -0,0 +1,38 @@
+package thyyxxk.webserver.entity.highreport;
+
+import lombok.Data;
+
+/**
+ * @Description: 报表查询dto
+ * @Author: hsh
+ * @CreateTime: 2022-11-02  09:09
+ * @Version: 1.0
+ */
+@Data
+public class HighReportDto {
+
+    private String reportId;
+    private String reportName;
+    private String reportType;
+    private String menuId;
+    private String level;
+    private String startTime;
+    private String endTime;
+    /**
+     * 险种
+     **/
+    private String insurName;
+    /**
+     * 诊断
+     **/
+    private String diagn;
+    /**
+     * 类型:1.单个菜单;2.功能集合页面(单个页面填写菜单id,功能集合页面填写功能页面的父菜单id)
+     **/
+    private String type;
+    /**
+     * 导出excel表格标题
+     **/
+    private String exportName;
+
+}

+ 57 - 0
src/main/java/thyyxxk/webserver/entity/highreport/ReportBaseInfo.java

@@ -0,0 +1,57 @@
+package thyyxxk.webserver.entity.highreport;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @Description: 报表基础信息
+ * @Author: hsh
+ * @CreateTime: 2022-11-01  16:47
+ * @Version: 1.0
+ */
+@Data
+@TableName("report_base_info")
+public class ReportBaseInfo implements Serializable {
+
+    private String reportId;
+    private String reportName;
+    /**
+     * 报表类型(zy:在院,cy:出院,mz:门诊,qt:其他)
+     **/
+    private String reportType;
+    private String unit;
+    /**
+     * 质控等级(1.正常,2.一般,3.中度,4.严重)
+     **/
+    private String level;
+    private String gatherSql;
+    private String baseSql;
+    /**
+     * 展示类型(mx:明细,qst:趋势图,fbt:分布图包括柱状图或者饼状图)
+     **/
+    private String displayType;
+    private String flag;
+    private String menuId;
+    private Integer sort;
+    /**
+     * 页面展示
+     **/
+    @TableField("exist = false")
+    private List<TableDisplayInfo> tableDisplays;
+    /**
+     * 页面查询的数据结果
+     **/
+    @TableField("exist = false")
+    private List<Map<String, Object>> dataList;
+    /**
+     * 页面合计
+     **/
+    @TableField("exist = false")
+    private Map<String, Object> total;
+
+}

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

@@ -0,0 +1,83 @@
+package thyyxxk.webserver.entity.highreport;
+
+import org.jetbrains.annotations.Nullable;
+import thyyxxk.webserver.utils.StringUtil;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @description: 报表所需字典类型集合
+ * @author: hsh
+ * @date: 2022/11/2 10:56
+ **/
+public enum ReportType {
+    ONE("1", "单个菜单"),
+
+    TWO("2", "功能集合页面"),
+
+    THREE("3", "其他"),
+
+    ZY("zy_jc", "在院运营监测"),
+
+    CY("cy_jc", "出院运营监测"),
+
+    MZ("mz_jc", "门诊运营监测"),
+
+    QT("qt_jc", "其他运营监测"),
+
+    MX("mx_show", "明细"),
+
+    QST("qst_show", "趋势图"),
+
+    FBT("fbt_show", "分布图");
+
+    private final String code;
+    private final String name;
+
+    ReportType(String code, String name) {
+        this.code = code;
+        this.name = name;
+    }
+
+    public String getCode() {
+        return code;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public static @Nullable String find(String code) {
+        if (StringUtil.isBlank(code)) {
+            return null;
+        }
+        for (ReportType type : ReportType.values()) {
+            if(type.getCode().startsWith(code)){
+                return type.getName();
+            }
+        }
+        return null;
+    }
+
+    /**
+     * @description: 获取对应的枚举(以”_“加code或者code结尾)
+     * @author: hsh
+     * @date: 2022/11/2 11:22
+     * @param: [code]
+     * @return: List<ReportType>
+     **/
+    public static @Nullable List<ReportType> get(String code) {
+        if (StringUtil.isBlank(code)) {
+            return null;
+        }
+        List<ReportType> list = new ArrayList<>();
+        for (ReportType type : ReportType.values()) {
+            if(type.getCode().endsWith(code)){
+                list.add(type);
+            }
+        }
+        return list;
+    }
+
+}

+ 47 - 0
src/main/java/thyyxxk/webserver/entity/highreport/TableDisplayInfo.java

@@ -0,0 +1,47 @@
+package thyyxxk.webserver.entity.highreport;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+
+import java.util.List;
+
+/**
+ * @Description: 表格展示字段
+ * @Author: hsh
+ * @CreateTime: 2022-11-01  16:58
+ * @Version: 1.0
+ */
+@Data
+@TableName("table_display_info")
+public class TableDisplayInfo {
+
+    private String reportId;
+    /**
+     * 报表层级(比如ks: 科室;ys: 医生;br: 病人明细等等)
+     **/
+    private String levelId;
+    private String levelName;
+    private String title;
+    private String prop;
+    private String label;
+    private String align;
+    private String width;
+    private String sortable;
+    private String flag;
+    private Integer sort;
+    /**
+     * 表格行id
+     **/
+    private String id;
+    /**
+     * 表格行父id
+     **/
+    private String pid;
+    /**
+     * 图表X,Y轴参数
+     **/
+    @TableField("exist = false")
+    private List<XYBean> beans;
+
+}

+ 19 - 0
src/main/java/thyyxxk/webserver/entity/highreport/XYBean.java

@@ -0,0 +1,19 @@
+package thyyxxk.webserver.entity.highreport;
+
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+/**
+ * @Description: 图表X,Y轴数据实体
+ * @Author: hsh
+ * @CreateTime: 2022-11-03  09:08
+ * @Version: 1.0
+ */
+@Data
+public class XYBean {
+
+    private String x;
+    private BigDecimal y;
+
+}

+ 176 - 0
src/main/java/thyyxxk/webserver/service/highreport/HighReportService.java

@@ -0,0 +1,176 @@
+package thyyxxk.webserver.service.highreport;
+
+import lombok.extern.slf4j.Slf4j;
+import org.jetbrains.annotations.NotNull;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import thyyxxk.webserver.config.exception.ExceptionEnum;
+import thyyxxk.webserver.dao.his.highreport.HighReportDao;
+import thyyxxk.webserver.entity.HeadInfo;
+import thyyxxk.webserver.entity.ResultVo;
+import thyyxxk.webserver.entity.highreport.HighReportDto;
+import thyyxxk.webserver.entity.highreport.ReportBaseInfo;
+import thyyxxk.webserver.entity.highreport.ReportType;
+import thyyxxk.webserver.entity.highreport.TableDisplayInfo;
+import thyyxxk.webserver.utils.ExcelUtil;
+import thyyxxk.webserver.utils.ReportUtil;
+import thyyxxk.webserver.utils.ResultVoUtil;
+import thyyxxk.webserver.utils.StringUtil;
+
+import javax.servlet.http.HttpServletResponse;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+/**
+ * @Description: 报表统一门户入口
+ * @Author: hsh
+ * @CreateTime: 2022-10-31  17:04
+ * @Version: 1.0
+ */
+@Service
+@Slf4j
+public class HighReportService {
+
+    private final HighReportDao dao;
+
+    @Autowired
+    public HighReportService(HighReportDao dao) {
+        this.dao = dao;
+    }
+
+    public ResultVo<Map<String, Object>> selectReportPortal(HighReportDto dto) {
+        Map<String, Object> map = new HashMap<>();
+        String reportType = dto.getReportType();
+        String menuId = dto.getMenuId();
+        String title = ReportType.find(reportType);
+        List<ReportBaseInfo> reportList = dao.selectReportPortal(reportType, menuId);
+        map.put("title", title);
+        map.put("data", reportList);
+        return ResultVoUtil.success(map);
+    }
+
+    /**
+     * @description: 单个报表查询页面数据展示以及数据结果信息
+     * @author: hsh
+     * @date: 2022/11/4 9:10
+     * @param: [dto]
+     * @return: ResultVo<ReportBaseInfo>
+     **/
+    public ResultVo<ReportBaseInfo> selectReportPortalMenu(HighReportDto dto) {
+        String reportId = dto.getReportId();
+        String menuId = dto.getMenuId();
+        String reportType = dto.getReportType();
+        ReportBaseInfo report = dao.selectReportPortalMenu(reportId, menuId, reportType);
+        if(null == report){
+            log.info("没有配置报表参数");
+            return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST);
+        }
+
+        List<TableDisplayInfo> tableInfoList = dao.selectTableDisplayInfoByReportId(reportId);
+        if(tableInfoList.size() == 0){
+            log.info("没有配置报表页面展示表格信息");
+            return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST);
+        }
+        report.setTableDisplays(tableInfoList);
+
+        // 根据配置的sql查询数据结果
+        // 组装查询sql
+        String baseSql = report.getBaseSql();
+        String gatherSql = report.getGatherSql();
+        String sql = ReportUtil.callSqlFormat(dto, baseSql, gatherSql);
+        log.info("查询sql: {}", sql);
+        // 查询结果
+        List<Map<String, Object>> dataList = dao.selectReportPortalData(reportId, menuId, reportType, sql);
+        report.setDataList(dataList);
+        return ResultVoUtil.success(report);
+    }
+
+    /**
+     * @description: 报表数据导出
+     * @author: hsh
+     * @date: 2022/11/7 10:26
+     * @param: [response, dto]
+     * @return: ResultVo<String>
+     **/
+    public ResultVo<Map<String, Object>> exportReportPortalData(HttpServletResponse response, HighReportDto dto){
+        Map<String, Object> map = new HashMap<>();
+        ResultVo<ReportBaseInfo> resultVo = selectReportPortalMenu(dto);
+        ReportBaseInfo report = resultVo.getData();
+        if(null == report || report.getDataList().size() == 0){
+            map.put("code", 1);
+            map.put("massage", "查询数据为空,导出失败!");
+            return ResultVoUtil.success(map);
+        }
+
+        // 数据
+        List<Map<String, Object>> list = report.getDataList();
+        // 合计
+        if(null != report.getTotal() && report.getTotal().size() != 0){
+            Map<String, Object> total = report.getTotal();
+            list.add(total);
+        }
+
+        // 导出标题
+        String exportName = dto.getExportName();
+
+        // 组装表头
+        List<HeadInfo> headInfoList = calHeadList(report.getTableDisplays());
+
+        // 导出
+        ExcelUtil.exportExcelReport(response, list, headInfoList, exportName);
+
+        map.put("code", 0);
+        map.put("massage", "导出成功!");
+        return ResultVoUtil.success(map);
+    }
+
+    /**
+     * @description: 组装导出的表头
+     * @author: hsh
+     * @date: 2022/11/7 11:17
+     * @param: [tableDisplays]
+     * @return: List<HeadInfo>
+     **/
+    private @NotNull List<HeadInfo> calHeadList(@NotNull List<TableDisplayInfo> tableDisplays) {
+        List<HeadInfo> headList = new ArrayList<>();
+        Map<String, List<TableDisplayInfo>> map = tableDisplays.stream().collect(
+                Collectors.groupingBy(TableDisplayInfo::getPid, Collectors.toList()));
+
+        for(Map.Entry<String, List<TableDisplayInfo>> entry : map.entrySet()){
+            String pid = entry.getKey();
+            List<TableDisplayInfo> list = entry.getValue();
+            HeadInfo headInfo = new HeadInfo();
+            List<HeadInfo> headInfoChildrenList = new ArrayList<>();
+            for(TableDisplayInfo table : list){
+                String id = table.getId();
+                /*
+                * 重要:一定要维护父id!!!一定要维护父id!!!一定要维护父id!!!
+                * 表格行父id是独一无二的一个,证明是单独一个表格个列,没有多表头,放在同一个表头对象中
+                * 如果表格行id与表格行父id是一样的话,表示这条记录是此表格行的父级行,其余的都是表格的子级行
+                *(例如二级表头pid与id父子关系:1 1,1 2,1 3,1 4 其中1 1是父级表头,1 2、1 3、1 4都是它的子级表头)
+                */
+                if(StringUtil.notBlank(pid) && id.equals(pid)){
+                    headInfo.setDisplay(table.getLabel());
+                    headInfo.setName(table.getProp());
+                } else if(StringUtil.notBlank(pid) && !id.equals(pid)){
+                    HeadInfo headInfoChild = new HeadInfo();
+                    headInfoChild.setDisplay(table.getLabel());
+                    headInfoChild.setName(table.getProp());
+                    headInfoChildrenList.add(headInfoChild);
+                } else {
+                    headInfo.setDisplay(table.getLabel());
+                    headInfo.setName(table.getProp());
+                }
+            }
+            if(headInfoChildrenList.size() > 0){
+                headInfo.setColumns(headInfoChildrenList);
+            }
+            headList.add(headInfo);
+        }
+        return headList;
+    }
+
+}

+ 20 - 10
src/main/java/thyyxxk/webserver/utils/ExcelUtil.java

@@ -30,6 +30,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
@@ -187,7 +188,14 @@ public class ExcelUtil {
         }
     }
 
-    public static void exportExcelReport(HttpServletResponse response, List<Map<String, Object>> recordList, List<HeadInfo> headlList, String report_name) {
+    /**
+     * @description: 后台导出excel
+     * @author: hsh
+     * @date: 2022/11/4 8:47
+     * @param: [response, recordList 导出数据, headList 导出excel表头, report_name 导出excel名称、标题]
+     * @return: void
+     **/
+    public static void exportExcelReport(HttpServletResponse response, List<Map<String, Object>> recordList, List<HeadInfo> headList, String report_name) {
         // Excel数据拼接
         HSSFWorkbook wb = new HSSFWorkbook();
 
@@ -197,7 +205,7 @@ public class ExcelUtil {
 
         boolean isSecondaryMeter = false; // 不存在二级表头
 
-        for (HeadInfo head : headlList) {
+        for (HeadInfo head : headList) {
             if(!"操作".equals(head.getDisplay())){
                 if(head.getColumns() != null){
                     List<HeadInfo>  columns = head.getColumns();
@@ -249,16 +257,17 @@ public class ExcelUtil {
         }
 
         int index = 0 ;
-        List<String> keyList = new ArrayList<String>();
-        for (HeadInfo head : headlList) {
+        List<String> keyList = new ArrayList<>();
+        for (HeadInfo head : headList) {
             if(!"操作".equals(head.getDisplay())){
                 if(head.getColumns() != null){
                     List<HeadInfo>  columns = head.getColumns();
                     CellRangeAddress cra = new CellRangeAddress(1, 1, index, index+columns.size()-1);
                     sheet.addMergedRegion(cra);
                     createCellRangeBorder(cra, sheet);
-                    createHeaderInfo(row2,cellStyle,index,head.getDisplay(), report_name);
+                    createHeaderInfo(row2,cellStyle,index,head.getDisplay());
                     for (HeadInfo column : columns) {
+                        assert row3 != null;
                         createHeader(row3,cellStyle,index,column.getDisplay());
                         keyList.add(column.getName());
                         index++;
@@ -269,7 +278,7 @@ public class ExcelUtil {
                         sheet.addMergedRegion(cra);
                         createCellRangeBorder(cra, sheet);
                     }
-                    createHeaderInfo(row2,cellStyle,index,head.getDisplay(), report_name);
+                    createHeaderInfo(row2,cellStyle,index,head.getDisplay());
                     keyList.add(head.getName());
                     index++;
                 }
@@ -282,7 +291,7 @@ public class ExcelUtil {
             HSSFRow row = sheet.createRow(index2);
 
             for (int i = 0; i < keyList.size(); i++) {
-                createHeaderInfo(row,cellStyle,i,(map.get(keyList.get(i))==null?"":map.get(keyList.get(i)).toString())+"", report_name);
+                createHeaderInfo(row,cellStyle,i,(map.get(keyList.get(i))==null?"":map.get(keyList.get(i)).toString())+"");
 
             }
             index2++;
@@ -333,7 +342,8 @@ public class ExcelUtil {
 
     private static void createHeader(HSSFRow hfCell1, HSSFCellStyle cellStyle, int column, String value) {
         HSSFCell row = hfCell1.createCell(column);
-        row.setCellStyle(cellStyle);// 将样式应用于单元格
+        // 将样式应用于单元格
+        row.setCellStyle(cellStyle);
         if(StringUtils.isNotEmpty(value) && !"null".equals(value)){
             value=processNumer(value);
             row.setCellValue(value);
@@ -343,7 +353,7 @@ public class ExcelUtil {
         }
     }
 
-    private static void createHeaderInfo(HSSFRow hfCell1, HSSFCellStyle cellStyle, int column, String value, String title) {
+    private static void createHeaderInfo(HSSFRow hfCell1, HSSFCellStyle cellStyle, int column, String value) {
         HSSFCell row = hfCell1.createCell(column);
         // 将样式应用于单元格
         row.setCellStyle(cellStyle);
@@ -362,7 +372,7 @@ public class ExcelUtil {
         if(value.contains(".") && value.matches(pattren)){
             try{
                 BigDecimal bigDecimal=new BigDecimal(value);
-                bigDecimal=bigDecimal.setScale(2,BigDecimal.ROUND_HALF_UP);
+                bigDecimal=bigDecimal.setScale(2, RoundingMode.HALF_UP);
                 return bigDecimal.toString();
             }catch (Exception e){
                 return value;

+ 52 - 0
src/main/java/thyyxxk/webserver/utils/ReportUtil.java

@@ -0,0 +1,52 @@
+package thyyxxk.webserver.utils;
+
+import org.jetbrains.annotations.NotNull;
+import thyyxxk.webserver.entity.highreport.HighReportDto;
+
+/**
+ * @Description: 报表相关的工具类
+ * @Author: hsh
+ * @CreateTime: 2022-11-04  08:34
+ * @Version: 1.0
+ */
+public class ReportUtil {
+
+    private static final String START_TIME = ":startTime";
+    private static final String END_TIME = ":endTime";
+    /**
+     * 险种(下拉选查询使用)
+     **/
+    private static final String INSUR_NAME = "_insurName";
+    /**
+     * 诊断(模糊查询使用)
+     **/
+    private static final String DIAGN = "_diagn";
+
+    /**
+     * @description: 拼接查询数据的sql(备注:采用了script标签包裹方式拼接sql)
+     * @author: hsh
+     * @date: 2022/11/7 16:21
+     * @param: [dto, baseSql, gatherSql]
+     * @return: String
+     **/
+    public static @NotNull String callSqlFormat(HighReportDto dto, @NotNull String baseSql, String gatherSql){
+        // 查询必填字段(包括开始时间,结束时间,钻取科室,医生等sql用:拼接的字符)替换
+        if(baseSql.contains(START_TIME)){
+            baseSql = baseSql.replaceAll(START_TIME, "'" + dto.getStartTime() + "'");
+        }
+        if(baseSql.contains(END_TIME)){
+            baseSql = baseSql.replaceAll(END_TIME, "'" + dto.getEndTime() + "'");
+        }
+        // 查询非必填字段(一般是下拉选险种,模糊查询科室、诊断等sql用_拼接的字符)
+        StringBuilder sql = new StringBuilder();
+        sql.append(" select ").append(gatherSql).append(" from (").append(baseSql).append(") t where 1 = 1 ");
+        if(baseSql.contains(INSUR_NAME) && StringUtil.notBlank(dto.getInsurName())){
+            sql.append(" and t._insurName = '").append(dto.getInsurName()).append("' ");
+        }
+        if(baseSql.contains(DIAGN) && StringUtil.notBlank(dto.getDiagn())){
+            sql.append(" and t._diagn like '%").append(dto.getDiagn()).append("%' ");
+        }
+        return sql.toString();
+    }
+
+}