package com.fs.stats;

import com.fs.common.core.domain.R;
import com.fs.company.service.ICompanyService;
import com.fs.company.vo.DeptDataVO;
import com.fs.sop.service.IQwSopService;
import com.fs.sop.vo.QwSopTask;
import com.fs.statis.domain.FsStatisSalerWatch;
import com.fs.statis.dto.StatsWatchLogPageListDTO;
import com.fs.statis.service.FsStatisSalerWatchService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.AllArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 看课统计接口
 */
@RestController
@RequestMapping("/stats")
@AllArgsConstructor
public class SalesWatchStatisController {

    @Autowired
    private FsStatisSalerWatchService fsStatisSalerWatchService;

    @Autowired
    private IQwSopService qwSopService;

    @Autowired
    private ICompanyService companyService;

    /**
     * 销售完播统计查询
     * @param param param
     * @return R
     */
    @PostMapping("/seller/pageList")
    public R sellerQueryList(@RequestBody StatsWatchLogPageListDTO param){
        if(param.getPageNum() == null) {
            param.setPageNum(1);
        }
        if(param.getPageSize() == null) {
            param.setPageSize(10);
        }
        PageHelper.startPage(param.getPageNum(), param.getPageSize());

        List<FsStatisSalerWatch> list = fsStatisSalerWatchService.queryList(param);
        return R.ok().put("data",new PageInfo<>(list));
    }

    /**
     * 训练营完播统计查询
     * @param param param
     * @return R
     */
    @PostMapping("/period/pageList")
    public R periodQueryList(@RequestBody StatsWatchLogPageListDTO param){
        if(param.getPageNum() == null) {
            param.setPageNum(1);
        }
        if(param.getPageSize() == null) {
            param.setPageSize(10);
        }
        PageHelper.startPage(param.getPageNum(), param.getPageSize());

        List<FsStatisSalerWatch> list = fsStatisSalerWatchService.queryPeriodList(param);
        return R.ok().put("data", new PageInfo<>(list));
    }

    /**
     * 每日完播统计查询
     * @param param param
     * @return R
     */
    @PostMapping("/everyDay/pageList")
    public R everyDayQueryList(@RequestBody StatsWatchLogPageListDTO param){
        if(param.getPageNum() == null) {
            param.setPageNum(1);
        }
        if(param.getPageSize() == null) {
            param.setPageSize(10);
        }
        PageHelper.startPage(param.getPageNum(), param.getPageSize());
        List<FsStatisSalerWatch> list = fsStatisSalerWatchService.queryTodayList(param);
        return R.ok().put("data", new PageInfo<>(list));
    }

    /**
     * 获取SOP任务数据
     * @return
     */
    @GetMapping("/sopTaskData")
    public R getSOPTaskData(){
        List<QwSopTask> qwSopTaskList = qwSopService.getQwSopTaskList();

        return R.ok().put("data",qwSopTaskList);
    }

    /**
     * 获取部门数据
     * @return
     */
    @GetMapping("/getDeptData")
    public R getDeptData(Long companyId){
        List<DeptDataVO> data = companyService.getDeptData(companyId);
        return R.ok().put("data",data);
    }

}
