From 89e370bfdda29ac8a8f7080a18dc09a6ddc75c09 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期一, 26 十月 2020 18:42:16 +0800
Subject: [PATCH] 风行爱奇艺视频更新

---
 src/main/java/com/yeshi/buwan/service/imp/ResourceVideoService.java |  125 +++++++++++++++++++++++++++++------------
 1 files changed, 89 insertions(+), 36 deletions(-)

diff --git a/src/main/java/com/yeshi/buwan/service/imp/ResourceVideoService.java b/src/main/java/com/yeshi/buwan/service/imp/ResourceVideoService.java
index 61a84e3..0f265a9 100644
--- a/src/main/java/com/yeshi/buwan/service/imp/ResourceVideoService.java
+++ b/src/main/java/com/yeshi/buwan/service/imp/ResourceVideoService.java
@@ -3,6 +3,9 @@
 import java.util.ArrayList;
 import java.util.List;
 
+import com.yeshi.buwan.domain.VideoResource;
+import com.yeshi.buwan.dto.mq.VideoExtraInfoChangeMQMsg;
+import com.yeshi.buwan.util.mq.CMQManager;
 import org.hibernate.HibernateException;
 import org.hibernate.Query;
 import org.hibernate.Session;
@@ -13,45 +16,95 @@
 import com.yeshi.buwan.dao.ResourceVideoDao;
 import com.yeshi.buwan.domain.ResourceVideo;
 import com.yeshi.buwan.domain.VideoInfo;
+import org.springframework.transaction.annotation.Transactional;
+
+import javax.annotation.Resource;
 
 @Service
 public class ResourceVideoService {
-	
-	@Autowired
-	private ResourceVideoDao resourceVideoDao;
 
-	@SuppressWarnings("unchecked")
-	public List<ResourceVideo> getResourceList(final List<VideoInfo> list) {
-		if(list == null || list.size() ==0){
-			return new ArrayList<ResourceVideo>();
-		}
-		return (List<ResourceVideo>) resourceVideoDao.excute(new HibernateCallback<List<ResourceVideo>>() {
-			@Override
-			public List<ResourceVideo> doInHibernate(Session session)
-					throws HibernateException {
-				StringBuffer hql=new StringBuffer("from ResourceVideo rv  ");
-				int i=0;
-				for (VideoInfo videoInfo : list) {
-					if(i==0)
-						hql.append(" where ( rv.video.id = ? ) ");
-					else
-						hql.append(" or ( rv.video.id = ? ) ");
-					i++;
-				}
-				hql.append(" order by rv.video.id desc ");
-				Query query = session.createQuery(hql.toString());
-				i=0;
-				for (VideoInfo videoInfo : list) {
-					query.setParameter(i, videoInfo.getId());
-					i++;
-				}
-				return query.list();
-			}
-		});
-	}
+    @Autowired
+    private ResourceVideoDao resourceVideoDao;
 
-	public void save(ResourceVideo resourceVideo) {
-		resourceVideoDao.save(resourceVideo);
-	}
-	
+    @SuppressWarnings("unchecked")
+    public List<ResourceVideo> getResourceList(final List<VideoInfo> list) {
+        if (list == null || list.size() == 0) {
+            return new ArrayList<ResourceVideo>();
+        }
+        return (List<ResourceVideo>) resourceVideoDao.excute(new HibernateCallback<List<ResourceVideo>>() {
+            @Override
+            public List<ResourceVideo> doInHibernate(Session session)
+                    throws HibernateException {
+                StringBuffer hql = new StringBuffer("from ResourceVideo rv  ");
+                int i = 0;
+                for (VideoInfo videoInfo : list) {
+                    if (i == 0)
+                        hql.append(" where ( rv.video.id = ? ) ");
+                    else
+                        hql.append(" or ( rv.video.id = ? ) ");
+                    i++;
+                }
+                hql.append(" order by rv.video.id desc ");
+                Query query = session.createQuery(hql.toString());
+                i = 0;
+                for (VideoInfo videoInfo : list) {
+                    query.setParameter(i, videoInfo.getId());
+                    i++;
+                }
+                return query.list();
+            }
+        });
+    }
+
+    /**
+     * 鑾峰彇璧勬簮鍒楄〃
+     *
+     * @param videoId
+     * @return
+     */
+    public List<ResourceVideo> getResourceList(String videoId) {
+        List<VideoInfo> videoInfoList = new ArrayList<>();
+        videoInfoList.add(new VideoInfo(videoId));
+        return getResourceList(videoInfoList);
+    }
+
+
+    /**
+     * 鏍规嵁瑙嗛ID涓嶳esourceId鏌ヨ
+     *
+     * @param videoId
+     * @param sourceId
+     * @return
+     */
+
+    public long countByVideoIdAndResourceId(String videoId, long sourceId) {
+        return resourceVideoDao.countByVideoIdAndResourceId(videoId, sourceId + "");
+    }
+
+    public void save(ResourceVideo resourceVideo) {
+        resourceVideoDao.save(resourceVideo);
+    }
+
+    public void addVideoResource(String videoId, String resourceId) {
+        ResourceVideo rv = resourceVideoDao.selectByVideoIdAndResourceId(videoId, resourceId);
+        if (rv == null) {
+            System.out.println(videoId + ":" + resourceId);
+            rv = new ResourceVideo();
+            rv.setResource(new VideoResource(resourceId + ""));
+            rv.setVideo(new VideoInfo(videoId + ""));
+            resourceVideoDao.save(rv);
+            CMQManager.getInstance().addVideoExtraInfoChanged(new VideoExtraInfoChangeMQMsg(VideoExtraInfoChangeMQMsg.TYPE_RESOURCE, videoId, VideoExtraInfoChangeMQMsg.ACTION_ADD));
+        }
+    }
+
+    @Transactional
+    public void delete(String videoId, String resourceId) {
+        ResourceVideo resourceVideo = resourceVideoDao.selectByVideoIdAndResourceId(videoId, resourceId + "");
+        if (resourceVideo != null)
+            resourceVideoDao.delete(resourceVideo);
+        CMQManager.getInstance().addVideoResourceDeleteMsg(videoId);
+        CMQManager.getInstance().addVideoExtraInfoChanged(new VideoExtraInfoChangeMQMsg(VideoExtraInfoChangeMQMsg.TYPE_RESOURCE, videoId, VideoExtraInfoChangeMQMsg.ACTION_DELETE));
+    }
+
+
 }

--
Gitblit v1.8.0