|
@@ -1,17 +1,25 @@
|
|
|
package com.fjhx.service.apply.impl;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.fjhx.constants.StockJournalTypeConstant;
|
|
|
import com.fjhx.entity.apply.ApplyPurchase;
|
|
|
+import com.fjhx.entity.logistics.LogisticsDetails;
|
|
|
+import com.fjhx.entity.logistics.LogisticsInfo;
|
|
|
import com.fjhx.entity.product.ProductInfo;
|
|
|
import com.fjhx.entity.stock.Stock;
|
|
|
import com.fjhx.entity.stock.StockJournal;
|
|
|
import com.fjhx.entity.warehouse.Warehouse;
|
|
|
import com.fjhx.enums.apply.ApplyPurchaseStatusEnum;
|
|
|
import com.fjhx.mapper.apply.ApplyPurchaseMapper;
|
|
|
+import com.fjhx.mapper.logistics.LogisticsInfoMapper;
|
|
|
import com.fjhx.params.apply.ApplyPurchaseVo;
|
|
|
+import com.fjhx.params.logistics.LogisticsInfoEx;
|
|
|
import com.fjhx.service.apply.ApplyPurchaseService;
|
|
|
+import com.fjhx.service.logistics.LogisticsDetailsService;
|
|
|
+import com.fjhx.service.logistics.LogisticsInfoService;
|
|
|
import com.fjhx.service.product.ProductInfoService;
|
|
|
import com.fjhx.service.stock.StockJournalService;
|
|
|
import com.fjhx.service.stock.StockService;
|
|
@@ -21,8 +29,10 @@ import com.fjhx.utils.wrapperUtil.IWrapper;
|
|
|
import org.springblade.core.log.exception.ServiceException;
|
|
|
import org.springblade.core.redis.lock.RedisLockClient;
|
|
|
import org.springblade.core.secure.utils.AuthUtil;
|
|
|
+import org.springblade.core.tool.utils.BeanUtil;
|
|
|
import org.springblade.core.tool.utils.DateUtil;
|
|
|
import org.springblade.core.tool.utils.Func;
|
|
|
+import org.springblade.core.tool.utils.ObjectUtil;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
@@ -56,6 +66,12 @@ public class ApplyPurchaseServiceImpl extends ServiceImpl<ApplyPurchaseMapper, A
|
|
|
@Autowired
|
|
|
private StockJournalService stockJournalService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ LogisticsDetailsService logisticsDetailsService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ LogisticsInfoMapper logisticsInfoMapper;
|
|
|
+
|
|
|
private final String REDIS_LOCK_CACHE_KEY = "seq:lock:" + AuthUtil.getTenantId() + ":apply_purchase:";
|
|
|
|
|
|
@Override
|
|
@@ -234,9 +250,13 @@ public class ApplyPurchaseServiceImpl extends ServiceImpl<ApplyPurchaseMapper, A
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
- public List<ApplyPurchase> getByPurchaseId(Long purchaseId) {
|
|
|
+ public List<ApplyPurchaseVo> getByPurchaseId(Long purchaseId) {
|
|
|
+
|
|
|
+ List<ApplyPurchase> purchases0 = lambdaQuery().eq(ApplyPurchase::getPurchaseId, purchaseId).list();
|
|
|
+ //去重
|
|
|
+ purchases0 = purchases0.stream().distinct().collect(Collectors.toList());
|
|
|
+ List<ApplyPurchaseVo> purchases = BeanUtil.copy(purchases0, ApplyPurchaseVo.class);
|
|
|
|
|
|
- List<ApplyPurchase> purchases = lambdaQuery().eq(ApplyPurchase::getPurchaseId, purchaseId).list();
|
|
|
if (Func.isNotEmpty(purchases)) {
|
|
|
//物品ID集合
|
|
|
List<Long> goodsIds = purchases.stream().map(ApplyPurchase::getGoodsId).distinct().collect(Collectors.toList());
|
|
@@ -252,7 +272,15 @@ public class ApplyPurchaseServiceImpl extends ServiceImpl<ApplyPurchaseMapper, A
|
|
|
//物品出库信息map
|
|
|
Map<Long, BigDecimal> outStockMap = getOutStockMap(goodsIds);
|
|
|
|
|
|
- for (ApplyPurchase record : purchases) {
|
|
|
+ //获取物流明细
|
|
|
+ List<Long> purchaseIds = purchases.stream().map(ApplyPurchase::getPurchaseId).collect(Collectors.toList());
|
|
|
+ QueryWrapper<Object> wrapper = new QueryWrapper<>();
|
|
|
+ wrapper.in("ld.purchase_id", purchaseIds);
|
|
|
+ List<LogisticsInfoEx> logisticsInfoExes = logisticsInfoMapper.getLogisticsQuantity(wrapper);
|
|
|
+ Map<Long, List<LogisticsInfoEx>> map1 = logisticsInfoExes.stream()
|
|
|
+ .collect(Collectors.groupingBy(LogisticsInfoEx::getApplyPurchaseId));
|
|
|
+
|
|
|
+ for (ApplyPurchaseVo record : purchases) {
|
|
|
if (Func.isNotEmpty(productInfoMap) && Func.isNotEmpty(productInfoMap.get(record.getGoodsId()))) {
|
|
|
ProductInfo info = productInfoMap.get(record.getGoodsId());
|
|
|
record.setGoodsType(info.getType());
|
|
@@ -263,6 +291,21 @@ public class ApplyPurchaseServiceImpl extends ServiceImpl<ApplyPurchaseMapper, A
|
|
|
if (Func.isNotEmpty(outStockMap) && Func.isNotEmpty(outStockMap.get(record.getGoodsId()))) {
|
|
|
record.setOutStockQuantity(outStockMap.get(record.getGoodsId()));
|
|
|
}
|
|
|
+ //赋值发货,到货数量
|
|
|
+ List<LogisticsInfoEx> shipmentQuantityList = map1.get(record.getId());
|
|
|
+ if(ObjectUtil.isNotEmpty(shipmentQuantityList)) {
|
|
|
+ BigDecimal shipmentTotalQuantity = shipmentQuantityList.stream().map(LogisticsInfoEx::getShipmentQuantity)
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ BigDecimal receiptQuantity = shipmentQuantityList.stream().map(LogisticsInfoEx::getReceiptQuantity)
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ record.setQuantityList(shipmentQuantityList);
|
|
|
+ record.setShipmentTotalQuantity(shipmentTotalQuantity);
|
|
|
+ record.setArrivalTotalQuantity(receiptQuantity);
|
|
|
+ }else{
|
|
|
+ record.setQuantityList(new ArrayList<>());
|
|
|
+ record.setShipmentTotalQuantity(BigDecimal.ZERO);
|
|
|
+ record.setReceiptQuantity(BigDecimal.ZERO);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
return purchases;
|