diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/YtHsResUtils.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/YtHsResUtils.java index cb28cf5419..3f72228656 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/YtHsResUtils.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/YtHsResUtils.java @@ -43,7 +43,33 @@ public class YtHsResUtils { log.info("hscy api param:{}", param); //todo 核酸检测 mock数据 放开她 //Result result = HttpClientManager.getInstance().sendGet(SERVER_URL+"hscyxxcx", param); - String mockData = "{\"id\":\"1570924677539635484\",\"name\":\"杨XX\",\"card_type\":\"1\",\"card_no\":\"370283199912010302\",\"create_by\":\"370613594\",\"create_time\":\"2022-09-17 07:15:22\",\"sys_org_code\":\"370613\",\"sample_tube\":\"GCJ-0825-0441\",\"package_id\":\"bcj00208083952\",\"city\":\"烟台市\",\"uuid\":\"6225684525062602095\",\"county\":\"莱山区\",\"depart_ids\":\"未填写\",\"depart_name\":null,\"realname\":\"采样点327\",\"upload_time\":\"2022-09-17 07:56:45\",\"sd_id\":null,\"sd_batch\":null,\"sd_operation\":null,\"sd_time\":null,\"inserttime\":\"2022-09-17 09:36:20\"}"; + String mockData = "{\n" + + " \"code\":0,\n" + + " \"msg\":\"success\",\n" + + " \"data\":[{\n" + + " \"id\": \"1570924677539635484\",\n" + + " \"name\": \"杨XX\",\n" + + " \"card_type\": \"1\",\n" + + " \"card_no\": \"370283199912010302\",\n" + + " \"create_by\": \"370613594\",\n" + + " \"create_time\": \"2022-09-17 07:15:22\",\n" + + " \"sys_org_code\": \"370613\",\n" + + " \"sample_tube\": \"GCJ-0825-0441\",\n" + + " \"package_id\": \"bcj00208083952\",\n" + + " \"city\": \"烟台市\",\n" + + " \"uuid\": \"6225684525062602095\",\n" + + " \"county\": \"莱山区\",\n" + + " \"depart_ids\": \"未填写\",\n" + + " \"depart_name\": null,\n" + + " \"realname\": \"采样点327\",\n" + + " \"upload_time\": \"2022-09-17 07:56:45\",\n" + + " \"sd_id\": null,\n" + + " \"sd_batch\": null,\n" + + " \"sd_operation\": null,\n" + + " \"sd_time\": null,\n" + + " \"inserttime\": \"2022-09-17 09:36:20\"\n" + + "}]\n" + + "}"; Result result = new Result().ok(mockData); log.info("hscy api result:{}", JSON.toJSONString(result)); if (result.success()) { @@ -74,7 +100,7 @@ public class YtHsResUtils { log.info("hsjc api param:{}", param); //todo 核酸检测 mock数据 放开她 //Result result = HttpClientManager.getInstance().sendGet(SERVER_URL+"hsjcxx", param); - String mockData = "{\"code\":\"200\",\"msg\":\"请求成功\",\"data\":[{\"id\":\"6a31eb2d38c011eda054fa163ebc7ff4\",\"name\":\"数据同步测试用户\",\"card_no\":\"370283199912010302\",\"telephone\":\"13697890860\",\"address\":\"保利香榭里公馆18-1-302\",\"test_time\":\"2022-09-20 12:52:28\",\"depart_name\":\"天仁医学检验实验室有限公司\",\"county\":\"莱山区\",\"upload_time\":\"2022-09-20 21:23:10\",\"sample_result_pcr\":\"2\",\"sample_time\":\"2022-09-20 06:48:28\",\"sampling_org_pcr\":\"采样点327\"}],\"total\":1}"; + String mockData = "{\"code\":\"200\",\"msg\":\"请求成功\",\"data\":[{\"id\":\"6a31eb2d38c011eda054fa163ebc7ff4\",\"name\":\"数据同步测试用户\",\"card_no\":\"370283199912010302\",\"telephone\":\"13697890860\",\"address\":\"保利香榭里公馆18-1-302\",\"test_time\":\"2022-09-20 12:52:28\",\"depart_name\":\"天仁医学检验实验室有限公司\",\"county\":\"莱山区\",\"upload_time\":\"2022-09-20 21:23:10\",\"sample_result_pcr\":\"2\",\"sample_time\":\"2022-09-17 07:15:22\",\"sampling_org_pcr\":\"采样点327\"}],\"total\":1}"; Result result = new Result().ok(mockData); log.info("hsjc api result:{}", JSON.toJSONString(result)); if (result.success()) { diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/IcNatDao.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/IcNatDao.java index b2419b09f5..f21ec91eb3 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/IcNatDao.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/IcNatDao.java @@ -64,4 +64,6 @@ public interface IcNatDao extends BaseDao { List getExistNatInfo(@Param("list") List entities); + void updateBatchNat(@Param("list")List entities); + } diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/IcNatService.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/IcNatService.java index ea75c911e4..430a66424a 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/IcNatService.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/IcNatService.java @@ -92,4 +92,6 @@ public interface IcNatService extends BaseService { * @return */ Integer updateIsResiFlag(String customerId, String icResiUserId); + + void updateBatchNat(List entities); } diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/DataSyncConfigServiceImpl.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/DataSyncConfigServiceImpl.java index 2517791025..90ddad6372 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/DataSyncConfigServiceImpl.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/DataSyncConfigServiceImpl.java @@ -454,100 +454,64 @@ public class DataSyncConfigServiceImpl extends BaseServiceImpl idCards, String customerId, String isSync) { try { - List entities = new ArrayList<>(); idCards.forEach(idCard -> { -// YtHscyResDTO sampleResult = YtHsResUtils.hscy(idCard.getIdCard(), NumConstant.ONE, NumConstant.ONE); - YtHsjcResDTO natInfoResult = YtHsResUtils.hsjc(idCard.getIdCard(), NumConstant.ONE, NumConstant.ONE); - /*Boolean aBoolean = CollectionUtils.isEmpty(sampleResult.getData()) && CollectionUtils.isNotEmpty(natInfoResult.getData()); - Boolean bBoolean = CollectionUtils.isNotEmpty(sampleResult.getData()) && CollectionUtils.isNotEmpty(natInfoResult.getData());*/ - /** - * 1.采样结果 和 检测结果 都不为空,以检测结果为准 - * 2.采样结果为空,检测结果不为空 - */ -// if (aBoolean || bBoolean) { - if (CollectionUtils.isNotEmpty(natInfoResult.getData())) { - natInfoResult.getData().forEach(natInfo -> { + YtHscyResDTO sampleResult = YtHsResUtils.hscy(idCard.getIdCard(), NumConstant.ONE, NumConstant.ONE); + if (CollectionUtils.isNotEmpty(sampleResult.getData())){ + List entities = new ArrayList<>(); + sampleResult.getData().forEach(sampleInfo -> { IcNatEntity e = new IcNatEntity(); e.setCustomerId(customerId); e.setIsResiUser(StringUtils.isBlank(idCard.getUserId()) ? NumConstant.ZERO_STR : NumConstant.ONE_STR); e.setUserId(idCard.getUserId()); + e.setMobile(""); e.setUserType(isSync.equals(NumConstant.ONE_STR) ? "manualSync" : "sync"); - e.setName(StringUtils.isNotBlank(natInfo.getName()) ? natInfo.getName() : ""); - e.setMobile(StringUtils.isNotBlank(natInfo.getTelephone()) ? natInfo.getTelephone() : ""); - e.setIdCard(StringUtils.isNotBlank(natInfo.getCard_no()) ? natInfo.getCard_no() : ""); - e.setNatTime(DateUtils.parseDate(natInfo.getTest_time(), DateUtils.DATE_TIME_PATTERN)); - e.setSampleTime(DateUtils.parseDate(natInfo.getSample_time(), DateUtils.DATE_TIME_PATTERN)); - String resultPcr = natInfo.getSample_result_pcr(); - //检测结果 转换 我们 0:阴性 1:阳性, 他们 :1:阳性,2:阴性 - e.setNatResult(NumConstant.ZERO_STR); - if (NumConstant.ONE_STR.equals(resultPcr)) { - e.setNatResult(NumConstant.ONE_STR); - } - e.setNatAddress(natInfo.getSampling_org_pcr()); + e.setName(StringUtils.isNotBlank(sampleInfo.getName()) ? sampleInfo.getName() : ""); + e.setIdCard(StringUtils.isNotBlank(sampleInfo.getCard_no()) ? sampleInfo.getCard_no() : ""); + e.setSampleTime(DateUtils.parseDate(sampleInfo.getCreate_time(), DateUtils.DATE_TIME_PATTERN)); e.setAgencyId(idCard.getAgencyId()); e.setPids(idCard.getPids()); e.setAttachmentType(""); e.setAttachmentUrl(""); entities.add(e); }); + if (CollectionUtils.isNotEmpty(entities)){ + List existSampleInfo = icNatDao.getExistNatInfo(entities); + sampleAndNat(existSampleInfo,entities,NumConstant.ONE_STR,customerId,isSync); + } } - /*if (CollectionUtils.isNotEmpty(sampleResult.getData()) && CollectionUtils.isEmpty(natInfoResult.getData())){ - sampleResult.getData().forEach(sampleInfo -> { + YtHsjcResDTO natInfoResult = YtHsResUtils.hsjc(idCard.getIdCard(), NumConstant.ONE, NumConstant.ONE); + if (CollectionUtils.isNotEmpty(natInfoResult.getData())) { + List entities = new ArrayList<>(); + natInfoResult.getData().forEach(natInfo -> { IcNatEntity e = new IcNatEntity(); e.setCustomerId(customerId); e.setIsResiUser(StringUtils.isBlank(idCard.getUserId()) ? NumConstant.ZERO_STR : NumConstant.ONE_STR); e.setUserId(idCard.getUserId()); e.setUserType(isSync.equals(NumConstant.ONE_STR) ? "manualSync" : "sync"); - e.setName(StringUtils.isNotBlank(sampleInfo.getName()) ? sampleInfo.getName() : ""); - e.setMobile(StringUtils.isNotBlank(sampleInfo.get()) ? sampleInfo.getTelephone() : ""); - e.setIdCard(StringUtils.isNotBlank(sampleInfo.getCard_no()) ? sampleInfo.getCard_no() : ""); - e.setNatTime(DateUtils.parseDate(sampleInfo.getTest_time(), DateUtils.DATE_TIME_PATTERN)); - e.setSampleTime(DateUtils.parseDate(sampleInfo.getSample_time(), DateUtils.DATE_TIME_PATTERN)); - String resultPcr = sampleInfo.getSample_result_pcr(); + e.setName(StringUtils.isNotBlank(natInfo.getName()) ? natInfo.getName() : ""); + e.setMobile(StringUtils.isNotBlank(natInfo.getTelephone()) ? natInfo.getTelephone() : ""); + e.setIdCard(StringUtils.isNotBlank(natInfo.getCard_no()) ? natInfo.getCard_no() : ""); + e.setNatTime(DateUtils.parseDate(natInfo.getTest_time(), DateUtils.DATE_TIME_PATTERN)); + e.setSampleTime(DateUtils.parseDate(natInfo.getSample_time(), DateUtils.DATE_TIME_PATTERN)); + String resultPcr = natInfo.getSample_result_pcr(); //检测结果 转换 我们 0:阴性 1:阳性, 他们 :1:阳性,2:阴性 e.setNatResult(NumConstant.ZERO_STR); - if (NumConstant.ONE_STR.equals(resultPcr)){ + if (NumConstant.ONE_STR.equals(resultPcr)) { e.setNatResult(NumConstant.ONE_STR); } - e.setNatAddress(sampleInfo.getSampling_org_pcr()); + e.setNatAddress(natInfo.getSampling_org_pcr()); e.setAgencyId(idCard.getAgencyId()); e.setPids(idCard.getPids()); e.setAttachmentType(""); e.setAttachmentUrl(""); entities.add(e); }); - } - });*/ - if (CollectionUtils.isNotEmpty(entities)) { - List existNatInfos = icNatDao.getExistNatInfo(entities); - entities.forEach(e -> existNatInfos.stream().filter(i -> i.getUserId().equals(e.getUserId()) && i.getIdCard().equals(e.getIdCard())).forEach(i -> e.setExistStatus(true))); - Map> groupByStatus = entities.stream().collect(Collectors.groupingBy(IcNatEntity::getExistStatus)); - if (CollectionUtils.isNotEmpty(groupByStatus.get(false))) { - for (List icNatEntities : ListUtils.partition(groupByStatus.get(false), NumConstant.FIVE_HUNDRED)) { - icNatService.insertBatch(icNatEntities); - //组织关系表 - List relationEntities = new ArrayList<>(); - icNatEntities.forEach(ne -> { - // 不是居民的先不加关系表吧 - if (ne.getIsResiUser().equals(NumConstant.ONE_STR)) { - IcNatRelationEntity e = new IcNatRelationEntity(); - e.setCustomerId(customerId); - e.setAgencyId(ne.getAgencyId()); - e.setPids(ne.getPids()); - e.setIcNatId(ne.getId()); - e.setUserType("sync"); - relationEntities.add(e); - } - }); - if (CollectionUtils.isNotEmpty(relationEntities)) { - icNatRelationService.insertBatch(relationEntities); - } - } + if (CollectionUtils.isNotEmpty(entities)) { + List existNatInfos = icNatDao.getExistNatInfo(entities); + sampleAndNat(existNatInfos,entities,NumConstant.TWO_STR,customerId,isSync); } - } }); } catch (Exception e) { @@ -556,6 +520,58 @@ public class DataSyncConfigServiceImpl extends BaseServiceImpl existInfo, List entities, String type, String customerId, String isSync){ + /** + * 采样结果不为空 + * 数据库采样时间+idCard+userId 存在的 不做操作 + * 数据库采样时间+idCard+userId 不存在的 新增 + * + * 检测结果不为空 + * 数据库采样时间+idCard+userId 存在的 做更新 + * 数据库采样时间+idCard+userId 不存在的 新增 + */ + entities.forEach(e -> existInfo.stream().filter(i -> i.getUserId().equals(e.getUserId()) && i.getIdCard().equals(e.getIdCard())).forEach(i -> e.setExistStatus(true))); + Map> groupByStatus = entities.stream().collect(Collectors.groupingBy(IcNatEntity::getExistStatus)); + if (CollectionUtils.isNotEmpty(groupByStatus.get(false))) { + for (List icNatEntities : ListUtils.partition(groupByStatus.get(false), NumConstant.FIVE_HUNDRED)) { + // 主表新增 + icNatService.insertBatch(icNatEntities); + // 组织关系表 + List relationEntities = new ArrayList<>(); + icNatEntities.forEach(ne -> { + if (ne.getIsResiUser().equals(NumConstant.ONE_STR)) { + IcNatRelationEntity e = new IcNatRelationEntity(); + e.setCustomerId(customerId); + e.setAgencyId(ne.getAgencyId()); + e.setPids(ne.getPids()); + e.setIcNatId(ne.getId()); + e.setUserType(isSync.equals(NumConstant.ONE_STR) ? "manualSync" : "sync"); + relationEntities.add(e); + } + }); + if (CollectionUtils.isNotEmpty(relationEntities)) { + icNatRelationService.insertBatch(relationEntities); + } + } + } + if (NumConstant.TWO_STR.equals(type)){ + if (CollectionUtils.isNotEmpty(groupByStatus.get(true))){ + for (List icNatEntities : ListUtils.partition(groupByStatus.get(true), NumConstant.ONE_HUNDRED)) { + icNatService.updateBatchNat(icNatEntities); + } + } + } + } + private class JudgeDealStatus { private boolean isNext; private DataSyncRecordDisabilityDTO dbDisablityEntity; diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcNatServiceImpl.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcNatServiceImpl.java index 3a9282b9bb..fcc03adf39 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcNatServiceImpl.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcNatServiceImpl.java @@ -464,6 +464,14 @@ public class IcNatServiceImpl extends BaseServiceImpl imp return baseDao.updateIsResiFlag(customerId,icResiUserId); } + @Override + @Transactional(rollbackFor = Exception.class) + public void updateBatchNat(List entities) { + if (CollectionUtils.isNotEmpty(entities)){ + baseDao.updateBatchNat(entities); + } + } + /** * 批量持久化 * @param entities diff --git a/epmet-user/epmet-user-server/src/main/resources/mapper/IcNatDao.xml b/epmet-user/epmet-user-server/src/main/resources/mapper/IcNatDao.xml index 0295d92f3f..ea4f9a8bc6 100644 --- a/epmet-user/epmet-user-server/src/main/resources/mapper/IcNatDao.xml +++ b/epmet-user/epmet-user-server/src/main/resources/mapper/IcNatDao.xml @@ -164,7 +164,7 @@ WHERE del_flag = '0' AND USER_ID = #{l.userId} AND ID_CARD = #{l.idCard} - AND UNIX_TIMESTAMP(NAT_TIME) = UNIX_TIMESTAMP(#{l.natTime}) + AND UNIX_TIMESTAMP(SAMPLE_TIME) = UNIX_TIMESTAMP(#{l.sampleTime}) @@ -189,4 +189,36 @@ m.ID_CARD = t.ID_CARD AND m.DEL_FLAG = '0' + + UPDATE ic_nat + + + + when USER_ID = #{l.userId} AND ID_CARD = #{l.idCard} then #{l.natTime} + + + + + when USER_ID = #{l.userId} AND ID_CARD = #{l.idCard} then #{l.natAddress} + + + + + when USER_ID = #{l.userId} AND ID_CARD = #{l.idCard} then #{l.natResult} + + + + + when USER_ID = #{l.userId} AND ID_CARD = #{l.idCard} then #{l.mobile} + + + UPDATED_TIME = NOW() + + WHERE DEL_FLAG = '0' + + AND USER_ID = #{l.userId} + AND ID_CARD = #{l.idCard} + + +