xiaoyi
5 天以前 481d8165f26fc7e37f0e87f6444ac0340bb563a3
yudao-module-erp/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/purchase/ErpPurchasePlanController.java
@@ -8,6 +8,10 @@
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.module.erp.controller.admin.purchase.vo.plan.ErpPurchasePlanAuditReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.purchase.vo.plan.ErpPurchasePlanImportExcelVO;
import cn.iocoder.yudao.module.erp.controller.admin.purchase.vo.plan.ErpPurchasePlanImportReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.purchase.vo.plan.ErpPurchasePlanImportRespVO;
import cn.iocoder.yudao.module.erp.controller.admin.purchase.vo.plan.ErpPurchasePlanPageReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.purchase.vo.plan.ErpPurchasePlanRespVO;
import cn.iocoder.yudao.module.erp.controller.admin.purchase.vo.plan.ErpPurchasePlanSaveReqVO;
@@ -36,8 +40,10 @@
import org.springframework.web.bind.annotation.*;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
@@ -48,7 +54,7 @@
@Tag(name = "管理后台 - ERP 采购计划")
@RestController
@RequestMapping("/erp/purchase-plan")
@RequestMapping({"/purchase/plan", "/erp/purchase-plan"})
@Validated
public class ErpPurchasePlanController {
@@ -92,7 +98,6 @@
    @GetMapping("/get")
    @Operation(summary = "获得采购计划")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('erp:purchase-plan:query')")
    public CommonResult<ErpPurchasePlanRespVO> getPurchasePlan(@RequestParam("id") Long id) {
        ErpPurchasePlanDO plan = purchasePlanService.getPurchasePlan(id);
        if (plan == null) {
@@ -114,7 +119,6 @@
    @GetMapping("/page")
    @Operation(summary = "获得采购计划分页")
    @PreAuthorize("@ss.hasPermission('erp:purchase-plan:query')")
    public CommonResult<PageResult<ErpPurchasePlanRespVO>> getPurchasePlanPage(@Valid ErpPurchasePlanPageReqVO pageReqVO) {
        PageResult<ErpPurchasePlanDO> pageResult = purchasePlanService.getPurchasePlanPage(pageReqVO);
        return success(buildPurchasePlanVOPageResult(pageResult));
@@ -131,21 +135,51 @@
        ExcelUtils.write(response, "采购计划.xls", "数据", ErpPurchasePlanRespVO.class, list);
    }
    @GetMapping("/get-import-template")
    @Operation(summary = "获得导入采购计划模板")
    public void importTemplate(HttpServletResponse response) throws IOException {
        // 手动创建导出 demo
        List<ErpPurchasePlanImportExcelVO> list = Arrays.asList(
                ErpPurchasePlanImportExcelVO.builder().no("CGJH-示例-001").name("示例采购计划")
                        .demandSource(null).planDate(null).supplierName("")
                        .remark("").productCode("").productUnitCode("").count(null)
                        .demandTime(null).itemRemark("").build()
        );
        // 输出
        ExcelUtils.writeTemplate(response, "采购计划导入模板.xls", "采购计划列表", ErpPurchasePlanImportExcelVO.class, list);
    }
    @PostMapping("/import")
    @Operation(summary = "导入采购计划")
    @PreAuthorize("@ss.hasPermission('erp:purchase-plan:import')")
    public CommonResult<ErpPurchasePlanImportRespVO> importExcel(@Valid ErpPurchasePlanImportReqVO importReqVO)
            throws Exception {
        List<ErpPurchasePlanImportExcelVO> list = ExcelUtils.read(importReqVO.getFile(), ErpPurchasePlanImportExcelVO.class);
        return success(purchasePlanService.importPurchasePlanList(list, importReqVO));
    }
    @PutMapping("/submit")
    @Operation(summary = "提交采购计划审批")
    @Operation(summary = "提交采购计划审核(草稿/审核不通过 → 审批中)")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('erp:purchase-plan:submit')")
    public CommonResult<Boolean> submitPurchasePlan(@RequestParam("id") Long id,
                                                    @RequestParam("processDefinitionKey") String processDefinitionKey) {
        Long userId = getLoginUserId();
        purchasePlanService.submitPurchasePlan(id, processDefinitionKey, userId);
    public CommonResult<Boolean> submitPurchasePlan(@RequestParam("id") Long id) {
        purchasePlanService.submitPurchasePlan(id);
        return success(true);
    }
    @GetMapping("/approve-process-list")
    @Operation(summary = "获取采购计划审批流程列表")
    @PreAuthorize("@ss.hasPermission('erp:purchase-plan:query')")
    public CommonResult<List<Map<String, Object>>> getApproveProcessList() {
        return success(purchasePlanService.getPurchasePlanApproveProcessDefinitionList());
    @PutMapping("/audit")
    @Operation(summary = "审核采购计划(审批中 → 审核通过/审核不通过),仅审批人本人可操作")
    @PreAuthorize("@ss.hasPermission('erp:purchase-plan:audit')")
    public CommonResult<Boolean> auditPurchasePlan(@Valid @RequestBody ErpPurchasePlanAuditReqVO auditReqVO) {
        purchasePlanService.auditPurchasePlan(auditReqVO.getId(), auditReqVO.getPass(),
                auditReqVO.getReviewRemark());
        return success(true);
    }
    @GetMapping("/approver-ids")
    @Operation(summary = "获得采购计划的审批人编号集合,供前端判断是否展示审核按钮")
    public CommonResult<Set<Long>> getApproverUserIds() {
        return success(purchasePlanService.getPurchasePlanApproverUserIds());
    }
    @PostMapping("/generate-from-stock-alert")
@@ -157,6 +191,22 @@
        return success(plan.getId());
    }
    @GetMapping("/get-stock-alert-suggest-items")
    @Operation(summary = "获取库存预警建议采购明细", description = "遍历启用安全库存的物料,按默认仓库缺量返回建议采购明细,不落库")
    @PreAuthorize("@ss.hasPermission('erp:purchase-plan:create')")
    public CommonResult<List<ErpPurchasePlanRespVO.Item>> getStockAlertSuggestItems() {
        List<ErpPurchasePlanRespVO.Item> items = purchasePlanService.getStockAlertSuggestItems();
        if (CollUtil.isEmpty(items)) {
            return success(items);
        }
        // 1.2 单位信息
        Map<Long, MdmUnitMeasureRespDTO> unitMeasureMap = mdmUnitMeasureApi.getUnitMeasureMap(
                convertSet(items, ErpPurchasePlanRespVO.Item::getProductUnitId));
        items.forEach(item -> MapUtils.findAndThen(unitMeasureMap, item.getProductUnitId(),
                unit -> item.setProductUnitName(unit.getName())));
        return success(items);
    }
    @PostMapping("/generate-requests")
    @Operation(summary = "生成采购申请")
    @PreAuthorize("@ss.hasPermission('erp:purchase-plan:generate-request')")