|
|
package com.glxp.mipsdl.client.ptxhyy;
|
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.glxp.mipsdl.client.CommonHttpClient;
|
|
|
import com.glxp.mipsdl.config.ThirdSysConfig;
|
|
|
import com.glxp.mipsdl.constant.ConstantType;
|
|
|
import com.glxp.mipsdl.constant.Constants;
|
|
|
import com.glxp.mipsdl.dao.auth.AuthWarehouseDao;
|
|
|
import com.glxp.mipsdl.dao.basic.BasicBussinessTypeDao;
|
|
|
import com.glxp.mipsdl.dao.basic.BasicCorpDao;
|
|
|
import com.glxp.mipsdl.dao.inout.IoCodeDao;
|
|
|
import com.glxp.mipsdl.dao.inout.IoOrderDao;
|
|
|
import com.glxp.mipsdl.dao.inout.IoOrderDetailBizDao;
|
|
|
import com.glxp.mipsdl.dao.thrsys.ThrBustypeOriginDao;
|
|
|
import com.glxp.mipsdl.dao.thrsys.ThrInvWarehouseDao;
|
|
|
import com.glxp.mipsdl.dao.thrsys.ThrSystemBusApiDao;
|
|
|
import com.glxp.mipsdl.entity.auth.AuthWarehouseEntity;
|
|
|
import com.glxp.mipsdl.entity.basic.BasicBussinessTypeEntity;
|
|
|
import com.glxp.mipsdl.entity.inout.IoCodeEntity;
|
|
|
import com.glxp.mipsdl.entity.inout.IoOrderDetailBizEntity;
|
|
|
import com.glxp.mipsdl.entity.inout.IoOrderEntity;
|
|
|
import com.glxp.mipsdl.entity.thrsys.ThrCorpEntity;
|
|
|
import com.glxp.mipsdl.entity.thrsys.ThrInvWarehouseEntity;
|
|
|
import com.glxp.mipsdl.entity.thrsys.ThrSystemBusApiEntity;
|
|
|
import com.glxp.mipsdl.http.HttpClient;
|
|
|
import com.glxp.mipsdl.req.base.*;
|
|
|
import com.glxp.mipsdl.res.BaseResponse;
|
|
|
import com.glxp.mipsdl.service.auth.AuthWarehouseService;
|
|
|
import com.glxp.mipsdl.service.thrsys.ThrCorpService;
|
|
|
import com.glxp.mipsdl.service.thrsys.ThrSystemDetailService;
|
|
|
import com.glxp.mipsdl.util.DateUtil;
|
|
|
import com.glxp.mipsdl.util.ResultVOUtils;
|
|
|
import com.glxp.mipsdl.util.SubmitOrderUtil;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 平潭协和医院接口
|
|
|
*/
|
|
|
@Slf4j
|
|
|
@Service(value = "100008HttpClient")
|
|
|
@RequiredArgsConstructor
|
|
|
public class PtxhyyClient extends CommonHttpClient {
|
|
|
|
|
|
|
|
|
private final ThirdSysConfig thirdSysConfig;
|
|
|
private final IoOrderDao orderDao;
|
|
|
private final ThrSystemBusApiDao thrSystemBusApiDao;
|
|
|
private final BasicBussinessTypeDao basicBussinessTypeDao;
|
|
|
private final BasicCorpDao basicCorpDao;
|
|
|
private final AuthWarehouseDao authWarehouseDao;
|
|
|
private final ThrInvWarehouseDao thrInvWarehouseDao;
|
|
|
private final AuthWarehouseService authWarehouseService;
|
|
|
private final ThrCorpService thrCorpService;
|
|
|
private final IoCodeDao codeDao;
|
|
|
private final IoOrderDetailBizDao orderDetailBizDao;
|
|
|
private final SubmitOrderUtil submitOrderUtil;
|
|
|
|
|
|
@Override
|
|
|
public BaseResponse submitOrders(UdiwmsOrderRequest udiwmsOrderRequest) {
|
|
|
if (StrUtil.isBlank(udiwmsOrderRequest.getBillNo())) {
|
|
|
return ResultVOUtils.error(500, "单据号不能为空");
|
|
|
}
|
|
|
//查询单据和详情信息,组装第三方系统接口参数
|
|
|
IoOrderEntity orderEntity = orderDao.selectOne(new LambdaQueryWrapper<IoOrderEntity>().eq(IoOrderEntity::getBillNo, udiwmsOrderRequest.getBillNo()));
|
|
|
udiwmsOrderRequest.setBillDate(DateUtil.formatDateTime(orderEntity.getCreateTime()));
|
|
|
//查询对应的第三方单据类型
|
|
|
ThrSystemBusApiEntity thrSystemBusApiEntity = thrSystemBusApiDao.selectOne(new LambdaQueryWrapper<ThrSystemBusApiEntity>().eq(ThrSystemBusApiEntity::getCode, udiwmsOrderRequest.getBillType()));
|
|
|
if (StrUtil.isBlank(thrSystemBusApiEntity.getUrl())) {
|
|
|
return ResultVOUtils.error(500, "接口未配置,无法提交!");
|
|
|
}
|
|
|
udiwmsOrderRequest.setBillType(thrSystemBusApiEntity.getThirdBuyCode());
|
|
|
//查询单据类型,设置往来单位信息
|
|
|
BasicBussinessTypeEntity basicBussinessTypeEntity = basicBussinessTypeDao.selectByAction(udiwmsOrderRequest.getBillType());
|
|
|
if (basicBussinessTypeEntity.getCorpType().equals(Constants.CORP_HOSPTIAL)) {
|
|
|
//医院客户
|
|
|
udiwmsOrderRequest.setCorpId(orderEntity.getFromCorp());
|
|
|
//查询客户名称
|
|
|
String corpName = basicCorpDao.selectNameByErpId(orderEntity.getFromCorp());
|
|
|
udiwmsOrderRequest.setCorpName(corpName);
|
|
|
} else if (basicBussinessTypeEntity.getCorpType().equals(Constants.CORP_INTTERNAL)) {
|
|
|
//内部科室
|
|
|
AuthWarehouseEntity warehouseEntity = authWarehouseDao.selectOne(new LambdaQueryWrapper<AuthWarehouseEntity>().eq(AuthWarehouseEntity::getCode, udiwmsOrderRequest.getCorpId()));
|
|
|
try {
|
|
|
//根据第三方系统标识,获取对应字段的值
|
|
|
ThrInvWarehouseEntity thrInvWarehouseEntity = thrInvWarehouseDao.selectOne(new LambdaQueryWrapper<ThrInvWarehouseEntity>()
|
|
|
.eq(ThrInvWarehouseEntity::getCode, authWarehouseService.getThirdInvCode(warehouseEntity))
|
|
|
.eq(ThrInvWarehouseEntity::getThirdSysFk, thirdSysConfig.getThirdId()));
|
|
|
udiwmsOrderRequest.setCorpId(thrInvWarehouseEntity.getCode());
|
|
|
udiwmsOrderRequest.setCorpName(thrInvWarehouseEntity.getName());
|
|
|
} catch (Exception e) {
|
|
|
String msg = "查询单据对应往来单位的第三方仓库信息异常";
|
|
|
log.error(msg, e);
|
|
|
return ResultVOUtils.error(500, msg);
|
|
|
}
|
|
|
} else if (basicBussinessTypeEntity.getCorpType().equals(Constants.CORP_SP)) {
|
|
|
//供应商
|
|
|
ThrCorpEntity thrCorp = thrCorpService.getThrCorp(udiwmsOrderRequest.getCorpId());
|
|
|
if (null != thrCorp) {
|
|
|
udiwmsOrderRequest.setCorpId(thrCorp.getUnitId());
|
|
|
udiwmsOrderRequest.setCorpName(thrCorp.getName());
|
|
|
} else {
|
|
|
String msg = "查询单据对应的第三方往来单位信息异常";
|
|
|
log.error(msg);
|
|
|
return ResultVOUtils.error(500, msg);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//查询仓库信息
|
|
|
AuthWarehouseEntity warehouseEntity = authWarehouseDao.selectOne(new LambdaQueryWrapper<AuthWarehouseEntity>().eq(AuthWarehouseEntity::getCode, orderEntity.getInvCode()));
|
|
|
try {
|
|
|
ThrInvWarehouseEntity thrInvWarehouseEntity = thrInvWarehouseDao.selectOne(new LambdaQueryWrapper<ThrInvWarehouseEntity>()
|
|
|
.eq(ThrInvWarehouseEntity::getCode, authWarehouseService.getThirdInvCode(warehouseEntity))
|
|
|
.eq(ThrInvWarehouseEntity::getThirdSysFk, thirdSysConfig.getThirdId()));
|
|
|
|
|
|
udiwmsOrderRequest.setLocInvCode(thrInvWarehouseEntity.getCode());
|
|
|
udiwmsOrderRequest.setLocInvName(thrInvWarehouseEntity.getName());
|
|
|
|
|
|
// udiwmsOrderRequest.setLocStorageCode(thrInvWarehouseEntity.getCode());
|
|
|
// udiwmsOrderRequest.setLocStorageName(thrInvWarehouseEntity.getName());
|
|
|
} catch (Exception e) {
|
|
|
log.info("查询第三方系统仓库信息异常", e);
|
|
|
}
|
|
|
|
|
|
// if (StrUtil.nullToEmpty(thrSystemBusApiEntity.getUrl()).equals("useOut")) {
|
|
|
// udiwmsOrderRequest.setCorpId(udiwmsOrderRequest.getLocStorageCode());
|
|
|
// udiwmsOrderRequest.setCorpName(udiwmsOrderRequest.getLocStorageName());
|
|
|
//
|
|
|
// ThrInvWarehouseEntity thrInvWarehouseEntity = thrInvWarehouseDao.selectOne(new LambdaQueryWrapper<ThrInvWarehouseEntity>().eq(ThrInvWarehouseEntity::getCode, "29")
|
|
|
// .eq(ThrInvWarehouseEntity::getThirdSysFk, thirdSysConfig.getThirdId()));
|
|
|
// udiwmsOrderRequest.setLocStorageCode("29");
|
|
|
// udiwmsOrderRequest.setLocStorageName(thrInvWarehouseEntity.getName());
|
|
|
// }
|
|
|
|
|
|
udiwmsOrderRequest.setBillFlag("1");
|
|
|
//设置单据出入库类型
|
|
|
if (basicBussinessTypeEntity.getMainAction().equals(ConstantType.TYPE_PUT)) {
|
|
|
udiwmsOrderRequest.setInoutType(1); //入库
|
|
|
} else if (basicBussinessTypeEntity.getMainAction().equals(ConstantType.TYPE_OUT)) {
|
|
|
udiwmsOrderRequest.setInoutType(2); //出库
|
|
|
}
|
|
|
|
|
|
udiwmsOrderRequest.setRemark("udi管理系统提交单据");
|
|
|
|
|
|
//组装单据明细数据
|
|
|
List<IoCodeEntity> ioCodeEntities = codeDao.selectList(new LambdaQueryWrapper<IoCodeEntity>()
|
|
|
.eq(IoCodeEntity::getOrderId, orderEntity.getBillNo())
|
|
|
.ne(IoCodeEntity::getAction, "StockCheck")
|
|
|
);
|
|
|
|
|
|
List<UdiwmsOrderDetailRequest> items = new ArrayList<>();
|
|
|
//查询业务单据详情
|
|
|
List<IoOrderDetailBizEntity> detailBizEntities = orderDetailBizDao.selectList(new LambdaQueryWrapper<IoOrderDetailBizEntity>().eq(IoOrderDetailBizEntity::getOrderIdFk, orderEntity.getBillNo()));
|
|
|
|
|
|
|
|
|
setOrderDetailList(ioCodeEntities, items, detailBizEntities);
|
|
|
|
|
|
Collections.reverse(items);
|
|
|
|
|
|
//云霄使用items字段,其他医院使用item字段
|
|
|
udiwmsOrderRequest.setItem(items);
|
|
|
|
|
|
return submitOrderUtil.submitOrder(orderEntity, udiwmsOrderRequest);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 封装单据详情参数
|
|
|
*
|
|
|
* @param ioCodeEntities 单据码明细
|
|
|
* @param orderDetailRequests 单据详情参数
|
|
|
* @param detailBizEntities 单据业务详情
|
|
|
*/
|
|
|
private void setOrderDetailList(List<IoCodeEntity> ioCodeEntities, List<UdiwmsOrderDetailRequest> orderDetailRequests, List<IoOrderDetailBizEntity> detailBizEntities) {
|
|
|
for (IoOrderDetailBizEntity detailBizEntity : detailBizEntities) {
|
|
|
UdiwmsOrderDetailRequest item = submitOrderUtil.buildProductInfo(detailBizEntity);
|
|
|
//封装条码信息
|
|
|
submitOrderUtil.setCodeList(ioCodeEntities, detailBizEntity, item);
|
|
|
orderDetailRequests.add(item);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|