sinake
2 天以前 2a3d4e4c082403aeb31d4c1c499a6107ffa835af
ruoyi-quartz/src/main/java/com/ruoyi/quartz/service/impl/CollectHISServiceImpl.java
@@ -6,6 +6,7 @@
import com.ruoyi.common.core.domain.entity.SysUserRole;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.quartz.mapper.CollectHISMapper;
import com.ruoyi.quartz.mapper.UtilsMapper;
import com.ruoyi.quartz.service.ICollectHISService;
import com.smartor.domain.*;
import com.smartor.mapper.*;
@@ -20,6 +21,7 @@
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.*;
import java.util.stream.Collectors;
@Slf4j
@Service
@@ -57,6 +59,9 @@
    @Autowired
    private ShardingMapper shardingMapper;
    @Autowired
    private UtilsMapper utilsMapper;
    private static final long SHARDING_THRESHOLD = 5_000_000L;
    private static final String PAT_ARCHIVE_TABLE = "pat_archive";
    private static final String PAT_MED_INHOSP_TABLE = "pat_med_inhosp";
@@ -79,6 +84,189 @@
//        return 0; // 返回0表示任务已提交到后台执行
//    }
    /**
     * 同步任务
     * @param
     * @return
     */
    @Override
    public Integer sync() {
        Integer count = 0;
        List<Map<String, Object>> syncList = utilsMapper.getList("SELECT id,syncName,DATE_FORMAT(ADDDATE(startTime, INTERVAL -1 MINUTE), '%Y-%m-%d %H:%i:%s') startTime  FROM sys_sync_time  where state=0");
        if (syncList.size() > 0) {
            String endTime = chMapper.getSqlString("select sysdate from healthy_inhosp where rownum=1");
            //同步患者基本信息
//            List<Map<String, Object>> syncTemp = syncList.stream().filter(row -> row.get("syncName").equals("pat_archive")).collect(Collectors.toList());
//            if (syncTemp.size() > 0) {
//                count+=syncArchive(syncTemp.get(0).get("startTime") + "", endTime);
//                utilsMapper.updateSql("update sys_sync_time set startTime='"+endTime+"' where syncName='pat_archive' ");
//            }
            //同步住院病人信息
            List<Map<String, Object>> syncTemp = syncList.stream().filter(row -> row.get("syncName").equals("pat_med_inhosp")).collect(Collectors.toList());
            if (syncTemp.size() > 0) {
                count+=syncMedInhosp(syncTemp.get(0).get("startTime") + "", endTime);
                utilsMapper.updateSql("update sys_sync_time set startTime='"+endTime+"' where syncName='pat_med_inhosp' ");
            }
            //同步门诊信息
            syncTemp = syncList.stream().filter(row -> row.get("syncName").equals("pat_med_outhosp")).collect(Collectors.toList());
            if (syncTemp.size() > 0) {
                count+=syncOuthosp(syncTemp.get(0).get("startTime") + "", endTime);
                utilsMapper.updateSql("update sys_sync_time set startTime='"+endTime+"' where syncName='pat_med_outhosp' ");
            }
        } else {
            log.info("同步任务时间sys_sync_time表中没有需要同步的任务");
        }
        return count;
    }
    /**
     * 同步患者基本信息
     * @param
     * @return
     */
    private  Integer syncArchive(String startTime,String endTime) {
        Integer count = 0;
        PatArchive pa = new PatArchive();
        pa.setLastStartTime(startTime);
        pa.setLastEndTime(endTime);
        List<PatArchive> patArchives = chMapper.selectPatArchiveList(pa);
        log.info("可同患者基本信息数量" + patArchives.size());
        for (PatArchive pm : patArchives) {
            try {
                PatArchive pa1 = new PatArchive();
                pa1.setPatientno(pm.getPatientno());
                List<PatArchive> patArchives1 = patArchiveMapper.selectPatArchiveList(pa1);
                if (CollectionUtils.isNotEmpty(patArchives1)) {
                    pm.setId(patArchives1.get(0).getId());
                    pm.setUpdateTime(new Date());
                    count += patArchiveMapper.updatePatArchive(pm);
                } else {
                    pm.setCreateTime(new Date());
                    count += patArchiveMapper.insertPatArchiveSingle(pm);
                }
            }catch (Exception ex){
                log.info("可同患者基本信息:"+ex.getMessage());
            }
        }
        return count;
    }
    /**
     * 同步出入院信息
     * @param
     * @return
     */
    private  Integer syncMedInhosp(String startTime,String endTime) {
        Integer count = 0;
        PatMedInhosp patMedInhosp = new PatMedInhosp();
        patMedInhosp.setLastStartTime(startTime);
        patMedInhosp.setLastEndTime(endTime);
        List<PatMedInhosp> patMedInhospList = chMapper.selectPatMedInhospList(patMedInhosp);
        log.info("可同步出入院数量" + patMedInhospList.size());
        for (PatMedInhosp pm : patMedInhospList) {
            try {
                //患者基本信息
                PatArchive patArchive = new PatArchive();
                patArchive.setPatientno(pm.getPatno());
                List<PatArchive> patArchives = chMapper.selectPatArchiveList(patArchive);
                if (patArchives.size() > 0) {
                    PatArchive pa1 = new PatArchive();
                    pa1.setPatientno(pm.getPatno());
                    List<PatArchive> patArchives1 = patArchiveMapper.selectPatArchiveList(pa1);
                    if (CollectionUtils.isNotEmpty(patArchives1)) {
                        patArchives.get(0).setId(patArchives1.get(0).getId());
                        patArchives.get(0).setUpdateTime(new Date());
                        count += patArchiveMapper.updatePatArchive(patArchives.get(0));
                    } else {
                        patArchives.get(0).setCreateTime(new Date());
                        count += patArchiveMapper.insertPatArchiveSingle(patArchives.get(0));
                    }
                }
            }catch (Exception ex) {
                log.info("同患者基本信息:" + ex.getMessage());
            }
            try {
                //同步出入院
                PatMedInhosp pmi = new PatMedInhosp();
                pmi.setSerialnum(pm.getSerialnum());
                List<PatMedInhosp> patMedInhospList1 = patMedInhospMapper.selectPatMedInhospListBySerialnum(pmi);
                if (patMedInhospList1.size() == 0) {
                    pm.setCreateTime(new Date());
                    count += patMedInhospMapper.insertPatMedInhosp(pm);
                } else {
                    pm.setInhospid(patMedInhospList1.get(0).getInhospid());
                    pm.setUpdateTime(new Date());
                    count += patMedInhospMapper.updatePatMedInhosp(pm);
                }
            } catch (Exception ex) {
                log.info("同步出入院:" + ex.getMessage());
            }
        }
        return count;
    }
    /**
     * 同步门诊信息
     * @param
     * @return
     */
    private  Integer syncOuthosp(String startTime,String endTime) {
        Integer count = 0;
        PatMedOuthosp patMedOuthosp = new PatMedOuthosp();
        patMedOuthosp.setLastStartTime(startTime);
        patMedOuthosp.setLastEndTime(endTime);
        List<PatMedOuthosp> patMedOuthosps = chMapper.selectPatMedOuthospList(patMedOuthosp);
        log.info("同步门诊信息数量" + patMedOuthosps.size());
        for (PatMedOuthosp patMedOuthosp1 : patMedOuthosps) {
            try {
                //患者基本信息
                PatArchive patArchive = new PatArchive();
                patArchive.setPatientno(patMedOuthosp1.getPatno());
                List<PatArchive> patArchives = chMapper.selectPatArchiveList(patArchive);
                if (patArchives.size() > 0) {
                    PatArchive pa1 = new PatArchive();
                    pa1.setPatientno(patMedOuthosp1.getPatno());
                    List<PatArchive> patArchives1 = patArchiveMapper.selectPatArchiveList(pa1);
                    if (CollectionUtils.isNotEmpty(patArchives1)) {
                        patArchives.get(0).setId(patArchives1.get(0).getId());
                        patArchives.get(0).setUpdateTime(new Date());
                        count += patArchiveMapper.updatePatArchive(patArchives.get(0));
                    } else {
                        patArchives.get(0).setCreateTime(new Date());
                        count += patArchiveMapper.insertPatArchiveSingle(patArchives.get(0));
                    }
                }
            }catch (Exception ex) {
                log.info("同患者基本信息:" + ex.getMessage());
            }
            try {
                PatMedOuthosp patMedOuthospTemp = new PatMedOuthosp();
                patMedOuthospTemp.setSerialnum(patMedOuthosp1.getSerialnum());
                List<PatMedOuthosp> patMedOuthospsTemp = chMapper.selectPatMedOuthospList(patMedOuthosp);
                if (patMedOuthospsTemp.size() > 0) {
                    patMedOuthosp1.setUpdateTime(new Date());
                    patMedOuthosp1.setId(patMedOuthospsTemp.get(0).getId());
                    count += patMedOuthospMapper.updatePatMedOuthosp(patMedOuthosp1);
                } else {
                    patMedOuthosp1.setCreateTime(new Date());
                    count += patMedOuthospMapper.insertPatMedOuthosp(patMedOuthosp1);
                }
            } catch (Exception ex) {
                log.info("同步出入院:" + ex.getMessage());
            }
        }
        return count;
    }
    @Override
    public Integer selectPatMedInhospList(PatMedInhosp patMedInhosp) {
@@ -221,33 +409,40 @@
    public Integer selectUserList(SysUser sysUser) {
        List<SysUser> sysUserList = chMapper.selectUserList(sysUser);
        log.info("sysUserList的采集到的数量为:{}", sysUserList.size());
        int i = sysUser2Mapper.batchUser(sysUserList);
        int i =0;// sysUser2Mapper.batchUser(sysUserList);
        for (SysUser sysUser1 : sysUserList) {
            log.info("sysUser1的ID为:{}", sysUser1.getUserId());
            log.info("sysUser1的HISUSERID为:{}", sysUser1.getHisUserId());
            //新增用户与角色
            SysUserRole yhyjsxx = chMapper.yhyjsxx(sysUser1);
            if (yhyjsxx == null) continue;
            yhyjsxx.setUserId(sysUser1.getUserId());
            List<SysUserRole> userRoleList = new ArrayList<>();
            userRoleList.add(yhyjsxx);
            sysUserRoleMapper.batchUserRole(userRoleList);
//            log.info("sysUser1的ID为:{}", sysUser1.getUserId());
//            log.info("sysUser1的HISUSERID为:{}", sysUser1.getHisUserId());
//            //新增用户与角色
//            SysUserRole yhyjsxx = chMapper.yhyjsxx(sysUser1);
//            if (yhyjsxx != null&&yhyjsxx.getUserId()!=null) {
//                yhyjsxx.setUserId(sysUser1.getUserId());
//                List<SysUserRole> userRoleList = new ArrayList<>();
//                userRoleList.add(yhyjsxx);
//                sysUserRoleMapper.batchUserRole(userRoleList);
//            }
            if (StringUtils.isEmpty(sysUser1.getHisUserId())) continue;
            SysUser suTemp=new SysUser();
            suTemp.setHisUserId(sysUser1.getHisUserId());
            List<SysUser> usersTemp= sysUser2Mapper.selectUserList(suTemp);
            if (usersTemp.size()>0) {
                sysUser1.setUserId(usersTemp.get(0).getUserId());
                sysUser2Mapper.updateUser(sysUser1);
            }else{
                sysUser2Mapper.insertUser(sysUser1);
                usersTemp= sysUser2Mapper.selectUserList(suTemp);
            }
            //新增用户与部门
            if (StringUtils.isEmpty(sysUser1.getHisUserId())) continue;
            SysUserDept sysUserDept = chMapper.yhyksxx(sysUser1);
            if (Objects.isNull(sysUserDept) || sysUserDept.getDeptId() == null) continue;
            SysDept dept = new SysDept();
            dept.setHisDeptId(sysUserDept.getDeptId().toString());
            List<SysDept> sysDepts = sysDept2Mapper.selectDeptList(dept);
            if (CollectionUtils.isNotEmpty(sysDepts)) {
                sysUserDept.setDeptId(sysDepts.get(0).getDeptId());
                sysUserDept.setDeptCode(sysDepts.get(0).getDeptCode());
            List<SysUserDept> sysUserDept = chMapper.yhyksxx(sysUser1);
            for(SysUserDept sud :sysUserDept) {
                if (usersTemp.size()>0) {
                    sud.setUserId(usersTemp.get(0).getUserId());
                    sysUserDeptMapper.insertSysUserDept(sud);
            }
            sysUserDept.setUserId(sysUser1.getUserId());
            sysUserDeptMapper.insertSysUserDept(sysUserDept);
        }
        }
        return i;
    }