From 7804263c6061aef813f0db27cb3046f746572606 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期六, 06 三月 2021 16:07:26 +0800
Subject: [PATCH] 后台管理优化

---
 src/test/java/com/hxh/spring/test/ClearVideo.java |  229 ++++++++++++++++++++++++++++++--------------------------
 1 files changed, 123 insertions(+), 106 deletions(-)

diff --git a/src/test/java/com/hxh/spring/test/ClearVideo.java b/src/test/java/com/hxh/spring/test/ClearVideo.java
index 4c7b8c5..3659c12 100644
--- a/src/test/java/com/hxh/spring/test/ClearVideo.java
+++ b/src/test/java/com/hxh/spring/test/ClearVideo.java
@@ -4,6 +4,8 @@
 
 import org.hibernate.HibernateException;
 import org.hibernate.Session;
+import org.junit.Test;
+import org.junit.runner.RunWith;
 import org.springframework.orm.hibernate4.HibernateCallback;
 
 import com.yeshi.buwan.dao.VideoInfoDao;
@@ -13,130 +15,145 @@
 import com.yeshi.buwan.iqiyi.entity.VideoIqiyi;
 import com.yeshi.buwan.service.imp.ClearService;
 import com.yeshi.buwan.util.BeanUtil;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.web.WebAppConfiguration;
+
+import javax.annotation.Resource;
 
 /**
  * 娓呴櫎鏃堕棿姣旇緝涔呰繙鐨勫皬瑙嗛鏁版嵁
- * 
- * @author Administrator
  *
+ * @author Administrator
  */
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations = {"classpath:spring.xml"})
+@WebAppConfiguration
 public class ClearVideo {
 
-	public static void main(String[] args) {
-		// ClearService clearService = BeanUtil.getBean(ClearService.class);
-		// for (int i = 0; i < 1000; i++) {
-		// clearService.clearDependVideo();
-		// }
-		ClearService clearService = BeanUtil.getBean(ClearService.class);
+    @Resource
+    public ClearService clearService;
 
-		for (int i = 0; i < 300; i++) {
-			long[] typeIds = new long[] { 299,242,216,249,290,219 };
-			for (long id : typeIds) {
-				clearService.clearVideos(new long[] { id }, "2019-01-20");
-			}
-		}
-		// }
-	}
+    @Test
+    public void main() {
+        // ClearService clearService = BeanUtil.getBean(ClearService.class);
+        // for (int i = 0; i < 1000; i++) {
+        // clearService.clearDependVideo();
+        // }
 
-	/**
-	 * 娓呴櫎鎺変紭閰凤紝鎼滅嫄锛孭PTV瑙嗛
-	 */
-	public static void clearYouKuAndSouHuAndPPTVVideo(final int p) {
-		VideoInfoDao videoInfoDao = BeanUtil.getBean(VideoInfoDao.class);
-		videoInfoDao.excute(new HibernateCallback<Object>() {
+        for (int i = 0; i < 300; i++) {
+            long[] typeIds = new long[]{299, 242, 216, 249, 290, 219};
+            for (long id : typeIds) {
+                clearService.clearVideos(new long[]{id}, "2021-02-01");
+            }
+        }
+        // }
+    }
 
-			@Override
-			public Object doInHibernate(Session session) throws HibernateException {
-				List videoIdList = session
-						.createSQLQuery(
-								"SELECT  DISTINCT(rv.`videoid`) FROM `wk_resource_video` rv WHERE rv.`resourceid`=15 OR rv.`resourceid`=16 OR rv.`resourceid`= 20 OR rv.`resourceid`=14")
-						.setFirstResult((p - 1) * 20000).setMaxResults(20000).list();
+    /**
+     * 娓呴櫎鎺変紭閰凤紝鎼滅嫄锛孭PTV瑙嗛
+     */
+    public static void clearYouKuAndSouHuAndPPTVVideo(final int p) {
+        VideoInfoDao videoInfoDao = BeanUtil.getBean(VideoInfoDao.class);
+        videoInfoDao.excute(new HibernateCallback<Object>() {
 
-				for (int i = 0; i < videoIdList.size(); i++) {
-					session.getTransaction().begin();
-					String videoId = videoIdList.get(i).toString();
-					List<ResourceVideo> resourceVideoList = session
-							.createQuery("from ResourceVideo rv where rv.video.id=" + videoId).list();
-					for (int n = 0; n < resourceVideoList.size(); n++) {
-						long resourceId = Long.parseLong(resourceVideoList.get(n).getResource().getId());
-						if (resourceId == 14L || resourceId == 15L || resourceId == 16L || resourceId == 20L) {
-							session.createSQLQuery(
-									"delete from wk_resource_video where id=" + resourceVideoList.get(n).getId())
-									.executeUpdate();
-							resourceVideoList.remove(n);
-							n--;
-						}
-					}
-					if (resourceVideoList != null && resourceVideoList.size() <= 0) {
-						session.createSQLQuery("delete from wk_video_video where id=" + videoId).executeUpdate();
-					}
-					session.flush();
-					session.getTransaction().commit();
-				}
+            @Override
+            public Object doInHibernate(Session session) throws HibernateException {
+                List videoIdList = session
+                        .createSQLQuery(
+                                "SELECT  DISTINCT(rv.`videoid`) FROM `wk_resource_video` rv WHERE rv.`resourceid`=15 OR rv.`resourceid`=16 OR rv.`resourceid`= 20 OR rv.`resourceid`=14")
+                        .setFirstResult((p - 1) * 20000).setMaxResults(20000).list();
 
-				return null;
-			}
-		});
+                for (int i = 0; i < videoIdList.size(); i++) {
+                    session.getTransaction().begin();
+                    String videoId = videoIdList.get(i).toString();
+                    List<ResourceVideo> resourceVideoList = session
+                            .createQuery("from ResourceVideo rv where rv.video.id=" + videoId).list();
+                    for (int n = 0; n < resourceVideoList.size(); n++) {
+                        long resourceId = Long.parseLong(resourceVideoList.get(n).getResource().getId());
+                        if (resourceId == 14L || resourceId == 15L || resourceId == 16L || resourceId == 20L) {
+                            session.createSQLQuery(
+                                    "delete from wk_resource_video where id=" + resourceVideoList.get(n).getId())
+                                    .executeUpdate();
+                            resourceVideoList.remove(n);
+                            n--;
+                        }
+                    }
+                    if (resourceVideoList != null && resourceVideoList.size() <= 0) {
+                        session.createSQLQuery("delete from wk_video_video where id=" + videoId).executeUpdate();
+                    }
+                    session.flush();
+                    session.getTransaction().commit();
+                }
 
-	}
+                return null;
+            }
+        });
 
-	/**
-	 * 娓呴櫎鐖卞鑹轰腑涓嶈兘鎾斁鐨勫唴瀹�
-	 */
-	public static void clearCantPlayIqiyiVideo() {
-		VideoInfoDao videoInfoDao = BeanUtil.getBean(VideoInfoDao.class);
-		videoInfoDao.excute(new HibernateCallback<Object>() {
+    }
 
-			@SuppressWarnings("unchecked")
-			@Override
-			public Object doInHibernate(Session session) throws HibernateException {
+    /**
+     * 娓呴櫎鐖卞鑹轰腑涓嶈兘鎾斁鐨勫唴瀹�
+     */
+    public static void clearCantPlayIqiyiVideo() {
+        VideoInfoDao videoInfoDao = BeanUtil.getBean(VideoInfoDao.class);
+        videoInfoDao.excute(new HibernateCallback<Object>() {
 
-				List<IqiyiVideoInfo> list = session
-						.createSQLQuery(
-								"SELECT tv.* FROM `wk_iqiyi_album_tvid` tv   WHERE tv.`playcontrols` NOT LIKE '%15%'")
-						.addEntity(IqiyiVideoInfo.class).setMaxResults(1000).list();
-				for (IqiyiVideoInfo iqiyiVideoInfo : list) {
-					try {
-						session.getTransaction().begin();
-						session.createSQLQuery("delete from wk_iqiyi_album_tvid where id=" + iqiyiVideoInfo.getId())
-								.executeUpdate();
-						List<IqiyiAlbum> iaList = session
-								.createQuery("from IqiyiAlbum ia where ia.albumId=" + iqiyiVideoInfo.getAlbumId())
-								.list();
-						if (iaList != null)
-							for (IqiyiAlbum ia : iaList) {
-								List<VideoIqiyi> vlist = session
-										.createQuery("from VideoIqiyi vi where vi.album.id=" + ia.getId()).list();
-								for (VideoIqiyi vi : vlist) {
-									session.createSQLQuery("delete from wk_video_iqiyi where id=" + vi.getId())
-											.executeUpdate();
-									List<ResourceVideo> rvList = session
-											.createQuery(
-													"from ResourceVideo rv where rv.video.id=" + vi.getVideo().getId())
-											.list();
-									for (ResourceVideo rv : rvList) {
-										session.delete(rv);
-									}
-									if (rvList != null && rvList.size() <= 1
-											&& rvList.get(0).getResource().getId().equalsIgnoreCase("13")) {
-										session.delete(rvList.get(0).getVideo());
-									}
-								}
+            @SuppressWarnings("unchecked")
+            @Override
+            public Object doInHibernate(Session session) throws HibernateException {
 
-								session.createSQLQuery("delete from wk_iqiyi_album where id=" + ia.getId())
-										.executeUpdate();
-							}
-						session.flush();
-						session.getTransaction().commit();
-					} catch (Exception e) {
-						e.printStackTrace();
-					}
-				}
+                List<IqiyiVideoInfo> list = session
+                        .createSQLQuery(
+                                "SELECT tv.* FROM `wk_iqiyi_album_tvid` tv   WHERE tv.`playcontrols` NOT LIKE '%15%'")
+                        .addEntity(IqiyiVideoInfo.class).setMaxResults(1000).list();
+                for (IqiyiVideoInfo iqiyiVideoInfo : list) {
+                    try {
+                        session.getTransaction().begin();
+                        session.createSQLQuery("delete from wk_iqiyi_album_tvid where id=" + iqiyiVideoInfo.getId())
+                                .executeUpdate();
+                        List<IqiyiAlbum> iaList = session
+                                .createQuery("from IqiyiAlbum ia where ia.albumId=" + iqiyiVideoInfo.getAlbumId())
+                                .list();
+                        if (iaList != null)
+                            for (IqiyiAlbum ia : iaList) {
+                                List<VideoIqiyi> vlist = session
+                                        .createQuery("from VideoIqiyi vi where vi.album.id=" + ia.getId()).list();
+                                for (VideoIqiyi vi : vlist) {
+                                    session.createSQLQuery("delete from wk_video_iqiyi where id=" + vi.getId())
+                                            .executeUpdate();
+                                    List<ResourceVideo> rvList = session
+                                            .createQuery(
+                                                    "from ResourceVideo rv where rv.video.id=" + vi.getVideo().getId())
+                                            .list();
+                                    for (ResourceVideo rv : rvList) {
+                                        session.delete(rv);
+                                    }
+                                    if (rvList != null && rvList.size() <= 1
+                                            && rvList.get(0).getResource().getId().equalsIgnoreCase("13")) {
+                                        session.delete(rvList.get(0).getVideo());
+                                    }
+                                }
 
-				return null;
-			}
-		});
+                                session.createSQLQuery("delete from wk_iqiyi_album where id=" + ia.getId())
+                                        .executeUpdate();
+                            }
+                        session.flush();
+                        session.getTransaction().commit();
+                    } catch (Exception e) {
+                        e.printStackTrace();
+                    }
+                }
 
-	}
+                return null;
+            }
+        });
+
+    }
+
+    @Test
+    public void clearDepend(){
+        clearService.clearDependVideo();
+    }
 
 }

--
Gitblit v1.8.0