package com.palmnest.dao.estateserve.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.palmnest.dao.estateserve.AppUseVersionDao;
import com.palmnest.dao.hibernate.GenericDaoHibernate;
import com.palmnest.model.estateserve.AppUseVersion;

/**
 * app版本管理Dao实现类
 *
 * @author longmeizhen
 */
@Repository("appUseVersionDao")
public class AppUseVersionDaoImpl extends GenericDaoHibernate<AppUseVersion, Long> implements AppUseVersionDao {

	public AppUseVersionDaoImpl() {
		super(AppUseVersion.class);
	}

	@Override
	public AppUseVersion getLatestRecode(String useCode, String type) {
		String sql = "from AppUseVersion where isLast='1' and usePlatform=? and useCode=?";
		List<AppUseVersion> list = getSession().createQuery(sql).setString(0, type).setString(1, useCode).list();
		if (list != null && list.size() > 0) {
			return list.get(0);
		}
		return null;
	}

	@Override
	public List<AppUseVersion> getByRecode(String useCode, String type) {
		String sql = "from AppUseVersion where  usePlatform=? and useCode=?";
		List<AppUseVersion> list = getSession().createQuery(sql).setString(0, type).setString(1, useCode).list();
		return list;
	}

	@Override
	public int updateRecodeByType(String type, String useCode) throws Exception {
		String sql = "update AppUseVersion set isLast='2',status='2' where usePlatform=? and useCode=? ";
		return getSession().createQuery(sql).setString(0, type).setString(1, useCode).executeUpdate();
	}

}
