package cn.pluss.platform.controller.systemConfig;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
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 cn.pluss.platform.entity.SystemConfig;
import cn.pluss.platform.systemConfig.SystemConfigService;
import cn.pluss.platform.util.StringUtil;


@Controller
@RequestMapping("systemconfig")
public class SystemConfigController {

	private Integer PAGE_SIZE=12;
    @Autowired
    private SystemConfigService systemConfigService;
    
    //引导页
    @RequestMapping(value = "/index", method = RequestMethod.GET)
    public String index() {
    	
        return "systemConfig/systemconfigList";
    }
    
    
	//分页查询
    @RequestMapping(value = "/querySystemconfigByPage", method = RequestMethod.POST)
    @ResponseBody
    public  Map<String,Object> querySystemconfigByPage(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<SystemConfig> systemconfigList=systemConfigService.querySystemConfigPage(map);
    	Integer count=systemConfigService.querySystemConfigPageCount(map);
        Map<String,Object> result=new HashMap<String,Object>();
        result.put("systemconfigList", systemconfigList);
        result.put("count", count);
        result.put("pageCount",StringUtil.getPageCount(count,PAGE_SIZE));
        result.put("currPage", currPage);
    
        return result;
    }
    
    
    //查询详情
    @RequestMapping(value = "/querySystemconfigDetails", method = RequestMethod.GET)
    public String querySystemconfigDetails(HttpServletRequest request,Integer id,Integer pageIndex) {
    	if(id!=null&&id!=0) {
    		SystemConfig systemconfig=new SystemConfig();
        	systemconfig.setId(id);
        	systemconfig=systemConfigService.querySystemConfig(systemconfig);
        	request.setAttribute("systemconfig", systemconfig);
        	request.setAttribute("pageIndex", pageIndex);
    		
    	}
    
        return "systemConfig/systemconfigDetails";
    }
    
    
    
    /**
     *查询详情
     */
    @RequestMapping(value = "/querySystemconfigBaseInfo", method = RequestMethod.GET)
     public String querySystemConfigBaseInfo(HttpServletRequest request ,Integer id){
    	if(id!=null&&id!=0) {
		     SystemConfig systemconfig=new SystemConfig();
		     systemconfig.setId(id);
	    	 systemconfig=systemConfigService.querySystemConfig(systemconfig);
	    	 request.setAttribute("systemconfig", systemconfig);
    	}
         return "systemConfig/systemconfigBaseInfo";
     }
     /**
     *查询详情
     */
    @RequestMapping(value = "/querySystemconfigExtendsInfo", method = RequestMethod.GET)
     public String querySystemConfigExtendsInfo(){
    
         return "systemConfig/systemconfigExtendsInfo";
     }
     /**
     *查询详情
     */
    @RequestMapping(value = "/querySystemconfigFunctionsInfo", method = RequestMethod.GET)
     public String querySystemConfigFunctionsInfo(){
    
         return "systemConfig/systemconfigFunctionsInfo";
     }
     /**
     *保存对象
     */
    @RequestMapping(value = "/saveSystemconfig", method = RequestMethod.POST)
    @ResponseBody
     public Map<String,Object> saveSystemConfig(SystemConfig systemconfig){
        if(systemconfig.getId()!=null&&systemconfig.getId()!=0){
     		systemConfigService.updateSystemConfig(systemconfig);
     	 }else{  
     		 systemConfigService.saveSystemConfig(systemconfig);
     	 }  
 		Map<String,Object> result=new HashMap<String,Object>();
     	result.put("resultCode", "1");
     	result.put("resultMessage", "保存成功!");
     	return result;
     }
     /**
     *修改对象
     */
    @RequestMapping(value = "/updateSystemconfig", method = RequestMethod.POST)
    @ResponseBody
     public  Map<String,Object> updateSystemConfig(Integer id){
	     SystemConfig systemconfig=new SystemConfig();
	     systemconfig.setId(id);
       	systemConfigService.updateSystemConfig(systemconfig);
       	Map<String,Object> result=new HashMap<String,Object>();
     	result.put("resultCode", "1");
     	result.put("resultMessage", "保存成功!");
     	return result;
     }
     /**
     *删除对象
     */
    @RequestMapping(value = "/deleteSystemconfig", method = RequestMethod.POST)
    @ResponseBody
     public Map<String,Object> deleteSystemConfig(Integer id){
        SystemConfig systemconfig=new SystemConfig();
	    systemconfig.setId(id);
 		systemConfigService.deleteSystemConfig(systemconfig);
 		Map<String,Object> result=new HashMap<String,Object>();
     	result.put("resultCode", "1");
     	result.put("resultMessage", "保存成功!");
     	return result;
     }
    
}
