Browse Source

出入库

2 years ago
parent
commit
8a33a65845

+ 7 - 7
platform-service/src/main/java/com/platform/service/store/impl/InStoreFormServiceImpl.java

@@ -231,17 +231,14 @@ public class InStoreFormServiceImpl extends BaseServiceImpl<InStoreFormMapper, I
 
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public void spareInStore(InStoreFormDTO model) {
         SparePartInfo sparePartInfo = sparePartInfoMapper.selectById(model.getSpareId());
         SpareStore spareStore = new SpareStore();
         spareStore.setSpareId(model.getSpareId());
-        List<SpareStore> spareStores = spareStoreMapper.select(spareStore);
-        Integer currentStock=0;
-        for (SpareStore store:spareStores){
-            Integer num = (store.getNum()==null?0:store.getNum().intValue());
-            currentStock+=num;
-        }
-        if (currentStock+model.getInNum()>sparePartInfo.getMaxStock().intValue()){
+        spareStore = spareStoreMapper.selectOne(spareStore);
+
+        if (spareStore.getNum().intValue()+model.getInNum()>sparePartInfo.getMaxStock().intValue()){
             throw new BusinessException("该备件的最大库存量为"+sparePartInfo.getMaxStock()+"目前已超出,请修改入库数量!");
         }
         UserInfo userInfo = SecurityUtils.getUserInfo();
@@ -253,6 +250,9 @@ public class InStoreFormServiceImpl extends BaseServiceImpl<InStoreFormMapper, I
         model.setUserInfo(userInfo);
         model.setStatus(InStoreStatusEnum.EXECUTING.getValue());
         InStoreForm inStoreForm = super.saveModelByDTO(model);
+        //修改库存
+        spareStore.setNum(new BigDecimal(spareStore.getNum().intValue()+model.getInNum()));
+        spareStoreMapper.updateByPrimaryKeySelective(spareStore);
     }
 
     @Override

+ 8 - 7
platform-service/src/main/java/com/platform/service/store/impl/OutStoreFormServiceImpl.java

@@ -55,16 +55,12 @@ public class OutStoreFormServiceImpl extends BaseServiceImpl<OutStoreFormMapper,
     private SparePickDetailMapper sparePickDetailMapper;
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public void spareOutStore(OutStoreFormDTO model) {
         SpareStore spareStore = new SpareStore();
         spareStore.setSpareId(model.getSpareId());
-        List<SpareStore> spareStores = spareStoreMapper.select(spareStore);
-        Integer currentStock=0;
-        for (SpareStore store:spareStores){
-            Integer num = (store.getNum()==null?0:store.getNum().intValue());
-            currentStock+=num;
-        }
-        if (currentStock<model.getOutNum()){
+        spareStore = spareStoreMapper.selectOne(spareStore);
+        if (spareStore.getNum().intValue()<model.getOutNum()){
             throw new BusinessException("库存不足,请修改出库数量!");
         }
         UserInfo userInfo = SecurityUtils.getUserInfo();
@@ -74,8 +70,13 @@ public class OutStoreFormServiceImpl extends BaseServiceImpl<OutStoreFormMapper,
         model.setOutNo(IdGeneratorUtils.getOutStoreNo(++count));
         model.setDelFlag(false);
         model.setUserInfo(userInfo);
+
         model.setStatus(OutStoreStatusEnum.EXECUTING.getValue());
         OutStoreForm outStoreForm = super.saveModelByDTO(model);
+        //修改库存
+        spareStore.setNum(new BigDecimal(spareStore.getNum().intValue()-model.getOutNum()));
+        spareStoreMapper.updateByPrimaryKeySelective(spareStore);
+
 
     }