You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
udi-spms-java/src/main/java/com/glxp/api/util/alihealth/AlihealthYljgUtils.java

296 lines
12 KiB
Java

package com.glxp.api.util.alihealth;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.glxp.api.common.res.BaseResponse;
import com.glxp.api.common.util.ResultVOUtils;
import com.glxp.api.dao.auth.AuthCompanyMapper;
import com.glxp.api.dao.basic.BasicCorpDao;
import com.glxp.api.entity.alihealth.AliYljgBillDetail;
import com.glxp.api.entity.alihealth.AliYljgSearchbill;
import com.glxp.api.entity.auth.AuthCompany;
import com.glxp.api.entity.basic.BasicCorpEntity;
import com.glxp.api.entity.inout.IoCodeLostEntity;
import com.glxp.api.httpClient.serviceClient.AlihealthClient;
import com.glxp.api.req.alihealth.*;
import com.glxp.api.res.alihealth.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.List;
@Component
@Slf4j
public class AlihealthYljgUtils {
@Resource
private AuthCompanyMapper authCompanyMapper;
@Resource
private BasicCorpDao basicCorpDao;
@Resource
private AlihealthClient alihealthClient;
/**
* 统一获取阿里往来单位ID
*
* @param authCompany
* @param erpId
* @return
*/
public String getEntId(AuthCompany authCompany, String erpId) {
if (StringUtils.isNotEmpty(erpId)) {
BasicCorpEntity basicCorpEntity = basicCorpDao.selectOne(
new QueryWrapper<BasicCorpEntity>().eq("erpId", erpId)
);
if (ObjectUtil.isNotEmpty(basicCorpEntity) && StringUtils.isNotEmpty(basicCorpEntity.getAliEntId())) {
return basicCorpEntity.getAliEntId();
}
if (ObjectUtil.isNull(basicCorpEntity)) {
return null;
}
AlihealthKytGetentinfoResponse alihealthKytGetentinfoResponse = null;
try {
AlihealthKytGetentinfoReqeust alihealthKytGetentinfoReqeust = new AlihealthKytGetentinfoReqeust();
alihealthKytGetentinfoReqeust.setMethod("alibaba.alihealth.drugtrace.top.yljg.query.getentinfo");
alihealthKytGetentinfoReqeust.setApp_key(authCompany.getAppId());
alihealthKytGetentinfoReqeust.setEnt_name(basicCorpEntity.getName());
String json = alihealthClient.accessAliInterface(alihealthKytGetentinfoReqeust, authCompany.getAppSecret());
alihealthKytGetentinfoResponse = new AlihealthKytGetentinfoResponse(json);
} catch (Exception e) {
log.error("阿里健康接口调用失败===往来单位名称请检查");
return null;
}
if (StringUtils.isNotEmpty(alihealthKytGetentinfoResponse.getMsg_info())
&& alihealthKytGetentinfoResponse.getMsg_info().equals("调用成功")
) {
// 写入往来单位表
BasicCorpEntity basicCorpEntityNew = new BasicCorpEntity();
basicCorpEntityNew.setId(basicCorpEntity.getId());
basicCorpEntityNew.setAliEntId(alihealthKytGetentinfoResponse.getEnt_id());
basicCorpDao.updateById(basicCorpEntityNew);
return alihealthKytGetentinfoResponse.getEnt_id();
} else {
log.error("阿里健康接口调用失败===往来单位名称请检查===" + alihealthKytGetentinfoResponse.getMsg_info());
return null;
}
}
return null;
}
/**
* 出入库单据上传
*
* @param reqeust
* @return
*/
public BaseResponse<AlihealthKytSinglerelationResponse> yljgUploadinoutbill(AlihealthYljgUploadinoutbillReqeust reqeust, String erpId) {
AuthCompany authCompany = authCompanyMapper.selectOne(
new QueryWrapper<AuthCompany>().last("limit 1")
);
reqeust.setApp_key(authCompany.getAppId());
reqeust.setRef_user_id(authCompany.getRefEntId());
reqeust.setTo_user_id(authCompany.getRefEntId());
AlihealthYljgUploadinoutbillResponse alihealthYljgUploadinoutbillResponse = null;
// 获取阿里往来单位ID
reqeust.setFrom_user_id(getEntId(authCompany, erpId));
if (StringUtils.isEmpty(reqeust.getFrom_user_id())) {
log.error("阿里往来单位ID获取失败去检查");
}
if (reqeust != null
&& org.apache.commons.lang3.StringUtils.isNotEmpty(authCompany.getAppId())
&& org.apache.commons.lang3.StringUtils.isNotEmpty(authCompany.getAppSecret())
) {
try {
String json = alihealthClient.accessAliInterface(reqeust, authCompany.getAppSecret());
log.error("阿里单据上传返回参数===" + json);
alihealthYljgUploadinoutbillResponse = JSONUtil.toBean(json, AlihealthYljgUploadinoutbillResponse.class);
} catch (Exception e) {
return ResultVOUtils.error("阿里健康接口调用失败===" + e.getMessage());
}
} else {
return ResultVOUtils.error("阿里健康接口调用失败===用户找不到或者key和秘钥为空");
}
if (alihealthYljgUploadinoutbillResponse.judgeCall()) {
return ResultVOUtils.success(alihealthYljgUploadinoutbillResponse);
} else {
return ResultVOUtils.error("阿里健康接口调用失败===" + alihealthYljgUploadinoutbillResponse.getMsg_info());
}
}
/**
* 单码关联关系查询
*
* @param reqeust
* @return
*/
public BaseResponse<AlihealthYljgSinglerelationResponse> relCodeInsert(AlihealthYljgSinglerelationReqeust reqeust) {
AuthCompany authCompany = authCompanyMapper.selectOne(
new QueryWrapper<AuthCompany>().last("limit 1")
);
reqeust.setApp_key(authCompany.getAppId());
reqeust.setRef_ent_id(authCompany.getRefEntId());
reqeust.setDes_ref_ent_id(authCompany.getRefEntId());
AlihealthYljgSinglerelationResponse alihealthYljgSinglerelationResponse = null;
if (reqeust != null
&& org.apache.commons.lang3.StringUtils.isNotEmpty(authCompany.getAppId())
&& org.apache.commons.lang3.StringUtils.isNotEmpty(authCompany.getAppSecret())
) {
try {
String json = alihealthClient.accessAliInterface(reqeust, authCompany.getAppSecret());
log.error("阿里啦关联关系结果===" + json);
alihealthYljgSinglerelationResponse = new AlihealthYljgSinglerelationResponse(json);
} catch (Exception e) {
return ResultVOUtils.error("阿里健康接口调用失败===" + e.getMessage());
}
} else {
return ResultVOUtils.error("阿里健康接口调用失败===用户找不到或者key和秘钥为空");
}
if (alihealthYljgSinglerelationResponse.judgeCall()) {
return ResultVOUtils.success(alihealthYljgSinglerelationResponse);
} else {
return ResultVOUtils.error("阿里健康接口调用失败===" + alihealthYljgSinglerelationResponse.getMsg_info());
}
}
/**
* 根据码查询码信息
*
* @param reqeust
* @return
*/
public BaseResponse<List<IoCodeLostEntity>> codedetail(AlihealthYljgCodedetailReqeust reqeust) {
AuthCompany authCompany = authCompanyMapper.selectOne(
new QueryWrapper<AuthCompany>().last("limit 1")
);
reqeust.setApp_key(authCompany.getAppId());
reqeust.setRef_ent_id(authCompany.getRefEntId());
AlihealthYljgCodedetailResponse alihealthYljgCodedetailResponse = null;
if (reqeust != null
&& org.apache.commons.lang3.StringUtils.isNotEmpty(authCompany.getAppId())
&& org.apache.commons.lang3.StringUtils.isNotEmpty(authCompany.getAppSecret())
) {
try {
String json = alihealthClient.accessAliInterface(reqeust, authCompany.getAppSecret());
alihealthYljgCodedetailResponse = new AlihealthYljgCodedetailResponse(json);
} catch (Exception e) {
return ResultVOUtils.error("阿里健康接口调用失败===" + e.getMessage());
}
} else {
return ResultVOUtils.error("阿里健康接口调用失败===用户找不到或者key和秘钥为空");
}
if (alihealthYljgCodedetailResponse.judgeCall()) {
return ResultVOUtils.success(alihealthYljgCodedetailResponse.disposeRelCodeBatch());
} else {
return ResultVOUtils.error("阿里健康接口调用失败===" + alihealthYljgCodedetailResponse.getMsg_info());
}
}
/**
* 查询单据
*
* @param reqeust
* @return
*/
public BaseResponse<List<AliYljgSearchbill>> listupout(AlihealthYljgListupoutReqeust reqeust, String erpId) {
AuthCompany authCompany = authCompanyMapper.selectOne(
new QueryWrapper<AuthCompany>().last("limit 1")
);
// 获取阿里往来单位ID
reqeust.setFrom_user_id(getEntId(authCompany, erpId));
if (StringUtils.isEmpty(reqeust.getFrom_user_id())) {
log.error("阿里往来单位ID获取失败去检查");
}
reqeust.setApp_key(authCompany.getAppId());
reqeust.setRef_ent_id(authCompany.getRefEntId());
AlihealthYljgListupoutResponse alihealthYljgListupoutResponse = null;
if (reqeust != null
&& org.apache.commons.lang3.StringUtils.isNotEmpty(reqeust.getApp_key())
&& org.apache.commons.lang3.StringUtils.isNotEmpty(authCompany.getAppSecret())
) {
try {
String json = alihealthClient.accessAliInterface(reqeust, authCompany.getAppSecret());
alihealthYljgListupoutResponse = new AlihealthYljgListupoutResponse(json);
} catch (Exception e) {
// e.getMessage();
return ResultVOUtils.error("阿里健康接口调用失败===" + e.getMessage());
}
} else {
return ResultVOUtils.error("阿里健康接口调用失败===用户找不到或者key和秘钥为空");
}
if (alihealthYljgListupoutResponse.judgeCall()) {
return ResultVOUtils.success(alihealthYljgListupoutResponse.disposeAliYljgSearchbill());
} else {
return ResultVOUtils.error("阿里健康接口调用失败===" + alihealthYljgListupoutResponse.getMsg_info());
}
}
/**
* 查询单据详情
*
* @param reqeust
* @return
*/
public BaseResponse<AliYljgBillDetail> listupoutDetail(AlihealthYljgListupoutDetailReqeust reqeust) {
AlihealthYljgListupoutDetailResponse alihealthYljgListupoutDetailResponse = null;
AuthCompany authCompany = authCompanyMapper.selectOne(
new QueryWrapper<AuthCompany>().last("limit 1")
);
reqeust.setApp_key(authCompany.getAppId());
reqeust.setRef_ent_id(authCompany.getRefEntId());
reqeust.setTo_ref_user_id(authCompany.getRefEntId());
if (reqeust != null
&& org.apache.commons.lang3.StringUtils.isNotEmpty(reqeust.getApp_key())
&& org.apache.commons.lang3.StringUtils.isNotEmpty(authCompany.getAppSecret())
) {
try {
String json = alihealthClient.accessAliInterface(reqeust, authCompany.getAppSecret());
alihealthYljgListupoutDetailResponse = new AlihealthYljgListupoutDetailResponse(json);
} catch (Exception e) {
return ResultVOUtils.error("阿里健康接口调用失败===" + e.getMessage());
}
} else {
return ResultVOUtils.error("阿里健康接口调用失败===用户找不到或者key和秘钥为空");
}
if (alihealthYljgListupoutDetailResponse.judgeCall()) {
return ResultVOUtils.success(alihealthYljgListupoutDetailResponse.disposeAliYljgBillDetail());
} else {
return ResultVOUtils.error("阿里健康接口调用失败===" + alihealthYljgListupoutDetailResponse.getMsg_info());
}
}
}