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/controller/alihealth/AlihealthBusController.java

275 lines
13 KiB
Java

package com.glxp.api.controller.alihealth;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.github.pagehelper.PageInfo;
import com.glxp.api.annotation.Log;
import com.glxp.api.common.res.BaseResponse;
import com.glxp.api.common.util.ResultVOUtils;
import com.glxp.api.constant.BusinessType;
import com.glxp.api.controller.BaseController;
import com.glxp.api.controller.inout.IoOrderReviewController;
import com.glxp.api.entity.alihealth.AliYljgBillDetail;
import com.glxp.api.entity.alihealth.AliYljgSearchbill;
import com.glxp.api.entity.collect.IoCollectCodeBackup;
import com.glxp.api.entity.inout.IoOrderEntity;
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.AliBillsDisposeReqeust;
import com.glxp.api.req.alihealth.local.AlihealthGetRelCodeReqeust;
import com.glxp.api.req.alihealth.local.AlihealthRelCodeInsertReqeust;
import com.glxp.api.req.alihealth.local.AlihealthThirdAliDrugInsertReqeust;
import com.glxp.api.req.thrsys.ThirdAliDrugRequest;
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.collect.RelCodeBatchService;
import com.glxp.api.service.inout.IoOrderService;
import com.glxp.api.util.alihealth.AlihealthUtils;
import com.glxp.api.util.alihealth.PaginationUtil;
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.RestController;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
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());
}
}
@PostMapping("/spms/alihealth/thirdAliDrugList")
@Log(title = "获取阿里药品码段信息列表包括查询国家库", businessType = BusinessType.OTHER)
public BaseResponse<PageSimpleResponse<ThirdAliDrug>> thirdAliDrugList(@RequestBody AlihealthThirdAliDrugInsertReqeust alihealthThirdAliDrugInsertReqeust) {
List<ThirdAliDrug> thirdAliDrugsListGjk = null;
PageSimpleResponse<ThirdAliDrug> pageSimpleResponse = new PageSimpleResponse();
// 本地查询和新增都先注释了 到时候加到这边来
YbDrug ybDrug = alihealthThirdAliDrugInsertReqeust.getYbDrug();
if (alihealthThirdAliDrugInsertReqeust.isSelectCodeRelMark() && 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<List<ThirdAliDrug>> responseListAndAliDrug =
JSONObject.parseObject(response, new TypeReference<BaseResponse<List<ThirdAliDrug>>>() {
});
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());
}
} else {
// 查询国家库药品信息 并且要插入到多玛融合表
AlihealthKytDrugrescodeReqeust alihealthKytDrugrescodeReqeust = alihealthThirdAliDrugInsertReqeust.getAlihealthKytDrugrescodeReqeust();
ThirdAliDrugRequest thirdAliDrugRequest = new ThirdAliDrugRequest();
BeanUtil.copyProperties(alihealthThirdAliDrugInsertReqeust, thirdAliDrugRequest);
if (com.glxp.api.util.StringUtils.isNotEmpty(alihealthKytDrugrescodeReqeust.getPhysic_name())) {
thirdAliDrugRequest.setCpmctymc(alihealthKytDrugrescodeReqeust.getPhysic_name());
}
if (com.glxp.api.util.StringUtils.isNotEmpty(alihealthKytDrugrescodeReqeust.getApproval_licence_no())) {
thirdAliDrugRequest.setApprovalNum(alihealthKytDrugrescodeReqeust.getApproval_licence_no());
}
try {
String response = HttpUtil.get(udiUrl + "/udiwms/aliDrug/getDrugLevelList", BeanUtil.beanToMap(thirdAliDrugRequest));
BaseResponse<PageSimpleResponse<ThirdAliDrug>> udiDlDeviceResponse =
JSONObject.parseObject(response, new TypeReference<BaseResponse<PageSimpleResponse<ThirdAliDrug>>>() {
});
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());
}
return ResultVOUtils.success(pageSimpleResponse);
}
pageSimpleResponse.setList(thirdAliDrugsListGjk);
return ResultVOUtils.success(pageSimpleResponse);
}
@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<AliYljgSearchbill> list = alihealthBusService.aliYljgSearchbillPage(aliYljgSearchbillReqeust);
List<AliYljgSearchbill> listResp = new ArrayList<>();
if (CollUtil.isEmpty(list)) {
PageInfo<AliYljgSearchbill> pageInfo = new PageInfo<>(listResp);
return ResultVOUtils.page(pageInfo);
}
// 使用 groupingBy 进行分组
Map<String, List<AliYljgSearchbill>> groupedByMultipleFields = list.stream()
.collect(Collectors.groupingBy(
bill -> bill.getBillCode()
));
// 遍历分组结果
for (Map.Entry<String, List<AliYljgSearchbill>> entry : groupedByMultipleFields.entrySet()) {
List<AliYljgSearchbill> 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<AliYljgSearchbill> 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);
}
/**
* 阿里手动拉取完成单大级码没有关联关系的接口
*
* @return
*/
@Resource
private RelCodeBatchService relCodeBatchService;
@PostMapping("/spms/alihealth/getAliCode")
@Log(title = "阿里手动拉取完成单大级码没有关联关系的接口", businessType = BusinessType.OTHER)
public BaseResponse getAliCode(@RequestBody AlihealthGetRelCodeReqeust alihealthGetRelCodeReqeust) {
for (IoCollectCodeBackup ioCollectCodeBackup : alihealthGetRelCodeReqeust.getIoCollectCodeBackupList()) {
relCodeBatchService.addRelCodeAli(ioCollectCodeBackup.getCode(), ioCollectCodeBackup.getOperUser());
}
return ResultVOUtils.success("成功");
}
@Resource
private IoOrderReviewController ioOrderReviewController;
@PostMapping("/spms/alihealth/aliBillsDispose")
@Log(title = "手动调用阿里单据上传和关联关系拉取", businessType = BusinessType.OTHER)
public BaseResponse aliBillsDispose(@RequestBody AliBillsDisposeReqeust aliBillsDisposeReqeust) {
List<IoOrderEntity> ioOrderEntityList = aliBillsDisposeReqeust.getIoOrderEntityList();
log.error("开始补救上传和拉取关联关系列表==="+ioOrderEntityList);
for (IoOrderEntity ioOrderEntity : ioOrderEntityList) {
ioOrderReviewController.aliBillsDispose(ioOrderEntity);
}
return ResultVOUtils.success("成功");
}
}