优化库存逻辑和单据sku

This commit is contained in:
季圣华
2021-07-28 23:13:37 +08:00
parent f827e7c064
commit 7154492a51
14 changed files with 222 additions and 95 deletions

View File

@@ -281,8 +281,7 @@ public class DepotHeadService {
//更新当前库存
List<DepotItem> list = depotItemService.getListByHeaderId(id);
for (DepotItem depotItem : list) {
Long tenantId = redisService.getTenantId(request);
depotItemService.updateCurrentStock(depotItem, tenantId);
depotItemService.updateCurrentStock(depotItem);
}
/**删除单据主表信息*/
batchDeleteDepotHeadByIds(id.toString());
@@ -611,7 +610,7 @@ public class DepotHeadService {
* @throws Exception
*/
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public void addDepotHeadAndDetail(String beanJson, String rows, Long tenantId,
public void addDepotHeadAndDetail(String beanJson, String rows,
HttpServletRequest request) throws Exception {
/**处理单据主表数据*/
DepotHead depotHead = JSONObject.parseObject(beanJson, DepotHead.class);
@@ -668,7 +667,7 @@ public class DepotHeadService {
if(list!=null) {
Long headId = list.get(0).getId();
/**入库和出库处理单据子表信息*/
depotItemService.saveDetials(rows,headId,tenantId, request);
depotItemService.saveDetials(rows,headId, request);
}
/**如果关联单据号非空则更新订单的状态为2 (只操作采购订单和销售订单) */
if(depotHead.getLinkNumber()!=null) {
@@ -696,7 +695,7 @@ public class DepotHeadService {
* @throws Exception
*/
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public void updateDepotHeadAndDetail(String beanJson, String rows, Long tenantId,HttpServletRequest request)throws Exception {
public void updateDepotHeadAndDetail(String beanJson, String rows,HttpServletRequest request)throws Exception {
/**更新单据主表信息*/
DepotHead depotHead = JSONObject.parseObject(beanJson, DepotHead.class);
//获取之前的金额数据
@@ -742,7 +741,7 @@ public class DepotHeadService {
}
}
/**入库和出库处理单据子表信息*/
depotItemService.saveDetials(rows,depotHead.getId(),tenantId,request);
depotItemService.saveDetials(rows,depotHead.getId(),request);
logService.insertLog("单据",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(depotHead.getNumber()).toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());

View File

@@ -298,7 +298,7 @@ public class DepotItemService {
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public void saveDetials(String rows, Long headerId, Long tenantId, HttpServletRequest request) throws Exception{
public void saveDetials(String rows, Long headerId, HttpServletRequest request) throws Exception{
//查询单据主表信息
DepotHead depotHead =depotHeadMapper.selectByPrimaryKey(headerId);
//获得当前操作人
@@ -398,7 +398,7 @@ public class DepotItemService {
if(material==null){
continue;
}
BigDecimal stock = getStockByParam(depotItem.getDepotId(),depotItem.getMaterialId(),null,null,tenantId);
BigDecimal stock = getStockByParam(depotItem.getDepotId(),depotItem.getMaterialId(),null,null);
BigDecimal thisBasicNumber = depotItem.getBasicNumber()==null?BigDecimal.ZERO:depotItem.getBasicNumber();
if(systemConfigService.getMinusStockFlag() == false && stock.compareTo(thisBasicNumber)<0){
throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_STOCK_NOT_ENOUGH_CODE,
@@ -415,7 +415,7 @@ public class DepotItemService {
}
this.insertDepotItemWithObj(depotItem);
//更新当前库存
updateCurrentStock(depotItem,tenantId);
updateCurrentStock(depotItem);
}
} else {
throw new BusinessRunTimeException(ExceptionConstants.DEPOT_HEAD_ROW_FAILED_CODE,
@@ -455,6 +455,32 @@ public class DepotItemService {
return result;
}
/**
* 库存统计-sku
* @param depotId
* @param meId
* @param beginTime
* @param endTime
* @return
*/
public BigDecimal getSkuStockByParam(Long depotId, Long meId, String beginTime, String endTime){
DepotItemVo4Stock stockObj = depotItemMapperEx.getSkuStockByParam(depotId, meId, beginTime, endTime);
BigDecimal stockSum = BigDecimal.ZERO;
if(stockObj!=null) {
BigDecimal inTotal = stockObj.getInTotal();
BigDecimal transfInTotal = stockObj.getTransfInTotal();
BigDecimal assemInTotal = stockObj.getAssemInTotal();
BigDecimal disAssemInTotal = stockObj.getDisAssemInTotal();
BigDecimal outTotal = stockObj.getOutTotal();
BigDecimal transfOutTotal = stockObj.getTransfOutTotal();
BigDecimal assemOutTotal = stockObj.getAssemOutTotal();
BigDecimal disAssemOutTotal = stockObj.getDisAssemOutTotal();
stockSum = inTotal.add(transfInTotal).add(assemInTotal).add(disAssemInTotal)
.subtract(outTotal).subtract(transfOutTotal).subtract(assemOutTotal).subtract(disAssemOutTotal);
}
return stockSum;
}
/**
* 库存统计
* @param depotId
@@ -463,15 +489,26 @@ public class DepotItemService {
* @param endTime
* @return
*/
public BigDecimal getStockByParam(Long depotId, Long mId, String beginTime, String endTime, Long tenantId){
public BigDecimal getStockByParam(Long depotId, Long mId, String beginTime, String endTime){
//初始库存
BigDecimal initStock = materialService.getInitStockByMid(depotId, mId);
//盘点复盘后数量的变动
BigDecimal stockCheckSum = depotItemMapperEx.getStockCheckSum(depotId, mId, beginTime, endTime);
DepotItemVo4Stock stockObj = depotItemMapperEx.getStockByParam(depotId, mId, beginTime, endTime, tenantId);
BigDecimal intNum = stockObj.getInNum();
BigDecimal outNum = stockObj.getOutNum();
return initStock.add(intNum).subtract(outNum).add(stockCheckSum);
DepotItemVo4Stock stockObj = depotItemMapperEx.getStockByParam(depotId, mId, beginTime, endTime);
BigDecimal stockSum = BigDecimal.ZERO;
if(stockObj!=null) {
BigDecimal inTotal = stockObj.getInTotal();
BigDecimal transfInTotal = stockObj.getTransfInTotal();
BigDecimal assemInTotal = stockObj.getAssemInTotal();
BigDecimal disAssemInTotal = stockObj.getDisAssemInTotal();
BigDecimal outTotal = stockObj.getOutTotal();
BigDecimal transfOutTotal = stockObj.getTransfOutTotal();
BigDecimal assemOutTotal = stockObj.getAssemOutTotal();
BigDecimal disAssemOutTotal = stockObj.getDisAssemOutTotal();
stockSum = inTotal.add(transfInTotal).add(assemInTotal).add(disAssemInTotal)
.subtract(outTotal).subtract(transfOutTotal).subtract(assemOutTotal).subtract(disAssemOutTotal);
}
return initStock.add(stockCheckSum).add(stockSum);
}
/**
@@ -482,9 +519,17 @@ public class DepotItemService {
* @param endTime
* @return
*/
public BigDecimal getInNumByParam(Long depotId, Long mId, String beginTime, String endTime, Long tenantId){
DepotItemVo4Stock stockObj = depotItemMapperEx.getStockByParam(depotId, mId, beginTime, endTime, tenantId);
return stockObj.getInNum();
public BigDecimal getInNumByParam(Long depotId, Long mId, String beginTime, String endTime){
DepotItemVo4Stock stockObj = depotItemMapperEx.getStockByParam(depotId, mId, beginTime, endTime);
BigDecimal stockSum = BigDecimal.ZERO;
if(stockObj!=null) {
BigDecimal inTotal = stockObj.getInTotal();
BigDecimal transfInTotal = stockObj.getTransfInTotal();
BigDecimal assemInTotal = stockObj.getAssemInTotal();
BigDecimal disAssemInTotal = stockObj.getDisAssemInTotal();
stockSum = inTotal.add(transfInTotal).add(assemInTotal).add(disAssemInTotal);
}
return stockSum;
}
/**
@@ -495,21 +540,28 @@ public class DepotItemService {
* @param endTime
* @return
*/
public BigDecimal getOutNumByParam(Long depotId, Long mId, String beginTime, String endTime, Long tenantId){
DepotItemVo4Stock stockObj = depotItemMapperEx.getStockByParam(depotId, mId, beginTime, endTime, tenantId);
return stockObj.getOutNum();
public BigDecimal getOutNumByParam(Long depotId, Long mId, String beginTime, String endTime){
DepotItemVo4Stock stockObj = depotItemMapperEx.getStockByParam(depotId, mId, beginTime, endTime);
BigDecimal stockSum = BigDecimal.ZERO;
if(stockObj!=null) {
BigDecimal outTotal = stockObj.getOutTotal();
BigDecimal transfOutTotal = stockObj.getTransfOutTotal();
BigDecimal assemOutTotal = stockObj.getAssemOutTotal();
BigDecimal disAssemOutTotal = stockObj.getDisAssemOutTotal();
stockSum = outTotal.subtract(transfOutTotal).subtract(assemOutTotal).subtract(disAssemOutTotal);
}
return stockSum;
}
/**
* 根据单据明细来批量更新当前库存
* @param depotItem
* @param tenantId
*/
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public void updateCurrentStock(DepotItem depotItem, Long tenantId){
updateCurrentStockFun(depotItem.getMaterialId(), depotItem.getDepotId(),tenantId);
public void updateCurrentStock(DepotItem depotItem){
updateCurrentStockFun(depotItem.getMaterialId(), depotItem.getDepotId());
if(depotItem.getAnotherDepotId()!=null){
updateCurrentStockFun(depotItem.getMaterialId(), depotItem.getAnotherDepotId(),tenantId);
updateCurrentStockFun(depotItem.getMaterialId(), depotItem.getAnotherDepotId());
}
}
@@ -517,9 +569,8 @@ public class DepotItemService {
* 根据商品和仓库来更新当前库存
* @param mId
* @param dId
* @param tenantId
*/
public void updateCurrentStockFun(Long mId, Long dId, Long tenantId) {
public void updateCurrentStockFun(Long mId, Long dId) {
MaterialCurrentStockExample example = new MaterialCurrentStockExample();
example.createCriteria().andMaterialIdEqualTo(mId).andDepotIdEqualTo(dId)
.andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
@@ -527,7 +578,7 @@ public class DepotItemService {
MaterialCurrentStock materialCurrentStock = new MaterialCurrentStock();
materialCurrentStock.setMaterialId(mId);
materialCurrentStock.setDepotId(dId);
materialCurrentStock.setCurrentNumber(getStockByParam(dId,mId,null,null,tenantId));
materialCurrentStock.setCurrentNumber(getStockByParam(dId,mId,null,null));
if(list!=null && list.size()>0) {
Long mcsId = list.get(0).getId();
materialCurrentStock.setId(mcsId);

View File

@@ -142,8 +142,7 @@ public class MaterialService {
}
}
m.setMaterialOther(materialOther);
Long tenantId = m.getTenantId();
m.setStock(depotItemService.getStockByParam(null,m.getId(),null,null,tenantId));
m.setStock(depotItemService.getStockByParam(null,m.getId(),null,null));
resList.add(m);
}
}
@@ -228,8 +227,7 @@ public class MaterialService {
insertInitialStockByMaterialAndDepot(depotId, material.getId(), parseBigDecimalEx(number));
}
//更新当前库存
Long tenantId = redisService.getTenantId(request);
depotItemService.updateCurrentStockFun(material.getId(), depotId, tenantId);
depotItemService.updateCurrentStockFun(material.getId(), depotId);
}
}
}
@@ -454,8 +452,8 @@ public class MaterialService {
String categoryName = ExcelUtils.getContent(src, i, 4); //类别
String safetyStock = ExcelUtils.getContent(src, i, 5); //安全存量
String unit = ExcelUtils.getContent(src, i, 6); //基础单位
//校验名称、型号、单位是否为空
if(StringUtil.isNotEmpty(name) && StringUtil.isNotEmpty(model) && StringUtil.isNotEmpty(unit)) {
//校验名称、单位是否为空
if(StringUtil.isNotEmpty(name) && StringUtil.isNotEmpty(unit)) {
MaterialWithInitStock m = new MaterialWithInitStock();
m.setName(name);
m.setStandard(standard);
@@ -594,8 +592,7 @@ public class MaterialService {
depotId = depot.getId();
insertInitialStockByMaterialAndDepot(depotId, mId, stock);
//更新当前库存
Long tenantId = redisService.getTenantId(request);
depotItemService.updateCurrentStockFun(mId, depotId, tenantId);
depotItemService.updateCurrentStockFun(mId, depotId);
}
}
}