管理系统增加扫码的时候如果码关联关系找不到那就调用外网的阿里接口进行插入关联关系

dev_unify
qiuyt 7 months ago
parent ab3e5a7173
commit e86612240b

@ -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; // 接口调用企业的唯一标识
}

@ -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<BaseResponse>() {
});
if(response == null){
return ResultVOUtils.error("访问供应商平台访问不到");
}
return response;
}
}

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

@ -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<Map<String, String>> 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<String, String> 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<RelCodeDetail> disposeRelRodeDetailList(Integer batchIdFk) {
List<RelCodeDetail> list = new ArrayList<>();
List<Map<String, String>> jsonArray = (List) this.getCode_relation_list().get("code_info");
if (jsonArray != null && jsonArray.size() > 0) {
for (Map<String, String> 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;
}
}

@ -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<RelCodeBatchMapper, RelCode
private CustomerService customerService;
@Resource
private ProductInfoService productInfoService;
@Resource
private CompanyServiceImpl companyService;
@Resource
private BasicCorpServiceImpl basicCorpService;
@Resource
private RelCodeBatchService relCodeBatchService;
/**
*
@ -261,7 +278,8 @@ public class RelCodeBatchService extends ServiceImpl<RelCodeBatchMapper, RelCode
@Resource
SpsDirectClient spsDirectClient;
@Resource
private SpGetHttpClient spGetHttpClient;
/**
* spms
*/
@ -283,7 +301,7 @@ public class RelCodeBatchService extends ServiceImpl<RelCodeBatchMapper, RelCode
public void threadUpdateIoCodeTempEntity(String parentCode) {
List<IoCodeTempEntity> ioCodeTempEntities = ioCodeTempDao.selectList(new LambdaQueryWrapper<IoCodeTempEntity>().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<RelCodeBatchMapper, RelCode
return;
List<RelCodeBatch> navList = this.list(new LambdaQueryWrapper<RelCodeBatch>()
.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<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));
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))
) {

@ -18,7 +18,9 @@
productAddr = #{productAddr},
classes = #{classes},
appId = #{appId},
appSecret = #{appSecret}
appSecret = #{appSecret},
refEntId = #{refEntId}
</update>
<insert id="insertCompany" parameterType="com.glxp.api.entity.system.CompanyEntity">
@ -34,4 +36,4 @@
</insert>
</mapper>
</mapper>

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

Loading…
Cancel
Save