package com.glxp.api.controller.alihealth; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.http.HttpUtil; import cn.hutool.json.JSONUtil; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.TypeReference; import com.baomidou.mybatisplus.core.metadata.IPage; import com.github.pagehelper.PageInfo; import com.glxp.api.annotation.CusRedissonAnnotation; import com.glxp.api.annotation.Log; import com.glxp.api.annotation.RepeatSubmit; import com.glxp.api.common.res.BaseResponse; import com.glxp.api.common.util.ResultVOUtils; import com.glxp.api.constant.BusinessType; import com.glxp.api.constant.RedissonCacheKey; import com.glxp.api.controller.BaseController; import com.glxp.api.entity.alihealth.AliYljgBillDetail; import com.glxp.api.entity.alihealth.AliYljgBillDetailDrugCode; import com.glxp.api.entity.alihealth.AliYljgSearchbill; import com.glxp.api.entity.thrsys.CodeRel; import com.glxp.api.entity.thrsys.ThirdAliDrug; import com.glxp.api.entity.thrsys.YbDrug; import com.glxp.api.req.alihealth.AliYljgSearchbillReqeust; import com.glxp.api.req.alihealth.AlihealthKytDrugrescodeReqeust; import com.glxp.api.req.alihealth.AlihealthKytGetentinfoReqeust; import com.glxp.api.req.alihealth.local.AlihealthRelCodeInsertReqeust; import com.glxp.api.req.alihealth.local.AlihealthThirdAliDrugInsertReqeust; import com.glxp.api.req.thrsys.CodeRelRequest; import com.glxp.api.res.PageSimpleResponse; import com.glxp.api.res.alihealth.AlihealthKytGetentinfoResponse; import com.glxp.api.service.alihealth.AlihealthBusService; import com.glxp.api.service.basic.UdiContrastService; import com.glxp.api.service.inout.IoOrderService; import com.glxp.api.util.DimaUtil; import com.glxp.api.util.IntUtil; import com.glxp.api.util.JsonUtils; import com.glxp.api.util.alihealth.AlihealthUtils; import com.glxp.api.util.alihealth.CopyUtils; import com.glxp.api.util.alihealth.PaginationUtil; import com.google.api.client.json.Json; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import java.util.*; import java.util.stream.Collectors; @Slf4j @RestController public class AlihealthBusController extends BaseController { @Resource private AlihealthUtils alihealthUtils; @Value("${ALIHEALTH_URL:http://gw.api.taobao.com/router/rest}") private String alihealthUrl; @Value("${UDI_SERVER_URL}") private String udiUrl; @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()); } } @Resource private UdiContrastService udiContrastService; @PostMapping("/spms/alihealth/thirdAliDrugList") @Log(title = "获取阿里药品码段信息列表包括查询国家库", businessType = BusinessType.OTHER) public BaseResponse> thirdAliDrugList(@RequestBody AlihealthThirdAliDrugInsertReqeust alihealthThirdAliDrugInsertReqeust) { List thirdAliDrugsListGjk = null; PageSimpleResponse pageSimpleResponse =new PageSimpleResponse(); // 本地查询和新增都先注释了 到时候加到这边来 YbDrug ybDrug = alihealthThirdAliDrugInsertReqeust.getYbDrug(); if(ybDrug!= null && StringUtils.isNotEmpty(ybDrug.getGoodsCode())){ // 用医保编码查询国家库药品信息 try { CodeRel codeReNew = new CodeRel(); codeReNew.setYbbm(ybDrug.getGoodsCode()); String response = HttpUtil.post(udiUrl + "/udchs/codeRel/listAndAliDrug", JSONUtil.toJsonStr(codeReNew)); BaseResponse> responseListAndAliDrug = JSONObject.parseObject(response, new TypeReference>>() { }); if(responseListAndAliDrug.getCode() == 20000){ thirdAliDrugsListGjk = responseListAndAliDrug.getData(); if(thirdAliDrugsListGjk != null && thirdAliDrugsListGjk.size() >0){ pageSimpleResponse.setList(thirdAliDrugsListGjk); return ResultVOUtils.success(pageSimpleResponse); } }else { pageSimpleResponse.setList(thirdAliDrugsListGjk); return ResultVOUtils.success(pageSimpleResponse); } } catch (Exception e) { log.error("国家库===用医保编码查询国家库药品信息===出现错误===" + e.getMessage()); } } // 校验标识判断 为false不会后续增加多玛融合库的逻辑 直接返回 if(alihealthThirdAliDrugInsertReqeust.isDrugCheckMark() == false){ pageSimpleResponse.setList(thirdAliDrugsListGjk); return ResultVOUtils.success(pageSimpleResponse); } // 查询国家库药品信息 并且要插入到多玛融合表 AlihealthKytDrugrescodeReqeust alihealthKytDrugrescodeReqeust = alihealthThirdAliDrugInsertReqeust.getAlihealthKytDrugrescodeReqeust(); Map map = new HashMap(); if (com.glxp.api.util.StringUtils.isNotEmpty(alihealthKytDrugrescodeReqeust.getPhysic_name())) { map.put("cpmctymc", alihealthKytDrugrescodeReqeust.getPhysic_name()); } if (com.glxp.api.util.StringUtils.isNotEmpty(alihealthKytDrugrescodeReqeust.getApproval_licence_no())) { map.put("approvalNum", alihealthKytDrugrescodeReqeust.getApproval_licence_no()); } if (com.glxp.api.util.StringUtils.isNotEmpty(alihealthThirdAliDrugInsertReqeust.getManufactory())) { map.put("manufacturer", alihealthThirdAliDrugInsertReqeust.getManufactory()); } if (com.glxp.api.util.StringUtils.isNotEmpty(alihealthThirdAliDrugInsertReqeust.getFormSpec())) { map.put("formSpec", alihealthThirdAliDrugInsertReqeust.getFormSpec()); } if (com.glxp.api.util.StringUtils.isNotEmpty(alihealthThirdAliDrugInsertReqeust.getBzgg())) { map.put("bzgg", alihealthThirdAliDrugInsertReqeust.getBzgg()); } map.put("page", alihealthThirdAliDrugInsertReqeust.getPage()); map.put("limit", alihealthThirdAliDrugInsertReqeust.getLimit()); map.put("nameCodeIn", alihealthThirdAliDrugInsertReqeust.getNameCodeIn()); if(alihealthThirdAliDrugInsertReqeust.getGjkSwitch()){ try { String response = HttpUtil.get(udiUrl + "/udiwms/aliDrug/getDrugLevelList", map); BaseResponse> udiDlDeviceResponse = JSONObject.parseObject(response, new TypeReference>>() { }); if (udiDlDeviceResponse != null ) { // 查询国家库是否有值 有值直接返回没值查询阿里接口 thirdAliDrugsListGjk = udiDlDeviceResponse.getData().getList(); if(thirdAliDrugsListGjk.size() == udiDlDeviceResponse.getData().getTotal()){ thirdAliDrugsListGjk = PaginationUtil.getPage(thirdAliDrugsListGjk, alihealthThirdAliDrugInsertReqeust.getPage() , alihealthThirdAliDrugInsertReqeust.getLimit()); } pageSimpleResponse.setList(thirdAliDrugsListGjk); pageSimpleResponse.setTotal(Long.valueOf(udiDlDeviceResponse.getData().getTotal())); } } catch (Exception e) { log.error("国家库===查询药品信息===出现错误===" + e.getMessage()); } } // if (thirdAliDrugsListGjk != null && thirdAliDrugsListGjk.size() > 0) { // // } else { //// BaseResponse> baseResponse = alihealthUtils.thirdAliDrugInsertAll(alihealthThirdAliDrugInsertReqeust); //// if (baseResponse.getCode() == 20000) { //// thirdAliDrugsListGjk = baseResponse.getData(); //// } else { //// log.error("阿里接口未查到产品信息===" + baseResponse.getMessage()); //// return ResultVOUtils.error("阿里接口未查到产品信息===" + baseResponse.getMessage()); //// //// } //// // 上传到国家库 //// try { //// Map mapNew = new HashMap(); //// mapNew.put("list", thirdAliDrugsListGjk); //// String response = HttpUtil.post(udiUrl + "/udiwms/aliDrug/addThirdAliDrug", JSONUtil.toJsonStr(mapNew)); //// BaseResponse baseResponseAdd = JSONUtil.toBean(response, BaseResponse.class); //// log.info("成功上传国家库阿里产品数据"); //// } catch (Exception e) { //// //// log.error("国家库上传阿里产品访问出现错误===" + e.getMessage()); //// } // // } // // 上传多玛关系于处理规则在插入到融合表 // if(ybDrug!= null && StringUtils.isNotEmpty(ybDrug.getGoodsCode()) // ){ // // 规则匹配 // thirdAliDrugsListGjk = udiContrastService.disposeYbDrugList(thirdAliDrugsListGjk,ybDrug,alihealthThirdAliDrugInsertReqeust.getNameCodeIn()); // // } return ResultVOUtils.success(pageSimpleResponse); // udiProductService.insertUdiInfo(udiProductEntity); } @Resource AlihealthBusService alihealthBusService; @Resource IoOrderService orderService; /** * 阿里的采购单查询接口 * * @param aliYljgSearchbillReqeust * @return */ @PostMapping("/spms/alihealth/aliYljgSearchbillPage") @Log(title = "获取阿里药品的采购单", businessType = BusinessType.OTHER) public BaseResponse aliYljgSearchbillPage(@RequestBody AliYljgSearchbillReqeust aliYljgSearchbillReqeust) { String customerId = getCustomerId(); aliYljgSearchbillReqeust.setErpId(customerId); List list = alihealthBusService.aliYljgSearchbillPage(aliYljgSearchbillReqeust); List listResp = new ArrayList<>(); if (CollUtil.isEmpty(list)) { PageInfo pageInfo = new PageInfo<>(listResp); return ResultVOUtils.page(pageInfo); } // 使用 groupingBy 进行分组 Map> groupedByMultipleFields = list.stream() .collect(Collectors.groupingBy( bill -> bill.getBillCode() )); // 遍历分组结果 for (Map.Entry> entry : groupedByMultipleFields.entrySet()) { List group = entry.getValue(); if (!group.isEmpty()) { // 添加每个分组中的第一个对象到新列表 String key = entry.getKey(); //如果查得到就不可以再次选入 String billNo = orderService.selectAliYljgSearchbillByAliBillNo(key); AliYljgSearchbill aliYljgSearchbill = group.get(0); if (StringUtils.isNotEmpty(billNo)) { aliYljgSearchbill.setCheckBillNO(true); } listResp.add(aliYljgSearchbill); } } PageInfo pageInfo = new PageInfo<>(listResp); return ResultVOUtils.page(pageInfo); } /** * 阿里的采购单码明细查询接口 * * @param aliYljgSearchbillReqeust * @return */ @PostMapping("/spms/alihealth/aliYljgBillDetail") @Log(title = "获取阿里药品的采购单码明细", businessType = BusinessType.OTHER) public BaseResponse aliYljgBillDetail(@RequestBody AliYljgSearchbillReqeust aliYljgSearchbillReqeust) { AliYljgBillDetail aliYljgBillDetail = alihealthBusService.aliYljgBillDetail(aliYljgSearchbillReqeust); return ResultVOUtils.success(aliYljgBillDetail); } }