云
2 天以前 4966ba8b88ca9d6f3a7f93489d0e18a78a44a3c5
feat(mes): 新增MES质量巡检模块及前后端功能

- 新增质量巡检后端接口与数据访问层实现增删改查
- 新增前端巡检记录列表页及查询和表单弹窗功能
- 新增质检附件上传组件并集成至巡检记录表单中
- 新增Excel必填注解及导出表头必填项标红处理器
- 更新gitignore以忽略.playwright-mcp和.tmp目录
已添加4个文件
已修改1个文件
138 ■■■■■ 文件已修改
.gitignore 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/handler/ExcelRequired.java 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/handler/RequiredHeaderWriteHandler.java 52 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/qc/patrol/MesQcPatrolController.java 65 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/qc/patrol/PatrolMapper.java 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
.gitignore
@@ -1,5 +1,7 @@
######################################################################
# Build Tools
.playwright-mcp
.tmp
.gradle
/build/
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 {}
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;
    }
}
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,"巡检数量必须大于零"); }
}
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> {
}