liusheng
昨天 29069b790469cb7136cadba7ddcd63a83bc4ac70
门急诊分表代码(增、改、查)提交
已修改28个文件
已添加1个文件
2939 ■■■■■ 文件已修改
ruoyi-admin/src/main/java/com/ruoyi/web/component/DeptUtils.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-admin/src/main/java/com/ruoyi/web/controller/smartor/PatMedOuthospController.java 26 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-admin/src/main/java/com/ruoyi/web/controller/smartor/PersonWorkbenchController.java 16 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-admin/src/main/java/com/ruoyi/web/controller/smartor/ServiceTaskController.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-admin/src/main/java/com/ruoyi/web/controller/smartor/SvyTaskSingleController.java 12 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-quartz/src/main/java/com/ruoyi/quartz/service/impl/CollectHISServiceImpl.java 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/RyTask.java 21 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-quartz/src/main/java/com/ruoyi/quartz/util/CreateDataTable.java 587 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/java/com/smartor/mapper/PatArchiveMapper.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/java/com/smartor/mapper/PatArchiveOutMapper.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/java/com/smartor/mapper/PatMedInhospMapper.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/java/com/smartor/mapper/PatMedOuthospMapper.java 129 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/java/com/smartor/mapper/ServiceSubtaskMapper.java 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/java/com/smartor/service/PersonWorkbenchService.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/java/com/smartor/service/impl/HNGatherPatArchiveServiceImpl.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/java/com/smartor/service/impl/PatArchiveServiceImpl.java 68 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/java/com/smartor/service/impl/PatMedOuthospServiceImpl.java 177 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/java/com/smartor/service/impl/PersonWorkbenchServiceImpl.java 11 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/java/com/smartor/service/impl/ServiceExternalServiceImpl.java 108 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/java/com/smartor/service/impl/ServiceSLTDHealthcareRecordServiceImpl.java 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskAnswerServiceImpl.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java 55 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/java/com/smartor/service/impl/ServiceTaskServiceImpl.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/resources/mapper/smartor/HeLibraryAssortMapper.xml 23 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/resources/mapper/smartor/PatArchiveMapper.xml 240 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/resources/mapper/smartor/PatArchiveOutMapper.xml 113 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/resources/mapper/smartor/PatMedInhospMapper.xml 225 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/resources/mapper/smartor/PatMedOuthospMapper.xml 898 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml 162 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-admin/src/main/java/com/ruoyi/web/component/DeptUtils.java
@@ -15,9 +15,9 @@
        Map<String, String> map = new HashMap<>();
        LoginUser loginUser = getLoginUser();
        SysUser user = loginUser.getUser();
        String detpId = user.getDeptId().toString();
        String deptcodes = user.getDeptCode().toString();
        String userName = user.getUserName();
        map.put("deptId", detpId);
        map.put("deptcodes", deptcodes);
        map.put("userName", userName);
        return map;
    }
ruoyi-admin/src/main/java/com/ruoyi/web/controller/smartor/PatMedOuthospController.java
@@ -11,6 +11,7 @@
import com.ruoyi.common.constant.HttpStatus;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.exception.base.BaseException;
import com.ruoyi.common.utils.PageUtils;
import com.smartor.domain.PatArchiveOthreInfo;
import com.smartor.domain.PatMedReq;
@@ -81,11 +82,6 @@
    @ApiOperation("查询门诊看病人次和人数")
    public AjaxResult selectPatMedOuthospCount(@RequestBody PatMedReq patMedReq) {
        SysUser user = getLoginUser().getUser();
//        List<String> deptCode = new ArrayList<>();
//        for (Map<String, Object> map : user.getBelongDepts()) {
//            if (ObjectUtils.isNotEmpty(map.get("deptCode"))) deptCode.add(map.get("deptCode").toString());
//        }
//        patMedReq.setDeptcodeList(deptCode);
        patMedReq.setOrgid(user.getOrgid());
        PatMedRes patMedRes = patMedOuthospService.selectPatMedOuthospCount(patMedReq);
        return success(patMedRes);
@@ -110,16 +106,16 @@
        util.exportExcel(response, list, "患者门诊记录数据");
    }
    /**
     * èŽ·å–æ‚£è€…é—¨è¯Šè®°å½•è¯¦ç»†ä¿¡æ¯
     */
    @ApiOperation("获取患者门诊记录详细信息")
    @ApiImplicitParam(name = "getInfo", value = "主键ID", dataType = "long", dataTypeClass = Long.class)
    //@PreAuthorize("@ss.hasPermi('smartor:patouthosp:query')")
    @GetMapping(value = "getInfo/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(patMedOuthospService.selectPatMedOuthospById(id));
    }
//    /**
//     * èŽ·å–æ‚£è€…é—¨è¯Šè®°å½•è¯¦ç»†ä¿¡æ¯
//     */
//    @ApiOperation("获取患者门诊记录详细信息")
//    @ApiImplicitParam(name = "getInfo", value = "主键ID", dataType = "long", dataTypeClass = Long.class)
//    //@PreAuthorize("@ss.hasPermi('smartor:patouthosp:query')")
//    @GetMapping(value = "getInfo/{id}")
//    public AjaxResult getInfo(@PathVariable("id") Long id) {
//        return success(patMedOuthospService.selectPatMedOuthospById(id));
//    }
    /**
     * æ–°å¢žæ‚£è€…门诊记录
ruoyi-admin/src/main/java/com/ruoyi/web/controller/smartor/PersonWorkbenchController.java
@@ -33,17 +33,17 @@
     */
    @ApiOperation("当前登录用户的门诊、在院、出院病人的统计情况")
    @GetMapping("/getPatCount")
    public TableDataInfo getPatCount(@RequestParam("deptIds") String detpIds, @RequestParam("dcCodes") String dcCodes) {
    public TableDataInfo getPatCount(@RequestParam("deptcodes") String deptcodes, @RequestParam("dcCodes") String dcCodes) {
        //获取当前登陆人
        Map<String, String> deptAndDocID = DeptUtils.getDeptAndDocID();
        if (StringUtils.isEmpty(detpIds)) {
            detpIds = deptAndDocID.get("deptId");
        if (StringUtils.isEmpty(deptcodes)) {
            deptcodes = deptAndDocID.get("deptcodes");
        }
        if (StringUtils.isEmpty(dcCodes)) {
            dcCodes = deptAndDocID.get("userName");
        }
        List<PerSonWorkbenchDto> patCount = personWorkbenchService.getPatCount(detpIds, dcCodes);
        List<PerSonWorkbenchDto> patCount = personWorkbenchService.getPatCount(deptcodes, dcCodes);
        return getDataTable(patCount);
    }
@@ -53,17 +53,17 @@
    @ApiOperation("当前登录用户的门诊、在院、出院病人的统计情况")
    //@PreAuthorize("@ss.hasPermi('system:tag:list')")
    @GetMapping("/getTaskInfo")
    public TableDataInfo getTaskInfo(@RequestParam("deptIds") String detpIds, @RequestParam("dcCodes") String dcCodes) {
    public TableDataInfo getTaskInfo(@RequestParam("deptcode") String deptcode, @RequestParam("dcCodes") String dcCodes) {
        //获取当前登陆人
        Map<String, String> deptAndDocID = DeptUtils.getDeptAndDocID();
        if (StringUtils.isEmpty(detpIds)) {
            detpIds = deptAndDocID.get("deptId");
        if (StringUtils.isEmpty(deptcode)) {
            deptcode = deptAndDocID.get("deptcode");
        }
        if (StringUtils.isEmpty(dcCodes)) {
            dcCodes = deptAndDocID.get("userName");
        }
        List<PerSonWorkbenchDto> patCount = personWorkbenchService.getPatCount(detpIds, dcCodes);
        List<PerSonWorkbenchDto> patCount = personWorkbenchService.getPatCount(deptcode, dcCodes);
        return getDataTable(patCount);
    }
ruoyi-admin/src/main/java/com/ruoyi/web/controller/smartor/ServiceTaskController.java
@@ -65,7 +65,7 @@
    @ApiOperation("查询任务列表")
    //@PreAuthorize("@ss.hasPermi('smartor:ServiceTask:list')")
    @AddOrgId(field = "orgid", paramIndex = 0, campusField = "campusid")
    @PostMapping("list")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody ServiceTask serviceTask) {
        PageUtils.startPageByPost(serviceTask.getPageNum(), serviceTask.getPageSize());
//        List<ServiceTask> list = serviceTaskService.selectServiceTaskList(serviceTask);
ruoyi-admin/src/main/java/com/ruoyi/web/controller/smartor/SvyTaskSingleController.java
@@ -1,24 +1,18 @@
package com.ruoyi.web.controller.smartor;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.DtoConversionUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.smartor.domain.*;
import com.smartor.service.ISvyTaskSingleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
/**
 * å•一任务(问卷)Controller
ruoyi-quartz/src/main/java/com/ruoyi/quartz/service/impl/CollectHISServiceImpl.java
@@ -9,6 +9,7 @@
import com.ruoyi.quartz.service.ICollectHISService;
import com.smartor.domain.*;
import com.smartor.mapper.*;
import com.smartor.service.IPatMedOuthospService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ArrayUtils;
@@ -35,7 +36,7 @@
    private SysUser2Mapper sysUser2Mapper;
    @Autowired
    private SysUserRole2Mapper sysUserRoleMapper;
    private IPatMedOuthospService patMedOuthospService;
    @Autowired
    private SysDept2Mapper sysDept2Mapper;
@@ -291,7 +292,7 @@
                        patMedOuthosp1.setCampusid(patMedOuthosp1.getOrgid());
                        patMedOuthosp1.setOrgid("1");
                    }
                    count += patMedOuthospMapper.updatePatMedOuthosp(patMedOuthosp1);
                    count += patMedOuthospService.updatePatMedOuthosp(patMedOuthosp1);
                } else {
                    patMedOuthosp1.setCreateTime(new Date());
                    //市一 é™¢åŒºid对应orgid,机构id为默认的1
@@ -299,7 +300,7 @@
                        patMedOuthosp1.setCampusid(patMedOuthosp1.getOrgid());
                        patMedOuthosp1.setOrgid("1");
                    }
                    count += patMedOuthospMapper.insertPatMedOuthosp(patMedOuthosp1);
                    count += patMedOuthospService.insertPatMedOuthosp(patMedOuthosp1);
                }
            } catch (Exception ex) {
                log.info("同步出入院:" + ex.getMessage());
@@ -413,7 +414,7 @@
                patArchiveMapper.insertPatArchiveSingle(patArchives.get(0));
                patMedOuthosp1.setPatid(patArchives.get(0).getId());
            }
            i = patMedOuthospMapper.insertPatMedOuthosp(patMedOuthosp1);
            i = patMedOuthospService.insertPatMedOuthosp(patMedOuthosp1);
        }
        return i;
ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/RyTask.java
@@ -11,11 +11,11 @@
import com.ruoyi.common.enums.MsgLSEnum;
import com.ruoyi.common.enums.ServiceFromEnum;
import com.ruoyi.common.enums.WxGZHEnum;
import com.ruoyi.common.exception.base.BaseException;
import com.ruoyi.common.utils.*;
import com.ruoyi.common.utils.http.HttpUtils;
import com.ruoyi.common.utils.sms.smsUtils;
import com.ruoyi.quartz.service.ICollectHISService;
import com.ruoyi.quartz.util.CreateDataTable;
import com.ruoyi.system.domain.SysConfig;
import com.ruoyi.system.service.ISysConfigService;
import com.smartor.common.LSHospTokenUtil;
@@ -151,6 +151,9 @@
    @Autowired
    ICollectHISService icollectHis;
    @Autowired
    CreateDataTable createDataTable;
    @Value("${appid}")
@@ -471,6 +474,19 @@
    }
    /**
     * é—¨è¯Šåˆ†è¡¨å®šæ—¶ä»»åŠ¡ï¼šä»Ž sys_config è¯»å–分表模式,按模式建表并刷新视图 v_pat_med_outhosp
     * é…ç½® key: outhosp.split.mode
     * quarter -> æŒ‰å­£åº¦ï¼Œè¡¨åç¤ºä¾‹ï¼špat_med_outhosp_20260103
     * year    -> æŒ‰å¹´ï¼Œè¡¨åç¤ºä¾‹ï¼špat_med_outhosp_2026
     * month   -> æŒ‰æœˆï¼Œè¡¨åç¤ºä¾‹ï¼špat_med_outhosp_202601
     * æŸ¥è¯¢ä¸åˆ°é…ç½®åˆ™ä¸åˆ†è¡¨
     */
    public void createOuthospQuarterTable() {
        log.info("【createOuthospQuarterTable】开始执行门诊分表任务");
        createDataTable.createOuthospQuarterTable();
    }
    /**
     * å¤„理患者信息,进入子任务表(微信小程序)
     */
    public void dealOutHospInfoXHC() {
@@ -483,7 +499,7 @@
    /**
     *  é•¿æœŸä»»åŠ¡å‘é€
     * é•¿æœŸä»»åŠ¡å‘é€
     */
    public void longTaskSend() {
        //获取任务信息
@@ -582,6 +598,7 @@
    /**
     * éšè®¿-补偿处理
     *
     * @param serviceSubtask
     */
    public void sfHandlle(ServiceSubtask serviceSubtask) {
ruoyi-quartz/src/main/java/com/ruoyi/quartz/util/CreateDataTable.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,587 @@
package com.ruoyi.quartz.util;
import com.ruoyi.system.service.ISysConfigService;
import com.smartor.mapper.PatMedOuthospMapper;
import com.smartor.service.IPatMedOuthospService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.Statement;
import java.time.LocalDate;
import java.util.*;
/**
 * åˆ›å»ºæ•°æ®åº“表
 */
@Slf4j
@Component
public class CreateDataTable {
    @Autowired
    private ISysConfigService configService;
    @Autowired
    IPatMedOuthospService iPatMedOuthospService;
    @Autowired
    PatMedOuthospMapper patMedOuthospMapper;
    @Autowired
    private DataSource dataSource;
    public void createOuthospQuarterTable() {
        log.info("【createOuthospQuarterTable】开始执行门诊分表任务");
        try {
            // ä»Ž sys_config æŸ¥è¯¢åˆ†è¡¨æ¨¡å¼ï¼Œ key = outhosp.split.mode
            String splitMode = configService.selectConfigByKey("outhosp.split.mode");
            if (org.apache.commons.lang3.StringUtils.isBlank(splitMode)) {
                log.info("【createOuthospQuarterTable】未配置 outhosp.split.mode,不执行分表");
                return;
            }
            splitMode = splitMode.trim();
            if (!"季度".equals(splitMode) && !"å¹´".equals(splitMode) && !"月".equals(splitMode)) {
                log.warn("【createOuthospQuarterTable】分表模式配置非法:{},应为 quarter/year/month,不执行分表", splitMode);
                return;
            }
            String newTable = createPartitionTableAndRefreshView(splitMode);
            if (newTable == null) {
                log.info("【createOuthospQuarterTable】当前周期表已存在,无需操作");
            } else {
                log.info("【createOuthospQuarterTable】新建分表成功:{},已刷新视图 v_pat_med_outhosp", newTable);
            }
        } catch (Exception e) {
            log.error("【createOuthospQuarterTable】建表异常", e);
        }
    }
    /**
     * æŒ‰æŒ‡å®šæ¨¡å¼å»ºé—¨è¯Šåˆ†è¡¨å¹¶æ›´æ–°åŠ¨æ€è§†å›¾
     * splitMode: å­£åº¦ / å¹´ / æœˆ / ä¸åˆ†è¡¨
     * è¡¨åï¼š
     * quarter -> pat_med_outhosp_20260103
     * year    -> pat_med_outhosp_2026
     * month   -> pat_med_outhosp_202601
     */
    public String createPartitionTableAndRefreshView(String splitMode) {
        LocalDate today = LocalDate.now();
        int year = today.getYear();
        int month = today.getMonthValue();
        // 1. æ ¹æ®æ¨¡å¼è®¡ç®—新表名和模板表名
        String newTableName;
        String templateName;
        if ("å¹´".equals(splitMode)) {
            // æŒ‰å¹´ï¼špat_med_outhosp_2026
            newTableName = "pat_med_outhosp_" + year;
            // æ¨¡æ¿è¡¨ï¼šä¼˜å…ˆä¸Šä¸€å¹´åˆ†è¡¨
            String prevYearTable = "pat_med_outhosp_" + (year - 1);
            templateName = patMedOuthospMapper.tableExists(prevYearTable) > 0 ? prevYearTable : "pat_med_outhosp";
        } else if ("月".equals(splitMode)) {
            // æŒ‰æœˆï¼špat_med_outhosp_202601
            newTableName = String.format("pat_med_outhosp_%d%02d", year, month);
            // æ¨¡æ¿è¡¨ï¼šä¼˜å…ˆä¸Šä¸€æœˆåˆ†è¡¨
            LocalDate prevMonth = today.minusMonths(1);
            String prevMonthTable = String.format("pat_med_outhosp_%d%02d", prevMonth.getYear(), prevMonth.getMonthValue());
            templateName = patMedOuthospMapper.tableExists(prevMonthTable) > 0 ? prevMonthTable : "pat_med_outhosp";
        } else {
            // é»˜è®¤æŒ‰å­£åº¦ï¼špat_med_outhosp_20260103
            String quarterSuffix;
            if (month <= 3) {
                quarterSuffix = "0103";
            } else if (month <= 6) {
                quarterSuffix = "0406";
            } else if (month <= 9) {
                quarterSuffix = "0709";
            } else {
                quarterSuffix = "1012";
            }
            newTableName = "pat_med_outhosp_" + year + quarterSuffix;
            templateName = resolveQuarterTemplateName(year, quarterSuffix);
        }
        // 2. æ£€æŸ¥è¡¨æ˜¯å¦å·²å­˜åœ¨
        if (patMedOuthospMapper.tableExists(newTableName) > 0) {
            log.info("[建表] è¡¨ {} å·²å­˜åœ¨ï¼Œæ— éœ€é‡å¤å»ºè¡¨ï¼Œä½†ä»ç„¶å°è¯•刷新存储过程(确保分表已纳入查询)", newTableName);
            refreshOuthospView();
            return null;
        }
        log.info("[建表] æ¨¡å¼={},使用模板表 {} åˆ›å»º {}", splitMode, templateName, newTableName);
        // 3. åˆ›å»ºæ–°è¡¨ï¼ˆLIKE æ¨¡æ¿è¡¨ï¼Œåªå¤åˆ¶ç»“æž„+索引,不含数据)
        patMedOuthospMapper.createPatMedOuthosp(templateName, newTableName);
        // 4. è®¾ç½®è‡ªå¢žä¸»é”®
        patMedOuthospMapper.createPatMedOuthospAutoAdd(newTableName);
        // 5. é‡å»ºåŠ¨æ€è§†å›¾
        refreshOuthospView();
        log.info("[建表] å»ºè¡¨å¹¶åˆ·æ–°è§†å›¾å®Œæˆï¼Œæ–°è¡¨ï¼š{}", newTableName);
        return newTableName;
    }
    /**
     * å­£åº¦åˆ†è¡¨æ¨¡æ¿ç¡®å®šï¼šä¼˜å…ˆä¸Šä¸€å­£åº¦åˆ†è¡¨ï¼Œæ²¡æœ‰åˆ™ç”¨ä¸»è¡¨
     */
    private String resolveQuarterTemplateName(int year, String currentQuarterSuffix) {
        String[][] quarters = {{"0103", "1012"}, {"0406", "0103"}, {"0709", "0406"}, {"1012", "0709"}};
        String prevSuffix = null;
        int prevYear = year;
        for (String[] q : quarters) {
            if (q[0].equals(currentQuarterSuffix)) {
                prevSuffix = q[1];
                if (currentQuarterSuffix.equals("0103")) {
                    prevYear = year - 1;
                }
                break;
            }
        }
        if (prevSuffix != null) {
            String prevTableName = "pat_med_outhosp_" + prevYear + prevSuffix;
            if (patMedOuthospMapper.tableExists(prevTableName) > 0) {
                return prevTableName;
            }
        }
        return "pat_med_outhosp";
    }
    /**
     * åˆ·æ–°å­˜å‚¨è¿‡ç¨‹ sp_query_outhosp
     * é€»è¾‘:
     * 1. ä»Ž information_schema åŠ¨æ€èŽ·å– pat_med_outhosp å­—段列表
     * 2. æŸ¥å‡ºæ‰€æœ‰åˆ†è¡¨ï¼ˆåŽç¼€ä¸º4-8位纯数字)拼 UNION ALL
     * 3. æ ¹æ®å­—段是否存在动态决定存储过程参数和 WHERE æ¡ä»¶
     * 4. ç”¨åŽŸç”Ÿ JDBC æ‰§è¡Œï¼ˆCREATE PROCEDURE å†…含分号,MyBatis æ— æ³•处理)
     */
    private void refreshOuthospView() {
        // 1. èŽ·å–æ‰€æœ‰åˆ†è¡¨
        List<String> allTables = patMedOuthospMapper.getAllOuthospTableNames();
        List<String> partTables = allTables.stream().filter(t -> t.matches("pat_med_outhosp_[0-9]{4,8}")).sorted().collect(java.util.stream.Collectors.toList());
        // 2. åŠ¨æ€èŽ·å–ä¸»è¡¨å­—æ®µåˆ—è¡¨
        List<String> columns = patMedOuthospMapper.getTableColumns("pat_med_outhosp");
        Set<String> cs = new HashSet<>(columns);
        String colList = String.join(",", columns);
        // 3. æ‹¼ UNION ALL(del_flag å†…嵌入 SET @sql='...' ä¸­ï¼Œç”¨ ''0'' è½¬ä¹‰ï¼‰
        StringBuilder union = new StringBuilder();
        for (String tbl : partTables) {
            union.append("SELECT ").append(colList).append(" FROM ").append(tbl).append(" WHERE del_flag=''0'' UNION ALL ");
        }
        union.append("SELECT ").append(colList).append(" FROM pat_med_outhosp WHERE del_flag=''0''");
        // 4. ä»Ž DB å…ƒæ•°æ®åŠ¨æ€æž„å»ºå‚æ•°åˆ—è¡¨
        //    æŽ’除无业务意义的管理字段
        Set<String> excludeCols = new HashSet<>(java.util.Arrays.asList("id", "del_flag", "create_by", "create_time", "update_by", "update_time", "remark"));
        // å¼ºåˆ¶ç²¾ç¡®åŒ¹é…çš„字段(字段名不符合 eqPattern è§„则但业务上需精确查询)
        Set<String> forceEqCols = new HashSet<>(java.util.Arrays.asList("orgid", "guid", "campusid"));
        // ç²¾ç¡®åŒ¹é…å­—段的关键词(含 no/code/flag/status/state/num/type/level/grade/sex/gender/phone/tel/id_)
        java.util.regex.Pattern eqPattern = java.util.regex.Pattern.compile("(no|code|flag|status|state|num|type|level|grade|sex|gender|phone|tel|id_.*|.*_id)$", java.util.regex.Pattern.CASE_INSENSITIVE);
        List<Map<String, String>> colMetaList = patMedOuthospMapper.getTableColumnMeta("pat_med_outhosp");
        // [paramName, colName, kind, sqlType]
        List<Object[]> activeParams = new ArrayList<>();
        Set<String> addedDateCols = new HashSet<>();
        for (Map<String, String> meta : colMetaList) {
            String colName = meta.get("column_name");
            String dataType = meta.get("data_type").toLowerCase();
            String colType = meta.get("column_type").toUpperCase();
            if (excludeCols.contains(colName)) continue;
            switch (dataType) {
                case "tinyint":
                case "smallint":
                case "int":
                case "bigint":
                case "integer":
                case "decimal":
                case "float":
                case "double":
                    activeParams.add(new Object[]{"p_" + colName, colName, "num", colType});
                    break;
                case "date":
                case "datetime":
                case "timestamp":
                    // æ—¥æœŸåˆ—生成区间参数,防止重复添加
                    if (addedDateCols.add(colName)) {
                        if (colName.equals("admitdate")) {
                            activeParams.add(new Object[]{"p_begin_" + colName, colName, "date_ge", "DATE"});
                            activeParams.add(new Object[]{"p_end_" + colName, colName, "date_le", "DATE"});
                        }
                    }
                    break;
                default:
                    // varchar / char / text ç­‰å­—符串类型
                    if (dataType.contains("char") || dataType.contains("text") || dataType.contains("enum")) {
                        if (colName.equals("deptcode")) {
                            activeParams.add(new Object[]{"p_" + colName, colName, "in", colType});
                            break;
                        }
                        if (colName.equals("hospitaldistrictcode")) {
                            activeParams.add(new Object[]{"p_" + colName, colName, "in", colType});
                            break;
                        }
                        String kind = forceEqCols.contains(colName) ? "eq" : (eqPattern.matcher(colName).find() ? "eq" : "like");
                        activeParams.add(new Object[]{"p_" + colName, colName, kind, colType});
                    }
                    break;
            }
        }
        // 6. æ‹¼å‚数定义(去除重复参数名,如 p_begin_xxx/p_end_xxx åŒåˆ—)
        StringBuilder paramDef = new StringBuilder("CREATE PROCEDURE sp_query_outhosp(");
        Set<String> addedParams = new LinkedHashSet<>();
        for (Object[] m : activeParams) {
            String pName = (String) m[0];
            String dtype = (String) m[3];
            if (addedParams.add(pName)) {
                paramDef.append("IN ").append(pName).append(" ").append(dtype).append(",");
            }
        }
        paramDef.append("IN p_page_size INT,IN p_page_num INT)");
        // 7. æ‹¼å­˜å‚¨è¿‡ç¨‹ä¸»ä½“
        //    ä¼˜åŒ–策略:用 @cond å˜é‡æ”¶é›†æ‰€æœ‰è¿‡æ»¤æ¡ä»¶ï¼Œç„¶åŽæ³¨å…¥åˆ°æ¯ä¸ªå­æŸ¥è¯¢çš„ WHERE ä¸­
        //    è¿™æ · MySQL å¯ä»¥å¯¹æ¯å¼ åˆ†è¡¨ç›´æŽ¥èµ°ç´¢å¼•,避免全表扫描后外层再过滤
        List<String> body = new ArrayList<>();
        body.add(paramDef.toString());
        body.add("BEGIN");
        body.add("  SET @cond='';");
        // 7a. åŠ¨æ€æ‹¼æŽ¥ @cond æ¡ä»¶ç‰‡æ®µ
        for (Object[] m : activeParams) {
            String pName = (String) m[0];
            String col = (String) m[1];
            String kind = (String) m[2];
            String line;
            switch (kind) {
                case "num":
                    line = "  IF " + pName + " IS NOT NULL THEN SET @cond=CONCAT(@cond,' AND " + col + "='," + pName + "); END IF;";
                    break;
                case "eq":
                    line = "  IF " + pName + " IS NOT NULL THEN SET @cond=CONCAT(@cond,' AND " + col + "=',QUOTE(" + pName + ")); END IF;";
                    break;
                case "like":
                    // MySQL å­˜å‚¨è¿‡ç¨‹å†… '' è¡¨ç¤ºä¸€ä¸ªå•引号
                    line = "  IF " + pName + " IS NOT NULL THEN SET @cond=CONCAT(@cond,' AND " + col + " LIKE CONCAT(''%''," + pName + ",''%'')'); END IF;";
                    break;
                case "date_ge":
                    line = "  IF " + pName + " IS NOT NULL THEN SET @cond=CONCAT(@cond,' AND " + col + ">=',QUOTE(" + pName + ")); END IF;";
                    break;
                case "date_le":
                    line = "  IF " + pName + " IS NOT NULL THEN SET @cond=CONCAT(@cond,' AND " + col + "<=',QUOTE(" + pName + ")); END IF;";
                    break;
                case "in":
                    // å‚数为逗号分隔字符串,用 FIND_IN_SET åŒ¹é…å­—段在集合中
                    // ç”Ÿæˆ SQL: FIND_IN_SET(col, 'val1,val2,...')
                    line = "  IF " + pName + " IS NOT NULL THEN SET @cond=CONCAT(@cond,' AND FIND_IN_SET(" + col + ",',QUOTE(" + pName + "),')'); END IF;";
                    break;
                default:
                    line = "";
            }
            if (!line.isEmpty()) body.add(line);
        }
        // 7b. æž„建 UNION ALL SQL:每个子查询的 WHERE å†…直接注入 @cond
        //     æœ€ç»ˆå­˜å‚¨è¿‡ç¨‹é‡Œæ‰§è¡Œçš„ SQL ç±»ä¼¼ï¼š
        //     SELECT cols FROM tbl1 WHERE del_flag='0' AND orgid=? AND ...
        //     UNION ALL SELECT cols FROM tbl2 WHERE del_flag='0' AND orgid=? AND ...
        //     ORDER BY update_time DESC LIMIT ? OFFSET ?
        //
        //     å®žçŽ°æ–¹å¼ï¼šç”¨ CONCAT(单引号字符串, @cond, ...) æ‹¼æŽ¥
        //     del_flag=''0'' åœ¨å­˜å‚¨è¿‡ç¨‹å†…单引号字符串中表示一个 '0'
        List<String> allQueryTables = new ArrayList<>(partTables);
        allQueryTables.add("pat_med_outhosp");
        StringBuilder concatArgs = new StringBuilder();
        for (int i = 0; i < allQueryTables.size(); i++) {
            String tbl = allQueryTables.get(i);
            if (i > 0) {
                concatArgs.append(",' UNION ALL SELECT ").append(colList).append(" FROM ").append(tbl).append(" WHERE del_flag=''0''',@cond");
            } else {
                concatArgs.append("'SELECT ").append(colList).append(" FROM ").append(tbl).append(" WHERE del_flag=''0''',@cond");
            }
        }
        String orderCol = cs.contains("update_time") ? "update_time" : "id";
        body.add("  SET @sql=CONCAT(" + concatArgs + ",' ORDER BY " + orderCol + " DESC');");
        body.add("  IF p_page_size IS NOT NULL AND p_page_num IS NOT NULL THEN");
        body.add("    SET @sql=CONCAT(@sql,' LIMIT ',p_page_size,' OFFSET ',p_page_num);");
        body.add("  END IF;");
        body.add("  PREPARE stmt FROM @sql;");
        body.add("  EXECUTE stmt;");
        body.add("  DEALLOCATE PREPARE stmt;");
        body.add("END");
        String procSql = String.join("\n", body);
        log.debug("[刷新存储过程] DDL=\n{}", procSql);
        // 8. é€šè¿‡åŽŸç”Ÿ JDBC æ‰§è¡Œï¼ˆCREATE PROCEDURE å«åˆ†å·ï¼ŒMyBatis ä¸æ”¯æŒï¼‰
        // ç­–略:
        //   - å­˜å‚¨è¿‡ç¨‹ä¸å­˜åœ¨ â†’ å…¨é‡åˆ›å»º
        //   - å­˜å‚¨è¿‡ç¨‹å·²å­˜åœ¨ â†’ åªæŠŠ DB ä¸­è¿˜æ²¡æœ‰çš„分表以 UNION ALL å½¢å¼è¿½åŠ è¿› SET @sql=CONCAT(...) é‡Œï¼Œ
        //     å…¶ä½™æ‰€æœ‰æ¡ä»¶é€»è¾‘(人工改过的模糊/区间等)原样保留,绝不覆盖
        try (Connection conn = dataSource.getConnection(); Statement jdbcStmt = conn.createStatement()) {
            // å…ˆæŸ¥ DB ä¸­æ˜¯å¦å­˜åœ¨è¯¥å­˜å‚¨è¿‡ç¨‹åŠå…¶å®Œæ•´ DDL
            String showCreateDdl = null;
            try (java.sql.ResultSet rs = jdbcStmt.executeQuery("SHOW CREATE PROCEDURE sp_query_outhosp")) {
                if (rs.next()) {
                    showCreateDdl = rs.getString("Create Procedure");
                }
            } catch (Exception ignored) {
                // å­˜å‚¨è¿‡ç¨‹ä¸å­˜åœ¨æ—¶ SHOW CREATE ä¼šæŠ›å¼‚常,忽略
            }
            if (showCreateDdl == null) {
                // å­˜å‚¨è¿‡ç¨‹ä¸å­˜åœ¨ï¼Œå…¨é‡åˆ›å»º
                jdbcStmt.execute(procSql);
                log.info("[刷新存储过程] sp_query_outhosp é¦–次创建,分表数量:{}", partTables.size());
            } else {
                // å­˜å‚¨è¿‡ç¨‹å·²å­˜åœ¨ï¼šæ‰¾å‡º DB é‡Œå·²æœ‰å“ªäº›åˆ†è¡¨ï¼ŒæŠŠæ–°å¢žçš„追加进去
                // æ‰¾å‡ºå½“前 DDL é‡Œå·²å‡ºçŽ°çš„æ‰€æœ‰ pat_med_outhosp_xxx è¡¨å
                java.util.regex.Matcher tblMatcher = java.util.regex.Pattern.compile("pat_med_outhosp_([0-9]{4,8})").matcher(showCreateDdl);
                Set<String> existingTables = new java.util.LinkedHashSet<>();
                while (tblMatcher.find()) {
                    existingTables.add(tblMatcher.group(0));
                }
                // æ‰¾å‡ºæœ¬æ¬¡æ–°å»ºåŽè¿˜æ²¡è¿›å…¥å­˜å‚¨è¿‡ç¨‹çš„分表
                List<String> newTables = partTables.stream().filter(t -> !existingTables.contains(t)).collect(java.util.stream.Collectors.toList());
                if (newTables.isEmpty()) {
                    log.info("[刷新存储过程] æ— æ–°å¢žåˆ†è¡¨ï¼Œå­˜å‚¨è¿‡ç¨‹æ— éœ€æ›´æ–°");
                } else {
                    // ç›´æŽ¥ä»Ž DDL é‡Œæå–字段列表(避免与 Java åŠ¨æ€æŸ¥è¡¨å­—æ®µä¸ä¸€è‡´ï¼‰
                    // DDL é‡Œå­—段列表就在: SELECT åŽé¢åˆ° FROM å‰é¢
                    java.util.regex.Matcher colMatcher = java.util.regex.Pattern.compile("SELECT\\s+(.+?)\\s+FROM\\s+pat_med_outhosp", java.util.regex.Pattern.CASE_INSENSITIVE).matcher(showCreateDdl);
                    String existingColList = colMatcher.find() ? colMatcher.group(1).trim() : colList;
                    // ç²¾ç¡®é”šç‚¹ï¼š',@cond,' UNION ALL SELECT cols FROM pat_med_outhosp WHERE
                    String mainTableAnchor = "',@cond,' UNION ALL SELECT " + existingColList + " FROM pat_med_outhosp WHERE ";
                    int mainAnchorIdx = showCreateDdl.indexOf(mainTableAnchor);
                    // å­—段列表匹配不到时,简化定位
                    if (mainAnchorIdx < 0) {
                        // æ‰¾ ',@cond,' UNION ALL SELECT ... FROM pat_med_outhosp WHERE
                        // å…ˆæ‰¾ FROM pat_med_outhosp WHERE,再往前找 ',@cond,'
                        int fromIdx = showCreateDdl.indexOf(" FROM pat_med_outhosp WHERE ");
                        if (fromIdx >= 0) {
                            String before = showCreateDdl.substring(0, fromIdx);
                            int condIdx = before.lastIndexOf("',@cond,'");
                            if (condIdx >= 0) mainAnchorIdx = condIdx;
                        }
                    }
                    if (mainAnchorIdx < 0) {
                        log.warn("[刷新存储过程] æœªæ‰¾åˆ°ä¸»è¡¨é”šç‚¹ï¼Œè·³è¿‡è¿½åŠ ");
                    } else {
                        // æ–°è¡¨ç‰‡æ®µï¼šæ¯å¼ æ–°è¡¨è¿½åŠ ä¸€æ®µ ',@cond,' UNION ALL SELECT cols FROM æ–°è¡¨ WHERE del_flag=''0''
                        // æ’在主表锚点前面,主表锚点本身(',@cond,' UNION ALL ...主表...)保持不动
                        StringBuilder newTablesFragment = new StringBuilder();
                        for (String nt : newTables) {
                            newTablesFragment.append("',@cond,' UNION ALL SELECT ").append(existingColList).append(" FROM ").append(nt).append(" WHERE del_flag=''0''");
                        }
                        // æ’入到主表 ',@cond,' ç‰‡æ®µå‰é¢
                        String updatedDdl = showCreateDdl.substring(0, mainAnchorIdx) + newTablesFragment + showCreateDdl.substring(mainAnchorIdx);
                        log.debug("[刷新存储过程] æ›´æ–°åŽ DDL=\n{}", updatedDdl);
                        // å®‰å…¨ä¿æŠ¤ï¼šDROP å‰å…ˆä¿å­˜åŽŸ DDL,CREATE å¤±è´¥åˆ™ç«‹åˆ»ç”¨åŽŸ DDL æ¢å¤
                        jdbcStmt.execute("DROP PROCEDURE IF EXISTS sp_query_outhosp");
                        try {
                            jdbcStmt.execute(updatedDdl);
                            log.info("[刷新存储过程] sp_query_outhosp è¿½åŠ æ–°åˆ†è¡¨ {},原有条件保持不变", newTables);
                        } catch (Exception createEx) {
                            log.error("[刷新存储过程] æ–° DDL æ‰§è¡Œå¤±è´¥ï¼Œæ­£åœ¨ç”¨åŽŸ DDL æ¢å¤, updatedDdl=\n{}", updatedDdl, createEx);
                            try {
                                jdbcStmt.execute(showCreateDdl);
                                log.info("[刷新存储过程] sp_query_outhosp å·²ç”¨åŽŸ DDL æ¢å¤æˆåŠŸ");
                            } catch (Exception rollbackEx) {
                                log.error("[刷新存储过程] åŽŸ DDL æ¢å¤ä¹Ÿå¤±è´¥ï¼å­˜å‚¨è¿‡ç¨‹ä¸¢å¤±ï¼è¯·æ‰‹åŠ¨ä¿®å¤, åŽŸ DDL=\n{}", showCreateDdl, rollbackEx);
                            }
                        }
                    }
                }
            }
        } catch (Exception e) {
            log.error("[刷新存储过程] sp_query_outhosp æ›´æ–°å¤±è´¥, DDL=\n{}", procSql, e);
        }
        // 9. åŒæ­¥åˆ·æ–° count å­˜å‚¨è¿‡ç¨‹
        refreshOuthospCountProc(partTables, activeParams, colList);
    }
    /**
     * åˆ·æ–°è®¡æ•°å­˜å‚¨è¿‡ç¨‹ sp_count_outhosp
     * ä¸Ž sp_query_outhosp å‚数完全一致,只返回总条数,不分页
     */
    private void refreshOuthospCountProc(List<String> partTables, List<Object[]> activeParams, String colList) {
        // æ‹¼å‚数定义(去掉 p_page_size/p_page_num)
        StringBuilder paramDef = new StringBuilder("CREATE PROCEDURE sp_count_outhosp(");
        Set<String> addedParams = new LinkedHashSet<>();
        for (Object[] m : activeParams) {
            String pName = (String) m[0];
            String dtype = (String) m[3];
            if (addedParams.add(pName)) {
                paramDef.append("IN ").append(pName).append(" ").append(dtype).append(",");
            }
        }
        // åŽ»æŽ‰æœ€åŽçš„å¤šä½™é€—å·
        String paramDefStr = paramDef.toString();
        if (paramDefStr.endsWith(",")) {
            paramDefStr = paramDefStr.substring(0, paramDefStr.length() - 1);
        }
        paramDefStr += ")";
        List<String> body = new ArrayList<>();
        body.add(paramDefStr);
        body.add("BEGIN");
        body.add("  SET @cond='';");
        // æ¡ä»¶ç‰‡æ®µï¼ˆä¸Ž sp_query_outhosp å®Œå…¨ä¸€è‡´ï¼‰
        for (Object[] m : activeParams) {
            String pName = (String) m[0];
            String col = (String) m[1];
            String kind = (String) m[2];
            String line;
            switch (kind) {
                case "num":
                    line = "  IF " + pName + " IS NOT NULL THEN SET @cond=CONCAT(@cond,' AND " + col + "='," + pName + "); END IF;";
                    break;
                case "eq":
                    line = "  IF " + pName + " IS NOT NULL THEN SET @cond=CONCAT(@cond,' AND " + col + "=',QUOTE(" + pName + ")); END IF;";
                    break;
                case "like":
                    line = "  IF " + pName + " IS NOT NULL THEN SET @cond=CONCAT(@cond,' AND " + col + " LIKE CONCAT(''%''," + pName + ",''%'')'); END IF;";
                    break;
                case "date_ge":
                    line = "  IF " + pName + " IS NOT NULL THEN SET @cond=CONCAT(@cond,' AND " + col + ">=',QUOTE(" + pName + ")); END IF;";
                    break;
                case "date_le":
                    line = "  IF " + pName + " IS NOT NULL THEN SET @cond=CONCAT(@cond,' AND " + col + "<=',QUOTE(" + pName + ")); END IF;";
                    break;
                case "in":
                    line = "  IF " + pName + " IS NOT NULL THEN SET @cond=CONCAT(@cond,' AND FIND_IN_SET(" + col + ",',QUOTE(" + pName + "),')'); END IF;";
                    break;
                default:
                    line = "";
            }
            if (!line.isEmpty()) body.add(line);
        }
        // æ‹¼ COUNT UNION ALL SQL:各分表各计一次再汇总
        // SELECT SUM(cnt) FROM (SELECT COUNT(1) cnt FROM tbl1 WHERE del_flag=''0'' ...
        //                        UNION ALL SELECT COUNT(1) cnt FROM tbl2 WHERE del_flag=''0'' ...) t
        List<String> allQueryTables = new ArrayList<>(partTables);
        allQueryTables.add("pat_med_outhosp");
        StringBuilder concatArgs = new StringBuilder();
        concatArgs.append("'SELECT SUM(cnt) FROM (");
        for (int i = 0; i < allQueryTables.size(); i++) {
            String tbl = allQueryTables.get(i);
            if (i > 0) {
                concatArgs.append(" UNION ALL SELECT COUNT(1) cnt FROM ").append(tbl).append(" WHERE del_flag=''''0''''").append("',@cond,'");
            } else {
                concatArgs.append("SELECT COUNT(1) cnt FROM ").append(tbl).append(" WHERE del_flag=''''0''''").append("',@cond,'");
            }
        }
        concatArgs.append(") t';");
        // é‡æ–°æ‹¼ï¼šæ¯ä¸ªå­è¡¨ WHERE del_flag=''0'' åŽæ‹¼ @cond
        // å­˜å‚¨è¿‡ç¨‹å†… '' è¡¨ç¤ºä¸€ä¸ªå•引号,所以 del_flag=''0'' æ­£ç¡®
        StringBuilder concatArgs2 = new StringBuilder();
        for (int i = 0; i < allQueryTables.size(); i++) {
            String tbl = allQueryTables.get(i);
            if (i == 0) {
                concatArgs2.append("'SELECT SUM(cnt) FROM (SELECT COUNT(1) cnt FROM ").append(tbl).append(" WHERE del_flag=''0''',@cond");
            } else {
                concatArgs2.append(",' UNION ALL SELECT COUNT(1) cnt FROM ").append(tbl).append(" WHERE del_flag=''0''',@cond");
            }
        }
        concatArgs2.append(",' ) t'");
        body.add("  SET @sql=CONCAT(" + concatArgs2 + ");");
        body.add("  PREPARE stmt FROM @sql;");
        body.add("  EXECUTE stmt;");
        body.add("  DEALLOCATE PREPARE stmt;");
        body.add("END");
        String procSql = String.join("\n", body);
        log.debug("[刷新count存储过程] DDL=\n{}", procSql);
        try (Connection conn = dataSource.getConnection(); Statement jdbcStmt = conn.createStatement()) {
            String showCreateDdl = null;
            try (java.sql.ResultSet rs = jdbcStmt.executeQuery("SHOW CREATE PROCEDURE sp_count_outhosp")) {
                if (rs.next()) showCreateDdl = rs.getString("Create Procedure");
            } catch (Exception ignored) {
            }
            if (showCreateDdl == null) {
                jdbcStmt.execute(procSql);
                log.info("[刷新count存储过程] sp_count_outhosp é¦–次创建,分表数量:{}", partTables.size());
            } else {
                // åªè¿½åŠ æ–°åˆ†è¡¨ï¼Œä¸è¦†ç›–å·²æœ‰æ¡ä»¶
                java.util.regex.Matcher tblMatcher = java.util.regex.Pattern.compile("pat_med_outhosp_([0-9]{4,8})").matcher(showCreateDdl);
                Set<String> existingTables = new java.util.LinkedHashSet<>();
                while (tblMatcher.find()) existingTables.add(tblMatcher.group(0));
                List<String> newTables = partTables.stream().filter(t -> !existingTables.contains(t)).collect(java.util.stream.Collectors.toList());
                if (newTables.isEmpty()) {
                    log.info("[刷新count存储过程] æ— æ–°å¢žåˆ†è¡¨ï¼Œæ— éœ€æ›´æ–°");
                    return;
                }
                // ä»Ž DDL é‡Œæå– COUNT(1) cnt FROM åŽé¢çš„字段模式无案,COUNT存储过程没有字段列表
                // å®šä½ä¸»è¡¨é”šç‚¹ï¼š',@cond,' UNION ALL SELECT COUNT(1) cnt FROM pat_med_outhosp WHERE
                String mainAnchor = "',@cond,' UNION ALL SELECT COUNT(1) cnt FROM pat_med_outhosp WHERE ";
                int mainAnchorIdx = showCreateDdl.indexOf(mainAnchor);
                if (mainAnchorIdx < 0) {
                    int fromIdx = showCreateDdl.indexOf(" FROM pat_med_outhosp WHERE ");
                    if (fromIdx >= 0) {
                        String before = showCreateDdl.substring(0, fromIdx);
                        int condIdx = before.lastIndexOf("',@cond,'");
                        if (condIdx >= 0) mainAnchorIdx = condIdx;
                    }
                }
                if (mainAnchorIdx < 0) {
                    log.warn("[刷新count存储过程] æœªæ‰¾åˆ°ä¸»è¡¨é”šç‚¹ï¼Œè·³è¿‡è¿½åŠ ");
                    return;
                }
                StringBuilder newFrag = new StringBuilder();
                for (String nt : newTables) {
                    newFrag.append("',@cond,' UNION ALL SELECT COUNT(1) cnt FROM ").append(nt).append(" WHERE del_flag=''0''");
                }
                String updatedDdl = showCreateDdl.substring(0, mainAnchorIdx) + newFrag + showCreateDdl.substring(mainAnchorIdx);
                log.debug("[刷新count存储过程] æ›´æ–°åŽ DDL=\n{}", updatedDdl);
                jdbcStmt.execute("DROP PROCEDURE IF EXISTS sp_count_outhosp");
                try {
                    jdbcStmt.execute(updatedDdl);
                    log.info("[刷新count存储过程] sp_count_outhosp è¿½åŠ æ–°åˆ†è¡¨ {}", newTables);
                } catch (Exception createEx) {
                    log.error("[刷新count存储过程] æ–° DDL å¤±è´¥ï¼Œæ¢å¤åŽŸ DDL, updatedDdl=\n{}", updatedDdl, createEx);
                    try {
                        jdbcStmt.execute(showCreateDdl);
                        log.info("[刷新count存储过程] å·²æ¢å¤åŽŸ DDL");
                    } catch (Exception rollbackEx) {
                        log.error("[刷新count存储过程] æ¢å¤ä¹Ÿå¤±è´¥ï¼è¯·æ‰‹åŠ¨ä¿®å¤, åŽŸ DDL=\n{}", showCreateDdl, rollbackEx);
                    }
                }
            }
        } catch (Exception e) {
            log.error("[刷新count存储过程] sp_count_outhosp æ›´æ–°å¤±è´¥", e);
        }
    }
}
smartor/src/main/java/com/smartor/mapper/PatArchiveMapper.java
@@ -82,7 +82,7 @@
    public List<PatArchiveOthreInfo> selectPatArchiveInfoByInhospQC(PatArchiveReq patArchive);
    public List<PatArchiveOthreInfo> selectPatArchiveInfoByOuthospQC(PatArchiveReq patArchive);
//    public List<PatArchiveOthreInfo> selectPatArchiveInfoByOuthospQC(PatArchiveReq patArchive);
    public List<PatArchiveOthreInfo> selectPatArchiveInfoByPhysicalQC(PatArchiveReq patArchive);
smartor/src/main/java/com/smartor/mapper/PatArchiveOutMapper.java
@@ -24,7 +24,7 @@
     */
    public PatArchiveOut selectPatArchiveOutByPatid(Long patid);
    public List<PerSonWorkbenchDto> selectPatArchiveCount(@Param("deptIds") long[] deptIds,@Param("drCodes")  String[] drCodes);
    public List<PerSonWorkbenchDto> selectPatArchiveCount(@Param("deptcodes") List<String> deptcodes,@Param("drCodes")  String[] drCodes);
    /**
     * æŸ¥è¯¢å¤–部患者档案列表
smartor/src/main/java/com/smartor/mapper/PatMedInhospMapper.java
@@ -25,7 +25,7 @@
     */
    public PatMedInhosp selectPatMedInhospByInhospid(Long inhospid);
    public  List<PatMedInhosp> selectPatMedInhosp(PatMedInhosp patMedInhosp);
    public List<PatMedInhosp> selectPatMedInhosp(PatMedInhosp patMedInhosp);
    public String getTagnameBypatid(Long patid);
@@ -92,10 +92,9 @@
    public PatMedRes selectPatMedInhospCount(PatMedReq patMedReq);
    public List<PatMedRes> getDeptRanking(PatMedReq patMedReq);
    /**
     * æŸ¥è¯¢ä¸‰ä¸ªç»´åº¦ä»»æ„ä¸€ä¸ªæœªå¤„理的出院患者
     *
     * @return
     */
    public List<PatMedInhosp> selectNeedProcessList();
smartor/src/main/java/com/smartor/mapper/PatMedOuthospMapper.java
@@ -1,10 +1,9 @@
package com.smartor.mapper;
import java.util.List;
import java.util.Map;
import com.smartor.domain.PatMedOuthosp;
import com.smartor.domain.PatMedReq;
import com.smartor.domain.PatMedRes;
import com.smartor.domain.*;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@@ -16,21 +15,6 @@
 */
@Mapper
public interface PatMedOuthospMapper {
    /**
     * æŸ¥è¯¢æ‚£è€…门诊记录
     *
     * @param id æ‚£è€…门诊记录主键
     * @return æ‚£è€…门诊记录
     */
    public PatMedOuthosp selectPatMedOuthospById(Long id);
    /**
     * æŸ¥è¯¢æ‚£è€…门诊记录列表
     *
     * @param patMedOuthosp æ‚£è€…门诊记录
     * @return æ‚£è€…门诊记录集合
     */
    public List<PatMedOuthosp> selectPatMedOuthospList(PatMedOuthosp patMedOuthosp);
    /**
     * æ–°å¢žæ‚£è€…门诊记录
@@ -38,17 +22,44 @@
     * @param patMedOuthosp æ‚£è€…门诊记录
     * @return ç»“æžœ
     */
    public int insertPatMedOuthosp(PatMedOuthosp patMedOuthosp);
    public int batchPatMedOuthosp(List<PatMedOuthosp> patMedOuthosps);
//    public int insertPatMedOuthosp(PatMedOuthosp patMedOuthosp);
    /**
     * æ‰¹é‡æ’入,忽略重复(INSERT IGNORE)
     * æ–°å¢žåˆ°æŒ‡å®šåˆ†è¡¨ï¼ˆç”¨äºŽè·¯ç”±åˆ°æœ€æ–°åˆ†è¡¨ï¼‰
     *
     * @param patMedOuthosps é—¨æ€¥è¯Šè®°å½•列表
     * @return å®žé™…插入数量
     * @param tableName ç›®æ ‡è¡¨å
     * @param record    é—¨è¯Šè®°å½•
     * @return æ’入条数
     */
    public int batchInsertIgnore(List<PatMedOuthosp> patMedOuthosps);
    int insertIntoTable(@Param("tableName") String tableName, @Param("record") PatMedOuthosp record);
    /**
     * åˆ¤æ–­æŒ‡å®šåˆ†è¡¨ä¸­æ˜¯å¦å­˜åœ¨è¯¥ id
     */
    int existsInTable(@Param("tableName") String tableName, @Param("id") Long id);
    /**
     * æ›´æ–°åˆ°æŒ‡å®šåˆ†è¡¨ï¼ˆç”¨äºŽè·¯ç”±åˆ°æ­£ç¡®åˆ†è¡¨ï¼‰
     */
    int updateInTable(@Param("tableName") String tableName, @Param("record") PatMedOuthosp record);
    /**
     * è°ƒç”¨å­˜å‚¨è¿‡ç¨‹ sp_query_outhosp æŸ¥è¯¢é—¨è¯Šè®°å½•
     *
     * @param req å…¥å‚对象
     * @return é—¨è¯Šè®°å½•列表
     */
    List<PatMedOuthosp> callSpQueryOuthosp(PatMedOuthospQueryReq req);
    /**
     * è°ƒç”¨å­˜å‚¨è¿‡ç¨‹ sp_query_outhosp æŸ¥è¯¢é—¨è¯Šè®°å½•数量
     *
     * @param req å…¥å‚对象
     * @return é—¨è¯Šè®°å½•列表
     */
    Long callSpQueryOuthospCount(PatMedOuthospQueryReq req);
    /**
     * ä¿®æ”¹æ‚£è€…门诊记录
@@ -56,62 +67,46 @@
     * @param patMedOuthosp æ‚£è€…门诊记录
     * @return ç»“æžœ
     */
    public int updatePatMedOuthosp(PatMedOuthosp patMedOuthosp);
//    public int updatePatMedOuthosp(PatMedOuthosp patMedOuthosp);
    /**
     * åˆ é™¤æ‚£è€…门诊记录
     *
     * @param id æ‚£è€…门诊记录主键
     * @return ç»“æžœ
     */
    public int deletePatMedOuthospById(Long id);
    /**
     * æ‰¹é‡åˆ é™¤æ‚£è€…门诊记录
     *
     * @param ids éœ€è¦åˆ é™¤çš„æ•°æ®ä¸»é”®é›†åˆ
     * @return ç»“æžœ
     */
    public int deletePatMedOuthospByIds(Long[] ids);
    PatMedRes selectPatMedOuthospCount(PatMedReq patMedReq);
    public List<PatMedRes> getDeptRanking(PatMedReq patMedReq);
    /**
     * èŽ·å–è¡¨çš„æ•°é‡
     *
     * @return
     */
    int countPatMedOuthosp();
    /**
     * ä¿®æ”¹è¡¨å
     *
     * @return
     */
    void renameTable(@Param("oldName") String oldName, @Param("newName") String newName);
    /**
     * åˆ›å»ºæ–°è¡¨
     *
     * @param templateName
     * @param newName
     * @param templateName æ¨¡æ¿è¡¨å
     * @param newName      æ–°è¡¨å
     */
    void createPatMedOuthosp(@Param("templateName") String templateName, @Param("newName") String newName);
    void createPatMedOuthospAutoAdd(@Param("newName") String newName);
    void setAutoIncrement(@Param("tableName") String tableName, @Param("autoInc") long autoInc);
    // æŸ¥è¯¢æ‰€æœ‰ pat_med_outhosp å¼€å¤´çš„表名
    List<String> getAllOuthospTableNames();
    // æŸ¥è¯¢æŒ‡å®šè¡¨çš„æœ€å¤§id
    Long getMaxIdFromTable(@Param("tableName") String tableName);
    // æŸ¥è¯¢æŒ‡å®šè¡¨çš„字段列表(按 ordinal_position æŽ’序)
    List<String> getTableColumns(@Param("tableName") String tableName);
    void createOrReplaceView(@Param("viewSql") String viewSql);
    /**
     * æŸ¥è¯¢æŒ‡å®šè¡¨çš„字段元数据(column_name, data_type, column_type)
     *
     * @param tableName è¡¨å
     * @return æ¯è¡ŒåŒ…含 column_name / data_type / column_type
     */
    List<Map<String, String>> getTableColumnMeta(@Param("tableName") String tableName);
    /**
     * åˆ›å»ºæˆ–更新存储过程(支持 DROP / CREATE PROCEDURE è¯­å¥ï¼‰
     */
    void createOrReplaceProcedure(@Param("procSql") String procSql);
    /**
     * æ£€æŸ¥è¡¨æ˜¯å¦å·²å­˜åœ¨
     *
     * @param tableName è¡¨å
     * @return å­˜åœ¨è¿”回1,不存在返回0
     */
    int tableExists(@Param("tableName") String tableName);
}
smartor/src/main/java/com/smartor/mapper/ServiceSubtaskMapper.java
@@ -35,6 +35,7 @@
    /**
     * ç”¨äºŽè¡¥å¿æŸ¥è¯¢
     *
     * @param ServiceSubtaskEntity
     * @return
     */
@@ -75,7 +76,8 @@
     * @return
     */
    @MapKey("groupKey")
    public Map<String, Map<String,Object>> selectTimelyRateBatch(ServiceSubtaskEntity ServiceSubtaskvo);
    public Map<String, Map<String, Object>> selectTimelyRateBatch(ServiceSubtaskEntity ServiceSubtaskvo);
    /**
     * éšè®¿åŠæ—¶çŽ‡è¯¦æƒ…
     *
@@ -176,4 +178,12 @@
     *         allVisitCount: å½“前登录人随访任务总量
     */
    public Map<String, Object> getCurrentUserServiceSubtaskCount(ServiceSubtaskEntity serviceSubtaskVO);
    /**
     * èŽ·å–é—¨è¯Šéšè®¿äººæ•°
     *
     * @param patMedReq
     * @return
     */
    PatMedRes selectVisitCount(PatMedReq patMedReq);
}
smartor/src/main/java/com/smartor/service/PersonWorkbenchService.java
@@ -15,6 +15,6 @@
    /**
     * å½“前登录用户的门诊、在院、出院病人的统计情况
     */
    public  List<PerSonWorkbenchDto> getPatCount(String detpId, String drCode);
    public  List<PerSonWorkbenchDto> getPatCount(String deptIds, String drCode);
}
smartor/src/main/java/com/smartor/service/impl/HNGatherPatArchiveServiceImpl.java
@@ -8,6 +8,7 @@
import com.smartor.domain.*;
import com.smartor.mapper.*;
import com.smartor.service.IHNGatherPatArchiveService;
import com.smartor.service.IPatMedOuthospService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
@@ -56,7 +57,7 @@
    private PatArchiveMapper patArchiveMapper;
    @Autowired
    private ThreadPoolTaskExecutor taskExecutor;
    private IPatMedOuthospService patMedOuthospService;
    @Autowired
    private ShardingMapper shardingMapper;
@@ -187,7 +188,7 @@
                patArchiveMapper.insertPatArchiveSingle(patArchives.get(0));
                patMedOuthosp1.setPatid(patArchives.get(0).getId());
            }
            i = patMedOuthospMapper.insertPatMedOuthosp(patMedOuthosp1);
            i = patMedOuthospService.insertPatMedOuthosp(patMedOuthosp1);
        }
        return i;
smartor/src/main/java/com/smartor/service/impl/PatArchiveServiceImpl.java
@@ -63,7 +63,7 @@
    private PatArchivecontactMapper patArchivecontactMapper;
    @Autowired
    private IPatMedPhysicalService patMedPhysicalService;
    private PatMedOuthospMapper patMedOuthospMapper;
    @Autowired
    private RedisCache redisCache;
@@ -273,9 +273,11 @@
            }
        } else if (patArchiveReq.getAllhosp() != null && patArchiveReq.getAllhosp() == 2) {
            // æŸ¥çœ‹ä½é™¢  1  æŸ¥çœ‹é—¨è¯Š  2   æŸ¥çœ‹ä½“检  3
            List<PatArchiveOthreInfo> patArchives2 = patArchiveMapper.selectPatArchiveInfoByOuthosp(patArchiveReq);
            if (CollectionUtils.isNotEmpty(patArchives2)) {
                patArchiveList.addAll(patArchives2);
//            List<PatArchiveOthreInfo> patArchives2 = patArchiveMapper.selectPatArchiveInfoByOuthosp(patArchiveReq);
            List<PatArchiveOthreInfo> patientInfoQC = getPatientInfoUtils(patArchiveReq);
            if (CollectionUtils.isNotEmpty(patientInfoQC)) {
                patArchiveList.addAll(patientInfoQC);
            }
        } else if (patArchiveReq.getAllhosp() != null && patArchiveReq.getAllhosp() == 3) {
            //  æŸ¥çœ‹ä½é™¢  1  æŸ¥çœ‹é—¨è¯Š  2   æŸ¥çœ‹ä½“检  3
@@ -594,9 +596,9 @@
                patArchiveList.addAll(patArchives1);
            }
        } else if (patArchive.getAllhosp() != null && patArchive.getAllhosp() == 2) {
            List<PatArchiveOthreInfo> patArchives2 = patArchiveMapper.selectPatArchiveInfoByOuthosp(patArchive);
            if (CollectionUtils.isNotEmpty(patArchives2)) {
                patArchiveList.addAll(patArchives2);
            List<PatArchiveOthreInfo> patientInfoUtils = getPatientInfoUtils(patArchive);
            if (CollectionUtils.isNotEmpty(patientInfoUtils)) {
                patArchiveList.addAll(patientInfoUtils);
            }
        } else if (patArchive.getAllhosp() != null && patArchive.getAllhosp() == 3) {
            List<PatArchiveOthreInfo> patArchives3 = patArchiveMapper.selectPatArchiveInfoByPhysical(patArchive);
@@ -781,9 +783,13 @@
            }
        } else if (patArchiveReq.getAllhosp() != null && patArchiveReq.getAllhosp() == 2) {
            // æŸ¥çœ‹ä½é™¢  1  æŸ¥çœ‹é—¨è¯Š  2   æŸ¥çœ‹ä½“检  3 æŸ¥çœ‹å‡ºé™¢ 4
            List<PatArchiveOthreInfo> patArchives2 = patArchiveMapper.selectPatArchiveInfoByOuthospQC(patArchiveReq);
            if (CollectionUtils.isNotEmpty(patArchives2)) {
                patArchiveList.addAll(patArchives2);
            List<PatArchiveOthreInfo> patArchives2 = new ArrayList<>();
//            List<PatArchiveOthreInfo> patArchives2 = patArchiveMapper.selectPatArchiveInfoByOuthospQC(patArchiveReq);
            //门急诊信息,采用分表查询(先查门急诊的存储过程,再查患者基本信息表,关联条件:patid)
            List<PatArchiveOthreInfo> patientInfoUtils = getPatientInfoUtils(patArchiveReq);
            if (CollectionUtils.isNotEmpty(patientInfoUtils)) {
                patArchiveList.addAll(patientInfoUtils);
            }
        } else if (patArchiveReq.getAllhosp() != null && patArchiveReq.getAllhosp() == 3) {
            //  æŸ¥çœ‹ä½é™¢  1  æŸ¥çœ‹é—¨è¯Š  2   æŸ¥çœ‹ä½“检  3 æŸ¥çœ‹å‡ºé™¢ 4
@@ -847,7 +853,19 @@
            count = patArchiveMapper.countPatArchiveInfoByInhospQC(patArchiveReq);
        } else if (patArchiveReq.getAllhosp() != null && patArchiveReq.getAllhosp() == 2) {
            // æŸ¥çœ‹ä½é™¢  1  æŸ¥çœ‹é—¨è¯Š  2   æŸ¥çœ‹ä½“检  3 æŸ¥çœ‹å‡ºé™¢ 4
            count = patArchiveMapper.countPatArchiveInfoByOuthospQC(patArchiveReq);
//            count = patArchiveMapper.countPatArchiveInfoByOuthospQC(patArchiveReq);
            PatMedOuthospQueryReq req=new PatMedOuthospQueryReq();
            String deptcodes = CollectionUtils.isEmpty(patArchiveReq.getLeaveldeptcodes()) ? null : String.join(",", patArchiveReq.getLeaveldeptcodes());
            String leavehospitaldistrictcodes = CollectionUtils.isEmpty(patArchiveReq.getLeavehospitaldistrictcodes()) ? null : String.join(",", patArchiveReq.getLeavehospitaldistrictcodes());
            req.setDeptcode(deptcodes);
            req.setHospitaldistrictcode(leavehospitaldistrictcodes);
            req.setOrgid(patArchiveReq.getOrgid());
            req.setDrname(StringUtils.isNotEmpty(patArchiveReq.getDrname()) ? patArchiveReq.getDrname() : null);
            req.setPatname(StringUtils.isNotEmpty(patArchiveReq.getName()) ? patArchiveReq.getName() : null);
            req.setDiagname(StringUtils.isNotEmpty(patArchiveReq.getLeavediagname()) ? patArchiveReq.getLeavediagname() : null);
            count = patMedOuthospMapper.callSpQueryOuthospCount(req);
        } else if (patArchiveReq.getAllhosp() != null && patArchiveReq.getAllhosp() == 3) {
            //  æŸ¥çœ‹ä½é™¢  1  æŸ¥çœ‹é—¨è¯Š  2   æŸ¥çœ‹ä½“检  3 æŸ¥çœ‹å‡ºé™¢ 4
            count = patArchiveMapper.countPatArchiveInfoByPhysicalQC(patArchiveReq);
@@ -859,5 +877,33 @@
        return count;
    }
    private List<PatArchiveOthreInfo> getPatientInfoUtils(PatArchiveReq patArchiveReq) {
        List<PatArchiveOthreInfo> patArchiveList = new ArrayList<>();
        //门急诊信息,采用分表查询(先查门急诊的存储过程,再查患者基本信息表,关联条件:patid)
        PatMedOuthospQueryReq req=new PatMedOuthospQueryReq();
        String deptcodes = CollectionUtils.isEmpty(patArchiveReq.getLeaveldeptcodes()) ? null : String.join(",", patArchiveReq.getLeaveldeptcodes());
        String leavehospitaldistrictcodes = CollectionUtils.isEmpty(patArchiveReq.getLeavehospitaldistrictcodes()) ? null : String.join(",", patArchiveReq.getLeavehospitaldistrictcodes());
        req.setDeptcode(deptcodes);
        req.setHospitaldistrictcode(leavehospitaldistrictcodes);
        req.setOrgid(patArchiveReq.getOrgid());
        req.setDrname(StringUtils.isNotEmpty(patArchiveReq.getDrname()) ? patArchiveReq.getDrname() : null);
        req.setPatname(StringUtils.isNotEmpty(patArchiveReq.getName()) ? patArchiveReq.getName() : null);
        req.setDiagname(StringUtils.isNotEmpty(patArchiveReq.getLeavediagname()) ? patArchiveReq.getLeavediagname() : null);
        req.setPageNum(patArchiveReq.getPageNum()==null?null:patArchiveReq.getPageNum());
        req.setPageSize(patArchiveReq.getPageSize()==null?null:patArchiveReq.getPageSize());
        List<PatMedOuthosp> patMedOuthosps = patMedOuthospMapper.callSpQueryOuthosp(req);
        for (PatMedOuthosp patMedOuthosp:patMedOuthosps ) {
            PatArchive patArchive = patArchiveMapper.selectPatArchiveByPatid(patMedOuthosp.getPatid());
            PatArchiveOthreInfo patArchiveOthreInfo = DtoConversionUtils.sourceToTarget(patArchive, PatArchiveOthreInfo.class);
            patArchiveOthreInfo.setDeptcode(patMedOuthosp.getDeptcode());
            patArchiveOthreInfo.setDeptname(patMedOuthosp.getDeptname());
            patArchiveOthreInfo.setDrcode(patMedOuthosp.getDrcode());
            patArchiveOthreInfo.setDrname(patMedOuthosp.getDrname());
            patArchiveList.add(patArchiveOthreInfo);
        }
        return patArchiveList;
    }
}
smartor/src/main/java/com/smartor/service/impl/PatMedOuthospServiceImpl.java
@@ -1,27 +1,26 @@
package com.smartor.service.impl;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.DtoConversionUtils;
import com.ruoyi.common.utils.StringUtils;
import com.smartor.domain.*;
import com.smartor.domain.entity.ServiceSubtaskEntity;
import com.smartor.mapper.*;
import com.smartor.service.IPatMedOuthospService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.Statement;
import java.time.LocalDate;
import java.time.Period;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit;
import java.util.*;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.domain.entity.SysUserDept;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.DtoConversionUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.smartor.domain.*;
import com.smartor.domain.entity.ServiceSubtaskEntity;
import com.smartor.mapper.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import com.smartor.service.IPatMedOuthospService;
import org.springframework.util.CollectionUtils;
/**
 * æ‚£è€…门诊记录Service业务层处理
@@ -36,7 +35,7 @@
    private PatMedOuthospMapper patMedOuthospMapper;
    @Autowired
    private SysUserDeptMapper sysUserDeptMapper;
    private DataSource dataSource;
    @Autowired
    private ServiceSubtaskMapper serviceSubtaskMapper;
@@ -62,7 +61,8 @@
     */
    @Override
    public PatMedOuthosp selectPatMedOuthospById(Long id) {
        return patMedOuthospMapper.selectPatMedOuthospById(id);
//        return patMedOuthospMapper.selectPatMedOuthospById(id);
        return null;
    }
    /**
@@ -73,9 +73,10 @@
     */
    @Override
    public List<PatMedOuthosp> selectPatMedOuthospList(PatMedOuthosp patMedOuthosp) {
        List<PatMedOuthosp> patMedOuthosps = patMedOuthospMapper.selectPatMedOuthospList(patMedOuthosp);
        PatMedOuthospQueryReq patMedOuthospQueryReq = DtoConversionUtils.sourceToTarget(patMedOuthosp, PatMedOuthospQueryReq.class);
        List<PatMedOuthosp> patMedOuthospQueryResps = patMedOuthospMapper.callSpQueryOuthosp(patMedOuthospQueryReq);
        if (patMedOuthosp.getPageNum() != null) {
            for (PatMedOuthosp patMedOuthosp1 : patMedOuthosps) {
            for (PatMedOuthosp patMedOuthosp1 : patMedOuthospQueryResps) {
                PatArchive patArchive = patArchiveMapper.selectPatArchiveByPatid(patMedOuthosp1.getPatid());
                if (patArchive.getBirthdate() != null) {
                    Map<String, String> map = calculateAge(patArchive.getBirthdate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate(), LocalDate.now());
@@ -101,7 +102,7 @@
                if (!CollectionUtils.isEmpty(serviceSubtaskList)) patMedOuthosp1.setServerState("1");
            }
        }
        return patMedOuthosps;
        return patMedOuthospQueryResps;
    }
    public Map<String, String> calculateAge(LocalDate birthdate, LocalDate today) {
@@ -158,27 +159,109 @@
    /**
     * æ–°å¢žæ‚£è€…门诊记录
     * æ ¹æ® admitdate è·¯ç”±åˆ°å¯¹åº”分表;若分表不存在则写入主表
     *
     * @param patMedOuthosp æ‚£è€…门诊记录
     * @return ç»“æžœ
     */
    @Override
    public int insertPatMedOuthosp(PatMedOuthosp patMedOuthosp) {
        if (patMedOuthosp.getAdmitdate() != null) {
            log.error("门急就诊时间不能为空");
            return 0;
        }
        patMedOuthosp.setCreateTime(DateUtils.getNowDate());
        patMedOuthosp.setUpdateTime(DateUtils.getNowDate());
        return patMedOuthospMapper.insertPatMedOuthosp(patMedOuthosp);
        patMedOuthosp.setGuid(UUID.randomUUID().toString());
        //需要插入到哪个表,根据就诊时间的日期来定,如果根据就诊时间来确定的表不存在,则存在pat_med_outhosp表中
        String targetTable = resolveTargetTable(patMedOuthosp.getAdmitdate());
        if (targetTable != null) {
            log.info("[insert] è·¯ç”±åˆ°åˆ†è¡¨: {}", targetTable);
            return patMedOuthospMapper.insertIntoTable(targetTable, patMedOuthosp);
        }
        return 0;
    }
    /**
     * ä¿®æ”¹æ‚£è€…门诊记录
     * æ ¹æ® admitdate è·¯ç”±åˆ°å¯¹åº”分表;若分表不存在则改主表
     *
     * @param patMedOuthosp æ‚£è€…门诊记录
     * @return ç»“æžœ
     */
    @Override
    public int updatePatMedOuthosp(PatMedOuthosp patMedOuthosp) {
        patMedOuthosp.setUpdateTime(DateUtils.getNowDate());
        return patMedOuthospMapper.updatePatMedOuthosp(patMedOuthosp);
        if (patMedOuthosp.getSerialnum() == null) {
            log.error("流水号不能为空");
            return 0;
        }
        PatMedOuthospQueryReq patMedOuthospQueryReq = new PatMedOuthospQueryReq();
        patMedOuthospQueryReq.setSerialnum(patMedOuthosp.getSerialnum());
        patMedOuthospQueryReq.setGuid(patMedOuthosp.getGuid());
        patMedOuthospQueryReq.setOuthospno(patMedOuthosp.getOuthospno());
        List<PatMedOuthosp> patMedOuthosps = patMedOuthospMapper.callSpQueryOuthosp(patMedOuthospQueryReq);
        if (patMedOuthosps == null || patMedOuthosps.size() == 0) {
            insertPatMedOuthosp(patMedOuthosp);
        } else {
            patMedOuthosp.setUpdateTime(DateUtils.getNowDate());
            String targetTable = resolveTargetTable(patMedOuthosp.getAdmitdate());
            if (targetTable != null) {
                log.info("[update] è·¯ç”±åˆ°åˆ†è¡¨: {}", targetTable);
                return patMedOuthospMapper.updateInTable(targetTable, patMedOuthosp);
            }
        }
        return 0;
    }
    /**
     * æ ¹æ® create_time æŽ¨ç®—目标分表名,与建表策略保持一致
     * <ul>
     *   <li>6位后缀(YYYYMM)→ æŒ‰æœˆåˆ†è¡¨</li>
     *   <li>8位后缀(YYYYMMdd)→ æŒ‰å­£åº¦åˆ†è¡¨ï¼Œå­£åº¦åŽç¼€å›ºå®šä¸º 0103/0406/0709/1012</li>
     *   <li>4位后缀(YYYY)    â†’ æŒ‰å¹´åˆ†è¡¨</li>
     * </ul>
     * æŽ¨ç®—出表名后校验表是否存在,不存在返回 null(回落主表)
     *
     * @param createTime åˆ›å»ºæ—¶é—´ï¼Œä¸º null æ—¶è¿”回 null
     * @return ç›®æ ‡åˆ†è¡¨åï¼Œæˆ– null
     */
    private String resolveTargetTable(java.util.Date createTime) {
        if (createTime == null) return null;
        List<String> allTables = patMedOuthospMapper.getAllOuthospTableNames();
        if (allTables == null || allTables.isEmpty()) return null;
        // åˆ¤æ–­å½“前分表后缀长度(以第一张表为准)
        String sample = allTables.get(0);
        String suffix = sample.replaceFirst("pat_med_outhosp_", "");
        int suffixLen = suffix.length();
        java.util.Calendar cal = java.util.Calendar.getInstance();
        cal.setTime(createTime);
        int year = cal.get(java.util.Calendar.YEAR);
        int month = cal.get(java.util.Calendar.MONTH) + 1; // 1-based
        String targetTable;
        if (suffixLen == 4) {
            // æŒ‰å¹´
            targetTable = "pat_med_outhosp_" + year;
        } else if (suffixLen == 6) {
            // æŒ‰æœˆ
            targetTable = String.format("pat_med_outhosp_%d%02d", year, month);
        } else {
            // æŒ‰å­£åº¦ï¼ˆ8位后缀,如 20260103)
            String quarterSuffix;
            if (month <= 3) quarterSuffix = "0103";
            else if (month <= 6) quarterSuffix = "0406";
            else if (month <= 9) quarterSuffix = "0709";
            else quarterSuffix = "1012";
            targetTable = "pat_med_outhosp_" + year + quarterSuffix;
        }
        boolean exists = allTables.contains(targetTable);
        log.info("[路由] createTime={} â†’ ç›®æ ‡è¡¨={} exists={}", createTime, targetTable, exists);
        return exists ? targetTable : "pat_med_outhosp";
    }
    /**
@@ -189,7 +272,8 @@
     */
    @Override
    public int deletePatMedOuthospByIds(Long[] ids) {
        return patMedOuthospMapper.deletePatMedOuthospByIds(ids);
//        return patMedOuthospMapper.deletePatMedOuthospByIds(ids);
        return 0;
    }
    /**
@@ -200,22 +284,26 @@
     */
    @Override
    public int deletePatMedOuthospById(Long id) {
        return patMedOuthospMapper.deletePatMedOuthospById(id);
//        return patMedOuthospMapper.deletePatMedOuthospById(id);
        return 0;
    }
    @Override
    public PatMedRes selectPatMedOuthospCount(PatMedReq patMedReq) {
//        // èŽ·å–å½“å‰ç™»é™†äººçš„éƒ¨é—¨æƒé™
//        if (CollectionUtils.isEmpty(patMedReq.getDeptcodeList())) {
//            Long userId = SecurityUtils.getUserId();
//            List<SysDept> sysDepts = sysUserDeptMapper.selectDeptListByUserId(userId);
//            List<String> deptCode = new ArrayList<>();
//            for (SysDept sysDept : sysDepts) {
//                deptCode.add(sysDept.getDeptId().toString());
//            }
//            patMedReq.setDeptcodeList(deptCode);
//        }
        return patMedOuthospMapper.selectPatMedOuthospCount(patMedReq);
        //获取门诊病人信息,并统计人数和人次
        PatMedOuthospQueryReq req = new PatMedOuthospQueryReq();
        String deptcodes = CollectionUtils.isEmpty(patMedReq.getDeptcodeList()) ? null : String.join(",", patMedReq.getDeptcodeList());
        req.setBeginAdmitdate(patMedReq.getStartDate());
        req.setEndAdmitdate(patMedReq.getEndDate());
        req.setDeptcode(deptcodes);
        req.setOrgid(patMedReq.getOrgid());
//        req.setCampusid(patMedReq.getCampusid());
        Long count = patMedOuthospMapper.callSpQueryOuthospCount(req);
        //查询随访人次和人数
        PatMedRes patMedRes = serviceSubtaskMapper.selectVisitCount(patMedReq);
        patMedRes.setRc(count == null ? 0 : count.intValue());
        return patMedRes;
    }
    @Override
@@ -249,7 +337,7 @@
            if (org.apache.commons.collections4.CollectionUtils.isEmpty(serviceTaskdeptList) || serviceTaskdeptList.size() == 0) {
                patMedOuthosp1.setDeptcheckFlag("2");
                patMedOuthosp1.setRemark("通过部门,没有找到门诊随访任务ID");
                patMedOuthospMapper.updatePatMedOuthosp(patMedOuthosp1);
                updatePatMedOuthosp(patMedOuthosp1);
            } else {
                for (ServiceTaskdept serviceTaskdept1 : serviceTaskdeptList) {
                    writeInSubTask(serviceTaskdept1.getTaskId(), true, patMedOuthosp1, patArchive, 1);
@@ -265,7 +353,7 @@
            if (org.apache.commons.collections4.CollectionUtils.isEmpty(serviceTaskdiags) || serviceTaskdiags.size() == 0) {
                patMedOuthosp1.setDiagcheckFlag("2");
                patMedOuthosp1.setRemark("通过icd10,没有找到门诊随访任务ID");
                patMedOuthospMapper.updatePatMedOuthosp(patMedOuthosp1);
                updatePatMedOuthosp(patMedOuthosp1);
            } else {
                for (ServiceTaskdiag serviceTaskdept1 : serviceTaskdiags) {
                    writeInSubTask(serviceTaskdept1.getTaskId(), true, patMedOuthosp1, patArchive, 2);
@@ -294,7 +382,7 @@
            if (type == 1) patMedOuthosp.setDiagcheckFlag("2");
            if (type == 2) patMedOuthosp.setDeptcheckFlag("2");
            patMedOuthosp.setRemark("该患者门诊随访长期任务不存在,任务ID为:" + taskid);
            patMedOuthospMapper.updatePatMedOuthosp(patMedOuthosp);
            updatePatMedOuthosp(patMedOuthosp);
            return;
        }
        ServiceTask serviceTask = serviceTasks.get(0);
@@ -356,16 +444,17 @@
            patMedOuthosp1.setId(patMedOuthosp.getId());
            if (type == 1) patMedOuthosp1.setDiagcheckFlag("2");
            if (type == 2) patMedOuthosp1.setDeptcheckFlag("2");
            patMedOuthospMapper.updatePatMedOuthosp(patMedOuthosp1);
            updatePatMedOuthosp(patMedOuthosp1);
        } else {
            //生成子任务失败,
            log.info("生成子任务失败serviceSubtask的taskid为:{},patid为:{}", serviceSubtask.getTaskid(), serviceSubtask.getPatid());
            PatMedOuthosp pmo = new PatMedOuthosp();
            pmo.setId(patMedOuthosp.getId());
            pmo.setGuid(patMedOuthosp.getGuid());
            pmo.setSerialnum(patMedOuthosp.getSerialnum());
            if (type == 1) pmo.setDiagcheckFlag("2");
            if (type == 2) pmo.setDeptcheckFlag("2");
            pmo.setRemark("生成子任务失败");
            patMedOuthospMapper.updatePatMedOuthosp(pmo);
            updatePatMedOuthosp(pmo);
        }
    }
smartor/src/main/java/com/smartor/service/impl/PersonWorkbenchServiceImpl.java
@@ -1,7 +1,10 @@
package com.smartor.service.impl;
import com.smartor.domain.PatMedOuthosp;
import com.smartor.domain.PatMedOuthospQueryReq;
import com.smartor.domain.PerSonWorkbenchDto;
import com.smartor.mapper.PatArchiveOutMapper;
import com.smartor.mapper.PatMedOuthospMapper;
import com.smartor.service.PersonWorkbenchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -20,12 +23,16 @@
    @Autowired
    private PatArchiveOutMapper patArchiveOutMapper;
    @Autowired
    private PatMedOuthospMapper patMedOuthospMapper;
    @Override
    public List<PerSonWorkbenchDto> getPatCount(String detpId, String drCode) {
        long[] deptIds = Arrays.stream(detpId.split(",")).mapToLong(Long::parseLong).toArray();
    public List<PerSonWorkbenchDto> getPatCount(String deptcode, String drCode) {
        List<String> deptIds = Arrays.asList(deptcode.split(","));
        String[] drCodes = drCode.split(",");
        List<PerSonWorkbenchDto> perSonWorkbenchDtos = patArchiveOutMapper.selectPatArchiveCount(deptIds, drCodes);
        return perSonWorkbenchDtos;
    }
}
smartor/src/main/java/com/smartor/service/impl/ServiceExternalServiceImpl.java
@@ -8,10 +8,12 @@
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.exception.base.BaseException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.DtoConversionUtils;
import com.ruoyi.common.utils.StringUtils;
import com.smartor.domain.*;
import com.smartor.domain.entity.ServiceSubtaskEntity;
import com.smartor.mapper.*;
import com.smartor.service.IPatMedOuthospService;
import com.smartor.service.IServiceExternalService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
@@ -64,6 +66,8 @@
    private PatMedInspectionItemMapper patMedInspectionItemMapper;
    @Autowired
    private Icd10Mapper icd10Mapper;
    @Autowired
    private IPatMedOuthospService patMedOuthospService;
    @Autowired
    private PatMedOuthospMapper patMedOuthospMapper;
    @Autowired
@@ -223,13 +227,13 @@
        if (CollectionUtils.isNotEmpty(sysDepts)) {
            sysDept = sysDepts.get(0);
        }
        if(ObjectUtils.isEmpty(sysUser)){
        if (ObjectUtils.isEmpty(sysUser)) {
            log.error("ServiceExternalServiceImpl---addUserDeptInfo æ‰¾ä¸åˆ°å¯¹åº”的用户 username: {}", externalUserDeptInfo.getYongHuDLM());
            return false;
        }else if(ObjectUtils.isEmpty(sysDept)){
        } else if (ObjectUtils.isEmpty(sysDept)) {
            log.error("ServiceExternalServiceImpl---addUserDeptInfo æ‰¾ä¸åˆ°å¯¹åº”的科室 hisDeptId: {}", externalUserDeptInfo.getKeShiID());
            return false;
        }else {
        } else {
            SysUserDept sysUserDept = new SysUserDept();
            sysUserDept.setDelFlag(0L);
            sysUserDept.setUserId(sysUser.getUserId());
@@ -271,19 +275,18 @@
                log.info("ServiceExternalServiceImpl---addUserDeptInfo是否修改成功03:{}", i);
            }
            //更新sys-user deptId
            if(StringUtils.isNotEmpty(externalUserDeptInfo.getKeShiID())){
            if (StringUtils.isNotEmpty(externalUserDeptInfo.getKeShiID())) {
                sysUser.setDeptId(Long.valueOf(externalUserDeptInfo.getKeShiID()));
                //查询用户科室关系
                SysUserDept sysUserDeptTemp = new SysUserDept();
                sysUserDeptTemp.setUserId(sysUser.getUserId());
                sysUserDeptTemp.setOrgid(externalUserDeptInfo.getZuZhiJGID());
                List<SysUserDept> sysUserDepts = sysUserDeptMapper.selectSysUserDeptList(sysUserDeptTemp);
                List<String> userDepts = sysUserDepts.stream().map(SysUserDept::getDeptCode).
                        distinct().collect(Collectors.toList());
                List<String> userDepts = sysUserDepts.stream().map(SysUserDept::getDeptCode).distinct().collect(Collectors.toList());
                //和queryHospUserInfoList采集的数据格式保持一致
                List<List<String>> userDeptsList = new ArrayList<>();
                if(!userDepts.isEmpty()){
                    for(String userDept: userDepts){
                if (!userDepts.isEmpty()) {
                    for (String userDept : userDepts) {
                        List<String> uDept = new ArrayList<>();
                        uDept.add(userDept);
                        userDeptsList.add(uDept);
@@ -579,7 +582,7 @@
            // 4-非医嘱离院 5-死亡 9-其他 10-介入室 20-手术室
            String liYuanQxdm = ObjectUtils.isNotEmpty(JiuZhenXX.get("LiYuanQXDM")) ? JiuZhenXX.get("LiYuanQXDM").toString() : null;
            //判断病人是否死亡
            if(ObjectUtils.isNotEmpty(liYuanQxdm) &&("5").equals(liYuanQxdm)){
            if (ObjectUtils.isNotEmpty(liYuanQxdm) && ("5").equals(liYuanQxdm)) {
                deathFlag = true;
            }
        }
@@ -625,7 +628,7 @@
        }
        patMedInhosp1.setInhospstate("1");
        if(deathFlag){
        if (deathFlag) {
            //病人死亡无须随访
            patMedInhosp1.setFuflag("1");
            //更新病人 notrequiredFlag
@@ -1032,6 +1035,7 @@
     * ç¬¬ä¸€æ¡ï¼ˆæ€¥è¯Šç§‘室的)记录缺少“出院时间”,导致该记录在统计中始终显示为“在院”,
     * è€Œç¬¬äºŒæ¡ï¼ˆè½¬å…¥ç§‘室的)记录是完整的。我们需要采集 JZ_ZY_LiQiang接口的数据,
     * é‡Œé¢çš„离抢时间来反填第一条记录的“出院时间”,从而修正第一条记录的状态。
     *
     * @param dataMap
     * @return
     */
@@ -1051,7 +1055,7 @@
        List<PatMedInhosp> patMedInhospList = patMedInhospMapper.selectPatMedInhospList(patMedInhosp);
        PatMedInhosp patMedInhosp1 = null;
        if (CollectionUtils.isNotEmpty(patMedInhospList)) patMedInhosp1 = patMedInhospList.get(0);
        if(ObjectUtils.isNotEmpty(patMedInhosp1)){
        if (ObjectUtils.isNotEmpty(patMedInhosp1)) {
            if (ObjectUtils.isNotEmpty(JiuZhenXX.get("LiQiangSJ"))) {
                try {
                    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@@ -1066,16 +1070,15 @@
                }
            }
            return true;
        }else {
        } else {
            log.error("ServiceExternalServiceImpl---editRescueFinishedOutHospInfo的没有找到对应的出院记录:{}", dataMap);
            return false;
        }
    }
    @Override
    public Boolean addFinshJZInfo(Map dataMap) {
        log.info("ServiceExternalServiceImpl---addFinshJZInfo的新增的值为:{}", dataMap);
        //先对表进行维护
        tableMaintenance();
        Map yeWuXX = (Map) dataMap.get("YeWuXX");
        Map XiaoXiTou = (Map) dataMap.get("XiaoXiTou");
@@ -1114,10 +1117,10 @@
        PatArchive patArchive = addPatArchive(externalInHospPatientInfo, null, null);
        PatMedOuthosp patMedOuthosp = new PatMedOuthosp();
        patMedOuthosp.setOuthospno(externalInHospPatientInfo.getBingAnHao());
        patMedOuthosp.setSerialnum(externalInHospPatientInfo.getJiuZhenYWID());
        List<PatMedOuthosp> patMedOuthosps = patMedOuthospMapper.selectPatMedOuthospList(patMedOuthosp);
        PatMedOuthospQueryReq patMedOuthospreq = new PatMedOuthospQueryReq();
        patMedOuthospreq.setOuthospno(externalInHospPatientInfo.getBingAnHao());
        patMedOuthospreq.setSerialnum(externalInHospPatientInfo.getJiuZhenYWID());
        List<PatMedOuthosp> patMedOuthosps = patMedOuthospMapper.callSpQueryOuthosp(patMedOuthospreq);
        for (PatMedOuthosp patMedOuthosp1 : patMedOuthosps) {
            PatArchive pa = patArchiveMapper.selectPatArchiveByPatid(patMedOuthosp1.getPatid());
            if (patArchive.getBirthdate() != null) {
@@ -1133,6 +1136,7 @@
            }
        }
        PatMedOuthosp patMedOuthosp = DtoConversionUtils.sourceToTarget(patMedOuthospreq, PatMedOuthosp.class);
        patMedOuthosp.setPatid(patArchive.getId());
        patMedOuthosp.setPatno(externalInHospPatientInfo.getBingAnHao());
        patMedOuthosp.setPatname(externalInHospPatientInfo.getXingMing());
@@ -1175,7 +1179,7 @@
                //不需要长期任务随访,由医生自己去随访(丽水中医院首次提出)
                patMedOuthosp.setFuflag("1");
            }
            i = patMedOuthospMapper.updatePatMedOuthosp(patMedOuthosp);
            i = patMedOuthospService.updatePatMedOuthosp(patMedOuthosp);
        } else {
            patMedOuthosp.setCreateTime(new Date());
            patMedOuthosp.setUpdateTime(new Date());
@@ -1183,76 +1187,14 @@
                //不需要长期任务随访
                patMedOuthosp.setFuflag("1");
            }
            i = patMedOuthospMapper.insertPatMedOuthosp(patMedOuthosp);
        }
            i = patMedOuthospService.insertPatMedOuthosp(patMedOuthosp);
//        //先通过身份证和科室查询该患者是否有需要随访的(景宁提出来的)
//        if (patMedOuthosp.getOrgid().equals("47255004333112711A1001") && StringUtils.isNotEmpty(patMedOuthosp.getIdcardno()) && StringUtils.isNotEmpty(patMedOuthosp.getDeptcode())) {
//            ServiceSubtaskVO serviceSubtaskVO = new ServiceSubtaskVO();
//            serviceSubtaskVO.setSfzh(patMedOuthosp.getIdcardno());
//            serviceSubtaskVO.setDeptcode(patMedOuthosp.getDeptcode());
//            serviceSubtaskVO.setSendstate(2L);
//            List<ServiceSubtask> serviceSubtaskList = serviceSubtaskMapper.selectServiceSubtaskList(serviceSubtaskVO);
//            if (CollectionUtils.isNotEmpty(serviceSubtaskList)) {
//                for (ServiceSubtask serviceSubtask : serviceSubtaskList) {
//                    serviceSubtask.setSendstate(6L);
//                    serviceSubtask.setRemark("患者已经回来复诊");
//                    serviceSubtask.setUpdateTime(new Date());
//                    serviceSubtaskMapper.updateServiceSubtask(serviceSubtask);
//                }
//            }
//        }
        }
        if (i > 0) {
            return true;
        }
        return false;
    }
    public void tableMaintenance() {
        // 1. åˆ¤æ–­è¡¨æ•°æ®é‡
        int count = patMedOuthospMapper.countPatMedOuthosp();
        if (count > 3000000) {
            // 2. å†·è—è¡¨å¹¶æ–°å»º
            String timeSuffix = new SimpleDateFormat("yyyyMM").format(new Date());
            String oldName = "pat_med_outhosp";
            String newName = oldName + "_" + timeSuffix;
            // å†·è—
            patMedOuthospMapper.renameTable(oldName, newName);
            // 3. è®¡ç®—所有表的最大id
            List<String> tableNames = patMedOuthospMapper.getAllOuthospTableNames();
            long maxId = 0;
            for (String tableName : tableNames) {
                Long tableMaxId = patMedOuthospMapper.getMaxIdFromTable(tableName);
                if (tableMaxId != null && tableMaxId > maxId) {
                    maxId = tableMaxId;
                }
            }
            // 4. æ–°å»º(此时只剩冷表,PatMedOuthosp没了,需要新建一个)
            patMedOuthospMapper.createPatMedOuthosp(newName, oldName);
            //5.设置新表自增主键
            patMedOuthospMapper.createPatMedOuthospAutoAdd(oldName);
            //6. è®¾ç½®æ–°è¡¨è‡ªå¢žèµ·å§‹å€¼
            patMedOuthospMapper.setAutoIncrement(oldName, maxId + 1);
            // 7. æ›´æ–°/新建视图
            // é‡æ–°èŽ·å–æ‰€æœ‰è¡¨åï¼ˆåŒ…å«åˆšæ–°å»ºçš„ä¸»è¡¨ï¼‰
            List<String> allTables = patMedOuthospMapper.getAllOuthospTableNames();
            StringBuilder sb = new StringBuilder();
            sb.append("CREATE OR REPLACE VIEW v_pat_med_outhosp AS ");
            for (int i = 0; i < allTables.size(); i++) {
                sb.append("SELECT * FROM ").append(allTables.get(i));
                if (i < allTables.size() - 1) {
                    sb.append(" UNION ALL ");
                }
            }
            patMedOuthospMapper.createOrReplaceView(sb.toString());
        }
    }
    @Override
smartor/src/main/java/com/smartor/service/impl/ServiceSLTDHealthcareRecordServiceImpl.java
@@ -15,6 +15,7 @@
import com.smartor.mapper.*;
import com.smartor.service.IPatArchiveService;
import com.smartor.service.IPatMedInhospService;
import com.smartor.service.IPatMedOuthospService;
import com.smartor.service.IServiceSLTDHealthcareRecordService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
@@ -48,7 +49,7 @@
    private IPatMedInhospService patMedInhospService;
    @Autowired
    private PatMedOuthospMapper patMedOuthospMapper;
    private IPatMedOuthospService patMedOuthospService;
    @Autowired
    private SysUser2Mapper sysUser2Mapper;
@@ -502,19 +503,15 @@
            try {
                //这里用自动忽略重复会有问题,如果表重新建,serialnum索引会丢失。就无法去重,所以还是需要内存里去重
                batchList = DistinctByProperty.distinctByProperty(batchList, PatMedOuthosp::getSerialnum);
                int insertCount = patMedOuthospMapper.batchInsertIgnore(batchList);
                Integer insertCount = 0;
                for (PatMedOuthosp patMedOuthosp : batchList) {
                    insertCount += patMedOuthospService.insertPatMedOuthosp(patMedOuthosp);
                }
                log.info("批量插入门急诊记录,总数:{}, å®žé™…插入:{}", batchList.size(), insertCount);
            } catch (Exception e) {
                log.error("批量插入门急诊记录失败", e);
                // é™çº§ä¸ºé€æ¡æ’å…¥
                for (PatMedOuthosp patMedOuthosp : batchList) {
                    try {
                        patMedOuthospMapper.insertPatMedOuthosp(patMedOuthosp);
                    } catch (Exception ex) {
                        log.warn("单条插入失败:serialnum={}", patMedOuthosp.getSerialnum());
                    }
                }
            }
        }
        return true;
smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskAnswerServiceImpl.java
@@ -325,9 +325,9 @@
            if (CollectionUtils.isNotEmpty(patMedInhospList)) patid = patMedInhospList.get(0).getPatid();
        } else if (serviceSubTaskMYDAnswerReq.getMzzy().equals("2")) {
            //门诊
            PatMedOuthosp patMedOuthosp = new PatMedOuthosp();
            PatMedOuthospQueryReq patMedOuthosp = new PatMedOuthospQueryReq();
            patMedOuthosp.setSerialnum(serviceSubTaskMYDAnswerReq.getSerialnum());
            patMedOuthosps = patMedOuthospMapper.selectPatMedOuthospList(patMedOuthosp);
            patMedOuthosps = patMedOuthospMapper.callSpQueryOuthosp(patMedOuthosp);
            if (CollectionUtils.isNotEmpty(patMedOuthosps)) patid = patMedOuthosps.get(0).getPatid();
        } else if (serviceSubTaskMYDAnswerReq.getMzzy().equals("3")) {
            //指定一个部门,用来处理投诉建议
smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java
@@ -104,10 +104,16 @@
    private IServiceOutPathService iServiceOutPathService;
    @Autowired
    private IPatMedOuthospService iPatMedOuthospService;
    @Autowired
    private FtpService ftpService;
    @Autowired
    private PatMedInhospMapper patMedInhospMapper;
    @Autowired
    private PatMedOuthospMapper patMedOuthospMapper;
    @Autowired
    private PatArchiveMapper patArchiveMapper;
@@ -315,7 +321,7 @@
        List<ServiceSubtaskRes> serviceSubtaskResList = new ArrayList<>();
        for (ServiceSubtask serviceSubtask : selectServiceSubtaskList) {
            ServiceSubtaskRes serviceSubtaskRes = DtoConversionUtils.sourceToTarget(serviceSubtask, ServiceSubtaskRes.class);
            if(ObjectUtils.isNotEmpty(serviceSubtask.getContinueContent())){
            if (ObjectUtils.isNotEmpty(serviceSubtask.getContinueContent())) {
                serviceSubtaskRes.setContinueContent(serviceSubtask.getContinueContent());
            }
            serviceSubtaskResList.add(serviceSubtaskRes);
@@ -621,8 +627,7 @@
                            serviceTaskdept.setDeptCode(deptCode);
                            serviceTaskdept.setDeptType("1");
                            serviceTaskdept.setServiceType(serviceTaskVO.getServiceType());
                            //先通过任务ID、部门code,判断ServiceTaskdept是否存在,不存在则新增,存在则修改
                            serviceTaskdeptService.insertOrUpdateServiceTaskdept(serviceTaskdept);
                            serviceTaskdeptService.insertServiceTaskdept(serviceTaskdept);
                        }
                    }
                    if (StringUtils.isNotEmpty(serviceTaskVO.getLeavehospitaldistrictcode())) {
@@ -631,8 +636,7 @@
                            serviceTaskdept.setDeptCode(districtcode);
                            serviceTaskdept.setDeptType("2");
                            serviceTaskdept.setServiceType(serviceTaskVO.getServiceType());
                            //先通过任务ID、部门code,判断ServiceTaskdept是否存在,不存在则新增,存在则修改
                            serviceTaskdeptService.insertOrUpdateServiceTaskdept(serviceTaskdept);
                            serviceTaskdeptService.insertServiceTaskdept(serviceTaskdept);
                        }
                    }
                }
@@ -765,8 +769,15 @@
                            serviceTaskdept.setDeptCode(deptCode);
                            serviceTaskdept.setDeptType("1");
                            serviceTaskdept.setServiceType(serviceTaskVO.getServiceType());
                            //先通过任务ID、部门code,判断ServiceTaskdept是否存在,不存在则新增,存在则修改
                            serviceTaskdeptService.insertOrUpdateServiceTaskdept(serviceTaskdept);
                            ServiceTaskdept st = new ServiceTaskdept();
                            st.setDeptCode(deptCode);
                            st.setTaskId(serviceTask.getTaskid());
                            List<ServiceTaskdept> serviceTaskdepts = serviceTaskdeptService.selectServiceTaskdeptList(st);
                            if (CollectionUtils.isEmpty(serviceTaskdepts)) {
                                serviceTaskdeptService.insertServiceTaskdept(serviceTaskdept);
                            } else {
                                serviceTaskdeptService.updateServiceTaskdept(serviceTaskdept);
                            }
                        }
                    }
                    if (StringUtils.isNotEmpty(serviceTaskVO.getLeavehospitaldistrictcode())) {
@@ -781,7 +792,15 @@
                            serviceTaskdept.setDeptType("2");
                            serviceTaskdept.setServiceType(serviceTaskVO.getServiceType());
                            //先通过任务ID、部门code,判断ServiceTaskdept是否存在,不存在则新增,存在则修改
                            serviceTaskdeptService.insertOrUpdateServiceTaskdept(serviceTaskdept);
                            ServiceTaskdept st = new ServiceTaskdept();
                            st.setDeptCode(districtcode);
                            st.setTaskId(serviceTask.getTaskid());
                            List<ServiceTaskdept> serviceTaskdepts = serviceTaskdeptService.selectServiceTaskdeptList(st);
                            if (CollectionUtils.isEmpty(serviceTaskdepts)) {
                                serviceTaskdeptService.insertServiceTaskdept(serviceTaskdept);
                            } else {
                                serviceTaskdeptService.updateServiceTaskdept(serviceTaskdept);
                            }
                        }
                    }
                } else if (serviceTaskVO.getAppltype().equals("3")) {
@@ -2183,6 +2202,26 @@
        List<ServiceStatisticsResponse> result = serviceSubtaskMapper.getServiceStatistics(request);
        //获取门急诊数据
        //填充门诊数据
        for (ServiceStatisticsResponse serviceStatisticsResponse : result) {
            PatMedOuthospQueryReq req = new PatMedOuthospQueryReq();
            String deptcodes = CollectionUtils.isEmpty(request.getDeptcodes()) ? null : String.join(",", request.getDeptcodes());
            if (!request.getTimeType().equals("month")) {
                req.setBeginAdmitdate(DateUtils.parseDate(serviceStatisticsResponse.getTimePeriod()));
                req.setEndAdmitdate(DateUtils.parseDate(serviceStatisticsResponse.getTimePeriod()));
            } else {
                // year ç±»åž‹ï¼štimePeriod æ ¼å¼ä¸º "yyyy-MM",取当月第一天和最后一天
                java.time.YearMonth ym = java.time.YearMonth.parse(serviceStatisticsResponse.getTimePeriod());
                req.setBeginAdmitdate(DateUtils.toDate(ym.atDay(1)));
                req.setEndAdmitdate(DateUtils.toDate(ym.atEndOfMonth()));
            }
            req.setDeptcode(deptcodes);
            req.setOrgid(request.getOrgid());
            Long count = patMedOuthospMapper.callSpQueryOuthospCount(req);
            serviceStatisticsResponse.setPmoCount(count);
        }
        log.info("getServiceStatistics返回结果数量:{}", result.size());
        return result;
smartor/src/main/java/com/smartor/service/impl/ServiceTaskServiceImpl.java
@@ -325,9 +325,9 @@
                patArchive = patArchiveMapper.selectPatArchiveByPatid(patMedInhospList.get(0).getPatid());
            }
        } else if (StringUtils.isNotEmpty(mzserialnum)) {
            PatMedOuthosp patMedOuthosp = new PatMedOuthosp();
            PatMedOuthospQueryReq patMedOuthosp = new PatMedOuthospQueryReq();
            patMedOuthosp.setSerialnum(mzserialnum);
            List<PatMedOuthosp> patMedOuthosps = patMedOuthospMapper.selectPatMedOuthospList(patMedOuthosp);
            List<PatMedOuthosp> patMedOuthosps = patMedOuthospMapper.callSpQueryOuthosp(patMedOuthosp);
            if (CollectionUtils.isNotEmpty(patMedOuthosps)) {
                patArchive = patArchiveMapper.selectPatArchiveByPatid(patMedOuthosps.get(0).getPatid());
            }
smartor/src/main/resources/mapper/smartor/HeLibraryAssortMapper.xml
@@ -42,18 +42,17 @@
    <select id="selectHeLibraryAssortList" parameterType="com.smartor.domain.HeLibraryAssort"
            resultMap="HeLibraryAssortResult">
        <include refid="selectHeLibraryAssortVo"/>
        where 1=1
            and del_flag != 1
            <if test="assortname != null  and assortname != ''">and assortname like concat('%', #{assortname}, '%')</if>
            <if test="orgid != null  and orgid != ''">and orgid = #{orgid}</if>
            <if test="isupload != null ">and isupload = #{isupload}</if>
            <if test="uploadTime != null ">and upload_time = #{uploadTime}</if>
            <if test="pid != null ">and pid = #{pid}</if>
            <if test="guid != null  and guid != ''">and guid = #{guid}</if>
            <if test="seqno != null  ">and seqno = #{seqno}</if>
            <if test="hetype != null  ">and hetype = #{hetype}</if>
        where del_flag != 1
        <if test="assortname != null  and assortname != ''">and assortname like concat('%', #{assortname}, '%')</if>
        <if test="orgid != null  and orgid != ''">and orgid = #{orgid}</if>
        <if test="isupload != null ">and isupload = #{isupload}</if>
        <if test="uploadTime != null ">and upload_time = #{uploadTime}</if>
        <if test="pid != null ">and pid = #{pid}</if>
        <if test="guid != null  and guid != ''">and guid = #{guid}</if>
        <if test="seqno != null  ">and seqno = #{seqno}</if>
        <if test="hetype != null  ">and hetype = #{hetype}</if>
        order by seqno asc
        <if test="pageSize != null  and pageNum != null">limit ${pageSize} OFFSET ${pageNum}</if>
    </select>
    <select id="selectSeqMax" resultType="integer">
@@ -124,7 +123,7 @@
    <update id="deleteHeLibraryAssortById" parameterType="Long">
        update he_library_assort
        <trim prefix="SET" suffixOverrides=",">
           del_flag = 1
            del_flag = 1
        </trim>
        where id = #{id}
    </update>
smartor/src/main/resources/mapper/smartor/PatArchiveMapper.xml
@@ -997,96 +997,96 @@
        ) as tmp
    </select>
    <select id="selectPatArchiveInfoByOuthospQC" parameterType="com.smartor.domain.PatArchiveReq"
            resultMap="PatArchiveOthreInfoResult">
<!--    <select id="selectPatArchiveInfoByOuthospQC" parameterType="com.smartor.domain.PatArchiveReq"-->
<!--            resultMap="PatArchiveOthreInfoResult">-->
        select
        a.idcardno,
        a.id,
        a.age_unit,
        a.age_unit2,
        a.patid_his,
        a.sd_flag,
        a.campusid,
        a.patientno,
        a.notrequired_flag,
        a.notrequiredreason,
        d.deptname,
        d.deptcode,
        d.drcode,
        d.drname,
        a.name,
        a.sex,
        a.nation,
        a.native_place,
        a.place_of_residence,
        a.birthplace,
        a.birthdate,
        a.age,
        a.age2,
        a.viptype,
        a.sourcefrom,
        a.archivetime,
        a.archiveby,
        a.telcode,
        a.relativetelcode,
        a.idcardtype,
        a.orgid,
        a.openid,
        a.del_flag,
        a.update_by,
        a.update_time,
        a.create_by,
        a.create_time,
        a.isupload,
        a.upload_time,
        a.filter_drname,
        a.filter_drcode,
        a.pattype
        from pat_med_outhosp d JOIN pat_archive a ON a.id = d.patid
        where 1=1
            and d.del_flag != 1
            AND a.del_flag != 1
            and d.orgid = #{orgid}
            <if test="pid != null  and pid != ''">and a.id = #{pid}</if>
            <if test="campusid != null  and campusid != ''">and a.campusid = #{campusid}</if>
            <if test="name != null  and name != ''">and a.name like concat('%', #{name}, '%')</if>
            <if test="idcardno != null  and idcardno != ''">and a.idcardno = #{idcardno}</if>
            <if test="telcode != null  and telcode != ''">and a.telcode = #{telcode}</if>
            <if test="hospitaldistrictname != null and hospitaldistrictname != ''">
                AND d.hospitaldistrictname LIKE concat('%',#{hospitaldistrictname}, '%')
            </if>
            <if test="notrequiredFlag != null  and notrequiredFlag != ''">and a.notrequired_flag = #{notrequiredFlag}
            </if>
            <if test="leavediagname != null and leavediagname != ''">
                AND d.diagname LIKE concat('%',#{leavediagname}, '%')
            </if>
            <if test="hospitalname != null and hospitalname != ''">
                AND d.hospitalname = #{hospitalname}
            </if>
            <if test="visitno != null and visitno != ''">
                AND d.outhospno = #{visitno}
            </if>
            <if test="deptname != null and deptname != ''">
                and d.deptname LIKE concat('%', #{deptname}, '%')
            </if>
            <if test="drname != null and drname != ''">
                AND d.drname LIKE concat('%',#{drname}, '%')
            </if>
            <if test="drcode != null">
                AND d.drcode = #{drcode}
            </if>
            <if test="pids != null">
                AND a.id NOT IN
                <foreach collection="pids" item="pid" open="(" separator="," close=")">
                    #{pid}
                </foreach>
            </if>
            <if test="isFilter == true">
                AND NOT exists ( SELECT 1 FROM pat_filterlist f where d.patid=f.patid)
            </if>
        <if test="pageSize != null  and pageNum != null">limit ${pageSize} OFFSET ${pageNum}</if>
    </select>
<!--        select-->
<!--        a.idcardno,-->
<!--        a.id,-->
<!--        a.age_unit,-->
<!--        a.age_unit2,-->
<!--        a.patid_his,-->
<!--        a.sd_flag,-->
<!--        a.campusid,-->
<!--        a.patientno,-->
<!--        a.notrequired_flag,-->
<!--        a.notrequiredreason,-->
<!--        d.deptname,-->
<!--        d.deptcode,-->
<!--        d.drcode,-->
<!--        d.drname,-->
<!--        a.name,-->
<!--        a.sex,-->
<!--        a.nation,-->
<!--        a.native_place,-->
<!--        a.place_of_residence,-->
<!--        a.birthplace,-->
<!--        a.birthdate,-->
<!--        a.age,-->
<!--        a.age2,-->
<!--        a.viptype,-->
<!--        a.sourcefrom,-->
<!--        a.archivetime,-->
<!--        a.archiveby,-->
<!--        a.telcode,-->
<!--        a.relativetelcode,-->
<!--        a.idcardtype,-->
<!--        a.orgid,-->
<!--        a.openid,-->
<!--        a.del_flag,-->
<!--        a.update_by,-->
<!--        a.update_time,-->
<!--        a.create_by,-->
<!--        a.create_time,-->
<!--        a.isupload,-->
<!--        a.upload_time,-->
<!--        a.filter_drname,-->
<!--        a.filter_drcode,-->
<!--        a.pattype-->
<!--        from pat_med_outhosp d JOIN pat_archive a ON a.id = d.patid-->
<!--        where 1=1-->
<!--            and d.del_flag != 1-->
<!--            AND a.del_flag != 1-->
<!--            and d.orgid = #{orgid}-->
<!--            <if test="pid != null  and pid != ''">and a.id = #{pid}</if>-->
<!--            <if test="campusid != null  and campusid != ''">and a.campusid = #{campusid}</if>-->
<!--            <if test="name != null  and name != ''">and a.name like concat('%', #{name}, '%')</if>-->
<!--            <if test="idcardno != null  and idcardno != ''">and a.idcardno = #{idcardno}</if>-->
<!--            <if test="telcode != null  and telcode != ''">and a.telcode = #{telcode}</if>-->
<!--            <if test="hospitaldistrictname != null and hospitaldistrictname != ''">-->
<!--                AND d.hospitaldistrictname LIKE concat('%',#{hospitaldistrictname}, '%')-->
<!--            </if>-->
<!--            <if test="notrequiredFlag != null  and notrequiredFlag != ''">and a.notrequired_flag = #{notrequiredFlag}-->
<!--            </if>-->
<!--            <if test="leavediagname != null and leavediagname != ''">-->
<!--                AND d.diagname LIKE concat('%',#{leavediagname}, '%')-->
<!--            </if>-->
<!--            <if test="hospitalname != null and hospitalname != ''">-->
<!--                AND d.hospitalname = #{hospitalname}-->
<!--            </if>-->
<!--            <if test="visitno != null and visitno != ''">-->
<!--                AND d.outhospno = #{visitno}-->
<!--            </if>-->
<!--            <if test="deptname != null and deptname != ''">-->
<!--                and d.deptname LIKE concat('%', #{deptname}, '%')-->
<!--            </if>-->
<!--            <if test="drname != null and drname != ''">-->
<!--                AND d.drname LIKE concat('%',#{drname}, '%')-->
<!--            </if>-->
<!--            <if test="drcode != null">-->
<!--                AND d.drcode = #{drcode}-->
<!--            </if>-->
<!--            <if test="pids != null">-->
<!--                AND a.id NOT IN-->
<!--                <foreach collection="pids" item="pid" open="(" separator="," close=")">-->
<!--                    #{pid}-->
<!--                </foreach>-->
<!--            </if>-->
<!--            <if test="isFilter == true">-->
<!--                AND NOT exists ( SELECT 1 FROM pat_filterlist f where d.patid=f.patid)-->
<!--            </if>-->
<!--        <if test="pageSize != null  and pageNum != null">limit ${pageSize} OFFSET ${pageNum}</if>-->
<!--    </select>-->
    <select id="selectPatArchiveInfoByPhysicalQC" parameterType="com.smartor.domain.PatArchiveReq"
            resultMap="PatArchiveOthreInfoResult">
@@ -1240,37 +1240,37 @@
    </select>
    <!-- é—¨è¯Šæ‚£è€…总数统计(去重) -->
    <select id="countPatArchiveInfoByOuthospQC" parameterType="com.smartor.domain.PatArchiveReq" resultType="long">
        SELECT COUNT(DISTINCT a.id)
        FROM pat_med_outhosp d
        JOIN pat_archive a ON a.id = d.patid
        WHERE 1=1
            AND d.del_flag != 1
            AND a.del_flag != 1
            AND d.orgid = #{orgid}
            <if test="pid != null  and pid != ''">AND a.id = #{pid}</if>
            <if test="campusid != null  and campusid != ''">AND a.campusid = #{campusid}</if>
            <if test="name != null  and name != ''">AND a.name like concat('%', #{name}, '%')</if>
            <if test="idcardno != null  and idcardno != ''">AND a.idcardno = #{idcardno}</if>
            <if test="telcode != null  and telcode != ''">AND a.telcode = #{telcode}</if>
            <if test="hospitaldistrictname != null and hospitaldistrictname != ''">AND d.hospitaldistrictname LIKE concat('%',#{hospitaldistrictname}, '%')</if>
            <if test="notrequiredFlag != null  and notrequiredFlag != ''">AND a.notrequired_flag = #{notrequiredFlag}</if>
            <if test="leavediagname != null and leavediagname != ''">AND d.diagname LIKE concat('%',#{leavediagname}, '%')</if>
            <if test="hospitalname != null and hospitalname != ''">AND d.hospitalname = #{hospitalname}</if>
            <if test="visitno != null and visitno != ''">AND d.outhospno = #{visitno}</if>
            <if test="deptname != null and deptname != ''">AND d.deptname LIKE concat('%', #{deptname}, '%')</if>
            <if test="drname != null and drname != ''">AND d.drname LIKE concat('%',#{drname}, '%')</if>
            <if test="drcode != null">AND d.drcode = #{drcode}</if>
            <if test="pids != null">
                AND a.id NOT IN
                <foreach collection="pids" item="pid" open="(" separator="," close=")">
                    #{pid}
                </foreach>
            </if>
            <if test="isFilter == true">
                AND NOT exists ( SELECT 1 FROM pat_filterlist f where d.patid=f.patid)
            </if>
    </select>
<!--    <select id="countPatArchiveInfoByOuthospQC" parameterType="com.smartor.domain.PatArchiveReq" resultType="long">-->
<!--        SELECT COUNT(DISTINCT a.id)-->
<!--        FROM pat_med_outhosp d-->
<!--        JOIN pat_archive a ON a.id = d.patid-->
<!--        WHERE 1=1-->
<!--            AND d.del_flag != 1-->
<!--            AND a.del_flag != 1-->
<!--            AND d.orgid = #{orgid}-->
<!--            <if test="pid != null  and pid != ''">AND a.id = #{pid}</if>-->
<!--            <if test="campusid != null  and campusid != ''">AND a.campusid = #{campusid}</if>-->
<!--            <if test="name != null  and name != ''">AND a.name like concat('%', #{name}, '%')</if>-->
<!--            <if test="idcardno != null  and idcardno != ''">AND a.idcardno = #{idcardno}</if>-->
<!--            <if test="telcode != null  and telcode != ''">AND a.telcode = #{telcode}</if>-->
<!--            <if test="hospitaldistrictname != null and hospitaldistrictname != ''">AND d.hospitaldistrictname LIKE concat('%',#{hospitaldistrictname}, '%')</if>-->
<!--            <if test="notrequiredFlag != null  and notrequiredFlag != ''">AND a.notrequired_flag = #{notrequiredFlag}</if>-->
<!--            <if test="leavediagname != null and leavediagname != ''">AND d.diagname LIKE concat('%',#{leavediagname}, '%')</if>-->
<!--            <if test="hospitalname != null and hospitalname != ''">AND d.hospitalname = #{hospitalname}</if>-->
<!--            <if test="visitno != null and visitno != ''">AND d.outhospno = #{visitno}</if>-->
<!--            <if test="deptname != null and deptname != ''">AND d.deptname LIKE concat('%', #{deptname}, '%')</if>-->
<!--            <if test="drname != null and drname != ''">AND d.drname LIKE concat('%',#{drname}, '%')</if>-->
<!--            <if test="drcode != null">AND d.drcode = #{drcode}</if>-->
<!--            <if test="pids != null">-->
<!--                AND a.id NOT IN-->
<!--                <foreach collection="pids" item="pid" open="(" separator="," close=")">-->
<!--                    #{pid}-->
<!--                </foreach>-->
<!--            </if>-->
<!--            <if test="isFilter == true">-->
<!--                AND NOT exists ( SELECT 1 FROM pat_filterlist f where d.patid=f.patid)-->
<!--            </if>-->
<!--    </select>-->
    <!-- ä½“检患者总数统计(去重) -->
    <select id="countPatArchiveInfoByPhysicalQC" parameterType="com.smartor.domain.PatArchiveReq" resultType="long">
smartor/src/main/resources/mapper/smartor/PatArchiveOutMapper.xml
@@ -77,33 +77,33 @@
            resultMap="PatArchiveOutResult">
        <include refid="selectPatArchiveOutVo"/>
        where 1=1
            <if test="patientno != null  and patientno != ''">and patientno = #{patientno}</if>
            <if test="pattype != null  and pattype != ''">and pattype = #{pattype}</if>
            <if test="name != null  and name != ''">and name like concat('%', #{name}, '%')</if>
            <if test="sex != null ">and sex = #{sex}</if>
            <if test="nation != null  and nation != ''">and nation = #{nation}</if>
            <if test="nativePlace != null  and nativePlace != ''">and native_place = #{nativePlace}</if>
            <if test="placeOfResidence != null  and placeOfResidence != ''">and place_of_residence =
                #{placeOfResidence}
            </if>
            <if test="birthplace != null  and birthplace != ''">and birthplace = #{birthplace}</if>
            <if test="idcardno != null  and idcardno != ''">and idcardno = #{idcardno}</if>
            <if test="birthdate != null ">and birthdate = #{birthdate}</if>
            <if test="age != null ">and age = #{age}</if>
            <if test="archivetime != null ">and archivetime = #{archivetime}</if>
            <if test="archiveby != null  and archiveby != ''">and archiveby = #{archiveby}</if>
            <if test="telcode != null  and telcode != ''">and telcode = #{telcode}</if>
            <if test="relativetelcode != null  and relativetelcode != ''">and relativetelcode = #{relativetelcode}</if>
            <if test="idcardtype != null  and idcardtype != ''">and idcardtype = #{idcardtype}</if>
            <if test="orgid != null  and orgid != ''">and orgid = #{orgid}</if>
            <if test="openid != null  and openid != ''">and openid = #{openid}</if>
            <if test="dduserid != null  and dduserid != ''">and dduserid = #{dduserid}</if>
            <if test="source != null ">and source = #{source}</if>
            <if test="isupload != null ">and isupload = #{isupload}</if>
            <if test="uploadTime != null ">and upload_time = #{uploadTime}</if>
            <if test="pid != null ">and pid = #{pid}</if>
            <if test="guid != null  and guid != ''">and guid = #{guid}</if>
            <if test="membertype != null  and membertype != ''">and membertype = #{membertype}</if>
        <if test="patientno != null  and patientno != ''">and patientno = #{patientno}</if>
        <if test="pattype != null  and pattype != ''">and pattype = #{pattype}</if>
        <if test="name != null  and name != ''">and name like concat('%', #{name}, '%')</if>
        <if test="sex != null ">and sex = #{sex}</if>
        <if test="nation != null  and nation != ''">and nation = #{nation}</if>
        <if test="nativePlace != null  and nativePlace != ''">and native_place = #{nativePlace}</if>
        <if test="placeOfResidence != null  and placeOfResidence != ''">and place_of_residence =
            #{placeOfResidence}
        </if>
        <if test="birthplace != null  and birthplace != ''">and birthplace = #{birthplace}</if>
        <if test="idcardno != null  and idcardno != ''">and idcardno = #{idcardno}</if>
        <if test="birthdate != null ">and birthdate = #{birthdate}</if>
        <if test="age != null ">and age = #{age}</if>
        <if test="archivetime != null ">and archivetime = #{archivetime}</if>
        <if test="archiveby != null  and archiveby != ''">and archiveby = #{archiveby}</if>
        <if test="telcode != null  and telcode != ''">and telcode = #{telcode}</if>
        <if test="relativetelcode != null  and relativetelcode != ''">and relativetelcode = #{relativetelcode}</if>
        <if test="idcardtype != null  and idcardtype != ''">and idcardtype = #{idcardtype}</if>
        <if test="orgid != null  and orgid != ''">and orgid = #{orgid}</if>
        <if test="openid != null  and openid != ''">and openid = #{openid}</if>
        <if test="dduserid != null  and dduserid != ''">and dduserid = #{dduserid}</if>
        <if test="source != null ">and source = #{source}</if>
        <if test="isupload != null ">and isupload = #{isupload}</if>
        <if test="uploadTime != null ">and upload_time = #{uploadTime}</if>
        <if test="pid != null ">and pid = #{pid}</if>
        <if test="guid != null  and guid != ''">and guid = #{guid}</if>
        <if test="membertype != null  and membertype != ''">and membertype = #{membertype}</if>
    </select>
    <select id="selectPatArchiveOutByPatid" parameterType="Long" resultMap="PatArchiveOutResult">
@@ -116,40 +116,37 @@
        from (
        SELECT "住院" as name1, count(1) as count FROM `pat_med_inhosp`
        where 1=1
            and del_flag = 0 and endtime = null
            <if test="orgid != null and orgid != ''">
                AND orgid = #{orgid}
            </if>
            <if test="deptIds != null ">and deptId in
                <foreach collection="deptIds" item="deptId" open="(" separator="," close=")">
                    #{deptId}
                </foreach>
            </if>
            <if test="drCodes != null ">and drcode in
                <foreach collection="drCodes" item="drCode" open="(" separator="," close=")">
                    #{drCode}
                </foreach>
            </if>
        and del_flag = 0 and endtime = null
        <if test="orgid != null and orgid != ''">
            AND orgid = #{orgid}
        </if>
        <if test="deptcodes != null ">and deptcode in
            <foreach collection="deptcodes" item="deptcode" open="(" separator="," close=")">
                #{deptcode}
            </foreach>
        </if>
        <if test="drCodes != null ">and drcode in
            <foreach collection="drCodes" item="drCode" open="(" separator="," close=")">
                #{drCode}
            </foreach>
        </if>
        union
        select "出院" name1, count(1) as count FROM `pat_med_inhosp`
        where 1=1
            and del_flag = 0 and endtime != null
            <if test="orgid != null and orgid != ''">
                AND orgid = #{orgid}
            </if>
            <if test="deptIds != null ">and deptId in
                <foreach collection="deptIds" item="deptId" open="(" separator="," close=")">
                    #{deptId}
                </foreach>
            </if>
            <if test="drCodes != null ">and drcode in
                <foreach collection="drCodes" item="drCode" open="(" separator="," close=")">
                    #{drCode}
                </foreach>
            </if>
        union
        select "门诊" name1, count(1) as count FROM `pat_med_outhosp`
        where del_flag=0
        and del_flag = 0 and endtime != null
        <if test="orgid != null and orgid != ''">
            AND orgid = #{orgid}
        </if>
        <if test="deptcodes != null ">and leaveldeptcode in
            <foreach collection="deptcodes" item="deptcode" open="(" separator="," close=")">
                #{deptcode}
            </foreach>
        </if>
        <if test="drCodes != null ">and drcode in
            <foreach collection="drCodes" item="drCode" open="(" separator="," close=")">
                #{drCode}
            </foreach>
        </if>
        ) aa
    </select>
smartor/src/main/resources/mapper/smartor/PatMedInhospMapper.xml
@@ -215,80 +215,80 @@
        LEFT JOIN
        pat_archivetag c ON c.patid = a.id AND (c.del_flag = 0 OR c.del_flag IS NULL)
        where 1=1
            AND a.del_flag = 0
            AND b.del_flag = 0
            AND a.idcardno IS NOT NULL
            <if test="startOutHospTime != null ">and date_format(b.endtime,'%y%m%d') &gt;=
                date_format(#{startOutHospTime},'%y%m%d')
            </if>
            <if test="endOutHospTime != null ">and date_format(b.endtime,'%y%m%d') &lt;=
                date_format(#{endOutHospTime},'%y%m%d')
            </if>
            <if test="startInHospTime != null ">and date_format(b.starttime,'%y%m%d') &gt;=
                date_format(#{startInHospTime},'%y%m%d')
            </if>
            <if test="endInHospTime != null ">and date_format(b.starttime,'%y%m%d') &lt;=
                date_format(#{endInHospTime},'%y%m%d')
            </if>
            <if test="hospitalname != null  and hospitalname != ''">and hospitalname like concat('%', #{hospitalname},
                '%')
            </if>
            <if test="patname != null  and patname != ''">and patname like concat('%', #{patname}, '%')</if>
            <if test="hospitaldistrictname != null  and hospitaldistrictname != ''">and hospitaldistrictname like
                concat('%', #{hospitaldistrictname}, '%')
            </if>
            <if test="endtime != null ">and b.endtime = #{endtime}</if>
            <if test="managementDoctor != null ">and b.management_doctor = #{managementDoctor}</if>
            <if test="managementDoctorCode != null ">and b.management_doctor_code = #{managementDoctorCode}</if>
            <if test="inhospno != null ">and b.inhospno = #{inhospno}</if>
            <if test="fuflag != null ">and b.fuflag = #{fuflag}</if>
            <if test="orgid != null ">and b.orgid = #{orgid}</if>
            <if test="serialnum != null ">and b.serialnum = #{serialnum}</if>
            <if test="endtime != null ">and b.endtime = #{endtime}</if>
            <if test="patno != null ">and b.patno = #{patno}</if>
            <if test="nurseId != null ">and b.nurse_id = #{nurseId}</if>
            <if test="nurseName != null and nurseName != ''">and b.nurse_name = #{nurseName}</if>
            <if test="deptcheckFlag != null ">and b.deptcheck_flag = #{deptcheckFlag}</if>
            <if test="wardcheckFlag != null ">and b.wardcheck_flag = #{wardcheckFlag}</if>
            <if test="diagcheckFlag != null ">and b.diagcheck_flag = #{diagcheckFlag}</if>
            <if test="cry != null and cry == 0 ">and b.endtime is null</if>
            <if test="cry != null and cry == 1 ">and b.inhospstate=1</if>
            <if test="inhospstate != null ">and b.inhospstate = #{inhospstate}</if>
            <if test="campusid != null ">and b.campusid = #{campusid}</if>
            <if test="schemestatus != null ">and b.schemestatus = #{schemestatus}</if>
            <if test="outWayId != null ">and b.out_way_id = #{outWayId}</if>
            <if test="outWayName != null ">and b.out_way_name = #{outWayName}</if>
            <if test="leaveldeptcode != null ">and b.leaveldeptcode = #{leaveldeptcode}</if>
            <if test="leavediagname != null  and leavediagname != ''">and b.leavediagname like concat('%',
                #{leavediagname}, '%')
            </if>
            <if test="drname != null  and drname != ''">and b.drname like concat('%', #{drname}, '%')</if>
            <if test="leaveldeptname != null  and leaveldeptname != ''">and b.leaveldeptname like concat('%',
                #{leaveldeptname}, '%')
            </if>
            <if test="deptname != null  and deptname != ''">and b.deptname like concat('%',
                #{deptname}, '%')
            </if>
            <if test="patid != null  and patid != ''">and a.id =#{patid}
            </if>
            <if test="leavehospitaldistrictname != null  and leavehospitaldistrictname != ''">and
                b.leavehospitaldistrictname like concat('%', #{leavehospitaldistrictname}, '%')
            </if>
        AND a.del_flag = 0
        AND b.del_flag = 0
        AND a.idcardno IS NOT NULL
        <if test="startOutHospTime != null ">and date_format(b.endtime,'%y%m%d') &gt;=
            date_format(#{startOutHospTime},'%y%m%d')
        </if>
        <if test="endOutHospTime != null ">and date_format(b.endtime,'%y%m%d') &lt;=
            date_format(#{endOutHospTime},'%y%m%d')
        </if>
        <if test="startInHospTime != null ">and date_format(b.starttime,'%y%m%d') &gt;=
            date_format(#{startInHospTime},'%y%m%d')
        </if>
        <if test="endInHospTime != null ">and date_format(b.starttime,'%y%m%d') &lt;=
            date_format(#{endInHospTime},'%y%m%d')
        </if>
        <if test="hospitalname != null  and hospitalname != ''">and hospitalname like concat('%', #{hospitalname},
            '%')
        </if>
        <if test="patname != null  and patname != ''">and patname like concat('%', #{patname}, '%')</if>
        <if test="hospitaldistrictname != null  and hospitaldistrictname != ''">and hospitaldistrictname like
            concat('%', #{hospitaldistrictname}, '%')
        </if>
        <if test="endtime != null ">and b.endtime = #{endtime}</if>
        <if test="managementDoctor != null ">and b.management_doctor = #{managementDoctor}</if>
        <if test="managementDoctorCode != null ">and b.management_doctor_code = #{managementDoctorCode}</if>
        <if test="inhospno != null ">and b.inhospno = #{inhospno}</if>
        <if test="fuflag != null ">and b.fuflag = #{fuflag}</if>
        <if test="orgid != null ">and b.orgid = #{orgid}</if>
        <if test="serialnum != null ">and b.serialnum = #{serialnum}</if>
        <if test="endtime != null ">and b.endtime = #{endtime}</if>
        <if test="patno != null ">and b.patno = #{patno}</if>
        <if test="nurseId != null ">and b.nurse_id = #{nurseId}</if>
        <if test="nurseName != null and nurseName != ''">and b.nurse_name = #{nurseName}</if>
        <if test="deptcheckFlag != null ">and b.deptcheck_flag = #{deptcheckFlag}</if>
        <if test="wardcheckFlag != null ">and b.wardcheck_flag = #{wardcheckFlag}</if>
        <if test="diagcheckFlag != null ">and b.diagcheck_flag = #{diagcheckFlag}</if>
        <if test="cry != null and cry == 0 ">and b.endtime is null</if>
        <if test="cry != null and cry == 1 ">and b.inhospstate=1</if>
        <if test="inhospstate != null ">and b.inhospstate = #{inhospstate}</if>
        <if test="campusid != null ">and b.campusid = #{campusid}</if>
        <if test="schemestatus != null ">and b.schemestatus = #{schemestatus}</if>
        <if test="outWayId != null ">and b.out_way_id = #{outWayId}</if>
        <if test="outWayName != null ">and b.out_way_name = #{outWayName}</if>
        <if test="leaveldeptcode != null ">and b.leaveldeptcode = #{leaveldeptcode}</if>
        <if test="leavediagname != null  and leavediagname != ''">and b.leavediagname like concat('%',
            #{leavediagname}, '%')
        </if>
        <if test="drname != null  and drname != ''">and b.drname like concat('%', #{drname}, '%')</if>
        <if test="leaveldeptname != null  and leaveldeptname != ''">and b.leaveldeptname like concat('%',
            #{leaveldeptname}, '%')
        </if>
        <if test="deptname != null  and deptname != ''">and b.deptname like concat('%',
            #{deptname}, '%')
        </if>
        <if test="patid != null  and patid != ''">and a.id =#{patid}
        </if>
        <if test="leavehospitaldistrictname != null  and leavehospitaldistrictname != ''">and
            b.leavehospitaldistrictname like concat('%', #{leavehospitaldistrictname}, '%')
        </if>
            <if test="leavehospitaldistrictcodes != null and leavehospitaldistrictcodes.size()>0">
                AND b.leavehospitaldistrictcode IN
                <foreach collection="leavehospitaldistrictcodes" item="leavehospitaldistrictcode" open="(" separator=","
                         close=")">
                    #{leavehospitaldistrictcode}
                </foreach>
            </if>
            <if test="leaveldeptcodes != null and leaveldeptcodes.size()>0">
                AND b.leaveldeptcode IN
                <foreach collection="leaveldeptcodes" item="leaveldeptcode" open="(" separator=","
                         close=")">
                    #{leaveldeptcode}
                </foreach>
            </if>
        <if test="leavehospitaldistrictcodes != null and leavehospitaldistrictcodes.size()>0">
            AND b.leavehospitaldistrictcode IN
            <foreach collection="leavehospitaldistrictcodes" item="leavehospitaldistrictcode" open="(" separator=","
                     close=")">
                #{leavehospitaldistrictcode}
            </foreach>
        </if>
        <if test="leaveldeptcodes != null and leaveldeptcodes.size()>0">
            AND b.leaveldeptcode IN
            <foreach collection="leaveldeptcodes" item="leaveldeptcode" open="(" separator=","
                     close=")">
                #{leaveldeptcode}
            </foreach>
        </if>
        GROUP BY
        b.inhospid,
        a.age,
@@ -854,80 +854,6 @@
        </foreach>
    </delete>
    <select id="getDeptRanking" parameterType="com.smartor.domain.PatMedReq" resultType="com.smartor.domain.PatMedRes">
        SELECT deptname, COUNT(1) AS rc
        FROM (
        <if test="mz != null">
            SELECT deptname
            FROM pat_med_outhosp
            where 1=1
            and del_flag=0
            <if test="deptcodeList != null   and deptcodeList.size() > 0">
                and deptcode in
                <foreach collection="deptcodeList" item="deptcode" open="(" separator="," close=")">
                    #{deptcode}
                </foreach>
            </if>
            <if test="orgid != null and orgid != ''">
                and orgid = #{orgid}
            </if>
        </if>
        <if test="mz != null and zy != null">
            UNION ALL
        </if>
        <if test="zy != null">
            SELECT deptname
            FROM pat_med_inhosp
            where 1=1
            and del_flag=0
            and inhospstate=0
            <if test="deptcodeList != null   and deptcodeList.size() > 0">
                and deptcode in
                <foreach collection="deptcodeList" item="deptcode" open="(" separator="," close=")">
                    #{deptcode}
                </foreach>
            </if>
            <if test="orgid != null and orgid != ''">
                and orgid = #{orgid}
            </if>
        </if>
        <if test="cy != null and zy != null">
            UNION ALL
            SELECT deptname
            FROM pat_med_inhosp
            where 1=1
            and del_flag=0
            and inhospstate=1
            <if test="deptcodeList != null   and deptcodeList.size() > 0">
                and deptcode in
                <foreach collection="deptcodeList" item="deptcode" open="(" separator="," close=")">
                    #{deptcode}
                </foreach>
            </if>
            <if test="orgid != null and orgid != ''">
                and orgid = #{orgid}
            </if>
        </if>
        <if test="mz != null and zy != null and cy==null">
            UNION ALL
            SELECT deptname
            FROM pat_med_inhosp
            where 1=1
            and del_flag=0
            and inhospstate=1
            <if test="deptcodeList != null   and deptcodeList.size() > 0">
                and deptcode in
                <foreach collection="deptcodeList" item="deptcode" open="(" separator="," close=")">
                    #{deptcode}
                </foreach>
            </if>
            <if test="orgid != null and orgid != ''">
                and orgid = #{orgid}
            </if>
        </if>
        ) AS combined
        GROUP BY deptname;
    </select>
    <select id="selectPatMedInhospCount" parameterType="com.smartor.domain.PatMedReq"
            resultType="com.smartor.domain.PatMedRes">
        SELECT SUM( rs ) AS rs,
@@ -1093,12 +1019,13 @@
    <!-- æŸ¥è¯¢ä¸‰ä¸ªç»´åº¦ä»»æ„ä¸€ä¸ªæœªå¤„理的出院患者 -->
    <select id="selectNeedProcessList" resultMap="PatMedInhospResult">
        SELECT * FROM pat_med_inhosp
        SELECT *
        FROM pat_med_inhosp
        WHERE inhospstate = '1'
          AND fuflag = '1'
          AND del_flag = '0'
          AND (
            dept_check_flag = '0'
                    dept_check_flag = '0'
                OR ward_check_flag = '0'
                OR diag_check_flag = '0'
            )
smartor/src/main/resources/mapper/smartor/PatMedOuthospMapper.xml
@@ -43,482 +43,460 @@
        <result property="campusid" column="campusid"/>
    </resultMap>
    <sql id="selectPatMedOuthospVo">
        select id,
               outhospno,
               campusid,
               server_state,
               diagcheck_flag,
               patno,
               remark,
               fudate,
               fuflag,
               serialnum,
               patid,
               hospitalname,
               hospitalcode,
               icd10code,
               diagname,
               deptcode,
               deptname,
               drcode,
               drname,
               admitdate,
               orgid,
               del_flag,
               guid,
               update_by,
               update_time,
               create_by,
               create_time,
               isupload,
               upload_time,
               schemestatus,
               deptid,
               schemetime,
               hpi,
               patname,
               mainsuit
        from pat_med_outhosp
    </sql>
<!--    <sql id="selectPatMedOuthospVo">-->
<!--        select id,-->
<!--               outhospno,-->
<!--               campusid,-->
<!--               server_state,-->
<!--               diagcheck_flag,-->
<!--               patno,-->
<!--               remark,-->
<!--               fudate,-->
<!--               fuflag,-->
<!--               serialnum,-->
<!--               patid,-->
<!--               hospitalname,-->
<!--               hospitalcode,-->
<!--               icd10code,-->
<!--               diagname,-->
<!--               deptcode,-->
<!--               deptname,-->
<!--               drcode,-->
<!--               drname,-->
<!--               admitdate,-->
<!--               orgid,-->
<!--               del_flag,-->
<!--               guid,-->
<!--               update_by,-->
<!--               update_time,-->
<!--               create_by,-->
<!--               create_time,-->
<!--               isupload,-->
<!--               upload_time,-->
<!--               schemestatus,-->
<!--               deptid,-->
<!--               schemetime,-->
<!--               hpi,-->
<!--               patname,-->
<!--               mainsuit-->
<!--        from pat_med_outhosp-->
<!--    </sql>-->
    <select id="selectPatMedOuthospList" parameterType="com.smartor.domain.PatMedOuthosp"
            resultMap="PatMedOuthospResult">
        select
        pmo.id,
        pmo.outhospno,
        pmo.patno,
        pmo.serialnum,
        pmo.patid,
        pmo.icd10code,
        pmo.diagname,
        pmo.deptcode,
        pmo.deptname,
        pmo.drcode,
        pmo.drname,
        pmo.admitdate,
        pmo.schemestatus,
        pmo.deptid,
        pmo.schemetime,
        pmo.fuflag,
        pmo.patname,
        pmo.update_time,
        pmo.mainsuit
        from pat_med_outhosp pmo
        <where>pmo.del_flag='0'
            <if test="orgid != null ">and pmo.orgid = #{orgid}</if>
            <if test="serialnum != null ">and pmo.serialnum = #{serialnum}</if>
            <if test="serverState != null ">and pmo.server_state = #{serverState}</if>
            <if test="hospitalname != null  and hospitalname != ''">and pmo.hospitalname like concat('%',
                #{hospitalname},
                '%')
            </if>
            <if test="deptcodes != null and deptcodes.size()>0">
                AND pmo.deptcode IN
                <foreach collection="deptcodes" item="deptcode" open="(" separator=","
                         close=")">
                    #{deptcode}
                </foreach>
            </if>
            <if test="deptname != null  and deptname != ''">and pmo.deptname like concat('%', #{deptname}, '%')</if>
            <if test="drname != null  and drname != ''">and pmo.drname like concat('%', #{drname}, '%')</if>
            <if test="patname != null  and patname != ''">and pmo.patname like concat('%', #{patname}, '%')</if>
            <if test="beginTime != null ">and date_format(pmo.admitdate,'%y%m%d') &gt;=
                date_format(#{beginTime},'%y%m%d')
            </if>
            <if test="endTime != null ">and date_format(pmo.admitdate,'%y%m%d') &lt;=
                date_format(#{endTime},'%y%m%d')
            </if>
            <if test="patid != null ">and pmo.patid = #{patid}</if>
            <if test="campusid != null ">and pmo.campusid = #{campusid}</if>
            <if test="fuflag != null ">and pmo.fuflag = #{fuflag}</if>
            <if test="patno != null ">and pmo.patno = #{patno}</if>
            <if test="outhospno != null  and outhospno != ''">and pmo.outhospno = #{outhospno}</if>
            <if test="diagcheckFlag != null  and diagcheckFlag != ''">and pmo.diagcheck_flag = #{diagcheckFlag}</if>
            <if test="diagname != null  and diagname != ''">and pmo.diagname like concat('%',#{diagname}, '%')</if>
        </where>
        order by pmo.update_time desc
        <if test="pageSize != null  and pageNum != null">limit ${pageSize} OFFSET ${pageNum}</if>
    </select>
    <!--    <select id="selectPatMedOuthospList" parameterType="com.smartor.domain.PatMedOuthosp"-->
    <!--            resultMap="PatMedOuthospResult">-->
    <!--        select-->
    <!--        pmo.id,-->
    <!--        pmo.outhospno,-->
    <!--        pmo.patno,-->
    <!--        pmo.serialnum,-->
    <!--        pmo.patid,-->
    <!--        pmo.icd10code,-->
    <!--        pmo.diagname,-->
    <!--        pmo.deptcode,-->
    <!--        pmo.deptname,-->
    <!--        pmo.drcode,-->
    <!--        pmo.drname,-->
    <!--        pmo.admitdate,-->
    <!--        pmo.schemestatus,-->
    <!--        pmo.deptid,-->
    <!--        pmo.schemetime,-->
    <!--        pmo.fuflag,-->
    <!--        pmo.patname,-->
    <!--        pmo.update_time,-->
    <!--        pmo.mainsuit-->
    <!--        from pat_med_outhosp pmo-->
    <!--        <where>pmo.del_flag='0'-->
    <!--            <if test="orgid != null ">and pmo.orgid = #{orgid}</if>-->
    <!--            <if test="serialnum != null ">and pmo.serialnum = #{serialnum}</if>-->
    <!--            <if test="serverState != null ">and pmo.server_state = #{serverState}</if>-->
    <!--            <if test="hospitalname != null  and hospitalname != ''">and pmo.hospitalname like concat('%',-->
    <!--                #{hospitalname},-->
    <!--                '%')-->
    <!--            </if>-->
    <!--            <if test="deptcodes != null and deptcodes.size()>0">-->
    <!--                AND pmo.deptcode IN-->
    <!--                <foreach collection="deptcodes" item="deptcode" open="(" separator=","-->
    <!--                         close=")">-->
    <!--                    #{deptcode}-->
    <!--                </foreach>-->
    <!--            </if>-->
    <!--            <if test="deptname != null  and deptname != ''">and pmo.deptname like concat('%', #{deptname}, '%')</if>-->
    <!--            <if test="drname != null  and drname != ''">and pmo.drname like concat('%', #{drname}, '%')</if>-->
    <!--            <if test="patname != null  and patname != ''">and pmo.patname like concat('%', #{patname}, '%')</if>-->
    <!--            <if test="beginTime != null ">and date_format(pmo.admitdate,'%y%m%d') &gt;=-->
    <!--                date_format(#{beginTime},'%y%m%d')-->
    <!--            </if>-->
    <!--            <if test="endTime != null ">and date_format(pmo.admitdate,'%y%m%d') &lt;=-->
    <!--                date_format(#{endTime},'%y%m%d')-->
    <!--            </if>-->
    <!--            <if test="patid != null ">and pmo.patid = #{patid}</if>-->
    <!--            <if test="campusid != null ">and pmo.campusid = #{campusid}</if>-->
    <!--            <if test="fuflag != null ">and pmo.fuflag = #{fuflag}</if>-->
    <!--            <if test="patno != null ">and pmo.patno = #{patno}</if>-->
    <!--            <if test="outhospno != null  and outhospno != ''">and pmo.outhospno = #{outhospno}</if>-->
    <!--            <if test="diagcheckFlag != null  and diagcheckFlag != ''">and pmo.diagcheck_flag = #{diagcheckFlag}</if>-->
    <!--            <if test="diagname != null  and diagname != ''">and pmo.diagname like concat('%',#{diagname}, '%')</if>-->
    <!--        </where>-->
    <!--        order by pmo.update_time desc-->
    <!--        <if test="pageSize != null  and pageNum != null">limit ${pageSize} OFFSET ${pageNum}</if>-->
    <!--    </select>-->
    <select id="selectPatMedOuthospById" parameterType="Long" resultMap="PatMedOuthospResult">
        <include refid="selectPatMedOuthospVo"/>
        where id = #{id}
    </select>
    <insert id="insertPatMedOuthosp" parameterType="com.smartor.domain.PatMedOuthosp" useGeneratedKeys="true"
            keyProperty="id">
        insert into pat_med_outhosp
    <!--    <insert id="insertPatMedOuthosp" parameterType="com.smartor.domain.PatMedOuthosp" useGeneratedKeys="true"-->
    <!--            keyProperty="id">-->
    <!--        insert into pat_med_outhosp-->
    <!--        <trim prefix="(" suffix=")" suffixOverrides=",">-->
    <!--            <if test="serialnum != null">serialnum,</if>-->
    <!--            <if test="patid != null">patid,</if>-->
    <!--            <if test="hospitalname != null">hospitalname,</if>-->
    <!--            <if test="hospitalcode != null">hospitalcode,</if>-->
    <!--            <if test="icd10code != null">icd10code,</if>-->
    <!--            <if test="diagname != null">diagname,</if>-->
    <!--            <if test="deptcode != null">deptcode,</if>-->
    <!--            <if test="deptname != null">deptname,</if>-->
    <!--            <if test="drcode != null">drcode,</if>-->
    <!--            <if test="drname != null">drname,</if>-->
    <!--            <if test="admitdate != null">admitdate,</if>-->
    <!--            <if test="orgid != null">orgid,</if>-->
    <!--            <if test="delFlag != null and delFlag != ''">del_flag,</if>-->
    <!--            <if test="updateBy != null">update_by,</if>-->
    <!--            <if test="updateTime != null">update_time,</if>-->
    <!--            <if test="createBy != null">create_by,</if>-->
    <!--            <if test="createTime != null">create_time,</if>-->
    <!--            <if test="isupload != null">isupload,</if>-->
    <!--            <if test="uploadTime != null">upload_time,</if>-->
    <!--            <if test="schemestatus != null">schemestatus,</if>-->
    <!--            <if test="deptid != null">deptid,</if>-->
    <!--            <if test="schemetime != null">schemetime,</if>-->
    <!--            <if test="hpi != null">hpi,</if>-->
    <!--            <if test="mainsuit != null">mainsuit,</if>-->
    <!--            <if test="outhospno != null">outhospno,</if>-->
    <!--            <if test="patname != null">patname,</if>-->
    <!--            <if test="guid != null">guid,</if>-->
    <!--            <if test="patno != null">patno,</if>-->
    <!--            <if test="diagcheckFlag != null">diagcheck_flag,</if>-->
    <!--            <if test="remark != null">remark,</if>-->
    <!--            <if test="fuflag != null">fuflag,</if>-->
    <!--            <if test="fudate != null">fudate,</if>-->
    <!--            <if test="campusid != null">campusid,</if>-->
    <!--            <if test="serverState != null">server_state,</if>-->
    <!--        </trim>-->
    <!--        <trim prefix="values (" suffix=")" suffixOverrides=",">-->
    <!--            <if test="serialnum != null">#{serialnum},</if>-->
    <!--            <if test="patid != null">#{patid},</if>-->
    <!--            <if test="hospitalname != null">#{hospitalname},</if>-->
    <!--            <if test="hospitalcode != null">#{hospitalcode},</if>-->
    <!--            <if test="icd10code != null">#{icd10code},</if>-->
    <!--            <if test="diagname != null">#{diagname},</if>-->
    <!--            <if test="deptcode != null">#{deptcode},</if>-->
    <!--            <if test="deptname != null">#{deptname},</if>-->
    <!--            <if test="drcode != null">#{drcode},</if>-->
    <!--            <if test="drname != null">#{drname},</if>-->
    <!--            <if test="admitdate != null">#{admitdate},</if>-->
    <!--            <if test="orgid != null">#{orgid},</if>-->
    <!--            <if test="delFlag != null and delFlag != ''">#{delFlag},</if>-->
    <!--            <if test="updateBy != null">#{updateBy},</if>-->
    <!--            <if test="updateTime != null">#{updateTime},</if>-->
    <!--            <if test="createBy != null">#{createBy},</if>-->
    <!--            <if test="createTime != null">#{createTime},</if>-->
    <!--            <if test="isupload != null">#{isupload},</if>-->
    <!--            <if test="uploadTime != null">#{uploadTime},</if>-->
    <!--            <if test="schemestatus != null">#{schemestatus},</if>-->
    <!--            <if test="deptid != null">#{deptid},</if>-->
    <!--            <if test="schemetime != null">#{schemetime},</if>-->
    <!--            <if test="hpi != null">#{hpi},</if>-->
    <!--            <if test="mainsuit != null">#{mainsuit},</if>-->
    <!--            <if test="outhospno != null">#{outhospno},</if>-->
    <!--            <if test="patname != null">#{patname},</if>-->
    <!--            <if test="guid != null">#{guid},</if>-->
    <!--            <if test="patno != null">#{patno},</if>-->
    <!--            <if test="diagcheckFlag != null">#{diagcheckFlag},</if>-->
    <!--            <if test="remark != null">#{remark},</if>-->
    <!--            <if test="fuflag != null">#{fuflag},</if>-->
    <!--            <if test="fudate != null">#{fudate},</if>-->
    <!--            <if test="campusid != null">#{campusid},</if>-->
    <!--            <if test="serverState != null">#{serverState},</if>-->
    <!--        </trim>-->
    <!--    </insert>-->
    <!-- æ–°å¢žåˆ°åŠ¨æ€è¡¨åï¼ˆç”¨äºŽè·¯ç”±åˆ°æœ€æ–°åˆ†è¡¨ï¼‰ -->
    <insert id="insertIntoTable" parameterType="map" useGeneratedKeys="true" keyProperty="record.id">
        insert into ${tableName}
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="serialnum != null">serialnum,</if>
            <if test="patid != null">patid,</if>
            <if test="hospitalname != null">hospitalname,</if>
            <if test="hospitalcode != null">hospitalcode,</if>
            <if test="icd10code != null">icd10code,</if>
            <if test="diagname != null">diagname,</if>
            <if test="deptcode != null">deptcode,</if>
            <if test="deptname != null">deptname,</if>
            <if test="drcode != null">drcode,</if>
            <if test="drname != null">drname,</if>
            <if test="admitdate != null">admitdate,</if>
            <if test="orgid != null">orgid,</if>
            <if test="delFlag != null and delFlag != ''">del_flag,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="isupload != null">isupload,</if>
            <if test="uploadTime != null">upload_time,</if>
            <if test="schemestatus != null">schemestatus,</if>
            <if test="deptid != null">deptid,</if>
            <if test="schemetime != null">schemetime,</if>
            <if test="hpi != null">hpi,</if>
            <if test="mainsuit != null">mainsuit,</if>
            <if test="outhospno != null">outhospno,</if>
            <if test="patname != null">patname,</if>
            <if test="guid != null">guid,</if>
            <if test="patno != null">patno,</if>
            <if test="diagcheckFlag != null">diagcheck_flag,</if>
            <if test="remark != null">remark,</if>
            <if test="fuflag != null">fuflag,</if>
            <if test="fudate != null">fudate,</if>
            <if test="campusid != null">campusid,</if>
            <if test="serverState != null">server_state,</if>
            <if test="record.serialnum != null">serialnum,</if>
            <if test="record.patid != null">patid,</if>
            <if test="record.hospitalname != null">hospitalname,</if>
            <if test="record.hospitalcode != null">hospitalcode,</if>
            <if test="record.icd10code != null">icd10code,</if>
            <if test="record.diagname != null">diagname,</if>
            <if test="record.deptcode != null">deptcode,</if>
            <if test="record.deptname != null">deptname,</if>
            <if test="record.drcode != null">drcode,</if>
            <if test="record.drname != null">drname,</if>
            <if test="record.admitdate != null">admitdate,</if>
            <if test="record.orgid != null">orgid,</if>
            <if test="record.delFlag != null and record.delFlag != ''">del_flag,</if>
            <if test="record.updateBy != null">update_by,</if>
            <if test="record.updateTime != null">update_time,</if>
            <if test="record.createBy != null">create_by,</if>
            <if test="record.createTime != null">create_time,</if>
            <if test="record.isupload != null">isupload,</if>
            <if test="record.uploadTime != null">upload_time,</if>
            <if test="record.schemestatus != null">schemestatus,</if>
            <if test="record.deptid != null">deptid,</if>
            <if test="record.schemetime != null">schemetime,</if>
            <if test="record.hpi != null">hpi,</if>
            <if test="record.mainsuit != null">mainsuit,</if>
            <if test="record.outhospno != null">outhospno,</if>
            <if test="record.patname != null">patname,</if>
            <if test="record.guid != null">guid,</if>
            <if test="record.patno != null">patno,</if>
            <if test="record.diagcheckFlag != null">diagcheck_flag,</if>
            <if test="record.remark != null">remark,</if>
            <if test="record.fuflag != null">fuflag,</if>
            <if test="record.fudate != null">fudate,</if>
            <if test="record.campusid != null">campusid,</if>
            <if test="record.serverState != null">server_state,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="serialnum != null">#{serialnum},</if>
            <if test="patid != null">#{patid},</if>
            <if test="hospitalname != null">#{hospitalname},</if>
            <if test="hospitalcode != null">#{hospitalcode},</if>
            <if test="icd10code != null">#{icd10code},</if>
            <if test="diagname != null">#{diagname},</if>
            <if test="deptcode != null">#{deptcode},</if>
            <if test="deptname != null">#{deptname},</if>
            <if test="drcode != null">#{drcode},</if>
            <if test="drname != null">#{drname},</if>
            <if test="admitdate != null">#{admitdate},</if>
            <if test="orgid != null">#{orgid},</if>
            <if test="delFlag != null and delFlag != ''">#{delFlag},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="isupload != null">#{isupload},</if>
            <if test="uploadTime != null">#{uploadTime},</if>
            <if test="schemestatus != null">#{schemestatus},</if>
            <if test="deptid != null">#{deptid},</if>
            <if test="schemetime != null">#{schemetime},</if>
            <if test="hpi != null">#{hpi},</if>
            <if test="mainsuit != null">#{mainsuit},</if>
            <if test="outhospno != null">#{outhospno},</if>
            <if test="patname != null">#{patname},</if>
            <if test="guid != null">#{guid},</if>
            <if test="patno != null">#{patno},</if>
            <if test="diagcheckFlag != null">#{diagcheckFlag},</if>
            <if test="remark != null">#{remark},</if>
            <if test="fuflag != null">#{fuflag},</if>
            <if test="fudate != null">#{fudate},</if>
            <if test="campusid != null">#{campusid},</if>
            <if test="serverState != null">#{serverState},</if>
            <if test="record.serialnum != null">#{record.serialnum},</if>
            <if test="record.patid != null">#{record.patid},</if>
            <if test="record.hospitalname != null">#{record.hospitalname},</if>
            <if test="record.hospitalcode != null">#{record.hospitalcode},</if>
            <if test="record.icd10code != null">#{record.icd10code},</if>
            <if test="record.diagname != null">#{record.diagname},</if>
            <if test="record.deptcode != null">#{record.deptcode},</if>
            <if test="record.deptname != null">#{record.deptname},</if>
            <if test="record.drcode != null">#{record.drcode},</if>
            <if test="record.drname != null">#{record.drname},</if>
            <if test="record.admitdate != null">#{record.admitdate},</if>
            <if test="record.orgid != null">#{record.orgid},</if>
            <if test="record.delFlag != null and record.delFlag != ''">#{record.delFlag},</if>
            <if test="record.updateBy != null">#{record.updateBy},</if>
            <if test="record.updateTime != null">#{record.updateTime},</if>
            <if test="record.createBy != null">#{record.createBy},</if>
            <if test="record.createTime != null">#{record.createTime},</if>
            <if test="record.isupload != null">#{record.isupload},</if>
            <if test="record.uploadTime != null">#{record.uploadTime},</if>
            <if test="record.schemestatus != null">#{record.schemestatus},</if>
            <if test="record.deptid != null">#{record.deptid},</if>
            <if test="record.schemetime != null">#{record.schemetime},</if>
            <if test="record.hpi != null">#{record.hpi},</if>
            <if test="record.mainsuit != null">#{record.mainsuit},</if>
            <if test="record.outhospno != null">#{record.outhospno},</if>
            <if test="record.patname != null">#{record.patname},</if>
            <if test="record.guid != null">#{record.guid},</if>
            <if test="record.patno != null">#{record.patno},</if>
            <if test="record.diagcheckFlag != null">#{record.diagcheckFlag},</if>
            <if test="record.remark != null">#{record.remark},</if>
            <if test="record.fuflag != null">#{record.fuflag},</if>
            <if test="record.fudate != null">#{record.fudate},</if>
            <if test="record.campusid != null">#{record.campusid},</if>
            <if test="record.serverState != null">#{record.serverState},</if>
        </trim>
    </insert>
    <insert id="batchPatMedOuthosp">
        insert into pat_med_outhosp
        (
        serialnum,
        patid,
        hospitalname,
        hospitalcode,
        icd10code,
        diagname,
        deptcode,
        deptname,
        drcode,
        drname,
        admitdate,
        orgid,
        del_flag,
        update_by,
        update_time,
        create_by,
        create_time,
        isupload,
        upload_time,
        schemestatus,
        deptid,
        schemetime,
        hpi,
        mainsuit,
        outhospno,
        patname,
        guid,
        patno,
        diagcheck_flag,
        fuflag,
        fudate,
        campusid,
        server_state,
        remark)
        values
        <foreach collection="list" item="item" separator=",">
            (
            #{item.serialnum},
            #{item.patid},
            #{item.hospitalname},
            #{item.hospitalcode},
            #{item.icd10code},
            #{item.diagname},
            #{item.deptcode},
            #{item.deptname},
            #{item.drcode},
            #{item.drname},
            #{item.admitdate},
            #{item.orgid},
            #{item.delFlag},
            #{item.updateBy},
            #{item.updateTime},
            #{item.createBy},
            #{item.createTime},
            #{item.isupload},
            #{item.uploadTime},
            #{item.schemestatus},
            #{item.deptid},
            #{item.schemetime},
            #{item.hpi},
            #{item.mainsuit},
            #{item.outhospno},
            #{item.patname},
            #{item.guid},
            #{item.patno},
            #{item.diagcheckFlag},
            #{item.fuflag},
            #{item.fudate},
            #{item.campusid},
            #{item.serverState},
            #{item.remark}
            )
        </foreach>
    </insert>
    <insert id="batchInsertIgnore">
        insert ignore into pat_med_outhosp
        (
        serialnum,
        patid,
        hospitalname,
        hospitalcode,
        icd10code,
        diagname,
        deptcode,
        deptname,
        drcode,
        drname,
        admitdate,
        orgid,
        del_flag,
        update_by,
        update_time,
        create_by,
        create_time,
        isupload,
        upload_time,
        schemestatus,
        deptid,
        schemetime,
        hpi,
        mainsuit,
        outhospno,
        patname,
        guid,
        patno,
        diagcheck_flag,
        fuflag,
        fudate,
        campusid,
        server_state,
        remark)
        values
        <foreach collection="list" item="item" separator=",">
            (
            #{item.serialnum},
            #{item.patid},
            #{item.hospitalname},
            #{item.hospitalcode},
            #{item.icd10code},
            #{item.diagname},
            #{item.deptcode},
            #{item.deptname},
            #{item.drcode},
            #{item.drname},
            #{item.admitdate},
            #{item.orgid},
            #{item.delFlag},
            #{item.updateBy},
            #{item.updateTime},
            #{item.createBy},
            #{item.createTime},
            #{item.isupload},
            #{item.uploadTime},
            #{item.schemestatus},
            #{item.deptid},
            #{item.schemetime},
            #{item.hpi},
            #{item.mainsuit},
            #{item.outhospno},
            #{item.patname},
            #{item.guid},
            #{item.patno},
            #{item.diagcheckFlag},
            #{item.fuflag},
            #{item.fudate},
            #{item.campusid},
            #{item.serverState},
            #{item.remark}
            )
        </foreach>
    </insert>
    <update id="updatePatMedOuthosp" parameterType="com.smartor.domain.PatMedOuthosp">
        update pat_med_outhosp
        <trim prefix="SET" suffixOverrides=",">
            <if test="serialnum != null">serialnum = #{serialnum},</if>
            <if test="patid != null">patid = #{patid},</if>
            <if test="hospitalname != null">hospitalname = #{hospitalname},</if>
            <if test="hospitalcode != null">hospitalcode = #{hospitalcode},</if>
            <if test="icd10code != null">icd10code = #{icd10code},</if>
            <if test="diagname != null">diagname = #{diagname},</if>
            <if test="deptcode != null">deptcode = #{deptcode},</if>
            <if test="deptname != null">deptname = #{deptname},</if>
            <if test="drcode != null">drcode = #{drcode},</if>
            <if test="drname != null">drname = #{drname},</if>
            <if test="admitdate != null">admitdate = #{admitdate},</if>
            <if test="orgid != null">orgid = #{orgid},</if>
            <if test="delFlag != null and delFlag != ''">del_flag = #{delFlag},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="isupload != null">isupload = #{isupload},</if>
            <if test="uploadTime != null">upload_time = #{uploadTime},</if>
            <if test="schemestatus != null">schemestatus = #{schemestatus},</if>
            <if test="deptid != null">deptid = #{deptid},</if>
            <if test="schemetime != null">schemetime = #{schemetime},</if>
            <if test="hpi != null">hpi = #{hpi},</if>
            <if test="mainsuit != null">mainsuit = #{mainsuit},</if>
            <if test="outhospno != null">outhospno = #{outhospno},</if>
            <if test="patname != null">patname = #{patname},</if>
            <if test="guid != null">guid = #{guid},</if>
            <if test="patno != null">patno = #{patno},</if>
            <if test="diagcheckFlag != null">diagcheck_flag = #{diagcheckFlag},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="fuflag != null">fuflag = #{fuflag},</if>
            <if test="fudate != null">fudate = #{fudate},</if>
            <if test="campusid != null">campusid = #{campusid},</if>
            <if test="serverState != null">server_state = #{serverState},</if>
        </trim>
        where id = #{id}
    <!--    <update id="updatePatMedOuthosp" parameterType="com.smartor.domain.PatMedOuthosp">-->
    <!--        update pat_med_outhosp-->
    <!--        <trim prefix="SET" suffixOverrides=",">-->
    <!--            <if test="serialnum != null">serialnum = #{serialnum},</if>-->
    <!--            <if test="patid != null">patid = #{patid},</if>-->
    <!--            <if test="hospitalname != null">hospitalname = #{hospitalname},</if>-->
    <!--            <if test="hospitalcode != null">hospitalcode = #{hospitalcode},</if>-->
    <!--            <if test="icd10code != null">icd10code = #{icd10code},</if>-->
    <!--            <if test="diagname != null">diagname = #{diagname},</if>-->
    <!--            <if test="deptcode != null">deptcode = #{deptcode},</if>-->
    <!--            <if test="deptname != null">deptname = #{deptname},</if>-->
    <!--            <if test="drcode != null">drcode = #{drcode},</if>-->
    <!--            <if test="drname != null">drname = #{drname},</if>-->
    <!--            <if test="admitdate != null">admitdate = #{admitdate},</if>-->
    <!--            <if test="orgid != null">orgid = #{orgid},</if>-->
    <!--            <if test="delFlag != null and delFlag != ''">del_flag = #{delFlag},</if>-->
    <!--            <if test="updateBy != null">update_by = #{updateBy},</if>-->
    <!--            <if test="updateTime != null">update_time = #{updateTime},</if>-->
    <!--            <if test="createBy != null">create_by = #{createBy},</if>-->
    <!--            <if test="createTime != null">create_time = #{createTime},</if>-->
    <!--            <if test="isupload != null">isupload = #{isupload},</if>-->
    <!--            <if test="uploadTime != null">upload_time = #{uploadTime},</if>-->
    <!--            <if test="schemestatus != null">schemestatus = #{schemestatus},</if>-->
    <!--            <if test="deptid != null">deptid = #{deptid},</if>-->
    <!--            <if test="schemetime != null">schemetime = #{schemetime},</if>-->
    <!--            <if test="hpi != null">hpi = #{hpi},</if>-->
    <!--            <if test="mainsuit != null">mainsuit = #{mainsuit},</if>-->
    <!--            <if test="outhospno != null">outhospno = #{outhospno},</if>-->
    <!--            <if test="patname != null">patname = #{patname},</if>-->
    <!--            <if test="guid != null">guid = #{guid},</if>-->
    <!--            <if test="patno != null">patno = #{patno},</if>-->
    <!--            <if test="diagcheckFlag != null">diagcheck_flag = #{diagcheckFlag},</if>-->
    <!--            <if test="remark != null">remark = #{remark},</if>-->
    <!--            <if test="fuflag != null">fuflag = #{fuflag},</if>-->
    <!--            <if test="fudate != null">fudate = #{fudate},</if>-->
    <!--            <if test="campusid != null">campusid = #{campusid},</if>-->
    <!--            <if test="serverState != null">server_state = #{serverState},</if>-->
    <!--        </trim>-->
    <!--        where id = #{id}-->
    <!--    </update>-->
    <select id="getTableColumns" resultType="String">
        SELECT column_name
        FROM information_schema.columns
        WHERE table_schema = DATABASE()
          AND table_name = #{tableName}
        ORDER BY ordinal_position
    </select>
    <select id="getTableColumnMeta" resultType="java.util.HashMap">
        SELECT column_name AS column_name,
               data_type   AS data_type,
               column_type AS column_type
        FROM information_schema.columns
        WHERE table_schema = DATABASE()
          AND table_name = #{tableName}
        ORDER BY ordinal_position
    </select>
    <update id="createOrReplaceProcedure">
        ${procSql}
    </update>
    <delete id="deletePatMedOuthospById" parameterType="Long">
        delete
        from pat_med_outhosp
        where id = #{id}
    </delete>
    <delete id="deletePatMedOuthospByIds" parameterType="String">
        delete from pat_med_outhosp where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <select id="selectPatMedOuthospCount" parameterType="com.smartor.domain.PatMedReq"
            resultType="com.smartor.domain.PatMedRes">
        SELECT SUM( rs ) AS rs,
        SUM( rc ) AS rc
        FROM (
        SELECT
        COUNT(id) AS rc,
        0 AS rs
        FROM
        pat_med_outhosp
        where 1=1
        and del_flag = 0
        <if test="orgid != null">
            and orgid = #{orgid}
        </if>
        and date_format(admitdate,'%y%m%d') &gt;= date_format(#{startDate},'%y%m%d')
        and date_format(admitdate,'%y%m%d') &lt;= date_format(#{endDate},'%y%m%d')
        <if test="deptcodeList != null and deptcodeList.size()>0">
            and deptcode in
            <foreach collection="deptcodeList" item="deptcode" open="(" separator="," close=")">
                #{deptcode}
            </foreach>
        </if>
        union all
        select
        0 AS rc,
        count(1) AS rs
        FROM
        service_subtask
        where 1=1
        and del_flag = 0
        and service_type=3
        <if test="orgid != null">
            and orgid = #{orgid}
        </if>
        <if test="startDate != null">
            AND date_format( visit_time, '%y%m%d' ) &gt;= date_format( #{startDate}, '%y%m%d' )
        </if>
        <if test="endDate != null">
            AND date_format( visit_time, '%y%m%d' ) &lt;= date_format(#{endDate},'%y%m%d')
        </if>
        <if test="deptcodeList != null and deptcodeList.size()>0">
            and deptcode in
            <foreach collection="deptcodeList" item="deptcode" open="(" separator="," close=")">
                #{deptcode}
            </foreach>
        </if>
        ) AS combined_data
    <!-- è°ƒç”¨å­˜å‚¨è¿‡ç¨‹ sp_query_outhosp æŸ¥è¯¢é—¨è¯Šè®°å½• -->
    <select id="callSpQueryOuthosp" parameterType="com.smartor.domain.PatMedOuthospQueryReq"
            resultType="com.smartor.domain.PatMedOuthosp"
            statementType="CALLABLE">
        {CALL sp_query_outhosp(
                #{outhospno,     jdbcType=VARCHAR,  mode=IN},
                #{serialnum,     jdbcType=VARCHAR,  mode=IN},
                #{patid,         jdbcType=BIGINT,   mode=IN},
                #{patname,       jdbcType=VARCHAR,  mode=IN},
                #{patno,        jdbcType=VARCHAR,  mode=IN},
                #{hospitalname,  jdbcType=VARCHAR,  mode=IN},
                #{hospitalcode,  jdbcType=VARCHAR,  mode=IN},
                #{icd10code,     jdbcType=VARCHAR,  mode=IN},
                #{diagname,      jdbcType=VARCHAR,  mode=IN},
                #{deptid,        jdbcType=BIGINT,   mode=IN},
                #{deptcode,      jdbcType=VARCHAR,  mode=IN},
                #{deptname,      jdbcType=VARCHAR,  mode=IN},
                #{drcode,        jdbcType=VARCHAR,  mode=IN},
                #{drname,        jdbcType=VARCHAR,  mode=IN},
                #{beginAdmitdate,jdbcType=DATE,     mode=IN},
                #{endAdmitdate,  jdbcType=DATE,     mode=IN},
                #{orgid,         jdbcType=VARCHAR,  mode=IN},
                #{isupload,      jdbcType=BIGINT,   mode=IN},
                #{schemestatus,  jdbcType=BIGINT,   mode=IN},
                #{hpi,         jdbcType=VARCHAR,  mode=IN},
                #{mainsuit,         jdbcType=VARCHAR,  mode=IN},
                #{pid,   jdbcType=INTEGER,  mode=IN},
                #{guid, jdbcType=VARCHAR,  mode=IN},
                #{pguid, jdbcType=VARCHAR,  mode=IN},
                #{hospitaldistrictcode,   jdbcType=VARCHAR,  mode=IN},
                #{hospitaldistrictname,   jdbcType=VARCHAR,  mode=IN},
                #{diagcheckFlag,          jdbcType=VARCHAR,  mode=IN},
                #{fuflag,          jdbcType=VARCHAR,  mode=IN},
                #{campusid,          jdbcType=VARCHAR,  mode=IN},
                #{serverState,      jdbcType=VARCHAR,  mode=IN}
                #{pageSize,      jdbcType=INTEGER,  mode=IN},
                #{pageNum,       jdbcType=INTEGER,  mode=IN}
            )}
    </select>
    <select id="getDeptRanking" parameterType="com.smartor.domain.PatMedReq" resultType="com.smartor.domain.PatMedRes">
        SELECT deptname, COUNT(1) AS rc
        FROM pat_med_outhosp
        where 1=1
        and del_flag = 0
        <if test="orgid != null  and orgid != ''">
            and orgid = #{orgid}
        </if>
        <if test="inhospstate != null">
            and inhospstate= #{inhospstate}
        </if>
        <if test="serverState != null">
            and server_state= #{inhospstate}
        </if>
        <if test="deptcodeList != null and deptcodeList.size()>0">
            and deptcode in
            <foreach collection="deptcodeList" item="deptcode" open="(" separator="," close=")">
                #{deptcode}
            </foreach>
        </if>
    <select id="callSpQueryOuthospCount" parameterType="com.smartor.domain.PatMedOuthospQueryReq"
            resultType="Long"
            statementType="CALLABLE">
        {CALL sp_count_outhosp(
                #{outhospno,     jdbcType=VARCHAR,  mode=IN},
                #{serialnum,     jdbcType=VARCHAR,  mode=IN},
                #{patid,         jdbcType=BIGINT,   mode=IN},
                #{patname,       jdbcType=VARCHAR,  mode=IN},
                #{patno,        jdbcType=VARCHAR,  mode=IN},
                #{hospitalname,  jdbcType=VARCHAR,  mode=IN},
                #{hospitalcode,  jdbcType=VARCHAR,  mode=IN},
                #{icd10code,     jdbcType=VARCHAR,  mode=IN},
                #{diagname,      jdbcType=VARCHAR,  mode=IN},
                #{deptid,        jdbcType=BIGINT,   mode=IN},
                #{deptcode,      jdbcType=VARCHAR,  mode=IN},
                #{deptname,      jdbcType=VARCHAR,  mode=IN},
                #{drcode,        jdbcType=VARCHAR,  mode=IN},
                #{drname,        jdbcType=VARCHAR,  mode=IN},
                #{beginAdmitdate,jdbcType=DATE,     mode=IN},
                #{endAdmitdate,  jdbcType=DATE,     mode=IN},
                #{orgid,         jdbcType=VARCHAR,  mode=IN},
                #{isupload,      jdbcType=BIGINT,   mode=IN},
                #{schemestatus,  jdbcType=BIGINT,   mode=IN},
                #{hpi,         jdbcType=VARCHAR,  mode=IN},
                #{mainsuit,         jdbcType=VARCHAR,  mode=IN},
                #{pid,   jdbcType=INTEGER,  mode=IN},
                #{guid, jdbcType=VARCHAR,  mode=IN},
                #{pguid, jdbcType=VARCHAR,  mode=IN},
                #{hospitaldistrictcode,   jdbcType=VARCHAR,  mode=IN},
                #{hospitaldistrictname,   jdbcType=VARCHAR,  mode=IN},
                #{diagcheckFlag,          jdbcType=VARCHAR,  mode=IN},
                #{fuflag,          jdbcType=VARCHAR,  mode=IN},
                #{campusid,          jdbcType=VARCHAR,  mode=IN},
                #{serverState,      jdbcType=VARCHAR,  mode=IN}
            )}
    </select>
    <!-- PatMedOuthospMapper.xml -->
    <select id="countPatMedOuthosp" resultType="int">
    <select id="existsInTable" resultType="int">
        SELECT COUNT(*)
        FROM pat_med_outhosp
        FROM ${tableName}
        WHERE id = #{id}
    </select>
    <update id="renameTable">
        RENAME
        TABLE
        ${oldName}
        TO
        ${newName}
    <update id="updateInTable" parameterType="map">
        update ${tableName}
        <trim prefix="SET" suffixOverrides=",">
            <if test="record.serialnum != null">serialnum = #{record.serialnum},</if>
            <if test="record.patid != null">patid = #{record.patid},</if>
            <if test="record.hospitalname != null">hospitalname = #{record.hospitalname},</if>
            <if test="record.hospitalcode != null">hospitalcode = #{record.hospitalcode},</if>
            <if test="record.icd10code != null">icd10code = #{record.icd10code},</if>
            <if test="record.diagname != null">diagname = #{record.diagname},</if>
            <if test="record.deptcode != null">deptcode = #{record.deptcode},</if>
            <if test="record.deptname != null">deptname = #{record.deptname},</if>
            <if test="record.drcode != null">drcode = #{record.drcode},</if>
            <if test="record.drname != null">drname = #{record.drname},</if>
            <if test="record.admitdate != null">admitdate = #{record.admitdate},</if>
            <if test="record.orgid != null">orgid = #{record.orgid},</if>
            <if test="record.delFlag != null and record.delFlag != ''">del_flag = #{record.delFlag},</if>
            <if test="record.updateBy != null">update_by = #{record.updateBy},</if>
            <if test="record.updateTime != null">update_time = #{record.updateTime},</if>
            <if test="record.createBy != null">create_by = #{record.createBy},</if>
            <if test="record.createTime != null">create_time = #{record.createTime},</if>
            <if test="record.isupload != null">isupload = #{record.isupload},</if>
            <if test="record.uploadTime != null">upload_time = #{record.uploadTime},</if>
            <if test="record.schemestatus != null">schemestatus = #{record.schemestatus},</if>
            <if test="record.deptid != null">deptid = #{record.deptid},</if>
            <if test="record.schemetime != null">schemetime = #{record.schemetime},</if>
            <if test="record.hpi != null">hpi = #{record.hpi},</if>
            <if test="record.mainsuit != null">mainsuit = #{record.mainsuit},</if>
            <if test="record.outhospno != null">outhospno = #{record.outhospno},</if>
            <if test="record.patname != null">patname = #{record.patname},</if>
            <if test="record.guid != null">guid = #{record.guid},</if>
            <if test="record.patno != null">patno = #{record.patno},</if>
            <if test="record.diagcheckFlag != null">diagcheck_flag = #{record.diagcheckFlag},</if>
            <if test="record.remark != null">remark = #{record.remark},</if>
            <if test="record.fuflag != null">fuflag = #{record.fuflag},</if>
            <if test="record.fudate != null">fudate = #{record.fudate},</if>
            <if test="record.campusid != null">campusid = #{record.campusid},</if>
            <if test="record.serverState != null">server_state = #{record.serverState},</if>
        </trim>
        <where>del_flag=0
            <if test="record.guid != null">and guid = #{record.guid}</if>
            <if test="record.serialnum != null">and serialnum = #{record.serialnum}</if>
        </where>
    </update>
    <select id="tableExists" resultType="int">
        SELECT COUNT(*)
        FROM information_schema.tables
        WHERE table_schema = DATABASE()
          AND table_name = #{tableName}
    </select>
    <update id="createPatMedOuthosp">
        CREATE TABLE ${newName} LIKE ${templateName}
@@ -538,14 +516,4 @@
        WHERE table_schema = DATABASE()
          AND table_name LIKE 'pat_med_outhosp%'
    </select>
    <select id="getMaxIdFromTable" resultType="Long">
        SELECT IFNULL(MAX(id), 0)
        FROM ${tableName}
    </select>
    <update id="createOrReplaceView">
        ${viewSql}
    </update>
</mapper>
smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml
@@ -1927,25 +1927,6 @@
            </foreach>
        </if>
        <!--        GROUP BY-->
        <!--        <choose>-->
        <!--            <when test="timeType == 'day'">-->
        <!--                DATE_FORMAT(visit_time, '%Y-%m-%d')-->
        <!--            </when>-->
        <!--            <when test="timeType == 'month'">-->
        <!--                DATE_FORMAT(visit_time, '%Y-%m')-->
        <!--            </when>-->
        <!--            <when test="timeType == 'year'">-->
        <!--                DATE_FORMAT(visit_time, '%Y')-->
        <!--            </when>-->
        <!--            <when test="timeType == 'week'">-->
        <!--                CONCAT(YEAR(visit_time), '-W', LPAD(WEEK(visit_time, 1), 2, '0'))-->
        <!--            </when>-->
        <!--            <otherwise>-->
        <!--                DATE_FORMAT(visit_time, '%Y-%m-%d')-->
        <!--            </otherwise>-->
        <!--        </choose>-->
        UNION ALL
        -- å‡ºé™¢äººæ¬¡æ•°æ®
@@ -1997,85 +1978,48 @@
            </foreach>
        </if>
        <!--        GROUP BY-->
        <!--        <choose>-->
        <!--            <when test="timeType == 'day'">-->
        <!--                DATE_FORMAT(endtime, '%Y-%m-%d')-->
        <!--            </when>-->
        <!--            <when test="timeType == 'month'">-->
        <!--                DATE_FORMAT(endtime, '%Y-%m')-->
        <!--            </when>-->
        <!--            <when test="timeType == 'year'">-->
        <!--                DATE_FORMAT(endtime, '%Y')-->
        <!--            </when>-->
        <!--            <when test="timeType == 'week'">-->
        <!--                CONCAT(YEAR(endtime), '-W', LPAD(WEEK(endtime, 1), 2, '0'))-->
        <!--            </when>-->
        <!--            <otherwise>-->
        <!--                DATE_FORMAT(endtime, '%Y-%m-%d')-->
        <!--            </otherwise>-->
        <!--        </choose>-->
<!--        UNION ALL-->
        UNION ALL
<!--        &#45;&#45; é—¨è¯Šäººæ¬¡æ•°æ®-->
<!--        SELECT-->
<!--        <choose>-->
<!--            <when test="timeType == 'day'">-->
<!--                DATE_FORMAT(admitdate, '%Y-%m-%d') AS timePeriod,-->
<!--            </when>-->
<!--            <when test="timeType == 'month'">-->
<!--                DATE_FORMAT(admitdate, '%Y-%m') AS timePeriod,-->
<!--            </when>-->
<!--            <when test="timeType == 'year'">-->
<!--                DATE_FORMAT(admitdate, '%Y') AS timePeriod,-->
<!--            </when>-->
<!--            <when test="timeType == 'week'">-->
<!--                CONCAT(YEAR(admitdate), '-W', LPAD(WEEK(admitdate, 1), 2, '0')) AS timePeriod,-->
<!--            </when>-->
<!--            <otherwise>-->
<!--                DATE_FORMAT(admitdate, '%Y-%m-%d') AS timePeriod,-->
<!--            </otherwise>-->
<!--        </choose>-->
<!--        0 AS dischargeFollowCount,-->
<!--        0 AS outpatientFollowCount,-->
<!--        0 AS pmiCount,-->
<!--        1 AS pmoCount-->
<!--        FROM pat_med_outhosp-->
<!--        WHERE del_flag = '0'-->
<!--        <if test="startDate != null and endDate != null">-->
<!--            AND admitdate >= #{startDate}-->
<!--            AND admitdate &lt;= DATE_ADD(#{endDate}, INTERVAL 1 DAY)-->
<!--        </if>-->
<!--        <if test="orgid != null">-->
<!--            AND orgid = #{orgid}-->
<!--        </if>-->
        -- é—¨è¯Šäººæ¬¡æ•°æ®
        SELECT
        <choose>
            <when test="timeType == 'day'">
                DATE_FORMAT(admitdate, '%Y-%m-%d') AS timePeriod,
            </when>
            <when test="timeType == 'month'">
                DATE_FORMAT(admitdate, '%Y-%m') AS timePeriod,
            </when>
            <when test="timeType == 'year'">
                DATE_FORMAT(admitdate, '%Y') AS timePeriod,
            </when>
            <when test="timeType == 'week'">
                CONCAT(YEAR(admitdate), '-W', LPAD(WEEK(admitdate, 1), 2, '0')) AS timePeriod,
            </when>
            <otherwise>
                DATE_FORMAT(admitdate, '%Y-%m-%d') AS timePeriod,
            </otherwise>
        </choose>
        0 AS dischargeFollowCount,
        0 AS outpatientFollowCount,
        0 AS pmiCount,
        1 AS pmoCount
        FROM pat_med_outhosp
        WHERE del_flag = '0'
        <if test="startDate != null and endDate != null">
            AND admitdate >= #{startDate}
            AND admitdate &lt;= DATE_ADD(#{endDate}, INTERVAL 1 DAY)
        </if>
        <if test="orgid != null">
            AND orgid = #{orgid}
        </if>
<!--        <if test="deptcodes != null and deptcodes.size() > 0">-->
<!--            AND deptcode IN-->
<!--            <foreach collection="deptcodes" item="deptcode" open="(" separator="," close=")">-->
<!--                #{deptcode}-->
<!--            </foreach>-->
<!--        </if>-->
        <if test="deptcodes != null and deptcodes.size() > 0">
            AND deptcode IN
            <foreach collection="deptcodes" item="deptcode" open="(" separator="," close=")">
                #{deptcode}
            </foreach>
        </if>
        <!--        GROUP BY-->
        <!--        <choose>-->
        <!--            <when test="timeType == 'day'">-->
        <!--                DATE_FORMAT(admitdate, '%Y-%m-%d')-->
        <!--            </when>-->
        <!--            <when test="timeType == 'month'">-->
        <!--                DATE_FORMAT(admitdate, '%Y-%m')-->
        <!--            </when>-->
        <!--            <when test="timeType == 'year'">-->
        <!--                DATE_FORMAT(admitdate, '%Y')-->
        <!--            </when>-->
        <!--            <when test="timeType == 'week'">-->
        <!--                CONCAT(YEAR(admitdate), '-W', LPAD(WEEK(admitdate, 1), 2, '0'))-->
        <!--            </when>-->
        <!--            <otherwise>-->
        <!--                DATE_FORMAT(admitdate, '%Y-%m-%d')-->
        <!--            </otherwise>-->
        <!--        </choose>-->
        ) AS combined_data
        GROUP BY timePeriod
        ORDER BY timePeriod DESC
@@ -2265,6 +2209,34 @@
        </if>
    </select>
    <select id="selectVisitCount" parameterType="com.smartor.domain.PatMedReq"
            resultType="com.smartor.domain.PatMedRes">
        select
        0 AS rc,
        count(1) AS rs
        FROM
        service_subtask
        where 1=1
        and del_flag = 0
        and service_type=3
        <if test="orgid != null">
            and orgid = #{orgid}
        </if>
        <if test="startDate != null">
            AND date_format( visit_time, '%y%m%d' ) &gt;= date_format( #{startDate}, '%y%m%d' )
        </if>
        <if test="endDate != null">
            AND date_format( visit_time, '%y%m%d' ) &lt;= date_format(#{endDate},'%y%m%d')
        </if>
        <if test="deptcodeList != null and deptcodeList.size()>0">
            and deptcode in
            <foreach collection="deptcodeList" item="deptcode" open="(" separator="," close=")">
                #{deptcode}
            </foreach>
        </if>
    </select>
    <select id="getCurrentUserServiceSubtaskCount" parameterType="com.smartor.domain.entity.ServiceSubtaskEntity" resultType="map">
        SELECT
        COUNT(CASE WHEN sendstate = 2 AND date_format(visit_time,'%y%m%d') &lt;= date_format(CURDATE(),'%y%m%d') THEN 1 END) AS pendingVisitCount,