package com.gyee.frame.service;

import com.gyee.frame.common.base.BaseService;
import com.gyee.frame.common.dataSources.DataSource;
import com.gyee.frame.common.dataSources.DataSourceType;
import com.gyee.frame.common.support.Convert;
import com.gyee.frame.mapper.auto.WobugeqMapper;
import com.gyee.frame.model.auto.Wobugeq;
import com.gyee.frame.model.auto.WobugeqExample;
import com.gyee.frame.model.custom.MainTrackVo;
import com.gyee.frame.model.custom.SimpleVo;
import com.gyee.frame.model.custom.Tablepar;
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;

/**
 * 线路 WobugeqService
 * @Title: WobugeqService.java 
 * @Package com.gyee.frame.service 
 * @author gyee_自动生成
 * @email 1@qq.com
 * @date 2019-12-31 14:58:09  
 **/
@Service
public class WobugeqService implements BaseService<Wobugeq, WobugeqExample> {
	@Resource
	private WobugeqMapper wobugeqMapper;
	


	@Override
	public int deleteByPrimaryKey(String ids) {
				
			List<Double> lista=Convert.toDoubleArrayList(ids);
			WobugeqExample example=new WobugeqExample();
			example.createCriteria().andIdIn(lista);
			return wobugeqMapper.deleteByExample(example);


	}
	
	
	@Override
	public Wobugeq selectByPrimaryKey(String id) {
				
			return wobugeqMapper.selectByPrimaryKey(Double.valueOf(id));
				
	}

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

				
		return wobugeqMapper.insertSelective(record);
	}
	
	
	@Override
	public int updateByExampleSelective(Wobugeq record, WobugeqExample example) {
		
		return wobugeqMapper.updateByExampleSelective(record, example);
	}

	
	@Override
	public int updateByExample(Wobugeq record, WobugeqExample example) {
		
		return wobugeqMapper.updateByExample(record, example);
	}

	@Override
	public List<Wobugeq> selectByExample(WobugeqExample example) {
		
		return wobugeqMapper.selectByExample(example);
	}

	
	@Override
	public long countByExample(WobugeqExample example) {
		
		return wobugeqMapper.countByExample(example);
	}

	
	@Override
	public int deleteByExample(WobugeqExample example) {
		
		return wobugeqMapper.deleteByExample(example);
	}
	@DataSource(value = DataSourceType.TICKET)
	public List<Wobugeq> getWobugeqList(String wtId,Date beginDate,Date endDate) {

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

		if(StringUtils.notEmp(wtId) && StringUtils.notEmp(beginDate) && StringUtils.notEmp(endDate))
		{
			List<Integer> ls=wobugeqMapper.getWtnum(wtId);
			if(!ls.isEmpty())
			{
				int wtnum=ls.get(0);


					WobugeqExample example=new WobugeqExample();
					example.setOrderByClause("transmittime asc");

					WobugeqExample.Criteria criteria =example.createCriteria();

					criteria.andTransmittimeGreaterThanOrEqualTo(beginDate).andTransmittimeLessThan(endDate);

					criteria.andWtnumEqualTo(String.valueOf(wtnum));

					list= wobugeqMapper.selectByExample(example);


			}

		}

		return list;

	}

	@DataSource(value = DataSourceType.TICKET)
	public Wobugeq findRecommenmainById(String woId) {


		Wobugeq po=new Wobugeq();

		if(StringUtils.notEmp(woId) )
		{
			WobugeqExample example=new WobugeqExample();
			example.setOrderByClause("transmittime asc");

			WobugeqExample.Criteria criteria =example.createCriteria();

			criteria.andBugnumEqualTo(woId);

			List<Wobugeq> list= wobugeqMapper.selectByExample(example);

			if(!list.isEmpty())
			{
				po=list.get(0);

			}

		}

		return po;

	}

	@DataSource(value = DataSourceType.TICKET)
	public MainTrackVo findDuration() {

		MainTrackVo po=new MainTrackVo();

		List<MainTrackVo> list=wobugeqMapper.findDuration();

		if(!list.isEmpty())
		{
			po=list.get(0);
		}
		return po;

	}

	@DataSource(value = DataSourceType.TICKET)
	public int totalNum(Date beginDate,Date endDate) {

		int num=0;

		List<SimpleVo> list=wobugeqMapper.totalNum(beginDate,endDate);

		if(!list.isEmpty())
		{
			num=list.get(0).getValue();
		}
		return num;

	}


	@DataSource(value = DataSourceType.TICKET)
	public List<Wobugeq> findWobugeqByLocation(Tablepar tablepar,String location, Date beginDate, Date endDate) {


		List<Wobugeq> vos=new ArrayList<>();

		if(StringUtils.notEmp(location) )
		{
			WobugeqExample example=new WobugeqExample();

			WobugeqExample.Criteria criteria =example.createCriteria();

			criteria.andLocationEqualTo(location);

			criteria.andFindtimeGreaterThanOrEqualTo(beginDate).andFindtimeLessThan(endDate);


			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("transmittime ASC");
			}

			vos= wobugeqMapper.selectByExample(example);



		}

		return vos;

	}

}
