package com.jpsoft.shinestar.modules.base.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.jpsoft.shinestar.modules.base.dao.AlarmInfoDAO;
import com.jpsoft.shinestar.modules.base.entity.AlarmInfo;
import com.jpsoft.shinestar.modules.base.service.AlarmInfoService;
import com.jpsoft.shinestar.modules.common.dto.Sort;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

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

@Transactional
@Component(value="alarmInfoService")
public class AlarmInfoServiceImpl implements AlarmInfoService {
	@Resource(name="alarmInfoDAO")
	private AlarmInfoDAO alarmInfoDAO;

	@Override
	public AlarmInfo get(String id) {
		// TODO Auto-generated method stub
		return alarmInfoDAO.get(id);
	}

	@Override
	public int insert(AlarmInfo model) {
		// TODO Auto-generated method stub
		//model.setId(UUID.randomUUID().toString());
		
		return alarmInfoDAO.insert(model);
	}

	@Override
	public int update(AlarmInfo model) {
		// TODO Auto-generated method stub
		return alarmInfoDAO.update(model);		
	}

	@Override
	public int delete(String id) {
		// TODO Auto-generated method stub
		return alarmInfoDAO.delete(id);
	}

	@Override
	public AlarmInfo queryLatestAlarm(String type) {
		// TODO Auto-generated method stub
		return alarmInfoDAO.queryLatestAlarm(type);
	}

	@Override
	public boolean exist(String id) {
		// TODO Auto-generated method stub
		int count = alarmInfoDAO.exist(id);
		
		return count > 0 ? true : false;
	}
	
	@Override
	public List<AlarmInfo> list() {
		// TODO Auto-generated method stub
		return alarmInfoDAO.list();
	}
		
	@Override
	public Page<AlarmInfo> pageSearch(Map<String, Object> searchParams, int pageNumber, int pageSize,boolean count,List<Sort> sortList) {
        Page<AlarmInfo> page = PageHelper.startPage(pageNumber,pageSize,count).doSelectPage(()->{
            alarmInfoDAO.search(searchParams,sortList);
        });
        
        return page;
	}
}