package com.gyee.frame.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gyee.frame.common.base.BaseService;
import com.gyee.frame.common.support.Convert;
import com.gyee.frame.mapper.auto.Brownoutsevent2Mapper;
import com.gyee.frame.model.auto.Brownoutsevent2;
import com.gyee.frame.model.auto.Brownoutsevent2Example;
import com.gyee.frame.model.custom.Tablepar;
import com.gyee.frame.util.SnowflakeIdWorker;
import com.gyee.frame.util.StringUtils;
import org.springframework.stereotype.Service;

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


@Service
public class Brownoutsevent2Service implements BaseService<Brownoutsevent2, Brownoutsevent2Example> {
	@Resource
	private Brownoutsevent2Mapper brownoutsevent2Mapper;
	

	@Override
	public int deleteByPrimaryKey(String ids) {
				
			List<String> lista=Convert.toListStrArray(ids);
			Brownoutsevent2Example example=new Brownoutsevent2Example();
			example.createCriteria().andIdIn(lista);
			return brownoutsevent2Mapper.deleteByExample(example);
			
				
	}
	
	
	@Override
	public Brownoutsevent2 selectByPrimaryKey(String id) {
				
			return brownoutsevent2Mapper.selectByPrimaryKey(id);
				
	}

	
	@Override
	public int updateByPrimaryKeySelective(Brownoutsevent2 record) {
		return brownoutsevent2Mapper.updateByPrimaryKeySelective(record);
	}
	
	
	/**
	 * 添加
	 */
	@Override
	public int insertSelective(Brownoutsevent2 record) {
				
		//添加雪花主键id
		record.setId(SnowflakeIdWorker.getUUID());
			
				
		return brownoutsevent2Mapper.insertSelective(record);
	}
	
	
	@Override
	public int updateByExampleSelective(Brownoutsevent2 record, Brownoutsevent2Example example) {
		
		return brownoutsevent2Mapper.updateByExampleSelective(record, example);
	}

	
	@Override
	public int updateByExample(Brownoutsevent2 record, Brownoutsevent2Example example) {
		
		return brownoutsevent2Mapper.updateByExample(record, example);
	}

	@Override
	public List<Brownoutsevent2> selectByExample(Brownoutsevent2Example example) {
		
		return brownoutsevent2Mapper.selectByExample(example);
	}

	
	@Override
	public long countByExample(Brownoutsevent2Example example) {
		
		return brownoutsevent2Mapper.countByExample(example);
	}

	
	@Override
	public int deleteByExample(Brownoutsevent2Example example) {
		
		return brownoutsevent2Mapper.deleteByExample(example);
	}


	public PageInfo<Brownoutsevent2> getBrownoutsevent2ListById(Tablepar tablepar, String wtId, Date beginDate, Date endDate) {

		Brownoutsevent2Example example = new Brownoutsevent2Example();

		if(StringUtils.isNotEmpty(tablepar.getOrderByColumn()))
		{
			StringBuilder sb=new StringBuilder();
			sb.append(" ").append(tablepar.getOrderByColumn());
			if(StringUtils.isNotEmpty(tablepar.getIsAsc()))
			{
				sb.append(" ").append(tablepar.getIsAsc());
			}else
			{
				sb.append(" asc ");
			}
			example.setOrderByClause(String.valueOf(sb));
		}else {
			example.setOrderByClause("windturbineid ASC");
		}


		PageHelper.startPage(tablepar.getPageNum(), tablepar.getPageSize());

		Brownoutsevent2Example.Criteria criteria = example.createCriteria();
		if (StringUtils.notEmp(beginDate) && StringUtils.notEmp(endDate)) {

			criteria.andStoptimeGreaterThanOrEqualTo(beginDate).andStoptimeLessThan(endDate);
		}

		if (StringUtils.notEmp(wtId)) {
			criteria.andWindturbineidEqualTo(wtId);
		}

		List<Brownoutsevent2> list = brownoutsevent2Mapper.selectByExample(example);

		PageInfo<Brownoutsevent2> pageInfo = new PageInfo<Brownoutsevent2>(list);

		return pageInfo;
	}


	public PageInfo<Brownoutsevent2> getBrownoutsevent2List(Tablepar tablepar, String wtId, Date beginDate, Date endDate) {

		Brownoutsevent2Example example = new Brownoutsevent2Example();

		if(StringUtils.isNotEmpty(tablepar.getOrderByColumn()))
		{
			StringBuilder sb=new StringBuilder();
			sb.append(" ").append(tablepar.getOrderByColumn());
			if(StringUtils.isNotEmpty(tablepar.getIsAsc()))
			{
				sb.append(" ").append(tablepar.getIsAsc());
			}else
			{
				sb.append(" asc ");
			}
			example.setOrderByClause(String.valueOf(sb));
		}else {
			example.setOrderByClause("windturbineid ASC");
		}


		PageHelper.startPage(tablepar.getPageNum(), tablepar.getPageSize());

		Brownoutsevent2Example.Criteria criteria = example.createCriteria();
		if (StringUtils.notEmp(beginDate) && StringUtils.notEmp(endDate)) {

			criteria.andStoptimeGreaterThanOrEqualTo(beginDate).andStoptimeLessThan(endDate);
		}

		if (StringUtils.notEmp(wtId)) {
			criteria.andWindturbineidEqualTo(wtId);
		}

		List<Brownoutsevent2> list = brownoutsevent2Mapper.selectByExample(example);

		PageInfo<Brownoutsevent2> pageInfo = new PageInfo<Brownoutsevent2>(list);

		return pageInfo;
	}

	public List<Brownoutsevent2> getBrownoutsevent2List(String mainId) {

		Brownoutsevent2Example example = new Brownoutsevent2Example();


		Brownoutsevent2Example.Criteria criteria = example.createCriteria();
		if(StringUtils.notEmp(mainId))
		{
			criteria.andMainidEqualTo(mainId);
		}
		List<Brownoutsevent2> list = brownoutsevent2Mapper.selectByExample(example);



		return list;
	}


}
