package cn.pluss.platform.controller;

import cn.pluss.platform.api.Result;
import cn.pluss.platform.api.ResultGenerator;
import cn.pluss.platform.entity.UserApp;
import cn.pluss.platform.leshua.ExpandDto;
import cn.pluss.platform.service.common.SpreadService;
import cn.pluss.platform.vo.SpreadData;
import cn.pluss.platform.vo.UserNumVO;
import cn.pluss.platform.vo.UserTeamAchieVO;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author DJH
 */
@RestController
@RequestMapping("spread")
public class SpreadController {

    @Setter(onMethod_ = @Autowired)
    private SpreadService spreadService;

    @GetMapping("/expandPageData")
    public Result<Page<UserApp>> expandPageData(ExpandDto dto) {
        Page<UserApp> userAppPage = spreadService.expandPageData(dto);
        return ResultGenerator.genSuccessResult(userAppPage);
    }

    /**
     * 获取升级图片
     * @return
     */
    @GetMapping("/upgradeImg")
    public Result<String> getUpgradeImage() {
        String imgUrl = spreadService.getUpgradeImage();
        return ResultGenerator.genSuccessResult(imgUrl);
    }

    /**
     * 获取支付成功后页面的数据配置数据
     */
    @GetMapping("/paySuccessPageData")
    public Result<Map<String, Object>> paySuccessPageData() {
        Map<String, Object> result = spreadService.appPaySuccessPageData();
        return ResultGenerator.genSuccessResult(result);
    }


    @GetMapping("/todaySpreadData")
    public Result<SpreadData> todaySpreadData() {
        SpreadData spreadData = spreadService.apiTodaySpreadData();
        return ResultGenerator.genSuccessResult(spreadData);
    }

    @GetMapping("/historySpreadPageData")
    public Result<Page<SpreadData>> historySpreadPageData(Page<SpreadData> page, String type, String target) {
        page.getOrders().clear();
        page.getOrders().add(OrderItem.desc("startDate"));
        Page<SpreadData> pageData = spreadService.apiHistorySpreadPageData(page, type, target);
        return ResultGenerator.genSuccessResult(pageData);
    }

    /**
     * 查询团队业绩
     * @date: 2022/1/24 14:23
     * @param vo:
     * @return cn.pluss.platform.api.Result<com.baomidou.mybatisplus.extension.plugins.pagination.Page<cn.pluss.platform.vo.UserTeamAchieVO>>
     */
    @GetMapping("/getUserTeamAchie")
    public Result<Page<UserTeamAchieVO>> getUserTeamAchie(Page<UserTeamAchieVO> page,UserTeamAchieVO vo) {
        page = spreadService.userTeamAchiePage(page,vo);
        return ResultGenerator.genSuccessResult(page);
    }

    /**
     * 获取用户团队交易流水
     * @date: 2022/1/24 22:50
     * @param vo:
     */
    @GetMapping("/getUserFlow")
    public Result<UserTeamAchieVO> getUserFlow(UserTeamAchieVO vo) {
        UserTeamAchieVO result = spreadService.getAppUserTeanFlow(vo);
        return ResultGenerator.genSuccessResult(result);
    }

    /**
     * 获取直推商户数量信息
     * @date: 2022/1/24 22:50
     * @param vo:
     */
    @GetMapping("/getUserDirectMercInfo")
    public Result<UserNumVO> getUserDirectMercInfo(UserNumVO vo) {
        UserNumVO result = spreadService.getUserDirectNumInfo(vo,UserNumVO.DATA_TYPE_MERCHANT);
        return ResultGenerator.genSuccessResult(result);
    }


    /**
     * 获取直推成员数量信息
     * @date: 2022/1/24 22:50
     * @param vo:
     */
    @GetMapping("/getUserDirectMemberInfo")
    public Result<UserNumVO> getUserDirectMemberInfo(UserNumVO vo) {
        UserNumVO result = spreadService.getUserDirectNumInfo(vo,UserNumVO.DATE_TYPE_MEMBER);
        return ResultGenerator.genSuccessResult(result);
    }
}
