package org.cs.mgr.user.dao.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import java.util.List;

import org.cs.core.dao.impl.BaseDao;
import org.cs.util.Pager;
import org.cs.util.StringUtil;
import org.cs.mgr.user.model.MgmMessage;
import org.cs.mgr.user.dao.IMgmMessageDao;

/**
 * 
 * @ClassName: MgmMessageDao
 * @Description:  
 * @author: sunny_shi
 * @date: 2018-06-09 13:28:56
 */
@Repository
public class MgmMessageDao extends BaseDao<MgmMessage> implements IMgmMessageDao {
	private final Logger logger = LoggerFactory.getLogger(this.getClass());
	
	@Override
	public Pager queryMgmMessages(Pager page){
		String hql = "from MgmMessage where isDelete = false";
		return findPageByHql(hql, page, null);
	}
	
	@Override
	public Pager queryMgmMessageByUserId(Pager page,String userId){
		String hql = "from MgmMessage where isDelete = false";
		if(StringUtil.isNotBlank(userId)){
			hql+=" and userId="+userId;
		}
		hql+="order by createDate desc";
		return findPageByHql(hql, page, null);
	} 
	
	@Override
	public List<MgmMessage> queryMgmMessageByUserId(String userId){
		String hql = "from MgmMessage where isDelete = false";
		if(StringUtil.isNotBlank(userId)){
			hql+=" and userId="+userId;
		}
		hql+=" order by createDate desc";
		return (List<MgmMessage>) findByHql(hql, null);
	}
	
	@Override
	public int countMgmMessage(String userId){
		String hql = "select count(1) as id from Mgm_Message where is_Delete=0 and state=0";
		if(StringUtil.isNotBlank(userId)){
			hql+=" and user_Id="+userId;
		}
		hql+=" order by create_Date desc";
		return countBySql(hql, null).intValue();
	}
}
