package cn.com.countrygarden.bi.main.controller.project;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
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 org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageRowBounds;

import cn.com.countrygarden.bi.main.core.Response;
import cn.com.countrygarden.bi.main.model.AccessToken;
import cn.com.countrygarden.bi.main.model.PageData;
import cn.com.countrygarden.bi.main.model.project.ProjectJointPlan;
import cn.com.countrygarden.bi.main.service.AccessTokenService;
import cn.com.countrygarden.bi.main.service.project.ProjectJointPlanService;
/**
 * 
 * 
 * <pre>
 * 。
 * </pre>
 * 
 * @author developer developer@meicloud.com
 * @version 1.00.00
 * 
 *          <pre>
 * 修改记录
 *    修改后版本:     修改人：  修改日期:     修改内容:
 * </pre>
 */
@RestController("ProjectJointPlanController")
@RequestMapping("/api/project/projectJointPlan")
public class ProjectJointPlanController {
	  @Autowired
	    private ProjectJointPlanService projectJointPlan;
	  @Autowired
	    private AccessTokenService accessTokenService;
	  
	  @RequestMapping(value = "/list/{menuId}", method = {RequestMethod.GET}, produces = {"application/json;charset=utf-8"})
	 // @RequestMapping(value = "/list", method = {RequestMethod.GET}, produces = {"application/json;charset=utf-8"})
	  public Object search(  
			  @PathVariable Integer menuId,
			  @RequestParam(value = "skip", required = false, defaultValue = "") Integer page,
              @RequestParam(value = "limit", required = false, defaultValue = "") Integer size){
		  PageData p = projectJointPlan.search(menuId,page,size);
		 
		  return Response.response(p);
	  }
	  @ResponseBody
	  @RequestMapping(value = "/add", method = {RequestMethod.POST} ,produces = "application/json; charset=utf-8")
	  public Object create(
			 // @RequestBody ProjectJointPlan  p,
			  @RequestParam(value = "id", required = false) Integer id,
			  @RequestParam(value = "name", required = false, defaultValue = "") String name,
			  @RequestParam(value = "level", required = false) Integer level,
			  @RequestParam(value = "sort", required = false) Integer sort,
			  @RequestParam(value = "menuId", required = false) Integer menuId,
			  @RequestParam(value = "isSuspicious", required = false) Integer isSuspicious,
			  HttpServletRequest request, HttpServletResponse response) {
		  ProjectJointPlan p = new ProjectJointPlan();
		  p.setId(id);
		  p.setName(name);
		  p.setLevel(level);
		  p.setSort(sort);
		  p.setMenuId(menuId);
		  p.setIsDelete(0);
		  p.setIsSuspicious(isSuspicious);
		  String accessToken = request.getParameter("AccessToken");
		  AccessToken token = accessTokenService.findByToken(accessToken);
		  return Response.response(projectJointPlan.save(p, token.getUserCode()));
	  }
	  @RequestMapping(value = "/delete/{id}", method = {RequestMethod.GET}, produces = {"application/json;charset=utf-8"})
	  public Object create(@PathVariable Integer id) {
		  projectJointPlan.delete(id);
		  return  Response.response(new Boolean(true));
	  }
	  @RequestMapping(value = "/findOne/{id}", method = {RequestMethod.GET}, produces = {"application/json;charset=utf-8"})
	  public Object findOne(@PathVariable Integer id) {
		  return Response.response(projectJointPlan.findOne(id));
		//  return projectJointPlan.findOne(id);
	  }
}
