package cn.newfeifan.mall.module.distri.controller.app.ptdailywithdrawal;

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.newfeifan.mall.framework.common.pojo.PageParam;
import cn.newfeifan.mall.framework.common.pojo.PageResult;
import cn.newfeifan.mall.framework.common.pojo.CommonResult;
import cn.newfeifan.mall.framework.common.util.object.BeanUtils;
import static cn.newfeifan.mall.framework.common.pojo.CommonResult.success;

import cn.newfeifan.mall.framework.excel.core.util.ExcelUtils;

import cn.newfeifan.mall.framework.operatelog.core.annotations.OperateLog;
import static cn.newfeifan.mall.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.newfeifan.mall.module.distri.controller.app.ptdailywithdrawal.vo.*;
import cn.newfeifan.mall.module.distri.dal.dataobject.ptdailywithdrawal.PtDailyWithdrawalDO;
import cn.newfeifan.mall.module.distri.service.ptdailywithdrawal.PtDailyWithdrawalService;

@Tag(name = "用户 APP - 平台每日提现记录")
@RestController
@RequestMapping("/distri/pt-daily-withdrawal")
@Validated
public class AppPtDailyWithdrawalController {

    @Resource
    private PtDailyWithdrawalService ptDailyWithdrawalService;

    @PostMapping("/create")
    @Operation(summary = "创建平台每日提现记录")
    public CommonResult<Long> createPtDailyWithdrawal(@Valid @RequestBody AppPtDailyWithdrawalSaveReqVO createReqVO) {
        return success(ptDailyWithdrawalService.createPtDailyWithdrawal(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新平台每日提现记录")
    public CommonResult<Boolean> updatePtDailyWithdrawal(@Valid @RequestBody AppPtDailyWithdrawalSaveReqVO updateReqVO) {
        ptDailyWithdrawalService.updatePtDailyWithdrawal(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除平台每日提现记录")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> deletePtDailyWithdrawal(@RequestParam("id") Long id) {
        ptDailyWithdrawalService.deletePtDailyWithdrawal(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得平台每日提现记录")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<AppPtDailyWithdrawalRespVO> getPtDailyWithdrawal(@RequestParam("id") Long id) {
        PtDailyWithdrawalDO ptDailyWithdrawal = ptDailyWithdrawalService.getPtDailyWithdrawal(id);
        return success(BeanUtils.toBean(ptDailyWithdrawal, AppPtDailyWithdrawalRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得平台每日提现记录分页")
    public CommonResult<PageResult<AppPtDailyWithdrawalRespVO>> getPtDailyWithdrawalPage(@Valid AppPtDailyWithdrawalPageReqVO pageReqVO) {
        PageResult<PtDailyWithdrawalDO> pageResult = ptDailyWithdrawalService.getPtDailyWithdrawalPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, AppPtDailyWithdrawalRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出平台每日提现记录 Excel")
    @OperateLog(type = EXPORT)
    public void exportPtDailyWithdrawalExcel(@Valid AppPtDailyWithdrawalPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<PtDailyWithdrawalDO> list = ptDailyWithdrawalService.getPtDailyWithdrawalPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "平台每日提现记录.xls", "数据", AppPtDailyWithdrawalRespVO.class,
                        BeanUtils.toBean(list, AppPtDailyWithdrawalRespVO.class));
    }

}