Commit 6d4dc2bdf47d29f76f0ef5d03b32176364433fec

Authored by YunaiV
1 parent 83fdaad4

feat(mes): add RQC line request and response VO, and implement RQC line controller and service

Showing 15 changed files with 1428 additions and 0 deletions
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/qc/rqc/MesQcRqcController.java 0 → 100644
  1 +package cn.iocoder.yudao.module.mes.controller.admin.qc.rqc;
  2 +
  3 +import cn.hutool.core.collection.CollUtil;
  4 +import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
  5 +import cn.iocoder.yudao.framework.common.pojo.CommonResult;
  6 +import cn.iocoder.yudao.framework.common.pojo.PageParam;
  7 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  8 +import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
  9 +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
  10 +import cn.iocoder.yudao.module.mes.controller.admin.qc.rqc.vo.MesQcRqcPageReqVO;
  11 +import cn.iocoder.yudao.module.mes.controller.admin.qc.rqc.vo.MesQcRqcRespVO;
  12 +import cn.iocoder.yudao.module.mes.controller.admin.qc.rqc.vo.MesQcRqcSaveReqVO;
  13 +import cn.iocoder.yudao.module.mes.dal.dataobject.md.item.MesMdItemDO;
  14 +import cn.iocoder.yudao.module.mes.dal.dataobject.md.unitmeasure.MesMdUnitMeasureDO;
  15 +import cn.iocoder.yudao.module.mes.dal.dataobject.qc.rqc.MesQcRqcDO;
  16 +import cn.iocoder.yudao.module.mes.service.md.item.MesMdItemService;
  17 +import cn.iocoder.yudao.module.mes.service.md.unitmeasure.MesMdUnitMeasureService;
  18 +import cn.iocoder.yudao.module.mes.service.qc.rqc.MesQcRqcService;
  19 +import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
  20 +import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
  21 +import io.swagger.v3.oas.annotations.Operation;
  22 +import io.swagger.v3.oas.annotations.Parameter;
  23 +import io.swagger.v3.oas.annotations.tags.Tag;
  24 +import jakarta.annotation.Resource;
  25 +import jakarta.servlet.http.HttpServletResponse;
  26 +import jakarta.validation.Valid;
  27 +import org.springframework.security.access.prepost.PreAuthorize;
  28 +import org.springframework.validation.annotation.Validated;
  29 +import org.springframework.web.bind.annotation.*;
  30 +
  31 +import java.io.IOException;
  32 +import java.util.Collections;
  33 +import java.util.List;
  34 +import java.util.Map;
  35 +
  36 +import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
  37 +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
  38 +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
  39 +import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen;
  40 +
  41 +@Tag(name = "管理后台 - MES 退货检验单(RQC)")
  42 +@RestController
  43 +@RequestMapping("/mes/qc/rqc")
  44 +@Validated
  45 +public class MesQcRqcController {
  46 +
  47 + @Resource
  48 + private MesQcRqcService rqcService;
  49 + @Resource
  50 + private MesMdItemService itemService;
  51 + @Resource
  52 + private MesMdUnitMeasureService unitMeasureService;
  53 +
  54 + @Resource
  55 + private AdminUserApi adminUserApi;
  56 +
  57 + @PostMapping("/create")
  58 + @Operation(summary = "创建退货检验单")
  59 + @PreAuthorize("@ss.hasPermission('mes:qc-rqc:create')")
  60 + public CommonResult<Long> createRqc(@Valid @RequestBody MesQcRqcSaveReqVO createReqVO) {
  61 + return success(rqcService.createRqc(createReqVO));
  62 + }
  63 +
  64 + @PutMapping("/update")
  65 + @Operation(summary = "更新退货检验单")
  66 + @PreAuthorize("@ss.hasPermission('mes:qc-rqc:update')")
  67 + public CommonResult<Boolean> updateRqc(@Valid @RequestBody MesQcRqcSaveReqVO updateReqVO) {
  68 + rqcService.updateRqc(updateReqVO);
  69 + return success(true);
  70 + }
  71 +
  72 + @PutMapping("/complete")
  73 + @Operation(summary = "完成退货检验单")
  74 + @Parameter(name = "id", description = "编号", required = true)
  75 + @PreAuthorize("@ss.hasPermission('mes:qc-rqc:update')")
  76 + public CommonResult<Boolean> completeRqc(@RequestParam("id") Long id) {
  77 + rqcService.completeRqc(id);
  78 + return success(true);
  79 + }
  80 +
  81 + @DeleteMapping("/delete")
  82 + @Operation(summary = "删除退货检验单")
  83 + @Parameter(name = "id", description = "编号", required = true)
  84 + @PreAuthorize("@ss.hasPermission('mes:qc-rqc:delete')")
  85 + public CommonResult<Boolean> deleteRqc(@RequestParam("id") Long id) {
  86 + rqcService.deleteRqc(id);
  87 + return success(true);
  88 + }
  89 +
  90 + @GetMapping("/get")
  91 + @Operation(summary = "获得退货检验单")
  92 + @Parameter(name = "id", description = "编号", required = true, example = "1024")
  93 + @PreAuthorize("@ss.hasPermission('mes:qc-rqc:query')")
  94 + public CommonResult<MesQcRqcRespVO> getRqc(@RequestParam("id") Long id) {
  95 + MesQcRqcDO rqc = rqcService.getRqc(id);
  96 + return success(buildRqcRespVOList(Collections.singletonList(rqc)).get(0));
  97 + }
  98 +
  99 + @GetMapping("/page")
  100 + @Operation(summary = "获得退货检验单分页")
  101 + @PreAuthorize("@ss.hasPermission('mes:qc-rqc:query')")
  102 + public CommonResult<PageResult<MesQcRqcRespVO>> getRqcPage(@Valid MesQcRqcPageReqVO pageReqVO) {
  103 + PageResult<MesQcRqcDO> pageResult = rqcService.getRqcPage(pageReqVO);
  104 + return success(new PageResult<>(buildRqcRespVOList(pageResult.getList()), pageResult.getTotal()));
  105 + }
  106 +
  107 + @GetMapping("/export-excel")
  108 + @Operation(summary = "导出退货检验单 Excel")
  109 + @PreAuthorize("@ss.hasPermission('mes:qc-rqc:export')")
  110 + @ApiAccessLog(operateType = EXPORT)
  111 + public void exportRqcExcel(@Valid MesQcRqcPageReqVO pageReqVO,
  112 + HttpServletResponse response) throws IOException {
  113 + pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
  114 + List<MesQcRqcDO> list = rqcService.getRqcPage(pageReqVO).getList();
  115 + List<MesQcRqcRespVO> voList = buildRqcRespVOList(list);
  116 + ExcelUtils.write(response, "退货检验单.xls", "数据", MesQcRqcRespVO.class, voList);
  117 + }
  118 +
  119 + // ==================== 拼接 VO ====================
  120 +
  121 + private List<MesQcRqcRespVO> buildRqcRespVOList(List<MesQcRqcDO> list) {
  122 + if (CollUtil.isEmpty(list)) {
  123 + return Collections.emptyList();
  124 + }
  125 + // 批量查询物料
  126 + Map<Long, MesMdItemDO> itemMap = itemService.getItemMap(
  127 + convertSet(list, MesQcRqcDO::getItemId));
  128 + // 批量查询计量单位
  129 + Map<Long, MesMdUnitMeasureDO> unitMeasureMap = unitMeasureService.getUnitMeasureMap(
  130 + convertSet(itemMap.values(), MesMdItemDO::getUnitMeasureId));
  131 + // 批量查询检测人员
  132 + Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(
  133 + convertSet(list, MesQcRqcDO::getInspectorUserId));
  134 + // 拼装 VO
  135 + return BeanUtils.toBean(list, MesQcRqcRespVO.class, vo -> {
  136 + findAndThen(itemMap, vo.getItemId(), item -> {
  137 + vo.setItemCode(item.getCode()).setItemName(item.getName()).setItemSpecification(item.getSpecification());
  138 + findAndThen(unitMeasureMap, item.getUnitMeasureId(),
  139 + unit -> vo.setUnitName(unit.getName()));
  140 + });
  141 + findAndThen(userMap, vo.getInspectorUserId(),
  142 + user -> vo.setInspectorNickname(user.getNickname()));
  143 + });
  144 + }
  145 +
  146 +}
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/qc/rqc/MesQcRqcLineController.java 0 → 100644
  1 +package cn.iocoder.yudao.module.mes.controller.admin.qc.rqc;
  2 +
  3 +import cn.hutool.core.collection.CollUtil;
  4 +import cn.iocoder.yudao.framework.common.pojo.CommonResult;
  5 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  6 +import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
  7 +import cn.iocoder.yudao.module.mes.controller.admin.qc.rqc.vo.line.MesQcRqcLinePageReqVO;
  8 +import cn.iocoder.yudao.module.mes.controller.admin.qc.rqc.vo.line.MesQcRqcLineRespVO;
  9 +import cn.iocoder.yudao.module.mes.dal.dataobject.md.unitmeasure.MesMdUnitMeasureDO;
  10 +import cn.iocoder.yudao.module.mes.dal.dataobject.qc.rqc.MesQcRqcLineDO;
  11 +import cn.iocoder.yudao.module.mes.dal.dataobject.qc.indicator.MesQcIndicatorDO;
  12 +import cn.iocoder.yudao.module.mes.dal.dataobject.tm.tool.MesTmToolDO;
  13 +import cn.iocoder.yudao.module.mes.service.md.unitmeasure.MesMdUnitMeasureService;
  14 +import cn.iocoder.yudao.module.mes.service.qc.rqc.MesQcRqcLineService;
  15 +import cn.iocoder.yudao.module.mes.service.qc.indicator.MesQcIndicatorService;
  16 +import cn.iocoder.yudao.module.mes.service.tm.tool.MesTmToolService;
  17 +import io.swagger.v3.oas.annotations.Operation;
  18 +import io.swagger.v3.oas.annotations.Parameter;
  19 +import io.swagger.v3.oas.annotations.tags.Tag;
  20 +import jakarta.annotation.Resource;
  21 +import jakarta.validation.Valid;
  22 +import org.springframework.security.access.prepost.PreAuthorize;
  23 +import org.springframework.validation.annotation.Validated;
  24 +import org.springframework.web.bind.annotation.GetMapping;
  25 +import org.springframework.web.bind.annotation.RequestMapping;
  26 +import org.springframework.web.bind.annotation.RequestParam;
  27 +import org.springframework.web.bind.annotation.RestController;
  28 +
  29 +import java.util.Collections;
  30 +import java.util.List;
  31 +import java.util.Map;
  32 +
  33 +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
  34 +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
  35 +import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen;
  36 +
  37 +@Tag(name = "管理后台 - MES 退货检验单行")
  38 +@RestController
  39 +@RequestMapping("/mes/qc/rqc/line")
  40 +@Validated
  41 +public class MesQcRqcLineController {
  42 +
  43 + @Resource
  44 + private MesQcRqcLineService rqcLineService;
  45 + @Resource
  46 + private MesQcIndicatorService indicatorService;
  47 + @Resource
  48 + private MesMdUnitMeasureService unitMeasureService;
  49 + @Resource
  50 + private MesTmToolService toolService;
  51 +
  52 + @GetMapping("/get")
  53 + @Operation(summary = "获得退货检验单行")
  54 + @Parameter(name = "id", description = "编号", required = true, example = "1024")
  55 + @PreAuthorize("@ss.hasPermission('mes:qc-rqc:query')")
  56 + public CommonResult<MesQcRqcLineRespVO> getRqcLine(@RequestParam("id") Long id) {
  57 + MesQcRqcLineDO line = rqcLineService.getRqcLine(id);
  58 + return success(buildLineRespVOList(Collections.singletonList(line)).get(0));
  59 + }
  60 +
  61 + @GetMapping("/page")
  62 + @Operation(summary = "获得退货检验单行分页")
  63 + @PreAuthorize("@ss.hasPermission('mes:qc-rqc:query')")
  64 + public CommonResult<PageResult<MesQcRqcLineRespVO>> getRqcLinePage(@Valid MesQcRqcLinePageReqVO pageReqVO) {
  65 + PageResult<MesQcRqcLineDO> pageResult = rqcLineService.getRqcLinePage(pageReqVO);
  66 + return success(new PageResult<>(buildLineRespVOList(pageResult.getList()), pageResult.getTotal()));
  67 + }
  68 +
  69 + // ==================== 拼接 VO ====================
  70 +
  71 + private List<MesQcRqcLineRespVO> buildLineRespVOList(List<MesQcRqcLineDO> list) {
  72 + if (CollUtil.isEmpty(list)) {
  73 + return Collections.emptyList();
  74 + }
  75 + // 批量查询检测指标
  76 + Map<Long, MesQcIndicatorDO> indicatorMap = indicatorService.getIndicatorMap(
  77 + convertSet(list, MesQcRqcLineDO::getIndicatorId));
  78 + // 批量查询计量单位
  79 + Map<Long, MesMdUnitMeasureDO> unitMeasureMap = unitMeasureService.getUnitMeasureMap(
  80 + convertSet(list, MesQcRqcLineDO::getUnitMeasureId));
  81 + // 拼装 VO
  82 + return BeanUtils.toBean(list, MesQcRqcLineRespVO.class, vo -> {
  83 + findAndThen(indicatorMap, vo.getIndicatorId(), indicator ->
  84 + vo.setIndicatorCode(indicator.getCode()).setIndicatorName(indicator.getName())
  85 + .setIndicatorType(indicator.getType()));
  86 + findAndThen(unitMeasureMap, vo.getUnitMeasureId(),
  87 + unit -> vo.setUnitMeasureName(unit.getName()));
  88 + // 逐个查询工具名称(工具数量通常较少)
  89 + if (vo.getToolId() != null) {
  90 + MesTmToolDO tool = toolService.getTool(vo.getToolId());
  91 + if (tool != null) {
  92 + vo.setToolName(tool.getName());
  93 + }
  94 + }
  95 + });
  96 + }
  97 +
  98 +}
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/qc/rqc/vo/MesQcRqcPageReqVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.mes.controller.admin.qc.rqc.vo;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.PageParam;
  4 +import io.swagger.v3.oas.annotations.media.Schema;
  5 +import lombok.Data;
  6 +import lombok.EqualsAndHashCode;
  7 +import lombok.ToString;
  8 +import org.springframework.format.annotation.DateTimeFormat;
  9 +
  10 +import java.time.LocalDateTime;
  11 +
  12 +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
  13 +
  14 +@Schema(description = "管理后台 - MES 退货检验单分页 Request VO")
  15 +@Data
  16 +@EqualsAndHashCode(callSuper = true)
  17 +@ToString(callSuper = true)
  18 +public class MesQcRqcPageReqVO extends PageParam {
  19 +
  20 + @Schema(description = "检验单编号", example = "RQC2025")
  21 + private String code;
  22 +
  23 + @Schema(description = "产品物料 ID", example = "20")
  24 + private Long itemId;
  25 +
  26 + @Schema(description = "退货检验类型", example = "1")
  27 + private String rqcType;
  28 +
  29 + @Schema(description = "检测结果", example = "1")
  30 + private Integer checkResult;
  31 +
  32 + @Schema(description = "状态", example = "0")
  33 + private Integer status;
  34 +
  35 + @Schema(description = "检测人员用户 ID", example = "1")
  36 + private Long inspectorUserId;
  37 +
  38 + @Schema(description = "检测日期")
  39 + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
  40 + private LocalDateTime[] inspectDate;
  41 +
  42 +}
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/qc/rqc/vo/MesQcRqcRespVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.mes.controller.admin.qc.rqc.vo;
  2 +
  3 +import cn.idev.excel.annotation.ExcelIgnoreUnannotated;
  4 +import cn.idev.excel.annotation.ExcelProperty;
  5 +import io.swagger.v3.oas.annotations.media.Schema;
  6 +import lombok.Data;
  7 +
  8 +import java.math.BigDecimal;
  9 +import java.time.LocalDateTime;
  10 +
  11 +@Schema(description = "管理后台 - MES 退货检验单 Response VO")
  12 +@Data
  13 +@ExcelIgnoreUnannotated
  14 +public class MesQcRqcRespVO {
  15 +
  16 + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
  17 + @ExcelProperty("编号")
  18 + private Long id;
  19 +
  20 + @Schema(description = "检验单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "RQC20250101001")
  21 + @ExcelProperty("检验单编号")
  22 + private String code;
  23 +
  24 + @Schema(description = "检验单名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "物料A退货检验")
  25 + @ExcelProperty("检验单名称")
  26 + private String name;
  27 +
  28 + @Schema(description = "检验模板 ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
  29 + private Long templateId;
  30 +
  31 + // ========== 来源单据 ==========
  32 +
  33 + @Schema(description = "来源单据 ID", example = "200")
  34 + private Long sourceDocId;
  35 +
  36 + @Schema(description = "来源单据类型", example = "RTISSUE")
  37 + private String sourceDocType;
  38 +
  39 + @Schema(description = "来源单据编号", example = "RT20250101001")
  40 + private String sourceDocCode;
  41 +
  42 + @Schema(description = "来源单据行 ID", example = "300")
  43 + private Long sourceLineId;
  44 +
  45 + // ========== 退货类型 ==========
  46 +
  47 + @Schema(description = "退货检验类型", example = "1")
  48 + @ExcelProperty("退货类型")
  49 + private String rqcType;
  50 +
  51 + // ========== 物料 ==========
  52 +
  53 + @Schema(description = "产品物料 ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "20")
  54 + private Long itemId;
  55 +
  56 + @Schema(description = "产品物料编码", example = "ITEM001")
  57 + @ExcelProperty("产品物料编码")
  58 + private String itemCode;
  59 +
  60 + @Schema(description = "产品物料名称", example = "物料A")
  61 + @ExcelProperty("产品物料名称")
  62 + private String itemName;
  63 +
  64 + @Schema(description = "规格型号", example = "100mm*50mm")
  65 + private String itemSpecification;
  66 +
  67 + @Schema(description = "单位名称", example = "个")
  68 + private String unitName;
  69 +
  70 + @Schema(description = "批次号", example = "BATCH001")
  71 + @ExcelProperty("批次号")
  72 + private String batchCode;
  73 +
  74 + // ========== 数量 ==========
  75 +
  76 + @Schema(description = "检测数量", example = "100")
  77 + @ExcelProperty("检测数量")
  78 + private BigDecimal checkQuantity;
  79 +
  80 + @Schema(description = "合格品数量", example = "90")
  81 + @ExcelProperty("合格品数量")
  82 + private BigDecimal qualifiedQuantity;
  83 +
  84 + @Schema(description = "不合格数量", example = "10")
  85 + @ExcelProperty("不合格数量")
  86 + private BigDecimal unqualifiedQuantity;
  87 +
  88 + // ========== 检验 ==========
  89 +
  90 + @Schema(description = "检测结果", example = "1")
  91 + @ExcelProperty("检测结果")
  92 + private Integer checkResult;
  93 +
  94 + @Schema(description = "检测日期")
  95 + @ExcelProperty("检测日期")
  96 + private LocalDateTime inspectDate;
  97 +
  98 + @Schema(description = "检测人员用户 ID", example = "1")
  99 + private Long inspectorUserId;
  100 +
  101 + @Schema(description = "检测人员昵称", example = "张三")
  102 + @ExcelProperty("检测人员")
  103 + private String inspectorNickname;
  104 +
  105 + @Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "0")
  106 + @ExcelProperty("状态")
  107 + private Integer status;
  108 +
  109 + @Schema(description = "备注", example = "备注")
  110 + @ExcelProperty("备注")
  111 + private String remark;
  112 +
  113 + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
  114 + @ExcelProperty("创建时间")
  115 + private LocalDateTime createTime;
  116 +
  117 +}
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/qc/rqc/vo/MesQcRqcSaveReqVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.mes.controller.admin.qc.rqc.vo;
  2 +
  3 +import io.swagger.v3.oas.annotations.media.Schema;
  4 +import jakarta.validation.constraints.NotEmpty;
  5 +import jakarta.validation.constraints.NotNull;
  6 +import lombok.Data;
  7 +
  8 +import java.math.BigDecimal;
  9 +import java.time.LocalDateTime;
  10 +
  11 +@Schema(description = "管理后台 - MES 退货检验单新增/修改 Request VO")
  12 +@Data
  13 +public class MesQcRqcSaveReqVO {
  14 +
  15 + @Schema(description = "编号", example = "1024")
  16 + private Long id;
  17 +
  18 + @Schema(description = "检验单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "RQC20250101001")
  19 + @NotEmpty(message = "检验单编号不能为空")
  20 + private String code;
  21 +
  22 + @Schema(description = "检验单名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "物料A退货检验")
  23 + @NotEmpty(message = "检验单名称不能为空")
  24 + private String name;
  25 +
  26 + @Schema(description = "检验模板 ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
  27 + @NotNull(message = "检验模板不能为空")
  28 + private Long templateId;
  29 +
  30 + // ========== 来源单据 ==========
  31 +
  32 + @Schema(description = "来源单据 ID", example = "200")
  33 + private Long sourceDocId;
  34 +
  35 + @Schema(description = "来源单据类型", example = "RTISSUE")
  36 + private String sourceDocType;
  37 +
  38 + @Schema(description = "来源单据编号", example = "RT20250101001")
  39 + private String sourceDocCode;
  40 +
  41 + @Schema(description = "来源单据行 ID", example = "300")
  42 + private Long sourceLineId;
  43 +
  44 + // ========== 退货类型 ==========
  45 +
  46 + @Schema(description = "退货检验类型", example = "1")
  47 + private String rqcType;
  48 +
  49 + // ========== 物料 ==========
  50 +
  51 + @Schema(description = "产品物料 ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "20")
  52 + @NotNull(message = "产品物料不能为空")
  53 + private Long itemId;
  54 +
  55 + @Schema(description = "批次号", example = "BATCH001")
  56 + private String batchCode;
  57 +
  58 + // ========== 数量 ==========
  59 +
  60 + @Schema(description = "检测数量", example = "100")
  61 + private BigDecimal checkQuantity;
  62 +
  63 + @Schema(description = "合格品数量", example = "90")
  64 + private BigDecimal qualifiedQuantity;
  65 +
  66 + @Schema(description = "不合格数量", example = "10")
  67 + private BigDecimal unqualifiedQuantity;
  68 +
  69 + // ========== 检验 ==========
  70 +
  71 + @Schema(description = "检测结果", example = "1")
  72 + private Integer checkResult;
  73 +
  74 + @Schema(description = "检测日期")
  75 + private LocalDateTime inspectDate;
  76 +
  77 + @Schema(description = "检测人员用户 ID", example = "1")
  78 + private Long inspectorUserId;
  79 +
  80 + @Schema(description = "备注", example = "备注")
  81 + private String remark;
  82 +
  83 +}
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/qc/rqc/vo/line/MesQcRqcLinePageReqVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.mes.controller.admin.qc.rqc.vo.line;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.PageParam;
  4 +import io.swagger.v3.oas.annotations.media.Schema;
  5 +import jakarta.validation.constraints.NotNull;
  6 +import lombok.Data;
  7 +import lombok.EqualsAndHashCode;
  8 +import lombok.ToString;
  9 +
  10 +@Schema(description = "管理后台 - MES 退货检验行分页 Request VO")
  11 +@Data
  12 +@EqualsAndHashCode(callSuper = true)
  13 +@ToString(callSuper = true)
  14 +public class MesQcRqcLinePageReqVO extends PageParam {
  15 +
  16 + @Schema(description = "退货检验单 ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
  17 + @NotNull(message = "退货检验单 ID 不能为空")
  18 + private Long rqcId;
  19 +
  20 +}
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/qc/rqc/vo/line/MesQcRqcLineRespVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.mes.controller.admin.qc.rqc.vo.line;
  2 +
  3 +import io.swagger.v3.oas.annotations.media.Schema;
  4 +import lombok.Data;
  5 +import lombok.experimental.Accessors;
  6 +
  7 +import java.math.BigDecimal;
  8 +import java.time.LocalDateTime;
  9 +
  10 +@Schema(description = "管理后台 - MES 退货检验行 Response VO")
  11 +@Data
  12 +@Accessors(chain = true)
  13 +public class MesQcRqcLineRespVO {
  14 +
  15 + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
  16 + private Long id;
  17 +
  18 + @Schema(description = "退货检验单 ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
  19 + private Long rqcId;
  20 +
  21 + @Schema(description = "检测指标 ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
  22 + private Long indicatorId;
  23 +
  24 + @Schema(description = "检测指标编码", example = "IND001")
  25 + private String indicatorCode;
  26 +
  27 + @Schema(description = "检测指标名称", example = "外观")
  28 + private String indicatorName;
  29 +
  30 + @Schema(description = "检测指标类型", example = "QUANTITATIVE")
  31 + private String indicatorType;
  32 +
  33 + @Schema(description = "检测工具 ID", example = "5")
  34 + private Long toolId;
  35 +
  36 + @Schema(description = "检测工具名称", example = "卡尺")
  37 + private String toolName;
  38 +
  39 + @Schema(description = "检测方法", example = "目测")
  40 + private String checkMethod;
  41 +
  42 + @Schema(description = "标准值", example = "10.5000")
  43 + private BigDecimal standardValue;
  44 +
  45 + @Schema(description = "计量单位 ID", example = "3")
  46 + private Long unitMeasureId;
  47 +
  48 + @Schema(description = "计量单位名称", example = "毫米")
  49 + private String unitMeasureName;
  50 +
  51 + @Schema(description = "误差上限", example = "11.0000")
  52 + private BigDecimal maxThreshold;
  53 +
  54 + @Schema(description = "误差下限", example = "10.0000")
  55 + private BigDecimal minThreshold;
  56 +
  57 + @Schema(description = "致命缺陷数量", example = "0")
  58 + private Integer criticalQuantity;
  59 +
  60 + @Schema(description = "严重缺陷数量", example = "0")
  61 + private Integer majorQuantity;
  62 +
  63 + @Schema(description = "轻微缺陷数量", example = "1")
  64 + private Integer minorQuantity;
  65 +
  66 + @Schema(description = "备注", example = "备注")
  67 + private String remark;
  68 +
  69 + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
  70 + private LocalDateTime createTime;
  71 +
  72 +}
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/dataobject/qc/oqc/MesQcOqcDO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.mes.dal.dataobject.qc.oqc;
  2 +
  3 +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
  4 +import cn.iocoder.yudao.module.mes.dal.dataobject.md.client.MesMdClientDO;
  5 +import cn.iocoder.yudao.module.mes.dal.dataobject.md.item.MesMdItemDO;
  6 +import cn.iocoder.yudao.module.mes.dal.dataobject.qc.template.MesQcTemplateDO;
  7 +import com.baomidou.mybatisplus.annotation.KeySequence;
  8 +import com.baomidou.mybatisplus.annotation.TableId;
  9 +import com.baomidou.mybatisplus.annotation.TableName;
  10 +import lombok.*;
  11 +
  12 +import java.math.BigDecimal;
  13 +import java.time.LocalDateTime;
  14 +
  15 +/**
  16 + * MES 出货检验单(OQC, Outgoing Quality Control) DO
  17 + *
  18 + * @author 芋道源码
  19 + */
  20 +@TableName("mes_qc_oqc")
  21 +@KeySequence("mes_qc_oqc_seq")
  22 +@Data
  23 +@EqualsAndHashCode(callSuper = true)
  24 +@ToString(callSuper = true)
  25 +@Builder
  26 +@NoArgsConstructor
  27 +@AllArgsConstructor
  28 +public class MesQcOqcDO extends BaseDO {
  29 +
  30 + /**
  31 + * 编号
  32 + */
  33 + @TableId
  34 + private Long id;
  35 + /**
  36 + * 检验单编号
  37 + */
  38 + private String code;
  39 + /**
  40 + * 检验单名称
  41 + */
  42 + private String name;
  43 + /**
  44 + * 检验模板 ID
  45 + *
  46 + * 关联 {@link MesQcTemplateDO#getId()}
  47 + */
  48 + private Long templateId;
  49 +
  50 + // ========== 来源单据(TODO @芋艿:WM 模块迁移后接入) ==========
  51 +
  52 + /**
  53 + * 来源单据 ID
  54 + */
  55 + private Long sourceDocId;
  56 + /**
  57 + * 来源单据类型
  58 + */
  59 + private String sourceDocType;
  60 + /**
  61 + * 来源单据编号
  62 + */
  63 + private String sourceDocCode;
  64 + /**
  65 + * 来源单据行 ID
  66 + */
  67 + private Long sourceLineId;
  68 +
  69 + // ========== 客户 ==========
  70 +
  71 + /**
  72 + * 客户 ID
  73 + *
  74 + * 关联 {@link MesMdClientDO#getId()}
  75 + */
  76 + private Long clientId;
  77 + /**
  78 + * 批次号
  79 + */
  80 + private String batchCode;
  81 +
  82 + // ========== 物料 ==========
  83 +
  84 + /**
  85 + * 产品物料 ID
  86 + *
  87 + * 关联 {@link MesMdItemDO#getId()}
  88 + */
  89 + private Long itemId;
  90 +
  91 + // ========== 数量 ==========
  92 +
  93 + /**
  94 + * 最低检测数
  95 + */
  96 + private Integer minCheckQuantity;
  97 + /**
  98 + * 最大不合格数
  99 + */
  100 + private Integer maxUnqualifiedQuantity;
  101 + /**
  102 + * 本次出货数量
  103 + */
  104 + private BigDecimal outQuantity;
  105 + /**
  106 + * 本次检测数量
  107 + */
  108 + private Integer checkQuantity;
  109 + /**
  110 + * 合格品数量
  111 + */
  112 + private Integer qualifiedQuantity;
  113 + /**
  114 + * 不合格品数量
  115 + */
  116 + private Integer unqualifiedQuantity;
  117 +
  118 + // ========== 缺陷统计 ==========
  119 +
  120 + /**
  121 + * 致命缺陷率(%)
  122 + */
  123 + private BigDecimal criticalRate;
  124 + /**
  125 + * 严重缺陷率(%)
  126 + */
  127 + private BigDecimal majorRate;
  128 + /**
  129 + * 轻微缺陷率(%)
  130 + */
  131 + private BigDecimal minorRate;
  132 + /**
  133 + * 致命缺陷数量
  134 + */
  135 + private Integer criticalQuantity;
  136 + /**
  137 + * 严重缺陷数量
  138 + */
  139 + private Integer majorQuantity;
  140 + /**
  141 + * 轻微缺陷数量
  142 + */
  143 + private Integer minorQuantity;
  144 +
  145 + // ========== 检验 ==========
  146 +
  147 + /**
  148 + * 检测结果
  149 + *
  150 + * 枚举 {@link cn.iocoder.yudao.module.mes.enums.qc.MesQcCheckResultEnum}
  151 + */
  152 + private Integer checkResult;
  153 + /**
  154 + * 出货日期
  155 + */
  156 + private LocalDateTime outDate;
  157 + /**
  158 + * 检测日期
  159 + */
  160 + private LocalDateTime inspectDate;
  161 + /**
  162 + * 检测人员用户 ID
  163 + *
  164 + * 关联 AdminUserDO 的 id
  165 + */
  166 + private Long inspectorUserId;
  167 + /**
  168 + * 状态
  169 + *
  170 + * 枚举 {@link cn.iocoder.yudao.module.mes.enums.qc.MesQcOqcStatusEnum}
  171 + */
  172 + private Integer status;
  173 + /**
  174 + * 备注
  175 + */
  176 + private String remark;
  177 +
  178 + // ========== 预留字段 ==========
  179 +
  180 + /**
  181 + * 预留字段 1
  182 + */
  183 + private String attribute1;
  184 + /**
  185 + * 预留字段 2
  186 + */
  187 + private String attribute2;
  188 + /**
  189 + * 预留字段 3
  190 + */
  191 + private Integer attribute3;
  192 + /**
  193 + * 预留字段 4
  194 + */
  195 + private Integer attribute4;
  196 +
  197 +}
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/dataobject/qc/oqc/MesQcOqcLineDO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.mes.dal.dataobject.qc.oqc;
  2 +
  3 +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
  4 +import cn.iocoder.yudao.module.mes.dal.dataobject.md.unitmeasure.MesMdUnitMeasureDO;
  5 +import cn.iocoder.yudao.module.mes.dal.dataobject.qc.indicator.MesQcIndicatorDO;
  6 +import com.baomidou.mybatisplus.annotation.KeySequence;
  7 +import com.baomidou.mybatisplus.annotation.TableId;
  8 +import com.baomidou.mybatisplus.annotation.TableName;
  9 +import lombok.*;
  10 +
  11 +import java.math.BigDecimal;
  12 +
  13 +/**
  14 + * MES 出货检验单行 DO
  15 + *
  16 + * @author 芋道源码
  17 + */
  18 +@TableName("mes_qc_oqc_line")
  19 +@KeySequence("mes_qc_oqc_line_seq")
  20 +@Data
  21 +@EqualsAndHashCode(callSuper = true)
  22 +@ToString(callSuper = true)
  23 +@Builder
  24 +@NoArgsConstructor
  25 +@AllArgsConstructor
  26 +public class MesQcOqcLineDO extends BaseDO {
  27 +
  28 + /**
  29 + * 编号
  30 + */
  31 + @TableId
  32 + private Long id;
  33 + /**
  34 + * 出货检验单 ID
  35 + *
  36 + * 关联 {@link MesQcOqcDO#getId()}
  37 + */
  38 + private Long oqcId;
  39 + /**
  40 + * 检测指标 ID
  41 + *
  42 + * 关联 {@link MesQcIndicatorDO#getId()}
  43 + */
  44 + private Long indicatorId;
  45 + /**
  46 + * 检测方法
  47 + */
  48 + private String checkMethod;
  49 + /**
  50 + * 标准值
  51 + */
  52 + private BigDecimal standardValue;
  53 + /**
  54 + * 计量单位 ID
  55 + *
  56 + * 关联 {@link MesMdUnitMeasureDO#getId()}
  57 + */
  58 + private Long unitMeasureId;
  59 + /**
  60 + * 误差上限
  61 + */
  62 + private BigDecimal maxThreshold;
  63 + /**
  64 + * 误差下限
  65 + */
  66 + private BigDecimal minThreshold;
  67 + /**
  68 + * 致命缺陷数量
  69 + */
  70 + private Integer criticalQuantity;
  71 + /**
  72 + * 严重缺陷数量
  73 + */
  74 + private Integer majorQuantity;
  75 + /**
  76 + * 轻微缺陷数量
  77 + */
  78 + private Integer minorQuantity;
  79 + /**
  80 + * 备注
  81 + */
  82 + private String remark;
  83 +
  84 + // ========== 预留字段 ==========
  85 +
  86 + /**
  87 + * 预留字段 1
  88 + */
  89 + private String attribute1;
  90 + /**
  91 + * 预留字段 2
  92 + */
  93 + private String attribute2;
  94 + /**
  95 + * 预留字段 3
  96 + */
  97 + private Integer attribute3;
  98 + /**
  99 + * 预留字段 4
  100 + */
  101 + private Integer attribute4;
  102 +
  103 +}
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/qc/oqc/MesQcOqcLineMapper.java 0 → 100644
  1 +package cn.iocoder.yudao.module.mes.dal.mysql.qc.oqc;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  4 +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
  5 +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
  6 +import cn.iocoder.yudao.module.mes.controller.admin.qc.oqc.vo.line.MesQcOqcLinePageReqVO;
  7 +import cn.iocoder.yudao.module.mes.dal.dataobject.qc.oqc.MesQcOqcLineDO;
  8 +import org.apache.ibatis.annotations.Mapper;
  9 +
  10 +import java.util.List;
  11 +
  12 +/**
  13 + * MES 出货检验单行 Mapper
  14 + *
  15 + * @author 芋道源码
  16 + */
  17 +@Mapper
  18 +public interface MesQcOqcLineMapper extends BaseMapperX<MesQcOqcLineDO> {
  19 +
  20 + default PageResult<MesQcOqcLineDO> selectPage(MesQcOqcLinePageReqVO reqVO) {
  21 + return selectPage(reqVO, new LambdaQueryWrapperX<MesQcOqcLineDO>()
  22 + .eqIfPresent(MesQcOqcLineDO::getOqcId, reqVO.getOqcId())
  23 + .orderByAsc(MesQcOqcLineDO::getId));
  24 + }
  25 +
  26 + default List<MesQcOqcLineDO> selectListByOqcId(Long oqcId) {
  27 + return selectList(MesQcOqcLineDO::getOqcId, oqcId);
  28 + }
  29 +
  30 + default void deleteByOqcId(Long oqcId) {
  31 + delete(new LambdaQueryWrapperX<MesQcOqcLineDO>()
  32 + .eq(MesQcOqcLineDO::getOqcId, oqcId));
  33 + }
  34 +
  35 +}
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/qc/oqc/MesQcOqcMapper.java 0 → 100644
  1 +package cn.iocoder.yudao.module.mes.dal.mysql.qc.oqc;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  4 +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
  5 +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
  6 +import cn.iocoder.yudao.module.mes.controller.admin.qc.oqc.vo.MesQcOqcPageReqVO;
  7 +import cn.iocoder.yudao.module.mes.dal.dataobject.qc.oqc.MesQcOqcDO;
  8 +import org.apache.ibatis.annotations.Mapper;
  9 +
  10 +/**
  11 + * MES 出货检验单(OQC) Mapper
  12 + *
  13 + * @author 芋道源码
  14 + */
  15 +@Mapper
  16 +public interface MesQcOqcMapper extends BaseMapperX<MesQcOqcDO> {
  17 +
  18 + default PageResult<MesQcOqcDO> selectPage(MesQcOqcPageReqVO reqVO) {
  19 + return selectPage(reqVO, new LambdaQueryWrapperX<MesQcOqcDO>()
  20 + .likeIfPresent(MesQcOqcDO::getCode, reqVO.getCode())
  21 + .eqIfPresent(MesQcOqcDO::getClientId, reqVO.getClientId())
  22 + .likeIfPresent(MesQcOqcDO::getBatchCode, reqVO.getBatchCode())
  23 + .eqIfPresent(MesQcOqcDO::getItemId, reqVO.getItemId())
  24 + .eqIfPresent(MesQcOqcDO::getCheckResult, reqVO.getCheckResult())
  25 + .eqIfPresent(MesQcOqcDO::getStatus, reqVO.getStatus())
  26 + .betweenIfPresent(MesQcOqcDO::getOutDate, reqVO.getOutDate())
  27 + .betweenIfPresent(MesQcOqcDO::getInspectDate, reqVO.getInspectDate())
  28 + .eqIfPresent(MesQcOqcDO::getInspectorUserId, reqVO.getInspectorUserId())
  29 + .orderByDesc(MesQcOqcDO::getId));
  30 + }
  31 +
  32 + default MesQcOqcDO selectByCode(String code) {
  33 + return selectOne(MesQcOqcDO::getCode, code);
  34 + }
  35 +
  36 +}
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/qc/oqc/MesQcOqcLineService.java 0 → 100644
  1 +package cn.iocoder.yudao.module.mes.service.qc.oqc;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  4 +import cn.iocoder.yudao.module.mes.controller.admin.qc.oqc.vo.line.MesQcOqcLinePageReqVO;
  5 +import cn.iocoder.yudao.module.mes.dal.dataobject.qc.defectrecord.MesQcDefectRecordDO;
  6 +import cn.iocoder.yudao.module.mes.dal.dataobject.qc.oqc.MesQcOqcLineDO;
  7 +
  8 +import java.util.List;
  9 +
  10 +/**
  11 + * MES 出货检验单行 Service 接口
  12 + *
  13 + * @author 芋道源码
  14 + */
  15 +public interface MesQcOqcLineService {
  16 +
  17 + /**
  18 + * 获得出货检验行
  19 + *
  20 + * @param id 编号
  21 + * @return 出货检验行
  22 + */
  23 + MesQcOqcLineDO getOqcLine(Long id);
  24 +
  25 + /**
  26 + * 获得出货检验行分页
  27 + *
  28 + * @param pageReqVO 分页查询
  29 + * @return 出货检验行分页
  30 + */
  31 + PageResult<MesQcOqcLineDO> getOqcLinePage(MesQcOqcLinePageReqVO pageReqVO);
  32 +
  33 + /**
  34 + * 根据出货检验单 ID 查询所有行
  35 + *
  36 + * @param oqcId 出货检验单 ID
  37 + * @return 行列表
  38 + */
  39 + List<MesQcOqcLineDO> getOqcLineListByOqcId(Long oqcId);
  40 +
  41 + /**
  42 + * 从模板指标自动生成检验行
  43 + *
  44 + * @param oqcId 出货检验单 ID
  45 + * @param templateId 模板 ID
  46 + */
  47 + void createLinesFromTemplate(Long oqcId, Long templateId);
  48 +
  49 + /**
  50 + * 根据出货检验单 ID 级联删除所有行
  51 + *
  52 + * @param oqcId 出货检验单 ID
  53 + */
  54 + void deleteByOqcId(Long oqcId);
  55 +
  56 + /**
  57 + * 校验出货检验行存在
  58 + *
  59 + * @param id 编号
  60 + * @return 出货检验行
  61 + */
  62 + MesQcOqcLineDO validateOqcLineExists(Long id);
  63 +
  64 + /**
  65 + * 根据缺陷记录重新计算行级缺陷统计
  66 + *
  67 + * @param oqcId 出货检验单 ID
  68 + * @param records 缺陷记录列表
  69 + */
  70 + void recalculateLineDefectStats(Long oqcId, List<MesQcDefectRecordDO> records);
  71 +
  72 +}
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/qc/oqc/MesQcOqcLineServiceImpl.java 0 → 100644
  1 +package cn.iocoder.yudao.module.mes.service.qc.oqc;
  2 +
  3 +import cn.hutool.core.collection.CollUtil;
  4 +import cn.hutool.core.util.ObjUtil;
  5 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  6 +import cn.iocoder.yudao.module.mes.controller.admin.qc.oqc.vo.line.MesQcOqcLinePageReqVO;
  7 +import cn.iocoder.yudao.module.mes.dal.dataobject.qc.defectrecord.MesQcDefectRecordDO;
  8 +import cn.iocoder.yudao.module.mes.dal.dataobject.qc.oqc.MesQcOqcLineDO;
  9 +import cn.iocoder.yudao.module.mes.dal.dataobject.qc.template.MesQcTemplateIndicatorDO;
  10 +import cn.iocoder.yudao.module.mes.dal.mysql.qc.oqc.MesQcOqcLineMapper;
  11 +import cn.iocoder.yudao.module.mes.dal.mysql.qc.template.MesQcTemplateIndicatorMapper;
  12 +import cn.iocoder.yudao.module.mes.enums.qc.MesQcDefectLevelEnum;
  13 +import jakarta.annotation.Resource;
  14 +import org.springframework.stereotype.Service;
  15 +import org.springframework.validation.annotation.Validated;
  16 +
  17 +import java.util.ArrayList;
  18 +import java.util.List;
  19 +import java.util.Objects;
  20 +
  21 +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
  22 +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
  23 +import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.*;
  24 +
  25 +/**
  26 + * MES 出货检验单行 Service 实现类
  27 + *
  28 + * @author 芋道源码
  29 + */
  30 +@Service
  31 +@Validated
  32 +public class MesQcOqcLineServiceImpl implements MesQcOqcLineService {
  33 +
  34 + @Resource
  35 + private MesQcOqcLineMapper oqcLineMapper;
  36 + @Resource
  37 + private MesQcTemplateIndicatorMapper templateIndicatorMapper;
  38 +
  39 + @Override
  40 + public MesQcOqcLineDO validateOqcLineExists(Long id) {
  41 + MesQcOqcLineDO line = oqcLineMapper.selectById(id);
  42 + if (line == null) {
  43 + throw exception(QC_OQC_LINE_NOT_EXISTS);
  44 + }
  45 + return line;
  46 + }
  47 +
  48 + @Override
  49 + public MesQcOqcLineDO getOqcLine(Long id) {
  50 + return oqcLineMapper.selectById(id);
  51 + }
  52 +
  53 + @Override
  54 + public PageResult<MesQcOqcLineDO> getOqcLinePage(MesQcOqcLinePageReqVO pageReqVO) {
  55 + return oqcLineMapper.selectPage(pageReqVO);
  56 + }
  57 +
  58 + @Override
  59 + public void createLinesFromTemplate(Long oqcId, Long templateId) {
  60 + List<MesQcTemplateIndicatorDO> indicators = templateIndicatorMapper.selectListByTemplateId(templateId);
  61 + List<MesQcOqcLineDO> lines = convertList(indicators, indicator -> new MesQcOqcLineDO()
  62 + .setOqcId(oqcId).setIndicatorId(indicator.getIndicatorId())
  63 + .setCheckMethod(indicator.getCheckMethod())
  64 + .setStandardValue(indicator.getStandardValue()).setUnitMeasureId(indicator.getUnitMeasureId())
  65 + .setMaxThreshold(indicator.getThresholdMax()).setMinThreshold(indicator.getThresholdMin())
  66 + .setCriticalQuantity(0).setMajorQuantity(0).setMinorQuantity(0));
  67 + oqcLineMapper.insertBatch(lines);
  68 + }
  69 +
  70 + @Override
  71 + public void recalculateLineDefectStats(Long oqcId, List<MesQcDefectRecordDO> records) {
  72 + List<MesQcOqcLineDO> lines = oqcLineMapper.selectListByOqcId(oqcId);
  73 + if (CollUtil.isEmpty(lines)) {
  74 + return;
  75 + }
  76 + List<MesQcOqcLineDO> updateLines = new ArrayList<>(lines.size());
  77 + for (MesQcOqcLineDO line : lines) {
  78 + int critical = 0, major = 0, minor = 0;
  79 + for (MesQcDefectRecordDO record : records) {
  80 + if (ObjUtil.notEqual(record.getLineId(), line.getId())) {
  81 + continue;
  82 + }
  83 + int quantity = ObjUtil.defaultIfNull(record.getQuantity(), 1);
  84 + if (Objects.equals(record.getLevel(), MesQcDefectLevelEnum.CRITICAL.getType())) {
  85 + critical += quantity;
  86 + } else if (Objects.equals(record.getLevel(), MesQcDefectLevelEnum.MAJOR.getType())) {
  87 + major += quantity;
  88 + } else if (Objects.equals(record.getLevel(), MesQcDefectLevelEnum.MINOR.getType())) {
  89 + minor += quantity;
  90 + } else {
  91 + throw exception(QC_DEFECT_RECORD_LEVEL_UNKNOWN);
  92 + }
  93 + }
  94 + updateLines.add(new MesQcOqcLineDO().setId(line.getId())
  95 + .setCriticalQuantity(critical).setMajorQuantity(major).setMinorQuantity(minor));
  96 + }
  97 + for (MesQcOqcLineDO updateLine : updateLines) {
  98 + oqcLineMapper.updateById(updateLine);
  99 + }
  100 + }
  101 +
  102 + @Override
  103 + public List<MesQcOqcLineDO> getOqcLineListByOqcId(Long oqcId) {
  104 + return oqcLineMapper.selectListByOqcId(oqcId);
  105 + }
  106 +
  107 + @Override
  108 + public void deleteByOqcId(Long oqcId) {
  109 + oqcLineMapper.deleteByOqcId(oqcId);
  110 + }
  111 +
  112 +}
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/qc/oqc/MesQcOqcService.java 0 → 100644
  1 +package cn.iocoder.yudao.module.mes.service.qc.oqc;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  4 +import cn.iocoder.yudao.module.mes.controller.admin.qc.oqc.vo.MesQcOqcPageReqVO;
  5 +import cn.iocoder.yudao.module.mes.controller.admin.qc.oqc.vo.MesQcOqcSaveReqVO;
  6 +import cn.iocoder.yudao.module.mes.dal.dataobject.qc.defectrecord.MesQcDefectRecordDO;
  7 +import cn.iocoder.yudao.module.mes.dal.dataobject.qc.oqc.MesQcOqcDO;
  8 +import jakarta.validation.Valid;
  9 +
  10 +import java.util.List;
  11 +
  12 +/**
  13 + * MES 出货检验单(OQC) Service 接口
  14 + *
  15 + * @author 芋道源码
  16 + */
  17 +public interface MesQcOqcService {
  18 +
  19 + /**
  20 + * 创建出货检验单
  21 + *
  22 + * @param createReqVO 创建信息
  23 + * @return 编号
  24 + */
  25 + Long createOqc(@Valid MesQcOqcSaveReqVO createReqVO);
  26 +
  27 + /**
  28 + * 更新出货检验单
  29 + *
  30 + * @param updateReqVO 更新信息
  31 + */
  32 + void updateOqc(@Valid MesQcOqcSaveReqVO updateReqVO);
  33 +
  34 + /**
  35 + * 完成出货检验单
  36 + *
  37 + * @param id 编号
  38 + */
  39 + void completeOqc(Long id);
  40 +
  41 + /**
  42 + * 删除出货检验单
  43 + *
  44 + * @param id 编号
  45 + */
  46 + void deleteOqc(Long id);
  47 +
  48 + /**
  49 + * 校验出货检验单存在
  50 + *
  51 + * @param id 编号
  52 + * @return 出货检验单
  53 + */
  54 + MesQcOqcDO validateOqcExists(Long id);
  55 +
  56 + /**
  57 + * 获得出货检验单
  58 + *
  59 + * @param id 编号
  60 + * @return 出货检验单
  61 + */
  62 + MesQcOqcDO getOqc(Long id);
  63 +
  64 + /**
  65 + * 获得出货检验单分页
  66 + *
  67 + * @param pageReqVO 分页查询
  68 + * @return 出货检验单分页
  69 + */
  70 + PageResult<MesQcOqcDO> getOqcPage(MesQcOqcPageReqVO pageReqVO);
  71 +
  72 + /**
  73 + * 根据缺陷记录重新计算主表的缺陷统计(含行级下沉)
  74 + *
  75 + * @param oqcId 出货检验单 ID
  76 + * @param records 缺陷记录列表
  77 + */
  78 + void recalculateDefectStats(Long oqcId, List<MesQcDefectRecordDO> records);
  79 +
  80 +}
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/qc/oqc/MesQcOqcServiceImpl.java 0 → 100644
  1 +package cn.iocoder.yudao.module.mes.service.qc.oqc;
  2 +
  3 +import cn.hutool.core.collection.CollUtil;
  4 +import cn.hutool.core.util.ObjUtil;
  5 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  6 +import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
  7 +import cn.iocoder.yudao.module.mes.controller.admin.qc.oqc.vo.MesQcOqcPageReqVO;
  8 +import cn.iocoder.yudao.module.mes.controller.admin.qc.oqc.vo.MesQcOqcSaveReqVO;
  9 +import cn.iocoder.yudao.module.mes.dal.dataobject.qc.defectrecord.MesQcDefectRecordDO;
  10 +import cn.iocoder.yudao.module.mes.dal.dataobject.qc.oqc.MesQcOqcDO;
  11 +import cn.iocoder.yudao.module.mes.dal.dataobject.qc.template.MesQcTemplateDO;
  12 +import cn.iocoder.yudao.module.mes.dal.dataobject.qc.template.MesQcTemplateItemDO;
  13 +import cn.iocoder.yudao.module.mes.dal.mysql.qc.oqc.MesQcOqcMapper;
  14 +import cn.iocoder.yudao.module.mes.enums.qc.MesQcDefectLevelEnum;
  15 +import cn.iocoder.yudao.module.mes.enums.qc.MesQcOqcStatusEnum;
  16 +import cn.iocoder.yudao.module.mes.enums.qc.MesQcTypeEnum;
  17 +import cn.iocoder.yudao.module.mes.service.qc.defectrecord.MesQcDefectRecordService;
  18 +import cn.iocoder.yudao.module.mes.service.qc.template.MesQcTemplateService;
  19 +import jakarta.annotation.Resource;
  20 +import org.springframework.context.annotation.Lazy;
  21 +import org.springframework.stereotype.Service;
  22 +import org.springframework.transaction.annotation.Transactional;
  23 +import org.springframework.validation.annotation.Validated;
  24 +
  25 +import java.math.BigDecimal;
  26 +import java.math.RoundingMode;
  27 +import java.util.List;
  28 +import java.util.Objects;
  29 +
  30 +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
  31 +import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.*;
  32 +
  33 +/**
  34 + * MES 出货检验单(OQC) Service 实现类
  35 + *
  36 + * @author 芋道源码
  37 + */
  38 +@Service
  39 +@Validated
  40 +public class MesQcOqcServiceImpl implements MesQcOqcService {
  41 +
  42 + @Resource
  43 + private MesQcOqcMapper oqcMapper;
  44 + @Resource
  45 + private MesQcTemplateService templateService;
  46 + @Resource
  47 + private MesQcOqcLineService oqcLineService;
  48 + @Resource
  49 + @Lazy
  50 + private MesQcDefectRecordService defectRecordService;
  51 +
  52 + @Override
  53 + @Transactional(rollbackFor = Exception.class)
  54 + public Long createOqc(MesQcOqcSaveReqVO createReqVO) {
  55 + // 1.1 校验编号唯一
  56 + validateOqcCodeUnique(null, createReqVO.getCode());
  57 + // 1.2 校验模板存在且包含 OQC 类型
  58 + Long templateId = createReqVO.getTemplateId();
  59 + MesQcTemplateDO template = templateService.validateTemplateExists(templateId);
  60 + if (!CollUtil.contains(template.getTypes(), MesQcTypeEnum.OQC.getType())) {
  61 + throw exception(QC_OQC_NO_TEMPLATE);
  62 + }
  63 +
  64 + // 1.3 从模板的产品关联中获取检测参数
  65 + // TODO @芋艿:【暂时不用删除】到底 miniCheckQuantity 和 maxUnqualifiedQuantity 是否有必要存储?
  66 + MesQcTemplateItemDO templateItem = templateService.getTemplateItemByTemplateIdAndItemId(
  67 + templateId, createReqVO.getItemId());
  68 + if (templateItem != null) {
  69 + if (createReqVO.getMinCheckQuantity() == null) {
  70 + createReqVO.setMinCheckQuantity(templateItem.getQuantityCheck());
  71 + }
  72 + if (createReqVO.getMaxUnqualifiedQuantity() == null) {
  73 + createReqVO.setMaxUnqualifiedQuantity(templateItem.getQuantityUnqualified());
  74 + }
  75 + }
  76 +
  77 + // 2. 插入主表
  78 + MesQcOqcDO oqc = BeanUtils.toBean(createReqVO, MesQcOqcDO.class);
  79 + oqc.setStatus(MesQcOqcStatusEnum.PREPARE.getType());
  80 + oqcMapper.insert(oqc);
  81 +
  82 + // 3. 从模板指标自动生成检验行
  83 + oqcLineService.createLinesFromTemplate(oqc.getId(), templateId);
  84 + return oqc.getId();
  85 + }
  86 +
  87 + @Override
  88 + public void updateOqc(MesQcOqcSaveReqVO updateReqVO) {
  89 + // 1.1 校验存在 + 草稿状态
  90 + validateOqcStatusPrepare(updateReqVO.getId());
  91 + // 1.2 校验编号唯一
  92 + validateOqcCodeUnique(updateReqVO.getId(), updateReqVO.getCode());
  93 +
  94 + // 2. 更新
  95 + MesQcOqcDO updateObj = BeanUtils.toBean(updateReqVO, MesQcOqcDO.class);
  96 + oqcMapper.updateById(updateObj);
  97 + }
  98 +
  99 + @Override
  100 + public void completeOqc(Long id) {
  101 + // 1.1 校验存在 + 草稿状态
  102 + MesQcOqcDO oqc = validateOqcStatusPrepare(id);
  103 + // 1.2 校验合格品 + 不合格品 = 检测数量
  104 + if (oqc.getCheckQuantity() != null && oqc.getCheckQuantity() > 0) {
  105 + int total = (oqc.getQualifiedQuantity() != null ? oqc.getQualifiedQuantity() : 0)
  106 + + (oqc.getUnqualifiedQuantity() != null ? oqc.getUnqualifiedQuantity() : 0);
  107 + if (total != oqc.getCheckQuantity()) {
  108 + throw exception(QC_OQC_QUANTITY_MISMATCH);
  109 + }
  110 + }
  111 +
  112 + // 2. 更新状态为已完成
  113 + MesQcOqcDO updateObj = new MesQcOqcDO()
  114 + .setId(id).setStatus(MesQcOqcStatusEnum.FINISHED.getType());
  115 + oqcMapper.updateById(updateObj);
  116 +
  117 + // TODO @芋艿:WM 模块迁移后,更新销售出库单行的检验结果
  118 + }
  119 +
  120 + @Override
  121 + @Transactional(rollbackFor = Exception.class)
  122 + public void deleteOqc(Long id) {
  123 + // 1. 校验存在 + 草稿状态
  124 + validateOqcStatusPrepare(id);
  125 +
  126 + // 2.1 删除主表
  127 + oqcMapper.deleteById(id);
  128 + // 2.2 级联删除行
  129 + oqcLineService.deleteByOqcId(id);
  130 + // 2.3 级联删除缺陷记录
  131 + defectRecordService.deleteByQcTypeAndQcId(MesQcTypeEnum.OQC.getType(), id);
  132 + }
  133 +
  134 + @Override
  135 + public MesQcOqcDO validateOqcExists(Long id) {
  136 + MesQcOqcDO oqc = oqcMapper.selectById(id);
  137 + if (oqc == null) {
  138 + throw exception(QC_OQC_NOT_EXISTS);
  139 + }
  140 + return oqc;
  141 + }
  142 +
  143 + /**
  144 + * 校验出货检验单存在且为草稿状态
  145 + */
  146 + private MesQcOqcDO validateOqcStatusPrepare(Long id) {
  147 + MesQcOqcDO oqc = validateOqcExists(id);
  148 + if (ObjUtil.notEqual(oqc.getStatus(), MesQcOqcStatusEnum.PREPARE.getType())) {
  149 + throw exception(QC_OQC_NOT_PREPARE);
  150 + }
  151 + return oqc;
  152 + }
  153 +
  154 + private void validateOqcCodeUnique(Long id, String code) {
  155 + MesQcOqcDO oqc = oqcMapper.selectByCode(code);
  156 + if (oqc == null) {
  157 + return;
  158 + }
  159 + if (ObjUtil.notEqual(oqc.getId(), id)) {
  160 + throw exception(QC_OQC_CODE_DUPLICATE);
  161 + }
  162 + }
  163 +
  164 + @Override
  165 + public MesQcOqcDO getOqc(Long id) {
  166 + return oqcMapper.selectById(id);
  167 + }
  168 +
  169 + @Override
  170 + public PageResult<MesQcOqcDO> getOqcPage(MesQcOqcPageReqVO pageReqVO) {
  171 + return oqcMapper.selectPage(pageReqVO);
  172 + }
  173 +
  174 + @Override
  175 + public void recalculateDefectStats(Long oqcId, List<MesQcDefectRecordDO> records) {
  176 + // 1. 行级缺陷统计
  177 + oqcLineService.recalculateLineDefectStats(oqcId, records);
  178 +
  179 + // 2.1 汇总主表的缺陷数量
  180 + int totalCritical = 0, totalMajor = 0, totalMinor = 0;
  181 + for (MesQcDefectRecordDO record : records) {
  182 + int quantity = ObjUtil.defaultIfNull(record.getQuantity(), 1);
  183 + if (Objects.equals(record.getLevel(), MesQcDefectLevelEnum.CRITICAL.getType())) {
  184 + totalCritical += quantity;
  185 + } else if (Objects.equals(record.getLevel(), MesQcDefectLevelEnum.MAJOR.getType())) {
  186 + totalMajor += quantity;
  187 + } else if (Objects.equals(record.getLevel(), MesQcDefectLevelEnum.MINOR.getType())) {
  188 + totalMinor += quantity;
  189 + } else {
  190 + throw exception(QC_DEFECT_RECORD_LEVEL_UNKNOWN);
  191 + }
  192 + }
  193 + // 2.2 计算缺陷率
  194 + MesQcOqcDO oqc = validateOqcExists(oqcId);
  195 + BigDecimal criticalRate = BigDecimal.ZERO;
  196 + BigDecimal majorRate = BigDecimal.ZERO;
  197 + BigDecimal minorRate = BigDecimal.ZERO;
  198 + if (oqc.getCheckQuantity() != null && oqc.getCheckQuantity() > 0) {
  199 + BigDecimal checkQty = BigDecimal.valueOf(oqc.getCheckQuantity());
  200 + criticalRate = BigDecimal.valueOf(totalCritical).multiply(BigDecimal.valueOf(100))
  201 + .divide(checkQty, 2, RoundingMode.HALF_UP);
  202 + majorRate = BigDecimal.valueOf(totalMajor).multiply(BigDecimal.valueOf(100))
  203 + .divide(checkQty, 2, RoundingMode.HALF_UP);
  204 + minorRate = BigDecimal.valueOf(totalMinor).multiply(BigDecimal.valueOf(100))
  205 + .divide(checkQty, 2, RoundingMode.HALF_UP);
  206 + }
  207 +
  208 + // 3. 更新主表
  209 + MesQcOqcDO updateOqc = new MesQcOqcDO().setId(oqcId)
  210 + .setCriticalQuantity(totalCritical).setMajorQuantity(totalMajor).setMinorQuantity(totalMinor)
  211 + .setCriticalRate(criticalRate).setMajorRate(majorRate).setMinorRate(minorRate);
  212 + oqcMapper.updateById(updateOqc);
  213 + }
  214 +
  215 +}
... ...