package com.ifish.action;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
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 com.ifish.enums.ResultEnum;
import com.ifish.exception.IfishException;
import com.ifish.service.GradeService;
import com.ifish.validator.AddValueParam;
import com.ifish.validator.PageParam;

/**
 * 等级
 * @author Administrator
 *
 */
@Controller
@RequestMapping("/grade")
@ResponseBody
public class GradeAction {
	
	@Autowired
	private GradeService gradeService;
	
	/**
	 * 新增经验值
	 * @param addValueParam
	 * @param result
	 * @return
	 */
	@RequestMapping(value="/gradeValue.do",method=RequestMethod.POST)
	public Object addGradeValue(@Validated AddValueParam addValueParam,BindingResult result) {
		//参数校验
		if(result.hasErrors()){
			throw new IfishException(ResultEnum.error401);
		}
		return this.gradeService.addGradeValue(addValueParam);
	}
	
	/**
	 * 获取规则等级信息
	 * @param version
	 * @return
	 */
	@RequestMapping(value="/gradeRuleInfo.do",method=RequestMethod.GET)
	public Object gradeRuleInfo(@RequestParam Integer userId){
		return this.gradeService.getGradeRuleInfo(userId);
	}
	
	/**
	 * 分页经验值获取记录
	 * @param pageParam
	 * @param result
	 * @return
	 */
	@RequestMapping(value="/gradeRecord.do",method=RequestMethod.GET)
	public Object getGradeRecordByPage(@Validated PageParam pageParam,BindingResult result){
		//参数校验
		if(result.hasErrors()){
			throw new IfishException(ResultEnum.error401);
		}
		return this.gradeService.getGradeRecordByPage(pageParam);
	}
	
}