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();
        }
    }

    /**
     * 找到所有推广为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();
        }
    }



}
