package cn.iocoder.lyzsys.module.tjt.controller.admin.employeeyearcostbudget;

import cn.iocoder.lyzsys.framework.common.pojo.CommonResult;
import cn.iocoder.lyzsys.framework.common.pojo.PageResult;
import cn.iocoder.lyzsys.module.tjt.controller.admin.employeeyearcostbudget.vo.*;
import cn.iocoder.lyzsys.module.tjt.service.employeeyearcostbudget.EmployeeYearCostBudgetService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import static cn.iocoder.lyzsys.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 员工年度成本预算")
@RestController
@RequestMapping("/tjt/employee-year-cost-budget")
@Validated
public class EmployeeYearCostBudgetController {

    @Resource
    private EmployeeYearCostBudgetService employeeYearCostBudgetService;

    @PostMapping("/create")
    @Operation(summary = "创建员工年度成本预算")
    @PreAuthorize("@ss.hasPermission('tjt:employee-year-cost-budget:create')")
    public CommonResult<Long> createEmployeeYearCostBudget(@Valid @RequestBody EmployeeYearCostBudgetSaveReqVO createReqVO) {
        return success(employeeYearCostBudgetService.createEmployeeYearCostBudget(createReqVO));
    }

    @PostMapping("/generate")
    @Operation(summary = "按年度生成员工年度成本预算")
    @PreAuthorize("@ss.hasPermission('tjt:employee-year-cost-budget:create')")
    public CommonResult<EmployeeYearCostBudgetGenerateRespVO> generateEmployeeYearCostBudget(
            @Valid @RequestBody EmployeeYearCostBudgetGenerateReqVO generateReqVO) {
        return success(employeeYearCostBudgetService.generateEmployeeYearCostBudget(generateReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "修改员工年度成本预算")
    @PreAuthorize("@ss.hasPermission('tjt:employee-year-cost-budget:update')")
    public CommonResult<Boolean> updateEmployeeYearCostBudget(@Valid @RequestBody EmployeeYearCostBudgetSaveReqVO updateReqVO) {
        employeeYearCostBudgetService.updateEmployeeYearCostBudget(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除员工年度成本预算")
    @Parameter(name = "id", description = "编号", required = true, example = "1")
    @PreAuthorize("@ss.hasPermission('tjt:employee-year-cost-budget:delete')")
    public CommonResult<Boolean> deleteEmployeeYearCostBudget(@RequestParam("id") Long id) {
        employeeYearCostBudgetService.deleteEmployeeYearCostBudget(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得员工年度成本预算详情")
    @Parameter(name = "id", description = "编号", required = true, example = "1")
    @PreAuthorize("@ss.hasPermission('tjt:employee-year-cost-budget:query')")
    public CommonResult<EmployeeYearCostBudgetRespVO> getEmployeeYearCostBudget(@RequestParam("id") Long id) {
        return success(employeeYearCostBudgetService.getEmployeeYearCostBudget(id));
    }

    @GetMapping("/page")
    @Operation(summary = "获得员工年度成本预算分页")
    @PreAuthorize("@ss.hasPermission('tjt:employee-year-cost-budget:query')")
    public CommonResult<PageResult<EmployeeYearCostBudgetRespVO>> getEmployeeYearCostBudgetPage(
            @Valid EmployeeYearCostBudgetPageReqVO pageReqVO) {
        return success(employeeYearCostBudgetService.getEmployeeYearCostBudgetPage(pageReqVO));
    }

}
