package com.yeshi.buwan.service.imp;
|
|
import java.io.Serializable;
|
import java.util.ArrayList;
|
import java.util.List;
|
|
import javax.annotation.Resource;
|
|
import com.yeshi.buwan.util.NumberUtil;
|
import org.hibernate.HibernateException;
|
import org.hibernate.Session;
|
import org.springframework.cache.annotation.CacheEvict;
|
import org.springframework.cache.annotation.Cacheable;
|
import org.springframework.orm.hibernate4.HibernateCallback;
|
import org.springframework.stereotype.Service;
|
|
import com.yeshi.buwan.dao.VideoBanQuanDao;
|
import com.yeshi.buwan.dao.VideoBanQuanVideoDao;
|
import com.yeshi.buwan.dao.WebVideoDao;
|
import com.yeshi.buwan.domain.system.DetailSystem;
|
import com.yeshi.buwan.domain.HomeVideo;
|
import com.yeshi.buwan.domain.VideoBanQuan;
|
import com.yeshi.buwan.domain.VideoBanQuanVideo;
|
import com.yeshi.buwan.domain.VideoInfo;
|
import com.yeshi.buwan.domain.VideoResource;
|
import com.yeshi.buwan.domain.web.BanquanKeyAdmin;
|
import com.yeshi.buwan.domain.web.BanquanVideoAdmin;
|
import com.yeshi.buwan.domain.web.DetailSystemSelect;
|
import com.yeshi.buwan.util.Constant;
|
import com.yeshi.buwan.util.StringUtil;
|
|
@Service
|
public class BanQuanService {
|
@Resource
|
private VideoBanQuanDao videoBanQuanDao;
|
@Resource
|
private VideoBanQuanVideoDao videoBanQuanVideoDao;
|
@Resource
|
private WebVideoDao webVideoDao;
|
|
@SuppressWarnings("unchecked")
|
@CacheEvict(value = "topCache", allEntries = true)
|
public void addBanQuanVideo(final List<VideoBanQuanVideo> list) {
|
videoBanQuanDao.excute(new HibernateCallback() {
|
public Object doInHibernate(Session session) throws HibernateException {
|
try {
|
session.getTransaction().begin();
|
for (int i = 0; i < list.size(); i++) {
|
List<VideoBanQuanVideo> bl = session
|
.createQuery("from VideoBanQuanVideo v where v.detailSystem.id="
|
+ list.get(i).getDetailSystem().getId() + " and v.info.id="
|
+ list.get(i).getInfo().getId())
|
.list();
|
if (bl == null || bl.size() == 0) {
|
session.persist(list.get(i));
|
}
|
}
|
session.flush();
|
session.getTransaction().commit();
|
} catch (Exception e) {
|
e.printStackTrace();
|
session.getTransaction().rollback();
|
}
|
return null;
|
}
|
});
|
|
}
|
|
@SuppressWarnings("unchecked")
|
public void addBanQuanKey(final List<VideoBanQuan> list) {
|
videoBanQuanDao.excute(new HibernateCallback() {
|
public Object doInHibernate(Session session) throws HibernateException {
|
try {
|
session.getTransaction().begin();
|
for (int i = 0; i < list.size(); i++) {
|
List<VideoBanQuan> bl = session
|
.createQuery("from VideoBanQuan v where v.detailSystem.id="
|
+ list.get(i).getDetailSystem().getId() + " and v.name=?")
|
.setParameter(0, list.get(i).getName()).list();
|
if (bl == null || bl.size() == 0) {
|
session.persist(list.get(i));
|
}
|
}
|
session.flush();
|
session.getTransaction().commit();
|
} catch (Exception e) {
|
e.printStackTrace();
|
session.getTransaction().rollback();
|
}
|
return null;
|
}
|
});
|
|
}
|
|
public VideoBanQuanVideo getBanQuanVideo(String id) {
|
|
return videoBanQuanVideoDao.find(VideoBanQuanVideo.class, id);
|
}
|
|
public VideoBanQuan getBanQuanKey(String id) {
|
|
return videoBanQuanDao.find(VideoBanQuan.class, id);
|
}
|
|
public void updateVideoBanQuanVideo(VideoBanQuanVideo video) {
|
|
videoBanQuanVideoDao.update(video);
|
}
|
|
public void updateVideoBanQuan(VideoBanQuan video) {
|
|
videoBanQuanDao.update(video);
|
}
|
|
public void deleteBanQuanVideo(final List<VideoBanQuanVideo> list) {
|
videoBanQuanDao.excute(new HibernateCallback() {
|
public Object doInHibernate(Session session) throws HibernateException {
|
try {
|
session.getTransaction().begin();
|
for (int i = 0; i < list.size(); i++) {
|
session.delete(list.get(i));
|
}
|
session.flush();
|
session.getTransaction().commit();
|
} catch (Exception e) {
|
e.printStackTrace();
|
session.getTransaction().rollback();
|
}
|
return null;
|
}
|
});
|
|
}
|
|
public void deleteBanQuanKey(final List<VideoBanQuan> list) {
|
videoBanQuanDao.excute(new HibernateCallback() {
|
public Object doInHibernate(Session session) throws HibernateException {
|
try {
|
session.getTransaction().begin();
|
for (int i = 0; i < list.size(); i++) {
|
session.delete(list.get(i));
|
}
|
session.flush();
|
session.getTransaction().commit();
|
} catch (Exception e) {
|
e.printStackTrace();
|
session.getTransaction().rollback();
|
}
|
return null;
|
}
|
});
|
|
}
|
|
public void deleteBanQuanKeyByKey(final String key) {
|
videoBanQuanDao.excute(new HibernateCallback() {
|
public Object doInHibernate(Session session) throws HibernateException {
|
try {
|
session.getTransaction().begin();
|
session.createQuery("delete from VideoBanQuan vb where vb.name=?").setParameter(0, key)
|
.executeUpdate();
|
session.flush();
|
session.getTransaction().commit();
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
return null;
|
}
|
});
|
|
}
|
|
@CacheEvict(value = "topCache", allEntries = true)
|
public void deleteBanQuanVideoByVID(final String videoid) {
|
videoBanQuanDao.excute(new HibernateCallback() {
|
public Object doInHibernate(Session session) throws HibernateException {
|
try {
|
session.getTransaction().begin();
|
session.createQuery("delete from VideoBanQuanVideo vb where vb.info.id=?").setParameter(0, videoid)
|
.executeUpdate();
|
session.flush();
|
session.getTransaction().commit();
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
return null;
|
}
|
});
|
|
}
|
|
public List<VideoBanQuanVideo> getBanQuanVideoList(int page, String key, int detailSystemId) {
|
String sql = "";
|
if (detailSystemId == 0)
|
sql = "from VideoBanQuanVideo vb where vb.name like ?";
|
else
|
sql = "from VideoBanQuanVideo vb where vb.name like ? and vb.detailSystem.id=" + detailSystemId;
|
|
return videoBanQuanVideoDao.list(sql, (page - 1) * Constant.pageCount, Constant.pageCount,
|
new String[]{"%" + key + "%"});
|
}
|
|
public long getBanQuanVideoPage(String key, int detailSystemId) {
|
String sql = "";
|
if (detailSystemId == 0) {
|
sql = "select count(*) from VideoBanQuanVideo v where v.name like ?";
|
} else {
|
sql = "select count(*) from VideoBanQuanVideo v where v.name like ? and v.detailSystem.id="
|
+ detailSystemId;
|
}
|
|
long count = videoBanQuanVideoDao.getCount(sql, new String[]{"%" + key + "%"});
|
|
return count % Constant.pageCount == 0 ? count / Constant.pageCount : count / Constant.pageCount + 1;
|
}
|
|
public List<VideoBanQuan> getBanQuanKeyList(int page, String key, int detailSystemId) {
|
String sql = "";
|
if (detailSystemId == 0)
|
sql = "from VideoBanQuan vb where vb.name like ?";
|
else
|
sql = "from VideoBanQuan vb where vb.name like ? and vb.detailSystem.id=" + detailSystemId;
|
|
return videoBanQuanDao.list(sql, (page - 1) * Constant.pageCount, Constant.pageCount,
|
new String[]{"%" + key + "%"});
|
}
|
|
public List<String> getBanQuanKeyListAll(int detailSystemId) {
|
String sql = "";
|
if (detailSystemId == 0)
|
sql = "from VideoBanQuan vb";
|
else
|
sql = "from VideoBanQuan vb where vb.detailSystem.id=" + detailSystemId;
|
|
List<VideoBanQuan> bList = videoBanQuanDao.list(sql);
|
List<String> keyList = new ArrayList<>();
|
if (bList != null)
|
for (VideoBanQuan b : bList)
|
keyList.add(b.getName());
|
return keyList;
|
}
|
|
public long getBanQuanKeyPage(String key, int detailSystemId) {
|
String sql = "";
|
if (detailSystemId == 0) {
|
sql = "select count(*) from VideoBanQuan v where v.name like ?";
|
} else {
|
sql = "select count(*) from VideoBanQuan v where v.name like ? and v.detailSystem.id=" + detailSystemId;
|
}
|
|
long count = videoBanQuanVideoDao.getCount(sql, new String[]{"%" + key + "%"});
|
|
return count % Constant.pageCount == 0 ? count / Constant.pageCount : count / Constant.pageCount + 1;
|
}
|
|
// 过滤版权视频
|
|
@SuppressWarnings({"rawtypes", "unchecked"})
|
@Cacheable(value = "userCache", key = "'getBanQuanVideo'+'-'+#cacheMD5+'-'+#detailSystemId")
|
public List<VideoInfo> getBanQuanVideo(final List<VideoInfo> list, final String detailSystemId, String cacheMD5) {
|
if (list == null || list.size() == 0)
|
return list;
|
List<VideoInfo> newList = (List<VideoInfo>) videoBanQuanDao.excute(new HibernateCallback<List<VideoInfo>>() {
|
public List<VideoInfo> doInHibernate(Session session) throws HibernateException {
|
String sql = "";
|
for (VideoInfo vi : list) {
|
if (NumberUtil.isNumeric(vi.getId()))
|
sql += " (SELECT v.`id`,bv.`videoid`,bv.`detailsystemid`,bv.`show` FROM wk_video_video v LEFT JOIN wk_video_banquan_video bv ON bv.`videoid`=v.`id` WHERE v.`id`="
|
+ vi.getId() + ") UNION ALL";
|
}
|
if (sql.endsWith("UNION ALL"))
|
sql = sql.substring(0, sql.length() - 9);
|
|
try {
|
List rlist = session.createSQLQuery(sql).list();
|
for (int i = 0; i < rlist.size(); i++) {
|
Object[] objs = (Object[]) rlist.get(i);
|
if (!StringUtil.isNullOrEmpty(objs[1] + "") && "1".equalsIgnoreCase(objs[3] + "")
|
&& detailSystemId.equalsIgnoreCase(objs[2] + "")) {
|
// 是版权视频
|
// if (list.size() > i)
|
// list.get(i).setShow("0");
|
// 20171009 update
|
for (VideoInfo vi : list) {
|
if (vi.getId().equals(objs[1] + "")) {
|
vi.setShow("0");
|
}
|
}
|
|
}
|
// else {
|
// if (list.size() > i)
|
// list.get(i).setShow("1");
|
// }
|
}
|
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
return list;
|
}
|
});
|
|
for (int i = 0; i < newList.size(); i++) {
|
if ("0".equalsIgnoreCase(newList.get(i).getShow())) {
|
newList.remove(i);
|
i--;
|
}
|
}
|
return newList;
|
}
|
|
@SuppressWarnings("rawtypes")
|
public List<HomeVideo> getBanQuanHomeVideo(final List<HomeVideo> list, final String detailSystemId) {
|
|
videoBanQuanDao.excute(new HibernateCallback<List<HomeVideo>>() {
|
public List<HomeVideo> doInHibernate(Session session) throws HibernateException {
|
String sql = "";
|
for (HomeVideo hv : list) {
|
sql += " (SELECT v.`id`,bv.`videoid`,bv.`detailsystemid`,bv.`show` FROM wk_video_video v LEFT JOIN wk_video_banquan_video bv ON bv.`videoid`=v.`id` WHERE v.`id`="
|
+ hv.getVideo().getId() + ") UNION ALL";
|
}
|
if (sql.endsWith("UNION ALL"))
|
sql = sql.substring(0, sql.length() - 9);
|
try {
|
List rlist = session.createSQLQuery(sql).list();
|
for (int i = 0; i < rlist.size(); i++) {
|
Object[] objs = (Object[]) rlist.get(i);
|
if (!StringUtil.isNullOrEmpty(objs[1] + "") && "1".equalsIgnoreCase(objs[2] + "")
|
&& detailSystemId.equalsIgnoreCase(objs[3] + "")) {
|
// 是版权视频
|
// list.get(i).getVideo().setShow("0");
|
// 20171009 update
|
for (HomeVideo hv : list) {
|
if (hv.getVideo().getId().equals(objs[1] + "")) {
|
hv.getVideo().setShow("0");
|
}
|
}
|
}
|
// else
|
// list.get(i).getVideo().setShow("1");
|
}
|
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
|
return list;
|
}
|
});
|
|
for (int i = 0; i < list.size(); i++) {
|
if (list.get(i).getVideo().getShow().equalsIgnoreCase("0")) {
|
list.remove(i);
|
i--;
|
}
|
}
|
return list;
|
}
|
|
/**
|
* 管理页面操作
|
*/
|
|
@SuppressWarnings("unchecked")
|
public List<BanquanKeyAdmin> getBanquanKeyAdmin(final String key, final int detailSystem, final int page) {
|
|
return (List<BanquanKeyAdmin>) videoBanQuanDao.excute(new HibernateCallback<List<BanquanKeyAdmin>>() {
|
public List<BanquanKeyAdmin> doInHibernate(Session session) throws HibernateException {
|
List<BanquanKeyAdmin> banquanList = new ArrayList<>();
|
try {
|
List<DetailSystem> detailSystemList = session.createQuery("from DetailSystem").list();
|
String where = "";
|
if (detailSystem > 0)
|
where = "where vb.detailSystem.id=" + detailSystem + " and";
|
else
|
where = "where";
|
|
List<VideoBanQuan> list = session
|
.createQuery("from VideoBanQuan vb " + where
|
+ " vb.name like ? group by vb.name order by vb.createtime desc")
|
.setParameter(0, "%" + key + "%").setFirstResult((page - 1) * Constant.pageCount)
|
.setMaxResults(Constant.pageCount).list();
|
for (VideoBanQuan vb : list) {
|
List<DetailSystem> detailSystemS = session
|
.createQuery("select vb.detailSystem from VideoBanQuan vb where vb.name=?")
|
.setParameter(0, vb.getName()).list();
|
|
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;
|
}
|
}
|
}
|
banquanList.add(new BanquanKeyAdmin(vb, dssList));
|
}
|
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
return banquanList;
|
}
|
});
|
|
}
|
|
public long getBanquanKeyAdminCount(String key, int detailSystem) {
|
String where = "";
|
if (detailSystem > 0)
|
where = "where vb.detailsystem=" + detailSystem + " and";
|
else
|
where = "where";
|
|
return videoBanQuanVideoDao.getCountSQL("select count(*) from (select count(*) from wk_video_banquan vb "
|
+ where + " vb.name like '%" + key + "%' group by vb.name ) s");
|
}
|
|
@SuppressWarnings("rawtypes")
|
public void addBanQuanKeyAdmin(final String key, final String detailSystemId) {
|
videoBanQuanDao.excute(new HibernateCallback() {
|
public Object doInHibernate(Session session) throws HibernateException {
|
try {
|
List list = session.createQuery("from VideoBanQuan vb where vb.name=? and vb.detailSystem.id=?")
|
.setParameter(0, key).setParameter(0, detailSystemId).list();
|
session.getTransaction().begin();
|
if (list == null || list.size() == 0) {
|
VideoBanQuan vb = new VideoBanQuan();
|
vb.setCreatetime(System.currentTimeMillis() + "");
|
vb.setDetailSystem(new DetailSystem(detailSystemId));
|
vb.setName(key);
|
vb.setShow(true);
|
vb.setVideoType(1);
|
vb.setVideoResource(new VideoResource("6"));
|
session.persist(vb);
|
}
|
session.flush();
|
session.getTransaction().commit();
|
|
} catch (Exception e) {
|
e.printStackTrace();
|
session.getTransaction().rollback();
|
}
|
|
return null;
|
}
|
});
|
|
}
|
|
@SuppressWarnings({"unchecked", "rawtypes"})
|
public void deleteBanQuanKeyAdmin(final String key, final String detailSystemId) {
|
videoBanQuanDao.excute(new HibernateCallback() {
|
public Object doInHibernate(Session session) throws HibernateException {
|
try {
|
session.getTransaction().begin();
|
List<VideoBanQuan> list = session
|
.createQuery("from VideoBanQuan vb where vb.name=? and vb.detailSystem.id=?")
|
.setParameter(0, key).setParameter(1, detailSystemId).list();
|
if (list != null && list.size() > 0) {
|
for (VideoBanQuan vb : list)
|
session.delete(vb);
|
}
|
session.flush();
|
session.getTransaction().commit();
|
|
} catch (Exception e) {
|
e.printStackTrace();
|
session.getTransaction().rollback();
|
}
|
return null;
|
}
|
});
|
|
}
|
|
@SuppressWarnings("unchecked")
|
public List<BanquanVideoAdmin> getBanquanVideoAdmin(final String key, final int detailSystem, final int page) {
|
|
return (List<BanquanVideoAdmin>) videoBanQuanDao.excute(new HibernateCallback<List<BanquanVideoAdmin>>() {
|
public List<BanquanVideoAdmin> doInHibernate(Session session) throws HibernateException {
|
List<BanquanVideoAdmin> banquanList = new ArrayList<>();
|
try {
|
List<DetailSystem> detailSystemList = session.createQuery("from DetailSystem").list();
|
String where = "";
|
if (detailSystem > 0)
|
where += " where vb.detailSystem.id= " + detailSystem + " and ";
|
else
|
where += " where ";
|
|
List<VideoBanQuanVideo> list = session
|
.createQuery("from VideoBanQuanVideo vb " + where
|
+ " vb.info.name like ? group by vb.info.id order by vb.createtime desc")
|
.setParameter(0, "%" + key + "%").setFirstResult((page - 1) * Constant.pageCount)
|
.setMaxResults(Constant.pageCount).list();
|
for (VideoBanQuanVideo vb : list) {
|
List<DetailSystem> detailSystemS = session
|
.createQuery("select vb.detailSystem from VideoBanQuanVideo vb where vb.info.id=?")
|
.setParameter(0, vb.getInfo().getId()).list();
|
|
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;
|
}
|
}
|
}
|
banquanList.add(new BanquanVideoAdmin(vb, dssList));
|
}
|
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
return banquanList;
|
}
|
});
|
|
}
|
|
public long getBanquanVideoAdminCount(String key, int detailSystem) {
|
|
String where = "";
|
if (detailSystem > 0)
|
where += " where bv.detailsystemid= " + detailSystem + " and ";
|
else
|
where += " where ";
|
|
return videoBanQuanVideoDao.getCountSQL(
|
"select count(*) from (select count(*) from wk_video_banquan_video bv left join wk_video_video v on v.id=bv.videoid "
|
+ where + " v.name like '%" + key + "%' group by bv.videoid) s");
|
}
|
|
@SuppressWarnings("rawtypes")
|
public void addBanQuanVideoAdmin(final String videoid, final String detailSystemId) {
|
videoBanQuanDao.excute(new HibernateCallback() {
|
public Object doInHibernate(Session session) throws HibernateException {
|
try {
|
List list = session
|
.createQuery("from VideoBanQuanVideo vb where vb.info.id=? and vb.detailSystem.id=?")
|
.setParameter(0, videoid).setParameter(1, detailSystemId).list();
|
session.getTransaction().begin();
|
if (list == null || list.size() == 0) {
|
VideoBanQuanVideo vb = new VideoBanQuanVideo();
|
vb.setCreatetime(System.currentTimeMillis() + "");
|
vb.setDetailSystem(new DetailSystem(detailSystemId));
|
vb.setInfo(new VideoInfo(videoid));
|
vb.setName(((VideoInfo) session.get(VideoInfo.class, videoid)).getName());
|
vb.setShow(true);
|
session.persist(vb);
|
}
|
session.flush();
|
session.getTransaction().commit();
|
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
return null;
|
}
|
});
|
|
}
|
|
@SuppressWarnings("unchecked")
|
public void deleteBanQuanVideoAdmin(final String videoid, final String detailSystemId) {
|
videoBanQuanDao.excute(new HibernateCallback() {
|
public Object doInHibernate(Session session) throws HibernateException {
|
try {
|
session.getTransaction().begin();
|
List<VideoBanQuanVideo> list = session
|
.createQuery("from VideoBanQuanVideo vb where vb.info.id=? and vb.detailSystem.id=?")
|
.setParameter(0, videoid).setParameter(1, detailSystemId).list();
|
if (list != null && list.size() > 0) {
|
for (VideoBanQuanVideo vb : list)
|
session.delete(vb);
|
}
|
session.flush();
|
session.getTransaction().commit();
|
} catch (Exception e) {
|
e.printStackTrace();
|
session.getTransaction().rollback();
|
}
|
return null;
|
}
|
});
|
|
}
|
|
public boolean isNeedWebPlay(String detailSystemId, String videoid) {
|
return webVideoDao.getCount("select count(*) from WebVideo web where web.detailSystem.id=? and web.info.id=?",
|
new Serializable[]{detailSystemId, videoid}) > 0;
|
}
|
|
}
|