package com.xintong.visualinspection.controller;

import java.util.List;

import javax.validation.Valid;

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.RestController;

import com.xintong.system.err.BusinessException;
import com.xintong.visualinspection.bean.Score;
import com.xintong.visualinspection.service.ScoreService;

/**
 * 文件名：TestController
 * 版本信息：日期：2017/3/30 Copyright 江苏省交通规划设计院 Corporation 2017 版权所有.
 */
@RestController
@RequestMapping("/score")
public class ScoreController extends BaseController {

    @Autowired
    private ScoreService scoreService;

   
    /**
     * 添加扣分项
     * @return
     * String
     * @exception
     * @since  1.0.0
     */
    @RequestMapping(value = "/add")
    public String add(@Valid @RequestBody Score score){
    	scoreService.insert(score);
    	return super.returnSuccessResult("添加成功");
    }
    
    /**
     * 修改扣分项
     * @return
     * String
     * @exception
     * @since  1.0.0
     */
    @RequestMapping(value = "/update")
    public String update(@Valid @RequestBody Score score){
    	scoreService.update(score);
    	return super.returnSuccessResult("修改成功");
    }
    
    /**
     * 删除扣分项
     * @return
     * String
     * @exception
     * @since  1.0.0
     */
    @RequestMapping(value = "/delete")
    public String delete(@RequestBody Score score){
    	scoreService.delete(score.getId());
    	return super.returnSuccessResult("删除成功");
    }
    
    /**
     * 通过任务id获取考核扣分项
     * @return
     * String
     * @exception
     * @since  1.0.0
     */
    @RequestMapping(value = "/getByTaskId")
    public String getByTaskId(@RequestBody Score score){
    	if(score.getTask_id()==null){
    		throw new BusinessException(20002);
    	}
    	List<Score> scorelist = scoreService.getScoreListByTaskId(score.getTask_id());
    	return super.returnSuccessResult(scorelist);
    }
    
    /**
     * 通过多条件获取考核扣分项
     * @return
     * String
     * @exception
     * @since  1.0.0
     */
    @RequestMapping(value = "/getScoreList/{page}/{size}")
    public String getScoreList(@PathVariable Integer page,@PathVariable Integer size, @RequestBody Score score){
    	List<Score> scorelist = scoreService.getScoreList(score);
    	return super.returnSuccessPageResult(scorelist);
    }
}
