增加关联关系获取接口用于关联系统用

阿里调用接口逻辑变更
dev_unify
qiuyt 7 months ago
parent b3c8dfecf8
commit 5be468c250

@ -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());
}
}
}

@ -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");
// }
}

@ -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;
}

@ -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;
}

@ -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);

@ -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<RelCodeBatchMapper, RelCode
private ProductInfoService productInfoService;
@Resource
private AlihealthUtils alihealthUtils;
@Resource
private CustomerInfoService customerInfoService;
@Resource
private RelCodeBatchService relCodeBatchService;
/**
*
*
@ -362,6 +371,7 @@ public class RelCodeBatchService extends ServiceImpl<RelCodeBatchMapper, RelCode
@Resource
UdiProductService udiProductService;
public void threadUpdateIoCodeTempEntity(String parentCode) {
List<IoCodeTempEntity> ioCodeTempEntities = ioCodeTempDao.selectList(new LambdaQueryWrapper<IoCodeTempEntity>().eq(IoCodeTempEntity::getCode, parentCode));
if (CollUtil.isNotEmpty(ioCodeTempEntities)) {
@ -379,8 +389,43 @@ public class RelCodeBatchService extends ServiceImpl<RelCodeBatchMapper, RelCode
// codeTempEntity.getSupId()
//todo if(navList)是空的 1.查供应商key2根据parentCode查阿里接口3根据返回结果再次查询
if(navList == null || navList.size() == 0 ){
BaseResponse baseResponse = alihealthUtils.relCodeInsert(codeTempEntity.getSupId(),parentCode);
CustomerInfoEntity customerInfoEntity = customerInfoService.selectById(codeTempEntity.getSupId());
AlihealthRelCodeInsertReqeust alihealthRelCodeInsertReqeust= new AlihealthRelCodeInsertReqeust();
alihealthRelCodeInsertReqeust.setAppKey(customerInfoEntity.getAppKey());
alihealthRelCodeInsertReqeust.setAppSecret(customerInfoEntity.getAppSecret());
alihealthRelCodeInsertReqeust.setCustomerId(codeTempEntity.getSupId());
alihealthRelCodeInsertReqeust.setCode(parentCode);
alihealthRelCodeInsertReqeust.setRefEntId(customerInfoEntity.getRefEntId());
BaseResponse<AlihealthKytSinglerelationResponse> baseResponse = alihealthUtils.relCodeInsert(alihealthRelCodeInsertReqeust);
if(baseResponse.getCode() == 20000){
AlihealthKytSinglerelationResponse alihealthKytSinglerelationResponse = baseResponse.getData();
// 返回的码关联关系进行插入
RelCodeBatch relCodeBatch = alihealthKytSinglerelationResponse.disposeRelCodeBatch( alihealthRelCodeInsertReqeust.getCustomerId());
RelCodeBatch relCodeBatchOne = relCodeBatchService.getOne(new QueryWrapper<RelCodeBatch>().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<RelCodeBatch>().eq("productCode",relCodeBatch.getProductCode()));
}
Integer id = Objects.isNull(relCodeBatch.getId()) ? relCodeBatchOne.getId() :relCodeBatch.getId();
// 进行查询
List<RelCodeDetail> 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<RelCodeDetail>().in("curCode",curCodeList));
relCodeDetailService.saveBatch(list);
}
// 插入成功就重新查询一下
navList = this.list(new LambdaQueryWrapper<RelCodeBatch>()
.eq(RelCodeBatch::getCurCode, parentCode));

@ -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<AlihealthKytSinglerelationResponse> 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<RelCodeBatch>().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<RelCodeBatch>().eq("productCode",relCodeBatch.getProductCode()));
}
Integer id = Objects.isNull(relCodeBatch.getId()) ? relCodeBatchOne.getId() :relCodeBatch.getId();
// 进行查询
List<RelCodeDetail> 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<RelCodeDetail>().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){

Loading…
Cancel
Save