package org.cs.mgr.product.ctl;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.cs.constants.Constants;
import org.cs.core.ctl.BaseCtl;
import org.cs.core.service.IDicService;
import org.cs.mgr.product.model.MgmIntentOrder;
import org.cs.mgr.product.model.MgmProduct;
import org.cs.mgr.product.service.IMgmIntentOrderService;
import org.cs.mgr.product.service.IMgmProductCategoryService;
import org.cs.mgr.product.service.IMgmProductService;
import org.cs.util.Pager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
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 com.alibaba.fastjson.JSONObject;


/**
 * 
 * @ClassName: MgmProduct 
 * @Description:  
 * @author: sunny_shi
 * @date: 2018-06-09 13:29:09
 */
@Controller
@RequestMapping("/mgmIntentOrderCtl")
public class MgmIntentOrderCtl extends BaseCtl {

	private final Logger logger = LoggerFactory.getLogger(this.getClass());
	
	@Autowired
	private IMgmIntentOrderService mgmIntentOrderService;
	
	@Autowired
	private IMgmProductCategoryService mgmProductCategoryService;
	
	@Autowired
	private IDicService dicService;
	
	@RequestMapping("list")
	public String list(ModelMap mm, @RequestParam(required=false)String menuCode){
		mm.put(MENU_CODE, menuCode);
		this.set(MENU_CODE, menuCode);
		return "mgr/intent/list";	
	}
	
	@RequestMapping(value="list2", method = RequestMethod.GET, produces="application/json;charset=UTF-8")
	@ResponseBody
	public String list2(int page, int pageSize, String data){
		Map<String, String> map = getMapFromJson(data);
		
		Map<String, Object> role = (Map<String, Object>) this.get(Constants.USER_ROLE);
		if(role.get("ONE_CATEGORY_ID") == null){
			map.put("oneid", "");
		}else{
			map.put("oneid", role.get("ONE_CATEGORY_ID").toString());
		}
		if(role.get("TWO_CATEGORY_ID") == null){
			map.put("twoid", "");
		}else{
			map.put("twoid", role.get("TWO_CATEGORY_ID").toString());
		}
		if(role.get("THREE_CATEGORY_ID") == null){
			map.put("threeid", "");
		}else{
			map.put("threeid", role.get("THREE_CATEGORY_ID").toString());
		}
		if(role.get("FOUR_CATEGORY_ID") == null){
			map.put("fourid", "");
		}else{
			map.put("fourid", role.get("FOUR_CATEGORY_ID").toString());
		}
		
		Pager pager = this.mgmIntentOrderService.queryIntentPager(new Pager(page, pageSize), map);
		JSONObject json = new JSONObject();
		json.put("rows", pager.getResults());
		json.put("total", pager.getTotal());
		return JSONObject.toJSONString(json, features);
	
	}
	
	@RequestMapping("transfer")
	public String transfer(String id, String action, ModelMap mm){
		Map<String, Object> mgmProduct = null;
		if(id != null){
			Map<String, String> map = new HashMap<>();
			map.put("id", id);
			mgmProduct = this.mgmIntentOrderService.queryIntent(map);
			mm.put("mgmProduct", mgmProduct);
		}
		return "mgr/intent/" + action;
	}
	
	
	
	@RequestMapping("del")
	@ResponseBody
	public String del(String id){
		if(id != null){
			this.mgmIntentOrderService.delIntentById(id);
		}
		
		return AJAX_SUCCESS;
	}
	
		
}

