package com.zjty.autotest.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

import com.zjty.autotest.dao.TestReportDao;
import com.zjty.autotest.pojo.sjq.TestReport;
import com.zjty.autotest.pojo.sjq.common.AppHttpCodeEnum;
import com.zjty.autotest.pojo.sjq.common.ResponseResult;
import com.zjty.autotest.service.TestReportService;
import com.zjty.autotest.util.IdWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * 服务层
 * 
 * @author Administrator
 *
 */
@Service
public class TestReportServiceImpl implements TestReportService {

	@Autowired
	private TestReportDao testReportDao;
	
	@Autowired
	private IdWorker idWorker;

	/**
	 * 查询全部列表
	 * @return
	 */
	public List<TestReport> findAll() {
		return testReportDao.findAll();
	}

	


	/**
	 * 根据ID查询实体
	 * @param id
	 * @return
	 */
	public TestReport findById(String id) {
		return testReportDao.findById(id).get();
	}

	/**
	 * 增加
	 * @param testReport
	 */
	public void add(TestReport testReport) {
		testReport.setId( idWorker.nextId()+"" );
		testReportDao.save(testReport);
	}

	/**
	 * 修改
	 * @param testReport
	 */
	public void update(TestReport testReport) {
		testReportDao.save(testReport);
	}

	/**
	 * 删除
	 * @param resultId
	 */
	public ResponseResult deleteByResultId(String resultId) {
		int i = testReportDao.deleteByResultId(resultId);
		return ResponseResult.okResult(i);
	}

	@Override
	public ResponseResult findByIdInData(String resultId) {
		String in = testReportDao.findByInResultId(resultId);
		if(StringUtils.isEmpty(in)){
			return ResponseResult.errorResult(AppHttpCodeEnum.DATA_NOT_EXIST);
		}
		return ResponseResult.okResult(in);
	}

	@Override
	public ResponseResult findByIdOutData(String resultId) {
		String out = testReportDao.findByOutResultId(resultId);
		if(StringUtils.isEmpty(out)){
			return ResponseResult.errorResult(AppHttpCodeEnum.DATA_NOT_EXIST);
		}
		return ResponseResult.okResult(out);
	}



}
