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.MessageReportDAO;
import com.jpsoft.shinestar.modules.base.entity.MessageReport;
import com.jpsoft.shinestar.modules.base.service.MessageReportService;
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="messageReportService")
public class MessageReportServiceImpl implements MessageReportService {
	@Resource(name="messageReportDAO")
	private MessageReportDAO messageReportDAO;

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

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

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

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

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