From 1458532478eedbd82947e6ee8515f881d4a4912a Mon Sep 17 00:00:00 2001
From: liyong <18434998025@163.com>
Date: 星期六, 18 七月 2026 16:14:23 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/dev_business' into dev_business

---
 yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/pro/mps/MesProMpsController.java |  156 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 156 insertions(+), 0 deletions(-)

diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/pro/mps/MesProMpsController.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/pro/mps/MesProMpsController.java
new file mode 100644
index 0000000..b174b5a
--- /dev/null
+++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/pro/mps/MesProMpsController.java
@@ -0,0 +1,156 @@
+package cn.iocoder.yudao.module.mes.controller.admin.pro.mps;
+
+import cn.hutool.core.collection.CollUtil;
+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.pojo.PageParam;
+import cn.iocoder.yudao.framework.common.pojo.PageResult;
+import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
+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.mps.vo.MesProMpsPageReqVO;
+import cn.iocoder.yudao.module.mes.controller.admin.pro.mps.vo.MesProMpsRespVO;
+import cn.iocoder.yudao.module.mes.controller.admin.pro.mps.vo.MesProMpsSaveReqVO;
+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.pro.mps.MesProMpsDO;
+import cn.iocoder.yudao.module.mes.service.md.item.MesMdItemService;
+import cn.iocoder.yudao.module.mes.service.pro.mps.MesProMpsService;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import jakarta.annotation.Resource;
+import jakarta.servlet.http.HttpServletResponse;
+import jakarta.validation.Valid;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+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;
+
+@Tag(name = "绠$悊鍚庡彴 - MES 鐢熶骇涓昏鍒�")
+@RestController
+@RequestMapping("/mes/pro-mps")
+@Validated
+public class MesProMpsController {
+
+    @Resource
+    private MesProMpsService mpsService;
+    @Resource
+    private MesMdItemService itemService;
+    @Resource
+    private CrmCustomerApi customerApi;
+
+    @PostMapping("/create")
+    @Operation(summary = "鍒涘缓鐢熶骇涓昏鍒�")
+    @PreAuthorize("@ss.hasPermission('mes:pro-mps:create')")
+    public CommonResult<Long> createMps(@Valid @RequestBody MesProMpsSaveReqVO createReqVO) {
+        return success(mpsService.createMps(createReqVO));
+    }
+
+    @PutMapping("/update")
+    @Operation(summary = "鏇存柊鐢熶骇涓昏鍒�")
+    @PreAuthorize("@ss.hasPermission('mes:pro-mps:update')")
+    public CommonResult<Boolean> updateMps(@Valid @RequestBody MesProMpsSaveReqVO updateReqVO) {
+        mpsService.updateMps(updateReqVO);
+        return success(true);
+    }
+
+    @DeleteMapping("/delete")
+    @Operation(summary = "鍒犻櫎鐢熶骇涓昏鍒�")
+    @Parameter(name = "id", description = "缂栧彿", required = true)
+    @PreAuthorize("@ss.hasPermission('mes:pro-mps:delete')")
+    public CommonResult<Boolean> deleteMps(@RequestParam("id") Long id) {
+        mpsService.deleteMps(id);
+        return success(true);
+    }
+
+    @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) {
+            return success(null);
+        }
+        return success(buildMpsRespVOList(ListUtil.of(mps)).get(0));
+    }
+
+    @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()));
+    }
+
+    @GetMapping("/export-excel")
+    @Operation(summary = "瀵煎嚭鐢熶骇涓昏鍒� Excel")
+    @PreAuthorize("@ss.hasPermission('mes:pro-mps:export')")
+    @ApiAccessLog(operateType = EXPORT)
+    public void exportMpsExcel(@Valid MesProMpsPageReqVO pageReqVO,
+                               HttpServletResponse response) throws IOException {
+        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
+        List<MesProMpsDO> list = mpsService.getMpsPage(pageReqVO).getList();
+        List<MesProMpsRespVO> voList = buildMpsRespVOList(list);
+        ExcelUtils.write(response, "鐢熶骇涓昏鍒�.xls", "鏁版嵁", MesProMpsRespVO.class, voList);
+    }
+
+    @PostMapping("/issue")
+    @Operation(summary = "涓嬪彂鐢熶骇涓昏鍒�")
+    @Parameter(name = "id", description = "MPS 缂栧彿", required = true)
+    @PreAuthorize("@ss.hasPermission('mes:pro-mps:issue')")
+    public CommonResult<Long> issueMps(@RequestParam("id") Long id) {
+        return success(mpsService.issueMps(id));
+    }
+
+    @PostMapping("/merge-issue")
+    @Operation(summary = "鍚堝苟涓嬪彂鐢熶骇涓昏鍒�")
+    @PreAuthorize("@ss.hasPermission('mes:pro-mps:merge-issue')")
+    public CommonResult<Long> mergeAndIssueMps(@RequestBody List<Long> mpsIds) {
+        return success(mpsService.mergeAndIssueMps(mpsIds));
+    }
+
+    @PostMapping("/cancel")
+    @Operation(summary = "鍙栨秷鐢熶骇涓昏鍒�")
+    @Parameter(name = "id", description = "MPS 缂栧彿", required = true)
+    @PreAuthorize("@ss.hasPermission('mes:pro-mps:cancel')")
+    public CommonResult<Boolean> cancelMps(@RequestParam("id") Long id) {
+        mpsService.cancelMps(id);
+        return success(true);
+    }
+
+    // ==================== 鎷兼帴 VO ====================
+
+    private List<MesProMpsRespVO> buildMpsRespVOList(List<MesProMpsDO> list) {
+        if (CollUtil.isEmpty(list)) {
+            return Collections.emptyList();
+        }
+        // 1. 鎵归噺鑾峰彇鍏宠仈鏁版嵁
+        Map<Long, MesMdItemDO> itemMap = itemService.getItemMap(
+                convertSet(list, MesProMpsDO::getProductId));
+        Map<Long, CrmCustomerRespDTO> clientMap = customerApi.getCustomerMap(
+                convertSet(list, MesProMpsDO::getClientId));
+        // 2. 鎷兼帴 VO
+        return BeanUtils.toBean(list, MesProMpsRespVO.class, vo -> {
+            MapUtils.findAndThen(itemMap, vo.getProductId(), item -> {
+                vo.setProductName(item.getName())
+                        .setProductCode(item.getCode())
+                        .setProductSpecification(item.getSpecification());
+            });
+            MapUtils.findAndThen(clientMap, vo.getClientId(),
+                    client -> vo.setClientName(client.getName()));
+        });
+    }
+
+}
\ No newline at end of file

--
Gitblit v1.9.3