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

库存增扣逻辑优化

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