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.ModelpowerRdMapper;
import com.gyee.frame.model.auto.ModelpowerRd;
import com.gyee.frame.model.auto.ModelpowerRdExample;
import com.gyee.frame.util.SnowflakeIdWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;


@Service
public class ModelpowerRdService implements BaseService<ModelpowerRd, ModelpowerRdExample> {
	@Autowired
	private ModelpowerRdMapper modelpowerRdMapper;
	

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

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

	
	@Override
	public int updateByExample(ModelpowerRd record, ModelpowerRdExample example) {
		
		return modelpowerRdMapper.updateByExample(record, example);
	}

	@Override
	public List<ModelpowerRd> selectByExample(ModelpowerRdExample example) {
		
		return modelpowerRdMapper.selectByExample(example);
	}

	
	@Override
	public long countByExample(ModelpowerRdExample example) {
		
		return modelpowerRdMapper.countByExample(example);
	}

	
	@Override
	public int deleteByExample(ModelpowerRdExample example) {
		
		return modelpowerRdMapper.deleteByExample(example);
	}

	public Map<String, Map<Double, ModelpowerRd>> getModelpowerRdAllMap()  {


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

		ModelpowerRdExample example=new ModelpowerRdExample();
		example.setOrderByClause("modelid ASC");

		ModelpowerRdExample.Criteria criteria =example.createCriteria();


		list= modelpowerRdMapper.selectByExample(example);


		Map<String, Map<Double, ModelpowerRd>> res = new HashMap<String, Map<Double,ModelpowerRd>>();
		Map<Double, ModelpowerRd> map = null;

		if(list != null && !list.isEmpty()){
			for(ModelpowerRd mp : list){
				if(res.containsKey(mp.getModelid())){
					map = res.get(mp.getModelid());
					map.put(mp.getSpeed(), mp);
				}else{
					map = new HashMap<Double, ModelpowerRd>();
					map.put(mp.getSpeed(), mp);
					res.put(mp.getModelid(), map);
				}
			}
		}
		return res;

	}
}
