admin
2021-09-24 f788607ff771a47bc60d6a86e00b3433c40f3d2c
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
160
161
162
163
package com.yeshi.buwan.job;
 
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import com.yeshi.buwan.domain.live.TVLiveChannel;
import com.yeshi.buwan.domain.live.TVLiveChannelResourceMap;
import com.yeshi.buwan.domain.live.TVLiveProgramResource;
import com.yeshi.buwan.domain.live.TVLiveResource;
import com.yeshi.buwan.live.migu.MiGuLiveListInfo;
import com.yeshi.buwan.live.migu.MiguLiveApiUtil;
import com.yeshi.buwan.service.inter.live.MiGuLiveService;
import com.yeshi.buwan.service.inter.live.TVLiveChannelResourceService;
import com.yeshi.buwan.service.inter.live.TVLiveChannelService;
import com.yeshi.buwan.service.inter.live.TVLiveProgramResourceService;
import com.yeshi.buwan.service.inter.system.SystemConfigService;
import com.yeshi.buwan.util.StringUtil;
import com.yeshi.buwan.util.factory.live.TVLiveChannelFactory;
import com.yeshi.buwan.util.tvlive.DianShiMaoUtil;
import com.yeshi.buwan.util.tvlive.TVSOUUtil;
import net.sf.json.JSONArray;
import org.springframework.stereotype.Component;
 
import javax.annotation.Resource;
import java.util.List;
 
//10409568
@Component
public class LiveJob {
    @Resource
    private SystemConfigService systemConfigService;
 
    @Resource
    private MiGuLiveService miGuLiveService;
 
    @Resource
    private TVLiveChannelService tvLiveService;
 
    @Resource
    private TVLiveChannelResourceService tvLiveChannelResourceService;
 
    //打开华为应用市场的广告
    @XxlJob("live-update-migu")
    public ReturnT<String> updateMiGu(String params) throws Exception {
        String value = systemConfigService.getConfigValueByKeyCache("miguLiveCategory");
        JSONArray array = JSONArray.fromObject(value);
        for (int i = 0; i < array.size(); i++) {
            String vomsID = array.optJSONObject(i).optString("vomsID");
            List<MiGuLiveListInfo> mList = MiguLiveApiUtil.getLiveList(vomsID);
            for (MiGuLiveListInfo info : mList) {
                miGuLiveService.saveChannelInfo(info);
                TVLiveChannel channel = TVLiveChannelFactory.create(info);
                TVLiveChannel old = tvLiveService.selectByPrimaryKey(channel.getId());
 
                if (old == null) {
                    //添加到频道
                    tvLiveService.save(channel);
                } else {
                    tvLiveService.update(channel);
                }
                TVLiveChannelResourceMap map = new TVLiveChannelResourceMap();
                map.setChannelId(channel.getId());
                map.setId(TVLiveChannelResourceMap.createId(channel.getId(), TVLiveResource.migu, null));
                map.setResource(TVLiveResource.migu);
                map.setRid(info.getId());
                map.setWeight(1);
                tvLiveChannelResourceService.add(map);
            }
        }
 
 
        return ReturnT.SUCCESS;
    }
 
 
    @Resource
    private TVLiveProgramResourceService tvLiveProgramResourceService;
 
    @Resource
    private TVLiveChannelService tvLiveChannelService;
 
    /**
     * 更新节目单
     *
     * @param params
     * @return
     * @throws Exception
     */
    @XxlJob("live-updateprograms")
    public ReturnT<String> updatePrograms(String params) throws Exception {
        updatePrograms_TVSOU(params);
        return ReturnT.SUCCESS;
    }
 
 
    /**
     * 电视猫
     *
     * @param params
     * @throws Exception
     */
    public void updatePrograms_DianshiMao(String params) throws Exception {
        if (StringUtil.isNullOrEmpty(params)) {
            List<TVLiveProgramResource> list = tvLiveProgramResourceService.listByType(TVLiveProgramResource.TVLiveProgramResourceType.dianshimao, 1, 1000);
            int count = 0;
            for (TVLiveProgramResource resource : list) {
                count++;
                List<TVLiveChannel.TVLiveProgram> plist = DianShiMaoUtil.getProgramList(resource.getUrl());
                System.out.println(count);
                Thread.sleep(1000);
                if (plist != null && plist.size() > 0) {
                    tvLiveChannelService.savePrograms(resource.getChannelId(), plist);
                }
            }
        } else {
            //更新单个节目单
            List<TVLiveProgramResource> list = tvLiveProgramResourceService.listByChannelId(params, 1, 10);
            for (TVLiveProgramResource resource : list) {
                if (resource.getType() != TVLiveProgramResource.TVLiveProgramResourceType.dianshimao)
                    continue;
                List<TVLiveChannel.TVLiveProgram> plist = DianShiMaoUtil.getProgramList(resource.getUrl());
                if (plist != null && plist.size() > 0) {
                    tvLiveChannelService.savePrograms(resource.getChannelId(), plist);
                }
            }
        }
    }
 
 
    /**
     * 搜视网
     *
     * @param params
     * @throws Exception
     */
    public void updatePrograms_TVSOU(String params) throws Exception {
        if (StringUtil.isNullOrEmpty(params)) {
            List<TVLiveProgramResource> list = tvLiveProgramResourceService.listByType(TVLiveProgramResource.TVLiveProgramResourceType.tvsou, 1, 1000);
            int count = 0;
            for (TVLiveProgramResource resource : list) {
                count++;
                List<TVLiveChannel.TVLiveProgram> plist = TVSOUUtil.getProgramList(resource.getUrl());
                System.out.println(count);
                Thread.sleep(1000);
                if (plist != null && plist.size() > 0) {
                    tvLiveChannelService.savePrograms(resource.getChannelId(), plist);
                }
            }
        } else {
            //更新单个节目单
            List<TVLiveProgramResource> list = tvLiveProgramResourceService.listByChannelId(params, 1, 10);
            for (TVLiveProgramResource resource : list) {
                if (resource.getType() != TVLiveProgramResource.TVLiveProgramResourceType.tvsou)
                    continue;
                List<TVLiveChannel.TVLiveProgram> plist = TVSOUUtil.getProgramList(resource.getUrl());
                if (plist != null && plist.size() > 0) {
                    tvLiveChannelService.savePrograms(resource.getChannelId(), plist);
                }
            }
        }
    }
 
 
}