package shop.alien.store.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import shop.alien.entity.result.R;
import shop.alien.entity.store.ManagementInfo;
import shop.alien.entity.store.vo.ManagementInfoVo;
import shop.alien.store.service.ManagementInfoService;

import java.util.HashMap;
import java.util.List;

@Api(tags = {"平台-对账结算"})
@Slf4j
@RestController
@CrossOrigin
@RequestMapping("/management_info")
@RequiredArgsConstructor
public class ManagementInfoController {

    private final ManagementInfoService managementInfoService;

    @ApiOperation("对账结算店铺套餐、代金券信息统计查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "分页序数", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "size", value = "分页长度", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "storeName", value = "商家名称", dataType = "String", paramType = "query")
    })
    @GetMapping("/getManagementInfo")
    public R<IPage<ManagementInfo>> getAllManagementInfo(
            @RequestParam(value = "page", defaultValue = "1") int page,
            @RequestParam(value = "size", defaultValue = "10") int size,
            @RequestParam(value = "storeName", required = false) String storeName) {
        return R.data(managementInfoService.getAllManagementInfo(page, size, storeName));
    }

    @ApiOperation("店铺账单统计")
    @ApiImplicitParams({@ApiImplicitParam(name = "queryType", value = "周期类型（year：年，month：月，周：week）", dataType = "String", paramType = "query")})
    @GetMapping("/storeBillingStatistics")
    public R<HashMap<String, Object>> storeBillingStatistics(
            @RequestParam(value = "queryType", required = false) String queryType) {
        return R.data(managementInfoService.storeBillingStatistics(queryType));
    }

    @ApiOperation("获取店铺订单详情，根据id")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "storeId", value = "店铺id", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "page", value = "分页序数", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "size", value = "分页长度", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "orderNo", value = "订单号", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "userId", value = "用户ID", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "userName", value = "用户名", dataType = "String", paramType = "query")
    })
    @GetMapping("/getStoreOrderDetail")
    public R<IPage<ManagementInfoVo>> getStoreOrderDetail(
            @RequestParam(value = "page", defaultValue = "1") int page,
            @RequestParam(value = "size", defaultValue = "10") int size,
            @RequestParam(value = "storeId", required = false) String storeId,
            @RequestParam(value = "orderNo", required = false) String orderNo,
            @RequestParam(value = "userId", required = false) String userId,
            @RequestParam(value = "userName", required = false) String userName) {
        return R.data(managementInfoService.getStoreOrderDetail(page, size, storeId, orderNo, userId, userName));
    }

    @ApiOperation("店铺详情账单统计")
    @ApiImplicitParams({@ApiImplicitParam(name = "storeId", value = "店铺id", dataType = "String", paramType = "query")})
    @GetMapping("/storeDetailBillingStatistics")
    public R<HashMap<String, Object>> storeDetailBillingStatistics(
            @RequestParam(value = "storeId", required = false) String storeId) {
        return R.data(managementInfoService.storeDetailBillingStatistics(storeId));
    }

    @ApiOperation("提现申请列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "storeName", value = "店铺名称", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "page", value = "分页序数", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "size", value = "分页长度", dataType = "String", paramType = "query")
    })
    @GetMapping("/getApplicationForWithdrawal")
    public R<IPage<ManagementInfoVo>> getApplicationForWithdrawal(
            @RequestParam(value = "page", defaultValue = "1") int page,
            @RequestParam(value = "size", defaultValue = "10") int size,
            @RequestParam(value = "storeId", required = false) Integer storeId,
            @RequestParam(value = "storeName", required = false) String storeName) {
        return R.data(managementInfoService.getApplicationForWithdrawal(page, size, storeId, storeName));
    }

    @ApiOperation("提现申请详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "提现申请id", dataType = "Integer", paramType = "query")
    })
    @GetMapping("/getCashOutDetail")
    public R<ManagementInfoVo> getCashOutDetail(
            @RequestParam(value = "id") Integer id) {
        return R.data(managementInfoService.getCashOutDetail(id));
    }

    @ApiOperation("生成结算回执单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "cashId", value = "提现记录id", dataType = "String", paramType = "query"),
    })
    @GetMapping("/generateClearingReceipt")
    public R<HashMap<String, Object>> generateClearingReceipt(
            @RequestParam(value = "cashId", required = false) String cashId) {
        HashMap<String, Object> stringObjectHashMap = managementInfoService.generateClearingReceipt(cashId);
        return R.data(stringObjectHashMap);
    }

    @ApiOperation("数据可视化-获取基础统计数据 ---（今日平台净利润、平台总计净利润、今日订单量、总订单量、今日成交金额、总成交金额）")
    @GetMapping("/getBasicStatistics")
    public R<HashMap<String, Object>> getBasicStatistics() {
        HashMap<String, Object> stringObjectHashMap = managementInfoService.getBasicStatistics();
        return R.data(stringObjectHashMap);
    }

    @ApiOperation("数据可视化-获取净利润")
    @GetMapping("/getQueryNetProfit")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "查询类型（日:0，周:1，月:2，年:3）", dataType = "Integer", paramType = "query"),
    })
    public R<List<ManagementInfoVo>> getQueryNetProfit(@RequestParam(value = "type", required = false) Integer type) {
        List<ManagementInfoVo> stringObjectHashMap = managementInfoService.getQueryNetProfit(type);
        return R.data(stringObjectHashMap);
    }

    @ApiOperation("数据可视化-获取成交金额")
    @GetMapping("/getTradingVolume")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "查询类型（日:0，周:1，月:2，年:3）", dataType = "Integer", paramType = "query"),
    })
    public R<List<ManagementInfoVo>> getTradingVolume(@RequestParam(value = "type", required = false) Integer type) {
        List<ManagementInfoVo> stringObjectHashMap = managementInfoService.getTradingVolume(type);
        return R.data(stringObjectHashMap);
    }

    @ApiOperation("数据可视化-获取订单量")
    @GetMapping("/getOrderQuantity")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "查询类型（日:0，周:1，月:2，年:3）", dataType = "Integer", paramType = "query"),
    })
    public R<List<ManagementInfoVo>> getOrderQuantity(@RequestParam(value = "type", required = false) Integer type) {
        List<ManagementInfoVo> stringObjectHashMap = managementInfoService.getOrderQuantity(type);
        return R.data(stringObjectHashMap);
    }

    @ApiOperation("数据可视化-商铺订单销量排行（单）TOP 10")
    @GetMapping("/getSalesVolume")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "查询类型（日:0，周:1，月:2，年:3）", dataType = "Integer", paramType = "query"),
    })
    public R<List<ManagementInfoVo>> getSalesVolume(@RequestParam(value = "type", required = false) Integer type) {
        List<ManagementInfoVo> stringObjectHashMap = managementInfoService.getSalesVolume(type);
        return R.data(stringObjectHashMap);
    }

    @ApiOperation("数据可视化-平台净利润（￥） 详情")
    @GetMapping("/getStorePlatformProfitDetails")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "分页序数", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "size", value = "分页长度", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "type", value = "查询类型（1：当日，2：所有）", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "storeId", value = "商家id", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "startTime", value = "开始时间", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "entTime", value = "结束时间", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "storeName", value = "店铺名称", dataType = "String", paramType = "query"),
    })
    public R<IPage<ManagementInfoVo>> getStorePlatformProfitDetails(@RequestParam(value = "page", defaultValue = "1") int page,
                                                                    @RequestParam(value = "size", defaultValue = "10") int size,
                                                                    @RequestParam(value = "type", required = false) String type,
                                                                    @RequestParam(value = "storeId", required = false) String storeId,
                                                                    @RequestParam(value = "startTime", required = false) String startTime,
                                                                    @RequestParam(value = "entTime", required = false) String entTime,
                                                                    @RequestParam(value = "storeName", required = false) String storeName) {
        IPage<ManagementInfoVo> storePlatformProfitDetails = managementInfoService.getStorePlatformProfitDetails(page, size, storeId, type, startTime, entTime, storeName);
        return R.data(storePlatformProfitDetails);
    }

    @ApiOperation("数据可视化-平台订单量（￥） 详情")
    @GetMapping("/getStorePlatformOrderVolume")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "分页序数", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "size", value = "分页长度", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "type", value = "查询类型（1：当日，2：所有）", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "tabType", value = "订单类型(全部，传空; 0，待付款;4，已取消;1，待使用;7，已完成;5，已退款;)", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "orderId", value = "订单编号", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "startTime", value = "开始时间", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "entTime", value = "结束时间", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "couponName", value = "商品名称", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "couponType", value = "商品类型", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "storeName", value = "店铺名称", dataType = "String", paramType = "query"),
    })
    public R<IPage<ManagementInfoVo>> getStorePlatformOrderVolume(@RequestParam(value = "page", defaultValue = "1") int page,
                                                                  @RequestParam(value = "size", defaultValue = "10") int size,
                                                                  @RequestParam(value = "type", required = false) String type,
                                                                  @RequestParam(value = "tabType", required = false) String tabType,
                                                                  @RequestParam(value = "orderId", required = false) String orderId,
                                                                  @RequestParam(value = "startTime", required = false) String startTime,
                                                                  @RequestParam(value = "entTime", required = false) String entTime,
                                                                  @RequestParam(value = "couponName", required = false) String couponName,
                                                                  @RequestParam(value = "couponType", required = false) String couponType,
                                                                  @RequestParam(value = "storeName", required = false) String storeName) {
        IPage<ManagementInfoVo> storePlatformProfitDetails = managementInfoService.getStorePlatformOrderVolume(page, size, orderId, type, tabType, startTime, entTime, couponName, couponType, storeName);
        return R.data(storePlatformProfitDetails);
    }

}