云
2026-10-27 ffca46b39d25439a06a27cafda2ec523a3fb67cf
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/pro/mps/MesProMpsController.java
@@ -34,15 +34,24 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.ArrayList;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import cn.iocoder.yudao.framework.common.exception.ServiceException;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.PRO_MPS_MERGE_ISSUE_DISABLED;
@Tag(name = "管理后台 - MES 生产主计划")
@RestController
@RequestMapping("/mes/pro-mps")
@Validated
@Slf4j
public class MesProMpsController {
    @Resource
@@ -81,7 +90,6 @@
    @GetMapping("/get")
    @Operation(summary = "获得生产主计划")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('mes:pro-mps:query')")
    public CommonResult<MesProMpsRespVO> getMps(@RequestParam("id") Long id) {
        MesProMpsDO mps = mpsService.getMps(id);
        if (mps == null) {
@@ -92,7 +100,6 @@
    @GetMapping("/page")
    @Operation(summary = "获得生产主计划分页")
    @PreAuthorize("@ss.hasPermission('mes:pro-mps:query')")
    public CommonResult<PageResult<MesProMpsRespVO>> getMpsPage(@Valid MesProMpsPageReqVO pageReqVO) {
        PageResult<MesProMpsDO> pageResult = mpsService.getMpsPage(pageReqVO);
        return success(new PageResult<>(buildMpsRespVOList(pageResult.getList()), pageResult.getTotal()));
@@ -122,7 +129,36 @@
    @Operation(summary = "合并下发生产主计划")
    @PreAuthorize("@ss.hasPermission('mes:pro-mps:merge-issue')")
    public CommonResult<Long> mergeAndIssueMps(@RequestBody List<Long> mpsIds) {
        return success(mpsService.mergeAndIssueMps(mpsIds));
        // 旧入口保留用于明确提示旧客户端升级,禁止绕过新的逐条下发权限校验。
        throw exception(PRO_MPS_MERGE_ISSUE_DISABLED);
    }
    @PostMapping("/batch-issue")
    @Operation(summary = "批量逐条下发生产主计划")
    @PreAuthorize("@ss.hasPermission('mes:pro-mps:issue')")
    public CommonResult<List<BatchIssueResult>> batchIssueMps(@RequestBody @NotEmpty List<@NotNull Long> ids) {
        List<BatchIssueResult> results = new ArrayList<>();
        for (Long id : ids) {
            BatchIssueResult result = new BatchIssueResult();
            result.setMpsId(id);
            try {
                result.setWorkOrderId(mpsService.issueMps(id));
            } catch (ServiceException ex) {
                result.setError(ex.getMessage());
            } catch (Exception ex) {
                log.error("[batchIssueMps] 下发失败,mpsId={}", id, ex);
                result.setError("下发失败,请联系管理员查看日志");
            }
            results.add(result);
        }
        return success(results);
    }
    @Data
    public static class BatchIssueResult {
        private Long mpsId;
        private Long workOrderId;
        private String error;
    }
    @PostMapping("/cancel")
@@ -161,4 +197,4 @@
        });
    }
}
}