添加商品库存校验
This commit is contained in:
@@ -32,10 +32,10 @@ public class ExceptionConstants {
|
|||||||
public static final int SERIAL_NUMBERE_ALREADY_EXISTS_CODE = 10500000;
|
public static final int SERIAL_NUMBERE_ALREADY_EXISTS_CODE = 10500000;
|
||||||
public static final String SERIAL_NUMBERE_ALREADY_EXISTS_MSG = "序列号已存在";
|
public static final String SERIAL_NUMBERE_ALREADY_EXISTS_MSG = "序列号已存在";
|
||||||
/**序列号不能为为空*/
|
/**序列号不能为为空*/
|
||||||
public static final int SERIAL_NUMBERE_NOT_BE_EMPTY_CODE = 10500000;
|
public static final int SERIAL_NUMBERE_NOT_BE_EMPTY_CODE = 10500001;
|
||||||
public static final String SERIAL_NUMBERE_NOT_BE_EMPTY_MSG = "序列号不能为为空";
|
public static final String SERIAL_NUMBERE_NOT_BE_EMPTY_MSG = "序列号不能为为空";
|
||||||
/**商品%s下序列号不充足,请补充后重试*/
|
/**商品%s下序列号不充足,请补充后重试*/
|
||||||
public static final int MATERIAL_SERIAL_NUMBERE_NOT_ENOUGH_CODE = 10500000;
|
public static final int MATERIAL_SERIAL_NUMBERE_NOT_ENOUGH_CODE = 10500002;
|
||||||
public static final String MATERIAL_SERIAL_NUMBERE_NOT_ENOUGH_MSG = "商品:%s下序列号不充足,请补充后重试";
|
public static final String MATERIAL_SERIAL_NUMBERE_NOT_ENOUGH_MSG = "商品:%s下序列号不充足,请补充后重试";
|
||||||
|
|
||||||
|
|
||||||
@@ -56,6 +56,9 @@ public class ExceptionConstants {
|
|||||||
//该商品已绑定序列号数量小于等于商品现有库存
|
//该商品已绑定序列号数量小于等于商品现有库存
|
||||||
public static final int MATERIAL_SERIAL_NUMBERE_NOT_MORE_THAN_STORAGE_CODE = 8000003;
|
public static final int MATERIAL_SERIAL_NUMBERE_NOT_MORE_THAN_STORAGE_CODE = 8000003;
|
||||||
public static final String MATERIAL_SERIAL_NUMBERE_NOT_MORE_THAN_STORAGE_MSG = "该商品已绑定序列号数量大于等于商品现有库存";
|
public static final String MATERIAL_SERIAL_NUMBERE_NOT_MORE_THAN_STORAGE_MSG = "该商品已绑定序列号数量大于等于商品现有库存";
|
||||||
|
//商品库存不足
|
||||||
|
public static final int MATERIAL_STOCK_NOT_ENOUGH_CODE = 8000004;
|
||||||
|
public static final String MATERIAL_STOCK_NOT_ENOUGH_MSG = "商品:%s库存不足";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 标准正常返回/操作成功返回
|
* 标准正常返回/操作成功返回
|
||||||
|
|||||||
@@ -3,11 +3,13 @@ package com.jsh.erp.service.depotItem;
|
|||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.jsh.erp.constants.BusinessConstants;
|
import com.jsh.erp.constants.BusinessConstants;
|
||||||
|
import com.jsh.erp.constants.ExceptionConstants;
|
||||||
import com.jsh.erp.datasource.entities.*;
|
import com.jsh.erp.datasource.entities.*;
|
||||||
import com.jsh.erp.datasource.mappers.DepotHeadMapper;
|
import com.jsh.erp.datasource.mappers.DepotHeadMapper;
|
||||||
import com.jsh.erp.datasource.mappers.DepotItemMapper;
|
import com.jsh.erp.datasource.mappers.DepotItemMapper;
|
||||||
import com.jsh.erp.datasource.mappers.DepotItemMapperEx;
|
import com.jsh.erp.datasource.mappers.DepotItemMapperEx;
|
||||||
import com.jsh.erp.datasource.mappers.SerialNumberMapperEx;
|
import com.jsh.erp.datasource.mappers.SerialNumberMapperEx;
|
||||||
|
import com.jsh.erp.exception.BusinessRunTimeException;
|
||||||
import com.jsh.erp.service.material.MaterialService;
|
import com.jsh.erp.service.material.MaterialService;
|
||||||
import com.jsh.erp.service.serialNumber.SerialNumberService;
|
import com.jsh.erp.service.serialNumber.SerialNumberService;
|
||||||
import com.jsh.erp.service.user.UserService;
|
import com.jsh.erp.service.user.UserService;
|
||||||
@@ -341,24 +343,39 @@ public class DepotItemService {
|
|||||||
depotItem.setMtype(tempInsertedJson.getString("MType"));
|
depotItem.setMtype(tempInsertedJson.getString("MType"));
|
||||||
}
|
}
|
||||||
this.insertDepotItemWithObj(depotItem);
|
this.insertDepotItemWithObj(depotItem);
|
||||||
/**出库时处理序列号*/
|
|
||||||
if(BusinessConstants.DEPOTHEAD_TYPE_OUT.equals(depotHead.getType())
|
/**
|
||||||
&&!BusinessConstants.SUB_TYPE_TRANSFER.equals(depotHead.getSubtype())){
|
* 出库时判断库存是否充足
|
||||||
if(depotItem==null){
|
* */
|
||||||
continue;
|
if(!BusinessConstants.DEPOTHEAD_TYPE_OUT.equals(depotHead.getType())){
|
||||||
}
|
//非出库,可以直接跳过下面的操作
|
||||||
/**
|
continue;
|
||||||
* 判断商品是否开启序列号,开启的收回序列号,未开启的跳过
|
|
||||||
* */
|
|
||||||
Material material= materialService.getMaterial(depotItem.getMaterialid());
|
|
||||||
if(material==null){
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if(BusinessConstants.ENABLE_SERIAL_NUMBER_ENABLED.equals(material.getEnableSerialNumber())) {
|
|
||||||
//查询单据子表中开启序列号的数据列表
|
|
||||||
serialNumberService.checkAndUpdateSerialNumber(depotItem, userInfo);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if(depotItem==null){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Material material= materialService.getMaterial(depotItem.getMaterialid());
|
||||||
|
if(material==null){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if(getCurrentInStock(depotItem.getMaterialid())<depotItem.getOpernumber().intValue()){
|
||||||
|
throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_STOCK_NOT_ENOUGH_CODE,
|
||||||
|
String.format(ExceptionConstants.MATERIAL_STOCK_NOT_ENOUGH_MSG,material==null?"":material.getName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**出库时处理序列号*/
|
||||||
|
if(BusinessConstants.SUB_TYPE_TRANSFER.equals(depotHead.getSubtype())) {
|
||||||
|
//调拨,不处理序列号问题
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 判断商品是否开启序列号,开启的收回序列号,未开启的跳过
|
||||||
|
* */
|
||||||
|
if(BusinessConstants.ENABLE_SERIAL_NUMBER_ENABLED.equals(material.getEnableSerialNumber())) {
|
||||||
|
//查询单据子表中开启序列号的数据列表
|
||||||
|
serialNumberService.checkAndUpdateSerialNumber(depotItem, userInfo);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -366,19 +383,19 @@ public class DepotItemService {
|
|||||||
for (int i = 0; i < updatedJson.size(); i++) {
|
for (int i = 0; i < updatedJson.size(); i++) {
|
||||||
JSONObject tempUpdatedJson = JSONObject.parseObject(updatedJson.getString(i));
|
JSONObject tempUpdatedJson = JSONObject.parseObject(updatedJson.getString(i));
|
||||||
DepotItem depotItem = this.getDepotItem(tempUpdatedJson.getLong("Id"));
|
DepotItem depotItem = this.getDepotItem(tempUpdatedJson.getLong("Id"));
|
||||||
|
if(depotItem==null){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Material material= materialService.getMaterial(depotItem.getMaterialid());
|
||||||
|
if(material==null){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
//首先回收序列号
|
//首先回收序列号
|
||||||
if(BusinessConstants.DEPOTHEAD_TYPE_OUT.equals(depotHead.getType())
|
if(BusinessConstants.DEPOTHEAD_TYPE_OUT.equals(depotHead.getType())
|
||||||
&&!BusinessConstants.SUB_TYPE_TRANSFER.equals(depotHead.getSubtype())) {
|
&&!BusinessConstants.SUB_TYPE_TRANSFER.equals(depotHead.getSubtype())) {
|
||||||
if(depotItem==null){
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* 判断商品是否开启序列号,开启的收回序列号,未开启的跳过
|
* 判断商品是否开启序列号,开启的收回序列号,未开启的跳过
|
||||||
* */
|
* */
|
||||||
Material material= materialService.getMaterial(depotItem.getMaterialid());
|
|
||||||
if(material==null){
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if(BusinessConstants.ENABLE_SERIAL_NUMBER_ENABLED.equals(material.getEnableSerialNumber())) {
|
if(BusinessConstants.ENABLE_SERIAL_NUMBER_ENABLED.equals(material.getEnableSerialNumber())) {
|
||||||
serialNumberMapperEx.cancelSerialNumber(depotItem.getMaterialid(), depotItem.getHeaderid(), depotItem.getOpernumber().intValue(),
|
serialNumberMapperEx.cancelSerialNumber(depotItem.getMaterialid(), depotItem.getHeaderid(), depotItem.getOpernumber().intValue(),
|
||||||
new Date(), userInfo == null ? null : userInfo.getId());
|
new Date(), userInfo == null ? null : userInfo.getId());
|
||||||
@@ -446,22 +463,24 @@ public class DepotItemService {
|
|||||||
depotItem.setMtype(tempUpdatedJson.getString("MType"));
|
depotItem.setMtype(tempUpdatedJson.getString("MType"));
|
||||||
this.updateDepotItemWithObj(depotItem);
|
this.updateDepotItemWithObj(depotItem);
|
||||||
/**出库时处理序列号*/
|
/**出库时处理序列号*/
|
||||||
if(BusinessConstants.DEPOTHEAD_TYPE_OUT.equals(depotHead.getType())
|
if(!BusinessConstants.DEPOTHEAD_TYPE_OUT.equals(depotHead.getType())){
|
||||||
&&!BusinessConstants.SUB_TYPE_TRANSFER.equals(depotHead.getSubtype())){
|
//非出库,不处理下面的逻辑
|
||||||
if(depotItem==null){
|
continue;
|
||||||
continue;
|
}
|
||||||
}
|
if(getCurrentInStock(depotItem.getMaterialid())<depotItem.getOpernumber().intValue()){
|
||||||
|
throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_STOCK_NOT_ENOUGH_CODE,
|
||||||
|
String.format(ExceptionConstants.MATERIAL_STOCK_NOT_ENOUGH_MSG,material==null?"":material.getName()));
|
||||||
|
}
|
||||||
|
if(BusinessConstants.SUB_TYPE_TRANSFER.equals(depotHead.getSubtype())) {
|
||||||
|
//调拨,不处理序列号问题
|
||||||
|
continue;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* 判断商品是否开启序列号,开启的收回序列号,未开启的跳过
|
* 判断商品是否开启序列号,开启的收回序列号,未开启的跳过
|
||||||
* */
|
* */
|
||||||
Material material= materialService.getMaterial(depotItem.getMaterialid());
|
if(BusinessConstants.ENABLE_SERIAL_NUMBER_ENABLED.equals(material.getEnableSerialNumber())) {
|
||||||
if(material==null){
|
//查询单据子表中开启序列号的数据列表
|
||||||
continue;
|
serialNumberService.checkAndUpdateSerialNumber(depotItem, userInfo);
|
||||||
}
|
|
||||||
if(BusinessConstants.ENABLE_SERIAL_NUMBER_ENABLED.equals(material.getEnableSerialNumber())) {
|
|
||||||
//查询单据子表中开启序列号的数据列表
|
|
||||||
serialNumberService.checkAndUpdateSerialNumber(depotItem, userInfo);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -487,5 +506,16 @@ public class DepotItemService {
|
|||||||
}
|
}
|
||||||
return unitName;
|
return unitName;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 查询商品当前库存数量是否充足,
|
||||||
|
*
|
||||||
|
* */
|
||||||
|
public int getCurrentInStock(Long materialId){
|
||||||
|
//入库数量
|
||||||
|
int inSum = findByTypeAndMaterialId(BusinessConstants.DEPOTHEAD_TYPE_STORAGE, materialId);
|
||||||
|
//出库数量
|
||||||
|
int outSum = findByTypeAndMaterialId(BusinessConstants.DEPOTHEAD_TYPE_OUT, materialId);
|
||||||
|
return (inSum-outSum);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user