zhoutg 5 年 前
コミット
7a84756d2a
1 ファイル変更122 行追加57 行削除
  1. 122 57
      src/main/java/com/diagbot/facade/DataImportFacade.java

+ 122 - 57
src/main/java/com/diagbot/facade/DataImportFacade.java

@@ -5,8 +5,10 @@ import com.diagbot.client.AuthServiceClient;
 import com.diagbot.entity.BehospitalInfo;
 import com.diagbot.entity.DoctorAdvice;
 import com.diagbot.entity.HomeDiagnoseInfo;
+import com.diagbot.entity.HomeOperationInfo;
 import com.diagbot.entity.HomePage;
 import com.diagbot.entity.MedCrisisInfo;
+import com.diagbot.entity.MedicalRecord;
 import com.diagbot.entity.MedicalRecordContent;
 import com.diagbot.exception.CommonErrorCode;
 import com.diagbot.exception.CommonException;
@@ -120,83 +122,145 @@ public class DataImportFacade {
                         .eq("hospital_id", hospitalId)
                         .in("doctor_advice_id", doctorAdviceIdList)
                 );
-                doctorAdviceService.saveOrUpdateBatch(doctorAdviceList);
+                doctorAdviceService.saveBatch(doctorAdviceList);
             }
         }
 
-        // 病案首页诊断 TODO
+        // 病案首页诊断
         List<HomeDiagnoseInfo> homeDiagnoseInfoList = dataImportVO.getHomeDiagnoseInfoList();
         if (ListUtil.isNotEmpty(homeDiagnoseInfoList)) {
-            List<String> ids = homeDiagnoseInfoList.stream().map(r -> r.getHomePageId()).collect(Collectors.toList());
-            if (ListUtil.isNotEmpty(ids)) {
-                // 先删除 TODO
-                // homeDiagnoseInfoService.remove(new QueryWrapper<HomeDiagnoseInfo>()
-                //         .eq("hospital_id", hospitalId)
-                //         .in("doctor_advice_id", ids)
-                // );
-                homeDiagnoseInfoService.saveOrUpdateBatch(homeDiagnoseInfoList);
+            StringBuffer sb = new StringBuffer();
+            sb.append(" ( ");
+            for (int i = 0; i < homeDiagnoseInfoList.size(); i++) {
+                HomeDiagnoseInfo s = homeDiagnoseInfoList.get(i);
+                if (i == 0) {
+                    sb.append(" (home_page_id = '" + s.getHomePageId() + "'"
+                            + " and diagnose_order_no = '" + s.getDiagnoseOrderNo() + "'"
+                            + ") " );
+                } else {
+                    sb.append(" or ( home_page_id = '" + s.getHomePageId() + "'"
+                            + " and diagnose_order_no = '" + s.getDiagnoseOrderNo() + "'"
+                            + ") " );
+                }
             }
+            sb.append(")");
+
+            // 先删除
+            homeDiagnoseInfoService.remove(new QueryWrapper<HomeDiagnoseInfo>()
+                    .eq("hospital_id", hospitalId)
+                    .apply(sb.toString())
+            );
+            homeDiagnoseInfoService.saveBatch(homeDiagnoseInfoList);
         }
 
         // 病案首页
         List<HomePage> homePageList = dataImportVO.getHomePageList();
         if (ListUtil.isNotEmpty(homePageList)) {
-            // 加密
-            for (HomePage homePage : dataImportVO.getHomePageList()) {
-                // 姓名
-                if (StringUtil.isNotBlank(homePage.getName())) {
-                    homePage.setName(homePage.getName().substring(0, 1) + "**");
-                }
-                // 身份证
-                if (StringUtil.isNotBlank(homePage.getIdentityCardNo())) {
-                    homePage.setIdentityCardNo(homePage.getIdentityCardNo().substring(0, 1) + "*****************");
-                }
-                // 现住址电话
-                if (StringUtil.isNotBlank(homePage.getCurPhone())) {
-                    homePage.setCurPhone(homePage.getCurPhone().substring(0, 1) + "**");
-                }
-                // 工作单位电话
-                if (StringUtil.isNotBlank(homePage.getWorkPhone())) {
-                    homePage.setWorkPhone(homePage.getWorkPhone().substring(0, 1) + "**");
-                }
-                // 联系人姓名
-                if (StringUtil.isNotBlank(homePage.getContactName())) {
-                    homePage.setContactName(homePage.getContactName().substring(0, 1) + "**");
-                }
-                // 联系人电话
-                if (StringUtil.isNotBlank(homePage.getContactPhone())) {
-                    homePage.setContactPhone(homePage.getContactPhone().substring(0, 1) + "**");
+            List<String> homePageIdList = homePageList.stream().map(r -> r.getHomePageId()).collect(Collectors.toList());
+            if (ListUtil.isNotEmpty(homePageIdList)) {
+                // 先删除
+                homePageService.remove(new QueryWrapper<HomePage>()
+                        .eq("hospital_id", hospitalId)
+                        .in("home_page_id", homePageIdList)
+                );
+                // 加密
+                for (HomePage homePage : dataImportVO.getHomePageList()) {
+                    // 姓名
+                    if (StringUtil.isNotBlank(homePage.getName())) {
+                        homePage.setName(homePage.getName().substring(0, 1) + "**");
+                    }
+                    // 身份证
+                    if (StringUtil.isNotBlank(homePage.getIdentityCardNo())) {
+                        homePage.setIdentityCardNo(homePage.getIdentityCardNo().substring(0, 1) + "*****************");
+                    }
+                    // 现住址电话
+                    if (StringUtil.isNotBlank(homePage.getCurPhone())) {
+                        homePage.setCurPhone(homePage.getCurPhone().substring(0, 1) + "**");
+                    }
+                    // 工作单位电话
+                    if (StringUtil.isNotBlank(homePage.getWorkPhone())) {
+                        homePage.setWorkPhone(homePage.getWorkPhone().substring(0, 1) + "**");
+                    }
+                    // 联系人姓名
+                    if (StringUtil.isNotBlank(homePage.getContactName())) {
+                        homePage.setContactName(homePage.getContactName().substring(0, 1) + "**");
+                    }
+                    // 联系人电话
+                    if (StringUtil.isNotBlank(homePage.getContactPhone())) {
+                        homePage.setContactPhone(homePage.getContactPhone().substring(0, 1) + "**");
+                    }
                 }
+                homePageService.saveBatch(homePageList);
             }
-            homePageService.saveBatch(homePageList);
         }
 
         // 病案首页手术信息
-        if (ListUtil.isNotEmpty(dataImportVO.getHomeOperationInfoList())) {
-            homeOperationInfoService.saveOrUpdateBatch(dataImportVO.getHomeOperationInfoList());
+        List<HomeOperationInfo> homeOperationInfoList = dataImportVO.getHomeOperationInfoList();
+        if (ListUtil.isNotEmpty(homeOperationInfoList)) {
+            StringBuffer sb = new StringBuffer();
+            sb.append(" ( ");
+            for (int i = 0; i < homeOperationInfoList.size(); i++) {
+                HomeOperationInfo s = homeOperationInfoList.get(i);
+                if (i == 0) {
+                    sb.append(" (home_page_id = '" + s.getHomePageId() + "'"
+                            + " and operation_order_no = '" + s.getOperationOrderNo() + "'"
+                            + ") " );
+                } else {
+                    sb.append(" or ( home_page_id = '" + s.getHomePageId() + "'"
+                            + " and operation_order_no = '" + s.getOperationOrderNo() + "'"
+                            + ") " );
+                }
+            }
+            sb.append(")");
+            // 先删除
+            homeOperationInfoService.remove(new QueryWrapper<HomeOperationInfo>()
+                    .eq("hospital_id", hospitalId)
+                    .apply(sb.toString())
+            );
+            homeOperationInfoService.saveBatch(homeOperationInfoList);
         }
+
         // 文书信息
-        if (ListUtil.isNotEmpty(dataImportVO.getMedicalRecordList())) {
-            medicalRecordService.saveOrUpdateBatch(dataImportVO.getMedicalRecordList());
+        List<MedicalRecord> medicalRecordList = dataImportVO.getMedicalRecordList();
+        if (ListUtil.isNotEmpty(medicalRecordList)) {
+            List<String> recIdList = medicalRecordList.stream().map(r -> r.getRecId()).collect(Collectors.toList());
+            if (ListUtil.isNotEmpty(recIdList)) {
+                // 先删除
+                medicalRecordService.remove(new QueryWrapper<MedicalRecord>()
+                        .eq("hospital_id", hospitalId)
+                        .in("rec_id", recIdList)
+                );
+                medicalRecordService.saveBatch(medicalRecordList);
+            }
         }
+
         // 文书明细信息
-        if (ListUtil.isNotEmpty(dataImportVO.getMedicalRecordContentList())) {
-            // 加密数据
-            if (encryptFlag) {
-                String recId = "";
-                try {
-                    EncrypDES encrypDES = new EncrypDES();
-                    for (MedicalRecordContent medicalRecordContent : dataImportVO.getMedicalRecordContentList()) {
-                        recId = medicalRecordContent.getRecId();
-                        if (StringUtil.isNotBlank(medicalRecordContent.getXmlText())) {
-                            medicalRecordContent.setXmlText(encrypDES.encrytor(medicalRecordContent.getXmlText()));
+        List<MedicalRecordContent> medicalRecordContentList = dataImportVO.getMedicalRecordContentList();
+        if (ListUtil.isNotEmpty(medicalRecordContentList)) {
+            List<String> recIdList = medicalRecordContentList.stream().map(r -> r.getRecId()).collect(Collectors.toList());
+            if (ListUtil.isNotEmpty(recIdList)) {
+                // 先删除
+                medicalRecordContentService.remove(new QueryWrapper<MedicalRecordContent>()
+                        .eq("hospital_id", hospitalId)
+                        .in("rec_id", recIdList));
+
+                // 加密数据
+                if (encryptFlag) {
+                    String recId = "";
+                    try {
+                        EncrypDES encrypDES = new EncrypDES();
+                        for (MedicalRecordContent medicalRecordContent : medicalRecordContentList) {
+                            recId = medicalRecordContent.getRecId();
+                            if (StringUtil.isNotBlank(medicalRecordContent.getXmlText())) {
+                                medicalRecordContent.setXmlText(encrypDES.encrytor(medicalRecordContent.getXmlText()));
+                            }
                         }
+                    } catch (Exception e) {
+                        throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "加密xml错误!recId=【" + recId + "】");
                     }
-                } catch (Exception e) {
-                    throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "加密xml错误!recId=【" + recId + "】");
                 }
+                medicalRecordContentService.saveBatch(medicalRecordContentList, 100);
             }
-            medicalRecordContentService.saveOrUpdateBatch(dataImportVO.getMedicalRecordContentList(), 100);
         }
         return true;
     }
@@ -208,11 +272,12 @@ public class DataImportFacade {
      * @return
      */
     public Boolean test() {
-        int size = 100;
+        int size = 5;
         Long hospitalId = 8L;
         int random = (int)(Math.random() * 100);
 
         DataImportVO dataImportVO = new DataImportVO();
+        dataImportVO.setHospitalId(hospitalId);
 
         // // 病历信息
         // List<BehospitalInfo> behospitalInfoList = behospitalInfoService.list(new QueryWrapper<BehospitalInfo>()
@@ -245,13 +310,13 @@ public class DataImportFacade {
         // );
         // homePageList.forEach(r -> {r.setHospitalId(hospitalId); r.setBehospitalCode(r.getBehospitalCode() + random);});
         // dataImportVO.setHomePageList(homePageList);
-        //
+
         // // 病案首页手术信息
         // List<HomeOperationInfo> homeOperationInfoList = homeOperationInfoService.list(new QueryWrapper<HomeOperationInfo>()
-        //         .ne("hospital_id", hospitalId)
+        //         .eq("hospital_id", hospitalId)
         //         .last(" limit " + size)
         // );
-        // homeOperationInfoList.forEach(r -> {r.setHospitalId(hospitalId); r.setHomePageId(r.getHomePageId() + random);});
+        // homeOperationInfoList.forEach(r -> {r.setHospitalId(hospitalId); r.setHomePageId(r.getHomePageId() );});
         // dataImportVO.setHomeOperationInfoList(homeOperationInfoList);
         //
         // // 文书信息