package com.yeshi.buwan.service.imp.zhibo;
|
|
import com.yeshi.buwan.dao.zhibo.LiveTypeDao;
|
import com.yeshi.buwan.dao.zhibo.ZhiBoStatisticsDao;
|
import com.yeshi.buwan.dao.zhibo.ZhiBoStatisticsDetailDao;
|
import com.yeshi.buwan.util.TimeUtil;
|
import com.yeshi.buwan.zhibo.entity.LiveType;
|
import com.yeshi.buwan.zhibo.entity.ZhiBoStatistics;
|
import com.yeshi.buwan.zhibo.entity.ZhiBoStatisticsDetail;
|
import org.hibernate.HibernateException;
|
import org.hibernate.Session;
|
import org.springframework.cache.annotation.Cacheable;
|
import org.springframework.orm.hibernate4.HibernateCallback;
|
import org.springframework.stereotype.Service;
|
|
import javax.annotation.Resource;
|
import java.io.Serializable;
|
import java.util.List;
|
|
@Service
|
public class ZhiBoServcie {
|
@Resource
|
private ZhiBoStatisticsDao zhiBoStatisticsDao;
|
@Resource
|
private ZhiBoStatisticsDetailDao zhiBoStatisticsDetailDao;
|
|
@Resource
|
private LiveTypeDao liveTypeDao;
|
|
@SuppressWarnings("rawtypes")
|
public void addStatistics(final String rid, final int type) {
|
zhiBoStatisticsDetailDao.excute(new HibernateCallback() {
|
@SuppressWarnings("unchecked")
|
public Object doInHibernate(Session session) throws HibernateException {
|
String hour = TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyy-MM-dd HH");
|
List<ZhiBoStatisticsDetail> detailList = session
|
.createQuery("from ZhiBoStatisticsDetail d where d.rid=? and d.type=? and hour=?")
|
.setParameter(0, rid).setParameter(1, type).setParameter(2, hour).list();
|
session.getTransaction().begin();
|
if (detailList != null && detailList.size() > 0) {
|
detailList.get(0).setCount(detailList.get(0).getCount() + 1);
|
session.update(detailList.get(0));
|
} else {
|
session.persist(new ZhiBoStatisticsDetail(rid, type, hour, 1));
|
}
|
|
List<ZhiBoStatistics> list = session.createQuery("from ZhiBoStatistics s where s.rid=? and s.type=?")
|
.setParameter(0, rid).setParameter(1, type).list();
|
if (list != null && list.size() > 0) {
|
list.get(0).setCount(list.get(0).getCount() + 1);
|
session.update(list.get(0));
|
} else {
|
session.persist(new ZhiBoStatistics(rid, type, 1));
|
}
|
|
session.flush();
|
session.getTransaction().commit();
|
|
return null;
|
}
|
});
|
|
}
|
|
|
@Cacheable(value = "zhiboCache", key = "'getNewListCount'")
|
public long getNewListCount() {
|
|
return (Long) zhiBoStatisticsDao.excute(new HibernateCallback<Long>() {
|
public Long doInHibernate(Session session) throws HibernateException {
|
Object obj = session.createQuery("select count(*) from LJFLiveData data").uniqueResult();
|
return Long.parseLong(obj + "");
|
}
|
});
|
|
}
|
|
public List<LiveType> getAllLiveType(String id) {
|
|
List<LiveType> list = liveTypeDao.list("from LiveType lt left outer join fetch lt.systems s where s.id = ?", new Serializable[]{id});
|
|
return list;
|
}
|
|
public LiveType getLiveType(String id) {
|
LiveType find = liveTypeDao.find(LiveType.class, Long.valueOf(id));
|
return find;
|
}
|
|
}
|