From f7b2baec57a19039ca85880bbba4e17fe27f0511 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期三, 10 三月 2021 18:21:13 +0800 Subject: [PATCH] 删除冗余代码,初步优化首页的推荐专题,3.8.7之后在我的里面添加VIP分类 --- src/main/java/com/yeshi/buwan/service/imp/HomeTypeService.java | 57 ++++++++++++++++++++++++++++++--------------------------- 1 files changed, 30 insertions(+), 27 deletions(-) diff --git a/src/main/java/com/yeshi/buwan/service/imp/HomeTypeService.java b/src/main/java/com/yeshi/buwan/service/imp/HomeTypeService.java index 0e6d786..e38f297 100644 --- a/src/main/java/com/yeshi/buwan/service/imp/HomeTypeService.java +++ b/src/main/java/com/yeshi/buwan/service/imp/HomeTypeService.java @@ -6,8 +6,10 @@ import javax.annotation.Resource; import com.yeshi.buwan.dao.*; +import com.yeshi.buwan.dao.system.DetailSystemDao; import com.yeshi.buwan.domain.*; -import com.yeshi.buwan.service.inter.VideoResourceMapExtraInfoService; +import com.yeshi.buwan.domain.system.DetailSystem; +import com.yeshi.buwan.service.inter.video.VideoInfoExtraService; import org.hibernate.HibernateException; import org.hibernate.Session; import org.springframework.cache.annotation.Cacheable; @@ -33,12 +35,17 @@ private DetailSystemDao detailSystemDao; @Resource - private VideoResourceMapExtraInfoService videoResourceMapExtraInfoService; + private VideoInfoExtraService videoInfoExtraService; - public List<HomeType> getHomeType() { + public List<HomeType> getHomeTypeDetailList() { List<HomeType> list = homeTypeDao.list("from HomeType h order by h.orderby desc"); return getHomeType(list); + } + + public List<HomeType> getHomeTypeList(String systemId) { + List<HomeType> list = homeTypeDao.list("from HomeType h where h.system.id=? order by h.orderby desc", systemId); + return list; } @SuppressWarnings("unchecked") @@ -92,7 +99,7 @@ video.setHpicture(obj[16] + ""); video.setLatestHpicture(obj[17] + ""); video.setWatchCount(obj[18] + ""); - video.setCommentCount(Integer.parseInt(obj[19] + "")); + video.setCommentCount(obj[19] != null ? Integer.parseInt(obj[19] + "") : 0); ht.setIcon(obj[20] + ""); hv.setVideo(video); @@ -101,10 +108,15 @@ // hv.getVideo().getName()); // 鏇存敼鍥剧墖鏄剧ず - if (!StringUtil.isNullOrEmpty(hv.getVideo().getLatestHpicture())) - hv.getVideo().setPicture(hv.getVideo().getLatestHpicture()); - else - hv.getVideo().setPicture(hv.getVideo().getHpicture()); + //濡傛灉涓虹珫鐗� + if (ht.getColumns() == 2) { + if (!StringUtil.isNullOrEmpty(hv.getVideo().getLatestHpicture())) + hv.getVideo().setPicture(hv.getVideo().getLatestHpicture()); + else + hv.getVideo().setPicture(hv.getVideo().getHpicture()); + } else { +// hv.getVideo().setPicture(hv.getVideo().getVpicture()); + } if (StringUtil.isNullOrEmpty(hv.getPicture())) hv.setPicture(hv.getVideo().getPicture()); @@ -150,25 +162,16 @@ } }); - List<String> videoIdList = new ArrayList<>(); + List<VideoInfo> videoInfoList = new ArrayList<>(); for (HomeType ht : homeTypeList) { if (ht.getHomeVideoList() != null) for (HomeVideo hv : ht.getHomeVideoList()) { if (hv.getVideo() != null) - videoIdList.add(hv.getVideo().getId()); + videoInfoList.add(hv.getVideo()); } } - Map<String, VideoResourceMapExtraInfo> videoMap = videoResourceMapExtraInfoService.listMap(videoIdList, resourceIds); - for (HomeType ht : homeTypeList) { - if (ht.getHomeVideoList() != null) - for (HomeVideo hv : ht.getHomeVideoList()) { - if (hv.getVideo() != null) - hv.getVideo().setVideoResourceMapExtraInfo(videoMap.get(hv.getVideo().getId())); - } - } - - + videoInfoExtraService.batchExtra(videoInfoList, resourceIds); return homeTypeList; } @@ -228,7 +231,7 @@ for (HomeVideo sp : homeVideoList) session.delete(sp); - session.delete(new HomeType(id)); + session.delete(session.get(HomeType.class, id)); session.flush(); session.getTransaction().commit(); } catch (Exception e) { @@ -338,7 +341,7 @@ for (int i = 0; i < list.size(); i++) { List<HomeVideo> videoList = session .createQuery( - "select h from HomeVideo h LEFT JOIN h.juhe as v where v.id=h.video.id and h.video.show='1' and hometype=:hometype order by v.orderby desc,v.watchCount desc,h.createtime desc") + "select h from HomeVideo h where h.video.show='1' and hometype=:hometype order by h.video.orderby desc,h.video.watchCount desc,h.video.createtime desc") .setParameter("hometype", ((HomeType) list.get(i)).getId()).setFirstResult(0) .setMaxResults(list.get(i).getNumber()).list(); ((HomeType) list.get(i)).setHomeVideoList(videoList); @@ -434,19 +437,19 @@ */ @SuppressWarnings("unchecked") - public List<HomeTypeAdmin> getHomeTypeAdmin(final String key, final int detailSystem, final int page) { + public List<HomeTypeAdmin> getHomeTypeAdmin(final String key, final String systemId, final int detailSystem, final int page) { return (List<HomeTypeAdmin>) homeTypeDao.excute(new HibernateCallback<List<HomeTypeAdmin>>() { public List<HomeTypeAdmin> doInHibernate(Session session) throws HibernateException { List<HomeTypeAdmin> zhiBoClassList = new ArrayList<>(); try { - List<DetailSystem> detailSystemList = session.createQuery("from DetailSystem").list(); + List<DetailSystem> detailSystemList = session.createQuery("from DetailSystem ds where ds.system.id=" + systemId).list(); String sql = ""; if (detailSystem > 0) sql = "select sh.homeType from SuperHomeType sh where sh.homeType.name like ? and sh.detailSystem.id=" + detailSystem + " order by sh.homeType.orderby desc"; else - sql = "from HomeType zb where zb.name like ? order by zb.orderby desc"; + sql = "from HomeType zb where zb.name like ? and zb.system.id=" + systemId + " order by zb.orderby desc"; List<HomeType> list = session.createQuery(sql).setParameter(0, "%" + key + "%") .setFirstResult((page - 1) * Constant.pageCount).setMaxResults(Constant.pageCount).list(); @@ -488,14 +491,14 @@ } - public long getHomeTypeAdminCount(String key, int detailSystem) { + public long getHomeTypeAdminCount(String key, String systemId, int detailSystem) { String sql = ""; if (detailSystem > 0) sql = "select count(*) from (select count(*) from wk_video_super_hometype zb left join wk_video_hometype c on c.id=zb.hometypeid where zb.detailsystemid=" + detailSystem + " and c.name like '%" + key + "%' group by zb.hometypeid) s"; else sql = "select count(*) from (select count(*) from wk_video_super_hometype zb left join wk_video_hometype c on c.id=zb.hometypeid where c.name like '%" - + key + "%' group by zb.hometypeid) s"; + + key + "%' and c.system=" + systemId + " group by zb.hometypeid) s"; return homeTypeDao.getCountSQL(sql); } -- Gitblit v1.8.0