package com.yeshi.buwan.service.imp;
|
|
import java.util.List;
|
|
import javax.annotation.Resource;
|
|
import org.hibernate.HibernateException;
|
import org.hibernate.Query;
|
import org.hibernate.Session;
|
import org.springframework.orm.hibernate4.HibernateCallback;
|
import org.springframework.stereotype.Service;
|
|
import com.yeshi.buwan.videos.acFun.AcFunVideo;
|
import com.yeshi.buwan.dao.AcFunVideoDao;
|
|
@Service
|
public class AcFunVideoService {
|
|
@Resource
|
private AcFunVideoDao dao;
|
|
public void save(AcFunVideo acFunVideo) {
|
dao.save(acFunVideo);
|
}
|
|
@SuppressWarnings("unchecked")
|
public List<AcFunVideo> getWaitStroagrAcFunVideoList(final Long[] types) {
|
return (List<AcFunVideo>) dao.excute(new HibernateCallback<List<AcFunVideo>>() {
|
@Override
|
public List<AcFunVideo> doInHibernate(Session session)
|
throws HibernateException {
|
|
StringBuffer sql=new StringBuffer("from AcFunVideo a where a.isStorage = 0 and (");
|
int i=0;
|
for (Long tid : types) {
|
if(i!=0){
|
sql.append(" or ");
|
}
|
sql.append(" a.videoType.id= "+tid);
|
i++;
|
}
|
sql.append(")");
|
Query query = session.createQuery(sql.toString());
|
query.setFirstResult(0);
|
query.setMaxResults(20);
|
return query.list();
|
}
|
});
|
}
|
|
public void success(AcFunVideo acFunVideo) {
|
acFunVideo.setIsStorage(true);
|
dao.update(acFunVideo);
|
}
|
|
public AcFunVideo find(Long id) {
|
return dao.find(AcFunVideo.class, id);
|
}
|
|
}
|