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.EarlywarningmainMapper;
import com.gyee.frame.model.auto.Earlywarningmain;
import com.gyee.frame.model.auto.EarlywarningmainExample;
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 EarlywarningmainService implements BaseService<Earlywarningmain, EarlywarningmainExample> {
	@Resource
	private EarlywarningmainMapper earlywarningmainMapper;
	

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

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

		return earlywarningmainMapper.insertSelective(record);
	}
	
	
	@Override
	public int updateByExampleSelective(Earlywarningmain record, EarlywarningmainExample example) {
		
		return earlywarningmainMapper.updateByExampleSelective(record, example);
	}

	
	@Override
	public int updateByExample(Earlywarningmain record, EarlywarningmainExample example) {
		
		return earlywarningmainMapper.updateByExample(record, example);
	}

	@Override
	public List<Earlywarningmain> selectByExample(EarlywarningmainExample example) {
		
		return earlywarningmainMapper.selectByExample(example);
	}

	
	@Override
	public long countByExample(EarlywarningmainExample example) {
		
		return earlywarningmainMapper.countByExample(example);
	}

	
	@Override
	public int deleteByExample(EarlywarningmainExample example) {
		
		return earlywarningmainMapper.deleteByExample(example);
	}


	public List<Earlywarningmain> getEarlywarningmainListBywtId(String wtId, Date recorddate) {

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

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

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

			EarlywarningmainExample.Criteria criteria =example.createCriteria();

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

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

		}
		return list;

	}
}
