admin
2021-03-01 d73687bc6115007145b4aab050e4e29ff87fd8ae
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   StarService.java
 
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.service.inter.VideoResourceMapExtraInfoService;
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.HotStarDao;
import com.yeshi.buwan.dao.SuperHotStarDao;
import com.yeshi.buwan.dao.VideoInfoDao;
import com.yeshi.buwan.domain.DetailSystem;
import com.yeshi.buwan.domain.HotStar;
import com.yeshi.buwan.domain.SuperHotStar;
import com.yeshi.buwan.domain.VideoInfo;
import com.yeshi.buwan.domain.web.DetailSystemSelect;
import com.yeshi.buwan.domain.web.HotStarAdmin;
import com.yeshi.buwan.util.Constant;
import com.yeshi.buwan.util.SolrUtil;
import com.yeshi.buwan.util.StringUtil;
 
@Service
public class StarService {
    @Resource
    private HotStarDao hotStarDao;
    @Resource
    private VideoInfoDao videoInfoDao;
    @Resource
    private SuperHotStarDao superHotStarDao;
 
    @Resource
    private DetailSystemDao detailSystemDao;
 
    @Resource
    private VideoResourceMapExtraInfoService videoResourceMapExtraInfoService;
 
    public StarService() {
 
    }
 
    @Cacheable(value = "classCache", key = "'getHotStarList'+'-'+#page+'-'+#pageCount")
    public List<HotStar> getHotStarList(int page, int pageCount) {
 
        List<HotStar> list = hotStarDao.list("from HotStar h order by h.orderby desc,h.createtime desc",
                (page - 1) * pageCount, pageCount, new String[]{});
        return list;
    }
 
    public List<HotStar> getHotStarList(String detailSystem, int page) {
        List<HotStar> list = hotStarDao.list(
                "select h.hotStar from SuperHotStar h where h.detailSystem.id=? order by h.hotStar.orderby desc,h.hotStar.createtime desc",
                (page - 1) * Constant.pageCount, Constant.pageCount, new String[]{detailSystem});
        return list;
    }
 
    @Cacheable(value = "classCache", key = "'getHotStarDetail'+'-'+#id")
    public HotStar getHotStarDetail(String id) {
 
        return hotStarDao.find(HotStar.class, id);
    }
 
    public long getHotStarCount() {
 
        return hotStarDao.getCount("select count(*)  from HotStar");
    }
 
    public long getHotStarCount(String detailSystem) {
 
        return hotStarDao.getCount("select count(*)  from SuperHotStar s where s.detailSystem.id=?",
                new String[]{detailSystem});
    }
 
    public List<VideoInfo> getHotStarVideo(String starId, int page) {
 
        List<VideoInfo> list = videoInfoDao.list(
                "select h.video from HotStarVideo as h LEFT JOIN h.video as v where h.video.show='1' and v.id=h.video.id and h.star.id=? order by h.video.updatetime desc",
                (page - 1) * Constant.pageCount, Constant.pageCount, new String[]{starId});
        return list;
    }
 
    public long getHotStarVideoCount(String starId) {
 
        long count = hotStarDao.getCount(
                "select count(*)  from HotStarVideo as h where h.video.show='1' and h.star.id=?",
                new String[]{starId});
        return count;
    }
 
    public List<HotStar> getStarList() {
        return hotStarDao.list("from HotStar h order by h.orderby DESC");
    }
 
    public HotStar getStar(String id) {
        if (!StringUtil.isNullOrEmpty(id)) {
            return (HotStar) hotStarDao.find(HotStar.class, id);
        } else {
            return null;
        }
    }
 
    public HotStar addStar(HotStar star) {
        if (star != null) {
            hotStarDao.save(star);
            List<HotStar> list = hotStarDao.list("from HotStar h where h.createtime=? and h.name=?",
                    new String[]{star.getCreatetime(), star.getName()});
            if (list != null && list.size() > 0)
                return (HotStar) list.get(0);
        }
        return null;
    }
 
    public HotStar updateStar(HotStar star) {
        if (star != null) {
            hotStarDao.update(star);
            List<HotStar> list = hotStarDao.list("from HotStar h where h.createtime=? and h.name=?",
                    new String[]{star.getCreatetime(), star.getName()});
            if (list != null && list.size() > 0)
                return (HotStar) list.get(0);
        }
        return null;
    }
 
    public void deleteStar(final HotStar star) {
        if (star != null) {
            hotStarDao.excute(new HibernateCallback() {
                public Object doInHibernate(Session session) throws HibernateException {
                    try {
                        @SuppressWarnings("unchecked")
                        List<SuperHotStar> list = session.createQuery("from SuperHotStar sh where sh.hotStar.id=?")
                                .setParameter(0, star.getId()).list();
                        session.getTransaction().begin();
                        for (SuperHotStar sh : list) {
                            session.delete(sh);
                        }
                        session.createQuery("delete from HotStar hs where hs.id=?").setParameter(0, star.getId())
                                .executeUpdate();
                        session.flush();
                        session.getTransaction().commit();
                    } catch (Exception e) {
                        e.printStackTrace();
                        session.getTransaction().rollback();
                    }
                    return null;
                }
            });
 
        }
    }
 
    @SuppressWarnings("unchecked")
    @Cacheable(value = "classCache", key = "'getStarVideo'+'-'+#detailSystemId+'-'+#starId+'-'+#pageIndex+'-'+#cachemd5")
    public List<VideoInfo> getStarVideo(String detailSystemId, String starId, int pageIndex, List<Long> resourceList,
                                        String cachemd5) {
        String resourceWhere = "";
        for (Long rid : resourceList)
            resourceWhere += String.format(" rv.`resourceid`=%d  or", rid);
        if (resourceWhere.endsWith("or"))
            resourceWhere = resourceWhere.substring(0, resourceWhere.length() - 2);
 
        List<VideoInfo> list = null;
        Session session = hotStarDao.getSession();
        try {
            HotStar star = (HotStar) session.get(HotStar.class, starId);
            String sql = String.format(
                    "SELECT v.* FROM wk_video_video v  LEFT JOIN wk_resource_video rv ON rv.`videoid`=v.`id` AND (%s) WHERE v.`contenttype`=1 AND v.`show`=1 AND v.`mainactor`  LIKE '%s'  AND rv.`videoid` IS NOT NULL and v.area is not null and v.area !='' GROUP BY v.`id` ORDER BY FROM_UNIXTIME(v.`updatetime`/1000) DESC",
                    resourceWhere, "%" + star.getName() + "%");
            list = session.createSQLQuery(sql).addEntity(VideoInfo.class)
                    .setFirstResult((pageIndex - 1) * Constant.pageCount).setMaxResults(Constant.pageCount).list();
        } catch (Exception e) {
            e.printStackTrace();
        }
 
        list = videoResourceMapExtraInfoService.batchExtraInfo(list, resourceList);
        return list;
    }
 
    @Cacheable(value = "classCache", key = "'getStarVideo'+'-'+#detailSystemId+'-'+#starId+'-'+#pageIndex+'-'+#cachemd5")
    public List<VideoInfo> getStarVideo(String detailSystemId, String starId, int pageIndex, String cachemd5) {
        HotStar star = hotStarDao.find(HotStar.class, starId);
        return SolrUtil.searchStarVideos(star.getName(), pageIndex);
    }
 
    @Cacheable(value = "classCache", key = "'getStarVideoCount'+'-'+#detailSystemId+'-'+#starId")
    public long getStarVideoCount(String detailSystemId, String starId) {
        long count = 0;
        try {
            HotStar star = (HotStar) hotStarDao.find(HotStar.class, starId);
            count = hotStarDao.getCount(
                    "select count(*) from CategoryVideo cv where cv.video.mainActor like ? and cv.video.contentType=1 and cv.video.area is not null and cv.video.area!=''",
                    new Serializable[]{"%" + star.getName() + "%"});
 
        } catch (Exception e) {
            e.printStackTrace();
        }
        return count;
    }
 
    public long getStarVideoPage(String detailSystemId, String starId) {
        long count = getStarVideoCount(detailSystemId, starId);
        return count % (long) Constant.pageCount != 0L ? count / (long) Constant.pageCount + 1L
                : count / (long) Constant.pageCount;
    }
 
    @SuppressWarnings("unchecked")
    public List<HotStarAdmin> getHotStarAdmin(String key, String systemId, int detailSystem, int page) {
        key = StringUtil.isNullOrEmpty(key) ? "" : key;
        List<HotStarAdmin> zhiBoClassList = new ArrayList<>();
 
        try {
            List<DetailSystem> detailSystemList = detailSystemDao.list("from DetailSystem ds where ds.system.id=" + systemId);
            String sql = "";
            if (detailSystem > 0)
                sql = "select sh.hotStar from SuperHotStar sh where  sh.detailSystem.id=" + detailSystem
                        + " and sh.hotStar.name like ?  order by  sh.hotStar.orderby desc";
            else
                sql = "from HotStar zb where zb.name like ? and zb.system.id=" + systemId + " order by zb.orderby desc";
 
            List<HotStar> list = hotStarDao.list(sql, (page - 1) * Constant.pageCount, Constant.pageCount,
                    new Serializable[]{"%" + key + "%"});
            for (HotStar vb : list) {
                List<DetailSystem> detailSystemS = detailSystemDao
                        .list("select vb.detailSystem from SuperHotStar vb where vb.hotStar.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;
                        }
                    }
                }
                SuperHotStar sz = new SuperHotStar();
                sz.setDetailSystem(null);
                sz.setHotStar(vb);
                zhiBoClassList.add(new HotStarAdmin(sz, dssList));
            }
 
        } catch (Exception e) {
            e.printStackTrace();
        }
        return zhiBoClassList;
    }
 
    public long getHotStarAdminCount(String key, String systemId, int detailSystem) {
        key = StringUtil.isNullOrEmpty(key) ? "" : key;
 
        String sql = "";
        if (detailSystem > 0)
            sql = "select count(*) from  (select count(*) from wk_video_super_hotstar zb left join wk_video_hotstar c on c.id=zb.hotstarid where zb.detailsystemid="
                    + detailSystem + " and c.name like '%" + key + "%' group by zb.hotstarid) s";
        else
            sql = "select count(*) from  (select count(*) from wk_video_hotstar zb left join wk_video_hotstar c on c.id=zb.id where c.name like '%"
                    + key + "%' and zb.system=" + systemId + "  group by zb.id) s";
 
        return hotStarDao.getCountSQL(sql);
    }
 
    @SuppressWarnings("unchecked")
    public void deleteHotStarAdmin(final String classId, final String detailSystemId) {
        hotStarDao.excute(new HibernateCallback() {
            public Object doInHibernate(Session session) throws HibernateException {
                try {
 
                    List<SuperHotStar> list = session
                            .createQuery("from SuperHotStar vb where vb.hotStar.id=? and vb.detailSystem.id=?")
                            .setParameter(0, classId).setParameter(1, detailSystemId).list();
                    if (list != null && list.size() > 0) {
                        session.getTransaction().begin();
                        for (SuperHotStar vb : list)
                            session.delete(vb);
                        session.flush();
                        session.getTransaction().commit();
                    }
 
                } catch (Exception e) {
                    e.printStackTrace();
                }
                return null;
            }
        });
 
    }
 
    /**
     * 明星
     */
 
    public List<HotStar> getHotStarList(String detailSystem) {
 
        return hotStarDao.list("select hs.hotStar FROM SuperHotStar hs where hs.detailSystem.id=" + detailSystem
                + " order by hs.hotStar.orderby desc");
    }
 
    public List<SuperHotStar> getSuperHotStarList(String detailSystem) {
        return superHotStarDao.list(
                "FROM SuperHotStar hs where hs.detailSystem.id=" + detailSystem + " order by hs.hotStar.orderby desc");
    }
 
    public void addSuperHotStar(SuperHotStar sv) {
        List<SuperHotStar> list = superHotStarDao.list("from SuperHotStar sv where sv.hotStar.id="
                + sv.getHotStar().getId() + " and sv.detailSystem.id=" + sv.getDetailSystem().getId());
        if (list != null && list.size() > 0)
            return;
        superHotStarDao.create(sv);
    }
 
    public void updateSuperHotStar(SuperHotStar hotSearch) {
        superHotStarDao.update(hotSearch);
    }
 
    public void deleteSuperHotStar(SuperHotStar hotSearch) {
        superHotStarDao.delete(hotSearch);
    }
 
    @SuppressWarnings("unchecked")
    public void updateSuperHotStarList(final String detailSystemId, final List<SuperHotStar> typeList) {
        hotStarDao.excute(new HibernateCallback() {
            public Object doInHibernate(Session session) throws HibernateException {
                try {
                    List<SuperHotStar> list = session
                            .createQuery("from SuperHotStar sh where sh.detailSystem.id=" + detailSystemId).list();
                    session.getTransaction().begin();
                    for (SuperHotStar ad : list) {
                        session.delete(ad);
                    }
 
                    for (SuperHotStar videoType : typeList) {
                        session.persist(videoType);
                    }
                    session.flush();
                    session.getTransaction().commit();
                } catch (Exception e) {
                    e.printStackTrace();
                    session.getTransaction().rollback();
                }
                return null;
            }
        });
 
    }
 
    @Cacheable(value = "foundCache", key = "'getHotStarOnMain'+'-'+#detailSystemId")
    public List<HotStar> getHotStarOnMain(String detailSystemId) {
        return hotStarDao.list("select hs.hotStar FROM SuperHotStar hs where hs.detailSystem.id=" + detailSystemId
                + " order by hs.hotStar.orderby desc", 0, 3, null);
    }
 
}