package cn.iocoder.yudao.module.member.controller.admin.statisticsspacecapsuleorder;

import cn.iocoder.yudao.module.member.controller.admin.statisticsspacecapsuleorder.vo.*;
import cn.iocoder.yudao.module.member.dal.dataobject.statisticsspacecapsuleorder.StatisticsSpaceCapsuleOrderDO;
import cn.iocoder.yudao.module.member.service.statisticsspacecapsuleorder.StatisticsSpaceCapsuleOrderService;
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.*;


@Tag(name = "管理后台 - 太空舱订单营业额统计")
@RestController
@RequestMapping("/statistics-space-capsule-order")
@Validated
public class StatisticsSpaceCapsuleOrderController {

    @Resource
    private StatisticsSpaceCapsuleOrderService statisticsSpaceCapsuleOrderService;
    @GetMapping("/space/money")
    @Operation(summary = "根据太空舱分组营业额")
    public CommonResult<List<SpaceCapsuleOrderNameRespVO>> getStatisticsSpaceCapsuleOrder(SpaceCapsuleOrderReqVO vo) {
        return success(statisticsSpaceCapsuleOrderService.getStatisticsSpaceCapsuleOrder(vo));
    }
    @PostMapping("/create")
    @Operation(summary = "创建太空舱订单营业额统计")
    @PreAuthorize("@ss.hasPermission('t:statistics-space-capsule-order:create')")
    public CommonResult<Long> createStatisticsSpaceCapsuleOrder(@Valid @RequestBody StatisticsSpaceCapsuleOrderSaveReqVO createReqVO) {
        return success(statisticsSpaceCapsuleOrderService.createStatisticsSpaceCapsuleOrder(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新太空舱订单营业额统计")
    @PreAuthorize("@ss.hasPermission('t:statistics-space-capsule-order:update')")
    public CommonResult<Boolean> updateStatisticsSpaceCapsuleOrder(@Valid @RequestBody StatisticsSpaceCapsuleOrderSaveReqVO updateReqVO) {
        statisticsSpaceCapsuleOrderService.updateStatisticsSpaceCapsuleOrder(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除太空舱订单营业额统计")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('t:statistics-space-capsule-order:delete')")
    public CommonResult<Boolean> deleteStatisticsSpaceCapsuleOrder(@RequestParam("id") Long id) {
        statisticsSpaceCapsuleOrderService.deleteStatisticsSpaceCapsuleOrder(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得太空舱订单营业额统计")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('t:statistics-space-capsule-order:query')")
    public CommonResult<StatisticsSpaceCapsuleOrderRespVO> getStatisticsSpaceCapsuleOrder(@RequestParam("id") Long id) {
        StatisticsSpaceCapsuleOrderDO statisticsSpaceCapsuleOrder = statisticsSpaceCapsuleOrderService.getStatisticsSpaceCapsuleOrder(id);
        return success(BeanUtils.toBean(statisticsSpaceCapsuleOrder, StatisticsSpaceCapsuleOrderRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得太空舱订单营业额统计分页")
    @PreAuthorize("@ss.hasPermission('t:statistics-space-capsule-order:query')")
    public CommonResult<PageResult<StatisticsSpaceCapsuleOrderRespVO>> getStatisticsSpaceCapsuleOrderPage(@Valid StatisticsSpaceCapsuleOrderPageReqVO pageReqVO) {
        PageResult<StatisticsSpaceCapsuleOrderDO> pageResult = statisticsSpaceCapsuleOrderService.getStatisticsSpaceCapsuleOrderPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, StatisticsSpaceCapsuleOrderRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出太空舱订单营业额统计 Excel")
    @PreAuthorize("@ss.hasPermission('t:statistics-space-capsule-order:export')")
    @OperateLog(type = EXPORT)
    public void exportStatisticsSpaceCapsuleOrderExcel(@Valid StatisticsSpaceCapsuleOrderPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<StatisticsSpaceCapsuleOrderDO> list = statisticsSpaceCapsuleOrderService.getStatisticsSpaceCapsuleOrderPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "太空舱订单营业额统计.xls", "数据", StatisticsSpaceCapsuleOrderRespVO.class,
                        BeanUtils.toBean(list, StatisticsSpaceCapsuleOrderRespVO.class));
    }

}