package com.xintong.visualinspection.controller.gettway;

import com.alibaba.dubbo.config.annotation.Reference;
import com.xintong.system.err.BusinessException;
import com.xintong.visualinspection.bean.Constant;
import com.xintong.visualinspection.bean.FwqScore;
import com.xintong.visualinspection.bean.User;
import com.xintong.visualinspection.controller.BaseController;
import com.xintong.visualinspection.service.ScoreService_F;
import com.xintong.visualinspection.util.CodeUtil;
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 javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

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

    @Reference(version = "1.0.0",
            application = "${dubbo.application.id}",
            registry = "${dubbo.registry.address}")
    private ScoreService_F scoreService;



   
    /**
     * 添加扣分项
     * @return
     * String
     * @exception
     * @since  1.0.0
     */
    @RequestMapping(value = "/add")
    public String add(@Valid @RequestBody FwqScore score){
    	scoreService.insert(score);
    	return super.returnSuccessResult("添加成功");
    }
    
    /**
     * 修改扣分项
     * @return
     * String
     * @exception
     * @since  1.0.0
     */
    @RequestMapping(value = "/update")
    public String update(HttpServletRequest request,@Valid @RequestBody FwqScore score){
    	User user = getCurrentUser(request);
    	score.setUpdate_user(new Long(user.getId()));
    	scoreService.update(score);
    	return super.returnSuccessResult("修改成功");
    }
    
    /**
     * 删除扣分项
     * @return
     * String
     * @exception
     * @since  1.0.0
     */
    @RequestMapping(value = "/delete")
    public String delete(@RequestBody FwqScore score){
    	scoreService.delete(score.getId());
    	return super.returnSuccessResult("删除成功");
    }
    
    /**
     * 通过任务id获取考核扣分项
     * @return
     * String
     * @exception
     * @since  1.0.0
     */
    @RequestMapping(value = "/getByTaskId")
    public String getByTaskId(@RequestBody FwqScore score){
    	if(score.getTask_id()==null){
    		throw new BusinessException(20002);
    	}
    	List<FwqScore> 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 FwqScore score){
    	List<FwqScore> scorelist = scoreService.getScoreList(score);
    	return super.returnSuccessPageResult(scorelist);
    }
    
    /**
     * 获取备注排名前10
     * @param checkItem
     * @return
     */
    @RequestMapping(value = "/getTopRemark")
    public String getTopRemark(){
    	Map<String,Object> param = new HashMap<String,Object>();
    	// 获取原因显示条数
    	int showNum = 10;
		Constant t =  CodeUtil.getCodeByFlagAndValue("top_show_num", "1");
		if(t!=null) showNum = Integer.parseInt(t.getCode_name());
    	param.put("num", showNum);
    	List<FwqScore> scoreList =  scoreService.getTopRemarkList(param);
    	return super.returnSuccessResult(scoreList);
    }
    

    
    /**
     * 撤销扣分
     * @return
     * String
     * @exception
     * @since  1.0.0
     */
    @RequestMapping(value = "/backoutScore")
    public String backoutScore(HttpServletRequest request,@Valid @RequestBody FwqScore score){
    	if(score.getId()==null){
    		throw new BusinessException(20002);
    	}
    	User user = getCurrentUser(request);
    	score.setUpdate_user(new Long(user.getId()));
    	scoreService.backoutScore(score);
    	return super.returnSuccessResult("撤销成功");
    }
}
