package com.glxp.api.util.alihealth; import cn.hutool.http.HttpUtil; 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.auth.CustomerInfoEntity; import com.glxp.api.entity.basic.BasicCorpEntity; import com.glxp.api.entity.collect.RelCodeBatch; import com.glxp.api.entity.inout.IoCodeLostEntity; import com.glxp.api.req.alihealth.*; import com.glxp.api.req.alihealth.local.*; import com.glxp.api.res.alihealth.*; import com.glxp.api.service.auth.CustomerInfoService; import com.glxp.api.service.collect.RelCodeBatchService; import com.glxp.api.service.collect.RelCodeDetailService; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.jfree.util.Log; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import javax.annotation.Resource; import java.util.List; import java.util.Map; @Component @Slf4j public class AlihealthYljgUtils { @Resource private CustomerInfoService customerInfoService; @Resource private AlihealthUtils alihealthUtils; @Resource private RelCodeDetailService relCodeDetailService; @Resource private RelCodeBatchService relCodeBatchService; @Value("${ALIHEALTH_URL:http://gw.api.taobao.com/router/rest}") private String alihealthUrl; @Resource private AuthCompanyMapper authCompanyMapper; @Resource private BasicCorpDao basicCorpDao; /** * 出入库单据上传 * @param reqeust * @return */ public BaseResponse yljgUploadinoutbill(AlihealthYljgUploadinoutbillReqeust reqeust,String erpId) { AuthCompany authCompany = authCompanyMapper.selectOne( new QueryWrapper().last("limit 1") ); reqeust.setApp_key(authCompany.getAppId()); reqeust.setRef_user_id(authCompany.getRefEntId()); reqeust.setTo_user_id(authCompany.getRefEntId()); AlihealthYljgUploadinoutbillResponse alihealthYljgUploadinoutbillResponse = null; if(StringUtils.isNotEmpty(erpId)){ BasicCorpEntity basicCorpEntity = basicCorpDao.selectOne( new QueryWrapper().eq("erpId",erpId) ); if(basicCorpEntity!=null){ }else { basicCorpEntity = new BasicCorpEntity(); basicCorpEntity.setName(erpId); } 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()); Map map = alihealthUtils.disposeSign(alihealthKytGetentinfoReqeust,authCompany.getAppSecret()); String json = HttpUtil.get(alihealthUrl,map); alihealthKytGetentinfoResponse =new AlihealthKytGetentinfoResponse(json); }catch (Exception e){ return ResultVOUtils.error("阿里健康接口调用失败===往来单位名称请检查"); } if(StringUtils.isNotEmpty(alihealthKytGetentinfoResponse.getMsg_info()) && alihealthKytGetentinfoResponse.getMsg_info().equals("调用成功") ){ reqeust.setFrom_user_id(alihealthKytGetentinfoResponse.getEnt_id()); }else { return ResultVOUtils.error("阿里健康接口调用失败===往来单位名称请检查==="+alihealthKytGetentinfoResponse.getMsg_info()); } } if (reqeust != null && org.apache.commons.lang3.StringUtils.isNotEmpty(authCompany.getAppId()) && org.apache.commons.lang3.StringUtils.isNotEmpty(authCompany.getAppSecret()) ) { try { Map map = alihealthUtils.disposeSign(reqeust, authCompany.getAppSecret()); String json = HttpUtil.get(alihealthUrl, map); 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 relCodeInsert(AlihealthYljgSinglerelationReqeust reqeust) { AuthCompany authCompany = authCompanyMapper.selectOne( new QueryWrapper().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 { Map map = alihealthUtils.disposeSign(reqeust, authCompany.getAppSecret()); log.error("阿里啦关联关系入参==="+map); String json = HttpUtil.get(alihealthUrl, map); 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> codedetail(AlihealthYljgCodedetailReqeust reqeust) { AuthCompany authCompany = authCompanyMapper.selectOne( new QueryWrapper().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 { Map map = alihealthUtils.disposeSign(reqeust, authCompany.getAppSecret()); String json = HttpUtil.get(alihealthUrl, map); 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> listupout(AlihealthYljgListupoutReqeust reqeust,String erpId) { AuthCompany authCompany = authCompanyMapper.selectOne( new QueryWrapper().last("limit 1") ); if(StringUtils.isNotEmpty(erpId)){ BasicCorpEntity basicCorpEntity = basicCorpDao.selectOne( new QueryWrapper().eq("erpId",erpId) ); if(basicCorpEntity!=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()); Map map = alihealthUtils.disposeSign(alihealthKytGetentinfoReqeust,authCompany.getAppSecret()); String json = HttpUtil.get(alihealthUrl,map); alihealthKytGetentinfoResponse =new AlihealthKytGetentinfoResponse(json); }catch (Exception e){ return ResultVOUtils.error("阿里健康接口调用失败===往来单位名称请检查"); } if(StringUtils.isNotEmpty(alihealthKytGetentinfoResponse.getMsg_info()) && alihealthKytGetentinfoResponse.getMsg_info().equals("调用成功") ){ reqeust.setFrom_user_id(alihealthKytGetentinfoResponse.getEnt_id()); }else { return ResultVOUtils.error("阿里健康接口调用失败===往来单位名称请检查==="+alihealthKytGetentinfoResponse.getMsg_info()); } } } 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 { Map map = alihealthUtils.disposeSign(reqeust, authCompany.getAppSecret()); String json = HttpUtil.get(alihealthUrl, map); 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 listupoutDetail(AlihealthYljgListupoutDetailReqeust reqeust) { AlihealthYljgListupoutDetailResponse alihealthYljgListupoutDetailResponse = null; AuthCompany authCompany = authCompanyMapper.selectOne( new QueryWrapper().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 { Map map = alihealthUtils.disposeSign(reqeust, authCompany.getAppSecret()); String json = HttpUtil.get(alihealthUrl, map); 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()); } } }