liusheng
昨天 29069b790469cb7136cadba7ddcd63a83bc4ac70
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
@@ -278,8 +282,7 @@
                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()){
@@ -1032,6 +1035,7 @@
     * 第一条(急诊科室的)记录缺少“出院时间”,导致该记录在统计中始终显示为“在院”,
     * 而第二条(转入科室的)记录是完整的。我们需要采集 JZ_ZY_LiQiang接口的数据,
     * 里面的离抢时间来反填第一条记录的“出院时间”,从而修正第一条记录的状态。
     *
     * @param dataMap
     * @return
     */
@@ -1071,11 +1075,10 @@
            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