package com.kiisoo.ic.customer.controller;

import com.kiisoo.ic.common.BaseController;
import com.kiisoo.ic.customer.entity.CustomerViewVO;
import com.kiisoo.ic.customer.entity.CustomerViewZeroExtendVO;
import com.kiisoo.ic.customer.service.CustomerViewService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

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

/**
 * @Description: 客户数据概览
 * @Author: wangyinjia
 * @Date: 2020/4/9
 * @Company: kiisoo
 * @Version: 1.0
 */
@Slf4j
@Controller
@RequestMapping("/customer/view")
public class CustomerViewController extends BaseController {

    /**
     * 客户数据概览service
     */
    @Autowired
    private CustomerViewService customerViewService;

    /**
     * 客户概览main——趋势图
     * @param userId 用户id
     * @param selectStartTime 选中开始时间
     * @param selectEndTime 选中结束时间
     * @param startTime 柱状图开始时间
     * @param endTime 柱状图结束时间
     * @return 客户概览VO
     */
    @ResponseBody
    @RequestMapping(value = "/main", method = RequestMethod.GET)
    public Map<String,Object> getMainData(@RequestParam("userId")Long userId, @RequestParam("selectStartTime")String selectStartTime, @RequestParam("selectEndTime")String selectEndTime,
                                          @RequestParam("startTime")String startTime, @RequestParam("endTime")String endTime){
        try{
            CustomerViewVO result = customerViewService.selectCustomerViewMain(userId, selectStartTime, selectEndTime, startTime, endTime);
            return data(result);
        }catch (Exception e){
            log.error("查询客户数据概览出错", e);
            return fail();
        }
    }

    /**
     * 客户概览——Top榜
     * @param userId 用户id
     * @param selectStartTime 选中开始时间
     * @param selectEndTime 选中结束时间
     * @return 客户概览VO
     */
    @ResponseBody
    @RequestMapping(value = "/main/date", method = RequestMethod.GET)
    public Map<String,Object> getMainDataDate(@RequestParam("userId")Long userId, @RequestParam("selectStartTime")String selectStartTime, @RequestParam("selectEndTime")String selectEndTime){
        try{
            CustomerViewVO result = customerViewService.selectCustomerViewMainDate(userId, selectStartTime, selectEndTime);
            return data(result);
        }catch (Exception e){
            log.error("查询客户数据概览出错", e);
            return fail();
        }
    }

    /**
     * 客户概览——拉黑数
     * @param userId 用户id
     * @return 客户概览VO
     */
    @ResponseBody
    @RequestMapping(value = "/main/del", method = RequestMethod.GET)
    public Map<String,Object>getMainDataDate(@RequestParam("userId")Long userId){
        try{
            CustomerViewVO result = customerViewService.getDelNum(userId);
            return data(result);
        }catch (Exception e){
            log.error("查询客户数据概览出错", e);
            return fail();
        }
    }

    /**
     * 客户概览——好友总数，好友去重数
     * @return 客户概览VO
     */
    @ResponseBody
    @RequestMapping(value = "/all/count", method = RequestMethod.GET)
    public Map<String,Object> getAllCount(){
        try{
            CustomerViewVO result = customerViewService.getAllCount();
            return data(result);
        }catch (Exception e){
            log.error("查询客户数据概览出错", e);
            return fail();
        }
    }

    /**
     * 全量同步总数
     * @return 客户概览VO
     */
    @RequestMapping(value = "/sync/all/count", method = RequestMethod.GET)
    public void syncAllCount(){
        try{
            customerViewService.syncAllCount();
        }catch (Exception e){
            log.error("全量同步总数出错", e);
        }
    }

    /**
     * 批量同步总数
     * @return 客户概览VO
     */
    @RequestMapping(value = "/sync/alive/count", method = RequestMethod.GET)
    public void syncAliveCount(){
        try{
            customerViewService.syncAliveCount();
        }catch (Exception e){
            log.error("批量同步总数出错", e);
        }
    }

    /**
     * 同步会员数据
     * @return
     */
    @RequestMapping(value = "/sync/vip", method = RequestMethod.GET)
    @ResponseBody
    public void syncVip(){
        try{
            customerViewService.syncVip();
        }catch (Exception e){
            log.error("批量同步总数出错", e);
        }
    }

    /**
     * 找到所有推广为0店铺
     * @param userId 用户id
     * @param regionId 大区id
     * @param companyId 公司id
     * @param customerId 客户公司id
     * @param startTime 开始时间
     * @param endTime 结束时间
     * @param pageNum
     * @param pageSize
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/all/zero", method = RequestMethod.GET)
    public Map<String,Object> getMainData(@RequestParam("userId") long userId, Long regionId , Long companyId, Long customerId,
                                          String startTime, String endTime, @RequestParam("pageNum") int pageNum, @RequestParam("pageSize") int pageSize){
        try{
            List<CustomerViewZeroExtendVO> result = customerViewService.zeroExtendList(userId, regionId, companyId, customerId, startTime, endTime, pageNum,pageSize);
            return data(result);
        }catch (Exception e){
            log.error("查询推广为0店铺出错", e);
            return fail();
        }
    }



}
