package com.yeshi.buwan.service.imp; import java.io.Serializable; 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 org.springframework.transaction.annotation.Transactional; import com.yeshi.buwan.dao.AcFunTemporaryDao; import com.yeshi.buwan.domain.AcFunTemporary; @Service public class AcFunTemporaryService { @Resource private AcFunTemporaryDao dao; @Transactional public void save(AcFunTemporary act) { dao.save(act); } @Transactional public List getWaitConsumerList(int pagesize) { return dao.list("from AcFunTemporary a where a.isConsume = 0 and a.errorCount < 6", 0, pagesize,new Serializable[]{}); } public void fial(final AcFunTemporary acFunTemporary) { dao.excute(new HibernateCallback() { @Override public AcFunTemporary doInHibernate(Session session) throws HibernateException { Query query = session.createQuery("update AcFunTemporary set isConsume=0,errorCount=errorCount+1,errorInfo=?"); query.setParameter(0, acFunTemporary.getErrorInfo()); query.executeUpdate(); return null; } }); } public void success(AcFunTemporary acFunTemporary) { acFunTemporary.setIsConsume(true); dao.update(acFunTemporary); } /** * 删除已经消费过的AcFunTemporary */ public void deleteByConsume() { dao.excute(new HibernateCallback() { @Override public Object doInHibernate(Session session) throws HibernateException { Query query = session.createQuery("delete from AcFunTemporary a where a.isConsume=true"); query.executeUpdate(); return null; } }); } }