package com.kxs.stat.biz.controller;

import com.kxs.common.core.util.R;
import com.kxs.common.security.util.SecurityUtils;
import com.kxs.stat.api.dto.statUser.StatUserGetMyTradeDTO;
import com.kxs.stat.api.dto.statUser.StatUserGetTradeDetailDTO;
import com.kxs.stat.api.dto.statUser.StatUserGetUserStatByDayOrMonthDTO;
import com.kxs.stat.api.dto.statUser.StatUserGetUserTradeListDTO;
import com.kxs.stat.biz.service.KxsMerchantTradeService;
import com.kxs.stat.biz.service.KxsUserActTradeService;
import com.kxs.stat.biz.service.KxsUserTradeService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 我的创客(StatUser)控制层
 *
 * @author 系统
 * @since 2024-05-15 11:18:44
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("statUser")
public class KxsStatUserController {

    /**
     * 服务对象
     */
    private final KxsUserTradeService kxsUserTradeService;

    private final KxsUserActTradeService kxsUserActTradeService;

    /**
     * 用户详情-获取用户统计数据
     *
     * @param param 访问实体
     * @return 用户详情-获取用户统计数据
     */
    @GetMapping("/getUserStatByDayOrMonth")
    public R getUserStatByDayOrMonth(@ParameterObject @Valid StatUserGetUserStatByDayOrMonthDTO param) {
        return kxsUserTradeService.getUserStatByDayOrMonth(param);
    }

    /**
     * 计奖交易趋势图
     *
     * @param totalType 总类型 0个人 1团队
     * @param type      类型 0近7日 1近半年
     * @return {@link R}
     */
    @GetMapping("/getUserTrend")
    public R getUserTrend(@RequestParam("totalType") Integer totalType, @RequestParam("type") Integer type){

        return kxsUserTradeService.getUserTrend(totalType, type);
    }




    /**
     * 计奖交易-首页交易总额
     *
     * @return 计奖交易-首页交易总额
     */
    @GetMapping("/getHomeAmount")
    public R getHomeAmount() {
        Long userId = SecurityUtils.getUser().getId();
        return kxsUserTradeService.getHomeAmount(userId);
    }


    /**
     *
     * 计奖交易-交易统计页面
     *
     * @param param 查询实体
     * @return 计奖交易-我的业绩
     */
    @GetMapping("/getUserTradeStatList")
    public R getUserTradeStatList(@Valid @ParameterObject StatUserGetUserTradeListDTO param) {
        if (param.getUserId().equals(0L)){
            param.setUserId(SecurityUtils.getUser().getId());
        }
        return kxsUserTradeService.getUserTradeStatList(param);
    }


    /**
     * 计奖交易-激活商户统计
     *
     * @param totalType 统计类型 0 个人  1 团队
     * @return 计奖交易-激活商户统计
     */
    @GetMapping("/getActivateMerchantList")
    public R getActivateMerchantList(@RequestParam("totalType")Integer totalType, @RequestParam("userId")Long userId,@RequestParam("month")String month) {
        if (userId == 0){
            userId = SecurityUtils.getUser().getId();
        }
        return kxsUserActTradeService.getActivateMerchantList(totalType,userId,month);
    }

    /**
     * 计奖交易-我的业绩
     *
     * @param param 查询实体
     * @return 计奖交易-我的业绩
     */
    @GetMapping("/getMyTrade")
    public R getMyTrade(@ParameterObject StatUserGetMyTradeDTO param) {

        return kxsUserTradeService.getMyTrade(param);
    }

    /**
     * 计奖交易-交易统计页面-交易明细
     *
     * @param param 查询实体
     * @return 计奖交易-交易统计页面-交易明细
     */
    @GetMapping("/getTradeDetail")
    public R getTradeDetail(@ParameterObject StatUserGetTradeDetailDTO param) {
        return kxsUserTradeService.getTradeDetail(param);
    }
}

