Selaa lähdekoodia

原数据在新导入的全部数据中不存在则删除

mlz 1 vuosi sitten
vanhempi
commit
e8c50d9636

+ 18 - 0
src/main/java/com/hgwebservice/service/syncCdm2/SyncPatientDataByDeptCodeImpl.java

@@ -14,7 +14,9 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
 import java.util.List;
+import java.util.Optional;
 import java.util.stream.Collectors;
 
 @Service
@@ -22,12 +24,18 @@ public class SyncPatientDataByDeptCodeImpl implements SyncPatientDataByDeptCode
     @Autowired
     OperatorDataMapper operatorDataMapper;
     @Autowired
+    PatientDataMapper patientDataMapper;
+    @Autowired
     HgWebService hgWebService;
     @Value("${hospital_id}")
     private Integer hospitalId;
     @Override
     public void saveCdm2() {
         List<OperatorDataDO> operatorDataDOS = operatorDataMapper.selectList(new LambdaQueryWrapper<>());
+
+        LambdaQueryWrapper<PatientDataDO> patientDataDOLambdaQueryWrapper = new LambdaQueryWrapper<>();
+        patientDataDOLambdaQueryWrapper.eq(PatientDataDO::getHospitalId,hospitalId);
+        List<PatientDataDO> patientDataDOS1 = patientDataMapper.selectList(patientDataDOLambdaQueryWrapper);
 //        if (CollUtil.isNotEmpty(operatorDataDOS)){
 //            List<String> collect = operatorDataDOS.stream().map(OperatorDataDO::getDeptCode).distinct().collect(Collectors.toList());
 //            if (CollUtil.isNotEmpty(collect)){
@@ -42,6 +50,16 @@ public class SyncPatientDataByDeptCodeImpl implements SyncPatientDataByDeptCode
 //        }
         List<PatientData> patientData = hgWebService.getPatientDataByDeptCode("55");
         if (CollUtil.isNotEmpty(patientData)){
+            List<Integer> deletedIds=new ArrayList<>();
+            for (PatientDataDO patientDataDO : patientDataDOS1) {
+                Optional<PatientData> first = patientData.stream().filter(item -> item.getPatientNo().equals(patientDataDO.getPatientNo())).findFirst();
+                if (!first.isPresent()){
+                    deletedIds.add(patientDataDO.getId());
+                }
+            }
+            if (CollUtil.isNotEmpty(deletedIds)){
+                patientDataMapper.deleteBatchIds(deletedIds);
+            }
             List<PatientDataDO> patientDataDOS = BeanUtil.copyToList(patientData, PatientDataDO.class);
             operatorDataMapper.replacePatientData(patientDataDOS,hospitalId);
         }