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.PartstatisticsmainMapper;
import com.gyee.frame.model.auto.Partstatisticsmain;
import com.gyee.frame.model.auto.PartstatisticsmainExample;
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 PartstatisticsmainService implements BaseService<Partstatisticsmain, PartstatisticsmainExample> {
	@Resource
	private PartstatisticsmainMapper partstatisticsmainMapper;
	

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

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

				
		return partstatisticsmainMapper.insertSelective(record);
	}
	
	
	@Override
	public int updateByExampleSelective(Partstatisticsmain record, PartstatisticsmainExample example) {
		
		return partstatisticsmainMapper.updateByExampleSelective(record, example);
	}

	
	@Override
	public int updateByExample(Partstatisticsmain record, PartstatisticsmainExample example) {
		
		return partstatisticsmainMapper.updateByExample(record, example);
	}

	@Override
	public List<Partstatisticsmain> selectByExample(PartstatisticsmainExample example) {
		
		return partstatisticsmainMapper.selectByExample(example);
	}

	
	@Override
	public long countByExample(PartstatisticsmainExample example) {
		
		return partstatisticsmainMapper.countByExample(example);
	}

	
	@Override
	public int deleteByExample(PartstatisticsmainExample example) {
		
		return partstatisticsmainMapper.deleteByExample(example);
	}


	public List<Partstatisticsmain> getPartstatisticsmainListBywtId(String wtId, Date recorddate) {

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

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

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

			PartstatisticsmainExample.Criteria criteria =example.createCriteria();

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

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

		}
		return list;

	}


}
