package com.gyee.frame.service;

import com.gyee.frame.common.base.BaseService;
import com.gyee.frame.common.support.Convert;
import com.gyee.frame.mapper.auto.WtTragetReportChartMapper;
import com.gyee.frame.model.auto.WtTragetReportChart;
import com.gyee.frame.model.auto.WtTragetReportChartExample;
import com.gyee.frame.util.DateUtils;
import com.gyee.frame.util.StringUtils;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;


@Service
public class WtTragetReportChartService implements BaseService<WtTragetReportChart, WtTragetReportChartExample> {
	@Resource
	private WtTragetReportChartMapper wtTragetReportChartMapper;


	@Override
	public int deleteByPrimaryKey(String ids) {

			List<Integer> lista=Convert.toIntArrayList(ids);
			WtTragetReportChartExample example=new WtTragetReportChartExample();
			example.createCriteria().andIdIn(lista);
			return wtTragetReportChartMapper.deleteByExample(example);
	}


	@Override
	public WtTragetReportChart selectByPrimaryKey(String id) {

			return wtTragetReportChartMapper.selectByPrimaryKey(Integer.valueOf(id));

	}


	@Override
	public int updateByPrimaryKeySelective(WtTragetReportChart record) {
		return wtTragetReportChartMapper.updateByPrimaryKeySelective(record);
	}


	/**
	 * 添加
	 */
	@Override
	public int insertSelective(WtTragetReportChart record) {


		return wtTragetReportChartMapper.insertSelective(record);
	}


	@Override
	public int updateByExampleSelective(WtTragetReportChart record, WtTragetReportChartExample example) {

		return wtTragetReportChartMapper.updateByExampleSelective(record, example);
	}


	@Override
	public int updateByExample(WtTragetReportChart record, WtTragetReportChartExample example) {

		return wtTragetReportChartMapper.updateByExample(record, example);
	}

	@Override
	public List<WtTragetReportChart> selectByExample(WtTragetReportChartExample example) {

		return wtTragetReportChartMapper.selectByExample(example);
	}


	@Override
	public long countByExample(WtTragetReportChartExample example) {

		return wtTragetReportChartMapper.countByExample(example);
	}


	@Override
	public int deleteByExample(WtTragetReportChartExample example) {

		return wtTragetReportChartMapper.deleteByExample(example);
	}

	public List<WtTragetReportChart> healthReportChart(String wtId,String partId, Date recorddate) {


		List<WtTragetReportChart> list=new ArrayList<>();

		WtTragetReportChartExample example=new WtTragetReportChartExample();
		example.setOrderByClause("recorddate asc");

		WtTragetReportChartExample.Criteria criteria =example.createCriteria();

		criteria.andWtidEqualTo(wtId);
		criteria.andPartidEqualTo(partId);
		Date endDate=recorddate;
		Date begin= DateUtils.addDays(recorddate,-7);
		criteria.andRecorddateGreaterThanOrEqualTo(begin).andRecorddateLessThan(endDate);

		criteria.andParentidEqualTo("null");
		list= wtTragetReportChartMapper.selectByExample(example);

		return list;

	}

	public List<WtTragetReportChart> healthReportChart(String wtId,String partId, Date beginDate,Date endDate) {


		List<WtTragetReportChart> list=new ArrayList<>();

		if(StringUtils.notEmp(wtId) && StringUtils.notEmp(partId) && StringUtils.notEmp(beginDate) && StringUtils.notEmp(endDate) )
		{
			WtTragetReportChartExample example=new WtTragetReportChartExample();
			example.setOrderByClause("recorddate asc");

			WtTragetReportChartExample.Criteria criteria =example.createCriteria();

			criteria.andWtidEqualTo(wtId);
			criteria.andPartidEqualTo(partId);
			criteria.andRecorddateGreaterThanOrEqualTo(beginDate).andRecorddateLessThan(endDate);

			criteria.andParentidEqualTo("null");
			list= wtTragetReportChartMapper.selectByExample(example);
		}


		return list;

	}
}
