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

import java.util.List;
import java.util.Map;
import java.util.UUID;
import javax.annotation.Resource;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import com.jpsoft.shinestar.modules.base.dao.MessageSendConditionDAO;
import com.jpsoft.shinestar.modules.base.entity.MessageSendCondition;
import com.jpsoft.shinestar.modules.base.service.MessageSendConditionService;
import com.github.pagehelper.Page;
import com.jpsoft.shinestar.modules.common.dto.Sort;
import com.github.pagehelper.PageHelper;

@Transactional
@Component(value="messageSendConditionService")
public class MessageSendConditionServiceImpl implements MessageSendConditionService {
	@Resource(name="messageSendConditionDAO")
	private MessageSendConditionDAO messageSendConditionDAO;

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

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

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

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

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

	@Override
	public List<String> findNewMessage(Map<String, Object> searchParams) {
		return messageSendConditionDAO.findNewMessage(searchParams);
	}
}