package com.ym.mec.biz.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ym.mec.biz.dal.dao.ImGroupNoticeDao;
import com.ym.mec.biz.dal.dto.ImGroupNoticeDto;
import com.ym.mec.biz.dal.entity.ImGroupNotice;
import com.ym.mec.biz.dal.page.ImGroupNoticeQueryInfo;
import com.ym.mec.biz.service.ImGroupNoticeService;
import com.ym.mec.common.dal.BaseDAO;
import com.ym.mec.common.page.PageInfo;
import com.ym.mec.common.service.impl.BaseServiceImpl;
import com.ym.mec.util.collection.MapUtil;

@Service
public class ImGroupNoticeServiceImpl extends BaseServiceImpl<Long, ImGroupNotice>  implements ImGroupNoticeService {
	
	@Autowired
	private ImGroupNoticeDao imGroupNoticeDao;

	@Override
	public BaseDAO<Long, ImGroupNotice> getDAO() {
		return imGroupNoticeDao;
	}

	@Override
	public PageInfo<ImGroupNoticeDto> queryPage(ImGroupNoticeQueryInfo queryInfo) {
		PageInfo<ImGroupNoticeDto> pageInfo = new PageInfo<ImGroupNoticeDto>(queryInfo.getPage(), queryInfo.getRows());
		Map<String, Object> params = new HashMap<String, Object>();
		MapUtil.populateMap(params, queryInfo);
		
		List<ImGroupNoticeDto> dataList = null;
		int count = this.findCount(params);
		if (count > 0) {
			pageInfo.setTotal(count);
			params.put("offset", pageInfo.getOffset());
			dataList = imGroupNoticeDao.queryForPage(params);
		}
		if (count == 0) {
			dataList = new ArrayList<ImGroupNoticeDto>();
		}
		pageInfo.setRows(dataList);
		return pageInfo;
	}

	@Override
	public ImGroupNoticeDto queryLatestNotice(Long imGroupId) {
		return imGroupNoticeDao.queryLatestNotice(imGroupId);
	}
	
}