陈昶聿
13 小时以前 6a53d35b5d56e2f6bc64bbfe41579f6f32039c90
smartor/src/main/java/com/smartor/service/impl/ServiceSLTDHealthcareRecordServiceImpl.java
@@ -10,10 +10,12 @@
import com.ruoyi.common.core.domain.entity.SysUserRole;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.http.HttpUtils;
import com.smartor.common.DistinctByProperty;
import com.smartor.domain.*;
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;
@@ -30,6 +32,8 @@
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.stream.Collectors;
@Slf4j
@Service
@@ -45,7 +49,7 @@
    private IPatMedInhospService patMedInhospService;
    @Autowired
    private PatMedOuthospMapper patMedOuthospMapper;
    private IPatMedOuthospService patMedOuthospService;
    @Autowired
    private SysUser2Mapper sysUser2Mapper;
@@ -484,7 +488,7 @@
    private Boolean outHospitalDate(List<ServiceSLTDInhospResDTO> resultList) {
        List<PatMedOuthosp> batchList = new ArrayList<>();
        for (ServiceSLTDInhospResDTO dto : resultList) {
            if (Objects.isNull(dto)) {
                continue;
@@ -493,22 +497,21 @@
            PatMedOuthosp patMedOuthosp = buildPatMedOuthosp(dto, patArchive);
            batchList.add(patMedOuthosp);
        }
        // 批量插入,自动忽略重复
        if (CollectionUtils.isNotEmpty(batchList)) {
            try {
                int insertCount = patMedOuthospMapper.batchInsertIgnore(batchList);
                //这里用自动忽略重复会有问题,如果表重新建,serialnum索引会丢失。就无法去重,所以还是需要内存里去重
                batchList = DistinctByProperty.distinctByProperty(batchList, PatMedOuthosp::getSerialnum);
                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;