package cn.pluss.platform.controller.phoneValidateCode;

import cn.pluss.platform.controller.BaseNoModelController;
import cn.pluss.platform.entity.PhoneValidateCode;
import cn.pluss.platform.phoneValidateCode.PhoneValidateCodeService;
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("phoneValidateCode")
public class PhoneValidateCodeController  extends BaseNoModelController {

	  private Integer PAGE_SIZE=12;

    @Autowired
	  private PhoneValidateCodeService phoneValidateCodeService;

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

    /**
    *分页查询
    */
    @RequestMapping(value = "/queryPhoneValidateCodeByPage", method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> queryPhoneValidateCodeByPage(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<PhoneValidateCode> phoneValidateCodeList=phoneValidateCodeService.queryPhoneValidateCodePage(map);
    	Integer count=phoneValidateCodeService.queryPhoneValidateCodePageCount(map);
        Map<String,Object> result=new HashMap<String,Object>();
        result.put("phoneValidateCodeList", phoneValidateCodeList);
        result.put("count", count);
        result.put("pageCount",StringUtil.getPageCount(count,PAGE_SIZE));
        result.put("currPage", currPage);
    	  return result;
    }
    /**
    *查询详情
    */
     @RequestMapping(value = "/queryPhoneValidateCodeDetails", method = RequestMethod.GET)
    public String queryPhoneValidateCodeDetails(HttpServletRequest request,Integer id,Integer pageIndex){
   
   	  if(id!=null&&id!=0) {
   		 PhoneValidateCode phoneValidateCode=new PhoneValidateCode();
   		 phoneValidateCode.setId(id);
           phoneValidateCode=phoneValidateCodeService.queryPhoneValidateCode(phoneValidateCode);
          request.setAttribute("phoneValidateCode", phoneValidateCode);
   		request.setAttribute("pageIndex", pageIndex);
       	}
        return "phoneValidateCode/phoneValidateCodeDetails";
    }
    /**
    *查询详情
    */
     @RequestMapping(value = "/queryPhoneValidateCodeBaseInfo", method = RequestMethod.GET)
    public String queryPhoneValidateCodeBaseInfo(HttpServletRequest request,Integer id,Integer pageIndex){
   
   	  if(id!=null&&id!=0) {
   		PhoneValidateCode phoneValidateCode=new PhoneValidateCode();
   		phoneValidateCode.setId(id);
        phoneValidateCode=phoneValidateCodeService.queryPhoneValidateCode(phoneValidateCode);
          request.setAttribute("phoneValidateCode", phoneValidateCode);
   		request.setAttribute("pageIndex", pageIndex);
       	}
        return "phoneValidateCode/phoneValidateCodeBaseInfo";
    }
    /**
    *查询详情
    */
     @RequestMapping(value = "/queryPhoneValidateCodeExtendsInfo", method = RequestMethod.GET)
    public String queryPhoneValidateCodeExtendsInfo(){
   
        return "phoneValidateCode/phoneValidateCodeExtendsInfo";
    }
    /**
    *查询详情
    */
     @RequestMapping(value = "/queryPhoneValidateCodeFunctionsInfo", method = RequestMethod.GET)
    public String queryPhoneValidateCodeFunctionsInfo(){
   
        return "phoneValidateCode/phoneValidateCodeFunctionsInfo";
    }
    /**
    *保存对象
    *@throws IOException
    */
    @RequestMapping(value = "/savePhoneValidateCode", method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> savePhoneValidateCode(PhoneValidateCode phoneValidateCode){
   
       if(phoneValidateCode.getId()!=null&&phoneValidateCode.getId()!=0){
    		phoneValidateCodeService.updatePhoneValidateCode(phoneValidateCode);
    	 }else{  
      	phoneValidateCodeService.savePhoneValidateCode(phoneValidateCode);
    	 }  
		Map<String,Object> result=new HashMap<String,Object>();
    	result.put("resultCode", "1");
    	result.put("resultMessage", "保存成功!");
    	return result;
    }
    /**
    *修改对象
    *@throws IOException
    */
    @RequestMapping(value = "/updatePhoneValidateCode", method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> updatePhoneValidateCode(Integer id){
   
   	PhoneValidateCode phoneValidateCode=new PhoneValidateCode();
   	phoneValidateCode.setId(id);
      phoneValidateCodeService.updatePhoneValidateCode(phoneValidateCode);
   	Map<String,Object> result=new HashMap<String,Object>();
    	result.put("resultCode", "1");
    	result.put("resultMessage", "保存成功!");
    	return result;
    }
    /**
    *删除对象
    *@throws IOException
    */
    @RequestMapping(value = "/deletePhoneValidateCode", method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> deletePhoneValidateCode(Integer id){
   	PhoneValidateCode phoneValidateCode=new PhoneValidateCode();
   	phoneValidateCode.setId(id);
		phoneValidateCodeService.deletePhoneValidateCode(phoneValidateCode);
		Map<String,Object> result=new HashMap<String,Object>();
    	result.put("resultCode", "1");
    	result.put("resultMessage", "保存成功!");
    	return result;
    }

}


