Commit 9588dc98 authored by 耿迪迪's avatar 耿迪迪

库存增扣逻辑优化

parent 7af1919d
......@@ -110,12 +110,23 @@ public class TProductStoreController extends BaseController
}
/**
* 入库信息
* @param storeInfo
* 入库
* @param storeInfo 入库信息
* @return
*/
@PostMapping("/inHouse")
public AjaxResult inHouse(@RequestBody List<HouseVo> storeInfo){
return toAjax(tProductStoreService.inHouse(storeInfo,true));
return toAjax(tProductStoreService.computeStock(storeInfo,true,"add"));
}
/**
* 出库
* @param storeInfo 出库信息
* @return
*/
@PostMapping("/outHouse")
public AjaxResult outHouse(@RequestBody List<HouseVo> storeInfo){
return toAjax(tProductStoreService.computeStock(storeInfo,true,"subtract"));
}
}
......@@ -105,7 +105,6 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
"/**/*.css",
"/**/*.js"
).permitAll()
.antMatchers("/track/store/**").permitAll()
.antMatchers("/profile/**").anonymous()
.antMatchers("/common/download**").anonymous()
.antMatchers("/common/download/resource**").anonymous()
......
......@@ -4,7 +4,6 @@ import com.zehong.common.exception.CustomException;
import com.zehong.common.utils.DateUtils;
import com.zehong.common.utils.SecurityUtils;
import com.zehong.system.domain.track.TProductInspectDetail;
import com.zehong.system.domain.track.TProductStore;
import com.zehong.system.domain.vo.HouseVo;
import com.zehong.system.mapper.TProductInspectDetailMapper;
import com.zehong.system.service.track.ITProductInspectDetailService;
......@@ -104,7 +103,7 @@ public class TProductInspectDetailServiceImpl implements ITProductInspectDetailS
storeInfo.add(house);
}
}
if(!CollectionUtils.isEmpty(storeInfo)) itProductStoreService.inHouse(storeInfo,false);
if(!CollectionUtils.isEmpty(storeInfo)) itProductStoreService.computeStock(storeInfo,false,"add");
return tProductInspectDetailMapper.deleteTProductInspectDetailByIds(ids);
}
......@@ -161,15 +160,15 @@ public class TProductInspectDetailServiceImpl implements ITProductInspectDetailS
*/
@Transactional(rollbackFor = Exception.class)
public int subtractStoreStock(List<TProductInspectDetail> productInspectDetailList){
List<TProductInspectDetail> storeList = productInspectDetailList.stream().filter(item -> 2 == item.getType()).collect(Collectors.toList());
for(TProductInspectDetail detail : storeList){
TProductStore store = itProductStoreService.selectTProductStoreById(detail.getTypeId());
if(store.getTotal().compareTo(detail.getNumber()) == -1){
throw new CustomException(store.getTitle() + "库存不足");
}
store.setTotal(store.getTotal() - detail.getNumber());
itProductStoreService.updateTProductStore(store);
}
List<HouseVo> storeList = productInspectDetailList.stream().filter(item -> 2 == item.getType())
.map(item ->{
HouseVo house = new HouseVo();
house.setId(item.getTypeId());
house.setNum(item.getNumber());
return house;
})
.collect(Collectors.toList());
itProductStoreService.computeStock(storeList,false,"subtract");
return tProductInspectDetailMapper.batchAddDetailInfo(productInspectDetailList);
}
}
package com.zehong.system.service.impl.track;
import com.zehong.common.exception.CustomException;
import com.zehong.common.utils.DateUtils;
import com.zehong.common.utils.SecurityUtils;
import com.zehong.system.domain.track.TProductInspectDetail;
import com.zehong.system.domain.track.TProductStore;
import com.zehong.system.domain.track.TProductStoreLog;
import com.zehong.system.domain.vo.HouseVo;
......@@ -14,7 +14,6 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
/**
......@@ -115,12 +114,17 @@ public class TProductStoreServiceImpl implements ITProductStoreService
* 配件批量入库
* @param storeInfo 配件信息
* @param isAddLog 是否插入日志
* @param type 操作类型
* @return
*/
@Override
public int inHouse(List<HouseVo> storeInfo,boolean isAddLog){
public int computeStock(List<HouseVo> storeInfo,boolean isAddLog,String type){
synchronized (this){
addStoreStock(storeInfo,isAddLog);
if("add".equals(type)){
addStoreStock(storeInfo,isAddLog);
}else{
subtractStoreStock(storeInfo);
}
}
return 1;
}
......@@ -145,4 +149,21 @@ public class TProductStoreServiceImpl implements ITProductStoreService
}
}
}
/**
* 扣出库存
* @param storeList
* @return
*/
@Transactional(rollbackFor = Exception.class)
public void subtractStoreStock(List<HouseVo> storeList){
for(HouseVo storeInfo : storeList){
TProductStore store = tProductStoreMapper.selectTProductStoreById(storeInfo.getId());
if(store.getTotal().compareTo(storeInfo.getNum()) == -1){
throw new CustomException(store.getTitle() + "库存不足");
}
store.setTotal(store.getTotal() - storeInfo.getNum());
tProductStoreMapper.updateTProductStore(store);
}
}
}
......@@ -66,8 +66,9 @@ public interface ITProductStoreService
* 配件批量入库
* @param storeInfo 配件信息
* @param isAddLog 是否记录日志
* @param type 操作类型
* @return
*/
int inHouse(List<HouseVo> storeInfo,boolean isAddLog);
int computeStock(List<HouseVo> storeInfo,boolean isAddLog,String type);
}
......@@ -150,9 +150,7 @@
validateData(){
//检查信息是否完整
for(var i = 0; i< this.detailInfoList.length; i++){
console.log("=============================",(this.detailInfoList[i].typeId && this.detailInfoList[i].type))
if(!(this.detailInfoList[i].typeId && this.detailInfoList[i].type && this.detailInfoList[i].number) && 2 == this.detailInfoList[i].type){
console.log("=============================")
this.$message.error("请检查信息是否填完整");
return true;
}
......
......@@ -73,8 +73,8 @@
}
},
submitStore(){
for(var i = 0; i< this.detailInfoList.length; i++){
if(!(this.detailInfoList[i].id && this.detailInfoList[i].num)){
for(var i = 0; i< this.inHouseStore.length; i++){
if(!(this.inHouseStore[i].id && this.inHouseStore[i].num)){
this.$message.error("请检查信息是否填完整");
return
}
......
......@@ -35,7 +35,7 @@
@click="handleAdd"
>新增</el-button>
</el-col>
<el-col :span="1.5">
<!--<el-col :span="1.5">
<el-button
type="success"
plain
......@@ -44,7 +44,7 @@
:disabled="single"
@click="handleUpdate"
>修改</el-button>
</el-col>
</el-col>-->
<el-col :span="1.5">
<el-button
type="danger"
......@@ -112,12 +112,12 @@
icon="el-icon-document"
@click="handleDetail(scope.row)"
>详情</el-button>
<el-button
<!--<el-button
size="mini"
type="text"
icon="el-icon-edit"
@click="handleUpdate(scope.row)"
>修改</el-button>
>修改</el-button>-->
<el-button
size="mini"
type="text"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment