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.ReviewQuestionnaireProblemType;
import cn.com.countrygarden.bi.main.dao.review.ReviewQuestionnaireProblemTypeMapper;
import cn.com.countrygarden.bi.main.service.review.ReviewQuestionnaireProblemTypeService;
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 ReviewQuestionnaireProblemTypeServiceImpl implements ReviewQuestionnaireProblemTypeService{
    @Autowired
    private ReviewQuestionnaireProblemTypeMapper reviewQuestionnaireProblemTypeMapper;

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

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

    @Override
    public Result add(ReviewQuestionnaireProblemType reviewQuestionnaireProblemType, AccessToken accessToken) {
    	reviewQuestionnaireProblemType.setCreateBy(accessToken.getUserCode());
        reviewQuestionnaireProblemTypeMapper.insert(reviewQuestionnaireProblemType);
        return Response.response();
    }

    @Override
    public Result edit(ReviewQuestionnaireProblemType reviewQuestionnaireProblemType, AccessToken accessToken) {
        reviewQuestionnaireProblemTypeMapper.updateByPrimaryKey(reviewQuestionnaireProblemType);
        return Response.response();
    }

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

}