feat: 新接口查原材料时查联查库存在途和需求
This commit is contained in:
@@ -97,4 +97,12 @@ public class WmsRawMaterialController extends BaseController {
|
|||||||
@PathVariable Long[] rawMaterialIds) {
|
@PathVariable Long[] rawMaterialIds) {
|
||||||
return toAjax(iWmsRawMaterialService.deleteWithValidByIds(Arrays.asList(rawMaterialIds), true));
|
return toAjax(iWmsRawMaterialService.deleteWithValidByIds(Arrays.asList(rawMaterialIds), true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询原材料列表(含需求、库存、在途信息)
|
||||||
|
*/
|
||||||
|
@GetMapping("/listWithDemand")
|
||||||
|
public TableDataInfo<WmsRawMaterialVo> listWithDemand(WmsRawMaterialBo bo, PageQuery pageQuery) {
|
||||||
|
return iWmsRawMaterialService.queryPageListWithDemand(bo, pageQuery);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -193,5 +193,23 @@ public class WmsRawMaterialVo {
|
|||||||
@ExcelProperty(value = "BOM 表头ID")
|
@ExcelProperty(value = "BOM 表头ID")
|
||||||
private Long bomId;
|
private Long bomId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 需求量
|
||||||
|
*/
|
||||||
|
@ExcelProperty(value = "需求量")
|
||||||
|
private BigDecimal demand;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 库存量
|
||||||
|
*/
|
||||||
|
@ExcelProperty(value = "库存量")
|
||||||
|
private BigDecimal inventory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在途量
|
||||||
|
*/
|
||||||
|
@ExcelProperty(value = "在途量")
|
||||||
|
private BigDecimal onTheWay;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -46,4 +46,9 @@ public interface IWmsRawMaterialService {
|
|||||||
* 校验并批量删除原材料信息
|
* 校验并批量删除原材料信息
|
||||||
*/
|
*/
|
||||||
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
|
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询原材料列表(含需求、库存、在途信息)
|
||||||
|
*/
|
||||||
|
TableDataInfo<WmsRawMaterialVo> queryPageListWithDemand(WmsRawMaterialBo bo, PageQuery pageQuery);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,19 @@ import com.klp.domain.vo.WmsRawMaterialVo;
|
|||||||
import com.klp.domain.WmsRawMaterial;
|
import com.klp.domain.WmsRawMaterial;
|
||||||
import com.klp.mapper.WmsRawMaterialMapper;
|
import com.klp.mapper.WmsRawMaterialMapper;
|
||||||
import com.klp.service.IWmsRawMaterialService;
|
import com.klp.service.IWmsRawMaterialService;
|
||||||
|
import com.klp.service.IWmsStockService;
|
||||||
|
import com.klp.service.IWmsPurchasePlanDetailService;
|
||||||
|
import com.klp.service.IWmsOrderDetailService;
|
||||||
|
import com.klp.service.IWmsProductBomService;
|
||||||
|
import com.klp.service.IWmsOrderService;
|
||||||
|
import com.klp.domain.bo.WmsPurchasePlanDetailBo;
|
||||||
|
import com.klp.domain.bo.WmsOrderDetailBo;
|
||||||
|
import com.klp.domain.bo.WmsProductBomBo;
|
||||||
|
import com.klp.domain.vo.WmsPurchasePlanDetailVo;
|
||||||
|
import com.klp.domain.vo.WmsProductBomVo;
|
||||||
|
import com.klp.domain.vo.WmsOrderDetailVo;
|
||||||
|
import com.klp.domain.vo.WmsOrderVo;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -30,6 +43,11 @@ import java.util.Collection;
|
|||||||
public class WmsRawMaterialServiceImpl implements IWmsRawMaterialService {
|
public class WmsRawMaterialServiceImpl implements IWmsRawMaterialService {
|
||||||
|
|
||||||
private final WmsRawMaterialMapper baseMapper;
|
private final WmsRawMaterialMapper baseMapper;
|
||||||
|
private final IWmsStockService stockService;
|
||||||
|
private final IWmsPurchasePlanDetailService purchasePlanDetailService;
|
||||||
|
private final IWmsOrderDetailService orderDetailService;
|
||||||
|
private final IWmsProductBomService productBomService;
|
||||||
|
private final IWmsOrderService orderService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询原材料
|
* 查询原材料
|
||||||
@@ -58,6 +76,92 @@ public class WmsRawMaterialServiceImpl implements IWmsRawMaterialService {
|
|||||||
return baseMapper.selectVoList(lqw);
|
return baseMapper.selectVoList(lqw);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询原材料列表(含需求、库存、在途信息)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public TableDataInfo<WmsRawMaterialVo> queryPageListWithDemand(WmsRawMaterialBo bo, PageQuery pageQuery) {
|
||||||
|
LambdaQueryWrapper<WmsRawMaterial> lqw = buildQueryWrapper(bo);
|
||||||
|
Page<WmsRawMaterialVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
||||||
|
// 填充需求、库存、在途信息
|
||||||
|
fillDemandInfo(result.getRecords());
|
||||||
|
return TableDataInfo.build(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 填充原材料需求、库存、在途信息
|
||||||
|
*/
|
||||||
|
private void fillDemandInfo(List<WmsRawMaterialVo> rawMaterialList) {
|
||||||
|
if (rawMaterialList == null || rawMaterialList.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 为每个原材料填充信息
|
||||||
|
for (WmsRawMaterialVo vo : rawMaterialList) {
|
||||||
|
Long rawMaterialId = vo.getRawMaterialId();
|
||||||
|
// 查询库存量
|
||||||
|
BigDecimal inventory = stockService.getStockByItemId(rawMaterialId);
|
||||||
|
vo.setInventory(inventory != null ? inventory : BigDecimal.ZERO);
|
||||||
|
// 查询在途量(采购计划明细)
|
||||||
|
BigDecimal onTheWay = getOnTheWayQuantity(rawMaterialId);
|
||||||
|
vo.setOnTheWay(onTheWay);
|
||||||
|
// 查询需求量(订单+BOM)
|
||||||
|
BigDecimal demand = getDemandQuantity(rawMaterialId);
|
||||||
|
vo.setDemand(demand);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取在途量
|
||||||
|
*/
|
||||||
|
private BigDecimal getOnTheWayQuantity(Long rawMaterialId) {
|
||||||
|
WmsPurchasePlanDetailBo bo = new WmsPurchasePlanDetailBo();
|
||||||
|
bo.setRawMaterialId(rawMaterialId);
|
||||||
|
List<WmsPurchasePlanDetailVo> list = purchasePlanDetailService.queryList(bo);
|
||||||
|
return list.stream()
|
||||||
|
.filter(item -> item.getStatus() != null && item.getStatus() == 1) // 在途状态
|
||||||
|
.map(WmsPurchasePlanDetailVo::getQuantity)
|
||||||
|
.filter(qty -> qty != null)
|
||||||
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取需求量
|
||||||
|
*/
|
||||||
|
private BigDecimal getDemandQuantity(Long rawMaterialId) {
|
||||||
|
// 先查询包含该原材料的BOM
|
||||||
|
WmsProductBomBo bomBo = new WmsProductBomBo();
|
||||||
|
bomBo.setRawMaterialId(rawMaterialId);
|
||||||
|
List<WmsProductBomVo> bomList = productBomService.queryList(bomBo);
|
||||||
|
if (bomList.isEmpty()) {
|
||||||
|
return BigDecimal.ZERO;
|
||||||
|
}
|
||||||
|
// 查询这些产品的订单明细
|
||||||
|
BigDecimal totalDemand = BigDecimal.ZERO;
|
||||||
|
for (WmsProductBomVo bom : bomList) {
|
||||||
|
WmsOrderDetailBo orderDetailBo = new WmsOrderDetailBo();
|
||||||
|
orderDetailBo.setProductId(bom.getProductId());
|
||||||
|
List<WmsOrderDetailVo> orderDetails = orderDetailService.queryList(orderDetailBo);
|
||||||
|
// 逐个查询订单状态,过滤出有效订单的明细
|
||||||
|
BigDecimal productDemand = BigDecimal.ZERO;
|
||||||
|
for (WmsOrderDetailVo detail : orderDetails) {
|
||||||
|
// 查询订单主表状态
|
||||||
|
WmsOrderVo order = orderService.queryById(detail.getOrderId());
|
||||||
|
if (order != null && order.getOrderStatus() != null && order.getOrderStatus() < 2) {
|
||||||
|
// 新建、生产中状态,累加数量
|
||||||
|
if (detail.getQuantity() != null) {
|
||||||
|
productDemand = productDemand.add(detail.getQuantity());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 需求量 = 产品需求量 × BOM用量
|
||||||
|
if (bom.getQuantity() != null) {
|
||||||
|
totalDemand = totalDemand.add(productDemand.multiply(bom.getQuantity()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return totalDemand;
|
||||||
|
}
|
||||||
|
|
||||||
private LambdaQueryWrapper<WmsRawMaterial> buildQueryWrapper(WmsRawMaterialBo bo) {
|
private LambdaQueryWrapper<WmsRawMaterial> buildQueryWrapper(WmsRawMaterialBo bo) {
|
||||||
Map<String, Object> params = bo.getParams();
|
Map<String, Object> params = bo.getParams();
|
||||||
LambdaQueryWrapper<WmsRawMaterial> lqw = Wrappers.lambdaQuery();
|
LambdaQueryWrapper<WmsRawMaterial> lqw = Wrappers.lambdaQuery();
|
||||||
|
|||||||
@@ -38,5 +38,4 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<result property="bomId" column="bom_id"/>
|
<result property="bomId" column="bom_id"/>
|
||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|||||||
Reference in New Issue
Block a user