package com.ylcm.sys.controller;


import java.util.List;

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

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

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ylcm.sys.domain.AdSelectType;
import com.ylcm.sys.form.AdSelectForm;
import com.ylcm.sys.service.AdSelectTypeService;



/**
 * <p>
 * 栏目管理表 前端控制器
 * </p>
 *
 * @author admin
 * @since 2020-07-01
 */
@Controller
@RequestMapping("/ad-select")
public class AdSelectTypeController extends BaseController{

    @Resource
    private AdSelectTypeService adSelectTypeService;
    
	/**
	 *    一级下拉分类菜单列表(用于select控件)
	 * @param form 
	 */
    @RequestMapping(value = "/top_category_by_type.do")
    public void getTopSelectCategoryList(AdSelectForm form
    		,HttpServletRequest request, HttpServletResponse response
    		){
        List<AdSelectType> result = adSelectTypeService.getTopSelectCategoryList(form);
		JSONArray results = new JSONArray();
		JSONObject vo = new JSONObject();
		for (AdSelectType select : result) {
			JSONObject obj = new JSONObject();
			obj.put("id", select.getName());
			obj.put("text", select.getName());
			results.add(obj);
		}
		int count = adSelectTypeService.getTopSelectCategoryTotal(form);
		vo.put("results", results);
		vo.put("total", count);
		returnResult(request, response, vo);
    }
    
    /**
	 *    二级下拉分类菜单列表(用于select控件)
	 * @param form 
	 */
    @RequestMapping(value = "/second_category_by_type.do")
    public void getSecondSelectCategoryList(AdSelectForm form
    		,HttpServletRequest request, HttpServletResponse response){
        List<AdSelectType> result = adSelectTypeService.getSecondSelectCategoryList(form);
		JSONArray results = new JSONArray();
		JSONObject vo = new JSONObject();
		for (AdSelectType select : result) {
			JSONObject obj = new JSONObject();
			obj.put("id", select.getName());
			obj.put("text", select.getName());
			results.add(obj);
		}
		int count = adSelectTypeService.getSecondSelectCategoryTotal(form);
		vo.put("results", results);
		vo.put("total", count);
		returnResult(request, response, vo);
    }
}
