package cn.newfeifan.mall.module.distri.controller.admin.ptprofitdailystatisticslog;

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.*;
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.admin.ptprofitdailystatisticslog.vo.*;
import cn.newfeifan.mall.module.distri.dal.dataobject.ptprofitdailystatisticslog.PtProfitDailyStatisticsLogDO;
import cn.newfeifan.mall.module.distri.service.ptprofitdailystatisticslog.PtProfitDailyStatisticsLogService;

@Tag(name = "管理后台 - 平台利润每日统计记录")
@RestController
@RequestMapping("/distri/pt-profit-daily-statistics-log")
@Validated
public class PtProfitDailyStatisticsLogController {

    @Resource
    private PtProfitDailyStatisticsLogService ptProfitDailyStatisticsLogService;

    @PostMapping("/create")
    @Operation(summary = "创建平台利润每日统计记录")
    @PreAuthorize("@ss.hasPermission('distri:pt-profit-daily-statistics-log:create')")
    public CommonResult<Long> createPtProfitDailyStatisticsLog(@Valid @RequestBody PtProfitDailyStatisticsLogSaveReqVO createReqVO) {
        return success(ptProfitDailyStatisticsLogService.createPtProfitDailyStatisticsLog(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新平台利润每日统计记录")
    @PreAuthorize("@ss.hasPermission('distri:pt-profit-daily-statistics-log:update')")
    public CommonResult<Boolean> updatePtProfitDailyStatisticsLog(@Valid @RequestBody PtProfitDailyStatisticsLogSaveReqVO updateReqVO) {
        ptProfitDailyStatisticsLogService.updatePtProfitDailyStatisticsLog(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除平台利润每日统计记录")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('distri:pt-profit-daily-statistics-log:delete')")
    public CommonResult<Boolean> deletePtProfitDailyStatisticsLog(@RequestParam("id") Long id) {
        ptProfitDailyStatisticsLogService.deletePtProfitDailyStatisticsLog(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得平台利润每日统计记录")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('distri:pt-profit-daily-statistics-log:query')")
    public CommonResult<PtProfitDailyStatisticsLogRespVO> getPtProfitDailyStatisticsLog(@RequestParam("id") Long id) {
        PtProfitDailyStatisticsLogDO ptProfitDailyStatisticsLog = ptProfitDailyStatisticsLogService.getPtProfitDailyStatisticsLog(id);
        return success(BeanUtils.toBean(ptProfitDailyStatisticsLog, PtProfitDailyStatisticsLogRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得平台利润每日统计记录分页")
    @PreAuthorize("@ss.hasPermission('distri:pt-profit-daily-statistics-log:query')")
    public CommonResult<PageResult<PtProfitDailyStatisticsLogRespVO>> getPtProfitDailyStatisticsLogPage(@Valid PtProfitDailyStatisticsLogPageReqVO pageReqVO) {
        PageResult<PtProfitDailyStatisticsLogDO> pageResult = ptProfitDailyStatisticsLogService.getPtProfitDailyStatisticsLogPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, PtProfitDailyStatisticsLogRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出平台利润每日统计记录 Excel")
    @PreAuthorize("@ss.hasPermission('distri:pt-profit-daily-statistics-log:export')")
    @OperateLog(type = EXPORT)
    public void exportPtProfitDailyStatisticsLogExcel(@Valid PtProfitDailyStatisticsLogPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<PtProfitDailyStatisticsLogDO> list = ptProfitDailyStatisticsLogService.getPtProfitDailyStatisticsLogPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "平台利润每日统计记录.xls", "数据", PtProfitDailyStatisticsLogRespVO.class,
                        BeanUtils.toBean(list, PtProfitDailyStatisticsLogRespVO.class));
    }

}