diff --git a/src/main/java/com/glxp/api/controller/alihealth/AlihealthBusController.java b/src/main/java/com/glxp/api/controller/alihealth/AlihealthBusController.java new file mode 100644 index 00000000..0282e1fb --- /dev/null +++ b/src/main/java/com/glxp/api/controller/alihealth/AlihealthBusController.java @@ -0,0 +1,76 @@ +package com.glxp.api.controller.alihealth; + +import cn.hutool.http.HttpUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.glxp.api.annotation.Log; +import com.glxp.api.common.enums.ResultEnum; +import com.glxp.api.common.res.BaseResponse; +import com.glxp.api.common.util.ResultVOUtils; +import com.glxp.api.constant.BusinessType; +import com.glxp.api.entity.collect.RelCodeBatch; +import com.glxp.api.req.alihealth.AlihealthKytGetentinfoReqeust; +import com.glxp.api.req.alihealth.AlihealthRelCodeInsertReqeust; +import com.glxp.api.req.system.DeleteRequest; +import com.glxp.api.req.thrsys.AuthCompanyRequest; +import com.glxp.api.res.alihealth.AlihealthKytGetentinfoResponse; +import com.glxp.api.util.alihealth.AlihealthUtils; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.validation.BindingResult; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; +import java.util.Map; + +@Slf4j +@RestController +public class AlihealthBusController { + @Resource + private AlihealthUtils alihealthUtils; + @Value("${ALIHEALTH_URL:http://gw.api.taobao.com/router/rest}") + private String alihealthUrl; + @PostMapping("/spms/alihealth/relCodeInsert") + @Log(title = "阿里健康自动赋码关联关系", businessType = BusinessType.OTHER) + public BaseResponse relCodeInsert(@RequestBody AlihealthRelCodeInsertReqeust alihealthRelCodeInsertReqeust) { + if(StringUtils.isEmpty(alihealthRelCodeInsertReqeust.getRefEntId())){ + AlihealthKytGetentinfoResponse alihealthKytGetentinfoResponse = null; + try { + AlihealthKytGetentinfoReqeust alihealthKytGetentinfoReqeust = new AlihealthKytGetentinfoReqeust(); + alihealthKytGetentinfoReqeust.setApp_key(alihealthRelCodeInsertReqeust.getAppKey()); + alihealthKytGetentinfoReqeust.setEnt_name(alihealthRelCodeInsertReqeust.getName()); + alihealthRelCodeInsertReqeust.getAppSecret(); + Map map = alihealthUtils.disposeSign(alihealthKytGetentinfoReqeust, alihealthRelCodeInsertReqeust.getAppSecret()); + String json = HttpUtil.get(alihealthUrl, map); + alihealthKytGetentinfoResponse = new AlihealthKytGetentinfoResponse(json); + + } catch (Exception e) { + e.printStackTrace(); + return ResultVOUtils.error("阿里健康接口调用失败===请检查key和密文"); + + } + if (StringUtils.isNotEmpty(alihealthKytGetentinfoResponse.getMsg_info()) + && alihealthKytGetentinfoResponse.getMsg_info().equals("调用成功") + ) { + alihealthRelCodeInsertReqeust.setRefEntId(alihealthKytGetentinfoResponse.getRef_ent_id()); + } else { + return ResultVOUtils.error("阿里健康接口调用失败===" + alihealthKytGetentinfoResponse.getMsg_info()); + + } + } + + BaseResponse baseResponse = alihealthUtils.relCodeInsert(alihealthRelCodeInsertReqeust); + + if(baseResponse.getCode() == 20000){ + // 插入成功返回 + return baseResponse; + }else { + log.error("调用阿里码获取关联关系接口==="+baseResponse.getMessage()); + return ResultVOUtils.error("调用阿里码获取关联关系接口==="+baseResponse.getMessage()); + + } + } + +} diff --git a/src/main/java/com/glxp/api/controller/test/TestCodeController.java b/src/main/java/com/glxp/api/controller/test/TestCodeController.java index 9de9f6df..b6875391 100644 --- a/src/main/java/com/glxp/api/controller/test/TestCodeController.java +++ b/src/main/java/com/glxp/api/controller/test/TestCodeController.java @@ -13,8 +13,8 @@ public class TestCodeController { @Resource private AlihealthUtils alihealthUtils; - @PostMapping("/test") - public BaseResponse test() { - return alihealthUtils.relCodeInsert("73157692795424", "88979920013901715365"); - } +// @PostMapping("/test") +// public BaseResponse test() { +// return alihealthUtils.relCodeInsert("73157692795424", "88979920013901715365"); +// } } 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 00000000..1d99e94d --- /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/req/thrsys/AuthCompanyRequest.java b/src/main/java/com/glxp/api/req/thrsys/AuthCompanyRequest.java new file mode 100644 index 00000000..b9adf743 --- /dev/null +++ b/src/main/java/com/glxp/api/req/thrsys/AuthCompanyRequest.java @@ -0,0 +1,17 @@ +package com.glxp.api.req.thrsys; + +import lombok.Data; + +@Data +public class AuthCompanyRequest { + /** + * 往来单位名称 + */ + private String name; + private String appId; + private String appSecret; + + private String refEntId; + private String code; + +} diff --git a/src/main/java/com/glxp/api/res/alihealth/AlihealthKytSinglerelationResponse.java b/src/main/java/com/glxp/api/res/alihealth/AlihealthKytSinglerelationResponse.java index b7c62dfc..c66c7e17 100644 --- a/src/main/java/com/glxp/api/res/alihealth/AlihealthKytSinglerelationResponse.java +++ b/src/main/java/com/glxp/api/res/alihealth/AlihealthKytSinglerelationResponse.java @@ -31,6 +31,8 @@ public class AlihealthKytSinglerelationResponse extends AlihealthKytCommonParame private JSONObject pkg_info_d_t_o; private JSONObject produce_info_list; + private String refEntId; + public AlihealthKytSinglerelationResponse(String json) { // 初始化请求的值 cn.hutool.json.JSONObject jsonObject = JSONUtil.parseObj(json); 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 04cd2b53..506f30d2 100644 --- a/src/main/java/com/glxp/api/service/collect/RelCodeBatchService.java +++ b/src/main/java/com/glxp/api/service/collect/RelCodeBatchService.java @@ -9,6 +9,7 @@ import cn.hutool.core.util.XmlUtil; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.TypeReference; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.github.pagehelper.PageHelper; @@ -17,6 +18,7 @@ import com.glxp.api.dao.basic.BasicProductsDao; import com.glxp.api.dao.collect.RelCodeBatchMapper; import com.glxp.api.dao.inout.IoCodeTempDao; import com.glxp.api.entity.auth.AuthAdmin; +import com.glxp.api.entity.auth.CustomerInfoEntity; import com.glxp.api.entity.basic.ProductInfoEntity; import com.glxp.api.entity.basic.UdiEntity; import com.glxp.api.entity.basic.UdiProductEntity; @@ -24,10 +26,13 @@ import com.glxp.api.entity.collect.RelCodeBatch; import com.glxp.api.entity.collect.RelCodeDetail; import com.glxp.api.entity.inout.IoCodeTempEntity; import com.glxp.api.exception.JsonException; +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.CustomerInfoService; import com.glxp.api.service.auth.CustomerService; import com.glxp.api.service.basic.ProductInfoService; import com.glxp.api.service.basic.UdiProductService; @@ -62,6 +67,10 @@ public class RelCodeBatchService extends ServiceImpl ioCodeTempEntities = ioCodeTempDao.selectList(new LambdaQueryWrapper().eq(IoCodeTempEntity::getCode, parentCode)); if (CollUtil.isNotEmpty(ioCodeTempEntities)) { @@ -379,8 +389,43 @@ public class RelCodeBatchService extends ServiceImpl baseResponse = alihealthUtils.relCodeInsert(alihealthRelCodeInsertReqeust); if(baseResponse.getCode() == 20000){ + AlihealthKytSinglerelationResponse alihealthKytSinglerelationResponse = baseResponse.getData(); + // 返回的码关联关系进行插入 + 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)); diff --git a/src/main/java/com/glxp/api/util/alihealth/AlihealthUtils.java b/src/main/java/com/glxp/api/util/alihealth/AlihealthUtils.java index e59ef19d..f3fce6a9 100644 --- a/src/main/java/com/glxp/api/util/alihealth/AlihealthUtils.java +++ b/src/main/java/com/glxp/api/util/alihealth/AlihealthUtils.java @@ -13,6 +13,7 @@ import com.glxp.api.entity.collect.RelCodeDetail; import com.glxp.api.req.alihealth.AlihealthKytCommonParametersReqeust; import com.glxp.api.req.alihealth.AlihealthKytGetentinfoReqeust; import com.glxp.api.req.alihealth.AlihealthKytSinglerelationReqeust; +import com.glxp.api.req.alihealth.AlihealthRelCodeInsertReqeust; import com.glxp.api.res.alihealth.AlihealthKytCommonParametersResponse; import com.glxp.api.res.alihealth.AlihealthKytGetentinfoResponse; import com.glxp.api.res.alihealth.AlihealthKytSinglerelationResponse; @@ -62,60 +63,42 @@ public class AlihealthUtils { //// AlibabaAlihealthDrugtraceTopLsydQueryRelationResponse alibabaAlihealthDrugtraceTopLsydQueryRelationResponse // // } + //TODO 调用阿里接口用码进行批量处理只测试了两个包装层级的 暂时没有三个包装层级的数据做测试 到时候有数据之后要好好测试一下 @Transactional(rollbackFor = Exception.class) - public BaseResponse relCodeInsert(String customerId , String code){ - CustomerInfoEntity customerInfoEntity = customerInfoService.selectById(customerId); - AlihealthKytSinglerelationResponse alihealthKytGetentinfoResponse = null; + public BaseResponse relCodeInsert(AlihealthRelCodeInsertReqeust alihealthRelCodeInsertReqeust){ + AlihealthKytSinglerelationResponse alihealthKytSinglerelationResponse = null; - if(customerInfoEntity != null){ + if(alihealthRelCodeInsertReqeust != null + && org.apache.commons.lang3.StringUtils.isNotEmpty(alihealthRelCodeInsertReqeust.getAppKey()) + && org.apache.commons.lang3.StringUtils.isNotEmpty(alihealthRelCodeInsertReqeust.getAppSecret()) + ){ try { AlihealthKytSinglerelationReqeust alihealthKytSinglerelationReqeust =new AlihealthKytSinglerelationReqeust(); - alihealthKytSinglerelationReqeust.setRef_ent_id(customerInfoEntity.getRefEntId()); - alihealthKytSinglerelationReqeust.setDes_ref_ent_id(customerInfoEntity.getRefEntId()); - alihealthKytSinglerelationReqeust.setCode(code); - alihealthKytSinglerelationReqeust.setApp_key(customerInfoEntity.getAppKey()); - Map map = alihealthUtils.disposeSign(alihealthKytSinglerelationReqeust,customerInfoEntity.getAppSecret()); + alihealthKytSinglerelationReqeust.setRef_ent_id(alihealthRelCodeInsertReqeust.getRefEntId()); + alihealthKytSinglerelationReqeust.setDes_ref_ent_id(alihealthRelCodeInsertReqeust.getRefEntId()); + alihealthKytSinglerelationReqeust.setCode(alihealthRelCodeInsertReqeust.getCode()); + alihealthKytSinglerelationReqeust.setApp_key(alihealthRelCodeInsertReqeust.getAppKey()); + Map map = alihealthUtils.disposeSign(alihealthKytSinglerelationReqeust,alihealthRelCodeInsertReqeust.getAppSecret()); String json = HttpUtil.get(alihealthUrl,map); - alihealthKytGetentinfoResponse =new AlihealthKytSinglerelationResponse(json); + alihealthKytSinglerelationResponse =new AlihealthKytSinglerelationResponse(json); }catch (Exception e){ return ResultVOUtils.error("阿里健康接口调用失败===请检查厂商的key和密文是否对"); } + }else { + return ResultVOUtils.error("阿里健康接口调用失败===用户找不到或者key和秘钥为空"); } - if(org.apache.commons.lang3.StringUtils.isNotEmpty(alihealthKytGetentinfoResponse.getMsg_info()) - && alihealthKytGetentinfoResponse.getMsg_info().equals("调用成功") + if(org.apache.commons.lang3.StringUtils.isNotEmpty(alihealthKytSinglerelationResponse.getMsg_info()) + && alihealthKytSinglerelationResponse.getMsg_info().equals("调用成功") ){ - RelCodeBatch relCodeBatch = alihealthKytGetentinfoResponse.disposeRelCodeBatch( customerId); - RelCodeBatch relCodeBatchOne = relCodeBatchService.getOne(new QueryWrapper().eq("productCode",relCodeBatch.getProductCode()) - .last("limit 1") - ); - if(Objects.isNull(relCodeBatchOne)){ - relCodeBatch.setCreateUser(customerId); - 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 = alihealthKytGetentinfoResponse.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); - } + alihealthKytSinglerelationResponse.setRefEntId(alihealthRelCodeInsertReqeust.getRefEntId()); + return ResultVOUtils.success(alihealthKytSinglerelationResponse ); }else { - return ResultVOUtils.error("阿里健康接口调用失败==="+alihealthKytGetentinfoResponse.getMsg_info()); + return ResultVOUtils.error("阿里健康接口调用失败==="+alihealthKytSinglerelationResponse.getMsg_info()); } - return ResultVOUtils.success("码关联关系获取成功"); } public Map disposeSign(AlihealthKytCommonParametersReqeust alihealthKytCommonParametersReqeust, String secret){