From e86612240bb796317df8d579f9cd2795ce6aa702 Mon Sep 17 00:00:00 2001 From: qiuyt Date: Fri, 22 Nov 2024 14:57:55 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AE=A1=E7=90=86=E7=B3=BB=E7=BB=9F=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E6=89=AB=E7=A0=81=E7=9A=84=E6=97=B6=E5=80=99=E5=A6=82?= =?UTF-8?q?=E6=9E=9C=E7=A0=81=E5=85=B3=E8=81=94=E5=85=B3=E7=B3=BB=E6=89=BE?= =?UTF-8?q?=E4=B8=8D=E5=88=B0=E9=82=A3=E5=B0=B1=E8=B0=83=E7=94=A8=E5=A4=96?= =?UTF-8?q?=E7=BD=91=E7=9A=84=E9=98=BF=E9=87=8C=E6=8E=A5=E5=8F=A3=E8=BF=9B?= =?UTF-8?q?=E8=A1=8C=E6=8F=92=E5=85=A5=E5=85=B3=E8=81=94=E5=85=B3=E7=B3=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../glxp/api/entity/system/CompanyEntity.java | 6 +- .../glxp/api/http/sync/SpGetHttpClient.java | 14 ++ .../AlihealthRelCodeInsertReqeust.java | 17 +++ .../AlihealthKytCommonParametersResponse.java | 15 ++ .../AlihealthKytSinglerelationResponse.java | 143 ++++++++++++++++++ .../service/collect/RelCodeBatchService.java | 81 +++++++++- .../mybatis/mapper/system/CompanyDao.xml | 6 +- src/main/resources/schemas/schema_v2.4.sql | 4 + 8 files changed, 280 insertions(+), 6 deletions(-) create mode 100644 src/main/java/com/glxp/api/req/alihealth/AlihealthRelCodeInsertReqeust.java create mode 100644 src/main/java/com/glxp/api/res/alihealth/AlihealthKytCommonParametersResponse.java create mode 100644 src/main/java/com/glxp/api/res/alihealth/AlihealthKytSinglerelationResponse.java diff --git a/src/main/java/com/glxp/api/entity/system/CompanyEntity.java b/src/main/java/com/glxp/api/entity/system/CompanyEntity.java index c25684b33..37c95d01e 100644 --- a/src/main/java/com/glxp/api/entity/system/CompanyEntity.java +++ b/src/main/java/com/glxp/api/entity/system/CompanyEntity.java @@ -11,7 +11,9 @@ public class CompanyEntity { private String addr; //住所地址 private String productAddr; //生产地址 private String classes; //企业类别 //企业类别:1.生产企业,2.流通企业,3。医疗机构 - private String appId; - private String appSecret; + private String appId; // 阿里AppKey + private String appSecret; // 阿里应用密文 private String auditComment; + private String refEntId; // 接口调用企业的唯一标识 + } diff --git a/src/main/java/com/glxp/api/http/sync/SpGetHttpClient.java b/src/main/java/com/glxp/api/http/sync/SpGetHttpClient.java index 042360e25..a58fc31ce 100644 --- a/src/main/java/com/glxp/api/http/sync/SpGetHttpClient.java +++ b/src/main/java/com/glxp/api/http/sync/SpGetHttpClient.java @@ -18,6 +18,7 @@ import com.glxp.api.entity.sync.SyncEditLogEntity; import com.glxp.api.entity.sync.SyncEditTypeEntity; import com.glxp.api.entity.system.SyncDataSetEntity; import com.glxp.api.idc.service.FileService; +import com.glxp.api.req.alihealth.AlihealthRelCodeInsertReqeust; import com.glxp.api.req.basic.BasicDataRequest; import com.glxp.api.req.basic.DeleteBasicDataRequest; import com.glxp.api.req.basic.ProductInfoFilterRequest; @@ -29,6 +30,7 @@ import com.glxp.api.req.sync.OrderStatusFilterRequest; import com.glxp.api.req.sync.SyncUpLoadRequest; import com.glxp.api.req.system.DeleteRequest; import com.glxp.api.res.PageSimpleResponse; +import com.glxp.api.res.alihealth.AlihealthKytSinglerelationResponse; import com.glxp.api.res.inout.RefreshInoiceResponse; import com.glxp.api.res.inv.InvPreProductResponse; import com.glxp.api.res.inv.InvPreinProductResponse; @@ -657,4 +659,16 @@ public class SpGetHttpClient { }); return response; } + //转发更新多码融合 + public BaseResponse relCodeInsert(AlihealthRelCodeInsertReqeust alihealthRelCodeInsertReqeust) { + String json = JSONUtil.toJsonStr(alihealthRelCodeInsertReqeust); + String result = okHttpCli.doPostJson(getIpUrl() + "/directToSpms" + "/spms/alihealth/relCodeInsert", json, buildHeader()); + BaseResponse response = + JSONObject.parseObject(result, new TypeReference() { + }); + if(response == null){ + return ResultVOUtils.error("访问供应商平台访问不到"); + } + return response; + } } diff --git a/src/main/java/com/glxp/api/req/alihealth/AlihealthRelCodeInsertReqeust.java b/src/main/java/com/glxp/api/req/alihealth/AlihealthRelCodeInsertReqeust.java new file mode 100644 index 000000000..1d99e94dc --- /dev/null +++ b/src/main/java/com/glxp/api/req/alihealth/AlihealthRelCodeInsertReqeust.java @@ -0,0 +1,17 @@ +package com.glxp.api.req.alihealth; + +import lombok.Data; + +@Data +public class AlihealthRelCodeInsertReqeust { + /** + * 往来单位名称 + */ + private String name; + private String appKey; + private String appSecret; + + private String customerId; + private String code; + private String refEntId; +} diff --git a/src/main/java/com/glxp/api/res/alihealth/AlihealthKytCommonParametersResponse.java b/src/main/java/com/glxp/api/res/alihealth/AlihealthKytCommonParametersResponse.java new file mode 100644 index 000000000..b337d9716 --- /dev/null +++ b/src/main/java/com/glxp/api/res/alihealth/AlihealthKytCommonParametersResponse.java @@ -0,0 +1,15 @@ +package com.glxp.api.res.alihealth; + +import lombok.Data; + +@Data +public class AlihealthKytCommonParametersResponse { + + private String msg_code; + private String msg_info; + private String response_success; + + + + +} diff --git a/src/main/java/com/glxp/api/res/alihealth/AlihealthKytSinglerelationResponse.java b/src/main/java/com/glxp/api/res/alihealth/AlihealthKytSinglerelationResponse.java new file mode 100644 index 000000000..5f4b3550c --- /dev/null +++ b/src/main/java/com/glxp/api/res/alihealth/AlihealthKytSinglerelationResponse.java @@ -0,0 +1,143 @@ +package com.glxp.api.res.alihealth; + +import cn.hutool.json.JSONArray; +import cn.hutool.json.JSONObject; +import cn.hutool.json.JSONUtil; +import com.glxp.api.entity.collect.RelCodeBatch; +import com.glxp.api.entity.collect.RelCodeDetail; +import lombok.Data; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.BeanUtils; + +import java.util.*; + +@Data +public class AlihealthKytSinglerelationResponse extends AlihealthKytCommonParametersResponse{ + private JSONObject base_infos_d_t_o; + private String code; + private JSONObject code_active_info_d_t_o; + private JSONObject code_relation_list; + private String is_smallest; + private JSONObject pkg_info_d_t_o; + private JSONObject produce_info_list; + + private String refEntId; + public AlihealthKytSinglerelationResponse() { + + } + + public AlihealthKytSinglerelationResponse(String json) { + // 初始化请求的值 + JSONObject jsonObject = JSONUtil.parseObj(json); + JSONObject jsonObjectResult = null; + for (String s : jsonObject.keySet()) { + jsonObjectResult = jsonObject.getJSONObject(s).getJSONObject("result"); + + } + AlihealthKytCommonParametersResponse alihealthKytCommonParametersResponse = JSONUtil.toBean(jsonObjectResult.toString(), + AlihealthKytCommonParametersResponse.class); + BeanUtils.copyProperties(alihealthKytCommonParametersResponse,this); + if(StringUtils.isNotEmpty(this.getMsg_info()) + && this.getMsg_info().equals("调用成功") + ){ + this.disposeResult(jsonObjectResult); + } + + } + public void disposeResult(JSONObject jsonObjectResult){ + JSONArray jsonArray = jsonObjectResult.getJSONObject("model_list").getJSONArray("code_relation_dto"); + JSONObject codeRelationDto = (JSONObject) jsonArray.get(0); + if (!Objects.isNull(codeRelationDto)) { + this.setBase_infos_d_t_o(codeRelationDto.getJSONObject("base_infos_d_t_o")); + this.setCode(codeRelationDto.getStr("code")); + this.setCode_active_info_d_t_o(codeRelationDto.getJSONObject("code_active_info_d_t_o")); + this.setCode_relation_list(codeRelationDto.getJSONObject("code_relation_list")); + this.setIs_smallest(codeRelationDto.getStr("is_smallest")); + this.setPkg_info_d_t_o(codeRelationDto.getJSONObject("pkg_info_d_t_o")); + this.setProduce_info_list(codeRelationDto.getJSONObject("produce_info_list")); + } + } + public RelCodeBatch disposeRelCodeBatch(String customerId){ + JSONArray jsonArrayBaseInfoDto = this.getBase_infos_d_t_o().getJSONObject("base_info_list").getJSONArray("base_info_dto"); + JSONObject jsonObject = (JSONObject) jsonArrayBaseInfoDto.get(0); + RelCodeBatch relCodeBatch = new RelCodeBatch(); + List> jsonArray = (List) this.getCode_relation_list().get("code_info"); + Integer oneLevelCount = 0; + Integer twoLevelCount = 0; + Integer threeLevelCount = 0; + String parentCode = null; + if (jsonArray != null && jsonArray.size() > 0) { + parentCode = jsonArray.get(0).get("parent_code"); + relCodeBatch.setCurCode(parentCode); + + for (Map map : jsonArray) { + switch (map.get("code_level")) { + case "1": + oneLevelCount++; + break; + case "2": + twoLevelCount++; + break; + case "3": + threeLevelCount++; + break; + } + } + } +// relCodeBatch.setId(); + relCodeBatch.setProductCode(parentCode); + relCodeBatch.setSubTypeNo(jsonObject.getStr("relation_type")); + relCodeBatch.setCascadeRatio(jsonObject.getStr("pkg_ratio")); + relCodeBatch.setPackageSpec(jsonObject.getStr("pkg_spec")); +// relCodeBatch.setComment(); + relCodeBatch.setBatchNo(jsonObject.getStr("produce_batch_no")); + relCodeBatch.setMadeDate(jsonObject.getStr("produce_date")); + relCodeBatch.setValidateDate(jsonObject.getStr("exprie_date")); + relCodeBatch.setWorkShop(jsonObject.getStr("exprie_date")); +// relCodeBatch.setLineName(); + relCodeBatch.setLineManager(jsonObject.getStr("oper_ic_name")); +// relCodeBatch.setCreateTime(); +// relCodeBatch.setCreateUser(); + relCodeBatch.setUpdateTime(new Date()); + relCodeBatch.setUpdateUser(customerId); + relCodeBatch.setUploadFlagUp(0); + relCodeBatch.setUploadFlagDown(0); + relCodeBatch.setParentCode(null); +// relCodeBatch.setErpId(); + + relCodeBatch.setOneLevelCount(oneLevelCount); + relCodeBatch.setTwoLevelCount(twoLevelCount); + relCodeBatch.setThreeLevelCount(threeLevelCount); + + return relCodeBatch; + } + + + public List disposeRelRodeDetailList(Integer batchIdFk) { + List list = new ArrayList<>(); + List> jsonArray = (List) this.getCode_relation_list().get("code_info"); + if (jsonArray != null && jsonArray.size() > 0) { + for (Map map : jsonArray) { + if (!Objects.isNull(map)) { + RelCodeDetail relCodeDetail = new RelCodeDetail(); + relCodeDetail.setCurCode(map.get("code")); + relCodeDetail.setPackLayer(Integer.valueOf(map.get("code_level"))); + relCodeDetail.setParentCode(map.get("parent_code")); + Integer flag = null; + switch (map.get("status")) { + case "I": + flag = 1; + break; + case "O": + flag = 0; + break; + } + relCodeDetail.setFlag(flag); + relCodeDetail.setBatchIdFk(batchIdFk); + list.add(relCodeDetail); + } + } + } + return list; + } +} diff --git a/src/main/java/com/glxp/api/service/collect/RelCodeBatchService.java b/src/main/java/com/glxp/api/service/collect/RelCodeBatchService.java index 2d2cbe054..02ec959a1 100644 --- a/src/main/java/com/glxp/api/service/collect/RelCodeBatchService.java +++ b/src/main/java/com/glxp/api/service/collect/RelCodeBatchService.java @@ -6,24 +6,35 @@ import cn.hutool.core.io.FileUtil; import cn.hutool.core.thread.ThreadUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.XmlUtil; +import cn.hutool.json.JSONUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.github.pagehelper.PageHelper; +import com.glxp.api.common.res.BaseResponse; import com.glxp.api.dao.inout.IoCodeTempDao; import com.glxp.api.entity.auth.AuthAdmin; +import com.glxp.api.entity.basic.BasicCorpEntity; import com.glxp.api.entity.basic.ProductInfoEntity; import com.glxp.api.entity.basic.UdiEntity; import com.glxp.api.entity.basic.UdiProductEntity; import com.glxp.api.entity.collect.RelCodeDetail; import com.glxp.api.entity.inout.IoCodeTempEntity; +import com.glxp.api.entity.system.CompanyEntity; import com.glxp.api.exception.JsonException; +import com.glxp.api.http.sync.SpGetHttpClient; import com.glxp.api.http.sync.SpsDirectClient; +import com.glxp.api.req.alihealth.AlihealthRelCodeInsertReqeust; import com.glxp.api.req.collect.RelCodeBatchRequest; import com.glxp.api.req.collect.RelCodeDetailRequest; +import com.glxp.api.res.alihealth.AlihealthKytSinglerelationResponse; import com.glxp.api.res.collect.RelCodeBatchResponse; import com.glxp.api.res.collect.RelCodeDetailByParentCodeResponse; import com.glxp.api.service.auth.CustomerService; import com.glxp.api.service.basic.ProductInfoService; import com.glxp.api.service.basic.UdiProductService; +import com.glxp.api.service.basic.impl.BasicCorpServiceImpl; +import com.glxp.api.service.system.impl.CompanyServiceImpl; +import com.glxp.api.util.StringUtils; import com.glxp.api.util.udi.FilterUdiUtils; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.BeanUtils; @@ -53,6 +64,12 @@ public class RelCodeBatchService extends ServiceImpl ioCodeTempEntities = ioCodeTempDao.selectList(new LambdaQueryWrapper().eq(IoCodeTempEntity::getCode, parentCode)); if (CollUtil.isNotEmpty(ioCodeTempEntities)) { - + IoCodeTempEntity codeTempEntity = ioCodeTempEntities.get(0); //1、排除掉层级是1的 UdiEntity udi = FilterUdiUtils.getUdi(parentCode); if (udi == null) @@ -294,6 +312,65 @@ public class RelCodeBatchService extends ServiceImpl navList = this.list(new LambdaQueryWrapper() .eq(RelCodeBatch::getParentCode, parentCode)); + + // + if(navList == null || navList.size() == 0 ){ + CompanyEntity companyEntity = companyService.findCompany(); + BasicCorpEntity basicCorpEntity = basicCorpService.selectByErpId(codeTempEntity.getSupId()); + AlihealthRelCodeInsertReqeust alihealthRelCodeInsertReqeust = new AlihealthRelCodeInsertReqeust(); + alihealthRelCodeInsertReqeust.setName(basicCorpEntity.getName()); + alihealthRelCodeInsertReqeust.setAppKey(companyEntity.getAppId()); + alihealthRelCodeInsertReqeust.setAppSecret(companyEntity.getAppSecret()); + alihealthRelCodeInsertReqeust.setCustomerId(codeTempEntity.getSupId()); + alihealthRelCodeInsertReqeust.setCode(parentCode); + alihealthRelCodeInsertReqeust.setRefEntId(companyEntity.getRefEntId()); + + BaseResponse baseResponse = spGetHttpClient.relCodeInsert(alihealthRelCodeInsertReqeust); + if(baseResponse.getCode() == 20000){ + System.out.println("sda"+baseResponse.getData().toString()); + AlihealthKytSinglerelationResponse alihealthKytSinglerelationResponse = JSONUtil.toBean(baseResponse.getData().toString(),AlihealthKytSinglerelationResponse.class); + // 返回的码关联关系进行插入 + RelCodeBatch relCodeBatch = alihealthKytSinglerelationResponse.disposeRelCodeBatch( alihealthRelCodeInsertReqeust.getCustomerId()); + RelCodeBatch relCodeBatchOne = relCodeBatchService.getOne(new QueryWrapper().eq("productCode",relCodeBatch.getProductCode()) + .last("limit 1") + ); + if(Objects.isNull(relCodeBatchOne)){ + relCodeBatch.setCreateUser(alihealthRelCodeInsertReqeust.getCustomerId()); + relCodeBatch.setCreateTime(new Date()); + relCodeBatchService.save(relCodeBatch); + + }else { + relCodeBatchService.update(relCodeBatch,new QueryWrapper().eq("productCode",relCodeBatch.getProductCode())); + } + Integer id = Objects.isNull(relCodeBatch.getId()) ? relCodeBatchOne.getId() :relCodeBatch.getId(); + // 进行查询 + List list = alihealthKytSinglerelationResponse.disposeRelRodeDetailList(id); + if(list!=null && list.size()>0){ + List curCodeList = new ArrayList(); + for (RelCodeDetail relCodeDetail : list) { + curCodeList.add(relCodeDetail.getCurCode()); + } + relCodeDetailService.remove(new QueryWrapper().in("curCode",curCodeList)); + + relCodeDetailService.saveBatch(list); + } + + // 插入成功就重新查询一下 + navList = this.list(new LambdaQueryWrapper() + .eq(RelCodeBatch::getCurCode, parentCode)); + + if(StringUtils.isEmpty(companyEntity.getRefEntId())){ + companyEntity.setRefEntId(alihealthKytSinglerelationResponse.getRefEntId()); + companyService.modifyCompany(companyEntity); + } + }else { + if(StringUtils.isNotEmpty(companyEntity.getRefEntId())){ + companyEntity.setRefEntId(null); + companyService.modifyCompany(companyEntity); + } + log.error(baseResponse.getMessage()); + } + } if ((udiProductEntity != null && "1".equals(udiProductEntity.getPackLevel())) || (CollUtil.isNotEmpty(navList)) ) { diff --git a/src/main/resources/mybatis/mapper/system/CompanyDao.xml b/src/main/resources/mybatis/mapper/system/CompanyDao.xml index 275430358..8c7a41b2d 100644 --- a/src/main/resources/mybatis/mapper/system/CompanyDao.xml +++ b/src/main/resources/mybatis/mapper/system/CompanyDao.xml @@ -18,7 +18,9 @@ productAddr = #{productAddr}, classes = #{classes}, appId = #{appId}, - appSecret = #{appSecret} + appSecret = #{appSecret}, + refEntId = #{refEntId} + @@ -34,4 +36,4 @@ - \ No newline at end of file + diff --git a/src/main/resources/schemas/schema_v2.4.sql b/src/main/resources/schemas/schema_v2.4.sql index ac9d7f886..c9b7aad23 100644 --- a/src/main/resources/schemas/schema_v2.4.sql +++ b/src/main/resources/schemas/schema_v2.4.sql @@ -4836,3 +4836,7 @@ CALL Pro_Temp_ColumnWork('sync_data_set', 'drugDataTask', CALL Pro_Temp_ColumnWork('io_collect_set', 'startUploadHour', ' int DEFAULT NULL COMMENT ''自动上传已完成单据轮询时间''', 1); + +CALL Pro_Temp_ColumnWork('auth_company', 'refEntId', + ' varchar(255) DEFAULT NULL COMMENT ''接口调用企业的唯一标识''', + 1);