gaoluyang
3 天以前 d39e4f7d839167c16425086dfa2f8747bccfdff9
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/pro/mps/MesProMpsController.java
@@ -15,8 +15,10 @@
import cn.iocoder.yudao.module.crm.api.customer.CrmCustomerApi;
import cn.iocoder.yudao.module.crm.api.customer.dto.CrmCustomerRespDTO;
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.pro.mps.MesProMpsDO;
import cn.iocoder.yudao.module.mes.service.md.item.MesMdItemService;
import cn.iocoder.yudao.module.mes.service.md.unitmeasure.MesMdUnitMeasureService;
import cn.iocoder.yudao.module.mes.service.pro.mps.MesProMpsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
@@ -32,21 +34,32 @@
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
    private MesProMpsService mpsService;
    @Resource
    private MesMdItemService itemService;
    @Resource
    private MesMdUnitMeasureService unitMeasureService;
    @Resource
    private CrmCustomerApi customerApi;
@@ -77,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) {
@@ -88,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()));
@@ -118,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")
@@ -139,6 +179,8 @@
        // 1. 批量获取关联数据
        Map<Long, MesMdItemDO> itemMap = itemService.getItemMap(
                convertSet(list, MesProMpsDO::getProductId));
        Map<Long, MesMdUnitMeasureDO> unitMap = unitMeasureService.getUnitMeasureMap(
                convertSet(itemMap.values(), MesMdItemDO::getUnitMeasureId));
        Map<Long, CrmCustomerRespDTO> clientMap = customerApi.getCustomerMap(
                convertSet(list, MesProMpsDO::getClientId));
        // 2. 拼接 VO
@@ -147,10 +189,12 @@
                vo.setProductName(item.getName())
                        .setProductCode(item.getCode())
                        .setProductSpecification(item.getSpecification());
                MapUtils.findAndThen(unitMap, item.getUnitMeasureId(),
                        unit -> vo.setUnitMeasureName(unit.getName()));
            });
            MapUtils.findAndThen(clientMap, vo.getClientId(),
                    client -> vo.setClientName(client.getName()));
        });
    }
}
}