package cn.pluss.platform.controller.merchantIncome;

import cn.pluss.platform.controller.BaseNoModelController;
import cn.pluss.platform.entity.MerchantIncome;
import cn.pluss.platform.merchantIncome.MerchantIncomeService;
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("merchantIncome")
public class MerchantIncomeController  extends BaseNoModelController {

	  private Integer PAGE_SIZE=12;

    @Autowired
	  private MerchantIncomeService merchantIncomeService;

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

    /**
    *分页查询
    */
    @RequestMapping(value = "/queryMerchantIncomeByPage", method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> queryMerchantIncomeByPage(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<MerchantIncome> merchantIncomeList=merchantIncomeService.queryMerchantIncomePage(map);
    	Integer count=merchantIncomeService.queryMerchantIncomePageCount(map);
        Map<String,Object> result=new HashMap<String,Object>();
        result.put("merchantIncomeList", merchantIncomeList);
        result.put("count", count);
        result.put("pageCount",StringUtil.getPageCount(count,PAGE_SIZE));
        result.put("currPage", currPage);
    	  return result;
    }
    /**
    *查询详情
    */
     @RequestMapping(value = "/queryMerchantIncomeDetails", method = RequestMethod.GET)
    public String queryMerchantIncomeDetails(HttpServletRequest request,Integer id,Integer pageIndex){
   
   	  if(id!=null&&id!=0) {
   		 MerchantIncome merchantIncome=new MerchantIncome();
   		 merchantIncome.setId(id);
           merchantIncome=merchantIncomeService.queryMerchantIncome(merchantIncome);
          request.setAttribute("merchantIncome", merchantIncome);
   		request.setAttribute("pageIndex", pageIndex);
       	}
        return "merchantIncome/merchantIncomeDetails";
    }
    /**
    *查询详情
    */
     @RequestMapping(value = "/queryMerchantIncomeBaseInfo", method = RequestMethod.GET)
    public String queryMerchantIncomeBaseInfo(HttpServletRequest request,Integer id,Integer pageIndex){
   
   	  if(id!=null&&id!=0) {
   		MerchantIncome merchantIncome=new MerchantIncome();
   		merchantIncome.setId(id);
        merchantIncome=merchantIncomeService.queryMerchantIncome(merchantIncome);
          request.setAttribute("merchantIncome", merchantIncome);
   		request.setAttribute("pageIndex", pageIndex);
       	}
        return "merchantIncome/merchantIncomeBaseInfo";
    }
    /**
    *查询详情
    */
     @RequestMapping(value = "/queryMerchantIncomeExtendsInfo", method = RequestMethod.GET)
    public String queryMerchantIncomeExtendsInfo(){
   
        return "merchantIncome/merchantIncomeExtendsInfo";
    }
    /**
    *查询详情
    */
     @RequestMapping(value = "/queryMerchantIncomeFunctionsInfo", method = RequestMethod.GET)
    public String queryMerchantIncomeFunctionsInfo(){
   
        return "merchantIncome/merchantIncomeFunctionsInfo";
    }
    /**
    *保存对象
    *@throws IOException
    */
    @RequestMapping(value = "/saveMerchantIncome", method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> saveMerchantIncome(MerchantIncome merchantIncome){
   
       if(merchantIncome.getId()!=null&&merchantIncome.getId()!=0){
    		merchantIncomeService.updateMerchantIncome(merchantIncome);
    	 }else{  
      	merchantIncomeService.saveMerchantIncome(merchantIncome);
    	 }  
		Map<String,Object> result=new HashMap<String,Object>();
    	result.put("resultCode", "1");
    	result.put("resultMessage", "保存成功!");
    	return result;
    }
    /**
    *修改对象
    *@throws IOException
    */
    @RequestMapping(value = "/updateMerchantIncome", method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> updateMerchantIncome(Integer id){
   
   	MerchantIncome merchantIncome=new MerchantIncome();
   	merchantIncome.setId(id);
      merchantIncomeService.updateMerchantIncome(merchantIncome);
   	Map<String,Object> result=new HashMap<String,Object>();
    	result.put("resultCode", "1");
    	result.put("resultMessage", "保存成功!");
    	return result;
    }
    /**
    *删除对象
    *@throws IOException
    */
    @RequestMapping(value = "/deleteMerchantIncome", method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> deleteMerchantIncome(Integer id){
   	MerchantIncome merchantIncome=new MerchantIncome();
   	merchantIncome.setId(id);
		merchantIncomeService.deleteMerchantIncome(merchantIncome);
		Map<String,Object> result=new HashMap<String,Object>();
    	result.put("resultCode", "1");
    	result.put("resultMessage", "保存成功!");
    	return result;
    }

}


