增加当前库存表

This commit is contained in:
季圣华
2020-07-14 00:18:14 +08:00
parent cbba347579
commit f759c0f980
18 changed files with 1388 additions and 760 deletions

View File

@@ -3,10 +3,7 @@ package com.jsh.erp.service.depotHead;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.constants.BusinessConstants;
import com.jsh.erp.constants.ExceptionConstants;
import com.jsh.erp.datasource.entities.DepotHead;
import com.jsh.erp.datasource.entities.DepotHeadExample;
import com.jsh.erp.datasource.entities.DepotItem;
import com.jsh.erp.datasource.entities.User;
import com.jsh.erp.datasource.entities.*;
import com.jsh.erp.datasource.mappers.DepotHeadMapper;
import com.jsh.erp.datasource.mappers.DepotHeadMapperEx;
import com.jsh.erp.datasource.mappers.DepotItemMapperEx;
@@ -555,7 +552,7 @@ public class DepotHeadService {
* @throws Exception
*/
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public void deleteDepotHeadAndDetail(Long id) throws Exception {
public void deleteDepotHeadAndDetail(Long id, HttpServletRequest request) throws Exception {
//查询单据主表信息
DepotHead depotHead =getDepotHead(id);
User userInfo=userService.getCurrentUser();
@@ -581,6 +578,12 @@ public class DepotHeadService {
/**删除单据子表数据*/
try{
depotItemMapperEx.batchDeleteDepotItemByDepotHeadIds(new Long []{id});
//更新当前库存
List<DepotItem> list = depotItemService.getListByHeaderId(id);
for(DepotItem depotItem: list){
Long tenantId = Long.parseLong(request.getSession().getAttribute("tenantId").toString());
depotItemService.updateCurrentStock(depotItem,tenantId);
}
}catch(Exception e){
JshException.writeFail(logger, e);
}
@@ -598,11 +601,11 @@ public class DepotHeadService {
* @throws Exception
*/
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public void batchDeleteDepotHeadAndDetail(String ids) throws Exception{
public void batchDeleteDepotHeadAndDetail(String ids, HttpServletRequest request) throws Exception{
if(StringUtil.isNotEmpty(ids)){
String [] headIds=ids.split(",");
for(int i=0;i<headIds.length;i++){
deleteDepotHeadAndDetail(Long.valueOf(headIds[i]));
deleteDepotHeadAndDetail(Long.valueOf(headIds[i]), request);
}
}
}

View File

@@ -5,10 +5,7 @@ import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.constants.BusinessConstants;
import com.jsh.erp.constants.ExceptionConstants;
import com.jsh.erp.datasource.entities.*;
import com.jsh.erp.datasource.mappers.DepotHeadMapper;
import com.jsh.erp.datasource.mappers.DepotItemMapper;
import com.jsh.erp.datasource.mappers.DepotItemMapperEx;
import com.jsh.erp.datasource.mappers.SerialNumberMapperEx;
import com.jsh.erp.datasource.mappers.*;
import com.jsh.erp.datasource.vo.DepotItemStockWarningCount;
import com.jsh.erp.datasource.vo.DepotItemVo4Stock;
import com.jsh.erp.exception.BusinessRunTimeException;
@@ -63,6 +60,8 @@ public class DepotItemService {
@Resource
private SystemConfigService systemConfigService;
@Resource
private MaterialCurrentStockMapper materialCurrentStockMapper;
@Resource
private LogService logService;
public DepotItem getDepotItem(long id)throws Exception {
@@ -221,6 +220,18 @@ public class DepotItemService {
return result;
}
public List<DepotItem> getListByHeaderId(Long headerId)throws Exception {
List<DepotItem> list =null;
try{
DepotItemExample example = new DepotItemExample();
example.createCriteria().andHeaderidEqualTo(headerId);
list = depotItemMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public List<DepotItemVo4WithInfoEx> getDetailList(Long headerId)throws Exception {
List<DepotItemVo4WithInfoEx> list =null;
try{
@@ -333,13 +344,18 @@ public class DepotItemService {
userInfo);
}
}
this.deleteDepotItem(tempDeletedJson.getLong("Id"), request);
bf.append(tempDeletedJson.getLong("Id"));
if(i<(deletedJson.size()-1)){
bf.append(",");
}
}
this.batchDeleteDepotItemByIds(bf.toString());
//更新当前库存
for (int i = 0; i < deletedJson.size(); i++) {
JSONObject tempDeletedJson = JSONObject.parseObject(deletedJson.getString(i));
DepotItem depotItem = getDepotItem(tempDeletedJson.getLong("Id"));
updateCurrentStock(depotItem,tenantId);
}
}
if (null != insertedJson) {
for (int i = 0; i < insertedJson.size(); i++) {
@@ -449,6 +465,8 @@ public class DepotItemService {
}
}
this.insertDepotItemWithObj(depotItem);
//更新当前库存
updateCurrentStock(depotItem,tenantId);
}
}
@@ -576,6 +594,8 @@ public class DepotItemService {
}
}
this.updateDepotItemWithObj(depotItem);
//更新当前库存
updateCurrentStock(depotItem,tenantId);
}
}
return null;
@@ -680,4 +700,28 @@ public class DepotItemService {
DepotItemVo4Stock stockObj = depotItemMapperEx.getStockByParam(depotId, mId, beginTime, endTime, tenantId);
return stockObj.getOutNum();
}
/**
* 根据单据明细来批量更新当前库存
* @param depotItem
* @param tenantId
*/
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public void updateCurrentStock(DepotItem depotItem, Long tenantId){
MaterialCurrentStockExample example = new MaterialCurrentStockExample();
example.createCriteria().andMaterialIdEqualTo(depotItem.getMaterialid()).andDepotIdEqualTo(depotItem.getDepotid())
.andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<MaterialCurrentStock> list = materialCurrentStockMapper.selectByExample(example);
MaterialCurrentStock materialCurrentStock = new MaterialCurrentStock();
materialCurrentStock.setMaterialId(depotItem.getMaterialid());
materialCurrentStock.setDepotId(depotItem.getDepotid());
materialCurrentStock.setCurrentNumber(getStockByParam(depotItem.getDepotid(),depotItem.getMaterialid(),null,null,tenantId));
if(list!=null && list.size()>0) {
Long mcsId = list.get(0).getId();
materialCurrentStock.setId(mcsId);
materialCurrentStockMapper.updateByPrimaryKeySelective(materialCurrentStock);
} else {
materialCurrentStockMapper.insertSelective(materialCurrentStock);
}
}
}

View File

@@ -59,7 +59,7 @@ public class MaterialService {
@Resource
private UnitService unitService;
@Resource
private MaterialStockMapper materialStockMapper;
private MaterialInitialStockMapper materialInitialStockMapper;
@Resource
private DepotService depotService;
@Resource
@@ -201,9 +201,9 @@ public class MaterialService {
String number = jsonObj.getString("number");
Long depotId = jsonObj.getLong("depotId");
//先清除再插入
MaterialStockExample example = new MaterialStockExample();
MaterialInitialStockExample example = new MaterialInitialStockExample();
example.createCriteria().andMaterialIdEqualTo(id).andDepotIdEqualTo(depotId);
materialStockMapper.deleteByExample(example);
materialInitialStockMapper.deleteByExample(example);
if (number != null && Double.valueOf(number) > 0) {
insertStockByMaterialAndDepot(depotId, id, parseBigDecimalEx(number));
}
@@ -490,7 +490,7 @@ public class MaterialService {
basicMaterialExtend.setMaterialId(mId);
basicMaterialExtend.setDefaultFlag("1");
basicMaterialExtend.setCreateTime(new Date());
basicMaterialExtend.setUpdateTime(new Date().getTime());
basicMaterialExtend.setUpdateTime(System.currentTimeMillis());
basicMaterialExtend.setCreateSerial(user.getLoginName());
basicMaterialExtend.setUpdateSerial(user.getLoginName());
materialExtendMapper.insertSelective(basicMaterialExtend);
@@ -501,7 +501,7 @@ public class MaterialService {
otherMaterialExtend.setMaterialId(mId);
otherMaterialExtend.setDefaultFlag("0");
otherMaterialExtend.setCreateTime(new Date());
otherMaterialExtend.setUpdateTime(new Date().getTime());
otherMaterialExtend.setUpdateTime(System.currentTimeMillis());
otherMaterialExtend.setCreateSerial(user.getLoginName());
otherMaterialExtend.setUpdateSerial(user.getLoginName());
materialExtendMapper.insertSelective(otherMaterialExtend);
@@ -512,9 +512,9 @@ public class MaterialService {
for(Depot depot: depotList){
BigDecimal stock = stockMap.get(depot.getId());
//先清除再插入
MaterialStockExample example = new MaterialStockExample();
MaterialInitialStockExample example = new MaterialInitialStockExample();
example.createCriteria().andMaterialIdEqualTo(mId).andDepotIdEqualTo(depot.getId());
materialStockMapper.deleteByExample(example);
materialInitialStockMapper.deleteByExample(example);
if(stock!=null && stock.compareTo(BigDecimal.ZERO)!=0) {
depotId = depot.getId();
insertStockByMaterialAndDepot(depotId, mId, stock);
@@ -576,11 +576,11 @@ public class MaterialService {
*/
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public void insertStockByMaterialAndDepot(Long depotId, Long mId, BigDecimal stock){
MaterialStock materialStock = new MaterialStock();
materialStock.setDepotId(depotId);
materialStock.setMaterialId(mId);
materialStock.setNumber(stock);
materialStockMapper.insertSelective(materialStock); //存入初始库存
MaterialInitialStock materialInitialStock = new MaterialInitialStock();
materialInitialStock.setDepotId(depotId);
materialInitialStock.setMaterialId(mId);
materialInitialStock.setNumber(stock);
materialInitialStockMapper.insertSelective(materialInitialStock); //存入初始库存
}
public List<Material> getMaterialEnableSerialNumberList(Map<String, Object> parameterMap)throws Exception {
@@ -697,10 +697,10 @@ public class MaterialService {
*/
public BigDecimal getInitStock(Long materialId, Long depotId) {
BigDecimal stock = BigDecimal.ZERO;
MaterialStockExample example = new MaterialStockExample();
MaterialInitialStockExample example = new MaterialInitialStockExample();
example.createCriteria().andMaterialIdEqualTo(materialId).andDepotIdEqualTo(depotId)
.andDeleteFagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<MaterialStock> list = materialStockMapper.selectByExample(example);
.andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<MaterialInitialStock> list = materialInitialStockMapper.selectByExample(example);
if(list!=null && list.size()>0) {
stock = list.get(0).getNumber();
}
@@ -714,17 +714,17 @@ public class MaterialService {
*/
public BigDecimal getInitStockByMid(Long depotId, Long materialId) {
BigDecimal stock = BigDecimal.ZERO;
MaterialStockExample example = new MaterialStockExample();
MaterialInitialStockExample example = new MaterialInitialStockExample();
if(depotId!=null) {
example.createCriteria().andMaterialIdEqualTo(materialId).andDepotIdEqualTo(depotId)
.andDeleteFagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
.andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
} else {
example.createCriteria().andMaterialIdEqualTo(materialId)
.andDeleteFagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
.andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
}
List<MaterialStock> list = materialStockMapper.selectByExample(example);
List<MaterialInitialStock> list = materialInitialStockMapper.selectByExample(example);
if(list!=null && list.size()>0) {
for(MaterialStock ms: list) {
for(MaterialInitialStock ms: list) {
if(ms!=null) {
stock = stock.add(ms.getNumber());
}