admin
2021-03-06 7804263c6061aef813f0db27cb3046f746572606
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
package com.hxh.spring.test;
 
import java.util.List;
 
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;
import com.yeshi.buwan.domain.ResourceVideo;
import com.yeshi.buwan.iqiyi.entity.IqiyiAlbum;
import com.yeshi.buwan.iqiyi.entity.IqiyiVideoInfo;
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
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:spring.xml"})
@WebAppConfiguration
public class ClearVideo {
 
    @Resource
    public ClearService clearService;
 
    @Test
    public void main() {
        // ClearService clearService = BeanUtil.getBean(ClearService.class);
        // for (int i = 0; i < 1000; i++) {
        // clearService.clearDependVideo();
        // }
 
        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");
            }
        }
        // }
    }
 
    /**
     * 清除掉优酷,搜狐,PPTV视频
     */
    public static void clearYouKuAndSouHuAndPPTVVideo(final int p) {
        VideoInfoDao videoInfoDao = BeanUtil.getBean(VideoInfoDao.class);
        videoInfoDao.excute(new HibernateCallback<Object>() {
 
            @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();
 
                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 {
 
                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());
                                    }
                                }
 
                                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();
    }
 
}