/*
 * 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.pmPerformance.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.pmPerformance.entity.PmBudgetBase;
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.pmPerformance.entity.PmPerformance;
import com.unis.projectManagement.modular.pmPerformance.param.PmPerformanceAddParam;
import com.unis.projectManagement.modular.pmPerformance.param.PmPerformanceEditParam;
import com.unis.projectManagement.modular.pmPerformance.param.PmPerformanceIdParam;
import com.unis.projectManagement.modular.pmPerformance.param.PmPerformancePageParam;
import com.unis.projectManagement.modular.pmPerformance.service.PmPerformanceService;

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/30 19:34
 */
@Api(tags = "绩效上报管理控制器")
@ApiSupport(author = "UNIS_TEAM", order = 7)
@RestController
@Validated
public class PmPerformanceController {

    @Resource
    private PmPerformanceService pmPerformanceService;

    /**
     * 获取绩效上报管理分页
     *
     * @author QSHan
     * @date  2024/05/30 19:34
     */
    @ApiOperationSupport(order = 1)
    @ApiOperation("获取绩效上报管理分页")
//    @SaCheckPermission("/projectManagement/pmPerformance/page")
    @GetMapping("/projectManagement/pmPerformance/page")
    public CommonResult<Page<PmPerformance>> page(PmPerformancePageParam pmPerformancePageParam) {
        return CommonResult.data(pmPerformanceService.page(pmPerformancePageParam));
    }

    /**
     * 添加绩效上报管理
     *
     * @author QSHan
     * @date  2024/05/30 19:34
     */
    @ApiOperationSupport(order = 2)
    @ApiOperation("添加绩效上报管理")
    @CommonLog("添加绩效上报管理")
//    @SaCheckPermission("/projectManagement/pmPerformance/add")
    @PostMapping("/projectManagement/pmPerformance/add")
    public CommonResult<String> add(@RequestBody @Valid PmPerformanceAddParam pmPerformanceAddParam) {
        pmPerformanceService.add(pmPerformanceAddParam);
        return CommonResult.ok();
    }

    /**
     * 编辑绩效上报管理
     *
     * @author QSHan
     * @date  2024/05/30 19:34
     */
    @ApiOperationSupport(order = 3)
    @ApiOperation("编辑绩效上报管理")
    @CommonLog("编辑绩效上报管理")
//    @SaCheckPermission("/projectManagement/pmPerformance/edit")
    @PostMapping("/projectManagement/pmPerformance/edit")
    public CommonResult<String> edit(@RequestBody @Valid PmPerformanceEditParam pmPerformanceEditParam) {
        pmPerformanceService.edit(pmPerformanceEditParam);
        return CommonResult.ok();
    }

    /**
     * 删除绩效上报管理
     *
     * @author QSHan
     * @date  2024/05/30 19:34
     */
    @ApiOperationSupport(order = 4)
    @ApiOperation("删除绩效上报管理")
    @CommonLog("删除绩效上报管理")
//    @SaCheckPermission("/projectManagement/pmPerformance/delete")
    @PostMapping("/projectManagement/pmPerformance/delete")
    public CommonResult<String> delete(@RequestBody @Valid @NotEmpty(message = "集合不能为空")
                                                   CommonValidList<PmPerformanceIdParam> pmPerformanceIdParamList) {
        pmPerformanceService.delete(pmPerformanceIdParamList);
        return CommonResult.ok();
    }

    /**
     * 获取绩效上报管理详情
     *
     * @author QSHan
     * @date  2024/05/30 19:34
     */
    /*@ApiOperationSupport(order = 5)
    @ApiOperation("获取绩效上报管理详情")
    @SaCheckPermission("/projectManagement/pmPerformance/detail")
    @GetMapping("/projectManagement/pmPerformance/detail")
    public CommonResult<PmPerformance> detail(@Valid PmPerformanceIdParam pmPerformanceIdParam) {
        return CommonResult.data(pmPerformanceService.detail(pmPerformanceIdParam));
    }*/

    @ApiOperationSupport(order = 6)
    @ApiOperation("新增-项目名称下拉选")
    @GetMapping("/projectManagement/pmPerformance/getProjectNameList")
    public CommonResult<List<Map<String, Object>>> getProjectNameList() {
        return CommonResult.data(pmPerformanceService.getProjectNameList());
    }

    @ApiOperationSupport(order = 7)
    @ApiOperation("新增/详情/编辑-带出详情")
    @GetMapping("/projectManagement/pmPerformance/getDetailAllList/{budgetId}/{pmApplicationId}")
    public CommonResult<PmBudgetBase> getDetailAllList(@PathVariable("budgetId") String budgetId ,
                                                       @PathVariable("pmApplicationId") String pmApplicationId,
                                                       @RequestParam(required = false) String id) {
        return CommonResult.data(pmPerformanceService.getDetailAllList(budgetId, pmApplicationId, id));
    }
}
