package com.yeshi.buwan.service.imp;
|
|
import java.io.Serializable;
|
import java.util.ArrayList;
|
import java.util.List;
|
|
import javax.annotation.Resource;
|
|
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 com.yeshi.buwan.dao.DetailSystemDao;
|
import com.yeshi.buwan.dao.SpecialDao;
|
import com.yeshi.buwan.dao.SpecialVideoDao;
|
import com.yeshi.buwan.dao.SuperSpecialDao;
|
import com.yeshi.buwan.dao.VideoInfoDao;
|
import com.yeshi.buwan.domain.DetailSystem;
|
import com.yeshi.buwan.domain.VideoInfo;
|
import com.yeshi.buwan.domain.special.Special;
|
import com.yeshi.buwan.domain.special.SpecialVideo;
|
import com.yeshi.buwan.domain.special.SuperSpecial;
|
import com.yeshi.buwan.domain.web.DetailSystemSelect;
|
import com.yeshi.buwan.domain.web.SpecialAdmin;
|
import com.yeshi.buwan.util.Constant;
|
import com.yeshi.buwan.util.StringUtil;
|
import com.yeshi.buwan.web.tag.PageEntity;
|
|
@Service
|
public class SpecialService {
|
@Resource
|
private SpecialDao specialDao;
|
@Resource
|
private SpecialVideoDao specialVideoDao;
|
@Resource
|
private VideoInfoDao videoInfoDao;
|
@Resource
|
private SuperSpecialDao superSpecialDao;
|
@Resource
|
private DetailSystemDao detailSystemDao;
|
|
public SuperSpecialDao getSuperSpecialDao() {
|
return superSpecialDao;
|
}
|
|
public void setSuperSpecialDao(SuperSpecialDao superSpecialDao) {
|
this.superSpecialDao = superSpecialDao;
|
}
|
|
public VideoInfoDao getVideoInfoDao() {
|
return videoInfoDao;
|
}
|
|
public void setVideoInfoDao(VideoInfoDao videoInfoDao) {
|
this.videoInfoDao = videoInfoDao;
|
}
|
|
public SpecialVideoDao getSpecialVideoDao() {
|
return specialVideoDao;
|
}
|
|
public void setSpecialVideoDao(SpecialVideoDao specialVideoDao) {
|
this.specialVideoDao = specialVideoDao;
|
}
|
|
public SpecialDao getSpecialDao() {
|
return specialDao;
|
}
|
|
public void setSpecialDao(SpecialDao specialDao) {
|
this.specialDao = specialDao;
|
}
|
|
@Cacheable(value = "classCache",key="'getSpecialList'+'-'+#detailSystemId+'-'+#page")
|
public List<Special> getSpecialList(String detailSystemId, int page) {
|
return specialDao.list(
|
"select ss.special from SuperSpecial ss where ss.detailSystem.id=? and ss.special.show=1 order by ss.special.orderby desc",
|
(page - 1) * Constant.pageCount, Constant.pageCount, new String[] { detailSystemId });
|
}
|
|
public List<Special> getSpecialList(String detailSystemId) {
|
return specialDao.list(
|
"select ss.special from SuperSpecial ss where ss.detailSystem.id=? order by ss.special.orderby desc",
|
new String[] { detailSystemId });
|
}
|
|
public List<Special> getSpecialList() {
|
return specialDao.list("from Special");
|
}
|
|
@Cacheable(value = "classCache",key="'getSpecialCount'+'-'+#detailSystemId")
|
public long getSpecialCount(String detailSystemId) {
|
return specialDao.getCount("select count(*) from SuperSpecial ss where ss.detailSystem.id=?",
|
new String[] { detailSystemId });
|
}
|
|
@Cacheable(value = "classCache",key="'getSpecial'+'-'+#id")
|
public Special getSpecial(String id) {
|
return specialDao.find(Special.class, id);
|
}
|
|
public void addSpecial(Special special) {
|
specialDao.save(special);
|
}
|
|
@SuppressWarnings("rawtypes")
|
public void deleteSpecial(final Special special) {
|
if (special != null) {
|
specialDao.excute(new HibernateCallback() {
|
public Object doInHibernate(Session session) throws HibernateException {
|
try {
|
@SuppressWarnings("unchecked")
|
List<SuperSpecial> list = session.createQuery("from SuperSpecial sh where sh.special.id=?")
|
.setParameter(0, special.getId()).list();
|
session.getTransaction().begin();
|
for (SuperSpecial sh : list)
|
session.delete(sh);
|
session.delete(special);
|
session.flush();
|
session.getTransaction().commit();
|
} catch (Exception e) {
|
e.printStackTrace();
|
session.getTransaction().rollback();
|
}
|
return null;
|
}
|
});
|
|
}
|
}
|
|
public void updateSpecial(Special special) {
|
specialDao.update(special);
|
}
|
|
public void addSpecialVideo(SpecialVideo sv) {
|
specialVideoDao.create(sv);
|
}
|
|
@Cacheable(value = "classCache",key="'getSpecialVideoList'+'-'+#specialId")
|
public List<VideoInfo> getSpecialVideoList(String specialId) {
|
return videoInfoDao.list(
|
"select sv.video from SpecialVideo sv where sv.special.id=? and sv.video.show=1 order by sv.orderby desc",
|
new String[] { specialId });
|
}
|
|
public void deleteSpecialVideo(String specialVideoId) {
|
specialVideoDao.delete(new SpecialVideo(specialVideoId));
|
}
|
|
public long getSpecialVideoListCount(String specialId) {
|
|
return videoInfoDao.getCount("select sv.video from SpecialVideo sv where sv.special.id=?",
|
new String[] { specialId });
|
}
|
|
public List<SpecialVideo> getSpecialVideoList(String specialId, String key) {
|
return specialVideoDao.list("from SpecialVideo sv where sv.special.id=? and sv.video.name like ?",
|
new String[] { specialId, "%" + key + "%" });
|
}
|
|
public List<SpecialVideo> getSpecialVideoList(String specialId,PageEntity pg, String key) {
|
return specialVideoDao.list("from SpecialVideo sv where sv.special.id=? and sv.video.name like ?",((pg.getPageIndex()-1)*pg.getPageSize()),pg.getPageSize(),
|
new String[] { specialId, "%" + key + "%" });
|
}
|
|
public long getSpecialVideoListCount(String specialId, String key) {
|
return specialVideoDao.getCount(
|
"select count(*) from SpecialVideo sv where sv.special.id=? and sv.video.name like ?",
|
new String[] { specialId, "%" + key + "%" });
|
}
|
|
@SuppressWarnings("unchecked")
|
public List<SpecialAdmin> getSpecialAdmin(String key, int detailSystem, int page) {
|
key = StringUtil.isNullOrEmpty(key) ? "" : key;
|
List<SpecialAdmin> zhiBoClassList = new ArrayList<>();
|
|
try {
|
List<DetailSystem> detailSystemList = detailSystemDao.list("from DetailSystem");
|
String sql = "";
|
if (detailSystem > 0)
|
sql = "select sh.special from SuperSpecial sh where sh.special.name like ? and sh.detailSystem.id="
|
+ detailSystem + " order by sh.special.orderby desc";
|
else
|
sql = "from Special zb where zb.name like ? order by zb.orderby desc";
|
|
List<Special> list = specialDao.list(sql, (page - 1) * Constant.pageCount, Constant.pageCount,
|
new Serializable[] { "%" + key + "%" });
|
for (Special vb : list) {
|
List<DetailSystem> detailSystemS = detailSystemDao
|
.list("select vb.detailSystem from SuperSpecial vb where vb.special.id=" + vb.getId());
|
|
List<DetailSystemSelect> dssList = new ArrayList<>();
|
|
for (DetailSystem ds : detailSystemList) {
|
DetailSystemSelect dss = new DetailSystemSelect();
|
dss.setDetailSystem(ds);
|
dss.setSelected(false);
|
dssList.add(dss);
|
}
|
|
for (DetailSystem ds : detailSystemS) {
|
for (DetailSystemSelect dss : dssList) {
|
if (dss.getDetailSystem().getId().equalsIgnoreCase(ds.getId())) {
|
dss.setSelected(true);
|
break;
|
}
|
}
|
}
|
SuperSpecial sz = new SuperSpecial();
|
sz.setDetailSystem(null);
|
sz.setSpecial(vb);
|
zhiBoClassList.add(new SpecialAdmin(sz, dssList));
|
}
|
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
return zhiBoClassList;
|
}
|
|
public long getSpecialAdminCount(String key, int detailSystem) {
|
key = StringUtil.isNullOrEmpty(key) ? "" : key;
|
|
String sql = "";
|
if (detailSystem > 0)
|
sql = "select count(*) from (select count(*) from wk_video_super_special zb left join wk_video_special c on c.id=zb.specialid where zb.detailsystemid="
|
+ detailSystem + " and c.name like '%" + key + "%' group by zb.specialid) s";
|
else
|
sql = "select count(*) from (select count(*) from wk_video_super_special zb left join wk_video_special c on c.id=zb.specialid where c.name like '%"
|
+ key + "%' group by zb.specialid) s";
|
|
return specialVideoDao.getCountSQL(sql);
|
}
|
|
@SuppressWarnings("unchecked")
|
public void deleteSpecialAdmin(final String classId, final String detailSystemId) {
|
specialDao.excute(new HibernateCallback() {
|
public Object doInHibernate(Session session) throws HibernateException {
|
try {
|
|
List<SuperSpecial> list = session
|
.createQuery("from SuperSpecial vb where vb.special.id=? and vb.detailSystem.id=?")
|
.setParameter(0, classId).setParameter(1, detailSystemId).list();
|
session.getTransaction().begin();
|
if (list != null && list.size() > 0) {
|
for (SuperSpecial vb : list)
|
session.delete(vb);
|
}
|
session.flush();
|
session.getTransaction().commit();
|
|
} catch (Exception e) {
|
e.printStackTrace();
|
session.getTransaction().rollback();
|
}
|
return null;
|
}
|
});
|
|
}
|
|
/**
|
* 专题
|
*/
|
|
public List<SuperSpecial> getSuperSpecialList(String detailSystem) {
|
return superSpecialDao.list(
|
"FROM SuperSpecial hs where hs.detailSystem.id=" + detailSystem + " order by hs.Special.orderby desc");
|
}
|
|
public void addSuperSpecial(SuperSpecial sv) {
|
List<SuperSpecial> list = superSpecialDao.list("from SuperSpecial sv where sv.special.id="
|
+ sv.getSpecial().getId() + " and sv.detailSystem.id=" + sv.getDetailSystem().getId());
|
if (list != null && list.size() > 0)
|
return;
|
superSpecialDao.create(sv);
|
}
|
|
public void updateSuperSpecial(SuperSpecial hotSearch) {
|
superSpecialDao.update(hotSearch);
|
}
|
|
public void deleteSuperSpecial(SuperSpecial hotSearch) {
|
superSpecialDao.delete(hotSearch);
|
}
|
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
public void updateSuperSpecialList(final String detailSystemId, final List<SuperSpecial> typeList) {
|
specialDao.excute(new HibernateCallback() {
|
public Object doInHibernate(Session session) throws HibernateException {
|
try {
|
List<SuperSpecial> list = session
|
.createQuery("from SuperSpecial sh where sh.detailSystem.id=" + detailSystemId).list();
|
session.getTransaction().begin();
|
for (SuperSpecial ad : list) {
|
session.delete(ad);
|
}
|
|
for (SuperSpecial videoType : typeList) {
|
session.persist(videoType);
|
}
|
session.flush();
|
session.getTransaction().commit();
|
} catch (Exception e) {
|
e.printStackTrace();
|
session.getTransaction().rollback();
|
}
|
return null;
|
}
|
});
|
|
}
|
|
@Cacheable(value = "foundCache",key="'getSpecialOnMain'+'-'+#detailSystem")
|
public List<Special> getSpecialOnMain(String detailSystem) {
|
return specialDao.list("SELECT hs.special FROM SuperSpecial hs where hs.detailSystem.id=" + detailSystem
|
+ " and hs.special.show=1 and hs.special.showonmain=1 order by hs.special.orderby desc");
|
}
|
|
}
|