diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/qc/indicatorresult/MesQcIndicatorResultController.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/qc/indicatorresult/MesQcIndicatorResultController.java index 71bbd71..640cb1a 100644 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/qc/indicatorresult/MesQcIndicatorResultController.java +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/qc/indicatorresult/MesQcIndicatorResultController.java @@ -5,22 +5,14 @@ import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.mes.controller.admin.qc.indicatorresult.vo.*; -import cn.iocoder.yudao.module.mes.dal.dataobject.md.item.MesMdItemDO; -import cn.iocoder.yudao.module.mes.dal.dataobject.md.unitmeasure.MesMdUnitMeasureDO; import cn.iocoder.yudao.module.mes.dal.dataobject.qc.indicator.MesQcIndicatorDO; import cn.iocoder.yudao.module.mes.dal.dataobject.qc.indicatorresult.MesQcIndicatorResultDO; import cn.iocoder.yudao.module.mes.dal.dataobject.qc.indicatorresult.MesQcIndicatorResultDetailDO; -import cn.iocoder.yudao.module.mes.dal.dataobject.qc.lqc.MesQcIqcDO; import cn.iocoder.yudao.module.mes.dal.dataobject.qc.lqc.MesQcIqcLineDO; -import cn.iocoder.yudao.module.mes.dal.dataobject.tm.tool.MesTmToolDO; import cn.iocoder.yudao.module.mes.enums.qc.MesQcTypeEnum; -import cn.iocoder.yudao.module.mes.service.md.item.MesMdItemService; -import cn.iocoder.yudao.module.mes.service.md.unitmeasure.MesMdUnitMeasureService; import cn.iocoder.yudao.module.mes.service.qc.indicator.MesQcIndicatorService; import cn.iocoder.yudao.module.mes.service.qc.indicatorresult.MesQcIndicatorResultService; import cn.iocoder.yudao.module.mes.service.qc.lqc.MesQcIqcLineService; -import cn.iocoder.yudao.module.mes.service.qc.lqc.MesQcIqcService; -import cn.iocoder.yudao.module.mes.service.tm.tool.MesTmToolService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameters; @@ -47,17 +39,9 @@ public class MesQcIndicatorResultController { @Resource private MesQcIndicatorResultService resultService; @Resource - private MesQcIqcService iqcService; - @Resource private MesQcIqcLineService iqcLineService; @Resource - private MesMdItemService itemService; - @Resource - private MesMdUnitMeasureService unitMeasureService; - @Resource private MesQcIndicatorService indicatorService; - @Resource - private MesTmToolService toolService; @PostMapping("/create") @Operation(summary = "创建检验结果") @@ -83,21 +67,31 @@ public class MesQcIndicatorResultController { return success(true); } - // TODO @AI:是不是把 get 和 getIndicatorResultDetailTemplate 合并为一个接口?参数是 qcId + qcType;新的接口是 get-detail; - @GetMapping("/get") - @Operation(summary = "获得检验结果(含明细)") - @Parameter(name = "id", description = "编号", required = true, example = "1024") + @GetMapping("/get-detail") + @Operation(summary = "获得检验结果明细(含检测项模板)") + @Parameters({ + @Parameter(name = "id", description = "检验结果编号(编辑时传入;新增时不传)", example = "1024"), + @Parameter(name = "qcId", description = "质检单ID", required = true, example = "1"), + @Parameter(name = "qcType", description = "质检类型", required = true, example = "1") + }) @PreAuthorize("@ss.hasPermission('mes:qc-iqc:query')") - public CommonResult getIndicatorResult(@RequestParam("id") Long id) { - MesQcIndicatorResultDO result = resultService.getIndicatorResult(id); - if (result == null) { - return success(null); + public CommonResult getIndicatorResultDetail( + @RequestParam(value = "id", required = false) Long id, + @RequestParam("qcId") Long qcId, + @RequestParam("qcType") Integer qcType) { + MesQcIndicatorResultRespVO respVO; + List details; + if (id != null) { + // 编辑:加载已有结果主表 + 已有明细 + MesQcIndicatorResultDO result = resultService.getIndicatorResult(id); + respVO = BeanUtils.toBean(result, MesQcIndicatorResultRespVO.class); + details = resultService.getIndicatorResultDetailListByResultId(id); + } else { + // 新增:返回空壳 RespVO,仅填充检测项模板 + respVO = new MesQcIndicatorResultRespVO(); + details = Collections.emptyList(); } - // 构建 RespVO(含关联字段) - MesQcIndicatorResultRespVO respVO = buildIndicatorResultRespVOList(Collections.singletonList(result)).get(0); - // 查询明细并组装 - List details = resultService.getIndicatorResultDetailListByResultId(result.getId()); - respVO.setItems(buildDetailItemList(details, result.getQcId(), result.getQcType())); + respVO.setItems(buildDetailItemList(details, qcId, qcType)); return success(respVO); } @@ -106,62 +100,17 @@ public class MesQcIndicatorResultController { @PreAuthorize("@ss.hasPermission('mes:qc-iqc:query')") public CommonResult> getIndicatorResultPage(@Valid MesQcIndicatorResultPageReqVO pageReqVO) { PageResult pageResult = resultService.getIndicatorResultPage(pageReqVO); - return success(new PageResult<>(buildIndicatorResultRespVOList(pageResult.getList()), pageResult.getTotal())); - } - - @GetMapping("/detail-template") - @Operation(summary = "获取空值检测项模板") - @Parameters({ - @Parameter(name = "qcId", description = "质检单ID", required = true, example = "1"), - @Parameter(name = "qcType", description = "质检类型", required = true, example = "1") - }) - @PreAuthorize("@ss.hasPermission('mes:qc-iqc:query')") - public CommonResult> getIndicatorResultDetailTemplate( - @RequestParam("qcId") Long qcId, - @RequestParam("qcType") Integer qcType) { - return success(buildDetailItemList(Collections.emptyList(), qcId, qcType)); + // 前端列表只展示 code、sn、remark,无需关联查询 + PageResult voPageResult = BeanUtils.toBean(pageResult, MesQcIndicatorResultRespVO.class); + return success(voPageResult); } // ==================== 拼接 VO ==================== /** - * 构建主表 RespVO 列表(拼接物料、质检单等关联信息) - */ - private List buildIndicatorResultRespVOList(List list) { - if (CollUtil.isEmpty(list)) { - return Collections.emptyList(); - } - // 批量查询物料 - Map itemMap = itemService.getItemMap( - convertSet(list, MesQcIndicatorResultDO::getItemId)); - // 批量查询计量单位 - Map unitMeasureMap = unitMeasureService.getUnitMeasureMap( - convertSet(itemMap.values(), MesMdItemDO::getUnitMeasureId)); - // 批量查询 IQC 质检单 - Set iqcIds = convertSet(list, r -> - Objects.equals(r.getQcType(), MesQcTypeEnum.IQC.getType()) ? r.getQcId() : null); - iqcIds.remove(null); - Map iqcMap = iqcService.getIqcMap(iqcIds); - - // 拼装 VO - return BeanUtils.toBean(list, MesQcIndicatorResultRespVO.class, vo -> { - // 拼接物料信息 - findAndThen(itemMap, vo.getItemId(), item -> { - vo.setItemCode(item.getCode()).setItemName(item.getName()).setItemSpecification(item.getSpecification()); - findAndThen(unitMeasureMap, item.getUnitMeasureId(), - unit -> vo.setUnitName(unit.getName())); - }); - // 拼接质检单编号/名称 - if (Objects.equals(vo.getQcType(), MesQcTypeEnum.IQC.getType())) { - findAndThen(iqcMap, vo.getQcId(), iqc -> - vo.setQcCode(iqc.getCode()).setQcName(iqc.getName())); - } - // TODO @芋艿:IPQC/OQC/RQC 模块迁移后实现 - }); - } - - /** - * 构建明细 Item 列表:从 IQC line + indicator + tool + unitMeasure + 已有结果明细组装 + * 构建明细 Item 列表 + * + *

前端表单仅需:indicatorId、indicatorName、valueType、valueSpecification + 已有结果(id、value、remark)

* * @param details 已有结果明细(空列表表示获取空值模板) * @param qcId 质检单 ID @@ -169,70 +118,40 @@ public class MesQcIndicatorResultController { */ private List buildDetailItemList( List details, Long qcId, Integer qcType) { - // 1. 获取检验单行列表 + // 1.1 获取检验单行列表(知道有哪些检测指标) List lines; if (Objects.equals(qcType, MesQcTypeEnum.IQC.getType())) { lines = iqcLineService.getIqcLineListByIqcId(qcId); } else { // TODO @芋艿:IPQC/OQC/RQC 模块迁移后实现 - return Collections.emptyList(); + throw new IllegalArgumentException("暂不支持 qcType=" + qcType); } if (CollUtil.isEmpty(lines)) { return Collections.emptyList(); } - // 2. 批量查询关联信息 + // 1.2 批量查询检测指标 Map indicatorMap = indicatorService.getIndicatorMap( convertSet(lines, MesQcIqcLineDO::getIndicatorId)); - Map unitMeasureMap = unitMeasureService.getUnitMeasureMap( - convertSet(lines, MesQcIqcLineDO::getUnitMeasureId)); - - // 3. 构建已有明细 Map(按 indicatorId 索引) + // 1.3 构建已有明细 Map(按 indicatorId 索引) Map detailMap = CollUtil.isEmpty(details) ? Collections.emptyMap() : convertMap(details, MesQcIndicatorResultDetailDO::getIndicatorId); - // 4. 遍历行,组装 VO + // 2. 遍历行,组装 VO List voList = new ArrayList<>(lines.size()); for (MesQcIqcLineDO line : lines) { - MesQcIndicatorResultRespVO.Item vo = new MesQcIndicatorResultRespVO.Item(); - // 来自 IQC line - vo.setIndicatorId(line.getIndicatorId()); - vo.setCheckMethod(line.getCheckMethod()); - vo.setStandardValue(line.getStandardValue()); - vo.setMaxThreshold(line.getMaxThreshold()); - vo.setMinThreshold(line.getMinThreshold()); - + MesQcIndicatorResultRespVO.Item vo = new MesQcIndicatorResultRespVO.Item() + .setIndicatorId(line.getIndicatorId()); // 来自 indicator - findAndThen(indicatorMap, line.getIndicatorId(), indicator -> { - vo.setIndicatorCode(indicator.getCode()); - vo.setIndicatorName(indicator.getName()); - vo.setIndicatorType(indicator.getType()); - vo.setValueType(indicator.getResultType()); - vo.setValueSpecification(indicator.getResultSpecification()); - }); - - // 来自 unitMeasure - findAndThen(unitMeasureMap, line.getUnitMeasureId(), - unit -> vo.setUnitMeasureName(unit.getName())); - - // 来自 tool(逐个查询,数量通常较少) - if (line.getToolId() != null) { - MesTmToolDO tool = toolService.getTool(line.getToolId()); - if (tool != null) { - vo.setToolName(tool.getName()); - } - } - + findAndThen(indicatorMap, line.getIndicatorId(), indicator -> vo + .setIndicatorName(indicator.getName()) + .setValueType(indicator.getResultType()) + .setValueSpecification(indicator.getResultSpecification())); // 来自已有结果明细(如有) - MesQcIndicatorResultDetailDO detail = detailMap.get(line.getIndicatorId()); - if (detail != null) { - vo.setId(detail.getId()); - vo.setResultId(detail.getResultId()); - vo.setValue(detail.getValue()); - vo.setRemark(detail.getRemark()); - } - + findAndThen(detailMap, line.getIndicatorId(), detail -> vo + .setId(detail.getId()).setResultId(detail.getResultId()) + .setValue(detail.getValue()).setRemark(detail.getRemark())); voList.add(vo); } return voList; diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/qc/indicatorresult/vo/MesQcIndicatorResultRespVO.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/qc/indicatorresult/vo/MesQcIndicatorResultRespVO.java index ee86357..7d81a2b 100644 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/qc/indicatorresult/vo/MesQcIndicatorResultRespVO.java +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/qc/indicatorresult/vo/MesQcIndicatorResultRespVO.java @@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.mes.controller.admin.qc.indicatorresult.vo; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; -import java.math.BigDecimal; import java.time.LocalDateTime; import java.util.List; @@ -35,26 +34,6 @@ public class MesQcIndicatorResultRespVO { @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) private LocalDateTime createTime; - // ========== 关联查询字段 ========== - - @Schema(description = "质检单编号", example = "IQC-001") - private String qcCode; - - @Schema(description = "质检单名称", example = "xxx来料检验") - private String qcName; - - @Schema(description = "产品物料编码", example = "ITEM-001") - private String itemCode; - - @Schema(description = "产品物料名称", example = "电阻") - private String itemName; - - @Schema(description = "规格型号", example = "100Ω") - private String itemSpecification; - - @Schema(description = "单位名称", example = "个") - private String unitName; - // ========== 子表:检验结果明细 ========== @Schema(description = "检验结果明细列表") @@ -79,41 +58,17 @@ public class MesQcIndicatorResultRespVO { @Schema(description = "备注", example = "无") private String remark; - // ========== 关联查询字段(来自 IQC line + indicator) ========== - - @Schema(description = "检测指标编码", example = "IDX-001") - private String indicatorCode; + // ========== 关联查询字段(来自 indicator) ========== @Schema(description = "检测指标名称", example = "外观检查") private String indicatorName; - @Schema(description = "检测指标类型", example = "QUANTITATIVE") - private String indicatorType; - @Schema(description = "质检值类型", example = "1") private Integer valueType; @Schema(description = "值属性", example = "IMG") private String valueSpecification; - @Schema(description = "检测工具名称", example = "卡尺") - private String toolName; - - @Schema(description = "检测方法", example = "目视检查") - private String checkMethod; - - @Schema(description = "标准值", example = "10.0000") - private BigDecimal standardValue; - - @Schema(description = "计量单位名称", example = "mm") - private String unitMeasureName; - - @Schema(description = "误差上限", example = "10.5000") - private BigDecimal maxThreshold; - - @Schema(description = "误差下限", example = "9.5000") - private BigDecimal minThreshold; - } } diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/ErrorCodeConstants.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/ErrorCodeConstants.java index b65585f..cc9f07f 100644 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/ErrorCodeConstants.java +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/ErrorCodeConstants.java @@ -269,9 +269,6 @@ public interface ErrorCodeConstants { // ========== MES 质量管理-检验结果(1-040-606-000) ========== ErrorCode QC_RESULT_NOT_EXISTS = new ErrorCode(1_040_606_000, "检验结果不存在"); - ErrorCode QC_RESULT_ITEMS_EMPTY = new ErrorCode(1_040_606_001, "检测项结果值不能为空"); - ErrorCode QC_RESULT_SOURCE_DOC_NOT_EXISTS = new ErrorCode(1_040_606_002, "来源质检单不存在"); - ErrorCode QC_RESULT_SOURCE_DOC_TYPE_INVALID = new ErrorCode(1_040_606_003, "来源质检单类型不支持"); // ========== MES 仓库管理-仓库(1-040-700-000) ========== ErrorCode WM_WAREHOUSE_NOT_EXISTS = new ErrorCode(1_040_700_000, "仓库不存在"); @@ -303,8 +300,4 @@ public interface ErrorCodeConstants { // ========== MES 仓库管理-库存(1-040-703-000) ========== ErrorCode WM_MATERIAL_STOCK_NOT_EXISTS = new ErrorCode(1_040_703_000, "库存记录不存在"); - // ========== 兼容旧命名(storage_area=库区,storage_location=库位) ========== - ErrorCode WM_STORAGE_AREA_NOT_EXISTS = WM_WAREHOUSE_LOCATION_NOT_EXISTS; - ErrorCode WM_STORAGE_LOCATION_NOT_EXISTS = WM_WAREHOUSE_AREA_NOT_EXISTS; - } diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/qc/indicatorresult/MesQcIndicatorResultServiceImpl.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/qc/indicatorresult/MesQcIndicatorResultServiceImpl.java index 497a6e8..b576de0 100644 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/qc/indicatorresult/MesQcIndicatorResultServiceImpl.java +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/qc/indicatorresult/MesQcIndicatorResultServiceImpl.java @@ -119,7 +119,7 @@ public class MesQcIndicatorResultServiceImpl implements MesQcIndicatorResultServ return iqc.getItemId(); } // TODO @芋艿:IPQC/OQC/RQC 模块迁移后实现 - throw exception(QC_RESULT_SOURCE_DOC_TYPE_INVALID); + throw new IllegalArgumentException("暂不支持 qcType=" + qcType); } }