From 20f473dc4997e8b8a76f8c75d0a649be0a5ea139 Mon Sep 17 00:00:00 2001
From: admin <2780501319@qq.com>
Date: 星期五, 02 四月 2021 00:32:03 +0800
Subject: [PATCH] 广告控制逻辑代码初步编写
---
src/main/java/com/yeshi/buwan/service/imp/HomeTypeService.java | 199 +++++++++++++++++++++++++++++++++++++------------
1 files changed, 151 insertions(+), 48 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 3001d79..ca47e0b 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,11 @@
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 com.yeshi.buwan.util.VersionUtil;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.springframework.cache.annotation.Cacheable;
@@ -33,7 +36,7 @@
private DetailSystemDao detailSystemDao;
@Resource
- private VideoResourceMapExtraInfoService videoResourceMapExtraInfoService;
+ private VideoInfoExtraService videoInfoExtraService;
public List<HomeType> getHomeTypeDetailList() {
List<HomeType> list = homeTypeDao.list("from HomeType h order by h.orderby desc");
@@ -41,15 +44,15 @@
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);
+ 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) {
+ @Cacheable(value = "homeCache", key = "'getHomeType'+'-'+#detailSystem+'-'+#version+'-'+#cacheMd5+'-'+#maxNumber+'-'+#dataKey")
+ public List<HomeType> getHomeType(final String detailSystem, final String platform, final int version, final List<Long> resourceIds, String cacheMd5,
+ final int maxNumber, final String dataKey) {
List<HomeType> homeTypeList = (List<HomeType>) homeTypeDao.excute(new HibernateCallback<List<HomeType>>() {
public List<HomeType> doInHibernate(Session session) throws HibernateException {
@@ -63,13 +66,14 @@
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,big_picture,refresh_position,more_tag 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")
+ + " 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.special_data_key='"
+ + dataKey + "' 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.big_picture desc, hvideo.`orderby` DESC,v.orderby desc,v.updatetime desc")
.list();
List<HomeType> homeTypeList = new ArrayList<>();
+ Map<String, Integer> homeTypeVideoCountMap = new HashMap<>();
for (int i = 0; i < resultList.size(); i++) {
Object[] obj = (Object[]) resultList.get(i);
HomeType ht = new HomeType();
@@ -81,13 +85,18 @@
ht.setParams(obj[5] + "");
ht.setIosControl(obj[6] + "");
ht.setNumber(Integer.parseInt(obj[7] + ""));
+ ht.setRefreshPosition(Integer.parseInt(obj[25] + ""));
+ ht.setMoreTag(obj[26]+"");
+
ht.setOrderby(obj[21] + "");
+ ht.setNeedAd(Boolean.parseBoolean(obj[23] + ""));
HomeVideo hv = new HomeVideo();
hv.setId(obj[8] + "");
hv.setPicture(obj[10] + "");
hv.setTag(obj[11] + "");
+ hv.setBigPicture(Integer.parseInt(obj[24] + "")>0);
VideoInfo video = new VideoInfo();
video.setId(obj[12] + "");
@@ -97,7 +106,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);
@@ -106,10 +115,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());
@@ -124,10 +138,26 @@
if (maxNumber > -1)// 鏍规嵁maxNumber鐨勬暟閲忔潵,閫傜敤浜庣綉椤�
mn = maxNumber;
+ if (VersionUtil.isGraterThan390(platform, version)) {
+ //璁$畻宸叉湁澶у浘鏁伴噺
+ int bigCount = 0;
+ for (HomeVideo hv1 : eHomeType.getHomeVideoList()) {
+ if (hv1.getBigPicture()) {
+ bigCount++;
+ }
+ }
+ mn += bigCount;
+ }
+
+ if (homeTypeVideoCountMap.get(eHomeType.getId()) == null) {
+ homeTypeVideoCountMap.put(eHomeType.getId(), 0);
+ }
+ homeTypeVideoCountMap.put(eHomeType.getId(), homeTypeVideoCountMap.get(eHomeType.getId()) + 1);
if (eHomeType.getHomeVideoList().size() < mn)// 鍔犲叆鎸囧畾鐨勬暟閲忕殑鏁版嵁
{
eHomeType.getHomeVideoList().add(hv);
}
+
} else {
List<HomeVideo> videolist = new ArrayList<>();
@@ -144,6 +174,11 @@
// }
orderByType(homeTypeList);
+ for (HomeType ht : homeTypeList) {
+ //璁剧疆鏁伴噺
+ if (homeTypeVideoCountMap.containsKey(ht.getId()))
+ ht.setCount(homeTypeVideoCountMap.get(ht.getId()));
+ }
return homeTypeList;
} catch (Exception e) {
e.printStackTrace();
@@ -155,28 +190,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()));
- if (hv.getVideo().getVideoResourceMapExtraInfo() != null)
- hv.getVideo().setFree(hv.getVideo().getVideoResourceMapExtraInfo().getFree());
- }
- }
- }
-
-
+ videoInfoExtraService.batchExtra(videoInfoList, resourceIds);
return homeTypeList;
}
@@ -236,7 +259,7 @@
for (HomeVideo sp : homeVideoList)
session.delete(sp);
- session.delete(session.get(HomeType.class,id));
+ session.delete(session.get(HomeType.class, id));
session.flush();
session.getTransaction().commit();
} catch (Exception e) {
@@ -319,7 +342,7 @@
public List<HomeVideo> getHomeVideoList(String homeId, int page) {
return homeVideoDao.list(
- "from HomeVideo h where h.type.id=? order by h.video.orderby desc,h.video.watchCount desc,h.createtime desc",
+ "from HomeVideo h where h.type.id=? order by h.video.orderby desc,h.createtime desc",
(page - 1) * Constant.pageCount, Constant.pageCount, new String[]{homeId});
}
@@ -327,6 +350,60 @@
return homeVideoDao.list(
"from HomeVideo h where h.type.id=? and h.video.name like ? order by h.video.orderby desc,h.video.watchCount desc,h.createtime desc",
(page - 1) * Constant.pageCount, Constant.pageCount, new String[]{homeId, "%" + key + "%"});
+ }
+
+
+ public List<HomeVideo> getHomeVideoList(String homeId, List<Long> resourceIds, Boolean bigPicture, int page, int pageSize) {
+ List<HomeVideo> homeVideos = (List<HomeVideo>) homeVideoDao.excute(new HibernateCallback<List<HomeVideo>>() {
+ @Override
+ public List<HomeVideo> doInHibernate(Session session) throws HibernateException {
+
+ List<String> rids = new ArrayList<>();
+ for (Long rid : resourceIds) {
+ rids.add("rv.`resourceid`=" + rid);
+ }
+
+ String sql = String.format("SELECT hv.* FROM wk_video_homevideo hv LEFT JOIN wk_resource_video rv ON rv.`videoid`=hv.`videoid` LEFT JOIN wk_video_video v ON v.`id`=hv.`videoid` WHERE v.show=1 and hv.`hometype`=%s AND (%s) ", homeId, org.yeshi.utils.StringUtil.concat(rids, " or "));
+
+ if (bigPicture != null) {
+ sql += " and hv.big_picture=" + (bigPicture ? 1 : 0);
+ }
+ sql += " GROUP BY hv.id ORDER BY hv.big_picture desc,hv.`orderby` DESC,hv.`createtime` DESC";
+
+ return session.createSQLQuery(sql).addEntity(HomeVideo.class).setFirstResult((page - 1) * pageSize).setMaxResults(pageSize).list();
+ }
+ });
+
+ List<VideoInfo> videoInfoList = new ArrayList<>();
+ for (HomeVideo hv : homeVideos) {
+ if (hv.getVideo() != null)
+ videoInfoList.add(hv.getVideo());
+ }
+ videoInfoExtraService.batchExtra(videoInfoList, resourceIds);
+ return homeVideos;
+ }
+
+
+ public long getHomeVideoListCount(String homeId, List<Long> resourceIds, Boolean bigPicture) {
+ return (Long) homeVideoDao.excute(new HibernateCallback<Long>() {
+ @Override
+ public Long doInHibernate(Session session) throws HibernateException {
+
+ List<String> rids = new ArrayList<>();
+ for (Long rid : resourceIds) {
+ rids.add("rv.`resourceid`=" + rid);
+ }
+
+ String sql = String.format("SELECT count(distinct(hv.id)) FROM wk_video_homevideo hv LEFT JOIN wk_resource_video rv ON rv.`videoid`=hv.`videoid` LEFT JOIN wk_video_video v ON v.`id`=hv.`videoid` WHERE v.show=1 and hv.`hometype`=%s AND (%s)", homeId, org.yeshi.utils.StringUtil.concat(rids, " or "));
+
+ if (bigPicture != null) {
+ sql += " and hv.big_picture=" + (bigPicture ? 1 : 0);
+
+ }
+
+ return Long.parseLong(session.createSQLQuery(sql).uniqueResult() + "");
+ }
+ });
}
public long getHomeVideoListCount(String homeId, String key) {
@@ -442,7 +519,7 @@
*/
@SuppressWarnings("unchecked")
- public List<HomeTypeAdmin> getHomeTypeAdmin(final String key, final String systemId, final int detailSystem, final int page) {
+ public List<HomeTypeAdmin> getHomeTypeAdmin(final String key, final String systemId, final String dataKey, final int detailSystem, final int page) {
return (List<HomeTypeAdmin>) homeTypeDao.excute(new HibernateCallback<List<HomeTypeAdmin>>() {
public List<HomeTypeAdmin> doInHibernate(Session session) throws HibernateException {
@@ -450,12 +527,22 @@
try {
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 ? and zb.system.id=" + systemId + " order by zb.orderby desc";
-
+ List<String> andList = new ArrayList<>();
+ if (detailSystem > 0) {
+ andList.add("sh.homeType.name like ?");
+ andList.add("sh.detailSystem.id=" + detailSystem);
+ if (dataKey != null) {
+ andList.add("sh.homeType.specialDataKey='" + dataKey + "'");
+ }
+ sql = "select sh.homeType from SuperHomeType sh where " + org.yeshi.utils.StringUtil.concat(andList, " and ") + " order by sh.homeType.orderby desc";
+ } else {
+ andList.add("zb.name like ?");
+ andList.add("zb.system.id=" + systemId);
+ if (dataKey != null) {
+ andList.add("zb.specialDataKey='" + dataKey + "'");
+ }
+ sql = "from HomeType zb where " + org.yeshi.utils.StringUtil.concat(andList, " and ") + " order by zb.orderby desc";
+ }
List<HomeType> list = session.createQuery(sql).setParameter(0, "%" + key + "%")
.setFirstResult((page - 1) * Constant.pageCount).setMaxResults(Constant.pageCount).list();
for (HomeType vb : list) {
@@ -496,15 +583,31 @@
}
- 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 + "%' and c.system="+systemId+" group by zb.hometypeid) s";
+ public long getHomeTypeAdminCount(String key, String systemId, int detailSystem, final String dataKey) {
+ List<String> andList = new ArrayList<>();
+
+ String sql = "";
+ if (detailSystem > 0) {
+ andList.add("zb.detailsystemid=" + detailSystem);
+ andList.add("c.name like '%" + key + "%'");
+ if (dataKey != null) {
+ andList.add("c.special_data_key='" + dataKey + "'");
+ }
+
+ sql = "select count(*) from (select count(*) from wk_video_super_hometype zb left join wk_video_hometype c on c.id=zb.hometypeid where " + org.yeshi.utils.StringUtil.concat(andList, " and ") + " group by zb.hometypeid) s";
+
+
+ } else {
+
+ andList.add("c.name like '%" + key + "%'");
+ andList.add("c.system=" + systemId);
+ if (dataKey != null) {
+ andList.add("c.special_data_key='" + dataKey + "'");
+ }
+
+ sql = "select count(*) from (select count(*) from wk_video_super_hometype zb left join wk_video_hometype c on c.id=zb.hometypeid where " + org.yeshi.utils.StringUtil.concat(andList, " and ") + " group by zb.hometypeid) s";
+ }
return homeTypeDao.getCountSQL(sql);
}
--
Gitblit v1.8.0