feat: 阿里采购送货单的业务对接

dev_unify
chenhc 4 months ago
parent 4a92d3d323
commit dd9be6e8fe

@ -1,27 +1,29 @@
package com.glxp.api.controller.alihealth;
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.entity.auth.CustomerInfoEntity;
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.ThirdAliDrug;
import com.glxp.api.exception.JsonException;
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.res.PageSimpleResponse;
import com.glxp.api.res.alihealth.AlihealthKytGetentinfoResponse;
import com.glxp.api.service.alihealth.AlihealthBusService;
import com.glxp.api.util.alihealth.AlihealthUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
@ -142,4 +144,37 @@ public class AlihealthBusController {
}
// udiProductService.insertUdiInfo(udiProductEntity);
}
@Resource
AlihealthBusService alihealthBusService;
/**
*
* @param aliYljgSearchbillReqeust
* @return
*/
@PostMapping("/spms/alihealth/aliYljgSearchbillPage")
@Log(title = "获取阿里药品的采购单", businessType = BusinessType.OTHER)
public BaseResponse aliYljgSearchbillPage(@RequestBody AliYljgSearchbillReqeust aliYljgSearchbillReqeust) {
List<AliYljgSearchbill> list = alihealthBusService.aliYljgSearchbillPage(aliYljgSearchbillReqeust);
PageInfo<AliYljgSearchbill> pageInfo = new PageInfo<>(list);
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);
}
}

@ -957,385 +957,8 @@ public class IoCodeTempController extends BaseController {
if (bindingResult.hasErrors()) {
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage());
}
AddCodeResult addCodeResult = new AddCodeResult();
BasicBussinessTypeEntity bussinessTypeEntity = basicBussinessTypeService.findByAction(addOrderRequest.getAction());
InvWarehouseEntity invWarehouseEntity = invWarehouseService.findByInvSubByCode(addOrderRequest.getInvCode());
String code = addOrderRequest.getCode();
if (StringUtils.isBlank(code))
return ResultVOUtils.error(ResultEnum.DATA_ERROR);
if (code.endsWith("\u001D")) {
code = code.replace("\u001D", "");
}
UdiEntity udiEntity = FilterUdiUtils.getUdi(code);
if (udiEntity == null)
return ResultVOUtils.error(500, "无效条码!");
if (StrUtil.isNotEmpty(addOrderRequest.getBatchNo())) {
udiEntity.setBatchNo(addOrderRequest.getBatchNo());
}
if (StrUtil.isNotEmpty(addOrderRequest.getProduceDate())) {
udiEntity.setProduceDate(addOrderRequest.getProduceDate());
}
if (StrUtil.isNotEmpty(addOrderRequest.getExpireDate())) {
udiEntity.setExpireDate(addOrderRequest.getExpireDate());
}
if (StrUtil.isNotEmpty(addOrderRequest.getSerialNo())) {
udiEntity.setSerialNo(addOrderRequest.getSerialNo());
}
RelCodeDetailResponse codeRelEntity = null;
if (StrUtil.isEmpty(udiEntity.getBatchNo())) {
IoCodeLostEntity codeLostEntity = codeLostService.findByCode(code);
if (codeLostEntity != null) {
udiEntity.setBatchNo(codeLostEntity.getBatchNo());
udiEntity.setProduceDate(codeLostEntity.getProduceDate());
udiEntity.setExpireDate(codeLostEntity.getExpireDate());
} else {
codeRelEntity = relCodeDetailService.findByCode(code);
if (codeRelEntity != null) {
udiEntity.setBatchNo(codeRelEntity.getBatchNo());
udiEntity.setProduceDate(DateUtil.formatDate(codeRelEntity.getMadeDate(), "yyMMdd"));
udiEntity.setExpireDate(DateUtil.formatDate(codeRelEntity.getValidateDate(), "yyMMdd"));
}
}
}
//批次号校验
//判断此产品是否开启允许无批次号
UdiProductEntity udiInfoEntity = udiProductService.findByNameCode(udiEntity.getUdi());
if (udiInfoEntity == null) {
return ResultVOUtils.error(500, "耗材字典不存在此产品!");
}
String orderId = addOrderRequest.getBillNo();
//过期提醒:
if (IntUtil.value(bussinessTypeEntity.getCheckExpire()) == 1 && !addOrderRequest.isIgnoreExpire()) {
if (StrUtil.isNotEmpty(udiEntity.getExpireDate())) {
String expireDate = "20" + udiEntity.getExpireDate();
long expireTime = DateUtil.parseDateExpire(expireDate);
if (expireTime - System.currentTimeMillis() < 0) {
return ResultVOUtils.error(504, "当前产品已过期,是否确定继续添加?");
}
}
}
if (IntUtil.value(bussinessTypeEntity.getCheckExpire()) == 2) {
if (StrUtil.isNotEmpty(udiEntity.getExpireDate())) {
String expireDate = "20" + udiEntity.getExpireDate();
long expireTime = DateUtil.parseDateExpire(expireDate);
if (expireTime - System.currentTimeMillis() < 0) {
return ResultVOUtils.error(604, "当前产品已过期,无法添加?");
}
}
}
UdiRelevanceResponse udiRelevanceResponse = udiRelevanceService.selectByNameCode(udiEntity.getUdi());
long recent = 0;
if (udiRelevanceResponse.getRecentDateTime() != null)
recent = udiRelevanceResponse.getRecentDateTime().longValue();
if (IntUtil.value(bussinessTypeEntity.getCheckVailDate()) == 1 && recent > 0 && !addOrderRequest.isIgnoreRecentExpire()) {
if (StrUtil.isNotEmpty(udiEntity.getExpireDate())) {
String expireDate = "20" + udiEntity.getExpireDate();
long expireTime = DateUtil.parseDateExpire(expireDate);
long recentTieme = Math.abs(recent * 24 * 60 * 60 * 1000);
long resultTime = expireTime - System.currentTimeMillis();
if (resultTime > 0) {
long time = resultTime / (24 * 60 * 60 * 1000);
if (resultTime < recentTieme) {
return ResultVOUtils.error(505, "当前产品临近过期,距过期还剩" + time + "天,是否确定继续添加?");
}
}
}
}
if (IntUtil.value(bussinessTypeEntity.getCheckVailDate()) == 2 && recent > 0) {
if (StrUtil.isNotEmpty(udiEntity.getExpireDate())) {
String expireDate = "20" + udiEntity.getExpireDate();
long expireTime = DateUtil.parseDateExpire(expireDate);
long recentTieme = Math.abs(recent * 24 * 60 * 60 * 1000);
long resultTime = expireTime - System.currentTimeMillis();
if (resultTime > 0) {
long time = resultTime / (24 * 60 * 60 * 1000);
if (resultTime < recentTieme) {
return ResultVOUtils.error(605, "当前产品临近过期,距过期还剩" + time + "天,无法添加!");
}
}
}
}
//判断层级标识是否正确
if (bussinessTypeEntity.isUse()) {
if (udiRelevanceResponse.getUseMaxLevel() != null && IntUtil.value(udiRelevanceResponse.getUseMaxLevel()) < IntUtil.value(udiRelevanceResponse.getPackLevel())) {
return ResultVOUtils.error(500, "当前产品不支持采集该包装层级追溯码!");
}
if (udiRelevanceResponse.getUseMaxLevel() == null && IntUtil.value(udiRelevanceResponse.getPackLevel()) > 1) {
return ResultVOUtils.error(500, "当前产品不支持采集该包装层级追溯码!");
}
if (IntUtil.value(udiRelevanceResponse.getPackLevel()) < IntUtil.value(udiRelevanceResponse.getUseLevel())) {
return ResultVOUtils.error(500, "当前产品不支持采集该包装层级追溯码!");
}
} else {
if (udiRelevanceResponse.getDistributeMaxLevel() != null && IntUtil.value(udiRelevanceResponse.getDistributeMaxLevel()) < IntUtil.value(udiRelevanceResponse.getPackLevel())) {
return ResultVOUtils.error(500, "当前产品不支持采集该包装层级追溯码!");
}
if (IntUtil.value(udiRelevanceResponse.getPackLevel()) < IntUtil.value(udiRelevanceResponse.getDistributeLevel())) {
return ResultVOUtils.error(500, "当前产品不支持采集该包装层级追溯码!");
}
}
if (IntUtil.value(udiRelevanceResponse.getPackLevel()) == 0) {
RelCodeDetailResponse relCodeDetailResponse = relCodeDetailService.findByCode(code);
if (relCodeDetailResponse == null) {
return ResultVOUtils.error(500, "请先上传关联关系!");
}
}
//先生成扫码单据
IoOrderEntity orderEntity = orderService.findByBillNo(orderId);
String inBatch = "";
if (StringUtils.isBlank(orderId) || orderEntity == null) {
String orderNo = gennerOrderUtils.createScOrderNo(new OrderNoTypeBean(Constant.SCAN_ORDER + StrUtil.trimToEmpty(bussinessTypeEntity.getPrefix()), "yyyyMMdd"));
orderId = orderNo;
}
inBatch = orderId.substring((Constant.SCAN_ORDER + StrUtil.trimToEmpty(bussinessTypeEntity.getPrefix())).length());
List<IoCodeTempEntity> codeEnttitys = codeTempService.findByOrderId(orderId);
IoCodeTempEntity exitLocalEntity = null;
IoCodeTempEntity genDetaiEntity = new IoCodeTempEntity();
List<UdiRelevanceResponse> udiRelevanceResponses = null;
if (codeEnttitys.size() > 0) {
exitLocalEntity = isExitLocal(code, codeEnttitys);
if (exitLocalEntity != null) {
if (StrUtil.isEmpty(exitLocalEntity.getSupId()) || exitLocalEntity.getRelId() == null) {
return ResultVOUtils.error(500, "当前追溯码已存在,且存在异常未处理!");
}
if (StringUtils.isNotBlank(exitLocalEntity.getSerialNo())) {
return ResultVOUtils.error(500, "重复扫码!");
}
udiRelevanceResponses = udiRelevanceService.selectGroupByNameCode(exitLocalEntity.getNameCode(), null);
BeanUtils.copyProperties(exitLocalEntity, genDetaiEntity);
genDetaiEntity.setCount(1);
if (bussinessTypeEntity.isUse()) {
genDetaiEntity.setReCount(udiCalCountUtil.getUseActCount(udiRelevanceResponses.get(0)));
} else {
genDetaiEntity.setReCount(udiCalCountUtil.getCirActCount(udiRelevanceResponses.get(0)));
}
exitLocalEntity.setCount(exitLocalEntity.getMyCount() + 1);
if (bussinessTypeEntity.isUse()) {
exitLocalEntity.setReCount(exitLocalEntity.getMyReCount() * udiCalCountUtil.getUseActCount(udiRelevanceResponses.get(0)));
} else {
exitLocalEntity.setReCount(exitLocalEntity.getMyReCount() * udiCalCountUtil.getCirActCount(udiRelevanceResponses.get(0)));
}
BaseResponse invRes = checkInv(bussinessTypeEntity, exitLocalEntity);
if (invRes != null) {
return invRes;
}
if (addOrderRequest.getOrderType() == ConstantStatus.ORDER_TYPE_NORMAL && bussinessTypeEntity.isCheckEnable()) {
String errMsg = ioCheckInoutService.checkCode(genDetaiEntity);
if (errMsg != null) {
return ResultVOUtils.error(500, errMsg);
} else
codeTempService.updateById(exitLocalEntity);
} else if (addOrderRequest.getOrderType() == ConstantStatus.ORDER_TYPE_WAIT && bussinessTypeEntity.isCheckEnable()) {
String errMsg = ioCheckInoutService.checkNoPiCode(genDetaiEntity);
if (errMsg != null) {
return ResultVOUtils.error(500, errMsg);
} else
codeTempService.updateById(exitLocalEntity);
} else {
codeTempService.updateById(exitLocalEntity);
}
}
}
if (exitLocalEntity == null) {
if (codeTempService.ieExitRel(code, orderId)) {
return ResultVOUtils.error(500, "当前追溯码已上传关联关系,请勿重复扫码!");
}
IoCodeTempEntity codeEnttity = new IoCodeTempEntity();
codeEnttity.setCode(code);
codeEnttity.setOrderId(orderId);
codeEnttity.setCorpOrderId(addOrderRequest.getCorpOrderId());
codeEnttity.setCreateTime(new Date());
codeEnttity.setUpdateTime(new Date());
codeEnttity.setMainAction(bussinessTypeEntity.getMainAction());
codeEnttity.setAction(bussinessTypeEntity.getAction());
codeEnttity.setNameCode(udiEntity.getUdi());
codeEnttity.setBatchNo(udiEntity.getBatchNo());
codeEnttity.setProduceDate(udiEntity.getProduceDate());
codeEnttity.setExpireDate(udiEntity.getExpireDate());
codeEnttity.setSerialNo(udiEntity.getSerialNo());
codeEnttity.setDeptCode(invWarehouseEntity.getParentId());
codeEnttity.setInvCode(addOrderRequest.getInvCode());
if (codeRelEntity != null) {
codeEnttity.setParentCode(codeRelEntity.getParentCode());
RelCodeDetail relCodeDetail = relCodeDetailService.getOneByCode(codeRelEntity.getParentCode());
if (relCodeDetail != null) {
codeEnttity.setGrantPaCode(relCodeDetail.getParentCode());
}
}
codeEnttity.setCount(1);
codeEnttity.setProductType(2);
String unitFk = null;
if (bussinessTypeEntity.getCorpType() == ConstantStatus.CORP_TYPE_OUT) {
unitFk = addOrderRequest.getFromCorp();
}
//产品是否可以以使用单元入库
udiRelevanceResponses = udiRelevanceService.selectGroupByNameCode(codeEnttity.getNameCode(), false);
if (udiRelevanceResponses.size() >= 1) {
// UdiRelevanceResponse udiRelevanceResponse = udiRelevanceResponses.get(0);
if (udiRelevanceResponse == null) {
return ResultVOUtils.error(500, "该产品信息未维护!");
} else if (!udiRelevanceResponse.getUseDy() && udiRelevanceResponse.getDiType() == ConstantStatus.DITYPE_SYDY) {
return ResultVOUtils.error(500, "该产品不允许以使用单元入库!");
}
if (bussinessTypeEntity.isVailDispatch() && !udiRelevanceResponse.isDispatch()) {
return ResultVOUtils.error(500, "该产品不可配送,请联系院方!");
}
if (bussinessTypeEntity.getVailGroupBuy() == 1 && !udiRelevanceResponse.isGroupBuy()) { //只采集集采产品
return ResultVOUtils.error(500, bussinessTypeEntity.getName() + "单只允许录入集采产品!");
}
if (bussinessTypeEntity.getVailGroupBuy() == 2 && udiRelevanceResponse.isGroupBuy()) { //只采集非集采产品
return ResultVOUtils.error(500, bussinessTypeEntity.getName() + "单只允许录入非集采产品!");
}
//计算实际数量
if (bussinessTypeEntity.isUse()) {
codeEnttity.setReCount(IntUtil.value(codeEnttity.getMyReCount()) + udiCalCountUtil.getUseActCount(udiRelevanceResponse));
} else {
codeEnttity.setReCount(IntUtil.value(codeEnttity.getMyReCount()) + udiCalCountUtil.getCirActCount(udiRelevanceResponse));
}
} else if (udiRelevanceResponses.size() == 0) {
if (unitFk == null)
return ResultVOUtils.error(500, "药品字典不存在此产品!");
else
return ResultVOUtils.error(500, "当前供应商不存在此配送产品!");
}
//校验供应商是否配送此产品
BaseResponse corpResponse = checkCorp(codeEnttity, bussinessTypeEntity, unitFk);
if (corpResponse != null) {
return corpResponse;
}
IoOrderEntity isExit = orderService.findByBillNo(orderId);
if (isExit == null) {
orderEntity = new IoOrderEntity();
orderEntity.setBillNo(orderId);
orderEntity.setCorpOrderId(addOrderRequest.getCorpOrderId());
orderEntity.setMainAction(bussinessTypeEntity.getMainAction());
orderEntity.setAction(bussinessTypeEntity.getAction());
orderEntity.setFromCorp(addOrderRequest.getFromCorp());
if (StrUtil.isNotEmpty(addOrderRequest.getFromInvCode())) {
InvWarehouseEntity invWarehouseEntity1 = invWarehouseService.findByInvSubByCode(addOrderRequest.getFromInvCode());
orderEntity.setFromDeptCode(invWarehouseEntity1.getParentId());
}
orderEntity.setFromInvCode(addOrderRequest.getFromInvCode());
orderEntity.setFromType(ConstantStatus.FROM_WEBNEW);
orderEntity.setStatus(ConstantStatus.ORDER_STATUS_TEMP_SAVE);
orderEntity.setDealStatus(ConstantStatus.ORDER_DEAL_DRAFT);
AuthAdmin authAdmin = getUser();
orderEntity.setCreateUser(authAdmin.getId() + "");
orderEntity.setCreateTime(new Date());
orderEntity.setUpdateUser(authAdmin.getId() + "");
orderEntity.setUpdateTime(new Date());
orderEntity.setCustomerId(authAdmin.getCustomerId() + "");
orderEntity.setDeptCode(invWarehouseEntity.getParentId());
orderEntity.setCheckPreInOrders(addOrderRequest.getCheckPreInOrders());
orderEntity.setInvCode(addOrderRequest.getInvCode());
orderEntity.setOrderType(addOrderRequest.getOrderType());
orderEntity.setBusType(bussinessTypeEntity.getBusType());
orderEntity.setProductType(2);
orderService.insertOrder(orderEntity);
}
if (addOrderRequest.getOrderType() == ConstantStatus.ORDER_TYPE_NORMAL && bussinessTypeEntity.isCheckEnable() && bussinessTypeEntity.getCheckWebNew() != 0) {
boolean isBillExit = orderDetailBizService.isExit(orderEntity.getBillNo());
if (!isBillExit) {
orderService.deleteByBillNo(orderEntity.getBillNo());
return ResultVOUtils.error(500, "请先录入业务详情");
}
}
BaseResponse baseResponse = checkRelId(codeEnttity, unitFk);
BaseResponse invRes = checkInv(bussinessTypeEntity, codeEnttity);
if (invRes != null) {
return invRes;
}
genDetaiEntity = codeEnttity;
if (baseResponse == null) {
baseResponse = checkSupId(bussinessTypeEntity, codeEnttity, unitFk);
if (baseResponse != null)
return baseResponse;
} else {
if (baseResponse.getCode() == 501) {
return baseResponse;
} else if (baseResponse.getCode() == 502) {
return baseResponse;
}
checkSupId(bussinessTypeEntity, codeEnttity, unitFk);
return baseResponse;
}
if (IntUtil.value(bussinessTypeEntity.getCheckCertExpire()) == 2 && udiRelevanceResponse.isNeedCert()) {
SupProductEntity supProductEntity = supProductService.findExitByManufactury(udiRelevanceResponse.getCpmctymc(), udiRelevanceResponse.getManufactory(), unitFk);
if (supProductEntity != null && (supProductEntity.getAuditStatus() == ConstantStatus.AUDIT_PASS || supProductEntity.getAuditStatus() == ConstantStatus.AUDIT_CHANGE_PASS)) {
List<SupCertEntity> supCertEntities = supCertService.findByProductId(supProductEntity.getProductId());
if (CollUtil.isNotEmpty(supCertEntities)) {
Date curDate = new Date();
for (SupCertEntity supCertEntity : supCertEntities) {
if (supCertEntity.getExpireDate() != null && supCertEntity.getExpireDate().compareTo(curDate) < 0) {
return ResultVOUtils.error(500, "产品资质证书已过期!");
}
}
}
} else {
if (supProductEntity == null) {
return ResultVOUtils.error(500, "产品资质证书未维护!");
} else {
return ResultVOUtils.error(500, "产品资质证书未通过审核!");
}
}
}
codeEnttity.setPrice(udiRelevanceResponse.getPrice());
codeEnttity.setInBatchNo(inBatch);
//是否边扫边校验
if (addOrderRequest.getOrderType() == ConstantStatus.ORDER_TYPE_NORMAL && bussinessTypeEntity.isCheckEnable()) {
String errMsg = ioCheckInoutService.checkCode(codeEnttity);
if (errMsg != null) {
return ResultVOUtils.error(500, errMsg);
} else
codeTempService.insert(codeEnttity);
// 异步调用 查询是否存在药品关联信息 后将结果更新至 temp表
relCodeBatchService.threadUpdateIoCodeTempEntity(code);
} else if (addOrderRequest.getOrderType() == ConstantStatus.ORDER_TYPE_WAIT && bussinessTypeEntity.isCheckEnable()) {
String errMsg = ioCheckInoutService.checkDrugNoPiCode(codeEnttity);
if (errMsg != null) {
return ResultVOUtils.error(500, errMsg);
} else
codeTempService.insert(codeEnttity);
// 异步调用 查询是否存在药品关联信息 后将结果更新至 temp表
relCodeBatchService.threadUpdateIoCodeTempEntity(code);
} else {
codeTempService.insert(codeEnttity);
// 异步调用 查询是否存在药品关联信息 后将结果更新至 temp表
relCodeBatchService.threadUpdateIoCodeTempEntity(code);
}
}
addCodeResult.setOrderId(orderId);
transInoutService.genOrderDetailCode(orderEntity, genDetaiEntity);
return ResultVOUtils.success(addCodeResult);
return codeTempService.addDrugOrderWeb(addOrderRequest);
}

@ -5,6 +5,7 @@ import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.glxp.api.annotation.AuthRuleAnnotation;
import com.glxp.api.annotation.Log;
@ -16,7 +17,12 @@ import com.glxp.api.constant.BusinessType;
import com.glxp.api.constant.Constant;
import com.glxp.api.constant.ConstantStatus;
import com.glxp.api.controller.BaseController;
import com.glxp.api.dao.basic.UdiRelevanceDao;
import com.glxp.api.dao.inout.IoOrderDetailBizDao;
import com.glxp.api.entity.alihealth.AliYljgBillDetail;
import com.glxp.api.entity.alihealth.AliYljgBillDetailDrug;
import com.glxp.api.entity.alihealth.AliYljgBillDetailDrugCode;
import com.glxp.api.entity.alihealth.AliYljgSearchbill;
import com.glxp.api.entity.auth.AuthAdmin;
import com.glxp.api.entity.auth.InvWarehouseEntity;
import com.glxp.api.entity.basic.*;
@ -29,6 +35,8 @@ import com.glxp.api.entity.system.SystemParamConfigEntity;
import com.glxp.api.entity.thrsys.ThrOrderDetailEntity;
import com.glxp.api.entity.thrsys.ThrOrderEntity;
import com.glxp.api.entity.thrsys.ThrSystemBusApiEntity;
import com.glxp.api.req.alihealth.AliYljgSearchbillReqeust;
import com.glxp.api.req.basic.FilterUdiRelRequest;
import com.glxp.api.req.inout.*;
import com.glxp.api.req.inv.FilterInvoiceRequest;
import com.glxp.api.req.system.DeleteRequest;
@ -39,9 +47,11 @@ import com.glxp.api.res.inout.IoOrderDetailBizResponse;
import com.glxp.api.res.inout.IoOrderDetailCodeResponse;
import com.glxp.api.res.inout.IoOrderDetailResultResponse;
import com.glxp.api.res.inout.IoOrderInvoiceResponse;
import com.glxp.api.service.alihealth.AlihealthBusService;
import com.glxp.api.service.auth.InvWarehouseService;
import com.glxp.api.service.basic.*;
import com.glxp.api.service.inout.*;
import com.glxp.api.service.inout.impl.IoCodeTempService;
import com.glxp.api.service.inout.impl.IoOrderInvoiceService;
import com.glxp.api.service.purchase.PurOrderDetailService;
import com.glxp.api.service.purchase.PurOrderService;
@ -54,7 +64,9 @@ import com.glxp.api.service.thrsys.ThrSystemBusApiService;
import com.glxp.api.util.GennerOrderUtils;
import com.glxp.api.util.IntUtil;
import com.glxp.api.util.OrderNoTypeBean;
import com.glxp.api.util.udi.FilterUdiUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
@ -122,157 +134,9 @@ public class IoOrderDetailBizController extends BaseController {
@PostMapping("/udiwms/inout/order/addBizProduct")
@Log(title = "单据管理", businessType = BusinessType.INSERT)
public BaseResponse addBizProduct(@RequestBody AddBizProductReqeust addBizProductReqeust) {
SystemParamConfigEntity systemParamConfigEntity = systemParamConfigService.selectByParamKey("vail_product_cert");
// boolean isVailCert = systemParamConfigEntity.getParamValue().equals("1") ? true : false;
AuthAdmin authAdmin = getUser();
if (addBizProductReqeust.getRelId() == null && CollUtil.isEmpty(addBizProductReqeust.getDatas()))
return ResultVOUtils.error(500, "未选择产品信息");
if (addBizProductReqeust.getOrderEntity() == null)
return ResultVOUtils.error(500, "未指定订单");
IoOrderEntity orderEntity = addBizProductReqeust.getOrderEntity();
IoOrderEntity isExit = orderService.findByBillNo(orderEntity.getBillNo());
if (StrUtil.isEmpty(orderEntity.getBillNo()) || isExit == null) {
BasicBussinessTypeEntity bussinessTypeEntity = basicBussinessTypeService.findByAction(orderEntity.getAction());
InvWarehouseEntity invWarehouseEntity = invWarehouseService.findByInvSubByCode(orderEntity.getInvCode());
String orderNo = gennerOrderUtils.createScOrderNo(new OrderNoTypeBean(Constant.SCAN_ORDER + StrUtil.trimToEmpty(bussinessTypeEntity.getPrefix()), "yyyyMMdd"));
orderEntity.setBillNo(orderNo);
orderEntity.setCreateUser(authAdmin.getId() + "");
orderEntity.setCreateTime(new Date());
orderEntity.setMainAction(bussinessTypeEntity.getMainAction());
if (StrUtil.isNotEmpty(orderEntity.getFromInvCode())) {
InvWarehouseEntity fromEntity = invWarehouseService.findByInvSubByCode(orderEntity.getInvCode());
orderEntity.setFromDeptCode(fromEntity.getParentId());
}
orderEntity.setFromType(ConstantStatus.FROM_WEBNEW);
orderEntity.setStatus(ConstantStatus.ORDER_STATUS_TEMP_SAVE);
orderEntity.setDealStatus(ConstantStatus.ORDER_DEAL_DRAFT);
orderEntity.setCreateUser(authAdmin.getId() + "");
orderEntity.setCreateTime(new Date());
orderEntity.setUpdateUser(authAdmin.getId() + "");
orderEntity.setUpdateTime(new Date());
orderEntity.setCustomerId(authAdmin.getCustomerId() + "");
orderEntity.setDeptCode(invWarehouseEntity.getParentId());
orderEntity.setInvCode(orderEntity.getInvCode());
orderEntity.setBusType(bussinessTypeEntity.getBusType());
orderService.insertOrder(orderEntity);
}
List<AddBizProductReqeust> datas = new ArrayList<>();
if (CollUtil.isNotEmpty(addBizProductReqeust.getDatas())) {
datas.addAll(addBizProductReqeust.getDatas());
} else {
datas.add(addBizProductReqeust);
}
for (AddBizProductReqeust item : datas) {
UdiRelevanceResponse udiRelevanceResponse = udiRelevanceService.selectSupGroupById(item.getRelId(), addBizProductReqeust.getSupId());
BasicBussinessTypeEntity bussinessTypeEntity = basicBussinessTypeService.findByAction(orderEntity.getAction());
//是否校验产品采购类型 1校验2.无需校验
if (IntUtil.value(bussinessTypeEntity.getVailProductAttributes()) == 1) {
Integer purType = IntUtil.value(udiRelevanceResponse.getPurType()); //1普通入账产品2.预验收产品。3寄售产品
int actionType = IntUtil.value(bussinessTypeEntity.getActionType()); //1带票正常2.预验收。3寄售
if (purType != actionType) {
//包装友好提示
String msg = "";
switch (actionType) {
case 1:
msg = "普通入账产品";
break;
case 2:
msg = "预验收产品";
break;
case 3:
msg = "寄售产品";
break;
}
String msg2 = "";
switch (purType) {
case 1:
msg2 = "普通入账产品";
break;
case 2:
msg2 = "预验收产品";
break;
case 3:
msg2 = "寄售产品";
break;
}
return ResultVOUtils.error(500, "单据只允许录入" + msg + ",当前录入产品为" + msg2 + ",请检查后重试!");
}
}
if (bussinessTypeEntity != null && udiRelevanceResponse != null) {
//是否校验耗材材质 1高值耗材2.普通耗材
if (IntUtil.value(bussinessTypeEntity.getVailHcType()) == 1) {
if (IntUtil.value(udiRelevanceResponse.getHcType()) != 1) {
return ResultVOUtils.error(500, "单据只允许录入高值耗材" + ",请检查后重试!");
}
} else if (IntUtil.value(bussinessTypeEntity.getVailHcType()) == 2) {
if (IntUtil.value(udiRelevanceResponse.getHcType()) != 2) {
return ResultVOUtils.error(500, "单据只允许录入普通耗材" + ",请检查后重试!");
}
}
//是否开启校验扫码 0:不校验1:只允许录入扫码产品2:只允许录入不扫码产品
if (IntUtil.value(bussinessTypeEntity.getCodeCheck()) == 1) {
if (IntUtil.value(udiRelevanceResponse.getRequireScanCode()) != 1) {
return ResultVOUtils.error(500, "单据只允许录入需要扫码产品" + ",请检查后重试!");
}
} else if (IntUtil.value(bussinessTypeEntity.getCodeCheck()) == 2) {
if (IntUtil.value(udiRelevanceResponse.getRequireScanCode()) != 0) {
return ResultVOUtils.error(500, "单据只允许录入不需要扫码产品" + ",请检查后重试!");
}
}
}
if (IntUtil.value(bussinessTypeEntity.getCheckCertExpire()) == 2 && udiRelevanceResponse.isNeedCert()) {
SupProductEntity supProductEntity = supProductService.findExitByManufactury(udiRelevanceResponse.getCpmctymc(), udiRelevanceResponse.getManufactory(), authAdmin.getCustomerId());
if (supProductEntity != null && (supProductEntity.getAuditStatus() == ConstantStatus.AUDIT_PASS || supProductEntity.getAuditStatus() == ConstantStatus.AUDIT_CHANGE_PASS)) {
// List<SupCertEntity> supCertEntities = supCertService.findByProductId(supProductEntity.getProductId());
addBizProductReqeust.setProductId(supProductEntity.getProductId());
List<SupCertEntity> supCertEntities = supCertService.findByzczbhhzbapzbh(addBizProductReqeust);
if (CollUtil.isNotEmpty(supCertEntities)) {
Date curDate = new Date();
for (SupCertEntity supCertEntity : supCertEntities) {
if (supCertEntity.getExpireDate() != null && supCertEntity.getExpireDate().compareTo(curDate) < 0) {
return ResultVOUtils.error(500, "该注册备案号所属产品资质证书已过期!");
}
}
}
} else {
return ResultVOUtils.error(500, "产品资质证书未通过审核!");
}
}
if (bussinessTypeEntity.isVailDispatch()) {
if (!udiRelevanceResponse.isDispatch()) {
return ResultVOUtils.error(500, "该产品不可配送,请联系院方!");
}
}
IoOrderDetailBizEntity ioOrderDetailBizEntity = new IoOrderDetailBizEntity();
ioOrderDetailBizEntity.setOrderIdFk(orderEntity.getBillNo());
ioOrderDetailBizEntity.setBindRlFk(udiRelevanceResponse.getId());
ioOrderDetailBizEntity.setUuidFk(udiRelevanceResponse.getUuid());
ioOrderDetailBizEntity.setNameCode(udiRelevanceResponse.getNameCode());
ioOrderDetailBizEntity.setCoName(udiRelevanceResponse.getCpmctymc());
ioOrderDetailBizEntity.setCertCode(addBizProductReqeust.getZczbhhzbapzbh());
ioOrderDetailBizEntity.setYlqxzcrbarmc(udiRelevanceResponse.getYlqxzcrbarmc());
ioOrderDetailBizEntity.setManufacturer(udiRelevanceResponse.getManufactory());
ioOrderDetailBizEntity.setMeasname(udiRelevanceResponse.getMeasname());
ioOrderDetailBizEntity.setSpec(udiRelevanceResponse.getGgxh());
ioOrderDetailBizEntity.setPrice(udiRelevanceResponse.getPrice());
ioOrderDetailBizEntity.setProductDate(item.getProductDate());
ioOrderDetailBizEntity.setExpireDate(item.getExpireDate());
ioOrderDetailBizEntity.setBatchNo(item.getBatchNo());
ioOrderDetailBizEntity.setSupId(item.getSupId());
orderDetailBizService.insert(ioOrderDetailBizEntity);
}
return orderDetailBizService.addBizProduct(addBizProductReqeust);
orderEntity.setUpdateTime(new Date());
orderEntity.setUpdateUser(authAdmin.getId() + "");
orderService.update(orderEntity);
return ResultVOUtils.success(orderEntity);
}
@ -818,4 +682,103 @@ public class IoOrderDetailBizController extends BaseController {
return ResultVOUtils.page(pageInfo);
}
@Resource
IoCodeTempService ioCodeTempService;
@Resource
AlihealthBusService alihealthBusService;
@Resource
UdiRelevanceDao udiRelevanceDao;
//录入阿里送货单的业务单据详情
@AuthRuleAnnotation("")
@PostMapping("/udiwms/inout/order/addAliBizProduct")
@Log(title = "单据管理", businessType = BusinessType.INSERT)
@Transactional(rollbackFor = Exception.class)
public BaseResponse addAliBizProduct(@RequestBody AddBizProductReqeust addBizProductReqeust) {
//先获取阿里的行类 进行转换
AliYljgSearchbill aliData = addBizProductReqeust.getAliData();
if (aliData == null){
return ResultVOUtils.error("请先选择阿里的单据信息");
}
String billCode = aliData.getBillCode();
//去获取码明细
AliYljgSearchbillReqeust aliYljgSearchbillReqeust = new AliYljgSearchbillReqeust();
aliYljgSearchbillReqeust.setBillCode(billCode);
AliYljgBillDetail aliYljgBillDetail = alihealthBusService.aliYljgBillDetail(aliYljgSearchbillReqeust);
if (aliYljgBillDetail == null){
return ResultVOUtils.error("未找到单据信息!");
}
List<AliYljgBillDetailDrug> aliYljgBillDetailDrugList = aliYljgBillDetail.getAliYljgBillDetailDrugList();
if (CollUtil.isEmpty(aliYljgBillDetailDrugList)){
return ResultVOUtils.error("单据明细为空!");
}
List<AliYljgBillDetailDrugCode> aliYljgBillDetailDrugCodeList = aliYljgBillDetailDrugList.get(0).getAliYljgBillDetailDrugCodeList();
if (CollUtil.isEmpty(aliYljgBillDetailDrugCodeList)){
return ResultVOUtils.error("单据码明细为空!");
}
String code = aliYljgBillDetailDrugCodeList.get(0).getCode();
if (StrUtil.isEmpty(code)){
return ResultVOUtils.error("单据码为空!");
}
UdiEntity drugInfo = FilterUdiUtils.getDrugInfo(code);
if (drugInfo == null){
return ResultVOUtils.error("单据码解析药品信息错误!");
}
//获取药品信息
String nameCode = drugInfo.getUdi();
if (StrUtil.isEmpty(nameCode)){
return ResultVOUtils.error("单据码解析药品标识错误!");
}
FilterUdiRelRequest filterUdiRelRequest = new FilterUdiRelRequest();
filterUdiRelRequest.setNameCode(nameCode);
List<UdiRelevanceResponse> udiRelevanceResponses = udiRelevanceDao.filterUdiRelevance(filterUdiRelRequest);
if (CollUtil.isEmpty(udiRelevanceResponses)){
return ResultVOUtils.error("未通过药品标识获取详情信息!");
}
UdiRelevanceResponse udiRelevanceResponse = udiRelevanceResponses.get(0);
//1、直接模拟增加biz一行
addBizProductReqeust.setProductId(String.valueOf(udiRelevanceResponse.getProductId()));
addBizProductReqeust.setRelId(udiRelevanceResponse.getRelId());
addBizProductReqeust.setZczbhhzbapzbh(udiRelevanceResponse.getZczbhhzbapzbh());
addBizProductReqeust.setSupId(udiRelevanceResponse.getSupId());
addBizProductReqeust.setDatas(null);
IoOrderEntity ioOrderEntity = null;
for (int i = 0; i < aliYljgBillDetailDrugList.size(); i++) {
AliYljgBillDetailDrug aliYljgBillDetailDrug = aliYljgBillDetailDrugList.get(i);
addBizProductReqeust.setBatchNo(aliYljgBillDetailDrug.getProduceBatchNo());
addBizProductReqeust.setProductDate(aliYljgBillDetailDrug.getProduceDate());
addBizProductReqeust.setExpireDate(aliYljgBillDetailDrug.getProduceDate());
BaseResponse response = orderDetailBizService.addBizProduct(addBizProductReqeust);
if (response.getCode() != 20000){
return response;
}
if (i == 0){
ioOrderEntity = JSONObject.parseObject(JSONObject.toJSONString(response.getData()), IoOrderEntity.class);
}
}
AddOrderRequest addOrderRequest = new AddOrderRequest();
BeanUtils.copyProperties(ioOrderEntity,addOrderRequest);
for (int i = 0; i < aliYljgBillDetailDrugCodeList.size(); i++) {
AliYljgBillDetailDrugCode aliYljgBillDetailDrugCode = aliYljgBillDetailDrugCodeList.get(i);
addOrderRequest.setCode(aliYljgBillDetailDrugCode.getCode());
BaseResponse response = ioCodeTempService.addDrugOrderWeb(addOrderRequest);
if (response.getCode() != 20000){
return response;
}
}
return ResultVOUtils.success();
}
}

@ -0,0 +1,135 @@
package com.glxp.api.req.alihealth;
import com.baomidou.mybatisplus.annotation.TableField;
import com.glxp.api.entity.alihealth.AliYljgBillDetailDrugCode;
import com.glxp.api.util.page.ListPageRequest;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
import java.util.List;
@Data
public class AliYljgSearchbillReqeust extends ListPageRequest {
/**
*
*/
private String fromEntName;
/**
*
*/
private String codeCount;
/**
*
*/
private String exprieDate;
/**
*
*/
private String produceEntName;
/**
*
*/
private String produceDate;
/**
*
*/
private String produceBatchNo;
/**
*
*/
private String pkgSpec;
/**
*
*/
private String physicInfo;
/**
*
*/
private String physicName;
/**
*
*/
private String prepnCount;
/**
* REFENTID
*/
private String fromRefUserId;
/**
* REFENTID
*/
private String toRefUserId;
/**
*
*/
private String billTime;
/**
*
*/
private String billCode;
/**
*
*/
private String billType;
/**
*
*/
private String toUserName;
/**
*
*/
private String fromUserName;
/**
*
*/
private String exprieDateFormat;
/**
*
*/
private String billTimeFormat;
/**
* ID
*/
private String billOutId;
/**
*
*/
private String prepnUnit;
/**
*
*/
private String prepnSpec;
/**
* ID
*/
private String drugEntBaseInfoId;
/**
*
*/
private String produceDateFormat;
/**
* 12
*/
private String status;
private String erpId;
/**
*
*/
@TableField(value = "createTime")
@ApiModelProperty(value = "创建时间")
private Date createTime;
/**
*
*/
@TableField(value = "updateTime")
@ApiModelProperty(value = "更新时间")
private Date updateTime;
}

@ -1,5 +1,8 @@
package com.glxp.api.req.inout;
import com.glxp.api.entity.alihealth.AliYljgBillDetail;
import com.glxp.api.entity.alihealth.AliYljgBillDetailDrug;
import com.glxp.api.entity.alihealth.AliYljgSearchbill;
import com.glxp.api.entity.inout.IoOrderEntity;
import lombok.Data;
@ -20,5 +23,6 @@ public class AddBizProductReqeust {
private String expireDate;
List<AddBizProductReqeust> datas; //多选添加
AliYljgSearchbill aliData; //多选添加
}

@ -0,0 +1,16 @@
package com.glxp.api.service.alihealth;
import com.glxp.api.entity.alihealth.AliYljgBillDetail;
import com.glxp.api.entity.alihealth.AliYljgBillDetailDrug;
import com.glxp.api.entity.alihealth.AliYljgBillDetailDrugCode;
import com.glxp.api.entity.alihealth.AliYljgSearchbill;
import com.glxp.api.req.alihealth.AliYljgSearchbillReqeust;
import java.util.List;
public interface AlihealthBusService {
List<AliYljgSearchbill> aliYljgSearchbillPage(AliYljgSearchbillReqeust aliYljgSearchbillReqeust);
AliYljgBillDetail aliYljgBillDetail(AliYljgSearchbillReqeust aliYljgSearchbillReqeust);
}

@ -0,0 +1,42 @@
package com.glxp.api.service.alihealth.impl;
import com.github.pagehelper.PageHelper;
import com.glxp.api.entity.alihealth.AliYljgBillDetail;
import com.glxp.api.entity.alihealth.AliYljgBillDetailDrug;
import com.glxp.api.entity.alihealth.AliYljgBillDetailDrugCode;
import com.glxp.api.entity.alihealth.AliYljgSearchbill;
import com.glxp.api.req.alihealth.AliYljgSearchbillReqeust;
import com.glxp.api.service.alihealth.AlihealthBusService;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@Service
public class AlihealthBusServiceImpl implements AlihealthBusService {
@Override
public List<AliYljgSearchbill> aliYljgSearchbillPage(AliYljgSearchbillReqeust aliYljgSearchbillReqeust) {
if (aliYljgSearchbillReqeust == null) {
return Collections.emptyList();
}
if (aliYljgSearchbillReqeust.getPage() != null) {
int offset = (aliYljgSearchbillReqeust.getPage() - 1) * aliYljgSearchbillReqeust.getLimit();
PageHelper.offsetPage(offset, aliYljgSearchbillReqeust.getLimit());
}
// TODO: 2024/12/12
return new ArrayList<>();
}
@Override
public AliYljgBillDetail aliYljgBillDetail(AliYljgSearchbillReqeust aliYljgSearchbillReqeust) {
// TODO: 2024/12/12
AliYljgBillDetail aliYljgBillDetail = new AliYljgBillDetail();
return aliYljgBillDetail;
}
}

@ -1,6 +1,8 @@
package com.glxp.api.service.inout;
import com.glxp.api.common.res.BaseResponse;
import com.glxp.api.entity.inout.IoOrderDetailBizEntity;
import com.glxp.api.req.inout.AddBizProductReqeust;
import com.glxp.api.req.inout.FilterOrderDetailBizRequest;
import com.glxp.api.req.inout.FilterOrderDetailCodeRequest;
import com.glxp.api.res.inout.IoOrderDetailBizResponse;
@ -62,4 +64,6 @@ public interface IoOrderDetailBizService {
* @param oldBillNo
*/
boolean copyOrderDetailBiz(String newBillNo, String oldBillNo);
BaseResponse addBizProduct(AddBizProductReqeust addBizProductReqeust);
}

@ -6,18 +6,51 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageHelper;
import com.glxp.api.common.enums.ResultEnum;
import com.glxp.api.common.res.BaseResponse;
import com.glxp.api.common.util.ResultVOUtils;
import com.glxp.api.constant.Constant;
import com.glxp.api.constant.ConstantStatus;
import com.glxp.api.constant.ConstantType;
import com.glxp.api.dao.inout.IoCodeDao;
import com.glxp.api.dao.inout.IoCodeTempDao;
import com.glxp.api.entity.auth.AuthAdmin;
import com.glxp.api.entity.auth.InvWarehouseEntity;
import com.glxp.api.entity.basic.BasicBussinessTypeEntity;
import com.glxp.api.entity.basic.UdiEntity;
import com.glxp.api.entity.basic.UdiProductEntity;
import com.glxp.api.entity.collect.RelCodeDetail;
import com.glxp.api.entity.inout.IoCodeEntity;
import com.glxp.api.entity.inout.IoCodeLostEntity;
import com.glxp.api.entity.inout.IoCodeTempEntity;
import com.glxp.api.entity.inout.IoOrderEntity;
import com.glxp.api.entity.purchase.SupCertEntity;
import com.glxp.api.entity.purchase.SupProductEntity;
import com.glxp.api.req.basic.CompanyProductRelevanceRequest;
import com.glxp.api.req.inout.AddOrderRequest;
import com.glxp.api.req.inout.FilterCodeRequest;
import com.glxp.api.res.basic.UdiRelevanceResponse;
import com.glxp.api.res.collect.RelCodeDetailResponse;
import com.glxp.api.res.inout.AddCodeResult;
import com.glxp.api.res.inout.IoCodeTempResponse;
import com.glxp.api.service.auth.CustomerService;
import com.glxp.api.service.auth.InvWarehouseService;
import com.glxp.api.service.basic.*;
import com.glxp.api.service.collect.RelCodeBatchService;
import com.glxp.api.service.collect.RelCodeDetailService;
import com.glxp.api.util.BeanCopyUtils;
import com.glxp.api.service.inout.*;
import com.glxp.api.service.inv.InvPreProductDetailService;
import com.glxp.api.service.inv.InvPreinProductDetailService;
import com.glxp.api.service.inv.impl.InvProductServiceNew;
import com.glxp.api.service.purchase.SupCertService;
import com.glxp.api.service.purchase.SupProductService;
import com.glxp.api.service.system.SystemParamConfigService;
import com.glxp.api.util.*;
import com.glxp.api.util.page.PageQuery;
import com.glxp.api.util.page.TableDataInfo;
import com.glxp.api.util.udi.FilterUdiUtils;
import com.glxp.api.util.udi.UdiCalCountUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -26,6 +59,7 @@ import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;
@Service
@Transactional(rollbackFor = Exception.class)
@ -171,4 +205,562 @@ public class IoCodeTempService {
return true;
}
@Resource
UdiRelevanceService udiRelevanceService;
@Resource
UdiProductService udiProductService;
@Resource
GennerOrderUtils gennerOrderUtils;
@Resource
UdiCalCountUtil udiCalCountUtil;
@Resource
InvWarehouseService invWarehouseService;
@Resource
IoCheckInoutService ioCheckInoutService;
@Resource
IoCodeLostService codeLostService;
@Resource
IoOrderDetailBizService orderDetailBizService;
@Resource
private IBasicBussinessTypeService basicBussinessTypeService;
@Resource
private IoCodeTempService codeTempService;
@Resource
private IoOrderService orderService;
@Resource
CustomerService customerService;
@Resource
SupProductService supProductService;
@Resource
SupCertService supCertService;
@Resource
RelCodeBatchService relCodeBatchService;
@Resource
IoAddInoutService transInoutService;
@Resource
UdiRlSupService udiRlSupService;
@Resource
InvProductServiceNew invProductDetailService;
public BaseResponse addDrugOrderWeb(AddOrderRequest addOrderRequest) {
AddCodeResult addCodeResult = new AddCodeResult();
BasicBussinessTypeEntity bussinessTypeEntity = basicBussinessTypeService.findByAction(addOrderRequest.getAction());
InvWarehouseEntity invWarehouseEntity = invWarehouseService.findByInvSubByCode(addOrderRequest.getInvCode());
String code = addOrderRequest.getCode();
if (StringUtils.isBlank(code))
return ResultVOUtils.error(ResultEnum.DATA_ERROR);
if (code.endsWith("\u001D")) {
code = code.replace("\u001D", "");
}
UdiEntity udiEntity = FilterUdiUtils.getUdi(code);
if (udiEntity == null)
return ResultVOUtils.error(500, "无效条码!");
if (StrUtil.isNotEmpty(addOrderRequest.getBatchNo())) {
udiEntity.setBatchNo(addOrderRequest.getBatchNo());
}
if (StrUtil.isNotEmpty(addOrderRequest.getProduceDate())) {
udiEntity.setProduceDate(addOrderRequest.getProduceDate());
}
if (StrUtil.isNotEmpty(addOrderRequest.getExpireDate())) {
udiEntity.setExpireDate(addOrderRequest.getExpireDate());
}
if (StrUtil.isNotEmpty(addOrderRequest.getSerialNo())) {
udiEntity.setSerialNo(addOrderRequest.getSerialNo());
}
RelCodeDetailResponse codeRelEntity = null;
if (StrUtil.isEmpty(udiEntity.getBatchNo())) {
IoCodeLostEntity codeLostEntity = codeLostService.findByCode(code);
if (codeLostEntity != null) {
udiEntity.setBatchNo(codeLostEntity.getBatchNo());
udiEntity.setProduceDate(codeLostEntity.getProduceDate());
udiEntity.setExpireDate(codeLostEntity.getExpireDate());
} else {
codeRelEntity = relCodeDetailService.findByCode(code);
if (codeRelEntity != null) {
udiEntity.setBatchNo(codeRelEntity.getBatchNo());
udiEntity.setProduceDate(DateUtil.formatDate(codeRelEntity.getMadeDate(), "yyMMdd"));
udiEntity.setExpireDate(DateUtil.formatDate(codeRelEntity.getValidateDate(), "yyMMdd"));
}
}
}
//批次号校验
//判断此产品是否开启允许无批次号
UdiProductEntity udiInfoEntity = udiProductService.findByNameCode(udiEntity.getUdi());
if (udiInfoEntity == null) {
return ResultVOUtils.error(500, "耗材字典不存在此产品!");
}
String orderId = addOrderRequest.getBillNo();
//过期提醒:
if (IntUtil.value(bussinessTypeEntity.getCheckExpire()) == 1 && !addOrderRequest.isIgnoreExpire()) {
if (StrUtil.isNotEmpty(udiEntity.getExpireDate())) {
String expireDate = "20" + udiEntity.getExpireDate();
long expireTime = DateUtil.parseDateExpire(expireDate);
if (expireTime - System.currentTimeMillis() < 0) {
return ResultVOUtils.error(504, "当前产品已过期,是否确定继续添加?");
}
}
}
if (IntUtil.value(bussinessTypeEntity.getCheckExpire()) == 2) {
if (StrUtil.isNotEmpty(udiEntity.getExpireDate())) {
String expireDate = "20" + udiEntity.getExpireDate();
long expireTime = DateUtil.parseDateExpire(expireDate);
if (expireTime - System.currentTimeMillis() < 0) {
return ResultVOUtils.error(604, "当前产品已过期,无法添加?");
}
}
}
UdiRelevanceResponse udiRelevanceResponse = udiRelevanceService.selectByNameCode(udiEntity.getUdi());
long recent = 0;
if (udiRelevanceResponse.getRecentDateTime() != null)
recent = udiRelevanceResponse.getRecentDateTime().longValue();
if (IntUtil.value(bussinessTypeEntity.getCheckVailDate()) == 1 && recent > 0 && !addOrderRequest.isIgnoreRecentExpire()) {
if (StrUtil.isNotEmpty(udiEntity.getExpireDate())) {
String expireDate = "20" + udiEntity.getExpireDate();
long expireTime = DateUtil.parseDateExpire(expireDate);
long recentTieme = Math.abs(recent * 24 * 60 * 60 * 1000);
long resultTime = expireTime - System.currentTimeMillis();
if (resultTime > 0) {
long time = resultTime / (24 * 60 * 60 * 1000);
if (resultTime < recentTieme) {
return ResultVOUtils.error(505, "当前产品临近过期,距过期还剩" + time + "天,是否确定继续添加?");
}
}
}
}
if (IntUtil.value(bussinessTypeEntity.getCheckVailDate()) == 2 && recent > 0) {
if (StrUtil.isNotEmpty(udiEntity.getExpireDate())) {
String expireDate = "20" + udiEntity.getExpireDate();
long expireTime = DateUtil.parseDateExpire(expireDate);
long recentTieme = Math.abs(recent * 24 * 60 * 60 * 1000);
long resultTime = expireTime - System.currentTimeMillis();
if (resultTime > 0) {
long time = resultTime / (24 * 60 * 60 * 1000);
if (resultTime < recentTieme) {
return ResultVOUtils.error(605, "当前产品临近过期,距过期还剩" + time + "天,无法添加!");
}
}
}
}
//判断层级标识是否正确
if (bussinessTypeEntity.isUse()) {
if (udiRelevanceResponse.getUseMaxLevel() != null && IntUtil.value(udiRelevanceResponse.getUseMaxLevel()) < IntUtil.value(udiRelevanceResponse.getPackLevel())) {
return ResultVOUtils.error(500, "当前产品不支持采集该包装层级追溯码!");
}
if (udiRelevanceResponse.getUseMaxLevel() == null && IntUtil.value(udiRelevanceResponse.getPackLevel()) > 1) {
return ResultVOUtils.error(500, "当前产品不支持采集该包装层级追溯码!");
}
if (IntUtil.value(udiRelevanceResponse.getPackLevel()) < IntUtil.value(udiRelevanceResponse.getUseLevel())) {
return ResultVOUtils.error(500, "当前产品不支持采集该包装层级追溯码!");
}
} else {
if (udiRelevanceResponse.getDistributeMaxLevel() != null && IntUtil.value(udiRelevanceResponse.getDistributeMaxLevel()) < IntUtil.value(udiRelevanceResponse.getPackLevel())) {
return ResultVOUtils.error(500, "当前产品不支持采集该包装层级追溯码!");
}
if (IntUtil.value(udiRelevanceResponse.getPackLevel()) < IntUtil.value(udiRelevanceResponse.getDistributeLevel())) {
return ResultVOUtils.error(500, "当前产品不支持采集该包装层级追溯码!");
}
}
if (IntUtil.value(udiRelevanceResponse.getPackLevel()) == 0) {
RelCodeDetailResponse relCodeDetailResponse = relCodeDetailService.findByCode(code);
if (relCodeDetailResponse == null) {
return ResultVOUtils.error(500, "请先上传关联关系!");
}
}
//先生成扫码单据
IoOrderEntity orderEntity = orderService.findByBillNo(orderId);
String inBatch = "";
if (StringUtils.isBlank(orderId) || orderEntity == null) {
String orderNo = gennerOrderUtils.createScOrderNo(new OrderNoTypeBean(Constant.SCAN_ORDER + StrUtil.trimToEmpty(bussinessTypeEntity.getPrefix()), "yyyyMMdd"));
orderId = orderNo;
}
inBatch = orderId.substring((Constant.SCAN_ORDER + StrUtil.trimToEmpty(bussinessTypeEntity.getPrefix())).length());
List<IoCodeTempEntity> codeEnttitys = codeTempService.findByOrderId(orderId);
IoCodeTempEntity exitLocalEntity = null;
IoCodeTempEntity genDetaiEntity = new IoCodeTempEntity();
List<UdiRelevanceResponse> udiRelevanceResponses = null;
if (codeEnttitys.size() > 0) {
exitLocalEntity = isExitLocal(code, codeEnttitys);
if (exitLocalEntity != null) {
if (StrUtil.isEmpty(exitLocalEntity.getSupId()) || exitLocalEntity.getRelId() == null) {
return ResultVOUtils.error(500, "当前追溯码已存在,且存在异常未处理!");
}
if (StringUtils.isNotBlank(exitLocalEntity.getSerialNo())) {
return ResultVOUtils.error(500, "重复扫码!");
}
udiRelevanceResponses = udiRelevanceService.selectGroupByNameCode(exitLocalEntity.getNameCode(), null);
BeanUtils.copyProperties(exitLocalEntity, genDetaiEntity);
genDetaiEntity.setCount(1);
if (bussinessTypeEntity.isUse()) {
genDetaiEntity.setReCount(udiCalCountUtil.getUseActCount(udiRelevanceResponses.get(0)));
} else {
genDetaiEntity.setReCount(udiCalCountUtil.getCirActCount(udiRelevanceResponses.get(0)));
}
exitLocalEntity.setCount(exitLocalEntity.getMyCount() + 1);
if (bussinessTypeEntity.isUse()) {
exitLocalEntity.setReCount(exitLocalEntity.getMyReCount() * udiCalCountUtil.getUseActCount(udiRelevanceResponses.get(0)));
} else {
exitLocalEntity.setReCount(exitLocalEntity.getMyReCount() * udiCalCountUtil.getCirActCount(udiRelevanceResponses.get(0)));
}
BaseResponse invRes = checkInv(bussinessTypeEntity, exitLocalEntity);
if (invRes != null) {
return invRes;
}
if (addOrderRequest.getOrderType() == ConstantStatus.ORDER_TYPE_NORMAL && bussinessTypeEntity.isCheckEnable()) {
String errMsg = ioCheckInoutService.checkCode(genDetaiEntity);
if (errMsg != null) {
return ResultVOUtils.error(500, errMsg);
} else
codeTempService.updateById(exitLocalEntity);
} else if (addOrderRequest.getOrderType() == ConstantStatus.ORDER_TYPE_WAIT && bussinessTypeEntity.isCheckEnable()) {
String errMsg = ioCheckInoutService.checkNoPiCode(genDetaiEntity);
if (errMsg != null) {
return ResultVOUtils.error(500, errMsg);
} else
codeTempService.updateById(exitLocalEntity);
} else {
codeTempService.updateById(exitLocalEntity);
}
}
}
if (exitLocalEntity == null) {
if (codeTempService.ieExitRel(code, orderId)) {
return ResultVOUtils.error(500, "当前追溯码已上传关联关系,请勿重复扫码!");
}
IoCodeTempEntity codeEnttity = new IoCodeTempEntity();
codeEnttity.setCode(code);
codeEnttity.setOrderId(orderId);
codeEnttity.setCorpOrderId(addOrderRequest.getCorpOrderId());
codeEnttity.setCreateTime(new Date());
codeEnttity.setUpdateTime(new Date());
codeEnttity.setMainAction(bussinessTypeEntity.getMainAction());
codeEnttity.setAction(bussinessTypeEntity.getAction());
codeEnttity.setNameCode(udiEntity.getUdi());
codeEnttity.setBatchNo(udiEntity.getBatchNo());
codeEnttity.setProduceDate(udiEntity.getProduceDate());
codeEnttity.setExpireDate(udiEntity.getExpireDate());
codeEnttity.setSerialNo(udiEntity.getSerialNo());
codeEnttity.setDeptCode(invWarehouseEntity.getParentId());
codeEnttity.setInvCode(addOrderRequest.getInvCode());
if (codeRelEntity != null) {
codeEnttity.setParentCode(codeRelEntity.getParentCode());
RelCodeDetail relCodeDetail = relCodeDetailService.getOneByCode(codeRelEntity.getParentCode());
if (relCodeDetail != null) {
codeEnttity.setGrantPaCode(relCodeDetail.getParentCode());
}
}
codeEnttity.setCount(1);
codeEnttity.setProductType(2);
String unitFk = null;
if (bussinessTypeEntity.getCorpType() == ConstantStatus.CORP_TYPE_OUT) {
unitFk = addOrderRequest.getFromCorp();
}
//产品是否可以以使用单元入库
udiRelevanceResponses = udiRelevanceService.selectGroupByNameCode(codeEnttity.getNameCode(), false);
if (udiRelevanceResponses.size() >= 1) {
// UdiRelevanceResponse udiRelevanceResponse = udiRelevanceResponses.get(0);
if (udiRelevanceResponse == null) {
return ResultVOUtils.error(500, "该产品信息未维护!");
} else if (!udiRelevanceResponse.getUseDy() && udiRelevanceResponse.getDiType() == ConstantStatus.DITYPE_SYDY) {
return ResultVOUtils.error(500, "该产品不允许以使用单元入库!");
}
if (bussinessTypeEntity.isVailDispatch() && !udiRelevanceResponse.isDispatch()) {
return ResultVOUtils.error(500, "该产品不可配送,请联系院方!");
}
if (bussinessTypeEntity.getVailGroupBuy() == 1 && !udiRelevanceResponse.isGroupBuy()) { //只采集集采产品
return ResultVOUtils.error(500, bussinessTypeEntity.getName() + "单只允许录入集采产品!");
}
if (bussinessTypeEntity.getVailGroupBuy() == 2 && udiRelevanceResponse.isGroupBuy()) { //只采集非集采产品
return ResultVOUtils.error(500, bussinessTypeEntity.getName() + "单只允许录入非集采产品!");
}
//计算实际数量
if (bussinessTypeEntity.isUse()) {
codeEnttity.setReCount(IntUtil.value(codeEnttity.getMyReCount()) + udiCalCountUtil.getUseActCount(udiRelevanceResponse));
} else {
codeEnttity.setReCount(IntUtil.value(codeEnttity.getMyReCount()) + udiCalCountUtil.getCirActCount(udiRelevanceResponse));
}
} else if (udiRelevanceResponses.size() == 0) {
if (unitFk == null)
return ResultVOUtils.error(500, "药品字典不存在此产品!");
else
return ResultVOUtils.error(500, "当前供应商不存在此配送产品!");
}
//校验供应商是否配送此产品
BaseResponse corpResponse = checkCorp(codeEnttity, bussinessTypeEntity, unitFk);
if (corpResponse != null) {
return corpResponse;
}
IoOrderEntity isExit = orderService.findByBillNo(orderId);
if (isExit == null) {
orderEntity = new IoOrderEntity();
orderEntity.setBillNo(orderId);
orderEntity.setCorpOrderId(addOrderRequest.getCorpOrderId());
orderEntity.setMainAction(bussinessTypeEntity.getMainAction());
orderEntity.setAction(bussinessTypeEntity.getAction());
orderEntity.setFromCorp(addOrderRequest.getFromCorp());
if (StrUtil.isNotEmpty(addOrderRequest.getFromInvCode())) {
InvWarehouseEntity invWarehouseEntity1 = invWarehouseService.findByInvSubByCode(addOrderRequest.getFromInvCode());
orderEntity.setFromDeptCode(invWarehouseEntity1.getParentId());
}
orderEntity.setFromInvCode(addOrderRequest.getFromInvCode());
orderEntity.setFromType(ConstantStatus.FROM_WEBNEW);
orderEntity.setStatus(ConstantStatus.ORDER_STATUS_TEMP_SAVE);
orderEntity.setDealStatus(ConstantStatus.ORDER_DEAL_DRAFT);
AuthAdmin authAdmin = customerService.getUserBean();;
orderEntity.setCreateUser(authAdmin.getId() + "");
orderEntity.setCreateTime(new Date());
orderEntity.setUpdateUser(authAdmin.getId() + "");
orderEntity.setUpdateTime(new Date());
orderEntity.setCustomerId(authAdmin.getCustomerId() + "");
orderEntity.setDeptCode(invWarehouseEntity.getParentId());
orderEntity.setCheckPreInOrders(addOrderRequest.getCheckPreInOrders());
orderEntity.setInvCode(addOrderRequest.getInvCode());
orderEntity.setOrderType(addOrderRequest.getOrderType());
orderEntity.setBusType(bussinessTypeEntity.getBusType());
orderEntity.setProductType(2);
orderService.insertOrder(orderEntity);
}
if (addOrderRequest.getOrderType() == ConstantStatus.ORDER_TYPE_NORMAL && bussinessTypeEntity.isCheckEnable() && bussinessTypeEntity.getCheckWebNew() != 0) {
boolean isBillExit = orderDetailBizService.isExit(orderEntity.getBillNo());
if (!isBillExit) {
orderService.deleteByBillNo(orderEntity.getBillNo());
return ResultVOUtils.error(500, "请先录入业务详情");
}
}
BaseResponse baseResponse = checkRelId(codeEnttity, unitFk);
BaseResponse invRes = checkInv(bussinessTypeEntity, codeEnttity);
if (invRes != null) {
return invRes;
}
genDetaiEntity = codeEnttity;
if (baseResponse == null) {
baseResponse = checkSupId(bussinessTypeEntity, codeEnttity, unitFk);
if (baseResponse != null)
return baseResponse;
} else {
if (baseResponse.getCode() == 501) {
return baseResponse;
} else if (baseResponse.getCode() == 502) {
return baseResponse;
}
checkSupId(bussinessTypeEntity, codeEnttity, unitFk);
return baseResponse;
}
if (IntUtil.value(bussinessTypeEntity.getCheckCertExpire()) == 2 && udiRelevanceResponse.isNeedCert()) {
SupProductEntity supProductEntity = supProductService.findExitByManufactury(udiRelevanceResponse.getCpmctymc(), udiRelevanceResponse.getManufactory(), unitFk);
if (supProductEntity != null && (supProductEntity.getAuditStatus() == ConstantStatus.AUDIT_PASS || supProductEntity.getAuditStatus() == ConstantStatus.AUDIT_CHANGE_PASS)) {
List<SupCertEntity> supCertEntities = supCertService.findByProductId(supProductEntity.getProductId());
if (CollUtil.isNotEmpty(supCertEntities)) {
Date curDate = new Date();
for (SupCertEntity supCertEntity : supCertEntities) {
if (supCertEntity.getExpireDate() != null && supCertEntity.getExpireDate().compareTo(curDate) < 0) {
return ResultVOUtils.error(500, "产品资质证书已过期!");
}
}
}
} else {
if (supProductEntity == null) {
return ResultVOUtils.error(500, "产品资质证书未维护!");
} else {
return ResultVOUtils.error(500, "产品资质证书未通过审核!");
}
}
}
codeEnttity.setPrice(udiRelevanceResponse.getPrice());
codeEnttity.setInBatchNo(inBatch);
//是否边扫边校验
if (addOrderRequest.getOrderType() == ConstantStatus.ORDER_TYPE_NORMAL && bussinessTypeEntity.isCheckEnable()) {
String errMsg = ioCheckInoutService.checkCode(codeEnttity);
if (errMsg != null) {
return ResultVOUtils.error(500, errMsg);
} else
codeTempService.insert(codeEnttity);
// 异步调用 查询是否存在药品关联信息 后将结果更新至 temp表
relCodeBatchService.threadUpdateIoCodeTempEntity(code);
} else if (addOrderRequest.getOrderType() == ConstantStatus.ORDER_TYPE_WAIT && bussinessTypeEntity.isCheckEnable()) {
String errMsg = ioCheckInoutService.checkDrugNoPiCode(codeEnttity);
if (errMsg != null) {
return ResultVOUtils.error(500, errMsg);
} else
codeTempService.insert(codeEnttity);
// 异步调用 查询是否存在药品关联信息 后将结果更新至 temp表
relCodeBatchService.threadUpdateIoCodeTempEntity(code);
} else {
codeTempService.insert(codeEnttity);
// 异步调用 查询是否存在药品关联信息 后将结果更新至 temp表
relCodeBatchService.threadUpdateIoCodeTempEntity(code);
}
}
addCodeResult.setOrderId(orderId);
transInoutService.genOrderDetailCode(orderEntity, genDetaiEntity);
return ResultVOUtils.success(addCodeResult);
}
//校验供应商是否配送此产品
public BaseResponse checkCorp(IoCodeTempEntity codeEnttity, BasicBussinessTypeEntity bussinessTypeEntity, String unitFk) {
CompanyProductRelevanceRequest companyProductRelevanceRequest = new CompanyProductRelevanceRequest();
UdiEntity udiEntity = FilterUdiUtils.getUdi(codeEnttity.getCode());
companyProductRelevanceRequest.setNameCode(udiEntity.getUdi());
if (bussinessTypeEntity.getCorpType() == ConstantStatus.CORP_TYPE_OUT) {
companyProductRelevanceRequest.setUnitFk(unitFk);
boolean exist = udiRlSupService.findExist(companyProductRelevanceRequest);
if (!exist) {
return ResultVOUtils.error(500, "当前供应商不存在此配送产品!");
}
} else {
boolean exist = udiRlSupService.findExist(companyProductRelevanceRequest);
if (!exist) {
return ResultVOUtils.error(500, "此产品无指定供应商,请检查后添加!");
}
}
return null;
}
//校验产品ID唯一性
public BaseResponse checkRelId(IoCodeTempEntity codeEnttity, String unitFk) {
List<UdiRelevanceResponse> udiRelevanceEntities = udiRelevanceService.selectAllByNameCode(codeEnttity.getNameCode(), unitFk);
if (udiRelevanceEntities != null && udiRelevanceEntities.size() > 1 && codeEnttity.getRelId() == null) {//同一个DI绑定多个产品西信息
codeEnttity.setRelId(null);
codeEnttity.setStatus(ConstantStatus.ORDER_DETAIL_DI_MUTI);
codeTempService.insert(codeEnttity);
codeEnttity = codeTempService.findByUnique(codeEnttity.getOrderId(), codeEnttity.getCode());
BaseResponse baseResponse = ResultVOUtils.error(502, "DI绑定多个产品ID,请指定对应产品");
baseResponse.setData(codeEnttity);
return baseResponse;
} else if (udiRelevanceEntities == null || udiRelevanceEntities.size() == 0) {//未找到产品信息,一般不会出现
codeEnttity.setRelId(null);
codeEnttity.setStatus(2);
return ResultVOUtils.error(501, "耗材字典不存在此产品!");
} else {
codeEnttity.setStatus(0);
if (codeEnttity.getRelId() == null)
codeEnttity.setRelId(udiRelevanceEntities.get(0).getId());
}
return null;
}
//校验供应商唯一性
public BaseResponse checkSupId(BasicBussinessTypeEntity bussinessTypeEntity, IoCodeTempEntity codeEnttity, String unitFk) {
String originSupId = unitFk;
if (originSupId != null) {
codeEnttity.setSupId(originSupId);
} else {
IoCodeEntity ioCodeEntity = new IoCodeEntity();
BeanUtils.copyProperties(codeEnttity, ioCodeEntity);
String supId = transInoutService.checkInvExitSup(ioCodeEntity);
if (supId == null) {
supId = transInoutService.checkExitSup(codeEnttity.getRelId());
}
if (supId == null) {
codeEnttity.setSupId(null);
BaseResponse baseResponse = ResultVOUtils.error(503, "该产品未绑定供应商,请指定对应的供应商");
baseResponse.setData(codeEnttity);
return baseResponse;
} else if ("MUTI".equals(supId)) {
codeEnttity.setSupId(null);
BaseResponse baseResponse = ResultVOUtils.error(503, "该产品绑定多个供应商,请指定对应的供应商");
baseResponse.setData(codeEnttity);
return baseResponse;
} else {
codeEnttity.setSupId(supId);
}
}
codeTempService.updateById(codeEnttity);
return null;
}
//判断本单是否存在
public IoCodeTempEntity isExitLocal(String code, List<IoCodeTempEntity> codeEnttityList) {
UdiEntity udiEntity = FilterUdiUtils.getUdi(code);
for (int i = 0; i < codeEnttityList.size(); i++) {
IoCodeTempEntity drugCodeSelectEntity = codeEnttityList.get(i);
if (codeEnttityList.get(i).getCode().equals(code)) {
if (StrUtil.emptyIfNull(drugCodeSelectEntity.getSerialNo()).equals(StrUtil.emptyIfNull(udiEntity.getSerialNo()))) {
return drugCodeSelectEntity;
}
}
// UdiEntity originUdiEntity = FilterUdiUtils.getUdi(drugCodeSelectEntity.getCode());
if (!StrUtil.emptyIfNull(drugCodeSelectEntity.getNameCode()).equals(StrUtil.emptyIfNull(udiEntity.getUdi()))) {
continue;
}
if (!StrUtil.emptyIfNull(drugCodeSelectEntity.getBatchNo()).toUpperCase(Locale.ROOT).equals(StrUtil.emptyIfNull(udiEntity.getBatchNo()).toUpperCase(Locale.ROOT))) {
continue;
}
if (!StrUtil.emptyIfNull(drugCodeSelectEntity.getProduceDate()).equals(StrUtil.emptyIfNull(udiEntity.getProduceDate()))) {
continue;
}
if (!StrUtil.emptyIfNull(drugCodeSelectEntity.getExpireDate()).equals(StrUtil.emptyIfNull(udiEntity.getExpireDate()))) {
continue;
}
if (!StrUtil.emptyIfNull(drugCodeSelectEntity.getSerialNo()).equals(StrUtil.emptyIfNull(udiEntity.getSerialNo()))) {
continue;
}
return drugCodeSelectEntity;
}
return null;
}
public BaseResponse checkInv(BasicBussinessTypeEntity bussinessTypeEntity, IoCodeTempEntity codeTempEntity) {
if (bussinessTypeEntity.isVailInv() && bussinessTypeEntity.getMainAction().equals(ConstantType.TYPE_OUT)) {
if (bussinessTypeEntity.getActionType() == ConstantStatus.ACTION_TYPE_ADVANCE) {
// int count = invPreProductDetailService.vailStockCount(code); //todo 寄售
// if (count < 0) {
// return ResultVOUtils.error(500, "当前库存不足不允许0库存出库");
// }
} else {
int count = invProductDetailService.vailStockCount(codeTempEntity.getRelId(), codeTempEntity.getBatchNo(), codeTempEntity.getSupId(), codeTempEntity.getDeptCode(), codeTempEntity.getInvCode(), null, false);
if (count <= 0) {
if (count == -1) {
return ResultVOUtils.error(500, "该产品未入库");
} else
return ResultVOUtils.error(500, "当前库存不足");
} else {
//查询此单据已扫描的条码数量
if (codeTempEntity.getMyReCount() > count) {
return ResultVOUtils.error(500, "当前库存不足不允许0库存出库");
}
}
}
}
return null;
}
}

@ -5,24 +5,45 @@ import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.glxp.api.common.res.BaseResponse;
import com.glxp.api.common.util.ResultVOUtils;
import com.glxp.api.constant.Constant;
import com.glxp.api.constant.ConstantStatus;
import com.glxp.api.dao.inout.IoOrderDetailBizDao;
import com.glxp.api.entity.auth.AuthAdmin;
import com.glxp.api.entity.auth.InvWarehouseEntity;
import com.glxp.api.entity.basic.BasicBussinessTypeEntity;
import com.glxp.api.entity.basic.UdiProductEntity;
import com.glxp.api.entity.inout.IoOrderDetailBizEntity;
import com.glxp.api.entity.inout.IoOrderDetailCodeEntity;
import com.glxp.api.entity.inout.IoOrderEntity;
import com.glxp.api.entity.purchase.SupCertEntity;
import com.glxp.api.entity.purchase.SupProductEntity;
import com.glxp.api.entity.system.SystemParamConfigEntity;
import com.glxp.api.req.inout.AddBizProductReqeust;
import com.glxp.api.req.inout.FilterOrderDetailBizRequest;
import com.glxp.api.req.inout.FilterOrderDetailCodeRequest;
import com.glxp.api.res.basic.UdiRelevanceResponse;
import com.glxp.api.res.inout.IoOrderDetailBizResponse;
import com.glxp.api.res.inout.IoOrderDetailCodeResponse;
import com.glxp.api.res.inout.IoOrderDetailResultResponse;
import com.glxp.api.res.inout.IoOrderInvoiceResponse;
import com.glxp.api.service.auth.CustomerService;
import com.glxp.api.service.auth.InvWarehouseService;
import com.glxp.api.service.basic.IBasicBussinessTypeService;
import com.glxp.api.service.basic.UdiContrastService;
import com.glxp.api.service.basic.UdiProductService;
import com.glxp.api.service.basic.UdiRelevanceService;
import com.glxp.api.service.inout.IoCheckInoutService;
import com.glxp.api.service.inout.IoOrderDetailBizService;
import com.glxp.api.service.inout.IoOrderDetailCodeService;
import com.glxp.api.service.inout.IoOrderService;
import com.glxp.api.service.purchase.SupCertService;
import com.glxp.api.service.purchase.SupProductService;
import com.glxp.api.service.system.SystemParamConfigService;
import com.glxp.api.util.GennerOrderUtils;
import com.glxp.api.util.IntUtil;
import com.glxp.api.util.OrderNoTypeBean;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -257,4 +278,177 @@ public class IoOrderDetailBizServiceImpl implements IoOrderDetailBizService {
return true;
}
@Resource
CustomerService customerService;
@Resource
private IBasicBussinessTypeService basicBussinessTypeService;
@Resource
InvWarehouseService invWarehouseService;
@Resource
GennerOrderUtils gennerOrderUtils;
@Resource
UdiRelevanceService udiRelevanceService;
@Resource
SupProductService supProductService;
@Resource
SystemParamConfigService systemParamConfigService;
@Resource
SupCertService supCertService;
@Override
public BaseResponse addBizProduct(AddBizProductReqeust addBizProductReqeust) {
// SystemParamConfigEntity systemParamConfigEntity = systemParamConfigService.selectByParamKey("vail_product_cert");
// boolean isVailCert = systemParamConfigEntity.getParamValue().equals("1") ? true : false;
AuthAdmin authAdmin = customerService.getUserBean();
if (addBizProductReqeust.getRelId() == null && CollUtil.isEmpty(addBizProductReqeust.getDatas()))
return ResultVOUtils.error(500, "未选择产品信息");
if (addBizProductReqeust.getOrderEntity() == null)
return ResultVOUtils.error(500, "未指定订单");
IoOrderEntity orderEntity = addBizProductReqeust.getOrderEntity();
IoOrderEntity isExit = orderService.findByBillNo(orderEntity.getBillNo());
if (StrUtil.isEmpty(orderEntity.getBillNo()) || isExit == null) {
BasicBussinessTypeEntity bussinessTypeEntity = basicBussinessTypeService.findByAction(orderEntity.getAction());
InvWarehouseEntity invWarehouseEntity = invWarehouseService.findByInvSubByCode(orderEntity.getInvCode());
String orderNo = gennerOrderUtils.createScOrderNo(new OrderNoTypeBean(Constant.SCAN_ORDER + StrUtil.trimToEmpty(bussinessTypeEntity.getPrefix()), "yyyyMMdd"));
orderEntity.setBillNo(orderNo);
orderEntity.setCreateUser(authAdmin.getId() + "");
orderEntity.setCreateTime(new Date());
orderEntity.setMainAction(bussinessTypeEntity.getMainAction());
if (StrUtil.isNotEmpty(orderEntity.getFromInvCode())) {
InvWarehouseEntity fromEntity = invWarehouseService.findByInvSubByCode(orderEntity.getInvCode());
orderEntity.setFromDeptCode(fromEntity.getParentId());
}
orderEntity.setFromType(ConstantStatus.FROM_WEBNEW);
orderEntity.setStatus(ConstantStatus.ORDER_STATUS_TEMP_SAVE);
orderEntity.setDealStatus(ConstantStatus.ORDER_DEAL_DRAFT);
orderEntity.setCreateUser(authAdmin.getId() + "");
orderEntity.setCreateTime(new Date());
orderEntity.setUpdateUser(authAdmin.getId() + "");
orderEntity.setUpdateTime(new Date());
orderEntity.setCustomerId(authAdmin.getCustomerId() + "");
orderEntity.setDeptCode(invWarehouseEntity.getParentId());
orderEntity.setInvCode(orderEntity.getInvCode());
orderEntity.setBusType(bussinessTypeEntity.getBusType());
orderService.insertOrder(orderEntity);
}
List<AddBizProductReqeust> datas = new ArrayList<>();
if (CollUtil.isNotEmpty(addBizProductReqeust.getDatas())) {
datas.addAll(addBizProductReqeust.getDatas());
} else {
datas.add(addBizProductReqeust);
}
for (AddBizProductReqeust item : datas) {
UdiRelevanceResponse udiRelevanceResponse = udiRelevanceService.selectSupGroupById(item.getRelId(), addBizProductReqeust.getSupId());
BasicBussinessTypeEntity bussinessTypeEntity = basicBussinessTypeService.findByAction(orderEntity.getAction());
//是否校验产品采购类型 1校验2.无需校验
if (IntUtil.value(bussinessTypeEntity.getVailProductAttributes()) == 1) {
Integer purType = IntUtil.value(udiRelevanceResponse.getPurType()); //1普通入账产品2.预验收产品。3寄售产品
int actionType = IntUtil.value(bussinessTypeEntity.getActionType()); //1带票正常2.预验收。3寄售
if (purType != actionType) {
//包装友好提示
String msg = "";
switch (actionType) {
case 1:
msg = "普通入账产品";
break;
case 2:
msg = "预验收产品";
break;
case 3:
msg = "寄售产品";
break;
}
String msg2 = "";
switch (purType) {
case 1:
msg2 = "普通入账产品";
break;
case 2:
msg2 = "预验收产品";
break;
case 3:
msg2 = "寄售产品";
break;
}
return ResultVOUtils.error(500, "单据只允许录入" + msg + ",当前录入产品为" + msg2 + ",请检查后重试!");
}
}
if (bussinessTypeEntity != null && udiRelevanceResponse != null) {
//是否校验耗材材质 1高值耗材2.普通耗材
if (IntUtil.value(bussinessTypeEntity.getVailHcType()) == 1) {
if (IntUtil.value(udiRelevanceResponse.getHcType()) != 1) {
return ResultVOUtils.error(500, "单据只允许录入高值耗材" + ",请检查后重试!");
}
} else if (IntUtil.value(bussinessTypeEntity.getVailHcType()) == 2) {
if (IntUtil.value(udiRelevanceResponse.getHcType()) != 2) {
return ResultVOUtils.error(500, "单据只允许录入普通耗材" + ",请检查后重试!");
}
}
//是否开启校验扫码 0:不校验1:只允许录入扫码产品2:只允许录入不扫码产品
if (IntUtil.value(bussinessTypeEntity.getCodeCheck()) == 1) {
if (IntUtil.value(udiRelevanceResponse.getRequireScanCode()) != 1) {
return ResultVOUtils.error(500, "单据只允许录入需要扫码产品" + ",请检查后重试!");
}
} else if (IntUtil.value(bussinessTypeEntity.getCodeCheck()) == 2) {
if (IntUtil.value(udiRelevanceResponse.getRequireScanCode()) != 0) {
return ResultVOUtils.error(500, "单据只允许录入不需要扫码产品" + ",请检查后重试!");
}
}
}
if (IntUtil.value(bussinessTypeEntity.getCheckCertExpire()) == 2 && udiRelevanceResponse.isNeedCert()) {
SupProductEntity supProductEntity = supProductService.findExitByManufactury(udiRelevanceResponse.getCpmctymc(), udiRelevanceResponse.getManufactory(), authAdmin.getCustomerId());
if (supProductEntity != null && (supProductEntity.getAuditStatus() == ConstantStatus.AUDIT_PASS || supProductEntity.getAuditStatus() == ConstantStatus.AUDIT_CHANGE_PASS)) {
// List<SupCertEntity> supCertEntities = supCertService.findByProductId(supProductEntity.getProductId());
addBizProductReqeust.setProductId(supProductEntity.getProductId());
List<SupCertEntity> supCertEntities = supCertService.findByzczbhhzbapzbh(addBizProductReqeust);
if (CollUtil.isNotEmpty(supCertEntities)) {
Date curDate = new Date();
for (SupCertEntity supCertEntity : supCertEntities) {
if (supCertEntity.getExpireDate() != null && supCertEntity.getExpireDate().compareTo(curDate) < 0) {
return ResultVOUtils.error(500, "该注册备案号所属产品资质证书已过期!");
}
}
}
} else {
return ResultVOUtils.error(500, "产品资质证书未通过审核!");
}
}
if (bussinessTypeEntity.isVailDispatch()) {
if (!udiRelevanceResponse.isDispatch()) {
return ResultVOUtils.error(500, "该产品不可配送,请联系院方!");
}
}
IoOrderDetailBizEntity ioOrderDetailBizEntity = new IoOrderDetailBizEntity();
ioOrderDetailBizEntity.setOrderIdFk(orderEntity.getBillNo());
ioOrderDetailBizEntity.setBindRlFk(udiRelevanceResponse.getId());
ioOrderDetailBizEntity.setUuidFk(udiRelevanceResponse.getUuid());
ioOrderDetailBizEntity.setNameCode(udiRelevanceResponse.getNameCode());
ioOrderDetailBizEntity.setCoName(udiRelevanceResponse.getCpmctymc());
ioOrderDetailBizEntity.setCertCode(addBizProductReqeust.getZczbhhzbapzbh());
ioOrderDetailBizEntity.setYlqxzcrbarmc(udiRelevanceResponse.getYlqxzcrbarmc());
ioOrderDetailBizEntity.setManufacturer(udiRelevanceResponse.getManufactory());
ioOrderDetailBizEntity.setMeasname(udiRelevanceResponse.getMeasname());
ioOrderDetailBizEntity.setSpec(udiRelevanceResponse.getGgxh());
ioOrderDetailBizEntity.setPrice(udiRelevanceResponse.getPrice());
ioOrderDetailBizEntity.setProductDate(item.getProductDate());
ioOrderDetailBizEntity.setExpireDate(item.getExpireDate());
ioOrderDetailBizEntity.setBatchNo(item.getBatchNo());
ioOrderDetailBizEntity.setSupId(item.getSupId());
this.insert(ioOrderDetailBizEntity);
}
orderEntity.setUpdateTime(new Date());
orderEntity.setUpdateUser(authAdmin.getId() + "");
orderService.update(orderEntity);
return ResultVOUtils.success(orderEntity);
}
}

Loading…
Cancel
Save