package cn.pluss.platform.controller.memberSetting;

import cn.pluss.platform.controller.BaseNoModelController;
import cn.pluss.platform.entity.MemberSetting;
import cn.pluss.platform.memberSetting.MemberSettingService;
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("memberSetting")
public class MemberSettingController  extends BaseNoModelController {

	  private Integer PAGE_SIZE=12;

    @Autowired
	  private MemberSettingService memberSettingService;

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

    /**
    *分页查询
    */
    @RequestMapping(value = "/queryMemberSettingByPage", method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> queryMemberSettingByPage(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<MemberSetting> memberSettingList=memberSettingService.queryMemberSettingPage(map);
    	Integer count=memberSettingService.queryMemberSettingPageCount(map);
        Map<String,Object> result=new HashMap<String,Object>();
        result.put("memberSettingList", memberSettingList);
        result.put("count", count);
        result.put("pageCount",StringUtil.getPageCount(count,PAGE_SIZE));
        result.put("currPage", currPage);
    	  return result;
    }
    /**
    *查询详情
    */
     @RequestMapping(value = "/queryMemberSettingDetails", method = RequestMethod.GET)
    public String queryMemberSettingDetails(HttpServletRequest request,Integer id,Integer pageIndex){
   
   	  if(id!=null&&id!=0) {
   		 MemberSetting memberSetting=new MemberSetting();
   		 memberSetting.setId(id);
           memberSetting=memberSettingService.queryMemberSetting(memberSetting);
          request.setAttribute("memberSetting", memberSetting);
   		request.setAttribute("pageIndex", pageIndex);
       	}
        return "memberSetting/memberSettingDetails";
    }
    /**
    *查询详情
    */
     @RequestMapping(value = "/queryMemberSettingBaseInfo", method = RequestMethod.GET)
    public String queryMemberSettingBaseInfo(HttpServletRequest request,Integer id,Integer pageIndex){
   
   	  if(id!=null&&id!=0) {
   		MemberSetting memberSetting=new MemberSetting();
   		memberSetting.setId(id);
        memberSetting=memberSettingService.queryMemberSetting(memberSetting);
          request.setAttribute("memberSetting", memberSetting);
   		request.setAttribute("pageIndex", pageIndex);
       	}
        return "memberSetting/memberSettingBaseInfo";
    }
    /**
    *查询详情
    */
     @RequestMapping(value = "/queryMemberSettingExtendsInfo", method = RequestMethod.GET)
    public String queryMemberSettingExtendsInfo(){
   
        return "memberSetting/memberSettingExtendsInfo";
    }
    /**
    *查询详情
    */
     @RequestMapping(value = "/queryMemberSettingFunctionsInfo", method = RequestMethod.GET)
    public String queryMemberSettingFunctionsInfo(){
   
        return "memberSetting/memberSettingFunctionsInfo";
    }
    /**
    *保存对象
    *@throws IOException
    */
    @RequestMapping(value = "/saveMemberSetting", method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> saveMemberSetting(MemberSetting memberSetting){
   
       if(memberSetting.getId()!=null&&memberSetting.getId()!=0){
    		memberSettingService.updateMemberSetting(memberSetting);
    	 }else{  
      	memberSettingService.saveMemberSetting(memberSetting);
    	 }  
		Map<String,Object> result=new HashMap<String,Object>();
    	result.put("resultCode", "1");
    	result.put("resultMessage", "保存成功!");
    	return result;
    }
    /**
    *修改对象
    *@throws IOException
    */
    @RequestMapping(value = "/updateMemberSetting", method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> updateMemberSetting(Integer id){
   
   	MemberSetting memberSetting=new MemberSetting();
   	memberSetting.setId(id);
      memberSettingService.updateMemberSetting(memberSetting);
   	Map<String,Object> result=new HashMap<String,Object>();
    	result.put("resultCode", "1");
    	result.put("resultMessage", "保存成功!");
    	return result;
    }
    /**
    *删除对象
    *@throws IOException
    */
    @RequestMapping(value = "/deleteMemberSetting", method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> deleteMemberSetting(Integer id){
   	MemberSetting memberSetting=new MemberSetting();
   	memberSetting.setId(id);
		memberSettingService.deleteMemberSetting(memberSetting);
		Map<String,Object> result=new HashMap<String,Object>();
    	result.put("resultCode", "1");
    	result.put("resultMessage", "保存成功!");
    	return result;
    }

}


