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.ReviewQuestionnaireProblemOption;
import cn.com.countrygarden.bi.main.dao.review.ReviewQuestionnaireProblemOptionMapper;
import cn.com.countrygarden.bi.main.service.review.ReviewQuestionnaireProblemOptionService;
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 ReviewQuestionnaireProblemOptionServiceImpl implements ReviewQuestionnaireProblemOptionService{
    @Autowired
    private ReviewQuestionnaireProblemOptionMapper reviewQuestionnaireProblemOptionMapper;

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

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

    @Override
    public Result add(ReviewQuestionnaireProblemOption reviewQuestionnaireProblemOption, AccessToken accessToken) {
    	reviewQuestionnaireProblemOption.setCreateBy(accessToken.getUserCode());
        reviewQuestionnaireProblemOptionMapper.insert(reviewQuestionnaireProblemOption);
        return Response.response();
    }

    @Override
    public Result edit(ReviewQuestionnaireProblemOption reviewQuestionnaireProblemOption, AccessToken accessToken) {
        reviewQuestionnaireProblemOptionMapper.updateByPrimaryKey(reviewQuestionnaireProblemOption);
        return Response.response();
    }

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

}