| | |
| | | import cn.iocoder.yudao.module.mes.service.md.item.MesMdItemService; |
| | | import cn.iocoder.yudao.module.mes.service.md.item.MesMdItemTypeService; |
| | | import cn.iocoder.yudao.module.mes.service.md.unitmeasure.MesMdUnitMeasureService; |
| | | import cn.iocoder.yudao.module.mes.service.pro.material.MesProMaterialRequirementService; |
| | | import cn.iocoder.yudao.module.mes.service.pro.route.MesProRouteProductBomService; |
| | | import cn.iocoder.yudao.module.mes.service.pro.route.MesProRouteProductService; |
| | | import cn.iocoder.yudao.module.mes.service.pro.workorder.MesProWorkOrderBomService; |
| | |
| | | import cn.iocoder.yudao.module.mes.service.pro.workorder.MesProWorkOrderService; |
| | | import io.swagger.v3.oas.annotations.Operation; |
| | | import io.swagger.v3.oas.annotations.Parameter; |
| | | import io.swagger.v3.oas.annotations.Parameters; |
| | | import io.swagger.v3.oas.annotations.tags.Tag; |
| | | import jakarta.annotation.Resource; |
| | | import jakarta.validation.Valid; |
| | |
| | | private MesWmMaterialStockMapper materialStockMapper; |
| | | @Resource |
| | | private ErpPurchaseOrderApi purchaseOrderApi; |
| | | @Resource |
| | | private MesProMaterialRequirementService materialRequirementService; |
| | | |
| | | @PostMapping("/create") |
| | | @Operation(summary = "创建工单 BOM") |
| | |
| | | @GetMapping("/get") |
| | | @Operation(summary = "获得工单 BOM") |
| | | @Parameter(name = "id", description = "编号", required = true, example = "1024") |
| | | @PreAuthorize("@ss.hasPermission('mes:pro-work-order:query')") |
| | | public CommonResult<MesProWorkOrderBomRespVO> getWorkOrderBom(@RequestParam("id") Long id) { |
| | | MesProWorkOrderBomDO workOrderBom = workOrderBomService.getWorkOrderBom(id); |
| | | if (workOrderBom == null) { |
| | |
| | | |
| | | @GetMapping("/page") |
| | | @Operation(summary = "获得工单 BOM 分页") |
| | | @PreAuthorize("@ss.hasPermission('mes:pro-work-order:query')") |
| | | public CommonResult<PageResult<MesProWorkOrderBomRespVO>> getWorkOrderBomPage(@Valid MesProWorkOrderBomPageReqVO pageReqVO) { |
| | | PageResult<MesProWorkOrderBomDO> pageResult = workOrderBomService.getWorkOrderBomPage(pageReqVO); |
| | | return success(new PageResult<>(buildWorkOrderBomRespVOList(pageResult.getList()), pageResult.getTotal())); |
| | | } |
| | | |
| | | @GetMapping("/item-list-preview") |
| | | @Operation(summary = "按产品和数量预览辅料需求(新增工单时判断库存是否充足)") |
| | | @Parameters({ |
| | | @Parameter(name = "productId", description = "产品编号", required = true), |
| | | @Parameter(name = "quantity", description = "生产数量", required = true) |
| | | }) |
| | | @PreAuthorize("@ss.hasPermission('mes:pro-work-order:query')") |
| | | public CommonResult<List<MesProWorkOrderItemRespVO>> previewItemList( |
| | | @RequestParam("productId") Long productId, |
| | | @RequestParam("quantity") BigDecimal quantity) { |
| | | return success(materialRequirementService.getItemListByProduct(productId, quantity)); |
| | | } |
| | | |
| | | @GetMapping("/item-list-by-work-order-id") |
| | | @Operation(summary = "获得工单物料需求列表") |
| | | @Parameter(name = "workOrderId", description = "工单编号", required = true) |
| | | @PreAuthorize("@ss.hasPermission('mes:pro-work-order:query')") |
| | | public CommonResult<List<MesProWorkOrderItemRespVO>> getWorkOrderBomItemListByWorkOrderId( |
| | | @RequestParam("workOrderId") Long workOrderId) { |
| | | // 1. 获取工单 |
| | |
| | | } |
| | | List<MesProWorkOrderBomDO> items = new ArrayList<>(); |
| | | for (MesProWorkOrderBomDO bom : bomList) { |
| | | if (bom.getProcessId().equals(process.getProcessId())) { |
| | | // 跳过无工序编号的投料行(工单 BOM 中仅按工序维护投料明细,无工序的行不参与展开, |
| | | // 且 getProcessId 可能为 null,直接 equals 会 NPE) |
| | | if (Objects.equals(bom.getProcessId(), process.getProcessId())) { |
| | | items.add(bom); |
| | | } |
| | | } |
| | | processBomMap.put(process.getOutputItemId(), items); |
| | | processBomMap.put(Long.valueOf(process.getOutputItemId().split(",")[0].trim()), items); |
| | | } |
| | | |
| | | // 2. 取最后一道工序(sort 最大)作为展开起点,逐层向前递推 |
| | |
| | | // 3. 以最后一道工序的投料为起点 |
| | | Map<Long, BigDecimal> currentLayer = new LinkedHashMap<>(); |
| | | for (MesProWorkOrderBomDO bom : bomList) { |
| | | if (bom.getProcessId().equals(lastProcess.getProcessId())) { |
| | | if (Objects.equals(bom.getProcessId(), lastProcess.getProcessId())) { |
| | | currentLayer.merge(bom.getItemId(), bom.getQuantity(), BigDecimal::add); |
| | | } |
| | | } |