|
@@ -5,25 +5,28 @@ import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fjhx.common.utils.Assert;
|
|
|
import com.fjhx.item.entity.product.po.ProductInfo;
|
|
|
import com.fjhx.item.service.product.ProductInfoService;
|
|
|
import com.fjhx.wms.entity.stock.dto.StockWaitDetailsDto;
|
|
|
import com.fjhx.wms.entity.stock.dto.StockWaitDetailsSelectDto;
|
|
|
-import com.fjhx.wms.entity.stock.emums.StockWaitType;
|
|
|
-import com.fjhx.wms.entity.stock.po.*;
|
|
|
+import com.fjhx.wms.entity.stock.dto.StockWaitDto;
|
|
|
+import com.fjhx.wms.entity.stock.po.StockWait;
|
|
|
+import com.fjhx.wms.entity.stock.po.StockWaitDetails;
|
|
|
import com.fjhx.wms.entity.stock.vo.StockWaitDetailsVo;
|
|
|
import com.fjhx.wms.mapper.stock.StockWaitDetailsMapper;
|
|
|
-import com.fjhx.wms.service.WmsService;
|
|
|
-import com.fjhx.wms.service.stock.*;
|
|
|
-import com.fjhx.wms.utils.CodeEnum;
|
|
|
+import com.fjhx.wms.service.stock.StockWaitDetailsService;
|
|
|
+import com.fjhx.wms.service.stock.StockWaitService;
|
|
|
import com.obs.services.internal.ServiceException;
|
|
|
import com.ruoyi.common.utils.wrapper.IWrapper;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
-import java.util.Arrays;
|
|
|
+import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -40,16 +43,16 @@ public class StockWaitDetailsServiceImpl extends ServiceImpl<StockWaitDetailsMap
|
|
|
private ProductInfoService productInfoService;
|
|
|
@Autowired
|
|
|
private StockWaitService stockWaitService;
|
|
|
- @Autowired
|
|
|
- private StockJournalService stockJournalService;
|
|
|
- @Autowired
|
|
|
- private StockJournalDetailsService stockJournalDetailsService;
|
|
|
- @Autowired
|
|
|
- private StockService stockService;
|
|
|
- @Autowired
|
|
|
- private WmsService wmsService;
|
|
|
- @Autowired
|
|
|
- private StockFrozenService stockFrozenService;
|
|
|
+// @Autowired
|
|
|
+// private StockJournalService stockJournalService;
|
|
|
+// @Autowired
|
|
|
+// private StockJournalDetailsService stockJournalDetailsService;
|
|
|
+// @Autowired
|
|
|
+// private StockService stockService;
|
|
|
+// @Autowired
|
|
|
+// private WmsService wmsService;
|
|
|
+// @Autowired
|
|
|
+// private StockFrozenService stockFrozenService;
|
|
|
|
|
|
@Override
|
|
|
public Page<StockWaitDetailsVo> getPage(StockWaitDetailsSelectDto dto) {
|
|
@@ -92,7 +95,6 @@ public class StockWaitDetailsServiceImpl extends ServiceImpl<StockWaitDetailsMap
|
|
|
}
|
|
|
result.setBusinessType(stockWait.getBusinessType());
|
|
|
result.setBusinessCode(stockWait.getBusinessCode());
|
|
|
- ;
|
|
|
ProductInfo byId = productInfoService.getById(StockWaitDetails.getProductId());
|
|
|
if (ObjectUtil.isEmpty(byId)) {
|
|
|
throw new ServiceException("无法查询到产品信息,产品id" + StockWaitDetails.getProductId());
|
|
@@ -104,42 +106,50 @@ public class StockWaitDetailsServiceImpl extends ServiceImpl<StockWaitDetailsMap
|
|
|
@Override
|
|
|
@DSTransactional
|
|
|
public void add(StockWaitDetailsDto stockWaitDetailsDto) {
|
|
|
- //修改待出库状态
|
|
|
- changeStockWaitStatus(stockWaitDetailsDto);
|
|
|
- StockWaitDetails stockWaitDetails = getById(stockWaitDetailsDto.getId());
|
|
|
- StockWait byId = stockWaitService.getById(stockWaitDetails.getStockWaitId());
|
|
|
- Integer businessType = byId.getBusinessType();
|
|
|
-
|
|
|
- if (StockWaitType.SALE_ORDER_OUT.getDetailType().equals(businessType)) {
|
|
|
- //销售订单出库
|
|
|
- wmsService.outbound(stockWaitDetailsDto);
|
|
|
- }
|
|
|
- if (StockWaitType.PRODUCTION_TASK_OUT.getDetailType().equals(businessType)) {
|
|
|
- //生产任务待出库
|
|
|
- //减少冻结库存
|
|
|
- StockFrozen stockFrozen = stockFrozenService.getOne(q -> q.eq(StockFrozen::getProductId, stockWaitDetails.getProductId()));
|
|
|
- BigDecimal subtract = stockFrozen.getFrozenQuantity().subtract(stockWaitDetailsDto.getQuantity());
|
|
|
- stockFrozen.setFrozenQuantity(subtract);
|
|
|
- stockFrozenService.updateById(stockFrozen);
|
|
|
- }
|
|
|
+// //修改待出库状态
|
|
|
+// changeStockWaitStatus(stockWaitDetailsDto);
|
|
|
+// StockWaitDetails stockWaitDetails = getById(stockWaitDetailsDto.getId());
|
|
|
+// StockWait byId = stockWaitService.getById(stockWaitDetails.getStockWaitId());
|
|
|
+// Integer businessType = byId.getBusinessType();
|
|
|
+//
|
|
|
+// if (StockWaitType.SALE_ORDER_OUT.getDetailType().equals(businessType)) {
|
|
|
+// //销售订单出库
|
|
|
+// wmsService.outbound(stockWaitDetailsDto);
|
|
|
+// }
|
|
|
+// if (StockWaitType.PRODUCTION_TASK_OUT.getDetailType().equals(businessType)) {
|
|
|
+// //生产任务待出库
|
|
|
+// //减少冻结库存
|
|
|
+// StockFrozen stockFrozen = stockFrozenService.getOne(q -> q.eq(StockFrozen::getProductId, stockWaitDetails.getProductId()));
|
|
|
+// BigDecimal subtract = stockFrozen.getFrozenQuantity().subtract(stockWaitDetailsDto.getQuantity());
|
|
|
+// stockFrozen.setFrozenQuantity(subtract);
|
|
|
+// stockFrozenService.updateById(stockFrozen);
|
|
|
+// }
|
|
|
+//
|
|
|
+// //创建出入库记录
|
|
|
+// StockJournal stockJournal = new StockJournal();
|
|
|
+// stockJournal.setOpType(byId.getType());
|
|
|
+// //根据待入库业务类型创建待出入库记录
|
|
|
+// stockJournal.setType(stockWaitService.getStockJournalType(businessType));
|
|
|
+// stockJournal.setCode(byId.getType() == 1 ? CodeEnum.SIN_CODE.getCode() : CodeEnum.SOUT_CODE.getCode());
|
|
|
+// stockJournal.setWarehouseId(stockWaitDetailsDto.getWarehouseId());
|
|
|
+// stockJournal.setBusinessId(byId.getId());
|
|
|
+// //保存出入库记录
|
|
|
+// stockJournalService.save(stockJournal);
|
|
|
+// //操作库存
|
|
|
+// Stock stock = new Stock();
|
|
|
+// stock.setQuantity(stockWaitDetailsDto.getQuantity());
|
|
|
+// stock.setProductId(stockWaitDetails.getProductId());
|
|
|
+// List<StockJournalDetails> stockJournalDetailsList = stockService.ModifyInventory(stockJournal.getId(), byId.getType(), Arrays.asList(stock), stockWaitDetailsDto.getWarehouseId());
|
|
|
+// //保存出入库明细
|
|
|
+// stockJournalDetailsService.saveBatch(stockJournalDetailsList);
|
|
|
|
|
|
- //创建出入库记录
|
|
|
- StockJournal stockJournal = new StockJournal();
|
|
|
- stockJournal.setOpType(byId.getType());
|
|
|
- //根据待入库业务类型创建待出入库记录
|
|
|
- stockJournal.setType(stockWaitService.getStockJournalType(businessType));
|
|
|
- stockJournal.setCode(byId.getType() == 1 ? CodeEnum.SIN_CODE.getCode() : CodeEnum.SOUT_CODE.getCode());
|
|
|
- stockJournal.setWarehouseId(stockWaitDetailsDto.getWarehouseId());
|
|
|
- stockJournal.setBusinessId(byId.getId());
|
|
|
- //保存出入库记录
|
|
|
- stockJournalService.save(stockJournal);
|
|
|
- //操作库存
|
|
|
- Stock stock = new Stock();
|
|
|
- stock.setQuantity(stockWaitDetailsDto.getQuantity());
|
|
|
- stock.setProductId(stockWaitDetails.getProductId());
|
|
|
- List<StockJournalDetails> stockJournalDetailsList = stockService.ModifyInventory(stockJournal.getId(), byId.getType(), Arrays.asList(stock), stockWaitDetailsDto.getWarehouseId());
|
|
|
- //保存出入库明细
|
|
|
- stockJournalDetailsService.saveBatch(stockJournalDetailsList);
|
|
|
+ //优化
|
|
|
+ StockWaitDetails stockWaitDetails = this.getById(stockWaitDetailsDto.getId());
|
|
|
+ Assert.notEmpty(stockWaitDetails, "查询不到待出库明细信息");
|
|
|
+ StockWaitDto stockWaitDto = BeanUtil.copyProperties(stockWaitDetailsDto, StockWaitDto.class);
|
|
|
+ stockWaitDto.setId(stockWaitDetails.getStockWaitId());
|
|
|
+ stockWaitDto.setStockWaitDetailsList(Collections.singletonList(BeanUtil.copyProperties(stockWaitDetailsDto, StockWaitDetails.class)));
|
|
|
+ stockWaitService.addByWdly(stockWaitDto);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -147,22 +157,32 @@ public class StockWaitDetailsServiceImpl extends ServiceImpl<StockWaitDetailsMap
|
|
|
* 更新待出入库状态
|
|
|
*/
|
|
|
@Override
|
|
|
- public void changeStockWaitStatus(StockWaitDetailsDto stockWaitDetailsDto) {
|
|
|
- //更新已入库数量 根据明细id
|
|
|
- StockWaitDetails stockWaitDetails = getById(stockWaitDetailsDto.getId());
|
|
|
- if (ObjectUtil.isEmpty(stockWaitDetails)) {
|
|
|
- throw new ServiceException("无法查询到明细信息");
|
|
|
- }
|
|
|
- BigDecimal receiptQuantity = stockWaitDetails.getReceiptQuantity();
|
|
|
- receiptQuantity = ObjectUtil.isEmpty(receiptQuantity) ? BigDecimal.ZERO : receiptQuantity;
|
|
|
- stockWaitDetails.setReceiptQuantity(receiptQuantity.add(stockWaitDetailsDto.getQuantity()));
|
|
|
- if (stockWaitDetails.getReceiptQuantity().compareTo(stockWaitDetails.getQuantity()) > 0) {
|
|
|
- throw new ServiceException("出库数量+已出库数量不能大于待出库数量");
|
|
|
+ public void changeStockWaitStatus(StockWaitDto stockWaitDto) {
|
|
|
+ List<StockWaitDetails> stockWaitDetailsDtoList = stockWaitDto.getStockWaitDetailsList();
|
|
|
+ List<StockWaitDetailsDto> stockWaitDetailsDtoList1 = BeanUtil.copyToList(stockWaitDetailsDtoList, StockWaitDetailsDto.class);
|
|
|
+
|
|
|
+ //获取待入库明细信息
|
|
|
+ List<Long> swdIds = stockWaitDetailsDtoList.stream().map(StockWaitDetails::getId).collect(Collectors.toList());
|
|
|
+ Map<Long, StockWaitDetails> stockWaitDetailsMap = this.mapKEntity(StockWaitDetails::getId, q -> q.in(StockWaitDetails::getId, swdIds));
|
|
|
+
|
|
|
+ for (StockWaitDetailsDto stockWaitDetailsDto : stockWaitDetailsDtoList1) {
|
|
|
+ //更新已入库数量 根据明细id
|
|
|
+ StockWaitDetails stockWaitDetails = stockWaitDetailsMap.get(stockWaitDetailsDto.getId());
|
|
|
+ if (ObjectUtil.isEmpty(stockWaitDetails)) {
|
|
|
+ throw new ServiceException("无法查询到明细信息");
|
|
|
+ }
|
|
|
+ BigDecimal receiptQuantity = stockWaitDetails.getReceiptQuantity();
|
|
|
+ receiptQuantity = ObjectUtil.isEmpty(receiptQuantity) ? BigDecimal.ZERO : receiptQuantity;
|
|
|
+ stockWaitDetails.setReceiptQuantity(receiptQuantity.add(stockWaitDetailsDto.getQuantity()));
|
|
|
+ if (stockWaitDetails.getReceiptQuantity().compareTo(stockWaitDetails.getQuantity()) > 0) {
|
|
|
+ throw new ServiceException("出库数量+已出库数量不能大于待出库数量");
|
|
|
+ }
|
|
|
+ updateById(stockWaitDetails);
|
|
|
}
|
|
|
- updateById(stockWaitDetails);
|
|
|
+
|
|
|
//更新待出库记录状态
|
|
|
- Integer statusFlag = 0;
|
|
|
- List<StockWaitDetails> stockWaitDetailsList = list(q -> q.eq(StockWaitDetails::getStockWaitId, stockWaitDetails.getStockWaitId()));
|
|
|
+ int statusFlag = 0;
|
|
|
+ List<StockWaitDetails> stockWaitDetailsList = list(q -> q.eq(StockWaitDetails::getStockWaitId, stockWaitDto.getId()));
|
|
|
for (StockWaitDetails waitDetails : stockWaitDetailsList) {
|
|
|
//计算已经完全出库的数量
|
|
|
BigDecimal receiptQuantity1 = ObjectUtil.isEmpty(waitDetails.getReceiptQuantity()) ? BigDecimal.ZERO : waitDetails.getReceiptQuantity();
|
|
@@ -170,7 +190,7 @@ public class StockWaitDetailsServiceImpl extends ServiceImpl<StockWaitDetailsMap
|
|
|
statusFlag++;
|
|
|
}
|
|
|
}
|
|
|
- StockWait byId = stockWaitService.getById(stockWaitDetails.getStockWaitId());
|
|
|
+ StockWait byId = stockWaitService.getById(stockWaitDto.getId());
|
|
|
if (statusFlag == stockWaitDetailsList.size()) {
|
|
|
byId.setStatus(2);//入库完成
|
|
|
} else {
|