package com.palmnest.dao.estateserve.impl;

import com.palmnest.dao.estateserve.UserRepairDao;
import com.palmnest.dao.hibernate.GenericDaoHibernate;
import com.palmnest.model.estateserve.UserRepairAccount;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author HIAPAD
 * @Description TODO
 * @Date 2018/11/1 20:28
 **/
@Repository("userRepairDao")
public class UserRepairDaoImpl extends GenericDaoHibernate<UserRepairAccount, Long> implements UserRepairDao {

	public UserRepairDaoImpl() {
		super(UserRepairAccount.class);
	}


	@Override
	public UserRepairAccount checkUserRegister(String orgId, String openId) {
		String hql = "from UserRepairAccount where orgId=? and openId=?";
		List<UserRepairAccount> list = getSession().createQuery(hql).setString(0, orgId).setString(1, openId).list();
		if (null != list && list.size() > 0) {
			return list.get(0);
		}
		return null;
	}

	@Override
	public UserRepairAccount checkMobile(String orgId, String openId, String mobile) {
		String hql = "from UserRepairAccount where orgId=? and openId=? and mobile=?";
		List<UserRepairAccount> list =
				getSession().createQuery(hql).setString(0, orgId).setString(1, openId).setString(2, mobile).list();
		if (null != list && list.size() > 0) {
			return list.get(0);
		}
		return null;
	}

	@Override
	public UserRepairAccount getUserByUserCode(String userCode) {
		String hql = "from UserRepairAccount where userCode=?";
		List<UserRepairAccount> list =
				getSession().createQuery(hql).setString(0, userCode).list();
		if (null != list && list.size() > 0) {
			return list.get(0);
		}
		return null;
	}
}
