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.FailurestatisticsmainMapper;
import com.gyee.frame.model.auto.Failurestatisticsmain;
import com.gyee.frame.model.auto.FailurestatisticsmainExample;
import com.gyee.frame.util.DateUtils;
import com.gyee.frame.util.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;


@Service
public class FailurestatisticsmainService implements BaseService<Failurestatisticsmain, FailurestatisticsmainExample> {
	@Resource
	private FailurestatisticsmainMapper failurestatisticsmainMapper;
	

	@Override
	public int deleteByPrimaryKey(String ids) {
				
			List<Integer> lista=Convert.toIntArrayList(ids);
			FailurestatisticsmainExample example=new FailurestatisticsmainExample();
			example.createCriteria().andIdIn(lista);
			return failurestatisticsmainMapper.deleteByExample(example);
			
				
	}
	
	
	@Override
	public Failurestatisticsmain selectByPrimaryKey(String id) {
				
			return failurestatisticsmainMapper.selectByPrimaryKey(Integer.valueOf(id));
				
	}

	
	@Override
	public int updateByPrimaryKeySelective(Failurestatisticsmain record) {
		return failurestatisticsmainMapper.updateByPrimaryKeySelective(record);
	}
	
	
	/**
	 * 添加
	 */
	@Override
	public int insertSelective(Failurestatisticsmain record) {
				

				
		return failurestatisticsmainMapper.insertSelective(record);
	}
	
	
	@Override
	public int updateByExampleSelective(Failurestatisticsmain record, FailurestatisticsmainExample example) {
		
		return failurestatisticsmainMapper.updateByExampleSelective(record, example);
	}

	
	@Override
	public int updateByExample(Failurestatisticsmain record, FailurestatisticsmainExample example) {
		
		return failurestatisticsmainMapper.updateByExample(record, example);
	}

	@Override
	public List<Failurestatisticsmain> selectByExample(FailurestatisticsmainExample example) {
		
		return failurestatisticsmainMapper.selectByExample(example);
	}

	
	@Override
	public long countByExample(FailurestatisticsmainExample example) {
		
		return failurestatisticsmainMapper.countByExample(example);
	}

	
	@Override
	public int deleteByExample(FailurestatisticsmainExample example) {
		
		return failurestatisticsmainMapper.deleteByExample(example);
	}

	public List<Failurestatisticsmain> getFailurestatisticsmainListBywtId(String wtId, Date recorddate) {

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

		if (StringUtils.notEmp(wtId) && StringUtils.notEmp(recorddate) ) {

			FailurestatisticsmainExample example=new FailurestatisticsmainExample();
			example.setOrderByClause("recodedate DESC");

			FailurestatisticsmainExample.Criteria criteria =example.createCriteria();

			Date endDate= DateUtils.addDays(recorddate,1);
			criteria.andRecodedateGreaterThanOrEqualTo(recorddate).andRecodedateLessThan(endDate);

			criteria.andWtidEqualTo(wtId);
			list= failurestatisticsmainMapper.selectByExample(example);

		}
		return list;

	}
}
