/*
 * Copyright [2022] [https://www.xiaonuo.vip]
 *
 * Snowy采用APACHE LICENSE 2.0开源协议，您在使用过程中，需要注意以下几点：
 *
 * 1.请不要删除和修改根目录下的LICENSE文件。
 * 2.请不要删除和修改Snowy源码头部的版权声明。
 * 3.本项目代码可免费商业使用，商业使用请保留源码和相关描述文件的项目出处，作者声明等。
 * 4.分发源码时候，请注明软件出处 https://www.xiaonuo.vip
 * 5.不可二次分发开源参与同类竞品，如有想法可联系团队xiaonuobase@qq.com商议合作。
 * 6.若您的项目无法满足以上几点，需要更多功能代码，获取Snowy商业授权许可，请在官网购买授权，地址为 https://www.xiaonuo.vip
 */
package com.unis.projectManagement.modular.pmBudget.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.unis.projectManagement.modular.projectInfoPlan.entity.ProjectInfoPlan;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.unis.common.annotation.CommonLog;
import com.unis.common.pojo.CommonResult;
import com.unis.common.pojo.CommonValidList;
import com.unis.projectManagement.modular.pmBudget.entity.PmBudget;
import com.unis.projectManagement.modular.pmBudget.param.PmBudgetAddParam;
import com.unis.projectManagement.modular.pmBudget.param.PmBudgetEditParam;
import com.unis.projectManagement.modular.pmBudget.param.PmBudgetIdParam;
import com.unis.projectManagement.modular.pmBudget.param.PmBudgetPageParam;
import com.unis.projectManagement.modular.pmBudget.service.PmBudgetService;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import java.util.List;
import java.util.Map;

/**
 * 项目预算资金控制器
 *
 * @author QSHan
 * @date  2024/05/28 16:04
 */
@Api(tags = "项目预算资金控制器")
@ApiSupport(author = "UNIS_TEAM", order = 1)
@RestController
@Validated
public class PmBudgetController {

    @Resource
    private PmBudgetService pmBudgetService;

    /**
     * 获取项目预算资金分页
     *
     * @author QSHan
     * @date  2024/05/28 16:04
     */
    @ApiOperationSupport(order = 1)
    @ApiOperation("获取项目预算资金分页")
//    @SaCheckPermission("/projectManagement/pmBudget/page")
    @GetMapping("/projectManagement/pmBudget/page")
    public CommonResult<Page<PmBudget>> page(PmBudgetPageParam pmBudgetPageParam) {
        return CommonResult.data(pmBudgetService.page(pmBudgetPageParam));
    }

    /**
     * 添加项目预算资金
     *
     * @author QSHan
     * @date  2024/05/28 16:04
     */
    @ApiOperationSupport(order = 2)
    @ApiOperation("添加项目预算资金")
    @CommonLog("添加项目预算资金")
//    @SaCheckPermission("/projectManagement/pmBudget/add")
    @PostMapping("/projectManagement/pmBudget/add")
    public CommonResult<String> add(@RequestBody @Valid PmBudgetAddParam pmBudgetAddParam) {
        pmBudgetService.add(pmBudgetAddParam);
        return CommonResult.ok();
    }

    /**
     * 编辑项目预算资金
     *
     * @author QSHan
     * @date  2024/05/28 16:04
     */
    @ApiOperationSupport(order = 3)
    @ApiOperation("编辑项目预算资金")
    @CommonLog("编辑项目预算资金")
//    @SaCheckPermission("/projectManagement/pmBudget/edit")
    @PostMapping("/projectManagement/pmBudget/edit")
    public CommonResult<String> edit(@RequestBody @Valid PmBudgetEditParam pmBudgetEditParam) {
        pmBudgetService.edit(pmBudgetEditParam);
        return CommonResult.ok();
    }

    /**
     * 删除项目预算资金
     *
     * @author QSHan
     * @date  2024/05/28 16:04
     */
    @ApiOperationSupport(order = 4)
    @ApiOperation("删除项目预算资金")
    @CommonLog("删除项目预算资金")
//    @SaCheckPermission("/projectManagement/pmBudget/delete")
    @PostMapping("/projectManagement/pmBudget/delete")
    public CommonResult<String> delete(@RequestBody @Valid @NotEmpty(message = "集合不能为空")
                                                   CommonValidList<PmBudgetIdParam> pmBudgetIdParamList) {
        pmBudgetService.delete(pmBudgetIdParamList);
        return CommonResult.ok();
    }

    /**
     * 获取项目预算资金详情
     *
     * @author QSHan
     * @date  2024/05/28 16:04
     */
    @ApiOperationSupport(order = 5)
    @ApiOperation("获取项目预算资金详情")
//    @SaCheckPermission("/projectManagement/pmBudget/detail")
    @GetMapping("/projectManagement/pmBudget/detail")
    public CommonResult<PmBudget> detail(@Valid PmBudgetIdParam pmBudgetIdParam) {
        return CommonResult.data(pmBudgetService.detail(pmBudgetIdParam));
    }

    @ApiOperationSupport(order = 6)
    @ApiOperation("项目名称下拉选")
//    @SaCheckPermission("/projectManagement/pmBudget/getProjectList")
    @GetMapping("/projectManagement/pmBudget/getProjectList")
    public CommonResult<List<Map<String, Object>>> getProjectList() {
        return CommonResult.data(pmBudgetService.getProjectList());
    }

    @ApiOperationSupport(order = 7)
    @ApiOperation("id获取项目编号")
//    @SaCheckPermission("/projectManagement/pmBudget/getProjectCode")
    @GetMapping("/projectManagement/pmBudget/getProjectCode/{id}")
    public CommonResult<Map<String, Object>> getProjectCode(@PathVariable("id") String id) {
        return CommonResult.data(pmBudgetService.getProjectCode(id));
    }

    @ApiOperationSupport(order = 8)
    @ApiOperation("新增-根据pmApplicationId获取进度计划列表")
    @GetMapping("/projectManagement/pmBudget/getProjectPlanList/{pmApplicationId}")
    public CommonResult<List<ProjectInfoPlan>> getProjectPlanList(@PathVariable("pmApplicationId") String pmApplicationId) {
        return CommonResult.data(pmBudgetService.getProjectPlanList(pmApplicationId));
    }
}
