package cn.pluss.platform.controller.fansConsumReturn;

import cn.pluss.platform.controller.BaseNoModelController;
import cn.pluss.platform.entitiy.ShiroUser;
import cn.pluss.platform.entity.FansConsumReturn;
import cn.pluss.platform.fansConsumReturn.FansConsumReturnService;
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.RequestParam;
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("fansConsumReturn")
public class FansConsumReturnController  extends BaseNoModelController {

	  private Integer PAGE_SIZE=12;

    @Autowired
	  private FansConsumReturnService fansConsumReturnService;

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

    /**
    *分页查询
    */
    @RequestMapping(value = "/queryFansConsumReturnByPage", method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> queryFansConsumReturnByPage(@RequestParam(defaultValue="1") Integer currPage,FansConsumReturn fansConsumReturn){
   
    	Map<String,Object> map=new HashMap<String, Object>();
    	map.put("pageSize",PAGE_SIZE);
    	map.put("offset", (currPage-1)*PAGE_SIZE);
    	if(StringUtil.isNotEmpty(fansConsumReturn.getNickName())) {
    		map.put("nickName", fansConsumReturn.getNickName());
    	}
    	Boolean bol = verifyUserRole();
    	if(!bol)  {
    		ShiroUser shiroUser = queryCurrentShiroUser();
    		if(StringUtil.isNotEmpty(shiroUser.getMerchantCode())) {
    			map.put("merchantCode", shiroUser.getMerchantCode());
    		}else {
    			map.put("merchantCode", StringUtil.genRandomNum(33));
    		}
    	}
    	List<FansConsumReturn> fansConsumReturnList=fansConsumReturnService.queryFansConsumReturnPage(map);
    	Integer count=fansConsumReturnService.queryFansConsumReturnPageCount(map);
        Map<String,Object> result=new HashMap<String,Object>();
        result.put("fansConsumReturnList", fansConsumReturnList);
        result.put("count", count);
        result.put("pageCount",StringUtil.getPageCount(count,PAGE_SIZE));
        result.put("currPage", currPage);
    	  return result;
    }
    /**
    *查询详情
    */
     @RequestMapping(value = "/queryFansConsumReturnDetails", method = RequestMethod.GET)
    public String queryFansConsumReturnDetails(HttpServletRequest request,Integer id,Integer pageIndex){
   
   	  if(id!=null&&id!=0) {
   		 FansConsumReturn fansConsumReturn=new FansConsumReturn();
   		 fansConsumReturn.setId(id);
           fansConsumReturn=fansConsumReturnService.queryFansConsumReturn(fansConsumReturn);
          request.setAttribute("fansConsumReturn", fansConsumReturn);
   		request.setAttribute("pageIndex", pageIndex);
       	}
        return "fansConsumReturn/fansConsumReturnDetails";
    }
    /**
    *查询详情
    */
     @RequestMapping(value = "/queryFansConsumReturnBaseInfo", method = RequestMethod.GET)
    public String queryFansConsumReturnBaseInfo(HttpServletRequest request,Integer id,Integer pageIndex){
   
   	  if(id!=null&&id!=0) {
   		FansConsumReturn fansConsumReturn=new FansConsumReturn();
   		fansConsumReturn.setId(id);
        fansConsumReturn=fansConsumReturnService.queryFansConsumReturn(fansConsumReturn);
          request.setAttribute("fansConsumReturn", fansConsumReturn);
   		request.setAttribute("pageIndex", pageIndex);
       	}
        return "fansConsumReturn/fansConsumReturnBaseInfo";
    }
    /**
    *查询详情
    */
     @RequestMapping(value = "/queryFansConsumReturnExtendsInfo", method = RequestMethod.GET)
    public String queryFansConsumReturnExtendsInfo(){
   
        return "fansConsumReturn/fansConsumReturnExtendsInfo";
    }
    /**
    *查询详情
    */
     @RequestMapping(value = "/queryFansConsumReturnFunctionsInfo", method = RequestMethod.GET)
    public String queryFansConsumReturnFunctionsInfo(){
   
        return "fansConsumReturn/fansConsumReturnFunctionsInfo";
    }
    /**
    *保存对象
    *@throws IOException
    */
    @RequestMapping(value = "/saveFansConsumReturn", method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> saveFansConsumReturn(FansConsumReturn fansConsumReturn){
   
       if(fansConsumReturn.getId()!=null&&fansConsumReturn.getId()!=0){
    		fansConsumReturnService.updateFansConsumReturn(fansConsumReturn);
    	 }else{  
      	fansConsumReturnService.saveFansConsumReturn(fansConsumReturn);
    	 }  
		Map<String,Object> result=new HashMap<String,Object>();
    	result.put("resultCode", "1");
    	result.put("resultMessage", "保存成功!");
    	return result;
    }
    /**
    *修改对象
    *@throws IOException
    */
    @RequestMapping(value = "/updateFansConsumReturn", method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> updateFansConsumReturn(Integer id){
   
   	FansConsumReturn fansConsumReturn=new FansConsumReturn();
   	fansConsumReturn.setId(id);
      fansConsumReturnService.updateFansConsumReturn(fansConsumReturn);
   	Map<String,Object> result=new HashMap<String,Object>();
    	result.put("resultCode", "1");
    	result.put("resultMessage", "保存成功!");
    	return result;
    }
    /**
    *删除对象
    *@throws IOException
    */
    @RequestMapping(value = "/deleteFansConsumReturn", method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> deleteFansConsumReturn(Integer id){
   	FansConsumReturn fansConsumReturn=new FansConsumReturn();
   	fansConsumReturn.setId(id);
		fansConsumReturnService.deleteFansConsumReturn(fansConsumReturn);
		Map<String,Object> result=new HashMap<String,Object>();
    	result.put("resultCode", "1");
    	result.put("resultMessage", "保存成功!");
    	return result;
    }

}


