| | |
| | | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| | | import cn.iocoder.yudao.framework.common.util.collection.MapUtils; |
| | | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.pro.route.vo.process.MesProProcessBomItemVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.pro.route.vo.process.MesProRouteProcessOutputVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.pro.route.vo.process.MesProRouteProcessRespVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.pro.route.vo.process.MesProRouteProcessSaveReqVO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.md.item.MesMdItemDO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.pro.process.MesProProcessDO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.pro.route.MesProRouteProcessDO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.pro.route.MesProRouteProcessOutputDO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.pro.route.MesProRouteProductBomDO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.pro.route.MesProRouteProductDO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.wm.warehouse.MesWmWarehouseAreaDO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.wm.warehouse.MesWmWarehouseDO; |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.wm.warehouse.MesWmWarehouseLocationDO; |
| | | import cn.iocoder.yudao.module.mes.service.md.item.MesMdItemService; |
| | | import cn.iocoder.yudao.module.mes.service.pro.process.MesProProcessService; |
| | | import cn.iocoder.yudao.module.mes.service.pro.route.MesProRouteProcessService; |
| | | import cn.iocoder.yudao.module.mes.service.pro.route.MesProRouteProductService; |
| | | import cn.iocoder.yudao.module.mes.service.wm.warehouse.MesWmWarehouseAreaService; |
| | | import cn.iocoder.yudao.module.mes.service.wm.warehouse.MesWmWarehouseLocationService; |
| | | import cn.iocoder.yudao.module.mes.service.wm.warehouse.MesWmWarehouseService; |
| | | import io.swagger.v3.oas.annotations.Operation; |
| | | import io.swagger.v3.oas.annotations.Parameter; |
| | | import io.swagger.v3.oas.annotations.tags.Tag; |
| | |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| | | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; |
| | |
| | | private MesProRouteProcessService routeProcessService; |
| | | @Resource |
| | | private MesProProcessService processService; |
| | | @Resource |
| | | private MesMdItemService mdItemService; |
| | | @Resource |
| | | private MesProRouteProductService routeProductService; |
| | | @Resource |
| | | private MesWmWarehouseService warehouseService; |
| | | @Resource |
| | | private MesWmWarehouseLocationService warehouseLocationService; |
| | | @Resource |
| | | private MesWmWarehouseAreaService warehouseAreaService; |
| | | |
| | | @PostMapping("/create") |
| | | @Operation(summary = "创建工艺路线工序") |
| | |
| | | return success(buildRouteProcessRespVO(routeProcess)); |
| | | } |
| | | |
| | | // TODO @芋艿:到底叫 list-by-item 还是 list-by-product? |
| | | @GetMapping("/list-by-product") |
| | | @Operation(summary = "按产品获得工序列表", description = "根据产品查找关联的工艺路线,返回该路线的工序列表") |
| | | @Operation(summary = "按产品获得工序列表", description = "根据产品查找关联的工艺路线,返回该路线的工序列表(含各工序的投料BOM)") |
| | | @Parameter(name = "productId", description = "产品编号", required = true, example = "1") |
| | | @PreAuthorize("@ss.hasPermission('mes:pro-route:query')") |
| | | public CommonResult<List<MesProRouteProcessRespVO>> getRouteProcessListByProduct(@RequestParam("productId") Long productId) { |
| | | List<MesProRouteProcessDO> list = routeProcessService.getRouteProcessListByProductId(productId); |
| | | return success(buildRouteProcessRespVOList(list)); |
| | | List<MesProRouteProcessRespVO> result = buildRouteProcessRespVOList(list); |
| | | |
| | | // 查询配置投料并按工序填充 |
| | | Map<Long, List<MesProRouteProductBomDO>> bomByProcess = routeProcessService.getRouteProcessBomMapByProductId(productId); |
| | | if (!bomByProcess.isEmpty()) { |
| | | Set<Long> itemIds = bomByProcess.values().stream() |
| | | .flatMap(List::stream) |
| | | .map(MesProRouteProductBomDO::getItemId) |
| | | .collect(Collectors.toSet()); |
| | | Map<Long, MesMdItemDO> itemMap = mdItemService.getItemMap(itemIds); |
| | | for (MesProRouteProcessRespVO vo : result) { |
| | | List<MesProRouteProductBomDO> processBoms = bomByProcess.get(vo.getProcessId()); |
| | | if (CollUtil.isNotEmpty(processBoms)) { |
| | | vo.setBomItems(processBoms.stream().map(bom -> { |
| | | MesProProcessBomItemVO itemVO = new MesProProcessBomItemVO(); |
| | | itemVO.setItemId(bom.getItemId()); |
| | | itemVO.setQuantity(bom.getQuantity()); |
| | | itemVO.setRemark(bom.getRemark()); |
| | | MesMdItemDO item = itemMap.get(bom.getItemId()); |
| | | if (item != null) { |
| | | itemVO.setItemCode(item.getCode()); |
| | | itemVO.setItemName(item.getName()); |
| | | } |
| | | return itemVO; |
| | | }).collect(Collectors.toList())); |
| | | } |
| | | } |
| | | } |
| | | // 填充工艺路线产品上配置的默认报工仓库(下单时作为工序默认值) |
| | | fillDefaultOutputWarehouse(result, productId); |
| | | return success(result); |
| | | } |
| | | |
| | | private void fillDefaultOutputWarehouse(List<MesProRouteProcessRespVO> list, Long productId) { |
| | | if (CollUtil.isEmpty(list)) { |
| | | return; |
| | | } |
| | | MesProRouteProductDO routeProduct = routeProductService.getRouteProductByItemId(productId); |
| | | if (routeProduct == null || routeProduct.getWarehouseId() == null) { |
| | | return; |
| | | } |
| | | MesWmWarehouseDO warehouse = warehouseService.getWarehouse(routeProduct.getWarehouseId()); |
| | | MesWmWarehouseLocationDO location = routeProduct.getLocationId() != null |
| | | ? warehouseLocationService.getWarehouseLocation(routeProduct.getLocationId()) : null; |
| | | MesWmWarehouseAreaDO area = routeProduct.getAreaId() != null |
| | | ? warehouseAreaService.getWarehouseArea(routeProduct.getAreaId()) : null; |
| | | String warehouseName = warehouse != null ? warehouse.getName() : null; |
| | | String locationName = location != null ? location.getName() : null; |
| | | String areaName = area != null ? area.getName() : null; |
| | | for (MesProRouteProcessRespVO vo : list) { |
| | | vo.setWarehouseId(routeProduct.getWarehouseId()); |
| | | vo.setWarehouseName(warehouseName); |
| | | vo.setLocationId(routeProduct.getLocationId()); |
| | | vo.setLocationName(locationName); |
| | | vo.setAreaId(routeProduct.getAreaId()); |
| | | vo.setAreaName(areaName); |
| | | } |
| | | } |
| | | |
| | | @GetMapping("/list-by-route") |
| | |
| | | list.forEach(item -> { if (item.getNextProcessId() != null) processIds.add(item.getNextProcessId()); }); |
| | | Map<Long, MesProProcessDO> processMap = convertMap( |
| | | processService.getProcessList(new ArrayList<>(processIds)), MesProProcessDO::getId); |
| | | // 2. 拼接 VO |
| | | return BeanUtils.toBean(list, MesProRouteProcessRespVO.class, vo -> { |
| | | // 2. 批量获取产出产品物料信息(解析逗号分隔的字符串) |
| | | Set<Long> allOutputItemIds = new HashSet<>(); |
| | | Map<Long, List<Long>> voOutputItemIdsMap = new HashMap<>(); |
| | | for (int i = 0; i < list.size(); i++) { |
| | | String outputItemIdStr = list.get(i).getOutputItemId(); |
| | | if (outputItemIdStr != null && !outputItemIdStr.isBlank()) { |
| | | List<Long> ids = Arrays.stream(outputItemIdStr.split(",")) |
| | | .map(String::trim).filter(s -> !s.isEmpty()) |
| | | .map(Long::valueOf).collect(Collectors.toList()); |
| | | voOutputItemIdsMap.put((long) i, ids); |
| | | allOutputItemIds.addAll(ids); |
| | | } |
| | | } |
| | | Map<Long, MesMdItemDO> outputItemMap = allOutputItemIds.isEmpty() |
| | | ? Collections.emptyMap() : mdItemService.getItemMap(allOutputItemIds); |
| | | // 2.1 产出归属配置(productId 为空表示多产品通用) |
| | | Map<Long, List<MesProRouteProcessOutputVO>> outputsByRouteProcessId = new HashMap<>(); |
| | | Set<Long> routeProcessIds = convertSet(list, MesProRouteProcessDO::getId); |
| | | routeProcessIds.removeAll(Collections.singleton(null)); |
| | | if (CollUtil.isNotEmpty(routeProcessIds)) { |
| | | List<MesProRouteProcessOutputDO> outputList = routeProcessService |
| | | .getRouteProcessOutputListByRouteProcessIds(routeProcessIds); |
| | | if (CollUtil.isNotEmpty(outputList)) { |
| | | Set<Long> ownerItemIds = new HashSet<>(); |
| | | outputList.forEach(output -> { |
| | | if (output.getProductId() != null) { |
| | | ownerItemIds.add(output.getProductId()); |
| | | } |
| | | if (output.getItemId() != null) { |
| | | ownerItemIds.add(output.getItemId()); |
| | | } |
| | | }); |
| | | Map<Long, MesMdItemDO> ownerItemMap = mdItemService.getItemMap(ownerItemIds); |
| | | for (MesProRouteProcessOutputDO output : outputList) { |
| | | MesProRouteProcessOutputVO outputVO = new MesProRouteProcessOutputVO(); |
| | | outputVO.setId(output.getId()); |
| | | outputVO.setRouteProcessId(output.getRouteProcessId()); |
| | | outputVO.setProductId(output.getProductId()); |
| | | outputVO.setItemId(output.getItemId()); |
| | | outputVO.setSort(output.getSort()); |
| | | outputVO.setRemark(output.getRemark()); |
| | | MapUtils.findAndThen(ownerItemMap, output.getItemId(), |
| | | item -> outputVO.setItemCode(item.getCode()).setItemName(item.getName())); |
| | | MapUtils.findAndThen(ownerItemMap, output.getProductId(), |
| | | product -> outputVO.setProductName(product.getName())); |
| | | outputsByRouteProcessId.computeIfAbsent(output.getRouteProcessId(), |
| | | key -> new ArrayList<>()).add(outputVO); |
| | | } |
| | | } |
| | | } |
| | | // 3. 拼接 VO |
| | | List<MesProRouteProcessRespVO> result = BeanUtils.toBean(list, MesProRouteProcessRespVO.class); |
| | | for (int i = 0; i < result.size(); i++) { |
| | | MesProRouteProcessRespVO vo = result.get(i); |
| | | MapUtils.findAndThen(processMap, vo.getProcessId(), |
| | | process -> vo.setProcessCode(process.getCode()).setProcessName(process.getName())); |
| | | MapUtils.findAndThen(processMap, vo.getNextProcessId(), |
| | | nextProcess -> vo.setNextProcessName(nextProcess.getName())); |
| | | }); |
| | | // 产出产品(支持多选) |
| | | List<Long> ids = voOutputItemIdsMap.getOrDefault((long) i, Collections.emptyList()); |
| | | if (!ids.isEmpty()) { |
| | | vo.setOutputItemIds(ids); |
| | | List<String> names = ids.stream() |
| | | .map(id -> { |
| | | MesMdItemDO item = outputItemMap.get(id); |
| | | return item != null ? item.getName() : String.valueOf(id); |
| | | }).collect(Collectors.toList()); |
| | | vo.setOutputItemNames(String.join(", ", names)); |
| | | // 向后兼容:第一个产出产品 |
| | | Long firstId = ids.get(0); |
| | | vo.setOutputItemId(firstId); |
| | | MesMdItemDO firstItem = outputItemMap.get(firstId); |
| | | if (firstItem != null) { |
| | | vo.setOutputItemCode(firstItem.getCode()); |
| | | vo.setOutputItemName(firstItem.getName()); |
| | | } |
| | | } |
| | | vo.setOutputs(outputsByRouteProcessId.getOrDefault(vo.getId(), Collections.emptyList())); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | private MesProRouteProcessRespVO buildRouteProcessRespVO(MesProRouteProcessDO routeProcess) { |