package cn.iocoder.yudao.module.system.controller.admin.holiday.holidaybalancesetting;

import cn.iocoder.yudao.module.system.controller.admin.holiday.holidaybalancesetting.vo.HolidayBalanceSettingPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.holiday.holidaybalancesetting.vo.HolidayBalanceSettingRespVO;
import cn.iocoder.yudao.module.system.controller.admin.holiday.holidaybalancesetting.vo.HolidayBalanceSettingSaveReqVO;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
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.*;
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.dal.dataobject.holiday.holidaybalancesetting.HolidayBalanceSettingDO;
import cn.iocoder.yudao.module.system.service.holiday.holidaybalancesetting.HolidayBalanceSettingService;

@Tag(name = "管理后台 - 假期余额设置")
@RestController
@RequestMapping("/system/holiday-balance-setting")
@Validated
public class HolidayBalanceSettingController {

    @Resource
    private HolidayBalanceSettingService holidayBalanceSettingService;

    @PostMapping("/create")
    @Operation(summary = "创建假期余额设置")
    public CommonResult<Long> createHolidayBalanceSetting(@Valid @RequestBody HolidayBalanceSettingSaveReqVO createReqVO) {
        return success(holidayBalanceSettingService.createHolidayBalanceSetting(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新假期余额设置")
    public CommonResult<Boolean> updateHolidayBalanceSetting(@Valid @RequestBody HolidayBalanceSettingSaveReqVO updateReqVO) {
        holidayBalanceSettingService.updateHolidayBalanceSetting(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除假期余额设置")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> deleteHolidayBalanceSetting(@RequestParam("id") Long id) {
        holidayBalanceSettingService.deleteHolidayBalanceSetting(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得假期余额设置")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<HolidayBalanceSettingRespVO> getHolidayBalanceSetting(@RequestParam("id") Long id) {
        HolidayBalanceSettingDO holidayBalanceSetting = holidayBalanceSettingService.getHolidayBalanceSetting(id);
        return success(BeanUtils.toBean(holidayBalanceSetting, HolidayBalanceSettingRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得假期余额设置分页")
    public CommonResult<PageResult<HolidayBalanceSettingRespVO>> getHolidayBalanceSettingPage(@Valid HolidayBalanceSettingPageReqVO pageReqVO) {
        PageResult<HolidayBalanceSettingDO> pageResult = holidayBalanceSettingService.getHolidayBalanceSettingPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, HolidayBalanceSettingRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出假期余额设置 Excel")
    @OperateLog(type = EXPORT)
    public void exportHolidayBalanceSettingExcel(@Valid HolidayBalanceSettingPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<HolidayBalanceSettingDO> list = holidayBalanceSettingService.getHolidayBalanceSettingPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "假期余额设置.xls", "数据", HolidayBalanceSettingRespVO.class,
                        BeanUtils.toBean(list, HolidayBalanceSettingRespVO.class));
    }

}
