|
|
|
@ -1,30 +1,38 @@
|
|
|
|
|
package com.glxp.api.service.collect;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
import com.glxp.api.common.res.BaseResponse;
|
|
|
|
|
import com.glxp.api.common.util.ResultVOUtils;
|
|
|
|
|
import com.glxp.api.constant.BusTypeConstant;
|
|
|
|
|
import com.glxp.api.dao.basic.BasicProductsDao;
|
|
|
|
|
import com.glxp.api.dao.basic.UdiRelevanceDao;
|
|
|
|
|
import com.glxp.api.entity.basic.BasicProductsEntity;
|
|
|
|
|
import com.glxp.api.entity.basic.UdiRelevanceEntity;
|
|
|
|
|
import com.glxp.api.entity.collect.IoCollectOrder;
|
|
|
|
|
import com.glxp.api.entity.collect.IoCollectOrderBiz;
|
|
|
|
|
import com.glxp.api.http.ErpBasicClient;
|
|
|
|
|
import com.glxp.api.req.basic.GetSickPrescribeRequest;
|
|
|
|
|
import com.glxp.api.req.collect.CollectOrderRequest;
|
|
|
|
|
import com.glxp.api.service.collect.down.*;
|
|
|
|
|
import com.glxp.api.req.thrsys.FilterThrOrderRequest;
|
|
|
|
|
import com.glxp.api.res.PageSimpleResponse;
|
|
|
|
|
import com.glxp.api.util.IntUtil;
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
import org.springframework.transaction.annotation.Isolation;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 下载工厂
|
|
|
|
|
*/
|
|
|
|
|
@Component
|
|
|
|
|
@Service
|
|
|
|
|
public class DownloadFactory {
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private YPCF002Download ypcf002Download;
|
|
|
|
|
@Resource
|
|
|
|
|
private QXCF001Download qxcf001Download;
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private ThrOrderDownload thrOrderDownload;
|
|
|
|
|
@Resource
|
|
|
|
|
private IoCollectOrderService ioCollectOrderService;
|
|
|
|
|
|
|
|
|
@ -42,17 +50,211 @@ public class DownloadFactory {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (busType.startsWith("YPCF")) {
|
|
|
|
|
return ypcf002Download.downloadOrder(collectOrderRequest);
|
|
|
|
|
return this.downloadErpOrder(collectOrderRequest,"YPCF");
|
|
|
|
|
} else
|
|
|
|
|
if (busType.equals(BusTypeConstant.QXCF001.getBusType())) {
|
|
|
|
|
return qxcf001Download.downloadOrder(collectOrderRequest);
|
|
|
|
|
return this.downloadErpOrder(collectOrderRequest,BusTypeConstant.QXCF001.getBusType());
|
|
|
|
|
} else
|
|
|
|
|
if (busType.contains("SC")) {
|
|
|
|
|
return ioCollectOrderService.importUdi(collectOrderRequest);
|
|
|
|
|
} else
|
|
|
|
|
{
|
|
|
|
|
return thrOrderDownload.downloadOrder(collectOrderRequest);
|
|
|
|
|
return this.downloadErpThrOrder(collectOrderRequest);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private ErpBasicClient erpBasicClient;
|
|
|
|
|
|
|
|
|
|
public BaseResponse downloadErpOrder(CollectOrderRequest collectOrderRequest,String busType) {
|
|
|
|
|
|
|
|
|
|
int page = 1;
|
|
|
|
|
int limit = 100;
|
|
|
|
|
GetSickPrescribeRequest getSickPrescribeRequest = new GetSickPrescribeRequest();
|
|
|
|
|
getSickPrescribeRequest.setLimit(limit);
|
|
|
|
|
getSickPrescribeRequest.setCode(collectOrderRequest.getBillNo());
|
|
|
|
|
getSickPrescribeRequest.setThirdSys("thirdId");
|
|
|
|
|
getSickPrescribeRequest.setWorkPlaceCode(collectOrderRequest.getWorkPlaceCode());
|
|
|
|
|
getSickPrescribeRequest.setFromType(collectOrderRequest.getFromType());
|
|
|
|
|
getSickPrescribeRequest.setStartTime(collectOrderRequest.getStartTime());
|
|
|
|
|
getSickPrescribeRequest.setEndTime(collectOrderRequest.getEndTime());
|
|
|
|
|
getSickPrescribeRequest.setKey(collectOrderRequest.getKeyWords());
|
|
|
|
|
getSickPrescribeRequest.setBusType(collectOrderRequest.getBusType());
|
|
|
|
|
while (true) {
|
|
|
|
|
List<IoCollectOrder> list;
|
|
|
|
|
try {
|
|
|
|
|
getSickPrescribeRequest.setPage(page);
|
|
|
|
|
BaseResponse<PageSimpleResponse<IoCollectOrder>> baseResponse = new BaseResponse<>();
|
|
|
|
|
|
|
|
|
|
if (busType.equals(BusTypeConstant.QXCF001.getBusType())){
|
|
|
|
|
baseResponse = erpBasicClient.getPrescribeQx(getSickPrescribeRequest);
|
|
|
|
|
}else {
|
|
|
|
|
baseResponse = erpBasicClient.getPrescribeV2(getSickPrescribeRequest);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: 2024/9/11 添加一张中间表(io_collect_order_origin)原始表做为转换
|
|
|
|
|
|
|
|
|
|
if (baseResponse.getCode() == 20000) {
|
|
|
|
|
list = baseResponse.getData().getList();
|
|
|
|
|
if (list == null) {
|
|
|
|
|
return ResultVOUtils.error(500, "未查到此业务单据");
|
|
|
|
|
}
|
|
|
|
|
importThrOrder(list, collectOrderRequest);
|
|
|
|
|
if ((list.size() >= limit && !baseResponse.getData().getTotal().equals(-666)) || IntUtil.value(baseResponse.getData().getTotal()) == -555) {
|
|
|
|
|
page++;
|
|
|
|
|
} else {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return ResultVOUtils.error(500, "下载第三方系统产品信息异常");
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
return ResultVOUtils.error(500, e.getMessage());
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ResultVOUtils.success("下载成功");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public BaseResponse downloadErpThrOrder(CollectOrderRequest collectOrderRequest) {
|
|
|
|
|
int page = 1;
|
|
|
|
|
int limit = 100;
|
|
|
|
|
FilterThrOrderRequest filterThrOrderRequest = new FilterThrOrderRequest();
|
|
|
|
|
filterThrOrderRequest.setLimit(limit);
|
|
|
|
|
filterThrOrderRequest.setBillNo(collectOrderRequest.getBillNo());
|
|
|
|
|
filterThrOrderRequest.setThirdSys("thirdId");
|
|
|
|
|
filterThrOrderRequest.setBusType(collectOrderRequest.getBusType());
|
|
|
|
|
filterThrOrderRequest.setWorkPlaceCode(collectOrderRequest.getWorkPlaceCode());
|
|
|
|
|
filterThrOrderRequest.setFromType(collectOrderRequest.getFromType());
|
|
|
|
|
filterThrOrderRequest.setStartTime(collectOrderRequest.getStartTime());
|
|
|
|
|
filterThrOrderRequest.setEndTime(collectOrderRequest.getEndTime());
|
|
|
|
|
while (true) {
|
|
|
|
|
filterThrOrderRequest.setPage(page);
|
|
|
|
|
BaseResponse<PageSimpleResponse<IoCollectOrder>> baseResponse = erpBasicClient.getThrOrders(filterThrOrderRequest);
|
|
|
|
|
if (baseResponse.getCode() == 20000) {
|
|
|
|
|
List<IoCollectOrder> list = baseResponse.getData().getList();
|
|
|
|
|
if (list == null) {
|
|
|
|
|
return ResultVOUtils.error(500, "未查到此业务单据");
|
|
|
|
|
}
|
|
|
|
|
// TODO: 2024/9/11 2024/9/11 添加一张中间表(io_collect_order_origin)原始表做为转换
|
|
|
|
|
importThrOrder(list, collectOrderRequest);
|
|
|
|
|
if ((list.size() >= limit && !baseResponse.getData().getTotal().equals(-666)) || IntUtil.value(baseResponse.getData().getTotal()) == -555) {
|
|
|
|
|
page++;
|
|
|
|
|
} else {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return ResultVOUtils.error(500, "下载第三方系统产品信息异常");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ResultVOUtils.success("下载成功");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
UdiRelevanceDao udiRelevanceDao;
|
|
|
|
|
@Resource
|
|
|
|
|
BasicProductsDao basicProductsDao;
|
|
|
|
|
@Resource
|
|
|
|
|
private IoCollectOrderService collectOrderService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 下载至单据
|
|
|
|
|
*
|
|
|
|
|
* @param thrOrderEntities
|
|
|
|
|
* @param collectOrderRequest
|
|
|
|
|
*/
|
|
|
|
|
public BaseResponse importThrOrder(List<IoCollectOrder> thrOrderEntities, CollectOrderRequest collectOrderRequest) {
|
|
|
|
|
List<IoCollectOrder> ioCollectOrderList = new ArrayList<>();
|
|
|
|
|
if (CollUtil.isNotEmpty(thrOrderEntities)) {
|
|
|
|
|
for (IoCollectOrder thrOrder : thrOrderEntities) {
|
|
|
|
|
IoCollectOrder ioCollectOrder = new IoCollectOrder();
|
|
|
|
|
BeanUtil.copyProperties(thrOrder, ioCollectOrder);
|
|
|
|
|
StringBuilder errorMsg = new StringBuilder();
|
|
|
|
|
ioCollectOrder.setFromType("HIS系统");
|
|
|
|
|
ioCollectOrder.setWorkPlaceCode(collectOrderRequest.getWorkPlaceCode());
|
|
|
|
|
ioCollectOrder.setCreateTime(new Date());
|
|
|
|
|
ioCollectOrder.setCreateUser(collectOrderRequest.getCreateUser());
|
|
|
|
|
ioCollectOrder.setBackupOrderRemark1(null);
|
|
|
|
|
ioCollectOrder.setUpdateTime(new Date());
|
|
|
|
|
ioCollectOrder.setSplitStatus(0);
|
|
|
|
|
ioCollectOrder.setTagStatus(0);
|
|
|
|
|
|
|
|
|
|
List<IoCollectOrderBiz> bizList = new ArrayList<>();
|
|
|
|
|
for (IoCollectOrderBiz entity : thrOrder.getBizList()) {
|
|
|
|
|
IoCollectOrderBiz collectOrderBiz = new IoCollectOrderBiz();
|
|
|
|
|
BeanUtil.copyProperties(entity, collectOrderBiz);
|
|
|
|
|
|
|
|
|
|
if (BusTypeConstant.QXCF001.getBusType().equals(collectOrderRequest.getBusType())) {
|
|
|
|
|
collectOrderBiz.setRelId(entity.getRelId());
|
|
|
|
|
if (StrUtil.isNotEmpty(entity.getCheckCode())) {
|
|
|
|
|
// 1. 先查询完全匹配的情况
|
|
|
|
|
LambdaQueryWrapper<BasicProductsEntity> exactMatchWrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
exactMatchWrapper.eq(BasicProductsEntity::getYbbm, entity.getCheckCode());
|
|
|
|
|
List<BasicProductsEntity> exactMatches = basicProductsDao.selectList(exactMatchWrapper);
|
|
|
|
|
if (exactMatches.isEmpty()) {
|
|
|
|
|
// 2. 如果没有完全匹配,则查询前20位匹配的情况
|
|
|
|
|
LambdaQueryWrapper<BasicProductsEntity> prefixMatchWrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
prefixMatchWrapper.apply("LEFT(ybbm, 20) = LEFT({0}, 20)", entity.getCheckCode());
|
|
|
|
|
exactMatches = basicProductsDao.selectList(prefixMatchWrapper);
|
|
|
|
|
}
|
|
|
|
|
if (exactMatches.isEmpty()) {
|
|
|
|
|
errorMsg.append(entity.getCpmctymc()).append("字典未对照").append(";");
|
|
|
|
|
}
|
|
|
|
|
// UdiRelevanceEntity udiRelevanceEntity = udiRelevanceDao.selectOne(new LambdaQueryWrapper<UdiRelevanceEntity>().eq(UdiRelevanceEntity::getUuid, exactMatches.get(0).getUuid()).last("limit 1"));
|
|
|
|
|
// if (udiRelevanceEntity != null) {
|
|
|
|
|
// collectOrderBiz.setRelId(udiRelevanceEntity.getId());
|
|
|
|
|
// }
|
|
|
|
|
} else {
|
|
|
|
|
BasicProductsEntity basicProductsEntity = basicProductsDao.selectOne(new LambdaQueryWrapper<BasicProductsEntity>().eq(BasicProductsEntity::getYbbm, entity.getYbbm()).last("limit 1"));
|
|
|
|
|
if (basicProductsEntity == null || StrUtil.isEmpty(basicProductsEntity.getNameCode())) {
|
|
|
|
|
errorMsg.append(entity.getCpmctymc()).append("字典未对照").append(";");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
collectOrderBiz.setTagStatus(1);
|
|
|
|
|
collectOrderBiz.setUnTagCount(0);
|
|
|
|
|
bizList.add(collectOrderBiz);
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
UdiRelevanceEntity basicUdirelEntity = udiRelevanceDao.selectOne(new LambdaQueryWrapper<UdiRelevanceEntity>().eq(UdiRelevanceEntity::getMainId, entity.getThrCode()).last("limit 1"));
|
|
|
|
|
if (basicUdirelEntity != null) {
|
|
|
|
|
collectOrderBiz.setRelId(basicUdirelEntity.getId());
|
|
|
|
|
BasicProductsEntity basicProductsEntity = basicProductsDao.selectOne(new LambdaQueryWrapper<BasicProductsEntity>().eq(BasicProductsEntity::getUuid, basicUdirelEntity.getUuid()).eq(BasicProductsEntity::getPackLevel, "1").last("limit 1"));
|
|
|
|
|
if (basicProductsEntity == null || StrUtil.isEmpty(basicProductsEntity.getNameCode())) {
|
|
|
|
|
errorMsg.append(entity.getCpmctymc()).append("字典未对照").append(";");
|
|
|
|
|
} else {
|
|
|
|
|
collectOrderBiz.setMeasureUnit(basicProductsEntity.getXjdw());
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
errorMsg.append(entity.getCpmctymc()).append("字典未对照").append(";");
|
|
|
|
|
}
|
|
|
|
|
collectOrderBiz.setTagStatus(1);
|
|
|
|
|
collectOrderBiz.setUnTagCount(0);
|
|
|
|
|
bizList.add(collectOrderBiz);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (StrUtil.isNotBlank(errorMsg)) {
|
|
|
|
|
ioCollectOrder.setTagStatus(4);
|
|
|
|
|
} else
|
|
|
|
|
ioCollectOrder.setTagStatus(2);
|
|
|
|
|
ioCollectOrder.setErrorMsg(errorMsg.toString());
|
|
|
|
|
ioCollectOrder.setBizList(bizList);
|
|
|
|
|
ioCollectOrderList.add(ioCollectOrder);
|
|
|
|
|
}
|
|
|
|
|
collectOrderService.importPrescribe(ioCollectOrderList, collectOrderRequest.getBusType());
|
|
|
|
|
return ResultVOUtils.success("下载成功");
|
|
|
|
|
}
|
|
|
|
|
return ResultVOUtils.error("下载失败");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|