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.alibaba.fastjson.JSONObject;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import java.util.List;

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.ReviewQuestionnaireProblemClassification;
import cn.com.countrygarden.bi.main.dao.review.ReviewQuestionnaireProblemClassificationMapper;
import cn.com.countrygarden.bi.main.dto.ReviewQuestioClassificationDTO;
import cn.com.countrygarden.bi.main.service.review.ReviewQuestionnaireProblemClassificationService;
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 ReviewQuestionnaireProblemClassificationServiceImpl implements ReviewQuestionnaireProblemClassificationService{
    @Autowired
    private ReviewQuestionnaireProblemClassificationMapper reviewQuestionnaireProblemClassificationMapper;

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

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

    @Override
    public Result add(ReviewQuestionnaireProblemClassification reviewQuestionnaireProblemClassification, AccessToken accessToken) {
    	reviewQuestionnaireProblemClassification.setCreateBy(accessToken.getUserCode());
        reviewQuestionnaireProblemClassificationMapper.insert(reviewQuestionnaireProblemClassification);
        return Response.response();
    }

    @Override
    public Result edit(ReviewQuestionnaireProblemClassification reviewQuestionnaireProblemClassification, AccessToken accessToken) {
        reviewQuestionnaireProblemClassificationMapper.updateByPrimaryKey(reviewQuestionnaireProblemClassification);
        return Response.response();
    }

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

	@Override
	public Result pqpclist(Integer questionnaireId) {
		
		
		List<ReviewQuestioClassificationDTO> pqpclist=reviewQuestionnaireProblemClassificationMapper.pqpclist(questionnaireId);
		 PageData data = new PageData();
		 
		 
		 data.setData(pqpclist);
			
		 JSONObject object=new JSONObject();
		 object.put("data",data);
		 
		 return Response.response(object);
		
	}

}