From 4966ba8b88ca9d6f3a7f93489d0e18a78a44a3c5 Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期五, 06 十一月 2026 09:19:54 +0800
Subject: [PATCH] feat(mes): 新增MES质量巡检模块及前后端功能

---
 .gitignore                                                                                                                                  |    2 
 yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/qc/patrol/MesQcPatrolController.java                            |   65 +++++++++++++++++++++
 yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/qc/patrol/PatrolMapper.java                                     |    8 ++
 yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/handler/ExcelRequired.java              |   11 +++
 yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/handler/RequiredHeaderWriteHandler.java |   52 +++++++++++++++++
 5 files changed, 138 insertions(+), 0 deletions(-)

diff --git a/.gitignore b/.gitignore
index 4c35ec0..316e54b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,7 @@
 ######################################################################
 # Build Tools
+.playwright-mcp
+.tmp
 
 .gradle
 /build/
diff --git a/yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/handler/ExcelRequired.java b/yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/handler/ExcelRequired.java
new file mode 100644
index 0000000..3658b7e
--- /dev/null
+++ b/yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/handler/ExcelRequired.java
@@ -0,0 +1,11 @@
+package cn.iocoder.yudao.framework.excel.core.handler;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/** 琛ㄦ槑瀵煎叆妯℃澘璇ュ垪鏃犳潯浠跺繀濉紝浠呮敼鍙樻ā鏉挎牱寮忥紝涓嶆敼鍙樺瓧娈靛悕绉版垨鏍¢獙閫昏緫銆� */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.FIELD)
+public @interface ExcelRequired {}
diff --git a/yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/handler/RequiredHeaderWriteHandler.java b/yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/handler/RequiredHeaderWriteHandler.java
new file mode 100644
index 0000000..d4755fb
--- /dev/null
+++ b/yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/handler/RequiredHeaderWriteHandler.java
@@ -0,0 +1,52 @@
+package cn.iocoder.yudao.framework.excel.core.handler;
+
+import cn.idev.excel.write.handler.CellWriteHandler;
+import cn.idev.excel.write.handler.context.CellWriteHandlerContext;
+import jakarta.validation.constraints.NotBlank;
+import jakarta.validation.constraints.NotEmpty;
+import jakarta.validation.constraints.NotNull;
+import org.apache.poi.ss.usermodel.*;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
+import java.util.HashMap;
+import java.util.Map;
+
+/** 浠呬慨鏀瑰繀濉〃澶村瓧浣撻鑹诧紱涓嶆敼鍙樿〃澶存枃鏈紝浠ュ厤鐮村潖瀵煎叆鍖归厤銆� */
+public class RequiredHeaderWriteHandler implements CellWriteHandler {
+    private final Map<Short, CellStyle> redStyles = new HashMap<>();
+    @Override public int order() { return 50000; }
+    @Override public void afterCellDispose(CellWriteHandlerContext context) {
+        if (!Boolean.TRUE.equals(context.getHead()) || context.getHeadData() == null) return;
+        Field field = context.getHeadData().getField();
+        if (field == null || !required(field)) return;
+        Cell cell = context.getCell();
+        Workbook workbook = cell.getSheet().getWorkbook();
+        CellStyle old = cell.getCellStyle();
+        CellStyle style = redStyles.computeIfAbsent(old.getIndex(), index -> {
+            CellStyle copy = workbook.createCellStyle();
+            copy.cloneStyleFrom(old);
+            Font source = workbook.getFontAt(old.getFontIndex());
+            Font font = workbook.createFont();
+            font.setFontName(source.getFontName()); font.setFontHeight(source.getFontHeight());
+            font.setBold(source.getBold()); font.setItalic(source.getItalic());
+            font.setUnderline(source.getUnderline()); font.setStrikeout(source.getStrikeout());
+            font.setTypeOffset(source.getTypeOffset()); font.setCharSet(source.getCharSet());
+            font.setColor(IndexedColors.RED.getIndex());
+            copy.setFont(font);
+            return copy;
+        });
+        cell.setCellStyle(style);
+    }
+    private boolean required(Field field) {
+        if (field.isAnnotationPresent(ExcelRequired.class) || field.isAnnotationPresent(NotNull.class)
+                || field.isAnnotationPresent(NotBlank.class) || field.isAnnotationPresent(NotEmpty.class)) return true;
+        // Import VO 涓父鐢� OpenAPI 鐨� requiredMode 鏍囨槑蹇呭~锛涢伩鍏� Excel 妯″潡渚濊禆 Swagger銆�
+        for (Annotation annotation : field.getAnnotations()) {
+            if (!annotation.annotationType().getName().equals("io.swagger.v3.oas.annotations.media.Schema")) continue;
+            try {
+                if ("REQUIRED".equals(String.valueOf(annotation.annotationType().getMethod("requiredMode").invoke(annotation)))) return true;
+            } catch (ReflectiveOperationException ignored) { return false; }
+        }
+        return false;
+    }
+}
diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/qc/patrol/MesQcPatrolController.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/qc/patrol/MesQcPatrolController.java
new file mode 100644
index 0000000..b8c15db
--- /dev/null
+++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/qc/patrol/MesQcPatrolController.java
@@ -0,0 +1,65 @@
+package cn.iocoder.yudao.module.mes.controller.admin.qc.patrol;
+
+import cn.iocoder.yudao.framework.common.exception.ServiceException;
+import cn.iocoder.yudao.framework.common.pojo.CommonResult;
+import cn.iocoder.yudao.framework.common.pojo.PageParam;
+import cn.iocoder.yudao.framework.common.pojo.PageResult;
+import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
+import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
+import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import jakarta.annotation.Resource;
+import jakarta.validation.Valid;
+import jakarta.validation.constraints.*;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import org.apache.ibatis.annotations.Mapper;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+import java.math.BigDecimal;
+import java.time.LocalDateTime;
+import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
+
+@RestController
+@RequestMapping("/mes/qc/patrol")
+@Validated
+public class MesQcPatrolController {
+    @Resource private PatrolMapper mapper;
+    @Resource private cn.iocoder.yudao.module.mdm.api.item.MdmItemApi itemApi;
+    @Resource private cn.iocoder.yudao.module.system.api.user.AdminUserApi userApi;
+
+    @TableName("mes_qc_patrol") @Data @EqualsAndHashCode(callSuper = true)
+    public static class Patrol extends BaseDO {
+        @TableId private Long id;
+        @NotBlank @Size(max=100) private String code;
+        @NotBlank @Size(max=255) private String name;
+        @NotNull private Long itemId;
+        @Size(max=128) private String reelNo;
+        @Size(max=128) private String batchCode;
+        @NotNull @DecimalMin("0") private BigDecimal qualifiedQuantity;
+        @NotNull @DecimalMin("0") private BigDecimal unqualifiedQuantity;
+        @NotNull private LocalDateTime inspectDate;
+        @NotNull private Long inspectorUserId;
+        @Size(max=1000) private String remark;
+    }
+    @Data @EqualsAndHashCode(callSuper=true) public static class Query extends PageParam { private String code; private String reelNo; private Long itemId; }
+
+    @GetMapping("/page") @PreAuthorize("@ss.hasPermission('mes:qc-patrol:query')")
+    public CommonResult<PageResult<Patrol>> page(@Valid Query query) {
+        return success(mapper.selectPage(query, new LambdaQueryWrapperX<Patrol>()
+                .likeIfPresent(Patrol::getCode, query.getCode()).likeIfPresent(Patrol::getReelNo, query.getReelNo())
+                .eqIfPresent(Patrol::getItemId, query.getItemId()).orderByDesc(Patrol::getId)));
+    }
+    @GetMapping("/get") @PreAuthorize("@ss.hasPermission('mes:qc-patrol:query')")
+    public CommonResult<Patrol> get(@RequestParam Long id) { return success(require(id)); }
+    @PostMapping("/create") @PreAuthorize("@ss.hasPermission('mes:qc-patrol:create')")
+    public CommonResult<Long> create(@Valid @RequestBody Patrol row) { row.setId(null); validate(row); mapper.insert(row); return success(row.getId()); }
+    @PutMapping("/update") @PreAuthorize("@ss.hasPermission('mes:qc-patrol:update')")
+    public CommonResult<Boolean> update(@Valid @RequestBody Patrol row) { if(row.getId()==null) throw new ServiceException(400,"璁板綍缂栧彿涓嶈兘涓虹┖"); require(row.getId()); validate(row); mapper.updateById(row); return success(true); }
+    @DeleteMapping("/delete") @PreAuthorize("@ss.hasPermission('mes:qc-patrol:delete')")
+    public CommonResult<Boolean> delete(@RequestParam Long id) { require(id); mapper.deleteById(id); return success(true); }
+    private Patrol require(Long id) { Patrol p=mapper.selectById(id); if(p==null) throw new ServiceException(400,"宸℃璁板綍涓嶅瓨鍦�"); return p; }
+    private void validate(Patrol row) { itemApi.validateItemExists(row.getItemId()); userApi.validateUser(row.getInspectorUserId()); if(row.getQualifiedQuantity().add(row.getUnqualifiedQuantity()).signum()<=0) throw new ServiceException(400,"宸℃鏁伴噺蹇呴』澶т簬闆�"); }
+}
diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/qc/patrol/PatrolMapper.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/qc/patrol/PatrolMapper.java
new file mode 100644
index 0000000..c8634d2
--- /dev/null
+++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/qc/patrol/PatrolMapper.java
@@ -0,0 +1,8 @@
+package cn.iocoder.yudao.module.mes.controller.admin.qc.patrol;
+
+import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
+import org.apache.ibatis.annotations.Mapper;
+
+@Mapper
+public interface PatrolMapper extends BaseMapperX<MesQcPatrolController.Patrol> {
+}

--
Gitblit v1.9.3