package com.pusong.business.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaIgnore;
import com.pusong.business.domain.bo.PsSalaryBo;
import com.pusong.business.domain.vo.PsSalaryContractVo;
import com.pusong.business.domain.vo.PsSalaryVo;
import com.pusong.business.domain.vo.home.*;
import com.pusong.business.service.HomeService;
import com.pusong.business.service.IPsSalaryService;
import com.pusong.common.core.domain.R;
import com.pusong.common.mybatis.core.page.PageQuery;
import com.pusong.common.mybatis.core.page.TableDataInfo;
import com.pusong.common.web.core.BaseController;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
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;

import java.util.Map;

import java.util.List;
import java.util.Map;

/**
 * 员工提成提成
 *
 * @author wls
 * @date 2024-08-23
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/business/home")
@SaIgnore
public class HomeController extends BaseController {

    private final HomeService homeService;

    /**
     * 首页大盘数据：成交总金额
     * @param type 1本月 2上月 3本季度 4本年 5所有
     * @return
     */
    @SaCheckPermission("business:salary:list")
    @GetMapping("/selectMakeAmount")
    public R<MakeAmountVo> selectMakeAmount(@RequestParam() Integer type) {
        return R.ok(homeService.selectMakeAmount(type));
    }

    /**
     * 首页大盘数据：回款情况
     * @param type 1本月 2上月 3本季度 4本年 5所有
     * @return
     */
    @SaCheckPermission("business:salary:list")
    @GetMapping("/returnMoney")
    public R<ReturnMoneyInfoVo> returnMoney(@RequestParam() Integer type) {
        return R.ok(homeService.returnMoney(type));
    }

    /**
     * 首页大盘数据：人员成交数据列表
     * @param type 1本月 2上月 3本季度 4本年 5所有
     * @return
     */
    @SaCheckPermission("business:salary:list")
    @GetMapping("/getUserContractAmounts")
    public R<List> getUserContractAmounts(@RequestParam() Integer type, @RequestParam() Long deptId)  {
        return R.ok(homeService.getUserContractAmountsByDeptId(type,deptId));
    }

    /**
     * 首页大盘数据：人员转介绍成交数据列表
     * @param type 1本月 2上月 3本季度 4本年 5所有
     * @return
     */
    @SaCheckPermission("business:salary:list")
    @GetMapping("/getUserContractSourceAmounts")
    public R<Object> getUserContractSourceAmounts(@RequestParam() Integer type, @RequestParam() Long deptId){
        return R.ok(homeService.getUserContractSourceAmountsByDeptId(type,deptId));
    }

    /**
     * 首页大盘数据：人员成交数据饼图
     * @param type
     * @return
     */
    @GetMapping("/getUserContractAndPayInfo")
    public R<Object> getUserContractAndPayInfo(@RequestParam() Integer type){
        return R.ok(homeService.getUserContractAndPayInfo(type));
    }
    /**
     * 首页大盘数据：各渠道成交(公司总数居)
     * @param type 1本月 2上月 3本季度 4本年 5所有
     * @return
     */
    @SaCheckPermission("business:salary:list")
    @GetMapping("/byChannel")
    public R<ChannelAmountVo> byChannel(@RequestParam() Integer type) {
        return R.ok(homeService.byChannel(type,1));
    }
    /**
     * 首页大盘数据：销售个人数据
     * @param type 1本月 2上月 3本季度 4本年 5所有
     * @return
     */
    @SaCheckPermission("business:salary:list")
    @GetMapping("/channelByUser")
    public R<ChannelAmountVo> channelByUser(@RequestParam() Integer type) {
        return R.ok(homeService.byChannel(type,2));
    }
    /**
     * 首页大盘数据：任务完成情况
     * @param type 1本月 2上月 3本季度 4本年 5所有
     * @return
     */
    @GetMapping("/getTaskFinish")
    public R<FinishTaskVo> getTaskFinish(@RequestParam() Integer type) {
        return R.ok(homeService.getTaskList(type));
    }

    /**
     * 首页大盘数据：任务完成平均时间
     * @param type 1本月 2上月 3本季度 4本年 5所有
     * @return
     */
    @GetMapping("/getTaskTime")
    public R<Map<String,Object>> getTaskTime(@RequestParam() Integer type) {
        return R.ok(homeService.getTaskTime(type));
    }

    /**
     * 首页大盘数据：销售数据统计
     * @param type 1本月 2上月 3本季度 4本年 5所有
     * @return
     */
    @GetMapping("/salasData")
    public R<Map<String,Object>> salasData(@RequestParam() Integer type) {
        return R.ok(homeService.salasData(type));
    }
}
