|
@@ -21,6 +21,7 @@ import com.fjhx.mes.entity.production.po.ProductionTaskDetail;
|
|
|
import com.fjhx.mes.entity.work.dto.WorkOrderDto;
|
|
|
import com.fjhx.mes.entity.work.dto.WorkOrderSelectDto;
|
|
|
import com.fjhx.mes.entity.work.po.WorkOrder;
|
|
|
+import com.fjhx.mes.entity.work.po.WorkOrderBom;
|
|
|
import com.fjhx.mes.entity.work.po.WorkOrderProductionProcesses;
|
|
|
import com.fjhx.mes.entity.work.vo.WorkOrderVo;
|
|
|
import com.fjhx.mes.mapper.work.WorkOrderMapper;
|
|
@@ -30,6 +31,7 @@ import com.fjhx.mes.service.production.ProductionPlanService;
|
|
|
import com.fjhx.mes.service.production.ProductionProcessesService;
|
|
|
import com.fjhx.mes.service.production.ProductionTaskDetailService;
|
|
|
import com.fjhx.mes.service.production.ProductionTaskService;
|
|
|
+import com.fjhx.mes.service.work.WorkOrderBomService;
|
|
|
import com.fjhx.mes.service.work.WorkOrderProductionProcessesService;
|
|
|
import com.fjhx.mes.service.work.WorkOrderService;
|
|
|
import com.fjhx.mes.utils.code.CodeEnum;
|
|
@@ -101,6 +103,8 @@ public class WorkOrderServiceImpl extends ServiceImpl<WorkOrderMapper, WorkOrder
|
|
|
private StockWaitService stockWaitService;
|
|
|
@Autowired
|
|
|
private StockWaitDetailsService stockWaitDetailsService;
|
|
|
+ @Autowired
|
|
|
+ private WorkOrderBomService workOrderBomService;
|
|
|
|
|
|
@Override
|
|
|
public Page<WorkOrderVo> getPage(WorkOrderSelectDto dto) {
|
|
@@ -169,6 +173,9 @@ public class WorkOrderServiceImpl extends ServiceImpl<WorkOrderMapper, WorkOrder
|
|
|
@DSTransactional
|
|
|
@Override
|
|
|
public void add(WorkOrderDto workOrderDto) {
|
|
|
+ //查询一下BOM信息看看是否已经配置
|
|
|
+ getBomInfo(workOrderDto);
|
|
|
+
|
|
|
//生成工单编号,以及设置默认状态
|
|
|
workOrderDto.setCode(CodeEnum.WORK_ORDER.getCode());
|
|
|
workOrderDto.setStatus(0);
|
|
@@ -360,30 +367,67 @@ public class WorkOrderServiceImpl extends ServiceImpl<WorkOrderMapper, WorkOrder
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 冻结工单BOM
|
|
|
+ * 获取bom信息
|
|
|
+ *
|
|
|
+ * @return
|
|
|
*/
|
|
|
- private void freezeMaterial(WorkOrderDto workOrderDto){
|
|
|
+ @Override
|
|
|
+ public List<BomDetail> getBomInfo(WorkOrder workOrder) {
|
|
|
//获取产品信息
|
|
|
- ProductInfo productInfo = productInfoService.getById(workOrderDto.getProductId());
|
|
|
+ ProductInfo productInfo = productInfoService.getById(workOrder.getProductId());
|
|
|
if (ObjectUtil.isEmpty(productInfo)) {
|
|
|
- throw new ServiceException("查询不到产品信息 产品id->" + workOrderDto.getProductId());
|
|
|
+ throw new ServiceException("查询不到产品信息 产品id->" + workOrder.getProductId());
|
|
|
}
|
|
|
- //搜索BOM明细并到冻结库存
|
|
|
- BomInfo bomInfo = bomInfoService.getOne(q -> q.eq(BomInfo::getProductId, workOrderDto.getProductId()).eq(BomInfo::getCurrentVersion, 1));
|
|
|
+
|
|
|
+ //搜索BOM明细
|
|
|
+ List<BomDetail> bomDetailList = new ArrayList<>();
|
|
|
+ //非定制
|
|
|
+ BomInfo bomInfo = bomInfoService.getOne(q -> q.eq(BomInfo::getProductId, workOrder.getProductId()).eq(BomInfo::getCurrentVersion, 1));
|
|
|
if (ObjectUtil.isEmpty(bomInfo)) {
|
|
|
throw new ServiceException("查询不到产品的BOM信息 产品名称->" + productInfo.getName());
|
|
|
}
|
|
|
- List<BomDetail> bomDetailList = bomDetailService.list(q -> q.eq(BomDetail::getBomInfoId, bomInfo.getId()));
|
|
|
+ bomDetailList = bomDetailService.list(q -> q.eq(BomDetail::getBomInfoId, bomInfo.getId()));
|
|
|
if (ObjectUtil.isEmpty(bomDetailList)) {
|
|
|
throw new ServiceException("查询不到产品BOM明细 产品名称->" + productInfo.getName());
|
|
|
}
|
|
|
+
|
|
|
+ //如果是定制就获取定制的BOM
|
|
|
+ if ("1".equals(workOrder.getIsCustomized())) {
|
|
|
+ //定制
|
|
|
+ List<WorkOrderBom> workOrderBoms = workOrderBomService.list(q -> q.eq(WorkOrderBom::getWorkOrderId, workOrder.getId()));
|
|
|
+ bomDetailList = BeanUtil.copyToList(workOrderBoms, BomDetail.class);
|
|
|
+ }
|
|
|
+ return bomDetailList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 冻结工单BOM
|
|
|
+ */
|
|
|
+ @DSTransactional
|
|
|
+ @Override
|
|
|
+ public void freezeMaterial(WorkOrder workOrderDto){
|
|
|
+ WorkOrder workOrder = this.getById(workOrderDto.getId());
|
|
|
+
|
|
|
+ //如果定制且BOM未定制直接跳出
|
|
|
+ if ("1".equals(workOrder.getIsCustomized())&&workOrderDto.getBomStatus()!=1){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //如果待生产数量为空(需要如果干预)直接跳过
|
|
|
+ if (ObjectUtil.isEmpty(workOrder.getProductionQuantity())){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取Bom明细
|
|
|
+ List<BomDetail> bomDetailList = getBomInfo(workOrder);
|
|
|
+
|
|
|
+ //根据BOM明细冻结库存
|
|
|
List<Long> productIds = bomDetailList.stream().map(BomDetail::getProductId).collect(Collectors.toList());
|
|
|
Map<Long, List<Stock>> productMap = stockService.mapKGroup(Stock::getProductId, q -> q.in(Stock::getProductId, productIds));
|
|
|
List<StockFrozen> stockFrozenList = new ArrayList<>();
|
|
|
for (BomDetail bomDetail : bomDetailList) {
|
|
|
Long productId = bomDetail.getProductId();
|
|
|
//计算总数量 需要的物料数量*工单生产数量
|
|
|
- BigDecimal multiply = bomDetail.getQuantity().multiply(workOrderDto.getProductionQuantity());
|
|
|
+ BigDecimal multiply = bomDetail.getQuantity().multiply(workOrder.getProductionQuantity());
|
|
|
//添加冻结库存
|
|
|
List<Stock> stocks = productMap.get(productId);
|
|
|
if (ObjectUtil.isEmpty(stocks)) {
|