admin
2021-04-14 759f8df85ddb840682f91bad31e874fa0b58c075
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
package com.yeshi.buwan.service.imp;
 
import com.yeshi.buwan.dao.system.DetailSystemDao;
import com.yeshi.buwan.dao.system.SystemInfoDao;
import com.yeshi.buwan.domain.*;
import com.yeshi.buwan.domain.special.Special;
import com.yeshi.buwan.domain.special.SuperSpecial;
import com.yeshi.buwan.domain.system.DetailSystem;
import com.yeshi.buwan.domain.system.SystemInfo;
import com.yeshi.buwan.util.Constant;
import org.apache.log4j.Logger;
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 javax.annotation.Resource;
import java.util.List;
 
/**
 * 系统分类服务
 *
 * @author Administrator
 */
@Service
public class SystemService {
    Logger log = Logger.getLogger(SystemService.class);
 
    @Resource
    private DetailSystemDao detailSystemDao;
    @Resource
    private SystemInfoDao systemInfoDao;
    @Resource
    private ClassService classService;
    @Resource
    private StarService starService;
    @Resource
    private SpecialService specialService;
 
    public List<DetailSystem> getDetailSystemList(String systemId) {
        List<DetailSystem> list = detailSystemDao.list("from DetailSystem ds where ds.system.id=?", systemId);
        return list;
    }
 
    public List<DetailSystem> getDetailSystemList(String key, String systemId, int pageIndex) {
        List<DetailSystem> list = detailSystemDao.list(
                "from DetailSystem ds where ds.appName like ? and ds.system.id=? order by ds.createtime desc",
                (pageIndex - 1) * Constant.pageCount, Constant.pageCount, new String[]{"%" + key + "%", systemId});
        return list;
    }
 
    public long getDetailSystemListCount(String key, String systemId) {
        return detailSystemDao.getCount("select count(*)  from DetailSystem d where d.appName like ? and d.system.id=?",
                new String[]{"%" + key + "%", systemId});
    }
 
    @Cacheable(value = "homeCache", key = "'getDetailSystemByPackage'+'-'+#packageName")
    public DetailSystem getDetailSystemByPackage(String packageName) {
        long startTime = System.currentTimeMillis();
        log.info("getDetailSystemByPackage开始请求");
        List<DetailSystem> list = detailSystemDao.list("from DetailSystem d where d.packageName=?",
                new String[]{packageName});
        log.info("getDetailSystemByPackage请求完成:" + (System.currentTimeMillis() - startTime));
        if (list != null && list.size() > 0)
            return list.get(0);
        else
            return null;
    }
 
    public DetailSystem getDetailSystemById(String id) {
        return detailSystemDao.find(DetailSystem.class, id);
    }
 
    public void updateDetailSystem(DetailSystem system) {
        detailSystemDao.update(system);
    }
 
    public boolean addDetailSystem(DetailSystem system) {
 
        List<DetailSystem> list = detailSystemDao.list(
                "from DetailSystem ds where ds.system.id=" + system.getSystem().getId()
                        + " and ds.packageName=? and ds.platform=" + system.getPlatform(),
                new String[]{system.getPackageName()});
        if (list == null || list.size() == 0) {
            detailSystemDao.create(system);
            return true;
        } else
            return false;
    }
 
    public List<SystemInfo> getSystemList() {
        return systemInfoDao.list("from SystemInfo");
    }
 
 
    /**
     * 获取系统
     *
     * @param id
     * @return
     */
    public SystemInfo getSystem(String id) {
        return systemInfoDao.find(SystemInfo.class, id);
    }
 
    @SuppressWarnings("unchecked")
    public void deleteDetailSystem(final String dsId) {
        detailSystemDao.excute(new HibernateCallback() {
            public Object doInHibernate(Session session) throws HibernateException {
                try {
                    session.getTransaction().begin();
 
                    List<SuperHomeAd> shlist = session.createQuery("from SuperHomeAd sz where sz.detailSystem.id=?")
                            .setParameter(0, dsId).list();
                    for (SuperHomeAd sz : shlist)
                        session.delete(sz);
 
                    List<SuperHomeNotice> shnlist = session
                            .createQuery("from SuperHomeNotice sz where sz.detailSystem.id=?").setParameter(0, dsId)
                            .list();
                    for (SuperHomeNotice sz : shnlist)
                        session.delete(sz);
 
                    List<SuperHomeType> shtlist = session
                            .createQuery("from SuperHomeType sz where sz.detailSystem.id=?").setParameter(0, dsId)
                            .list();
                    for (SuperHomeType sz : shtlist)
                        session.delete(sz);
 
                    List<SuperHotSearch> shslist = session
                            .createQuery("from SuperHotSearch sz where sz.detailSystem.id=?").setParameter(0, dsId)
                            .list();
                    for (SuperHotSearch sz : shslist)
                        session.delete(sz);
 
                    List<SuperHotType> shotlist = session.createQuery("from SuperHotType sz where sz.detailSystem.id=?")
                            .setParameter(0, dsId).list();
                    for (SuperHotType sz : shotlist)
                        session.delete(sz);
 
                    List<SuperRecommendAd> sralist = session
                            .createQuery("from SuperRecommendAd sz where sz.detailSystem.id=?").setParameter(0, dsId)
                            .list();
                    for (SuperRecommendAd sz : sralist)
                        session.delete(sz);
 
                    List<SuperUserBanner> sublist = session
                            .createQuery("from SuperUserBanner sz where sz.detailSystem.id=?").setParameter(0, dsId)
                            .list();
                    for (SuperUserBanner sz : sublist)
                        session.delete(sz);
 
                    List<SuperVideoType> svtlist = session
                            .createQuery("from SuperVideoType sz where sz.detailSystem.id=?").setParameter(0, dsId)
                            .list();
                    for (SuperVideoType sz : svtlist)
                        session.delete(sz);
 
                    List<VideoBanQuan> vbqlist = session.createQuery("from VideoBanQuan sz where sz.detailSystem.id=?")
                            .setParameter(0, dsId).list();
                    for (VideoBanQuan sz : vbqlist)
                        session.delete(sz);
 
                    List<VideoBanQuanVideo> vbvlist = session
                            .createQuery("from VideoBanQuanVideo sz where sz.detailSystem.id=?").setParameter(0, dsId)
                            .list();
                    for (VideoBanQuanVideo sz : vbvlist)
                        session.delete(sz);
 
                    List<ShareContent> sclist = session.createQuery("from ShareContent sz where sz.detailSystem.id=?")
                            .setParameter(0, dsId).list();
                    for (ShareContent sz : sclist)
                        session.delete(sz);
 
                    session.delete(new DetailSystem(dsId));
                    session.flush();
                    session.getTransaction().commit();
                } catch (Exception e) {
                    e.printStackTrace();
                    session.getTransaction().rollback();
                }
                return null;
            }
        });
 
    }
 
    HomeAdService homeAdService;
    HomeTypeService homeTypeService;
    HotVideoTypeService hotVideoTypeService;
    SearchService searchService;
    UserBannerService userBannerService;
 
    public void detailSystemClone(String fromid, String toId) {
        // 首页Banner
        List<HomeAd> homeAdlist = homeAdService.getHomeAdList(new DetailSystem(fromid),"recommend");
        for (HomeAd ad : homeAdlist) {
            SuperHomeAd sa = new SuperHomeAd();
            sa.setCreatetime(System.currentTimeMillis() + "");
            sa.setDetailSystem(new DetailSystem(toId));
            sa.setHomeAd(ad);
            homeAdService.addSuperHomeAd(sa);
        }
        // 首页栏目
 
        List<HomeType> homeTypelist = homeTypeService.getHomeType(fromid);
        for (HomeType ht : homeTypelist) {
            SuperHomeType sa = new SuperHomeType();
            sa.setCreatetime(System.currentTimeMillis() + "");
            sa.setDetailSystem(new DetailSystem(toId));
            sa.setHomeType(ht);
            homeTypeService.addSuperHomeType(sa);
        }
 
        // 视频大分类
        List<SuperVideoType> videoTypeList = classService.getSuperVideoTypeList(fromid);
        for (SuperVideoType ht : videoTypeList) {
            SuperVideoType sa = new SuperVideoType();
            sa.setCreatetime(System.currentTimeMillis() + "");
            sa.setDetailSystem(new DetailSystem(toId));
            sa.setType(new VideoType(ht.getType().getId()));
            classService.addSuperVideoType(sa);
        }
 
        // 热门分类
        List<HotVideoType> hotVideoTypeList = hotVideoTypeService.getSuperHotTypeList(fromid);
        for (HotVideoType ht : hotVideoTypeList) {
            SuperHotType sa = new SuperHotType();
            sa.setCreatetime(System.currentTimeMillis() + "");
            sa.setDetailSystem(new DetailSystem(toId));
            sa.setHotType(ht);
            hotVideoTypeService.addSuperHotType(sa);
        }
 
        // 专题
 
        List<Special> specialList = specialService.getSpecialList(fromid);
        for (Special special : specialList) {
            SuperSpecial sa = new SuperSpecial();
            sa.setDetailSystem(new DetailSystem(toId));
            sa.setSpecial(new Special(special.getId()));
            specialService.addSuperSpecial(sa);
        }
 
        // 明星
        List<HotStar> hotStarList = starService.getHotStarList(fromid);
        for (HotStar hs : hotStarList) {
            SuperHotStar sa = new SuperHotStar();
            sa.setDetailSystem(new DetailSystem(toId));
            sa.setHotStar(new HotStar(hs.getId()));
            sa.setCreatetime(System.currentTimeMillis() + "");
            starService.addSuperHotStar(sa);
        }
        // 热门搜索
 
        List<HotSearch> hotSearchList = searchService.getHotSearchListByDS(fromid);
        for (HotSearch hs : hotSearchList) {
            SuperHotSearch sa = new SuperHotSearch();
            sa.setDetailSystem(new DetailSystem(toId));
            sa.setHotSearch(new HotSearch(hs.getId()));
            sa.setCreatetime(System.currentTimeMillis() + "");
            searchService.addSuperHotSearch(sa);
        }
 
        // 用户Banner
        List<UserBanner> userBannerList = userBannerService.getUserBannerList(fromid);
        for (UserBanner ub : userBannerList) {
            SuperUserBanner sa = new SuperUserBanner();
            sa.setDetailSystem(new DetailSystem(toId));
            sa.setUserBanner(new UserBanner(ub.getId()));
            sa.setCreatetime(System.currentTimeMillis() + "");
            userBannerService.addSuperUserBanner(sa);
        }
 
        // 直播
    }
}