3254194295 пре 3 година
родитељ
комит
52f1f2eb08

+ 2 - 2
platform-rest/src/main/java/com/platform/rest/controller/store/InStoreFormController.java

@@ -80,7 +80,7 @@ public class InStoreFormController {
     @PutMapping("/in/{id}")
     @PreAuthorize("@pms.hasPermission('store-in-store-forms-edit')")
     public R updateStore(@PathVariable("id") String id) {
-        inStoreFormService.updateStore(id,false);
+        inStoreFormService.updateStore(id);
         return new R<>();
     }
 
@@ -94,7 +94,7 @@ public class InStoreFormController {
   @PutMapping("/back/{id}")
   @PreAuthorize("@pms.hasPermission('store-in-store-forms-edit')")
   public R updateStore2(@PathVariable("id") String id) {
-    inStoreFormService.updateStore(id,true);
+    inStoreFormService.pasteInStore(id);
     return new R<>();
   }
 

+ 14 - 0
platform-rest/src/main/java/com/platform/rest/controller/store/OutStoreFormController.java

@@ -84,6 +84,20 @@ public class OutStoreFormController {
         return new R<>();
     }
 
+  /**
+   * 撤销出库
+   *
+   * @param id 出库登记单id
+   * @return R
+   */
+  @SysLog("修改出库登记单")
+  @PutMapping("/back/{id}")
+  @PreAuthorize("@pms.hasPermission('store-out-store-forms-edit')")
+  public R update2(@PathVariable("id") String id) {
+    outStoreFormService.pasteOutStore(id);
+    return new R<>();
+  }
+
   /**
    * 通过id删除一条记录
    *

+ 6 - 1
platform-service/src/main/java/com/platform/service/store/InStoreFormService.java

@@ -83,8 +83,13 @@ public interface InStoreFormService extends IBaseService<InStoreForm, InStoreFor
      * @param id
      * @return
      */
-    void updateStore(String id,boolean flag);
+    void updateStore(String id);
 
     InStoreForm saveModelByBackForm(SpareBackFormDTO sparePickFormDTO, List<SpareBackDetailVO> selectDetailList);
     void saveModelByStoreCheckJob(List<StoreCheckJobVO> jobs);
+
+   /**
+    * 撤销入库单
+    */
+   void pasteInStore(String id);
 }

+ 2 - 0
platform-service/src/main/java/com/platform/service/store/OutStoreFormService.java

@@ -63,4 +63,6 @@ public interface OutStoreFormService extends IBaseService<OutStoreForm, OutStore
     void saveModelBySbOil(List<SbOil> sbOils);
 
     void saveModelByStoreCheckJob(List<StoreCheckJobVO> jobs);
+    //撤销出库
+    void pasteOutStore(String id);
 }

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

@@ -360,7 +360,7 @@ public class InStoreFormServiceImpl extends BaseServiceImpl<InStoreFormMapper, I
         ;
         inStoreForm.setTotalPrice(totalPrice);
         mapper.updateByPrimaryKey(inStoreForm);
-        updateStore(inStoreForm.getId(),false);
+        updateStore(inStoreForm.getId());
         return inStoreForm;
     }
 
@@ -396,7 +396,7 @@ public class InStoreFormServiceImpl extends BaseServiceImpl<InStoreFormMapper, I
         }
         ;
         // 更新库存
-        updateStore(inStoreForm.getId(),false);
+        updateStore(inStoreForm.getId());
         return inStoreForm;
     }
 
@@ -524,7 +524,7 @@ public class InStoreFormServiceImpl extends BaseServiceImpl<InStoreFormMapper, I
         }
 
         // 采购验收后,直接入库,并通知仓库负责人
-        this.updateStore(inStoreForm.getId(),false);
+        this.updateStore(inStoreForm.getId());
         SpringContextHolder.publishEvent(new WorkplaceBacklogEvent(WorkplaceBacklogTypeEnum.PURCHASE_WUZI_MESSAGE.getValue(), WorkplaceBacklogDetailTypeEnum.PURCHASE_WUZI_MESSAGE.getValue(),
                 inStoreForm.getId(), MessageTemplateUtil.getPurchaseWuZiInStore(inStoreForm.getId()),
                 inStoreForm.getId(), ListUtils.newArrayList(store.getUserId())));
@@ -542,7 +542,7 @@ public class InStoreFormServiceImpl extends BaseServiceImpl<InStoreFormMapper, I
      * @param id
      */
     @Override
-    public void updateStore(String id,boolean flag) {
+    public void updateStore(String id) {
         // 入库单详情
         UserInfo userInfo = SecurityUtils.getUserInfo();
         InStoreForm model = this.getModelById(id);
@@ -551,11 +551,10 @@ public class InStoreFormServiceImpl extends BaseServiceImpl<InStoreFormMapper, I
             handlePurchaseInForm(model,userInfo);
             return;
         }
-        if(flag){
-            model.setStatus(InStoreStatusEnum.NOT_EXECUTE.getValue());
-        }else{
-            model.setStatus(InStoreStatusEnum.EXECUTING.getValue());
-        }
+
+
+        model.setStatus(InStoreStatusEnum.EXECUTING.getValue());
+
         mapper.updateByPrimaryKey(model);
 
         // 找到明细
@@ -800,9 +799,59 @@ public class InStoreFormServiceImpl extends BaseServiceImpl<InStoreFormMapper, I
         }
         if (!CollectionUtils.isEmpty(formList)) {
             for (InStoreForm form : formList) {
-                updateStore(form.getId(),false);
+                updateStore(form.getId());
             }
         }
 
     }
+
+    @Override
+    public void pasteInStore(String id) {
+        // 入库单详情
+        UserInfo userInfo = SecurityUtils.getUserInfo();
+        InStoreForm model = this.getModelById(id);
+        model.setStatus(InStoreStatusEnum.NOT_EXECUTE.getValue());
+
+        mapper.updateByPrimaryKey(model);
+
+        // 找到明细
+        Weekend<InStoreDetail> detailWeekend = new Weekend<>(InStoreDetail.class);
+        detailWeekend.weekendCriteria().andEqualTo(InStoreDetail::getInId, model.getId());
+        List<InStoreDetail> detailList = detailMapper.selectByExample(detailWeekend);
+
+        // 更新退库状态
+        if (model.getBackId() != null) {
+            SpareBackForm spareBackForm = spareBackFormMapper.selectByPrimaryKey(model.getBackId());
+            spareBackForm.setStatus(SpareBackFormStatusEnum.NOT_EXECUTE.getValue());
+            spareBackFormMapper.updateByPrimaryKeySelective(spareBackForm);
+
+            SpringContextHolder.publishEvent(new WorkplaceBacklogEvent(WorkplaceBacklogTypeEnum.OUT_STORE.getValue(), WorkplaceBacklogDetailTypeEnum.OUT_STORE_FOR_PICK.getValue(),
+                    spareBackForm.getId(), MessageTemplateUtil.getBackStoreFinish(spareBackForm.getId()),
+                    spareBackForm.getId(), ListUtils.newArrayList(spareBackForm.getPickUserId())));
+        }
+
+        //BigDecimal totalNum = new BigDecimal(0);
+        // 更新库存
+        for (InStoreDetail detail : detailList) {
+            // 更新库存信息
+            Weekend<SpareStore> spareStoreWeekend = new Weekend<>(SpareStore.class);
+            spareStoreWeekend.weekendCriteria().andEqualTo(SpareStore::getSpareId, detail.getSpareId())
+                    .andEqualTo(SpareStore::getStoreId, model.getStoreId());
+            SpareStore spareStore = spareStoreMapper.selectOneByExample(spareStoreWeekend);
+            if (ObjectUtil.isNull(spareStore)) {
+                throw new BusinessException("找不到该备件仓库!,备件ID:" + detail.getSpareId() + ",仓库ID:" + detail.getStoreId());
+            } else {
+                BigDecimal rest = spareStore.getNum().subtract(detail.getNum());
+                if (rest.compareTo(new BigDecimal(0)) < 0) {
+                    throw new BusinessException("库存不足,请调整出库数量,或等采购入库!");
+                }
+                spareStore.setNum(rest);
+                spareStore.setUpdateTime(LocalDateTime.now());
+                spareStore.setUpdateUserId(userInfo.getUserId());
+                spareStore.setUpdateUserName(userInfo.getRealName());
+                spareStore.setPrice(getNewPrice(spareStore,detail));
+                spareStoreMapper.updateByPrimaryKeySelective(spareStore);
+            }
+        }
+    }
 }

+ 115 - 46
platform-service/src/main/java/com/platform/service/store/impl/OutStoreFormServiceImpl.java

@@ -18,6 +18,7 @@ import com.platform.dao.mapper.store.*;
 import com.platform.dao.util.MessageTemplateUtil;
 import com.platform.dao.vo.query.store.*;
 import com.platform.service.event.WorkplaceBacklogEvent;
+import com.platform.service.store.InStoreFormService;
 import com.platform.service.store.OutStoreFormService;
 import com.platform.service.store.StoreService;
 import org.springframework.stereotype.Service;
@@ -53,6 +54,8 @@ public class OutStoreFormServiceImpl extends BaseServiceImpl<OutStoreFormMapper,
 
     private SparePickFormMapper sparePickFormMapper;
     private SparePickDetailMapper sparePickDetailMapper;
+    private InStoreFormServiceImpl inStoreFormServiceImpl;
+
     @Override
     public int batchDelete(List<String> ids) {
         //Weekend<OutStoreForm> weekend = new Weekend<>(OutStoreForm.class);
@@ -80,9 +83,9 @@ public class OutStoreFormServiceImpl extends BaseServiceImpl<OutStoreFormMapper,
     public OutStoreFormVO getDetail(Object id) {
         OutStoreForm outStoreForm = this.getModelById(id);
         OutStoreFormVO outStoreFormVO = new OutStoreFormVO();
-        BeanConverterUtil.copyObjectProperties(outStoreForm,outStoreFormVO);
+        BeanConverterUtil.copyObjectProperties(outStoreForm, outStoreFormVO);
         // 详情列表
-        if(StringUtils.isNotBlank(outStoreForm.getStoreId())){
+        if (StringUtils.isNotBlank(outStoreForm.getStoreId())) {
             Store store = storeService.getModelById(outStoreForm.getStoreId());
             outStoreFormVO.setStoreName(store.getName());
         }
@@ -107,6 +110,7 @@ public class OutStoreFormServiceImpl extends BaseServiceImpl<OutStoreFormMapper,
 
     /**
      * 只有未出库状态才可以删除,不需要回滚
+     *
      * @param id :
      * @return
      */
@@ -114,7 +118,7 @@ public class OutStoreFormServiceImpl extends BaseServiceImpl<OutStoreFormMapper,
     @Transactional(rollbackFor = Exception.class)
     public boolean cascadingDeleteByKey(String id) {
         OutStoreForm form = mapper.selectByPrimaryKey(id);
-        if( form.getStatus()!=null && (form.getStatus().intValue() == OutStoreStatusEnum.EXECUTING.getValue())){
+        if (form.getStatus() != null && (form.getStatus().intValue() == OutStoreStatusEnum.EXECUTING.getValue())) {
             throw new BusinessException("已出库的不可以删除,出库单id:" + form.getId());
         }
         // 刪除出库单
@@ -122,7 +126,7 @@ public class OutStoreFormServiceImpl extends BaseServiceImpl<OutStoreFormMapper,
         UserInfo userInfo = SecurityUtils.getUserInfo();
 
         // 刪除详情,更新详情涉及的库存
-        if(result == 1){
+        if (result == 1) {
             Weekend<OutStoreDetail> detailWeekend = new Weekend<>(OutStoreDetail.class);
             detailWeekend.weekendCriteria().andEqualTo(OutStoreDetail::getOutId, id);
             List<OutStoreDetail> detailList = detailMapper.selectByExample(detailWeekend);
@@ -159,24 +163,24 @@ public class OutStoreFormServiceImpl extends BaseServiceImpl<OutStoreFormMapper,
         BigDecimal totalPrice = new BigDecimal(0);
 
         // 判断备件是否在该仓库里面,出库单已经勾选了仓库。这个不允许了,pc和移动端都不允许
-        for(OutStoreDetailDTO detail:detailList) {
+        for (OutStoreDetailDTO detail : detailList) {
             SpareStore spareStore = new SpareStore();
-            if(StringUtils.isNotBlank(model.getStoreId())){
+            if (StringUtils.isNotBlank(model.getStoreId())) {
                 spareStore.setStoreId(model.getStoreId());
-            }else{
+            } else {
                 spareStore.setStoreId(detail.getStoreId());
             }
             spareStore.setSpareId(detail.getSpareId());
             List<SpareStore> spareStoreList = spareStoreMapper.select(spareStore);
-            if(spareStoreList == null || spareStoreList.size() == 0){
+            if (spareStoreList == null || spareStoreList.size() == 0) {
                 throw new BusinessException("该仓库中没有此备件,请检查");
             }
         }
         // 插
-        for(OutStoreDetailDTO detail:detailList) {
+        for (OutStoreDetailDTO detail : detailList) {
             detail.setUserInfo(userInfo);
             detail.setOutId(outStoreForm.getId());
-            if(StringUtils.isNotBlank(model.getStoreId())){
+            if (StringUtils.isNotBlank(model.getStoreId())) {
                 detail.setStoreId(model.getStoreId());
             }
             // detail.setStoreId(outStoreForm.getStoreId());
@@ -190,7 +194,8 @@ public class OutStoreFormServiceImpl extends BaseServiceImpl<OutStoreFormMapper,
             storeDetail.setId(IdGeneratorUtils.getObjectId());
             detailMapper.insertSelective(storeDetail);
 
-        };
+        }
+        ;
         outStoreForm.setTotalPrice(totalPrice);
         mapper.updateByPrimaryKey(outStoreForm);
         updateStore(outStoreForm.getId());
@@ -208,7 +213,7 @@ public class OutStoreFormServiceImpl extends BaseServiceImpl<OutStoreFormMapper,
     public void updateStore(String outStoreFormId) {
 
         OutStoreForm outStoreForm = this.getModelById(outStoreFormId);
-        outStoreForm.setStatus(OutStoreStatusEnum.NOT_EXECUTE.getValue());
+        outStoreForm.setStatus(OutStoreStatusEnum.EXECUTING.getValue());
         mapper.updateByPrimaryKey(outStoreForm);
 
         Weekend<OutStoreDetail> detailWeekend = new Weekend<>(OutStoreDetail.class);
@@ -217,13 +222,12 @@ public class OutStoreFormServiceImpl extends BaseServiceImpl<OutStoreFormMapper,
         UserInfo userInfo = SecurityUtils.getUserInfo();
 
         // 更新领用单状态
-        if( outStoreForm.getPickId() != null && outStoreForm.getType().equals(OutStoreTypeEnum.CHUKU_LINGYONG.getValue()) ){
+        if (outStoreForm.getPickId() != null && outStoreForm.getType().equals(OutStoreTypeEnum.CHUKU_LINGYONG.getValue())) {
             SparePickForm sparePickForm = sparePickFormMapper.selectByPrimaryKey(outStoreForm.getPickId());
             sparePickForm.setStatus(SparePickFormStatusEnum.FINISHED.getValue());
             sparePickFormMapper.updateByPrimaryKeySelective(sparePickForm);
-
             // 发送通知给领用人
-            SpringContextHolder.publishEvent(new WorkplaceBacklogEvent( WorkplaceBacklogTypeEnum.SPARE_PICK.getValue(), WorkplaceBacklogDetailTypeEnum.SPARE_PICK.getValue(),
+            SpringContextHolder.publishEvent(new WorkplaceBacklogEvent(WorkplaceBacklogTypeEnum.SPARE_PICK.getValue(), WorkplaceBacklogDetailTypeEnum.SPARE_PICK.getValue(),
                     sparePickForm.getId(), MessageTemplateUtil.getSparePickFinish(sparePickForm.getId()),
                     sparePickForm.getId(), ListUtils.newArrayList(sparePickForm.getPickUserId())));
         }
@@ -237,7 +241,7 @@ public class OutStoreFormServiceImpl extends BaseServiceImpl<OutStoreFormMapper,
                     .andEqualTo(SpareStore::getStoreId, storeDetail.getStoreId());
             SpareStore spareStore = spareStoreMapper.selectOneByExample(spareStoreWeekend);
             if (ObjectUtil.isNull(spareStore)) {
-                throw new BusinessException("找不到该备件仓库!,备件ID:"+storeDetail.getSpareId()+",仓库ID:"+storeDetail.getStoreId());
+                throw new BusinessException("找不到该备件仓库!,备件ID:" + storeDetail.getSpareId() + ",仓库ID:" + storeDetail.getStoreId());
             } else {
                 BigDecimal rest = spareStore.getNum().subtract(storeDetail.getNum());
                 if (rest.compareTo(new BigDecimal(0)) < 0) {
@@ -265,13 +269,13 @@ public class OutStoreFormServiceImpl extends BaseServiceImpl<OutStoreFormMapper,
 
         // 获取领用单详情
         SparePickForm sparePickForm = null;
-        if(model.getType().equals(OutStoreTypeEnum.CHUKU_LINGYONG.getValue())){
+        if (model.getType().equals(OutStoreTypeEnum.CHUKU_LINGYONG.getValue())) {
             sparePickForm = sparePickFormMapper.selectByPrimaryKey(model.getPickId());
         }
         BigDecimal totalPrice = new BigDecimal(0);
 
         // 插
-        for(OutStoreDetailDTO detail:detailList) {
+        for (OutStoreDetailDTO detail : detailList) {
             model.setCreatedUserId("1");
             detail.setOutId(outStoreForm.getId());
             detail.setStoreId(outStoreForm.getStoreId());
@@ -284,7 +288,8 @@ public class OutStoreFormServiceImpl extends BaseServiceImpl<OutStoreFormMapper,
             storeDetail.setId(IdGeneratorUtils.getObjectId());
             detailMapper.insertSelective(storeDetail);
 
-        };
+        }
+        ;
         // 更新库存
         updateStore(outStoreForm.getId());
     }
@@ -302,16 +307,16 @@ public class OutStoreFormServiceImpl extends BaseServiceImpl<OutStoreFormMapper,
         List<OutStoreDetailDTO> detailList = model.getDetailList();
 
         // 判断备件是否在该仓库里面,出库单已经勾选了仓库。这个不允许了,pc和移动端都不允许
-        for(OutStoreDetailDTO detail:detailList) {
+        for (OutStoreDetailDTO detail : detailList) {
             SpareStore spareStore = new SpareStore();
-            if(StringUtils.isNotBlank(model.getStoreId())){
+            if (StringUtils.isNotBlank(model.getStoreId())) {
                 spareStore.setStoreId(model.getStoreId());
-            }else{
+            } else {
                 spareStore.setStoreId(detail.getStoreId());
             }
             spareStore.setSpareId(detail.getSpareId());
             List<SpareStore> spareStoreList = spareStoreMapper.select(spareStore);
-            if(spareStoreList == null || spareStoreList.size() == 0){
+            if (spareStoreList == null || spareStoreList.size() == 0) {
                 throw new BusinessException("该仓库中没有此备件,请检查");
             }
         }
@@ -327,19 +332,19 @@ public class OutStoreFormServiceImpl extends BaseServiceImpl<OutStoreFormMapper,
         List<OutStoreDetail> addDetailList = new ArrayList<OutStoreDetail>();
         // 详情
         SparePickForm sparePickForm = null;
-        if(model.getType().equals(OutStoreTypeEnum.CHUKU_LINGYONG.getValue())){
+        if (model.getType().equals(OutStoreTypeEnum.CHUKU_LINGYONG.getValue())) {
             sparePickForm = sparePickFormMapper.selectByPrimaryKey(model.getPickId());
         }
         SparePickForm finalSparePickForm = sparePickForm;
 
         BigDecimal totalPrice = new BigDecimal(0);
         // 新增
-        for(OutStoreDetailDTO detail:detailList) {
+        for (OutStoreDetailDTO detail : detailList) {
             OutStoreDetail realDetail = detailMapper.selectByPrimaryKey(detail.getId());
-            if(ObjectUtil.isNull(realDetail)){
+            if (ObjectUtil.isNull(realDetail)) {
                 detail.setUserInfo(userInfo);
                 detail.setOutId(model.getId());
-                if(StringUtils.isNotBlank(model.getStoreId())){
+                if (StringUtils.isNotBlank(model.getStoreId())) {
                     detail.setStoreId(model.getStoreId());
                 }
                 //detail.setStoreId(model.getStoreId());
@@ -350,19 +355,20 @@ public class OutStoreFormServiceImpl extends BaseServiceImpl<OutStoreFormMapper,
                 BeanConverterUtil.copyObjectProperties(detail, storeDetail);
                 storeDetail.setId(IdGeneratorUtils.getObjectId());
                 addDetailList.add(storeDetail);
-            }else{// 修改数量的
+            } else {// 修改数量的
                 detail.setTotalPrice(detail.getNum().multiply(detail.getPrice()));
                 totalPrice = totalPrice.add(detail.getTotalPrice());
                 OutStoreDetail storeDetail = new OutStoreDetail();
                 BeanConverterUtil.copyObjectProperties(detail, storeDetail);
                 updateDetailList.add(storeDetail);
             }
-        };
+        }
+        ;
 
-        if(!CollectionUtils.isEmpty(addDetailList)){
+        if (!CollectionUtils.isEmpty(addDetailList)) {
             detailMapper.insertListforComplex(addDetailList);
         }
-        if(!CollectionUtils.isEmpty(updateDetailList)){
+        if (!CollectionUtils.isEmpty(updateDetailList)) {
             detailMapper.updateBatch(updateDetailList);
         }
         // 更新
@@ -394,22 +400,22 @@ public class OutStoreFormServiceImpl extends BaseServiceImpl<OutStoreFormMapper,
         model.setDelFlag(false);
         model.setUserInfo(userInfo);
 
-        Store store =  storeService.getModelById(sparePickFormDTO.getStoreId());
+        Store store = storeService.getModelById(sparePickFormDTO.getStoreId());
         model.setCreatedUserId(store.getUserId());
         model.setType(OutStoreTypeEnum.CHUKU_LINGYONG.getValue());
         model.setStatus(OutStoreStatusEnum.NOT_EXECUTE.getValue());
         model.setRemark(sparePickFormDTO.getRemark());
         OutStoreForm form = super.saveModelByDTO(model);
         List<OutStoreDetail> detailList = new ArrayList<OutStoreDetail>();
-        pickDetailList.forEach(pickDetail->{
+        pickDetailList.forEach(pickDetail -> {
             OutStoreDetail detail = new OutStoreDetail();
             detail.setId(IdGeneratorUtils.getObjectId());
             detail.setCreatedTime(pickDetail.getCreatedTime());
             detail.setNum(pickDetail.getNum());
             detail.setPrice(pickDetail.getPrice());
-            if(pickDetail.getTotalPrice() == null){
-                detail.setTotalPrice(BigDecimalUtil.mul(pickDetail.getNum(),pickDetail.getPrice()));
-            }else{
+            if (pickDetail.getTotalPrice() == null) {
+                detail.setTotalPrice(BigDecimalUtil.mul(pickDetail.getNum(), pickDetail.getPrice()));
+            } else {
                 detail.setTotalPrice(pickDetail.getTotalPrice());
             }
             detail.setSpareId(pickDetail.getSpareId());
@@ -420,7 +426,7 @@ public class OutStoreFormServiceImpl extends BaseServiceImpl<OutStoreFormMapper,
         });
         detailMapper.insertListforComplex(detailList);
 
-        SpringContextHolder.publishEvent(new WorkplaceBacklogEvent( WorkplaceBacklogTypeEnum.OUT_STORE.getValue(), WorkplaceBacklogDetailTypeEnum.OUT_STORE_FOR_PICK.getValue(),
+        SpringContextHolder.publishEvent(new WorkplaceBacklogEvent(WorkplaceBacklogTypeEnum.OUT_STORE.getValue(), WorkplaceBacklogDetailTypeEnum.OUT_STORE_FOR_PICK.getValue(),
                 form.getId(), MessageTemplateUtil.getOutStoreForSparePick(form.getId()),
                 form.getId(), ListUtils.newArrayList(store.getUserId())));
         return form;
@@ -436,7 +442,7 @@ public class OutStoreFormServiceImpl extends BaseServiceImpl<OutStoreFormMapper,
     public void saveModelBySbOil(List<SbOil> sbOils) {
         UserInfo userInfo = SecurityUtils.getUserInfo();
         List<OutStoreDetail> detailList = new ArrayList<OutStoreDetail>();
-        for(SbOil oil:sbOils){
+        for (SbOil oil : sbOils) {
             // 出库单
             Weekend<OutStoreForm> weekend = new Weekend<>(OutStoreForm.class);
             weekend.weekendCriteria().andIsNotNull(OutStoreForm::getId);
@@ -445,11 +451,11 @@ public class OutStoreFormServiceImpl extends BaseServiceImpl<OutStoreFormMapper,
             model.setPickId(oil.getId());
             model.setStoreId(oil.getStoreId());
             SpareStore spareStore = spareStoreMapper.selectByPrimaryKey(oil.getSpareStoreId());
-            if(spareStore == null){
+            if (spareStore == null) {
                 throw new BusinessException("找不到仓库备件,spareStoreId:" + oil.getSpareStoreId());
             }
             model.setCreatedTime(oil.getCreatedTime());
-            model.setTotalPrice(BigDecimalUtil.mul(spareStore.getPrice()== null?new BigDecimal(0):spareStore.getPrice(), oil.getRealOil()));
+            model.setTotalPrice(BigDecimalUtil.mul(spareStore.getPrice() == null ? new BigDecimal(0) : spareStore.getPrice(), oil.getRealOil()));
             model.setOutNo(IdGeneratorUtils.getOutStoreNo(++count));
             model.setDelFlag(false);
             model.setUserInfo(userInfo);
@@ -483,7 +489,7 @@ public class OutStoreFormServiceImpl extends BaseServiceImpl<OutStoreFormMapper,
                     .andEqualTo(SpareStore::getStoreId, storeDetail.getStoreId());
             SpareStore spareStore = spareStoreMapper.selectOneByExample(spareStoreWeekend);
             if (ObjectUtil.isNull(spareStore)) {
-                throw new BusinessException("找不到该备件仓库!,备件ID:"+storeDetail.getSpareId()+",仓库ID:"+storeDetail.getStoreId());
+                throw new BusinessException("找不到该备件仓库!,备件ID:" + storeDetail.getSpareId() + ",仓库ID:" + storeDetail.getStoreId());
             } else {
                 BigDecimal rest = spareStore.getNum().subtract(storeDetail.getNum());
                 if (rest.compareTo(new BigDecimal(0)) < 0) {
@@ -510,7 +516,7 @@ public class OutStoreFormServiceImpl extends BaseServiceImpl<OutStoreFormMapper,
         List<OutStoreDetail> detailList = new ArrayList<OutStoreDetail>();
         List<OutStoreForm> formList = new ArrayList<OutStoreForm>();
         LocalDateTime now = LocalDateTime.now();
-        for(StoreCheckJobVO job:jobs){
+        for (StoreCheckJobVO job : jobs) {
             // 出库单
             Weekend<OutStoreForm> weekend = new Weekend<>(OutStoreForm.class);
             weekend.weekendCriteria().andIsNotNull(OutStoreForm::getId);
@@ -519,11 +525,11 @@ public class OutStoreFormServiceImpl extends BaseServiceImpl<OutStoreFormMapper,
             model.setPickId(job.getId());
             model.setStoreId(job.getStoreId());
             SpareStore spareStore = spareStoreMapper.selectByPrimaryKey(job.getSpareStoreId());
-            if(spareStore == null){
+            if (spareStore == null) {
                 throw new BusinessException("找不到仓库备件,spareStoreId:" + job.getSpareStoreId());
             }
             model.setCreatedTime(now);
-            BigDecimal adjustNum = BigDecimalUtil.div(job.getCheckNum(),job.getRealNum());
+            BigDecimal adjustNum = BigDecimalUtil.div(job.getCheckNum(), job.getRealNum());
             model.setTotalPrice(job.getProfitPrice());
             model.setOutNo(IdGeneratorUtils.getOutStoreNo(++count));
             model.setDelFlag(false);
@@ -549,8 +555,8 @@ public class OutStoreFormServiceImpl extends BaseServiceImpl<OutStoreFormMapper,
             formList.add(form);
         }
         detailMapper.insertListforComplex(detailList);
-        if(!CollectionUtils.isEmpty(formList)){
-            for(OutStoreForm form: formList){
+        if (!CollectionUtils.isEmpty(formList)) {
+            for (OutStoreForm form : formList) {
                 updateStore(form.getId());
             }
         }
@@ -577,4 +583,67 @@ public class OutStoreFormServiceImpl extends BaseServiceImpl<OutStoreFormMapper,
             }
         });*/
     }
+
+    @Override
+    public void pasteOutStore(String id) {
+        OutStoreForm outStoreForm = this.getModelById(id);
+        outStoreForm.setStatus(OutStoreStatusEnum.NOT_EXECUTE.getValue());
+        mapper.updateByPrimaryKey(outStoreForm);
+
+        Weekend<OutStoreDetail> detailWeekend = new Weekend<>(OutStoreDetail.class);
+        detailWeekend.weekendCriteria().andEqualTo(OutStoreDetail::getOutId, id);
+        List<OutStoreDetail> detailList = detailMapper.selectByExample(detailWeekend);
+        UserInfo userInfo = SecurityUtils.getUserInfo();
+
+        // 更新领用单状态
+        if (outStoreForm.getPickId() != null && outStoreForm.getType().equals(OutStoreTypeEnum.CHUKU_LINGYONG.getValue())) {
+            SparePickForm sparePickForm = sparePickFormMapper.selectByPrimaryKey(outStoreForm.getPickId());
+            sparePickForm.setStatus(SparePickFormStatusEnum.NOT_EXECUTE.getValue());
+            sparePickFormMapper.updateByPrimaryKeySelective(sparePickForm);
+            // 发送通知给领用人
+            SpringContextHolder.publishEvent(new WorkplaceBacklogEvent(WorkplaceBacklogTypeEnum.BACK_STORE.getValue(), WorkplaceBacklogDetailTypeEnum.BACK_STORE.getValue(),
+                    sparePickForm.getId(), MessageTemplateUtil.getSparePickFinish(sparePickForm.getId()),
+                    sparePickForm.getId(), ListUtils.newArrayList(sparePickForm.getPickUserId())));
+        }
+
+        for (OutStoreDetail detail : detailList) {
+            // 更新库存信息
+            Weekend<SpareStore> spareStoreWeekend = new Weekend<>(SpareStore.class);
+            spareStoreWeekend.weekendCriteria().andEqualTo(SpareStore::getSpareId, detail.getSpareId())
+                    .andEqualTo(SpareStore::getStoreId, detail.getStoreId());
+            SpareStore spareStore = spareStoreMapper.selectOneByExample(spareStoreWeekend);
+            if (ObjectUtil.isNull(spareStore)) {
+                spareStore = new SpareStore();
+                spareStore.setCreatedUserId(userInfo.getUserId());
+                spareStore.setCreatedUserName(userInfo.getRealName());
+                spareStore.setCreatedTime(LocalDateTime.now());
+                spareStore.setId(IdGeneratorUtils.getObjectId());
+                spareStore.setNum(detail.getNum());
+                spareStore.setSpareId(detail.getSpareId());
+                spareStore.setDelFlag(DelFlagEnum.NORMAL.getValue());
+                spareStore.setStoreId(detail.getStoreId());
+                spareStore.setPrice(detail.getPrice());
+                spareStore.setInitPrice(detail.getPrice());
+                spareStore.setInitPurchasePrice(detail.getPrice());
+                spareStoreMapper.insertSelective(spareStore);
+            } else {
+                // 重新计算商品库存价格
+                spareStore.setUpdateTime(LocalDateTime.now());
+                spareStore.setUpdateUserId(userInfo.getUserId());
+                spareStore.setUpdateUserName(userInfo.getRealName());
+                spareStore.setPrice(getNewPrice(spareStore, detail));
+                spareStore.setNum(BigDecimalUtil.add(spareStore.getNum(), detail.getNum()));
+                spareStoreMapper.updateByPrimaryKeySelective(spareStore);
+            }
+        }
+    }
+
+    private BigDecimal getNewPrice(SpareStore spareStore, OutStoreDetail detail) {
+        BigDecimal totalStorePrice = BigDecimalUtil.mul(spareStore.getPrice(), spareStore.getNum());
+        BigDecimal totalInPrice = BigDecimalUtil.mul(detail.getPrice(), detail.getNum());
+        BigDecimal totalPrice = BigDecimalUtil.add(totalStorePrice, totalInPrice);
+        BigDecimal totalNum = BigDecimalUtil.add(spareStore.getNum(), detail.getNum());
+        BigDecimal price = BigDecimalUtil.div(totalPrice, totalNum);
+        return price;
+    }
 }