|
|
|
@ -1,10 +1,8 @@
|
|
|
|
|
package com.hw.mes.service.impl;
|
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
import com.hw.common.core.constant.MesConstants;
|
|
|
|
|
import com.hw.common.core.exception.ServiceException;
|
|
|
|
@ -14,6 +12,7 @@ import com.hw.common.core.utils.uuid.Seq;
|
|
|
|
|
import com.hw.common.security.utils.SecurityUtils;
|
|
|
|
|
import com.hw.mes.domain.MesMaterialBom;
|
|
|
|
|
import com.hw.mes.domain.MesProductPlan;
|
|
|
|
|
import com.hw.mes.mapper.MesMaterialBomMapper;
|
|
|
|
|
import com.hw.mes.mapper.MesProductPlanMapper;
|
|
|
|
|
import com.hw.mes.service.IMesMaterialBomService;
|
|
|
|
|
import org.apache.commons.lang3.time.DateFormatUtils;
|
|
|
|
@ -42,6 +41,9 @@ public class MesProductOrderServiceImpl implements IMesProductOrderService {
|
|
|
|
|
@Autowired
|
|
|
|
|
private MesProductPlanMapper mesProductPlanMapper;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private MesMaterialBomMapper mesMaterialBomMapper;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询生产工单
|
|
|
|
|
*
|
|
|
|
@ -333,6 +335,70 @@ public class MesProductOrderServiceImpl implements IMesProductOrderService {
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 在生产派工时校验库存信息
|
|
|
|
|
* @param mesProductOrder
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public List<MesMaterialBom> getMaterialUsages(MesProductOrder mesProductOrder) {
|
|
|
|
|
String saleType = mesProductOrder.getSaleType();
|
|
|
|
|
MesProductOrder queryProductOrder = new MesProductOrder();
|
|
|
|
|
if (saleType.equals(MesConstants.MES_PRODUCT_ORDER_SALE)) {//外部销售
|
|
|
|
|
Long materialId = mesProductOrder.getMaterialId();
|
|
|
|
|
queryProductOrder.setMaterialId(materialId);
|
|
|
|
|
} else {//对内生产
|
|
|
|
|
Long produceMaterialId = mesProductOrder.getProduceMaterialId();
|
|
|
|
|
queryProductOrder.setProduceMaterialId(produceMaterialId);
|
|
|
|
|
}
|
|
|
|
|
queryProductOrder.setSaleOrderId(mesProductOrder.getSaleOrderId());
|
|
|
|
|
List<MesProductOrder> mesProductOrders = mesProductOrderMapper.selectMesProductOrderList(queryProductOrder);
|
|
|
|
|
//工单状态:0-待发布;1-已发布;2-已完成;3-已开始;4-暂停;8-已撤回;9-已删除
|
|
|
|
|
//找到派工数量大于0,并且状态是已发布或者已开始的或者暂停的
|
|
|
|
|
List<MesProductOrder> filterProductOrders = mesProductOrders.stream().filter(p ->
|
|
|
|
|
(p.getDispatchAmount().compareTo(BigDecimal.ONE) >= 0) &&
|
|
|
|
|
(p.getOrderStatus().equals(MesConstants.PUBLISHED) || p.getOrderStatus().equals(MesConstants.BEGIN) || p.getOrderStatus().equals(MesConstants.PAUSE))
|
|
|
|
|
).collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
//先根据saleorderid和安全库存查询总库存和已出库的数量
|
|
|
|
|
//查询各生产任务需要物料的数量
|
|
|
|
|
List<List<MesMaterialBom>> materialBomAllList = new ArrayList<>();
|
|
|
|
|
for (MesProductOrder filterProductOrder : filterProductOrders) {
|
|
|
|
|
Long materialBomId = filterProductOrder.getMaterialBomId();
|
|
|
|
|
MesMaterialBom queryMaterialBom = new MesMaterialBom();
|
|
|
|
|
queryMaterialBom.setParentId(materialBomId);
|
|
|
|
|
List<MesMaterialBom> materialBomList = mesMaterialBomMapper.selectMesMaterialBomJoinList(queryMaterialBom);
|
|
|
|
|
materialBomAllList.add(materialBomList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 使用流处理合并所有列表并计数(计算每个物料需要的数量)
|
|
|
|
|
Map<String, BigDecimal> standardCountMap = materialBomAllList.stream()
|
|
|
|
|
.flatMap(List::stream) // 将所有列表扁平化为一个流
|
|
|
|
|
.collect(Collectors.groupingBy(
|
|
|
|
|
MesMaterialBom::getGroupBy,
|
|
|
|
|
Collectors.reducing(BigDecimal.ZERO, MesMaterialBom::getStandardAmount, BigDecimal::add)));
|
|
|
|
|
|
|
|
|
|
List<MesMaterialBom> mesMaterialBoms = new ArrayList<>();
|
|
|
|
|
standardCountMap.forEach((groupBy, sum) -> {
|
|
|
|
|
System.out.println("groupBy: " + groupBy + ", Sum of values: " + sum);
|
|
|
|
|
MesMaterialBom mesMaterialBom = new MesMaterialBom();
|
|
|
|
|
String[] groupByArr = groupBy.split("-");
|
|
|
|
|
mesMaterialBom.setMaterialId(Long.valueOf(groupByArr[0]));
|
|
|
|
|
mesMaterialBom.setMaterialCode(groupByArr[1]);
|
|
|
|
|
mesMaterialBom.setMaterialName(groupByArr[2]);
|
|
|
|
|
mesMaterialBom.setMaterialSpec(groupByArr[3]);
|
|
|
|
|
mesMaterialBom.setStandardAmount(sum);
|
|
|
|
|
mesMaterialBoms.add(mesMaterialBom);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// select * from wms_stock_total wst left join wms_raw_outstock wro on wst.stock_total_id=wro.stock_total_id
|
|
|
|
|
// and wst.sale_order_id=0;
|
|
|
|
|
return mesMaterialBoms;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 递归查找最顶级节点
|
|
|
|
|
private MesProductOrder findTopLevelOrder(Long productOrderId) {
|
|
|
|
|
MesProductOrder currentOrder = mesProductOrderMapper.selectMesProductOrderByProductOrderId(productOrderId);
|
|
|
|
|