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.MessageNoticeDAO;
import com.jpsoft.shinestar.modules.base.entity.MessageNotice;
import com.jpsoft.shinestar.modules.base.service.MessageNoticeService;
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="messageNoticeService")
public class MessageNoticeServiceImpl implements MessageNoticeService {
	@Resource(name="messageNoticeDAO")
	private MessageNoticeDAO messageNoticeDAO;

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

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

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

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

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

	@Override
	public Page<MessageNotice> pageSearchShort(Map<String, Object> searchParams, int pageNumber, int pageSize,boolean count,List<Sort> sortList) {
		Page<MessageNotice> page = PageHelper.startPage(pageNumber,pageSize,count).doSelectPage(()->{
			messageNoticeDAO.searchShort(searchParams,sortList);
		});

		return page;
	}

	@Override
	public List<MessageNotice> findByClassify(String classify,String id){
		return messageNoticeDAO.findByClassify(classify,id);
	}
}