diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/jdbc/config/JdbcTemplateConfig.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/jdbc/config/JdbcTemplateConfig.java index 4f8be141f3..1c26f1d808 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/jdbc/config/JdbcTemplateConfig.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/jdbc/config/JdbcTemplateConfig.java @@ -6,6 +6,7 @@ import org.springframework.boot.autoconfigure.AutoConfigurationPackage; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; import javax.sql.DataSource; @@ -27,4 +28,9 @@ public class JdbcTemplateConfig { DataSource yantaiLantuDataSource = jdbcDataSourceConfig.createYantaiLantuDataSource(); return new JdbcTemplate(yantaiLantuDataSource); } + + @Bean + NamedParameterJdbcTemplate yantaiNamedParamLantuJdbcTemplate() { + return new NamedParameterJdbcTemplate(yantaiLantuJdbcTemplate()); + } } \ No newline at end of file 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 6d4c42690d..e771aa4968 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 @@ -41,6 +41,7 @@ import org.apache.commons.collections4.ListUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -76,6 +77,9 @@ public class DataSyncConfigServiceImpl extends BaseServiceImpl resiInfos, String customerId, String isSync) { List> resiInfobatchs = ListUtils.partition(resiInfos, 50); for (List resibatch : resiInfobatchs) { - // 50个一批,来处理他们的核酸信息,太多怕给数据库查崩了。 - yantaiHsjcByDbViewBatch(resibatch, customerId, isSync); + // n个一批,来处理他们的核酸信息,太多怕给数据库查崩了。 + try { + yantaiHsjcByDbViewPartition(resibatch, customerId, isSync); + } catch (Exception e) { + String errorMsg = ExceptionUtils.getErrorStackTrace(e); + log.error("【更新核酸检测信息(from 兰图)】失败,信息:{}", errorMsg); + } } } /** - * 50个一批,来处理他们的核酸信息,太多怕给数据库查崩了。 + * n个一批,来处理他们的核酸信息,太多怕给数据库查崩了。 * @param resiInfos * @param customerId * @param isSync */ - public void yantaiHsjcByDbViewBatch(List resiInfos, String customerId, String isSync) { + public void yantaiHsjcByDbViewPartition(List resiInfos, String customerId, String isSync) { // 将居民信息转化为的map Map idCardAndResiInfo = resiInfos.stream().collect(Collectors.toMap(resi -> resi.getIdCard(), Function.identity())); - Set idCards = idCardAndResiInfo.keySet();//resiInfos.stream().map(resi -> resi.getIdCard()).collect(Collectors.toList()); - // String idCardsStr = "''" + String.join("','", idCards) + "''"; + List idCards = new ArrayList<>(idCardAndResiInfo.keySet()); // 1.获取核酸采样信息 - String sql = "select id, name,card_no, create_time, realname from hscyxxb where card_no in (:idCards) order by create_time desc"; - HashMap args = new HashMap<>(); - args.put("idCards", idCards); + Map args = new HashMap<>(); + args.put("idcards", idCards); + + log.info("【更新核酸检测信息(from 兰图)】本批次身份证号为:{}", String.join(",", idCards)); + + // 2.=====================核酸采样========================= // 这一批居民的核酸采样列表 - List> hscyList = yantaiJdbcTemplate.queryForList(sql, args); + List> hscyList = yantaiNamedParamLantuJdbcTemplate.queryForList( + "select id, name,card_no, create_time, realname from hscyxxb where card_no in (:idcards) order by create_time desc", args); if (CollectionUtils.isNotEmpty(hscyList)) { List entities = new ArrayList<>(); - hscyList.forEach(sampleInfo -> { + hscyList.forEach(resiHscyInfo -> { // 从视图中获取到的核酸采样相关信息 - String name = (String) sampleInfo.get("name"); - String cardNo = (String) sampleInfo.get("card_no"); - Date createTime = (Date) sampleInfo.get("create_time"); + String name = (String) resiHscyInfo.get("name"); + String cardNo = (String) resiHscyInfo.get("card_no"); + String createTime = (String) resiHscyInfo.get("create_time"); // 本地数据库中,居民信息 NatUserInfoResultDTO currentResiInfo = idCardAndResiInfo.get(cardNo); @@ -827,8 +839,7 @@ public class DataSyncConfigServiceImpl extends BaseServiceImpl> hsjcResultList = yantaiNamedParamLantuJdbcTemplate.queryForList( + "select name, telephone, card_no, test_time, SAMPLE_TIME, SAMPLE_RESULT_PCR, SAMPLING_ORG_PCR from hsjcxxb where card_no in (:idcards)", args); + if (CollectionUtils.isNotEmpty(hsjcResultList)) { + List entities = new ArrayList<>(); + hsjcResultList.forEach(natResult -> { + // 从视图中获取到的核酸采样相关信息 + String name = (String) natResult.get("name"); + String cardNo = (String) natResult.get("card_no"); + String testTime = (String) natResult.get("test_time"); + String telephone = (String) natResult.get("telephone"); + String sampleTime = (String) natResult.get("SAMPLE_TIME"); + String sampleResultPcr = (String) natResult.get("SAMPLE_RESULT_PCR"); + String samplingOrgPcr = (String) natResult.get("SAMPLING_ORG_PCR"); + + // 本地数据库中,居民信息 + NatUserInfoResultDTO currentResiInfo = idCardAndResiInfo.get(cardNo); + + IcNatEntity e = new IcNatEntity(); + e.setCustomerId(customerId); + e.setIsResiUser(StringUtils.isBlank(currentResiInfo.getUserId()) ? NumConstant.ZERO_STR : NumConstant.ONE_STR); + e.setUserId(currentResiInfo.getUserId()); + e.setUserType(isSync.equals(NumConstant.ONE_STR) ? "manualSync" : "sync"); + e.setName(StringUtils.isNotBlank(name) ? name : ""); + e.setMobile(StringUtils.isNotBlank(telephone) ? telephone : ""); + e.setIdCard(StringUtils.isNotBlank(cardNo) ? cardNo : ""); + e.setNatTime(DateUtils.parseDate(testTime, DateUtils.DATE_TIME_PATTERN)); + e.setSampleTime(DateUtils.parseDate(sampleTime, DateUtils.DATE_TIME_PATTERN)); + String resultPcr = sampleResultPcr; + //检测结果 转换 我们 0:阴性 1:阳性, 他们 :1:阳性,2:阴性 + e.setNatResult(NumConstant.ZERO_STR); + if (NumConstant.ONE_STR.equals(resultPcr)) { + e.setNatResult(NumConstant.ONE_STR); + } + e.setNatAddress(samplingOrgPcr); + e.setAgencyId(currentResiInfo.getAgencyId()); + e.setPids(currentResiInfo.getPids()); + e.setAttachmentType(""); + e.setAttachmentUrl(""); + entities.add(e); + }); + if (CollectionUtils.isNotEmpty(entities)) { + List existNatInfos = icNatDao.getExistNatInfo(entities); + sampleAndNat(existNatInfos,entities,NumConstant.TWO_STR,customerId,isSync); + } + } } } diff --git a/epmet-user/epmet-user-server/src/main/resources/bootstrap.yml b/epmet-user/epmet-user-server/src/main/resources/bootstrap.yml index 184c73ee7b..0f824c7155 100644 --- a/epmet-user/epmet-user-server/src/main/resources/bootstrap.yml +++ b/epmet-user/epmet-user-server/src/main/resources/bootstrap.yml @@ -56,9 +56,9 @@ spring: yantai: lantu: driver-class-name: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://localhost:3306/epmet_gov_voice?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai - username: root - password: root + url: jdbc:mysql://10.2.2.61:3367/epmet_gov_voice?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai + username: yilian + password: 1qaz2wsx initial-size: 10 max-active: 100 min-idle: 10