|
|
package com.glxp.api.service.inout;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.glxp.api.common.res.BaseResponse;
|
|
|
import com.glxp.api.common.util.ResultVOUtils;
|
|
|
import com.glxp.api.constant.ConstantStatus;
|
|
|
import com.glxp.api.constant.ConstantType;
|
|
|
import com.glxp.api.entity.auth.InvWarehouseEntity;
|
|
|
import com.glxp.api.entity.basic.BasicBussinessTypeEntity;
|
|
|
import com.glxp.api.entity.inout.IoCodeTempEntity;
|
|
|
import com.glxp.api.res.basic.UdiRelevanceResponse;
|
|
|
import com.glxp.api.res.inv.InvPlaceDetailResponse;
|
|
|
import com.glxp.api.service.auth.InvWarehouseService;
|
|
|
import com.glxp.api.service.inv.InvPreProductDetailService;
|
|
|
import com.glxp.api.service.inv.InvPreinProductDetailService;
|
|
|
import com.glxp.api.service.inv.impl.InvProductDetailService;
|
|
|
import com.glxp.api.util.IntUtil;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.util.List;
|
|
|
|
|
|
@Service
|
|
|
public class IoCheckInvService {
|
|
|
|
|
|
@Resource
|
|
|
private IoCodeTempService codeTempService;
|
|
|
@Resource
|
|
|
InvWarehouseService invWarehouseService;
|
|
|
@Resource
|
|
|
InvProductDetailService invProductDetailService;
|
|
|
@Resource
|
|
|
InvPreinProductDetailService invPreinProductDetailService;
|
|
|
@Resource
|
|
|
InvPreProductDetailService invPreProductDetailService;
|
|
|
|
|
|
|
|
|
public BaseResponse check(BasicBussinessTypeEntity bussinessTypeEntity, IoCodeTempEntity genDetaiEntity, UdiRelevanceResponse udiRelevanceResponse) {
|
|
|
BaseResponse invRes = null;
|
|
|
if (IntUtil.value(bussinessTypeEntity.getUseDyCount()) == 2) {
|
|
|
if (bussinessTypeEntity.isScanPreIn() && checkDiAttribute(bussinessTypeEntity, udiRelevanceResponse, 2)) { //校验预验收库存
|
|
|
invRes = checkPreInInv(bussinessTypeEntity, genDetaiEntity, false);
|
|
|
}
|
|
|
if (bussinessTypeEntity.isAdvancePreIn() && checkDiAttribute(bussinessTypeEntity, udiRelevanceResponse, 3)) { //校验寄售库存
|
|
|
invRes = checkPreInv(bussinessTypeEntity, genDetaiEntity, false);
|
|
|
}
|
|
|
if (bussinessTypeEntity.isVailInv() && checkDiAttribute(bussinessTypeEntity, udiRelevanceResponse, 1)) {
|
|
|
invRes = checkInv(bussinessTypeEntity, genDetaiEntity, false);
|
|
|
}
|
|
|
} else {
|
|
|
if (bussinessTypeEntity.isScanPreIn()) { //校验预验收库存
|
|
|
invRes = checkPreInInv(bussinessTypeEntity, genDetaiEntity, false);
|
|
|
} else if (bussinessTypeEntity.isAdvancePreIn()) { //校验寄售库存
|
|
|
invRes = checkPreInv(bussinessTypeEntity, genDetaiEntity, false);
|
|
|
} else {
|
|
|
invRes = checkInv(bussinessTypeEntity, genDetaiEntity, false);
|
|
|
}
|
|
|
}
|
|
|
return invRes;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 校验入账库库存
|
|
|
*
|
|
|
* @param bussinessTypeEntity
|
|
|
* @param codeTempEntity
|
|
|
* @param isEdit
|
|
|
* @return
|
|
|
*/
|
|
|
public BaseResponse checkInv(BasicBussinessTypeEntity bussinessTypeEntity, IoCodeTempEntity codeTempEntity, boolean isEdit) {
|
|
|
if (bussinessTypeEntity.isVailInv() && bussinessTypeEntity.getMainAction().equals(ConstantType.TYPE_OUT)) {
|
|
|
String outInvCode = codeTempEntity.getInvCode();
|
|
|
InvWarehouseEntity invWarehouseEntity = invWarehouseService.findNoInvTypeInv(bussinessTypeEntity.getDeptNoInvType(), outInvCode);
|
|
|
if (invWarehouseEntity != null) {
|
|
|
outInvCode = invWarehouseEntity.getCode();
|
|
|
}
|
|
|
int count = 0;
|
|
|
if (bussinessTypeEntity.getSpaceOut() == ConstantStatus.SPACE_OUT_NULL) {
|
|
|
count = invProductDetailService.vailStockCount(codeTempEntity.getRelId(), codeTempEntity.getBatchNo(), codeTempEntity.getSupId(), null, outInvCode, null);
|
|
|
} else if (bussinessTypeEntity.getSpaceOut() == ConstantStatus.SPACE_OUT_SET) {
|
|
|
count = invProductDetailService.vailStockCount(codeTempEntity.getRelId(), codeTempEntity.getBatchNo(), codeTempEntity.getSupId(), codeTempEntity.getDeptCode(), codeTempEntity.getInvCode(), codeTempEntity.getWarehouseCode());
|
|
|
} else if (bussinessTypeEntity.getSpaceOut() == ConstantStatus.SPACE_OUT_CODE) {
|
|
|
//按指定货位出库
|
|
|
if (StrUtil.isEmpty(codeTempEntity.getWarehouseCode())) {
|
|
|
List<InvPlaceDetailResponse> invProductDetailEntities = invProductDetailService.findByGroupCode(codeTempEntity.getInvCode(), codeTempEntity.getCode(), true);
|
|
|
if (CollUtil.isNotEmpty(invProductDetailEntities) && invProductDetailEntities.size() > 1) {
|
|
|
BaseResponse baseResponse = ResultVOUtils.error(511, "存在多个货位,请指定当前货位!");
|
|
|
baseResponse.setData(invProductDetailEntities);
|
|
|
return baseResponse;
|
|
|
} else if (invProductDetailEntities.size() == 1) {
|
|
|
InvPlaceDetailResponse invPlaceDetailResponse = invProductDetailEntities.get(0);
|
|
|
count = invPlaceDetailResponse.getReCount();
|
|
|
} else {
|
|
|
return ResultVOUtils.error(500, "添加失败,该产品未上架货位!");
|
|
|
}
|
|
|
} else {
|
|
|
count = invProductDetailService.vailStockCount(codeTempEntity.getRelId(), codeTempEntity.getBatchNo(), codeTempEntity.getSupId(), codeTempEntity.getDeptCode(), codeTempEntity.getInvCode(), codeTempEntity.getWarehouseCode());
|
|
|
}
|
|
|
}
|
|
|
if (count <= 0) {
|
|
|
if (count == -1) {
|
|
|
return ResultVOUtils.error(500, "该产品未入库");
|
|
|
} else
|
|
|
return ResultVOUtils.error(500, "当前库存不足");
|
|
|
} else {
|
|
|
//查询此单据已扫描的条码数量
|
|
|
if (bussinessTypeEntity.getSpaceOut() == ConstantStatus.SPACE_OUT_CODE) {
|
|
|
int exitCount = IntUtil.value(codeTempService.selectExitCount(codeTempEntity.getOrderId(), codeTempEntity.getCode()));
|
|
|
if (isEdit) {
|
|
|
if (exitCount > count) {
|
|
|
return ResultVOUtils.error(500, "当前库存不足");
|
|
|
}
|
|
|
} else {
|
|
|
if ((codeTempEntity.getMyReCount() + exitCount) > count) {
|
|
|
return ResultVOUtils.error(500, "当前库存不足");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
int exitCount = IntUtil.value(codeTempService.selectExitCount(codeTempEntity.getOrderId(), codeTempEntity.getBatchNo(), codeTempEntity.getRelId(), codeTempEntity.getSupId()));
|
|
|
if (isEdit) {
|
|
|
if (exitCount > count) {
|
|
|
return ResultVOUtils.error(500, "当前库存不足");
|
|
|
}
|
|
|
} else {
|
|
|
if ((codeTempEntity.getMyReCount() + exitCount) > count) {
|
|
|
return ResultVOUtils.error(500, "当前库存不足");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 校验预验收库存
|
|
|
*
|
|
|
* @param bussinessTypeEntity
|
|
|
* @param codeTempEntity
|
|
|
* @param isEdit
|
|
|
* @return
|
|
|
*/
|
|
|
public BaseResponse checkPreInInv(BasicBussinessTypeEntity bussinessTypeEntity, IoCodeTempEntity codeTempEntity, boolean isEdit) {
|
|
|
|
|
|
InvWarehouseEntity invWarehouseEntity = invWarehouseService.findByOne(ConstantStatus.ACTION_TYPE_PREIN);
|
|
|
|
|
|
int count = 0;
|
|
|
if (bussinessTypeEntity.getSpaceOut() == ConstantStatus.SPACE_OUT_NULL) {
|
|
|
if (StrUtil.isNotEmpty(codeTempEntity.getSerialNo())) {
|
|
|
count = invPreinProductDetailService.vailStockCountByCode(null, invWarehouseEntity.getCode(), null, codeTempEntity.getCode());
|
|
|
} else
|
|
|
count = invPreinProductDetailService.vailStockCount(codeTempEntity.getRelId(), codeTempEntity.getBatchNo(), codeTempEntity.getSupId(), null, invWarehouseEntity.getCode(), null);
|
|
|
} else if (bussinessTypeEntity.getSpaceOut() == ConstantStatus.SPACE_OUT_SET) {
|
|
|
if (StrUtil.isNotEmpty(codeTempEntity.getSerialNo())) {
|
|
|
count = invPreinProductDetailService.vailStockCountByCode(null, invWarehouseEntity.getCode(), codeTempEntity.getPreInSpaceCode(), codeTempEntity.getCode());
|
|
|
} else
|
|
|
count = invPreinProductDetailService.vailStockCount(codeTempEntity.getRelId(), codeTempEntity.getBatchNo(), codeTempEntity.getSupId(), null, invWarehouseEntity.getCode(), codeTempEntity.getPreInSpaceCode());
|
|
|
} else if (bussinessTypeEntity.getSpaceOut() == ConstantStatus.SPACE_OUT_CODE) {
|
|
|
//按指定货位出库
|
|
|
if (StrUtil.isEmpty(codeTempEntity.getPreSpaceCode())) {
|
|
|
List<InvPlaceDetailResponse> invProductDetailEntities = invPreinProductDetailService.findByGroupCode(invWarehouseEntity.getCode(), codeTempEntity.getCode());
|
|
|
if (CollUtil.isNotEmpty(invProductDetailEntities) && invProductDetailEntities.size() > 1) {
|
|
|
BaseResponse baseResponse = ResultVOUtils.error(511, "存在多个货位,请指定当前货位!");
|
|
|
baseResponse.setData(invProductDetailEntities);
|
|
|
return baseResponse;
|
|
|
} else if (invProductDetailEntities.size() == 1) {
|
|
|
InvPlaceDetailResponse invPlaceDetailResponse = invProductDetailEntities.get(0);
|
|
|
count = invPlaceDetailResponse.getReCount();
|
|
|
codeTempEntity.setPreSpaceCode(invPlaceDetailResponse.getInvSpaceCode());
|
|
|
} else {
|
|
|
return ResultVOUtils.error(500, "添加失败,该产品未上架货位!");
|
|
|
}
|
|
|
} else {
|
|
|
if (StrUtil.isNotEmpty(codeTempEntity.getSerialNo())) {
|
|
|
count = invPreinProductDetailService.vailStockCountByCode(null, codeTempEntity.getInvCode(), codeTempEntity.getPreInSpaceCode(), codeTempEntity.getCode());
|
|
|
} else
|
|
|
count = invPreinProductDetailService.vailStockCount(codeTempEntity.getRelId(), codeTempEntity.getBatchNo(), codeTempEntity.getSupId(), null, codeTempEntity.getInvCode(), codeTempEntity.getPreInSpaceCode());
|
|
|
}
|
|
|
}
|
|
|
// InvPreInProductDetailEntity invPreinDetailEntity = invPreinProductDetailService.findUseOneByCode(codeTempEntity.getCode());
|
|
|
if (count <= 0) {
|
|
|
if (count == -1) {
|
|
|
return ResultVOUtils.error(500, "该产品未入库");
|
|
|
} else
|
|
|
return ResultVOUtils.error(500, "预验收库存数量不足!");
|
|
|
} else {
|
|
|
// if (StrUtil.isNotEmpty(invPreinDetailEntity.getBatchNo()) && StrUtil.isNotEmpty(codeTempEntity.getBatchNo())
|
|
|
// && !invPreinDetailEntity.getBatchNo().equals(codeTempEntity.getBatchNo())) {
|
|
|
// return ResultVOUtils.error(500, "当前批次号与预验收录入批次号不匹配!");
|
|
|
// }
|
|
|
if (StrUtil.isNotEmpty(codeTempEntity.getOrderId())) {//非首次添加
|
|
|
if (StrUtil.isEmpty(codeTempEntity.getSerialNo())) {//该单据已有该产品
|
|
|
//无序列号,则可能存在多个预验收入库单
|
|
|
IoCodeTempEntity tempEntity = codeTempService.findByUnique(codeTempEntity.getOrderId(), codeTempEntity.getCode());
|
|
|
if (tempEntity != null) {
|
|
|
if (isEdit) {
|
|
|
if (count < (tempEntity.getReCount())) {
|
|
|
return ResultVOUtils.error(500, "超出预验收存数量");
|
|
|
}
|
|
|
} else {
|
|
|
if (count < (tempEntity.getReCount() + codeTempEntity.getReCount())) {
|
|
|
return ResultVOUtils.error(500, "超出预验收存数量");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
if (count < 1) {
|
|
|
return ResultVOUtils.error(500, "预验收库存数量不足");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 校验寄售库存
|
|
|
*
|
|
|
* @param bussinessTypeEntity
|
|
|
* @param codeTempEntity
|
|
|
* @param isEdit
|
|
|
* @return
|
|
|
*/
|
|
|
public BaseResponse checkPreInv(BasicBussinessTypeEntity bussinessTypeEntity, IoCodeTempEntity codeTempEntity, boolean isEdit) {
|
|
|
|
|
|
InvWarehouseEntity invWarehouseEntity = invWarehouseService.findByOne(ConstantStatus.ACTION_TYPE_ADVANCE);
|
|
|
int count = 0;
|
|
|
if (bussinessTypeEntity.getSpaceOut() == ConstantStatus.SPACE_OUT_NULL) {
|
|
|
count = invPreProductDetailService.vailStockCount(codeTempEntity.getRelId(), codeTempEntity.getBatchNo(), codeTempEntity.getSupId(), null, invWarehouseEntity.getCode(), null);
|
|
|
} else if (bussinessTypeEntity.getSpaceOut() == ConstantStatus.SPACE_OUT_SET) {
|
|
|
count = invPreProductDetailService.vailStockCount(codeTempEntity.getRelId(), codeTempEntity.getBatchNo(), codeTempEntity.getSupId(), null, invWarehouseEntity.getCode(), codeTempEntity.getPreSpaceCode());
|
|
|
} else if (bussinessTypeEntity.getSpaceOut() == ConstantStatus.SPACE_OUT_CODE) {
|
|
|
//按指定货位出库
|
|
|
if (StrUtil.isEmpty(codeTempEntity.getPreSpaceCode())) {
|
|
|
List<InvPlaceDetailResponse> invProductDetailEntities = invPreProductDetailService.findByGroupCode(invWarehouseEntity.getCode(), codeTempEntity.getCode());
|
|
|
if (CollUtil.isNotEmpty(invProductDetailEntities) && invProductDetailEntities.size() > 1) {
|
|
|
BaseResponse baseResponse = ResultVOUtils.error(511, "存在多个货位,请指定当前货位!");
|
|
|
baseResponse.setData(invProductDetailEntities);
|
|
|
return baseResponse;
|
|
|
} else if (invProductDetailEntities.size() == 1) {
|
|
|
InvPlaceDetailResponse invPlaceDetailResponse = invProductDetailEntities.get(0);
|
|
|
count = invPlaceDetailResponse.getReCount();
|
|
|
codeTempEntity.setPreSpaceCode(invPlaceDetailResponse.getInvSpaceCode());
|
|
|
} else {
|
|
|
return ResultVOUtils.error(500, "添加失败,该产品未上架货位!");
|
|
|
}
|
|
|
} else {
|
|
|
count = invPreProductDetailService.vailStockCount(codeTempEntity.getRelId(), codeTempEntity.getBatchNo(), codeTempEntity.getSupId(), null, invWarehouseEntity.getCode(), codeTempEntity.getPreSpaceCode());
|
|
|
}
|
|
|
}
|
|
|
if (count <= 0) {
|
|
|
if (count == -1) {
|
|
|
return ResultVOUtils.error(500, "该产品未入库");
|
|
|
} else
|
|
|
return ResultVOUtils.error(500, "寄售库存数量不足!");
|
|
|
} else {
|
|
|
int exitCount = IntUtil.value(codeTempService.selectExitCount(codeTempEntity.getOrderId(), codeTempEntity.getBatchNo(), codeTempEntity.getRelId(), codeTempEntity.getSupId()));
|
|
|
if (isEdit) {
|
|
|
if (exitCount > count) {
|
|
|
return ResultVOUtils.error(500, "寄售库存数量不足");
|
|
|
}
|
|
|
} else {
|
|
|
|
|
|
if ((codeTempEntity.getMyReCount() + exitCount) > count) {
|
|
|
return ResultVOUtils.error(500, "寄售库存数量不足");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @param purType 1:入账库;2:预验收库;3:寄售库
|
|
|
*/
|
|
|
public boolean checkDiAttribute(BasicBussinessTypeEntity bussinessTypeEntity, UdiRelevanceResponse udiRelevanceEntity, Integer purType) {
|
|
|
if (bussinessTypeEntity.getUseDyCount() == 2) {
|
|
|
if (IntUtil.value(udiRelevanceEntity.getPurType()) == IntUtil.value(purType)) {
|
|
|
return true;
|
|
|
} else
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
}
|