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.MessageNoticePersonDAO;
import com.jpsoft.shinestar.modules.base.entity.MessageNoticePerson;
import com.jpsoft.shinestar.modules.base.service.MessageNoticePersonService;
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="messageNoticePersonService")
public class MessageNoticePersonServiceImpl implements MessageNoticePersonService {
	@Resource(name="messageNoticePersonDAO")
	private MessageNoticePersonDAO messageNoticePersonDAO;

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

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

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

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

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

	@Override
	public MessageNoticePerson findByNIdAndPId(String noticeId, Long personId){
		return messageNoticePersonDAO.findByNIdAndPId(noticeId,personId);
	}
}