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

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

import org.cs.core.dao.impl.BaseDao;
import org.cs.mgr.user.dao.IMgmInviteRecordDao;
import org.cs.mgr.user.model.MgmInviteRecord;
import org.cs.util.Pager;
import org.cs.util.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

/**
 * 
 * @ClassName: MgmInviteRecordDao
 * @Description:  
 * @author: sunny_shi
 * @date: 2018-06-09 13:28:56
 */ 
@Repository
public class MgmInviteRecordDao extends BaseDao<MgmInviteRecord> implements IMgmInviteRecordDao {
	private final Logger logger = LoggerFactory.getLogger(this.getClass()); 
	 
	@Override
	public Pager queryMgmInviteRecords(Pager page){
		String hql = "from MgmInviteRecord where isDelete = false";
		return findPageByHql(hql, page, null);
	}
	
	@Override
	public MgmInviteRecord getByPropertie(String value,String entry) {
		Map<String, Object> params = new HashMap<>();
		params.put("value", value);
		List<Map<String,Object>> list=(List<Map<String, Object>>) this.findByHql("from MgmInviteRecord where "+entry+"=:value", params);
		if(list!=null && list.size() > 0){
			MgmInviteRecord mir=(MgmInviteRecord) list.get(0);
			return mir;
		}
		return null;
	}
	
	@Override
	public MgmInviteRecord getByRecordUserId(Integer userId) {
		List<Map<String,Object>> list=(List<Map<String, Object>>) this.findByHql("from MgmInviteRecord where  userId="+userId,null);
		if(list!=null && list.size() > 0){
			MgmInviteRecord mir=(MgmInviteRecord) list.get(0);
			return mir;
		}
		return null;
	}
	@Override
	public Pager queryMgmInviteRecordsByCode(Pager page,String code){
		String hql = "from MgmInviteRecord where isDelete = false ";
		if(StringUtil.isNotBlank(code)){
			hql+=" and inviteCode='"+code+"'"; 
		}
		hql+=" order by inviteDate desc";
		return findPageByHql(hql, page, null);
	}
	
	@Override
	public List<MgmInviteRecord> queryMgmInviteRecordsByCode(String code){
		String hql = "from MgmInviteRecord where isDelete = false ";
		if(StringUtil.isNotBlank(code)){
			hql+=" and inviteCode='"+code+"'"; 
		}
		hql+=" order by inviteDate desc";
		return (List<MgmInviteRecord>) findByHql(hql,null);
	}
}
