package cn.pluss.platform.controller.merchantAddress;

import cn.pluss.platform.controller.BaseNoModelController;
import cn.pluss.platform.entity.MerchantAddress;
import cn.pluss.platform.merchantAddress.MerchantAddressService;
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("merchantAddress")
public class MerchantAddressController  extends BaseNoModelController {

	  private Integer PAGE_SIZE=12;

    @Autowired
	  private MerchantAddressService merchantAddressService;

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

    /**
    *分页查询
    */
    @RequestMapping(value = "/queryMerchantAddressByPage", method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> queryMerchantAddressByPage(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<MerchantAddress> merchantAddressList=merchantAddressService.queryMerchantAddressPage(map);
    	Integer count=merchantAddressService.queryMerchantAddressPageCount(map);
        Map<String,Object> result=new HashMap<String,Object>();
        result.put("merchantAddressList", merchantAddressList);
        result.put("count", count);
        result.put("pageCount",StringUtil.getPageCount(count,PAGE_SIZE));
        result.put("currPage", currPage);
    	  return result;
    }
    /**
    *查询详情
    */
     @RequestMapping(value = "/queryMerchantAddressDetails", method = RequestMethod.GET)
    public String queryMerchantAddressDetails(HttpServletRequest request,Integer id,Integer pageIndex){
   
   	  if(id!=null&&id!=0) {
   		 MerchantAddress merchantAddress=new MerchantAddress();
   		 merchantAddress.setId(id);
           merchantAddress=merchantAddressService.queryMerchantAddress(merchantAddress);
          request.setAttribute("merchantAddress", merchantAddress);
   		request.setAttribute("pageIndex", pageIndex);
       	}
        return "merchantAddress/merchantAddressDetails";
    }
    /**
    *查询详情
    */
     @RequestMapping(value = "/queryMerchantAddressBaseInfo", method = RequestMethod.GET)
    public String queryMerchantAddressBaseInfo(HttpServletRequest request,Integer id,Integer pageIndex){
   
   	  if(id!=null&&id!=0) {
   		MerchantAddress merchantAddress=new MerchantAddress();
   		merchantAddress.setId(id);
        merchantAddress=merchantAddressService.queryMerchantAddress(merchantAddress);
          request.setAttribute("merchantAddress", merchantAddress);
   		request.setAttribute("pageIndex", pageIndex);
       	}
        return "merchantAddress/merchantAddressBaseInfo";
    }
    /**
    *查询详情
    */
     @RequestMapping(value = "/queryMerchantAddressExtendsInfo", method = RequestMethod.GET)
    public String queryMerchantAddressExtendsInfo(){
   
        return "merchantAddress/merchantAddressExtendsInfo";
    }
    /**
    *查询详情
    */
     @RequestMapping(value = "/queryMerchantAddressFunctionsInfo", method = RequestMethod.GET)
    public String queryMerchantAddressFunctionsInfo(){
   
        return "merchantAddress/merchantAddressFunctionsInfo";
    }
    /**
    *保存对象
    *@throws IOException
    */
    @RequestMapping(value = "/saveMerchantAddress", method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> saveMerchantAddress(MerchantAddress merchantAddress){
   
       if(merchantAddress.getId()!=null&&merchantAddress.getId()!=0){
    		merchantAddressService.updateMerchantAddress(merchantAddress);
    	 }else{  
      	merchantAddressService.saveMerchantAddress(merchantAddress);
    	 }  
		Map<String,Object> result=new HashMap<String,Object>();
    	result.put("resultCode", "1");
    	result.put("resultMessage", "保存成功!");
    	return result;
    }
    /**
    *修改对象
    *@throws IOException
    */
    @RequestMapping(value = "/updateMerchantAddress", method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> updateMerchantAddress(Integer id){
   
   	MerchantAddress merchantAddress=new MerchantAddress();
   	merchantAddress.setId(id);
      merchantAddressService.updateMerchantAddress(merchantAddress);
   	Map<String,Object> result=new HashMap<String,Object>();
    	result.put("resultCode", "1");
    	result.put("resultMessage", "保存成功!");
    	return result;
    }
    /**
    *删除对象
    *@throws IOException
    */
    @RequestMapping(value = "/deleteMerchantAddress", method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> deleteMerchantAddress(Integer id){
   	MerchantAddress merchantAddress=new MerchantAddress();
   	merchantAddress.setId(id);
		merchantAddressService.deleteMerchantAddress(merchantAddress);
		Map<String,Object> result=new HashMap<String,Object>();
    	result.put("resultCode", "1");
    	result.put("resultMessage", "保存成功!");
    	return result;
    }

}


