|
@@ -33,6 +33,7 @@ import com.platform.service.event.WorkplaceBacklogEvent;
|
|
|
import com.platform.service.store.InStoreFormService;
|
|
|
import com.platform.service.store.StoreService;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.boot.autoconfigure.session.StoreType;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -57,6 +58,7 @@ import java.util.stream.Collectors;
|
|
|
*/
|
|
|
@AllArgsConstructor
|
|
|
@Service("inStoreFormService")
|
|
|
+@Slf4j
|
|
|
public class InStoreFormServiceImpl extends BaseServiceImpl<InStoreFormMapper, InStoreForm, InStoreFormDTO> implements InStoreFormService {
|
|
|
private InStoreDetailMapper detailMapper;
|
|
|
private SpareStoreMapper spareStoreMapper;
|
|
@@ -67,6 +69,8 @@ public class InStoreFormServiceImpl extends BaseServiceImpl<InStoreFormMapper, I
|
|
|
private InStoreFormMapper inStoreFormMapper;
|
|
|
private OutStoreFormMapper outStoreFormMapper;
|
|
|
private StoreMapper storeMapper;
|
|
|
+ private PurchaseStoreFormDetailMapper purchaseStoreFormDetailMapper;
|
|
|
+ private PurchaseStoreFormMapper purchaseStoreFormMapper;
|
|
|
|
|
|
|
|
|
@Override
|
|
@@ -549,13 +553,17 @@ public class InStoreFormServiceImpl extends BaseServiceImpl<InStoreFormMapper, I
|
|
|
*/
|
|
|
@Override
|
|
|
public void updateStore(String id) {
|
|
|
+ // 入库单详情
|
|
|
+ UserInfo userInfo = SecurityUtils.getUserInfo();
|
|
|
InStoreForm model = this.getModelById(id);
|
|
|
+ // 采购单入库的路由至新流程
|
|
|
+ if(InStoreTypeEnum.CAIGOU_RUKU.getValue() == model.getType()){
|
|
|
+ handlePurchaseInForm(model,userInfo);
|
|
|
+ return;
|
|
|
+ }
|
|
|
model.setStatus(InStoreStatusEnum.NOT_EXECUTE.getValue());
|
|
|
mapper.updateByPrimaryKey(model);
|
|
|
|
|
|
- // 入库单详情
|
|
|
- UserInfo userInfo = SecurityUtils.getUserInfo();
|
|
|
-
|
|
|
// 找到明细
|
|
|
Weekend<InStoreDetail> detailWeekend = new Weekend<>(InStoreDetail.class);
|
|
|
detailWeekend.weekendCriteria().andEqualTo(InStoreDetail::getInId, model.getId());
|
|
@@ -607,6 +615,69 @@ public class InStoreFormServiceImpl extends BaseServiceImpl<InStoreFormMapper, I
|
|
|
;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 处理采购入库单的入库操作
|
|
|
+ * @param form
|
|
|
+ */
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ void handlePurchaseInForm(InStoreForm form,UserInfo userInfo){
|
|
|
+ PurchaseStoreForm storeForm = new PurchaseStoreForm();
|
|
|
+ storeForm.setId(form.getPurchaseId());
|
|
|
+ storeForm.setUpdateUserName(userInfo.getUsername());
|
|
|
+ storeForm.setUpdateUserId(userInfo.getUserId());
|
|
|
+ storeForm.setUpdateTime(LocalDateTime.now());
|
|
|
+ try{
|
|
|
+ String storeId = form.getStoreId();
|
|
|
+ // 找到入库备件明细
|
|
|
+ Weekend<PurchaseStoreFormDetail> detailWeekend = new Weekend<>(PurchaseStoreFormDetail.class);
|
|
|
+ detailWeekend.weekendCriteria().andEqualTo(PurchaseStoreFormDetail::getPurchaseStoreFormId, form.getPurchaseId()).andEqualTo(PurchaseStoreFormDetail::getDeleteFlag,PurchaseStoreFormDetailDelFlagEnum.NORMAL.getValue());
|
|
|
+ List<PurchaseStoreFormDetail> detailList = purchaseStoreFormDetailMapper.selectByExample(detailWeekend);
|
|
|
+ // 更新库存
|
|
|
+ for (PurchaseStoreFormDetail detail : detailList) {
|
|
|
+ // 更新库存信息
|
|
|
+ Weekend<SpareStore> spareStoreWeekend = new Weekend<>(SpareStore.class);
|
|
|
+ spareStoreWeekend.weekendCriteria().andEqualTo(SpareStore::getSpareId, detail.getSparePartInfoId())
|
|
|
+ .andEqualTo(SpareStore::getStoreId, storeId);
|
|
|
+ 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.getSparePartInfoId());
|
|
|
+ spareStore.setDelFlag(DelFlagEnum.NORMAL.getValue());
|
|
|
+ spareStore.setStoreId(storeId);
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 修改入库单状态
|
|
|
+ InStoreForm updForm = new InStoreForm();
|
|
|
+ updForm.setId(form.getId());
|
|
|
+ updForm.setStatus(InStoreStatusEnum.EXECUTING.getValue());
|
|
|
+ mapper.updateByPrimaryKey(updForm);
|
|
|
+ // 修正采购入库单状态
|
|
|
+ storeForm.setStatus(PurchaseStoreFormStatusEnum.COMPLETED.getValue());
|
|
|
+ }catch (Exception e){
|
|
|
+ log.error("采购入库失败----------------"+e.getCause().getMessage());
|
|
|
+ storeForm.setStatus(PurchaseStoreFormStatusEnum.STORE_FAIL.getValue());
|
|
|
+ }finally {
|
|
|
+ purchaseStoreFormMapper.updateByPrimaryKey(storeForm);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 软件修改后,可以通过新增来处理库存单价和数量不符的情况,首先看看库存数量,若是数量是对的,就入一个为0的数量进去,
|
|
|
* 填上入库单价就行:这里涉及到库存怎么合并单价的问题,
|
|
@@ -626,6 +697,14 @@ public class InStoreFormServiceImpl extends BaseServiceImpl<InStoreFormMapper, I
|
|
|
return price;
|
|
|
}
|
|
|
|
|
|
+ private BigDecimal getNewPrice(SpareStore spareStore, PurchaseStoreFormDetail detail) {
|
|
|
+ BigDecimal totalStorePrice = BigDecimalUtil.mul(spareStore.getPrice(), spareStore.getNum());
|
|
|
+ BigDecimal totalPrice = BigDecimalUtil.add(totalStorePrice, detail.getTotalPrice());
|
|
|
+ BigDecimal totalNum = BigDecimalUtil.add(spareStore.getNum(), detail.getNum());
|
|
|
+ BigDecimal price = BigDecimalUtil.div(totalPrice, totalNum);
|
|
|
+ return price;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public InStoreForm saveModelByBackForm(SpareBackFormDTO sparePickFormDTO, List<SpareBackDetailVO> selectDetailList) {
|
|
|
UserInfo userInfo = SecurityUtils.getUserInfo();
|