| | |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; |
| | | import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen; |
| | |
| | | } |
| | | |
| | | @GetMapping("/list-by-item-and-type") |
| | | @Operation(summary = "根据物料或工单/任务和检测种类获取可用质检方案") |
| | | @Operation(summary = "根据物料或工单/任务和检测种类获取可用质检方案(未指定物料/工单/任务时返回该检测种类下全部启用方案)") |
| | | @PreAuthorize("@ss.hasPermission('mes:qc-template:query')") |
| | | public CommonResult<List<MesQcTemplateItemOptionRespVO>> getTemplateItemOptionList( |
| | | @RequestParam(value = "qcType", required = false) Integer qcType, |
| | | @RequestParam(value = "itemId", required = false) Long itemId, |
| | | @RequestParam(value = "workOrderId", required = false) Long workOrderId, |
| | | @RequestParam(value = "taskId", required = false) Long taskId) { |
| | | // 未指定物料/工单/任务时,按检测种类返回全部启用的质检方案(不限制产品物料关联) |
| | | if (itemId == null && workOrderId == null && taskId == null && qcType != null) { |
| | | return success(buildEnabledTemplateOptions(qcType)); |
| | | } |
| | | List<MesQcTemplateItemDO> list = templateItemService.getTemplateItemList( |
| | | itemId, qcType, workOrderId, taskId); |
| | | if (CollUtil.isEmpty(list)) { |
| | | // 该物料未绑定方案时,回退为该检测种类下的全部启用方案,供用户手动选择; |
| | | // 否则无绑定的物料(如万通出货检验的绝大多数产品)下拉框永远为空,单据无法编制 |
| | | if (qcType != null && (itemId != null || workOrderId != null || taskId != null)) { |
| | | return success(buildEnabledTemplateOptions(qcType)); |
| | | } |
| | | return success(Collections.emptyList()); |
| | | } |
| | | Map<Long, MesQcTemplateDO> templateMap = templateService.getTemplateMap( |
| | |
| | | return success(result); |
| | | } |
| | | |
| | | /** |
| | | * 构建「该检测种类下全部启用方案」的选项列表 |
| | | */ |
| | | private List<MesQcTemplateItemOptionRespVO> buildEnabledTemplateOptions(Integer qcType) { |
| | | return templateService.getEnabledTemplateListByType(qcType).stream() |
| | | .map(template -> new MesQcTemplateItemOptionRespVO() |
| | | .setTemplateId(template.getId()).setTemplateCode(template.getCode()) |
| | | .setTemplateName(template.getName())) |
| | | .collect(Collectors.toList()); |
| | | } |
| | | |
| | | // ==================== 拼接 VO ==================== |
| | | |
| | | private List<MesQcTemplateItemRespVO> buildItemRespVOList(List<MesQcTemplateItemDO> list) { |