package cn.com.countrygarden.bi.main.service.review.impl;
import cn.com.countrygarden.bi.main.model.PageData;
import cn.com.countrygarden.bi.main.service.project.ProjectJointPlanService;
import cn.com.countrygarden.bi.main.model.test.Test;
import cn.com.countrygarden.bi.main.service.test.TestService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.apache.commons.lang.StringUtils;
import cn.com.countrygarden.bi.main.core.Result;
import cn.com.countrygarden.bi.main.model.AccessToken;
import cn.com.countrygarden.bi.main.model.sys.Function;
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.ReviewEvaluate;
import cn.com.countrygarden.bi.main.dao.review.ReviewEvaluateMapper;
import cn.com.countrygarden.bi.main.service.review.ReviewEvaluateService;
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-07-06
 */
@Service
@Transactional
public class ReviewEvaluateServiceImpl implements ReviewEvaluateService{
    @Autowired
    private ReviewEvaluateMapper reviewEvaluateMapper;

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

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

    @Override
    public Result add(ReviewEvaluate reviewEvaluate, AccessToken accessToken) {
    	reviewEvaluate.setFlag(1);
    	reviewEvaluate.setCreateBy(accessToken.getUserCode()); 
    	reviewEvaluate.setAdmin(accessToken.getUserCode());
        reviewEvaluateMapper.insert(reviewEvaluate);
        return Response.response();
    }

    @Override
    public Result edit(ReviewEvaluate reviewEvaluate, AccessToken accessToken) {
        reviewEvaluateMapper.updateByPrimaryKey(reviewEvaluate);
        return Response.response();
    }

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

}