package cn.pluss.platform.controller.deviceMerchantBuyDetail;

import cn.pluss.platform.controller.BaseNoModelController;
import cn.pluss.platform.deviceMerchantBuyDetail.DeviceMerchantBuyDetailService;
import cn.pluss.platform.entity.DeviceMerchantBuyDetail;
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("deviceMerchantBuyDetail")
public class DeviceMerchantBuyDetailController  extends BaseNoModelController {

	  private Integer PAGE_SIZE=12;

    @Autowired
	  private DeviceMerchantBuyDetailService deviceMerchantBuyDetailService;

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

    /**
    *分页查询
    */
    @RequestMapping(value = "/queryDeviceMerchantBuyDetailByPage", method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> queryDeviceMerchantBuyDetailByPage(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<DeviceMerchantBuyDetail> deviceMerchantBuyDetailList=deviceMerchantBuyDetailService.queryDeviceMerchantBuyDetailPage(map);
    	Integer count=deviceMerchantBuyDetailService.queryDeviceMerchantBuyDetailPageCount(map);
        Map<String,Object> result=new HashMap<String,Object>();
        result.put("deviceMerchantBuyDetailList", deviceMerchantBuyDetailList);
        result.put("count", count);
        result.put("pageCount",StringUtil.getPageCount(count,PAGE_SIZE));
        result.put("currPage", currPage);
    	  return result;
    }
    /**
    *查询详情
    */
     @RequestMapping(value = "/queryDeviceMerchantBuyDetailDetails", method = RequestMethod.GET)
    public String queryDeviceMerchantBuyDetailDetails(HttpServletRequest request,Integer id,Integer pageIndex){
   
   	  if(id!=null&&id!=0) {
   		 DeviceMerchantBuyDetail deviceMerchantBuyDetail=new DeviceMerchantBuyDetail();
   		 deviceMerchantBuyDetail.setId(id);
           deviceMerchantBuyDetail=deviceMerchantBuyDetailService.queryDeviceMerchantBuyDetail(deviceMerchantBuyDetail);
          request.setAttribute("deviceMerchantBuyDetail", deviceMerchantBuyDetail);
   		request.setAttribute("pageIndex", pageIndex);
       	}
        return "deviceMerchantBuyDetail/deviceMerchantBuyDetailDetails";
    }
    /**
    *查询详情
    */
     @RequestMapping(value = "/queryDeviceMerchantBuyDetailBaseInfo", method = RequestMethod.GET)
    public String queryDeviceMerchantBuyDetailBaseInfo(HttpServletRequest request,Integer id,Integer pageIndex){
   
   	  if(id!=null&&id!=0) {
   		DeviceMerchantBuyDetail deviceMerchantBuyDetail=new DeviceMerchantBuyDetail();
   		deviceMerchantBuyDetail.setId(id);
        deviceMerchantBuyDetail=deviceMerchantBuyDetailService.queryDeviceMerchantBuyDetail(deviceMerchantBuyDetail);
          request.setAttribute("deviceMerchantBuyDetail", deviceMerchantBuyDetail);
   		request.setAttribute("pageIndex", pageIndex);
       	}
        return "deviceMerchantBuyDetail/deviceMerchantBuyDetailBaseInfo";
    }
    /**
    *查询详情
    */
     @RequestMapping(value = "/queryDeviceMerchantBuyDetailExtendsInfo", method = RequestMethod.GET)
    public String queryDeviceMerchantBuyDetailExtendsInfo(){
   
        return "deviceMerchantBuyDetail/deviceMerchantBuyDetailExtendsInfo";
    }
    /**
    *查询详情
    */
     @RequestMapping(value = "/queryDeviceMerchantBuyDetailFunctionsInfo", method = RequestMethod.GET)
    public String queryDeviceMerchantBuyDetailFunctionsInfo(){
   
        return "deviceMerchantBuyDetail/deviceMerchantBuyDetailFunctionsInfo";
    }
    /**
    *保存对象
    *@throws IOException
    */
    @RequestMapping(value = "/saveDeviceMerchantBuyDetail", method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> saveDeviceMerchantBuyDetail(DeviceMerchantBuyDetail deviceMerchantBuyDetail){
   
       if(deviceMerchantBuyDetail.getId()!=null&&deviceMerchantBuyDetail.getId()!=0){
    		deviceMerchantBuyDetailService.updateDeviceMerchantBuyDetail(deviceMerchantBuyDetail);
    	 }else{  
      	deviceMerchantBuyDetailService.saveDeviceMerchantBuyDetail(deviceMerchantBuyDetail);
    	 }  
		Map<String,Object> result=new HashMap<String,Object>();
    	result.put("resultCode", "1");
    	result.put("resultMessage", "保存成功!");
    	return result;
    }
    /**
    *修改对象
    *@throws IOException
    */
    @RequestMapping(value = "/updateDeviceMerchantBuyDetail", method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> updateDeviceMerchantBuyDetail(Integer id){
   
   	DeviceMerchantBuyDetail deviceMerchantBuyDetail=new DeviceMerchantBuyDetail();
   	deviceMerchantBuyDetail.setId(id);
      deviceMerchantBuyDetailService.updateDeviceMerchantBuyDetail(deviceMerchantBuyDetail);
   	Map<String,Object> result=new HashMap<String,Object>();
    	result.put("resultCode", "1");
    	result.put("resultMessage", "保存成功!");
    	return result;
    }
    /**
    *删除对象
    *@throws IOException
    */
    @RequestMapping(value = "/deleteDeviceMerchantBuyDetail", method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> deleteDeviceMerchantBuyDetail(Integer id){
   	DeviceMerchantBuyDetail deviceMerchantBuyDetail=new DeviceMerchantBuyDetail();
   	deviceMerchantBuyDetail.setId(id);
		deviceMerchantBuyDetailService.deleteDeviceMerchantBuyDetail(deviceMerchantBuyDetail);
		Map<String,Object> result=new HashMap<String,Object>();
    	result.put("resultCode", "1");
    	result.put("resultMessage", "保存成功!");
    	return result;
    }

}


