yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/pro/feedback/MesProFeedbackController.java
@@ -4,13 +4,25 @@
import cn.hutool.core.collection.ListUtil;
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
import cn.iocoder.yudao.module.mes.service.pro.feedback.dto.MesTaskParamSnapshot;
import cn.iocoder.yudao.module.mes.service.pro.feedback.dto.MesFeedbackParamSnapshot;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.module.mes.controller.admin.pro.feedback.vo.MesProFeedbackApproveReqVO;
import cn.iocoder.yudao.module.mes.controller.admin.pro.feedback.vo.MesProFeedbackBatchCheckRespVO;
import cn.iocoder.yudao.module.mes.controller.admin.pro.feedback.vo.MesProFeedbackBatchCreateReqVO;
import cn.iocoder.yudao.module.mes.controller.admin.pro.feedback.vo.MesProFeedbackBatchCreateRespVO;
import cn.iocoder.yudao.module.mes.controller.admin.pro.feedback.vo.MesProFeedbackImportExcelVO;
import cn.iocoder.yudao.module.mes.controller.admin.pro.feedback.vo.MesProFeedbackImportRespVO;
import cn.iocoder.yudao.module.mes.controller.admin.pro.feedback.vo.MesProFeedbackPageReqVO;
import cn.iocoder.yudao.module.mes.controller.admin.pro.feedback.vo.MesProFeedbackQuickCreateReqVO;
import cn.iocoder.yudao.module.mes.controller.admin.pro.feedback.vo.MesProFeedbackQuickCreateRespVO;
import cn.iocoder.yudao.module.mes.controller.admin.pro.feedback.vo.MesProFeedbackRespVO;
import cn.iocoder.yudao.module.mes.controller.admin.pro.feedback.vo.MesProFeedbackSaveReqVO;
import cn.iocoder.yudao.module.mes.controller.admin.pro.feedback.vo.MesProFeedbackSummaryRespVO;
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.md.workstation.MesMdWorkstationDO;
@@ -33,13 +45,16 @@
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import cn.iocoder.yudao.module.mes.controller.admin.pro.feedback.vo.MesProFeedbackTraceRespVO;
import cn.iocoder.yudao.module.mes.dal.dataobject.qc.ipqc.MesQcIpqcDO;
@@ -55,6 +70,7 @@
import cn.iocoder.yudao.module.mes.enums.MesBizTypeConstants;
import java.io.IOException;
import java.time.LocalDate;
import java.util.*;
import java.util.stream.Stream;
@@ -130,7 +146,6 @@
    @GetMapping("/get")
    @Operation(summary = "获得生产报工")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('mes:pro-feedback:query')")
    public CommonResult<MesProFeedbackRespVO> getFeedback(@RequestParam("id") Long id) {
        MesProFeedbackDO feedback = feedbackService.getFeedback(id);
        if (feedback == null) {
@@ -141,16 +156,25 @@
    @GetMapping("/page")
    @Operation(summary = "获得生产报工分页")
    @PreAuthorize("@ss.hasPermission('mes:pro-feedback:query')")
    public CommonResult<PageResult<MesProFeedbackRespVO>> getFeedbackPage(@Valid MesProFeedbackPageReqVO pageReqVO) {
        PageResult<MesProFeedbackDO> pageResult = feedbackService.getFeedbackPage(pageReqVO);
        return success(new PageResult<>(buildFeedbackRespVOList(pageResult.getList()), pageResult.getTotal()));
    }
    @GetMapping("/param-config")
    @Operation(summary = "获得生产任务冻结的参数采集配置")
    public CommonResult<Map<String, Object>> getParamConfig(@RequestParam("taskId") Long taskId) {
        MesProTaskDO task = taskService.validateTaskExists(taskId);
        Map<String, Object> result = new LinkedHashMap<>();
        result.put("mode", task.getParamCollectMode() == null ? 0 : task.getParamCollectMode());
        result.put("template", JsonUtils.parseObject(task.getParamTemplateSnapshot(), MesTaskParamSnapshot.class));
        result.put("shared", JsonUtils.parseObject(task.getParamSharedSnapshot(), MesFeedbackParamSnapshot.class));
        return success(result);
    }
    @GetMapping("/list-by-task")
    @Operation(summary = "按任务获得报工历史列表")
    @Parameter(name = "taskId", description = "任务编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('mes:pro-feedback:query')")
    public CommonResult<List<MesProFeedbackRespVO>> getFeedbackListByTask(@RequestParam("taskId") Long taskId) {
        List<MesProFeedbackDO> list = feedbackService.getFeedbackListByTaskId(taskId);
        return success(buildFeedbackRespVOList(list));
@@ -166,6 +190,38 @@
        List<MesProFeedbackDO> list = feedbackService.getFeedbackPage(pageReqVO).getList();
        List<MesProFeedbackRespVO> voList = buildFeedbackRespVOList(list);
        ExcelUtils.write(response, "生产报工.xls", "数据", MesProFeedbackRespVO.class, voList);
    }
    @GetMapping("/get-import-template")
    @Operation(summary = "获得生产报工导入模板")
    public void importTemplate(HttpServletResponse response) throws IOException {
        // 手动创建导出 demo
        List<MesProFeedbackImportExcelVO> list = Collections.singletonList(
                MesProFeedbackImportExcelVO.builder()
                        .code("FB-001").type(1).taskCode("TASK-001")
                        .feedbackTime(java.time.LocalDateTime.of(2026, 10, 16, 10, 0, 0))
                        .scheduledQuantity(new java.math.BigDecimal("100"))
                        .feedbackQuantity(new java.math.BigDecimal("100"))
                        .qualifiedQuantity(new java.math.BigDecimal("100"))
                        .unqualifiedQuantity(new java.math.BigDecimal("0"))
                        .remark("").build()
        );
        // 输出
        ExcelUtils.writeTemplate(response, "生产报工导入模板.xls", "生产报工列表", MesProFeedbackImportExcelVO.class, list);
    }
    @PostMapping("/import")
    @Operation(summary = "导入生产报工")
    @Parameters({
            @Parameter(name = "file", description = "Excel 文件", required = true),
            @Parameter(name = "updateSupport", description = "是否支持更新,默认为 false", example = "true")
    })
    @PreAuthorize("@ss.hasPermission('mes:pro-feedback:import')")
    public CommonResult<MesProFeedbackImportRespVO> importExcel(@RequestParam("file") MultipartFile file,
                                                                @RequestParam(value = "updateSupport", required = false,
                                                                        defaultValue = "false") Boolean updateSupport) throws Exception {
        List<MesProFeedbackImportExcelVO> list = ExcelUtils.read(file, MesProFeedbackImportExcelVO.class);
        return success(feedbackService.importFeedbackList(list, updateSupport));
    }
    @PutMapping("/submit")
@@ -188,10 +244,33 @@
    @PutMapping("/approve")
    @Operation(summary = "审批报工")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('mes:pro-feedback:approve')")
    public CommonResult<Boolean> approveFeedback(@RequestParam("id") Long id) {
        return success(feedbackService.approveFeedback(id));
    public CommonResult<Boolean> approveFeedback(@Valid @RequestBody MesProFeedbackApproveReqVO reqVO) {
        return success(feedbackService.approveFeedback(reqVO));
    }
    @GetMapping("/batch-requirements")
    @Operation(summary = "检查报工审批前是否需要填写批次属性")
    @Parameter(name = "id", description = "报工单编号", required = true)
    @PreAuthorize("@ss.hasPermission('mes:pro-feedback:approve')")
    public CommonResult<MesProFeedbackBatchCheckRespVO> getBatchRequirements(@RequestParam("id") Long id) {
        return success(feedbackService.checkBatchRequirements(id));
    }
    @PostMapping("/quick-create")
    @Operation(summary = "快速报工(创建并提交)")
    @PreAuthorize("@ss.hasPermission('mes:pro-feedback:create')")
    public CommonResult<MesProFeedbackQuickCreateRespVO> quickCreateFeedback(
            @Valid @RequestBody MesProFeedbackQuickCreateReqVO reqVO) {
        return success(feedbackService.quickCreateFeedback(reqVO));
    }
    @PostMapping("/batch-create")
    @Operation(summary = "批量报工")
    @PreAuthorize("@ss.hasPermission('mes:pro-feedback:create')")
    public CommonResult<MesProFeedbackBatchCreateRespVO> batchCreateFeedback(
            @Valid @RequestBody MesProFeedbackBatchCreateReqVO reqVO) {
        return success(feedbackService.batchCreateFeedback(reqVO));
    }
    // ==================== 拼接 VO ====================
@@ -199,7 +278,6 @@
    @GetMapping("/trace/{id}")
    @Operation(summary = "获得报工追溯信息", description = "报工 + 产出/产出明细 + 消耗/消耗明细 + IPQC检验")
    @Parameter(name = "id", description = "报工编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('mes:pro-feedback:query')")
    public CommonResult<MesProFeedbackTraceRespVO> getFeedbackTrace(@PathVariable("id") Long id) {
        MesProFeedbackDO feedback = feedbackService.getFeedback(id);
        if (feedback == null) {
@@ -222,6 +300,15 @@
        return success(trace);
    }
    @GetMapping("/summary")
    @Operation(summary = "作业成果汇总统计", description = "按时间范围汇总已批准报工数量/合格数量,按工单类型、日期分组")
    public CommonResult<MesProFeedbackSummaryRespVO> getFeedbackSummary(
            @RequestParam(value = "beginDate", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate beginDate,
            @RequestParam(value = "endDate", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endDate,
            @RequestParam(value = "workOrderType", required = false) Integer workOrderType) {
        return success(feedbackService.getFeedbackSummary(beginDate, endDate, workOrderType));
    }
    private List<MesProFeedbackRespVO> buildFeedbackRespVOList(List<MesProFeedbackDO> list) {
        if (CollUtil.isEmpty(list)) {
            return Collections.emptyList();