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.StopAnalysisDetailMapper;
import com.gyee.frame.model.auto.StopAnalysisDetail;
import com.gyee.frame.model.auto.StopAnalysisDetailExample;
import com.gyee.frame.model.auto.StopAnalysisDetailVo;
import com.gyee.frame.util.SnowflakeIdWorker;
import com.gyee.frame.util.StringUtils;
import org.springframework.stereotype.Service;

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


@Service
public class StopAnalysisDetailService implements BaseService<StopAnalysisDetail, StopAnalysisDetailExample> {
	@Resource
	private StopAnalysisDetailMapper stopAnalysisDetailMapper;
	@Resource
	private StopAnalysisDetailVoService stopAnalysisDetailVoService;

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

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

	
	@Override
	public int updateByExample(StopAnalysisDetail record, StopAnalysisDetailExample example) {
		
		return stopAnalysisDetailMapper.updateByExample(record, example);
	}

	@Override
	public List<StopAnalysisDetail> selectByExample(StopAnalysisDetailExample example) {
		
		return stopAnalysisDetailMapper.selectByExample(example);
	}

	
	@Override
	public long countByExample(StopAnalysisDetailExample example) {
		
		return stopAnalysisDetailMapper.countByExample(example);
	}

	
	@Override
	public int deleteByExample(StopAnalysisDetailExample example) {
		
		return stopAnalysisDetailMapper.deleteByExample(example);
	}

	public void saveStopAnalysisDetailList(String mainId,List<StopAnalysisDetailVo> vos) {

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

		//List<StopAnalysisDetailVo> vos=stopAnalysisDetailVoService.findStopAnalysisDetailVoList();

		if(!vos.isEmpty())
		{
			for(StopAnalysisDetailVo vo:vos)
			{
				StopAnalysisDetail po=new StopAnalysisDetail();


				po.setMainid(mainId);
				po.setPid(vo.getPid());
				po.setName(vo.getName());
				po.setJudegvulue(vo.getJudegvulue());
				po.setUrl(vo.getUrl());
				po.setIsparent(vo.getIsparent());
				po.setWtid(vo.getWtid());
				po.setRid(vo.getId());
				insertSelective(po);
			}
		}

	}

	public List<StopAnalysisDetail> findStopAnalysisDetailList(String mainId) {

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

		if (StringUtils.notEmp(mainId) ) {

			StopAnalysisDetailExample example=new StopAnalysisDetailExample();
			example.setOrderByClause(" rid ");

			StopAnalysisDetailExample.Criteria criteria =example.createCriteria();


			criteria.andMainidEqualTo(mainId);
			list= stopAnalysisDetailMapper.selectByExample(example);

		}
		return list;

	}
}
