陈昶聿
9 小时以前 6e397c664037b898b5e9d9955da1d953089e679e
ruoyi-quartz/src/main/java/com/ruoyi/quartz/service/impl/CollectHISServiceImpl.java
@@ -334,9 +334,22 @@
        patMedOperation.setLastStartTime(startTime);
        patMedOperation.setLastEndTime(endTime);
        List<PatMedOperation> patMedOperations = chMapper.selectOperList(patMedOperation);
        Map<String, Long> patIdHisMap = buildOperationPatIdHisMap(patMedOperations);
        log.info("同步手术信息数量" + patMedOperations.size());
        for (PatMedOperation operation : patMedOperations) {
            try {
                Long patId = patIdHisMap.get(operation.getPatidHis());
                if (patId == null) {
                    patId = syncSinglePatient(operation.getPatidHis());
                    if (patId != null) {
                        patIdHisMap.put(operation.getPatidHis(), patId);
                    }
                }
                if (patId != null) {
                    operation.setPatid(patId);
                }
                PatMedOperation oper = new PatMedOperation();
                oper.setOpid(operation.getOpid());
                List<PatMedOperation> patMedOperations1 = patMedOperationMapper.selectPatMedOperationList(oper);
@@ -389,9 +402,68 @@
                    log.info("同步手术详情信息:" + ex.getMessage());
                }
            }
//            try {
//                patMedOperationItemMapper.deleteHardPatMedOperationItemByOpId(operation.getOpid());
//                count += patMedOperationItemMapper.insertPatMedOperationItems(patMedOperationItems);
//            }catch (Exception ex) {
//                log.info("同步手术详情信息:" + ex.getMessage());
//            }
        }
        return count;
    }
    private Map<String, Long> buildOperationPatIdHisMap(List<PatMedOperation> operations) {
        List<String> patidHiss = operations.stream()
                .map(PatMedOperation::getPatidHis)
                .filter(StringUtils::isNotEmpty)
                .distinct()
                .collect(Collectors.toList());
        if (CollectionUtils.isEmpty(patidHiss)) {
            return new HashMap<>();
        }
        return patArchiveMapper.selectPatArchiveByPatidHiss(patidHiss).stream()
                .filter(item -> StringUtils.isNotEmpty(item.getPatidHis()) && item.getId() !=
                        null)
                .collect(Collectors.toMap(
                        PatArchive::getPatidHis,
                        PatArchive::getId,
                        (a, b) -> a
                ));
    }
    private Long syncSinglePatient(String patidHis) {
        if (StringUtils.isEmpty(patidHis)) {
            return null;
        }
        PatArchive hisQuery = new PatArchive();
        hisQuery.setPatidHis(patidHis);
        hisQuery.setPageSize(5);
        List<PatArchive> hisArchives = chMapper.selectPatArchiveList(hisQuery);
        if (CollectionUtils.isEmpty(hisArchives)) {
            return null;
        }
        PatArchive localQuery = new PatArchive();
        localQuery.setPatidHis(patidHis);
        List<PatArchive> localArchives = patArchiveMapper.selectPatArchiveList(localQuery);
        PatArchive hisArchive = hisArchives.get(0);
        if (CollectionUtils.isNotEmpty(localArchives)) {
            hisArchive.setId(localArchives.get(0).getId());
            hisArchive.setUpdateTime(new Date());
            patArchiveMapper.updatePatArchive(hisArchive);
            return localArchives.get(0).getId();
        } else {
            hisArchive.setCreateTime(new Date());
            patArchiveMapper.insertPatArchiveSingle(hisArchive);
            return hisArchive.getId();
        }
    }
    @Override
    public Integer selectPatMedInhospList(PatMedInhosp patMedInhosp) {
        List<PatMedInhosp> patMedInhospList = chMapper.selectPatMedInhospList(patMedInhosp);