package com.ylcm.sys.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ylcm.sys.common.Constants;
import com.ylcm.sys.form.AdSpecialAnalysisQueryForm;
import com.ylcm.sys.service.SpecialAnalysisService;
import com.ylcm.sys.vo.AdSpecialAnalysisVO;
import com.ylcm.sys.vo.AdSpecialTopVO;

import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONObject;

@Slf4j
@Controller
public class SpecialAnalysisController extends BaseController{

	@Resource
	private SpecialAnalysisService specialAnalysisService;
	
	@RequestMapping(value = "/special_analysis.do")
	public String brandAnalysis(ModelMap model) {
		/**
		 * 1.跳转到列表页面
		 */
		return "analysis/special_analysis";
	}
	
	@RequestMapping(value = "/ajax_special_analysis_list.do")
	public void ajaxSearchList(HttpServletResponse response, AdSpecialAnalysisQueryForm queryForm) {
		try {
			
			IPage<AdSpecialAnalysisVO> page = specialAnalysisService.page(queryForm);
			/**
			 * 3.返回结果
			 */
			JSONObject jsonobj = new JSONObject();
			jsonobj.put("data", page);
			jsonobj.put("code", Constants.CODE_SUCCESS);
			ajaxJson(jsonobj.toString(), response);
		} catch (Exception e) {
			log.error(e.getMessage(), e);
			ajaxJson("{\"code\":\"0\",\"msg\":\"获取列表失败\"}", response);
		}
	}
	
	//产品专题广告投放排名
	@RequestMapping(value = "/list_special_product_rank.do")
	public void list_special_product_rank(HttpServletResponse response, Integer type, String startDate, String endDate) {
		try {
			
			List<AdSpecialTopVO> list = specialAnalysisService.specialTop(type, startDate, endDate);
			
			JSONObject jsonobj = new JSONObject();
			jsonobj.put("data", list);
			jsonobj.put("code", Constants.CODE_SUCCESS);
			ajaxJson(jsonobj.toString(), response);
		} catch (Exception e) {
			log.error(e.getMessage(), e);
			ajaxJson("{\"code\":\"0\",\"msg\":\"获取列表失败\"}", response);
		}
	}
}
