package com.kiisoo.ic.ls.controller;

import com.kiisoo.ic.common.BaseController;
import com.kiisoo.ic.ls.bean.*;
import com.kiisoo.ic.ls.service.LargeScreenAnalysisService;
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: 大屏数据分析controller
 * @Auther: yechenhao
 * @Date: 2020/5/11 14:54
 * @Version: v1
 */
@Controller
@RequestMapping("/ls/analysis")
@Slf4j
public class LargeScreenAnalysisController extends BaseController {

    @Autowired
    private LargeScreenAnalysisService largeScreenAnalysisService;

    /**
     * 查询总拓客和新增拓客
     * @param startDate 开始时间
     * @param endDate 结束时间
     * @return
     */
    @RequestMapping(value = "info",method = RequestMethod.GET)
    @ResponseBody
    public Map<String,Object> listAddInfo(@RequestParam("userId") Long userId,
                                                   @RequestParam("startDate") String startDate,
                                                   @RequestParam("endDate") String endDate){
        try{
            LsInfoDTO results = largeScreenAnalysisService.listAddInfo(userId,startDate,endDate);
            return data(results);
        }catch (Exception e){
            log.error("查询零售公司店均拓客TOP10失败",e);
            return fail();
        }
    }

    /**
     * 查询省拓客
     * @param startDate 开始时间
     * @param endDate 结束时间
     * @return
     */
    @RequestMapping(value = "province/info",method = RequestMethod.GET)
    @ResponseBody
    public Map<String,Object> listProvinceInfo(@RequestParam("userId") Long userId,
                                                   @RequestParam("startDate") String startDate,
                                                   @RequestParam("endDate") String endDate){
        try{
            List<ProvinceAddInfoDTO> results = largeScreenAnalysisService.listProvinceInfo(userId,startDate,endDate);
            return data(results);
        }catch (Exception e){
            log.error("查询省拓客失败",e);
            return fail();
        }
    }

    /**
     * 查询零售公司店均拓客TOP10
     * @param startDate 开始时间
     * @param endDate 结束时间
     * @return
     */
    @RequestMapping(value = "company/avg/add",method = RequestMethod.GET)
    @ResponseBody
    public Map<String,Object> listCompanyAvgAddTop(@RequestParam("userId") Long userId,
                                                   @RequestParam("startDate") String startDate,
                                                   @RequestParam("endDate") String endDate){
        try{
            List<CompanyAvgAddDTO> results = largeScreenAnalysisService.listCompanyAvgAddTop(userId,startDate,endDate);
            return data(results);
        }catch (Exception e){
            log.error("查询零售公司店均拓客TOP10失败",e);
            return fail();
        }
    }

    /**
     * 查询门店均拓客TOP10
     * @param startDate 开始时间
     * @param endDate 结束时间
     * @return
     */
    @RequestMapping(value = "store/add",method = RequestMethod.GET)
    @ResponseBody
    public Map<String,Object> listStoreAddTop(@RequestParam("userId") Long userId,
                                                   @RequestParam("startDate") String startDate,
                                                   @RequestParam("endDate") String endDate){
        try{
            List<StoreAddDTO> results = largeScreenAnalysisService.listStoreAddTop(userId,startDate,endDate);
            return data(results);
        }catch (Exception e){
            log.error("查询门店均拓客TOP10失败",e);
            return fail();
        }
    }

    /**
     * 查询日拓客列表
     * @param startDate 开始时间
     * @param endDate 结束时间
     * @return
     */
    @RequestMapping(value = "date/add",method = RequestMethod.GET)
    @ResponseBody
    public Map<String,Object> listDateAdd(@RequestParam("userId") Long userId,
                                                   @RequestParam("startDate") String startDate,
                                                   @RequestParam("endDate") String endDate){
        try{
            List<DateAddDTO> results = largeScreenAnalysisService.listDateAdd(userId,startDate,endDate);
            return data(results);
        }catch (Exception e){
            log.error("查询日拓客列表失败",e);
            return fail();
        }
    }
}
