From b37275dba6b782bf3bb3817c4504f6cdef1bef7c Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期四, 18 三月 2021 18:38:51 +0800
Subject: [PATCH] APP首页顶部标签兼容

---
 src/main/java/com/yeshi/buwan/service/imp/HomeTypeService.java |   90 ++++++++++++++++++++++++++------------------
 1 files changed, 53 insertions(+), 37 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 40d80b1..b1eceea 100644
--- a/src/main/java/com/yeshi/buwan/service/imp/HomeTypeService.java
+++ b/src/main/java/com/yeshi/buwan/service/imp/HomeTypeService.java
@@ -1,30 +1,21 @@
 package com.yeshi.buwan.service.imp;
 
 import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Iterator;
-import java.util.List;
+import java.util.*;
 
 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.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;
 import org.springframework.orm.hibernate4.HibernateCallback;
 import org.springframework.stereotype.Service;
 
-import com.yeshi.buwan.dao.DetailSystemDao;
-import com.yeshi.buwan.dao.HomeTypeDao;
-import com.yeshi.buwan.dao.HomeVideoDao;
-import com.yeshi.buwan.dao.SuperHomeTypeDao;
-import com.yeshi.buwan.dao.VideoInfoDao;
-import com.yeshi.buwan.domain.DetailSystem;
-import com.yeshi.buwan.domain.HomeType;
-import com.yeshi.buwan.domain.HomeVideo;
-import com.yeshi.buwan.domain.SuperHomeType;
-import com.yeshi.buwan.domain.VideoInfo;
 import com.yeshi.buwan.domain.web.DetailSystemSelect;
 import com.yeshi.buwan.domain.web.HomeTypeAdmin;
 import com.yeshi.buwan.util.Constant;
@@ -43,17 +34,25 @@
     @Resource
     private DetailSystemDao detailSystemDao;
 
-    public List<HomeType> getHomeType() {
+    @Resource
+    private VideoInfoExtraService videoInfoExtraService;
+
+    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")
     @Cacheable(value = "homeCache", key = "'getHomeType'+'-'+#detailSystem+'-'+#cacheMd5+'-'+#maxNumber+'-'+#vtid")
     public List<HomeType> getHomeType(final String detailSystem, final List<Long> resourceIds, String cacheMd5,
                                       final int maxNumber, final long vtid) {
-        return (List<HomeType>) homeTypeDao.excute(new HibernateCallback<List<HomeType>>() {
+        List<HomeType> homeTypeList = (List<HomeType>) homeTypeDao.excute(new HibernateCallback<List<HomeType>>() {
             public List<HomeType> doInHibernate(Session session) throws HibernateException {
 
                 return (List<HomeType>) homeTypeDao.excute(new HibernateCallback<List<HomeType>>() {
@@ -66,13 +65,13 @@
                                 resourceWhere = resourceWhere.substring(0, resourceWhere.length() - 2);
                             List resultList = session
                                     .createSQLQuery(
-                                            "SELECT  ht.`id` as htid,ht.`name` as htname,ht.`columns` as htcolumns ,ht.`hasmore`,ht.`activity` ,ht.`params` ,ht.`ioscontrol`,ht.number,hvideo.id as hvid,hvideo.`videoid` AS hvvideoid,hvideo.`picture`as hvpicture ,hvideo.`tag` as hvtag,    v.`id` as vid ,v.`picture` as vpicture ,v.`name` as vname ,v.`tag` as vtag ,v.`hpicture` as vhpicture ,v.`latest_hpicture` as vlatest_hpicture ,v.`watchcount` as vwatchcount,v.commentcount,ht.icon as hicon,ht.orderby as htorder,hvideo.orderby as hvorder FROM   (SELECT hv.* FROM `wk_resource_video` rv LEFT JOIN `wk_video_homevideo` hv ON rv.`videoid` =hv.`videoid` LEFT JOIN  `wk_video_video` v ON v.`id` =hv.`videoid`  LEFT JOIN `wk_video_banquan_video` bv ON bv.`videoid`=hv.`videoid` AND bv.`detailsystemid`="
+                                            "SELECT  ht.`id` as htid,ht.`name` as htname,ht.`columns` as htcolumns ,ht.`hasmore`,ht.`activity` ,ht.`params` ,ht.`ioscontrol`,ht.number,hvideo.id as hvid,hvideo.`videoid` AS hvvideoid,hvideo.`picture`as hvpicture ,hvideo.`tag` as hvtag,    v.`id` as vid ,v.`picture` as vpicture ,v.`name` as vname ,v.`tag` as vtag ,v.`hpicture` as vhpicture ,v.`latest_hpicture` as vlatest_hpicture ,v.`watchcount` as vwatchcount,v.commentcount,ht.icon as hicon,ht.orderby as htorder,hvideo.orderby as hvorder,need_ad FROM   (SELECT hv.* FROM `wk_resource_video` rv LEFT JOIN `wk_video_homevideo` hv ON rv.`videoid` =hv.`videoid` LEFT JOIN  `wk_video_video` v ON v.`id` =hv.`videoid`  LEFT JOIN `wk_video_banquan_video` bv ON bv.`videoid`=hv.`videoid` AND bv.`detailsystemid`="
                                                     + detailSystem
                                                     + " AND bv.`show`=1 LEFT JOIN `wk_video_hometype` ht ON ht.id=hv.hometype WHERE (hv.`id`>0 AND v.`show` =1  AND ht.vtid='"
                                                     + vtid + "'  AND (" + resourceWhere
                                                     + " ) AND bv.`videoid` IS NULL ) GROUP BY (hv.`id`) ORDER BY hv.`orderby` desc,v.createtime DESC ) hvideo LEFT JOIN  `wk_video_super_hometype` sht  ON sht.`hometypeid`=hvideo.hometype LEFT JOIN `wk_video_hometype` ht  ON sht.`hometypeid` =ht.`id` LEFT JOIN wk_video_video v ON v.`id`=hvideo.videoid  WHERE sht.`detailsystemid` =" + detailSystem + " ORDER BY hvideo.`orderby` DESC,v.orderby desc,v.updatetime desc")
                                     .list();
-                            List<HomeType> homeTypeList = new ArrayList<HomeType>();
+                            List<HomeType> homeTypeList = new ArrayList<>();
                             for (int i = 0; i < resultList.size(); i++) {
                                 Object[] obj = (Object[]) resultList.get(i);
                                 HomeType ht = new HomeType();
@@ -86,6 +85,7 @@
                                 ht.setNumber(Integer.parseInt(obj[7] + ""));
 
                                 ht.setOrderby(obj[21] + "");
+                                ht.setNeedAd(Boolean.parseBoolean(obj[23]+""));
 
                                 HomeVideo hv = new HomeVideo();
                                 hv.setId(obj[8] + "");
@@ -100,7 +100,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);
@@ -109,10 +109,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());
@@ -133,7 +138,7 @@
                                     }
 
                                 } else {
-                                    List<HomeVideo> videolist = new ArrayList<HomeVideo>();
+                                    List<HomeVideo> videolist = new ArrayList<>();
                                     videolist.add(hv);
                                     ht.setHomeVideoList(videolist);
                                     homeTypeList.add(ht);
@@ -158,6 +163,17 @@
 
             }
         });
+        List<VideoInfo> videoInfoList = new ArrayList<>();
+        for (HomeType ht : homeTypeList) {
+            if (ht.getHomeVideoList() != null)
+                for (HomeVideo hv : ht.getHomeVideoList()) {
+                    if (hv.getVideo() != null)
+                        videoInfoList.add(hv.getVideo());
+                }
+        }
+
+        videoInfoExtraService.batchExtra(videoInfoList, resourceIds);
+        return homeTypeList;
     }
 
     private void orderByType(List<HomeType> homeTypeList) {
@@ -216,7 +232,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) {
@@ -240,7 +256,7 @@
     }
 
     public List<DetailSystemSelect> getDetailSystemSelectByType(String homeType) {
-        List<DetailSystemSelect> li = new ArrayList<DetailSystemSelect>();
+        List<DetailSystemSelect> li = new ArrayList<>();
         List<DetailSystem> list = detailSystemDao
                 .list("select sht.detailSystem from SuperHomeType sht where sht.homeType.id=" + homeType);
         List<DetailSystem> sdList = detailSystemDao.list("from DetailSystem");
@@ -326,7 +342,7 @@
                     for (int i = 0; i < list.size(); i++) {
                         List<HomeVideo> videoList = session
                                 .createQuery(
-                                        "select h from HomeVideo h LEFT JOIN h.video 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);
@@ -398,9 +414,9 @@
     @Cacheable(value = "homeCache", key = "'getVideoByTypes'+'-'+#homeType+'-'+#page+'-'+#ds.id")
     public List<HomeVideo> getVideoByTypes(String homeType, int page, DetailSystem ds) {
         List<HomeVideo> list = null;
-        String sql = "select h from HomeVideo h  LEFT JOIN h.video as v  where  v.id=h.video.id and h.video.show='1' and  h.type.id=? order by h.video.orderby desc,h.video.watchCount desc,h.createtime desc";
+        String sql = "select h from HomeVideo h  LEFT JOIN h.juhe as v  where  v.id=h.video.id and h.video.show='1' and  h.type.id=? order by h.video.orderby desc,h.video.watchCount desc,h.createtime desc";
         if (ds.getPackageName().contains("doudou"))
-            sql = "select h from HomeVideo h  LEFT JOIN h.video as v  where  v.id=h.video.id and h.video.show='1' and  h.type.id=? order by h.video.year desc, h.video.month desc,h.video.day desc,h.createtime desc";
+            sql = "select h from HomeVideo h  LEFT JOIN h.juhe as v  where  v.id=h.video.id and h.video.show='1' and  h.type.id=? order by h.video.year desc, h.video.month desc,h.video.day desc,h.createtime desc";
         list = homeVideoDao.list(sql, (page - 1) * Constant.pageCount, Constant.pageCount, new String[]{homeType});
         return list;
     }
@@ -422,19 +438,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<HomeTypeAdmin>();
+                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();
@@ -443,7 +459,7 @@
                                 .createQuery("select vb.detailSystem from SuperHomeType vb where vb.homeType.id=?")
                                 .setParameter(0, vb.getId()).list();
 
-                        List<DetailSystemSelect> dssList = new ArrayList<DetailSystemSelect>();
+                        List<DetailSystemSelect> dssList = new ArrayList<>();
 
                         for (DetailSystem ds : detailSystemList) {
                             DetailSystemSelect dss = new DetailSystemSelect();
@@ -476,14 +492,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