package com.xiaoniu.system.order.storeorder.controller;

import com.xiaoniu.common.core.resdata.Result;
import com.xiaoniu.common.core.resdata.RowsData;
import com.xiaoniu.common.core.utils.poi.ExcelUtil;
import com.xiaoniu.common.log.annotation.Log;
import com.xiaoniu.common.log.enums.BusinessType;
import com.xiaoniu.system.order.storeorder.dto.*;
import com.xiaoniu.system.order.storeorder.service.ITbOrderInfoService;
import com.xiaoniu.system.order.storeorder.vo.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 订单信息表 前端控制器
 * </p>
 *
 * @author haoxuyang
 * @since 2024-10-16 09:11:47
 */
@Tag(name = "订单管理")
@RestController
@RequestMapping("/order")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class TbOrderInfoController {
    private final ITbOrderInfoService tbOrderInfoService;

    @Operation(summary = "门店订单列表")
    @PostMapping("/storeOrderList")
    public Result<RowsData<StoreOrderListVO>> storeOrderList(@RequestBody StoreOrderQueryDTO dto) {
        return Result.success("查询成功", tbOrderInfoService.storeOrderList(dto));
    }

    @Operation(summary = "团购订单列表")
    @PostMapping("/groupOrderList")
    public Result<RowsData<GroupOrderListVO>> groupOrderList(@RequestBody GroupOrderQueryDTO dto) {
        return Result.success("查询成功", tbOrderInfoService.groupOrderList(dto));
    }

    @Operation(summary = "投诉订单列表")
    @PostMapping("/complaintOrderList")
    public Result<RowsData<ComplaintOrderListVO>> complaintOrderList(@RequestBody ComplaintOrderQueryDTO dto) {
        return Result.success("查询成功", tbOrderInfoService.complaintOrderList(dto));
    }

    @Operation(summary = "积分商品订单列表")
    @PostMapping("/pointsOrderList")
    public Result<RowsData<PointsOrderListVO>> pointsOrderList(@RequestBody PointsOrderQueryDTO dto) {
        return Result.success("查询成功", tbOrderInfoService.pointsOrderList(dto));
    }

    @Operation(summary = "会员开通订单列表")
    @PostMapping("/memberOrderList")
    public Result<RowsData<MemberOrderListVO>> memberOrderList(@RequestBody MemberOrderQueryDTO dto) {
        return Result.success("查询成功", tbOrderInfoService.memberOrderList(dto));
    }

    @Operation(summary = "优惠券订单列表")
    @PostMapping("/couponOrderList")
    public Result<RowsData<CouponOrderListVO>> couponOrderList(@RequestBody CouponOrderQueryDTO dto) {
        return Result.success("查询成功", tbOrderInfoService.couponOrderList(dto));
    }

    @Operation(summary = "订单详情")
    @GetMapping("/orderDetails")
    public Result<OrderDetailsVO> orderDetails(@RequestParam Long orderId) {
        return Result.success("查询成功", tbOrderInfoService.orderDetails(orderId));
    }

    @Operation(summary = "审核投诉订单")
    @PostMapping("/reviewComplaintOrders")
    public Result<String> reviewComplaintOrders(@RequestBody @Validated ReviewComplaintOrdersDTO dto) {
        tbOrderInfoService.reviewComplaintOrders(dto);
        return Result.success("操作成功");
    }

    @Operation(summary = "平台财务统计列表")
    @PostMapping("/financialOrderList")
    public Result<RowsData<FinancialOrderListVO>> financialOrderList(@RequestBody FinancialOrderQueryDTO dto) {
        return Result.success("查询成功", tbOrderInfoService.financialOrderList(dto));
    }

    @Log(title = "平台财务统计管理", businessType = BusinessType.EXPORT)
    @PostMapping("/financialExport")
    public void export(HttpServletResponse response, FinancialOrderQueryDTO dto) {
        List<FinancialOrderListVO> list = tbOrderInfoService.financialOrderList(dto).getRows();
        ExcelUtil<FinancialOrderListVO> util = new ExcelUtil<FinancialOrderListVO>(FinancialOrderListVO.class);
        util.exportExcel(response, list, "平台财务统计数据");
    }
}
