package cn.iocoder.yudao.module.system.controller.admin.workovertime;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.system.controller.admin.workovertime.vo.*;
import cn.iocoder.yudao.module.system.dal.dataobject.workovertime.WorkOvertimeMoreRuleExtDO;
import cn.iocoder.yudao.module.system.service.workovertime.WorkOvertimeMoreRuleExtService;

@Tag(name = "管理后台 - 加班更多规则拓展")
@RestController
@RequestMapping("/system/work-overtime-more-rule-ext")
@Validated
public class WorkOvertimeMoreRuleExtController {

    @Resource
    private WorkOvertimeMoreRuleExtService workOvertimeMoreRuleExtService;

    @PostMapping("/create")
    @Operation(summary = "创建加班更多规则拓展")
    @PreAuthorize("@ss.hasPermission('system:work-overtime-more-rule-ext:create')")
    public CommonResult<Long> createWorkOvertimeMoreRuleExt(@Valid @RequestBody WorkOvertimeMoreRuleExtSaveReqVO createReqVO) {
        return success(workOvertimeMoreRuleExtService.createWorkOvertimeMoreRuleExt(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新加班更多规则拓展")
    @PreAuthorize("@ss.hasPermission('system:work-overtime-more-rule-ext:update')")
    public CommonResult<Boolean> updateWorkOvertimeMoreRuleExt(@Valid @RequestBody WorkOvertimeMoreRuleExtSaveReqVO updateReqVO) {
        workOvertimeMoreRuleExtService.updateWorkOvertimeMoreRuleExt(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除加班更多规则拓展")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('system:work-overtime-more-rule-ext:delete')")
    public CommonResult<Boolean> deleteWorkOvertimeMoreRuleExt(@RequestParam("id") Long id) {
        workOvertimeMoreRuleExtService.deleteWorkOvertimeMoreRuleExt(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得加班更多规则拓展")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('system:work-overtime-more-rule-ext:query')")
    public CommonResult<WorkOvertimeMoreRuleExtRespVO> getWorkOvertimeMoreRuleExt(@RequestParam("id") Long id) {
        WorkOvertimeMoreRuleExtDO workOvertimeMoreRuleExt = workOvertimeMoreRuleExtService.getWorkOvertimeMoreRuleExt(id);
        return success(BeanUtils.toBean(workOvertimeMoreRuleExt, WorkOvertimeMoreRuleExtRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得加班更多规则拓展分页")
    @PreAuthorize("@ss.hasPermission('system:work-overtime-more-rule-ext:query')")
    public CommonResult<PageResult<WorkOvertimeMoreRuleExtRespVO>> getWorkOvertimeMoreRuleExtPage(@Valid WorkOvertimeMoreRuleExtPageReqVO pageReqVO) {
        PageResult<WorkOvertimeMoreRuleExtDO> pageResult = workOvertimeMoreRuleExtService.getWorkOvertimeMoreRuleExtPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, WorkOvertimeMoreRuleExtRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出加班更多规则拓展 Excel")
    @PreAuthorize("@ss.hasPermission('system:work-overtime-more-rule-ext:export')")
    @OperateLog(type = EXPORT)
    public void exportWorkOvertimeMoreRuleExtExcel(@Valid WorkOvertimeMoreRuleExtPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<WorkOvertimeMoreRuleExtDO> list = workOvertimeMoreRuleExtService.getWorkOvertimeMoreRuleExtPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "加班更多规则拓展.xls", "数据", WorkOvertimeMoreRuleExtRespVO.class,
                        BeanUtils.toBean(list, WorkOvertimeMoreRuleExtRespVO.class));
    }

}