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 365e3b0d..f5156e13 100644 --- a/src/main/java/com/glxp/api/controller/test/TestCodeController.java +++ b/src/main/java/com/glxp/api/controller/test/TestCodeController.java @@ -3,15 +3,23 @@ package com.glxp.api.controller.test; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.glxp.api.common.res.BaseResponse; import com.glxp.api.entity.collect.RelCodeBatch; +import com.glxp.api.entity.collect.RelCodeDetail; import com.glxp.api.entity.thrsys.ThirdAliDrug; import com.glxp.api.req.alihealth.AlihealthKytDrugrescodeReqeust; +import com.glxp.api.req.alihealth.AlihealthKytSearchbillReqeust; +import com.glxp.api.req.alihealth.local.AlihealthRelCodeInsertReqeust; import com.glxp.api.req.alihealth.local.AlihealthThirdAliDrugInsertReqeust; +import com.glxp.api.req.alihealth.local.AlihealthThirdAliSearchbillInsertReqeust; +import com.glxp.api.res.alihealth.AlihealthKytSinglerelationResponse; +import com.glxp.api.service.collect.RelCodeBatchService; +import com.glxp.api.service.collect.RelCodeDetailService; import com.glxp.api.service.thrsys.ThirdAliDrugService; import com.glxp.api.util.alihealth.AlihealthUtils; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; +import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Objects; @@ -23,12 +31,52 @@ public class TestCodeController { private AlihealthUtils alihealthUtils; @Resource private ThirdAliDrugService thirdAliDrugService; -// @PostMapping("/test") -// public BaseResponse test() { -// return alihealthUtils.relCodeInsert("73157692795424", "88979920013901715365"); -// } - @PostMapping("/test1") + @Resource + private RelCodeBatchService relCodeBatchService; + @Resource + private RelCodeDetailService relCodeDetailService; + @PostMapping("/test") public BaseResponse test() { + AlihealthRelCodeInsertReqeust alihealthRelCodeInsertReqeust = new AlihealthRelCodeInsertReqeust(); + alihealthRelCodeInsertReqeust.setAppKey("31721223"); + alihealthRelCodeInsertReqeust.setAppSecret("5231c601505706a9d49823c3dfe2cb01"); + alihealthRelCodeInsertReqeust.setCustomerId("73157692795424"); + alihealthRelCodeInsertReqeust.setCode("88979920013901715365"); + alihealthRelCodeInsertReqeust.setRefEntId("ef99b78bd9c54c1284f813149c858fb0"); + BaseResponse 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); + } + } + return null; + + } + @PostMapping("/test1") + public BaseResponse test1() { AlihealthThirdAliDrugInsertReqeust alihealthThirdAliDrugInsertReqeust = new AlihealthThirdAliDrugInsertReqeust(); alihealthThirdAliDrugInsertReqeust.setErpId("123"); alihealthThirdAliDrugInsertReqeust.setAppSecret("5231c601505706a9d49823c3dfe2cb01"); @@ -67,4 +115,43 @@ public class TestCodeController { return alihealthUtils.thirdAliDrugInsert(alihealthThirdAliDrugInsertReqeust); } + @PostMapping("/test2") + public BaseResponse test2() { + AlihealthThirdAliSearchbillInsertReqeust alihealthThirdAliSearchbillInsertReqeust = new AlihealthThirdAliSearchbillInsertReqeust(); + alihealthThirdAliSearchbillInsertReqeust.setErpId("123"); + alihealthThirdAliSearchbillInsertReqeust.setAppSecret("5231c601505706a9d49823c3dfe2cb01"); + AlihealthKytSearchbillReqeust alihealthKytSearchbillReqeust = new AlihealthKytSearchbillReqeust(); + alihealthKytSearchbillReqeust.setRef_ent_id("ef99b78bd9c54c1284f813149c858fb0"); + alihealthKytSearchbillReqeust.setAuth_ref_user_id("ef99b78bd9c54c1284f813149c858fb0"); + alihealthKytSearchbillReqeust.setBegin_date("2019-01-01"); + alihealthKytSearchbillReqeust.setEnd_date("2024-05-01"); + alihealthKytSearchbillReqeust.setBill_type("A"); + alihealthKytSearchbillReqeust.setCur_page(1); + alihealthKytSearchbillReqeust.setPage_size(20); + alihealthKytSearchbillReqeust.setApp_key("31721223"); + + + alihealthThirdAliSearchbillInsertReqeust.setAlihealthKytSearchbillReqeust(alihealthKytSearchbillReqeust); +// BaseResponse> baseResponse = alihealthUtils.thirdAliDrugInsert(alihealthThirdAliDrugInsertReqeust); +// if(baseResponse.getCode() == 20000){ +// List list = baseResponse.getData(); +// if(list!=null && list.size() >0){ +// for (ThirdAliDrug thirdAliDrug : list) { +// ThirdAliDrug thirdAliDrugNew = thirdAliDrugService.getOne(new QueryWrapper().eq("nameCode", thirdAliDrug.getNameCode()) +// .last("limit 1") +// ); +// if (Objects.isNull(thirdAliDrugNew)) { +// +// thirdAliDrugService.save(thirdAliDrug); +// +// } else { +// thirdAliDrugService.update(thirdAliDrug, new QueryWrapper().eq("nameCode", thirdAliDrug.getNameCode())); +// } +// } +// } +// +// } + + return alihealthUtils.thirdAliSearchbillInsert(alihealthThirdAliSearchbillInsertReqeust); + } } diff --git a/src/main/java/com/glxp/api/entity/thrsys/ThirdAliSearchbill.java b/src/main/java/com/glxp/api/entity/thrsys/ThirdAliSearchbill.java new file mode 100644 index 00000000..394a4b6b --- /dev/null +++ b/src/main/java/com/glxp/api/entity/thrsys/ThirdAliSearchbill.java @@ -0,0 +1,49 @@ +package com.glxp.api.entity.thrsys; + +import com.baomidou.mybatisplus.annotation.TableField; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.Date; + +@Data +public class ThirdAliSearchbill { + private String billType; + private String billCode; + private String fromUserId; + private String refUserName; + private String refUserId; + private String produceDate; + private String uploadFileName; + private String fromUserName; + private String toUserId; + private String produceEntId; + private String billTime; + private String userRoleType; + private String processDate; + private String billId; + private String toUserName; + private String agentUserName; + private String agentRefUserId; + private String billTypeName; + private String toRefUserId; + private String fromRefUserId; + + + private String erpId; + /** + * 创建时间 + */ + @TableField(value = "createTime") + @ApiModelProperty(value = "创建时间") + private Date createTime; + + /** + * 更新时间 + */ + @TableField(value = "updateTime") + @ApiModelProperty(value = "更新时间") + private Date updateTime; + + +} diff --git a/src/main/java/com/glxp/api/req/alihealth/AlihealthKytSearchbillReqeust.java b/src/main/java/com/glxp/api/req/alihealth/AlihealthKytSearchbillReqeust.java new file mode 100644 index 00000000..ebde2ee7 --- /dev/null +++ b/src/main/java/com/glxp/api/req/alihealth/AlihealthKytSearchbillReqeust.java @@ -0,0 +1,25 @@ +package com.glxp.api.req.alihealth; + +import lombok.Data; + +@Data +public class AlihealthKytSearchbillReqeust extends AlihealthKytCommonParametersReqeust { + private String ref_ent_id; + private String auth_ref_user_id; + private String begin_date; + private String end_date; + + private String partner_id_send; + private String partner_id_recv; + private String agent_ref_user_id; + private String bill_code; + + private String bill_type; + private Integer cur_page; + private Integer page_size; + + public AlihealthKytSearchbillReqeust(){ + this.setMethod("alibaba.alihealth.drug.kyt.searchbill"); + } + +} diff --git a/src/main/java/com/glxp/api/req/alihealth/local/AlihealthThirdAliSearchbillInsertReqeust.java b/src/main/java/com/glxp/api/req/alihealth/local/AlihealthThirdAliSearchbillInsertReqeust.java new file mode 100644 index 00000000..f9cd764c --- /dev/null +++ b/src/main/java/com/glxp/api/req/alihealth/local/AlihealthThirdAliSearchbillInsertReqeust.java @@ -0,0 +1,12 @@ +package com.glxp.api.req.alihealth.local; + +import com.glxp.api.req.alihealth.AlihealthKytDrugrescodeReqeust; +import com.glxp.api.req.alihealth.AlihealthKytSearchbillReqeust; +import lombok.Data; + +@Data +public class AlihealthThirdAliSearchbillInsertReqeust { + private String erpId; + private String appSecret; + private AlihealthKytSearchbillReqeust alihealthKytSearchbillReqeust; +} diff --git a/src/main/java/com/glxp/api/res/alihealth/AlihealthKytSearchbillResponse.java b/src/main/java/com/glxp/api/res/alihealth/AlihealthKytSearchbillResponse.java new file mode 100644 index 00000000..c0c80908 --- /dev/null +++ b/src/main/java/com/glxp/api/res/alihealth/AlihealthKytSearchbillResponse.java @@ -0,0 +1,82 @@ +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.thrsys.ThirdAliDrug; +import com.glxp.api.entity.thrsys.ThirdAliSearchbill; +import lombok.Data; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.BeanUtils; + +import java.util.*; + +@Data +public class AlihealthKytSearchbillResponse extends AlihealthKytCommonParametersResponse { + private JSONArray bill_chk_in_out_do; + public AlihealthKytSearchbillResponse(String json) { + // 初始化请求的值 + cn.hutool.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){ + JSONObject jsonObjectModel = jsonObjectResult.getJSONObject("model"); + if (!Objects.isNull(jsonObjectModel)) { + this.setBill_chk_in_out_do(jsonObjectModel.getJSONObject("result_list").getJSONArray("bill_chk_in_out_do")); + } + } + + public List disposeThirdAliSearchbill(String customerId){ + List list = new ArrayList<>(); + List jsonArray = (List) this.getBill_chk_in_out_do(); + if (jsonArray != null && jsonArray.size() > 0) { + for (JSONObject jsonObject : jsonArray) { + if (!Objects.isNull(jsonObject)) { + ThirdAliSearchbill thirdAliSearchbill = new ThirdAliSearchbill(); + thirdAliSearchbill.setBillType(jsonObject.getStr("bill_type")); + thirdAliSearchbill.setBillCode(jsonObject.getStr("bill_code")); + thirdAliSearchbill.setFromUserId(jsonObject.getStr("from_user_id")); + thirdAliSearchbill.setRefUserName(jsonObject.getStr("ref_user_name"));; + thirdAliSearchbill.setRefUserId(jsonObject.getStr("ref_user_id")); + thirdAliSearchbill.setProduceDate(jsonObject.getStr("produce_date")); + thirdAliSearchbill.setUploadFileName(jsonObject.getStr("upload_file_name")); + thirdAliSearchbill.setFromUserName(jsonObject.getStr("from_user_name")); + thirdAliSearchbill.setToUserId(jsonObject.getStr("to_user_id")); + thirdAliSearchbill.setProduceEntId(jsonObject.getStr("produce_ent_id")); + thirdAliSearchbill.setBillTime(jsonObject.getStr("bill_time")); + thirdAliSearchbill.setUserRoleType(jsonObject.getStr("user_role_type")); + thirdAliSearchbill.setProcessDate(jsonObject.getStr("process_date")); + thirdAliSearchbill.setBillId(jsonObject.getStr("bill_id")); + thirdAliSearchbill.setToUserName(jsonObject.getStr("to_user_name")); + thirdAliSearchbill.setAgentUserName(jsonObject.getStr("agent_user_name")); + thirdAliSearchbill.setAgentRefUserId(jsonObject.getStr("agent_ref_user_id")); + thirdAliSearchbill.setBillTypeName(jsonObject.getStr("bill_type_name")); + thirdAliSearchbill.setToRefUserId(jsonObject.getStr("to_ref_user_id")); + thirdAliSearchbill.setFromRefUserId(jsonObject.getStr("from_ref_user_id")); + thirdAliSearchbill.setErpId("customerId"); + thirdAliSearchbill.setCreateTime(new Date()); + thirdAliSearchbill.setUpdateTime(new Date()); + list.add(thirdAliSearchbill); + + } + } + } + return list; + } + + +} 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 c66c7e17..b8e8d1c3 100644 --- a/src/main/java/com/glxp/api/res/alihealth/AlihealthKytSinglerelationResponse.java +++ b/src/main/java/com/glxp/api/res/alihealth/AlihealthKytSinglerelationResponse.java @@ -8,6 +8,7 @@ import cn.hutool.json.JSONUtil; import com.baomidou.mybatisplus.annotation.TableField; import com.glxp.api.entity.collect.RelCodeBatch; import com.glxp.api.entity.collect.RelCodeDetail; +import com.glxp.api.util.udi.FilterUdiUtils; import com.taobao.api.TaobaoObject; import com.taobao.api.internal.mapping.ApiField; import com.taobao.api.internal.mapping.ApiListField; @@ -92,7 +93,7 @@ public class AlihealthKytSinglerelationResponse extends AlihealthKytCommonParame } } // relCodeBatch.setId(); - relCodeBatch.setProductCode(parentCode); + relCodeBatch.setProductCode(FilterUdiUtils.getUdi(parentCode).getUdi()); relCodeBatch.setSubTypeNo(jsonObject.getStr("relation_type")); relCodeBatch.setCascadeRatio(jsonObject.getStr("pkg_ratio")); relCodeBatch.setPackageSpec(jsonObject.getStr("pkg_spec")); @@ -110,7 +111,7 @@ public class AlihealthKytSinglerelationResponse extends AlihealthKytCommonParame relCodeBatch.setUploadFlagUp(0); relCodeBatch.setUploadFlagDown(0); relCodeBatch.setParentCode(null); -// relCodeBatch.setErpId(); + relCodeBatch.setErpId(customerId); relCodeBatch.setOneLevelCount(oneLevelCount); relCodeBatch.setTwoLevelCount(twoLevelCount); 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 409c30d1..863594cf 100644 --- a/src/main/java/com/glxp/api/util/alihealth/AlihealthUtils.java +++ b/src/main/java/com/glxp/api/util/alihealth/AlihealthUtils.java @@ -5,12 +5,16 @@ import cn.hutool.http.HttpUtil; import com.glxp.api.common.res.BaseResponse; import com.glxp.api.common.util.ResultVOUtils; import com.glxp.api.entity.thrsys.ThirdAliDrug; +import com.glxp.api.entity.thrsys.ThirdAliSearchbill; import com.glxp.api.req.alihealth.AlihealthKytCommonParametersReqeust; import com.glxp.api.req.alihealth.AlihealthKytDrugrescodeReqeust; +import com.glxp.api.req.alihealth.AlihealthKytSearchbillReqeust; import com.glxp.api.req.alihealth.AlihealthKytSinglerelationReqeust; import com.glxp.api.req.alihealth.local.AlihealthRelCodeInsertReqeust; import com.glxp.api.req.alihealth.local.AlihealthThirdAliDrugInsertReqeust; +import com.glxp.api.req.alihealth.local.AlihealthThirdAliSearchbillInsertReqeust; import com.glxp.api.res.alihealth.AlihealthKytDrugrescodeResponse; +import com.glxp.api.res.alihealth.AlihealthKytSearchbillResponse; import com.glxp.api.res.alihealth.AlihealthKytSinglerelationResponse; import com.glxp.api.service.auth.CustomerInfoService; import com.glxp.api.service.collect.RelCodeBatchService; @@ -56,7 +60,44 @@ public class AlihealthUtils { //// AlibabaAlihealthDrugtraceTopLsydQueryRelationResponse alibabaAlihealthDrugtraceTopLsydQueryRelationResponse // // } + /** + * 查询药品码段信息 + * + * @param alihealthThirdAliDrugInsertReqeust + */ + public BaseResponse> thirdAliSearchbillInsert(AlihealthThirdAliSearchbillInsertReqeust alihealthThirdAliDrugInsertReqeust) { + if (alihealthThirdAliDrugInsertReqeust.getAlihealthKytSearchbillReqeust() == null) { + return ResultVOUtils.error("入参不能为空"); + } + AlihealthKytSearchbillResponse alihealthKytDrugrescodeResponse = null; + AlihealthKytSearchbillReqeust alihealthKytSearchbillReqeust = alihealthThirdAliDrugInsertReqeust.getAlihealthKytSearchbillReqeust(); + + if (alihealthKytSearchbillReqeust != null + && org.apache.commons.lang3.StringUtils.isNotEmpty(alihealthKytSearchbillReqeust.getApp_key()) + && org.apache.commons.lang3.StringUtils.isNotEmpty(alihealthThirdAliDrugInsertReqeust.getAppSecret()) + ) { + try { + + Map map = alihealthUtils.disposeSign(alihealthKytSearchbillReqeust, alihealthThirdAliDrugInsertReqeust.getAppSecret()); + String json = HttpUtil.get(alihealthUrl, map); + alihealthKytDrugrescodeResponse = new AlihealthKytSearchbillResponse(json); + + } catch (Exception e) { + e.printStackTrace(); + return ResultVOUtils.error("阿里健康接口调用失败===" + e.getMessage()); + } + + } else { + return ResultVOUtils.error("阿里健康接口调用失败===用户找不到或者key和秘钥为空"); + } + if (alihealthKytDrugrescodeResponse.judgeCall()) { + List list = alihealthKytDrugrescodeResponse.disposeThirdAliSearchbill(alihealthThirdAliDrugInsertReqeust.getErpId()); + return ResultVOUtils.success(list); + } else { + return ResultVOUtils.error("阿里健康接口调用失败===" + alihealthKytDrugrescodeResponse.getMsg_info()); + } + } /** * 查询药品码段信息 *