| | |
| | | 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.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.MesProRouteProductBomDO; |
| | | 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 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; |
| | |
| | | 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())); |
| | | } |
| | | } |
| | | } |
| | | return success(result); |
| | | } |
| | | |
| | | @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. 批量获取产出产品物料信息 |
| | | Set<Long> outputItemIds = convertSet(list, MesProRouteProcessDO::getOutputItemId); |
| | | outputItemIds.remove(null); |
| | | Map<Long, MesMdItemDO> outputItemMap = outputItemIds.isEmpty() |
| | | ? Collections.emptyMap() |
| | | : mdItemService.getItemMap(outputItemIds); |
| | | // 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); |
| | | // 3. 拼接 VO |
| | | return BeanUtils.toBean(list, MesProRouteProcessRespVO.class, 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())); |
| | | MapUtils.findAndThen(outputItemMap, vo.getOutputItemId(), |
| | | item -> vo.setOutputItemCode(item.getCode()).setOutputItemName(item.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()); |
| | | } |
| | | } |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | private MesProRouteProcessRespVO buildRouteProcessRespVO(MesProRouteProcessDO routeProcess) { |