package cn.com.countrygarden.bi.main.service.review.impl;
import cn.com.countrygarden.bi.main.model.PageData;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import cn.com.countrygarden.bi.main.core.Result;
import cn.com.countrygarden.bi.main.model.AccessToken;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.com.countrygarden.bi.main.model.review.ReviewGrade;
import cn.com.countrygarden.bi.main.dao.review.ReviewGradeMapper;
import cn.com.countrygarden.bi.main.service.review.ReviewGradeService;
import tk.mybatis.mapper.entity.Condition;
import tk.mybatis.mapper.entity.Example.Criteria;
import cn.com.countrygarden.bi.main.core.Response;

/**
 * 评选人级别-业务逻辑层实现
 *
 * @author 汤婷
 * @email www.justintoforest@gamail.com
 * @url 
 * @date 2018-06-25
 */
@Service
@Transactional
public class ReviewGradeServiceImpl implements ReviewGradeService{
    @Autowired
    private ReviewGradeMapper reviewGradeMapper;

    @Override
    public Result queryPageList(ReviewGrade reviewGrade, int page, int size) {
        Page<Object> pageList = PageHelper.startPage(page, size);
        Condition condition=new Condition(ReviewGrade.class);
        Criteria criteria = condition.createCriteria();
//		TODO 添加条件
		reviewGradeMapper.selectByCondition(condition);
        PageData data=new PageData(pageList);
        data.setData(pageList.getResult());
        return Response.response(data);
    }

    @Override
    public Result queryById(Integer id) {
        return Response.response(reviewGradeMapper.selectByPrimaryKey(id));
    }

    @Override
    public Result add(ReviewGrade reviewGrade, AccessToken accessToken) {
    	reviewGrade.setCreateBy(accessToken.getUserCode());
        reviewGradeMapper.insert(reviewGrade);
        
        return Response.response();
    }

    @Override
    public Result edit(ReviewGrade reviewGrade, AccessToken accessToken) {
        reviewGradeMapper.updateByPrimaryKey(reviewGrade);
        return Response.response();
    }

    @Override
    public Result del(Integer id) {
        int count = reviewGradeMapper.deleteByPrimaryKey(id);
        return Response.response(count);
    }
    
    @Override
	public Result printscore(Integer investigatedid) {
		
		return Response.response(reviewGradeMapper.printscore(investigatedid));
	}

}