package cn.pluss.platform.controller.newArea;

import cn.pluss.platform.controller.BaseNoModelController;
import cn.pluss.platform.entity.NewArea;
import cn.pluss.platform.newArea.NewAreaService;
import cn.pluss.platform.util.StringUtil;
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.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("newArea")
public class NewAreaController  extends BaseNoModelController {

	  private Integer PAGE_SIZE=12;

    @Autowired
	  private NewAreaService newAreaService;

    /**
    *引导页
    * @return
    */
    @RequestMapping(value = "/index", method = RequestMethod.GET)
    public String index() {
   
        return "newArea/newAreaList";
    }

    /**
    *分页查询
    */
    @RequestMapping(value = "/queryNewAreaByPage", method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> queryNewAreaByPage(Integer currPage,Integer id){
   
   	if(currPage==null) {
   	   currPage=1;
       }
    	Map<String,Object> map=new HashMap<String, Object>();
    	map.put("pageSize",PAGE_SIZE);
    	map.put("offset", (currPage-1)*PAGE_SIZE);
    	map.put("id",  id);
    	List<NewArea> newAreaList=newAreaService.queryNewAreaPage(map);
    	Integer count=newAreaService.queryNewAreaPageCount(map);
        Map<String,Object> result=new HashMap<String,Object>();
        result.put("newAreaList", newAreaList);
        result.put("count", count);
        result.put("pageCount",StringUtil.getPageCount(count,PAGE_SIZE));
        result.put("currPage", currPage);
    	  return result;
    }
    /**
    *查询详情
    */
     @RequestMapping(value = "/queryNewAreaDetails", method = RequestMethod.GET)
    public String queryNewAreaDetails(HttpServletRequest request,Integer id,Integer pageIndex){
   
   	  if(id!=null&&id!=0) {
   		 NewArea newArea=new NewArea();
   		 newArea.setId(id);
           newArea=newAreaService.queryNewArea(newArea);
          request.setAttribute("newArea", newArea);
   		request.setAttribute("pageIndex", pageIndex);
       	}
        return "newArea/newAreaDetails";
    }
    /**
    *查询详情
    */
     @RequestMapping(value = "/queryNewAreaBaseInfo", method = RequestMethod.GET)
    public String queryNewAreaBaseInfo(HttpServletRequest request,Integer id,Integer pageIndex){
   
   	  if(id!=null&&id!=0) {
   		NewArea newArea=new NewArea();
   		newArea.setId(id);
        newArea=newAreaService.queryNewArea(newArea);
          request.setAttribute("newArea", newArea);
   		request.setAttribute("pageIndex", pageIndex);
       	}
        return "newArea/newAreaBaseInfo";
    }
    /**
    *查询详情
    */
     @RequestMapping(value = "/queryNewAreaExtendsInfo", method = RequestMethod.GET)
    public String queryNewAreaExtendsInfo(){
   
        return "newArea/newAreaExtendsInfo";
    }
    /**
    *查询详情
    */
     @RequestMapping(value = "/queryNewAreaFunctionsInfo", method = RequestMethod.GET)
    public String queryNewAreaFunctionsInfo(){
   
        return "newArea/newAreaFunctionsInfo";
    }
    /**
    *保存对象
    *@throws IOException
    */
    @RequestMapping(value = "/saveNewArea", method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> saveNewArea(NewArea newArea){
   
       if(newArea.getId()!=null&&newArea.getId()!=0){
    		newAreaService.updateNewArea(newArea);
    	 }else{  
      	newAreaService.saveNewArea(newArea);
    	 }  
		Map<String,Object> result=new HashMap<String,Object>();
    	result.put("resultCode", "1");
    	result.put("resultMessage", "保存成功!");
    	return result;
    }
    /**
    *修改对象
    *@throws IOException
    */
    @RequestMapping(value = "/updateNewArea", method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> updateNewArea(Integer id){
   
   	NewArea newArea=new NewArea();
   	newArea.setId(id);
      newAreaService.updateNewArea(newArea);
   	Map<String,Object> result=new HashMap<String,Object>();
    	result.put("resultCode", "1");
    	result.put("resultMessage", "保存成功!");
    	return result;
    }
    /**
    *删除对象
    *@throws IOException
    */
    @RequestMapping(value = "/deleteNewArea", method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> deleteNewArea(Integer id){
   	NewArea newArea=new NewArea();
   	newArea.setId(id);
		newAreaService.deleteNewArea(newArea);
		Map<String,Object> result=new HashMap<String,Object>();
    	result.put("resultCode", "1");
    	result.put("resultMessage", "保存成功!");
    	return result;
    }

}


