From 5a07a3130526217e5303c394c3463c35ef4cd32a Mon Sep 17 00:00:00 2001 From: chenhc <2369838784@qq.com> Date: Fri, 23 Feb 2024 18:05:00 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=8C=BB=E4=BF=9D=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../udidl/admin/dao/chs/YbHcflMapper.java | 8 + .../udidl/admin/res/chs/YbHcxxGgResponse.java | 140 ++++++++++++++++ .../udidl/admin/res/chs/YbHcxxResponse.java | 108 +++++++++++++ .../admin/service/chs/YbChsHttpClient.java | 153 +++++++++++++++++- .../admin/service/chs/YbHcflService.java | 52 ++++++ .../udidl/admin/thread/YbChsHcflTask.java | 52 ++++++ .../mybatis/mapper/chs/YbHcflMapper.xml | 63 ++++++++ 7 files changed, 572 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/glxp/udidl/admin/res/chs/YbHcxxGgResponse.java create mode 100644 src/main/java/com/glxp/udidl/admin/res/chs/YbHcxxResponse.java create mode 100644 src/main/java/com/glxp/udidl/admin/thread/YbChsHcflTask.java diff --git a/src/main/java/com/glxp/udidl/admin/dao/chs/YbHcflMapper.java b/src/main/java/com/glxp/udidl/admin/dao/chs/YbHcflMapper.java index be8d092..a484338 100644 --- a/src/main/java/com/glxp/udidl/admin/dao/chs/YbHcflMapper.java +++ b/src/main/java/com/glxp/udidl/admin/dao/chs/YbHcflMapper.java @@ -3,7 +3,15 @@ package com.glxp.udidl.admin.dao.chs; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.glxp.udidl.admin.entity.chs.YbHcflEntity; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; @Mapper public interface YbHcflMapper extends BaseMapper { + + int batchSaveOrUpdateBySpecificationCode(@Param("list") List list); + + } diff --git a/src/main/java/com/glxp/udidl/admin/res/chs/YbHcxxGgResponse.java b/src/main/java/com/glxp/udidl/admin/res/chs/YbHcxxGgResponse.java new file mode 100644 index 0000000..2045c83 --- /dev/null +++ b/src/main/java/com/glxp/udidl/admin/res/chs/YbHcxxGgResponse.java @@ -0,0 +1,140 @@ +package com.glxp.udidl.admin.res.chs; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +@NoArgsConstructor +@Data +public class YbHcxxGgResponse { + @JsonProperty("records") + private Integer records; + @JsonProperty("total") + private Integer total; + @JsonProperty("rows") + private List rows; + @JsonProperty("page") + private Integer page; + @JsonProperty("count") + private Integer count; + @JsonProperty("firstResult") + private Integer firstResult; + @JsonProperty("maxResults") + private Integer maxResults; + @JsonProperty("success") + private Boolean success; + @JsonProperty("result") + private String result; + @JsonProperty("conditions") + private ConditionsDTO conditions; + @JsonProperty("msg") + private String msg; + @JsonProperty("form") + private String form; + @JsonProperty("code") + private Integer code; + @JsonProperty("operCount") + private Integer operCount; + @JsonProperty("sord") + private String sord; + @JsonProperty("sidx") + private String sidx; + @JsonProperty("orderby") + private String orderby; + + @NoArgsConstructor + @Data + public static class ConditionsDTO { + @JsonProperty("productionCode") + private String productionCode; + @JsonProperty("specificationCode") + private String specificationCode; + } + + @NoArgsConstructor + @Data + public static class RowsDTO { + @JsonProperty("releaseVersion") + private Integer releaseVersion; + @JsonProperty("companyName") + private String companyName; + @JsonProperty("catalogname1") + private String catalogname1; + @JsonProperty("catalogname2") + private String catalogname2; + @JsonProperty("catalogname3") + private String catalogname3; + @JsonProperty("commonname") + private String commonname; + @JsonProperty("matrial") + private String matrial; + @JsonProperty("characteristic") + private String characteristic; + @JsonProperty("relationId") + private String relationId; + @JsonProperty("catalogCode") + private String catalogCode; + @JsonProperty("specificationCode") + private String specificationCode; + @JsonProperty("productionCode") + private String productionCode; + @JsonProperty("regcardid") + private String regcardid; + @JsonProperty("regcardnm") + private String regcardnm; + @JsonProperty("regcardName") + private String regcardName; + @JsonProperty("productid") + private String productid; + @JsonProperty("productName") + private String productName; + @JsonProperty("goodsid") + private String goodsid; + @JsonProperty("specification") + private String specification; + @JsonProperty("model") + private String model; + @JsonProperty("isUsing") + private Integer isUsing; + @JsonProperty("relationStatus") + private String relationStatus; + @JsonProperty("addUserId") + private String addUserId; + @JsonProperty("addUserName") + private String addUserName; + @JsonProperty("addTime") + private String addTime; + @JsonProperty("lastUpdateUserId") + private String lastUpdateUserId; + @JsonProperty("lastUpdateUserName") + private String lastUpdateUserName; + @JsonProperty("lastUpdateTime") + private String lastUpdateTime; + @JsonProperty("auditRemark") + private String auditRemark; + @JsonProperty("auditUserId") + private String auditUserId; + @JsonProperty("auditUserName") + private String auditUserName; + @JsonProperty("auditTime") + private String auditTime; + @JsonProperty("udiCode") + private String udiCode; + @JsonProperty("ggxhCode") + private String ggxhCode; + @JsonProperty("oldregcardnm") + private String oldregcardnm; + @JsonProperty("mapingCode") + private String mapingCode; + @JsonProperty("codeOld") + private String codeOld; + @JsonProperty("codeShow") + private String codeShow; + @JsonProperty("dataType") + private String dataType; + @JsonProperty("registrant") + private String registrant; + } +} diff --git a/src/main/java/com/glxp/udidl/admin/res/chs/YbHcxxResponse.java b/src/main/java/com/glxp/udidl/admin/res/chs/YbHcxxResponse.java new file mode 100644 index 0000000..b48372a --- /dev/null +++ b/src/main/java/com/glxp/udidl/admin/res/chs/YbHcxxResponse.java @@ -0,0 +1,108 @@ +package com.glxp.udidl.admin.res.chs; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +@NoArgsConstructor +@Data +public class YbHcxxResponse { + @JsonProperty("records") + private Integer records; + @JsonProperty("total") + private Integer total; + @JsonProperty("rows") + private List rows; + @JsonProperty("page") + private Integer page; + @JsonProperty("count") + private Integer count; + @JsonProperty("firstResult") + private Integer firstResult; + @JsonProperty("maxResults") + private Integer maxResults; + @JsonProperty("success") + private Boolean success; + @JsonProperty("result") + private String result; + @JsonProperty("conditions") + private ConditionsDTO conditions; + @JsonProperty("msg") + private String msg; + @JsonProperty("form") + private String form; + @JsonProperty("code") + private Integer code; + @JsonProperty("operCount") + private Integer operCount; + @JsonProperty("sord") + private String sord; + @JsonProperty("sidx") + private String sidx; + @JsonProperty("orderby") + private String orderby; + + @NoArgsConstructor + @Data + public static class ConditionsDTO { + @JsonProperty("specificationCode") + private String specificationCode; + } + + @NoArgsConstructor + @Data + public static class RowsDTO { + @JsonProperty("releaseVersion") + private Integer releaseVersion; + @JsonProperty("regcardName") + private String regcardName; + @JsonProperty("regcardnm") + private String regcardnm; + @JsonProperty("productName") + private String productName; + @JsonProperty("specification") + private String specification; + @JsonProperty("model") + private String model; + @JsonProperty("specificationCode") + private String specificationCode; + @JsonProperty("catalogname1") + private String catalogname1; + @JsonProperty("catalogname2") + private String catalogname2; + @JsonProperty("catalogname3") + private String catalogname3; + @JsonProperty("commonname") + private String commonname; + @JsonProperty("matrial") + private String matrial; + @JsonProperty("characteristic") + private String characteristic; + @JsonProperty("companyName") + private String companyName; + @JsonProperty("prodCount") + private String prodCount; + @JsonProperty("regCount") + private String regCount; + @JsonProperty("specCount") + private String specCount; + @JsonProperty("codeCount") + private String codeCount; + @JsonProperty("codeCounts") + private String codeCounts; + @JsonProperty("proCounts") + private String proCounts; + @JsonProperty("regCounts") + private String regCounts; + @JsonProperty("compCounts") + private String compCounts; + @JsonProperty("specCounts") + private String specCounts; + @JsonProperty("totals") + private String totals; + @JsonProperty("productionCode") + private String productionCode; + } +} diff --git a/src/main/java/com/glxp/udidl/admin/service/chs/YbChsHttpClient.java b/src/main/java/com/glxp/udidl/admin/service/chs/YbChsHttpClient.java index d70369d..faaf8da 100644 --- a/src/main/java/com/glxp/udidl/admin/service/chs/YbChsHttpClient.java +++ b/src/main/java/com/glxp/udidl/admin/service/chs/YbChsHttpClient.java @@ -3,23 +3,36 @@ package com.glxp.udidl.admin.service.chs; import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.TypeReference; +import com.alibaba.fastjson2.JSON; import com.glxp.udidl.admin.req.chs.YbHcflRequest; +import com.glxp.udidl.admin.res.chs.YbHcflResponse; +import com.glxp.udidl.admin.res.chs.YbHcxxGgResponse; +import com.glxp.udidl.admin.res.chs.YbHcxxResponse; +import com.glxp.udidl.admin.res.tyapi.CompanyBaseResponse; +import com.glxp.udidl.admin.res.tyapi.ContactResponse; import com.glxp.udidl.admin.res.tyapi.SupplierResponse; import com.glxp.udidl.admin.util.OkHttpCli; import lombok.extern.slf4j.Slf4j; +import okhttp3.FormBody; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; +import org.apache.commons.lang3.exception.ExceptionUtils; import org.springframework.stereotype.Service; import javax.annotation.Resource; +import java.io.*; +import java.net.HttpURLConnection; +import java.net.URL; +import java.nio.charset.Charset; import java.util.HashMap; +import java.util.Iterator; import java.util.Map; @Slf4j @Service public class YbChsHttpClient { - @Resource - OkHttpCli okHttpCli; - /** * 获取耗材分类目录 */ @@ -27,14 +40,146 @@ public class YbChsHttpClient { /** * 获取医用耗材信息 */ - String getYyhcxxUrl = "https://code.nhsa.gov.cn/hc/stdPublishData/getNewPublishRelationDataList.html"; + String getHcxxUrl = "https://code.nhsa.gov.cn/hc/stdPublishData/getNewPublishRelationDataList.html"; /** * 获取医用耗材规格信息 */ String getHcxxGgUrl = "https://code.nhsa.gov.cn/hc/stdYgbData/getPublicHcDataList.html"; + //获取HCF列表 + public YbHcflResponse getYbHcflList(Integer pageNum, Integer pageSize) { + Map params = new HashMap<>(); + params.put("_search",false); + params.put("nd",System.currentTimeMillis()); + params.put("rows", pageSize); + params.put("page", pageNum); + params.put("sord", "asc"); + + String response = sendPost(getHcflUrl+getParams(params), "",Charset.forName("utf-8")); + YbHcflResponse baseResponse = JSONObject.parseObject(response, new TypeReference() { + }); + return baseResponse; + } + + //获取Hcxx列表 + public YbHcxxResponse getYbHcxxList(Integer pageNum, Integer pageSize) { + Map params = new HashMap<>(); + params.put("_search",false); + params.put("nd",System.currentTimeMillis()); + params.put("rows", pageSize); + params.put("page", pageNum); + params.put("sord", "asc"); + params.put("specificationCode", "C"); + + String response = sendPost(getHcxxUrl+getParams(params), "",Charset.forName("utf-8")); + YbHcxxResponse baseResponse = JSONObject.parseObject(response, new TypeReference() { + }); + return baseResponse; + } + + //获取HcxxGg列表 + public YbHcxxGgResponse getYbHcxxGgList(String specificationCode,Integer pageNum, Integer pageSize) { + Map params = new HashMap<>(); + params.put("_search",false); + params.put("nd",System.currentTimeMillis()); + params.put("rows", pageSize); + params.put("page", pageNum); + params.put("sord", "asc"); + params.put("specificationCode", specificationCode); + + String response = sendPost(getHcxxGgUrl+getParams(params), "",Charset.forName("utf-8")); + YbHcxxGgResponse baseResponse = JSONObject.parseObject(response, new TypeReference() { + }); + return baseResponse; + } + + public static void main(String[] args) { + YbChsHttpClient ybChsHttpClient = new YbChsHttpClient(); + YbHcxxGgResponse ybHcflList = ybChsHttpClient.getYbHcxxGgList("C0101010010100103941",1, 100); + System.out.println(ybHcflList); + } + + + /** + * @param paramsMap + * @return + */ + private static String getParams(Map paramsMap) { + String params = "?"; + Iterator iterator = paramsMap.keySet().iterator(); + while(iterator.hasNext()) { + String key = iterator.next(); + params += key + "=" + paramsMap.get(key) + "&"; + } + params = params.substring(0, params.length() - 1); + return params; + } + + + public static String sendPost(String url, String param, Charset charset) { + try { + URL httpurl = new URL(url); + //打开和url的连接 + HttpURLConnection httpConn = (HttpURLConnection) httpurl.openConnection(); + //设置通用的请求头属性 + httpConn.setRequestMethod("POST"); + httpConn.setRequestProperty("accept", "*/*"); + httpConn.setRequestProperty("connection", "Keep-Alive"); + httpConn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"); + httpConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=" + charset.name()); + /*httpConn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; " + + "Windows NT 5.1; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)");*/ + // 发送POST请求必须设置如下两行 否则会抛异常(java.net.ProtocolException: cannot write to a URLConnection if doOutput=false - call setDoOutput(true)) + httpConn.setDoOutput(true); + httpConn.setDoInput(true); + httpConn.setUseCaches(false); + /*httpConn.setRequestMethod("POST"); + httpConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=" + charset.name());*/ + httpConn.connect(); + OutputStream outputStream = httpConn.getOutputStream(); + PrintWriter out = new PrintWriter(outputStream); + //print在方法内也是调用的write方法,多了null的判断逻辑 + out.print(param); + //out.write(param); + out.flush(); + out.close(); + InputStream inputStream = httpConn.getInputStream(); + BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, charset.name())); + StringBuffer stringBuffer = new StringBuffer(); + String line = null; + while ((line = bufferedReader.readLine()) != null) { + stringBuffer.append(line); + } + String resp = stringBuffer.toString(); + // System.out.println(resp); + if (stringBuffer != null) { + try { + bufferedReader.close(); + } catch (IOException var18) { + var18.printStackTrace(); + } + } + if (inputStream != null) { + try { + inputStream.close(); + } catch (IOException var17) { + var17.printStackTrace(); + } + } + if (outputStream != null) { + try { + outputStream.close(); + } catch (IOException var17) { + var17.printStackTrace(); + } + } + return resp; + } catch (IOException e) { + throw new RuntimeException(String.format("url:%s,param:%s,message:%s", url, param, e.getMessage()), e); + } + } } diff --git a/src/main/java/com/glxp/udidl/admin/service/chs/YbHcflService.java b/src/main/java/com/glxp/udidl/admin/service/chs/YbHcflService.java index 3514428..4a812ee 100644 --- a/src/main/java/com/glxp/udidl/admin/service/chs/YbHcflService.java +++ b/src/main/java/com/glxp/udidl/admin/service/chs/YbHcflService.java @@ -1,10 +1,62 @@ package com.glxp.udidl.admin.service.chs; +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.collection.CollUtil; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.glxp.udidl.admin.entity.tyapi.TySupplierEntity; +import com.glxp.udidl.admin.res.chs.YbHcflResponse; +import com.glxp.udidl.admin.res.tyapi.SupplierResponse; +import com.glxp.udidl.admin.util.DateUtil; +import com.glxp.udidl.admin.util.IntUtil; +import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.glxp.udidl.admin.dao.chs.YbHcflMapper; import com.glxp.udidl.admin.entity.chs.YbHcflEntity; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + @Service public class YbHcflService extends ServiceImpl { + @Resource + YbChsHttpClient ybChsHttpClient; + @Resource + YbHcflMapper ybHcflMapper; + + /** + * 更新数据库的YbHcf列表数据 + * 以一定大小页面 分批对比数据库 医用耗材分类代码 是否存在 不存在进行新增 + */ + public void updateYbHcfList(){ + Integer pageNum = 1; + Integer pageSize = 200; + + //1、获取数据 + YbHcflResponse ybHcflResponse = ybChsHttpClient.getYbHcflList(pageNum, pageSize); + Integer total = ybHcflResponse.getTotal(); + //处理第一批数据 + processUpdates(ybHcflResponse); + //处理后续数据 + if (total>pageNum){ + for (int i = 2; i <= total ; i++) { + processUpdates(ybChsHttpClient.getYbHcflList(i, pageSize)); + } + } + } + + /** + * 处理比对更新 + * @param ybHcflResponse + */ + private void processUpdates(YbHcflResponse ybHcflResponse) { + List list = ybHcflResponse.getRows(); + List ybHcflEntities = BeanUtil.copyToList(list, YbHcflEntity.class); + ybHcflMapper.batchSaveOrUpdateBySpecificationCode(ybHcflEntities); + } + + } diff --git a/src/main/java/com/glxp/udidl/admin/thread/YbChsHcflTask.java b/src/main/java/com/glxp/udidl/admin/thread/YbChsHcflTask.java new file mode 100644 index 0000000..87a0128 --- /dev/null +++ b/src/main/java/com/glxp/udidl/admin/thread/YbChsHcflTask.java @@ -0,0 +1,52 @@ +package com.glxp.udidl.admin.thread; + +import com.glxp.udidl.admin.constant.Constant; +import com.glxp.udidl.admin.dao.info.ScheduledMapper; +import com.glxp.udidl.admin.entity.info.ScheduledEntity; +import com.glxp.udidl.admin.entity.udid.JobLog; +import com.glxp.udidl.admin.req.info.ScheduledRequest; +import com.glxp.udidl.admin.res.BaseResponse; +import com.glxp.udidl.admin.service.chs.YbHcflService; +import com.glxp.udidl.admin.util.DateUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.scheduling.annotation.SchedulingConfigurer; +import org.springframework.scheduling.config.ScheduledTaskRegistrar; +import org.springframework.scheduling.support.CronTrigger; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; + +@Component +@EnableScheduling +public class YbChsHcflTask implements SchedulingConfigurer { + + @Resource + private ScheduledMapper scheduledDao; + + @Resource + private YbHcflService ybHcflService; + + final Logger logger = LoggerFactory.getLogger(DownloadProductInfoTask.class); + + @Override + public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) { + scheduledTaskRegistrar.addTriggerTask(() -> process(), + triggerContext -> { + ScheduledRequest scheduledRequest = new ScheduledRequest(); + scheduledRequest.setCronName("ybChsHcflTask"); + ScheduledEntity scheduledEntity = scheduledDao.findScheduled(scheduledRequest); + String cron = scheduledEntity.getCron(); + if (cron.isEmpty()) { + logger.error("cron is null"); + } + return new CronTrigger(cron).nextExecutionTime(triggerContext); + }); + } + + private void process() { + System.out.println("开始执行更新医保数据"); + ybHcflService.updateYbHcfList(); + } +} diff --git a/src/main/resources/mybatis/mapper/chs/YbHcflMapper.xml b/src/main/resources/mybatis/mapper/chs/YbHcflMapper.xml index 1b0899f..865a9e6 100644 --- a/src/main/resources/mybatis/mapper/chs/YbHcflMapper.xml +++ b/src/main/resources/mybatis/mapper/chs/YbHcflMapper.xml @@ -35,4 +35,67 @@ characteristic, separateCharges, paymentType, paymentStandard, isusing, specificationType, productStatusS, productCount, compCount, regCount, goodsCount + + + + INSERT INTO + yb_hcfl + ( + specificationCode, specificationId, catalogcode, catalogname1, catalogname2, + catalogname3, commonnamecode, commonname, matrialcode, matrial, characteristiccode, + characteristic, separateCharges, paymentType, paymentStandard, isusing, specificationType, + productStatusS, productCount, compCount, regCount, goodsCount + ) + VALUES + + (#{item.specificationCode}, + #{item.specificationId}, + #{item.catalogcode}, + #{item.catalogname1}, + #{item.catalogname2}, + #{item.catalogname3}, + #{item.commonnamecode}, + #{item.commonname}, + #{item.matrialcode}, + #{item.matrial}, + #{item.characteristiccode}, + #{item.characteristic}, + #{item.separateCharges}, + #{item.paymentType}, + #{item.paymentStandard}, + #{item.isusing}, + #{item.specificationType}, + #{item.productStatusS}, + #{item.productCount}, + #{item.compCount}, + #{item.regCount}, + #{item.goodsCount}) + + ON DUPLICATE KEY UPDATE + specificationId = VALUES(specificationId), + catalogcode = VALUES(catalogcode), + catalogname1 = VALUES(catalogname1), + catalogname2 = VALUES(catalogname2), + + catalogname3 = VALUES(catalogname3), + commonnamecode = VALUES(commonnamecode), + commonname = VALUES(commonname), + matrialcode = VALUES(matrialcode), + matrial = VALUES(matrial), + characteristiccode = VALUES(characteristiccode), + + characteristic = VALUES(characteristic), + separateCharges = VALUES(separateCharges), + paymentType = VALUES(paymentType), + paymentStandard = VALUES(paymentStandard), + isusing = VALUES(isusing), + specificationType = VALUES(specificationType), + + productStatusS = VALUES(productStatusS), + productCount = VALUES(productCount), + compCount = VALUES(compCount), + regCount = VALUES(regCount), + goodsCount = VALUES(goodsCount) + +