From cad915058c3c53bf328a8ae9ca9bc7de099caba7 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期六, 06 二月 2021 15:27:49 +0800 Subject: [PATCH] 接口bug修改 --- src/main/java/com/yeshi/buwan/service/imp/VideoService.java | 316 +++++++++++++++++++++++++++------------------------- 1 files changed, 166 insertions(+), 150 deletions(-) diff --git a/src/main/java/com/yeshi/buwan/service/imp/VideoService.java b/src/main/java/com/yeshi/buwan/service/imp/VideoService.java index ea84bd9..96f1e07 100644 --- a/src/main/java/com/yeshi/buwan/service/imp/VideoService.java +++ b/src/main/java/com/yeshi/buwan/service/imp/VideoService.java @@ -24,181 +24,197 @@ @Service public class VideoService { - @Resource - private VideoInfoDao videoInfoDao; + @Resource + private VideoInfoDao videoInfoDao; - @Resource - private VideoResourceDao videoResourceDao; + @Resource + private VideoResourceDao videoResourceDao; - @Resource - private ResourceVideoDao resourceVideoDao; + @Resource + private ResourceVideoDao resourceVideoDao; - @Resource - private ClassService classServcie; + @Resource + private ClassService classServcie; - @Resource - private CategoryVideoDao categoryVideoDao; + @Resource + private CategoryVideoDao categoryVideoDao; - public CategoryVideoDao getCategoryVideoDao() { - return categoryVideoDao; - } + public CategoryVideoDao getCategoryVideoDao() { + return categoryVideoDao; + } - public void setCategoryVideoDao(CategoryVideoDao categoryVideoDao) { - this.categoryVideoDao = categoryVideoDao; - } + public void setCategoryVideoDao(CategoryVideoDao categoryVideoDao) { + this.categoryVideoDao = categoryVideoDao; + } - public ClassService getClassServcie() { - return classServcie; - } + public ClassService getClassServcie() { + return classServcie; + } - public void setClassServcie(ClassService classServcie) { - this.classServcie = classServcie; - } + public void setClassServcie(ClassService classServcie) { + this.classServcie = classServcie; + } - public VideoInfoDao getVideoInfoDao() { - return videoInfoDao; - } + public VideoInfoDao getVideoInfoDao() { + return videoInfoDao; + } - public void setVideoInfoDao(VideoInfoDao videoInfoDao) { - this.videoInfoDao = videoInfoDao; - } + public void setVideoInfoDao(VideoInfoDao videoInfoDao) { + this.videoInfoDao = videoInfoDao; + } - public VideoService() { + public VideoService() { - } + } - public VideoInfo getVideoInfo(String id) { - return videoInfoDao.find(VideoInfo.class, id); - } + public VideoInfo getVideoInfo(String id) { + return videoInfoDao.find(VideoInfo.class, id); + } - public List<VideoInfo> getVideoListByClass(int type, int page) { - String types[] = classServcie.getChildrenType(type); - String wheres = ""; - String as[]; - int j = (as = types).length; - for (int i = 0; i < j; i++) { - String st = as[i]; - wheres = (new StringBuilder(String.valueOf(wheres))).append("or v.videoType.id=").append(st).append(" ") - .toString(); - } - if (wheres.startsWith("or")) - wheres = wheres.substring(2, wheres.length()); - List<VideoInfo> list = videoInfoDao.list( - (new StringBuilder("from VideoInfo v where v.show='1' and (")).append(wheres).append(")").toString(), - (page - 1) * Constant.pageCount, 20, new String[] {}); - return list; - } + public List<VideoInfo> getVideoInfoList(List<String> ids) { + if (ids == null || ids.size() == 0) + return null; + List<VideoInfo> list = videoInfoDao.listByVideoIds(ids); + Map<String, VideoInfo> map = new HashMap<>(); + for (VideoInfo vi : list) { + map.put(vi.getId(), vi); + } + list.clear(); + for (String id : ids) { + list.add(map.get(id)); + } + return list; + } - public List<VideoInfo> searchVideoUsedByAdmin(String name) { - return videoInfoDao.list("from VideoInfo v where v.name like ? order by REPLACE(v.name,?,'')", 0, 20, - new String[] { "%" + name + "%", name }); - } + public List<VideoInfo> getVideoListByClass(int type, int page) { + String types[] = classServcie.getChildrenType(type); + String wheres = ""; + String as[]; + int j = (as = types).length; + for (int i = 0; i < j; i++) { + String st = as[i]; + wheres = (new StringBuilder(String.valueOf(wheres))).append("or v.videoType.id=").append(st).append(" ") + .toString(); + } - public long getVideoCountByClass(int type) { - String types[] = classServcie.getChildrenType(type); - String wheres = ""; - String as[]; - int j = (as = types).length; - for (int i = 0; i < j; i++) { - String st = as[i]; - wheres = (new StringBuilder(String.valueOf(wheres))).append("or v.videoType.id=").append(st).append(" ") - .toString(); - } + if (wheres.startsWith("or")) + wheres = wheres.substring(2, wheres.length()); + List<VideoInfo> list = videoInfoDao.list( + (new StringBuilder("from VideoInfo v where v.show='1' and (")).append(wheres).append(")").toString(), + (page - 1) * Constant.pageCount, 20, new String[]{}); + return list; + } - if (wheres.startsWith("or")) - wheres = wheres.substring(2, wheres.length()); - return videoInfoDao - .getCount((new StringBuilder("select count(*) from VideoInfo v where ")).append(wheres).toString()); - } + public List<VideoInfo> searchVideoUsedByAdmin(String name) { + return videoInfoDao.list("from VideoInfo v where v.name like ? order by REPLACE(v.name,?,'')", 0, 20, + new String[]{"%" + name + "%", name}); + } - public void addVideoWatch(final String vid) { - videoInfoDao.excute(new HibernateCallback() { - public Object doInHibernate(Session session) throws HibernateException { - try { - session.getTransaction().begin(); - session.createSQLQuery("update wk_video_video v set v.watchcount=v.watchcount+1 where v.id=?") - .setParameter(0, vid).executeUpdate(); - session.flush(); - session.getTransaction().commit(); - } catch (Exception exception) { - exception.printStackTrace(); - } - return null; - } - }); + public long getVideoCountByClass(int type) { + String types[] = classServcie.getChildrenType(type); + String wheres = ""; + String as[]; + int j = (as = types).length; + for (int i = 0; i < j; i++) { + String st = as[i]; + wheres = (new StringBuilder(String.valueOf(wheres))).append("or v.videoType.id=").append(st).append(" ") + .toString(); + } - } + if (wheres.startsWith("or")) + wheres = wheres.substring(2, wheres.length()); + return videoInfoDao + .getCount((new StringBuilder("select count(*) from VideoInfo v where ")).append(wheres).toString()); + } - public void addCategoryVideo(CategoryVideo cv) { - categoryVideoDao.save(cv); - } + public void addVideoWatch(final String vid) { + videoInfoDao.excute(new HibernateCallback() { + public Object doInHibernate(Session session) throws HibernateException { + try { + session.getTransaction().begin(); + session.createSQLQuery("update wk_video_video v set v.watchcount=v.watchcount+1 where v.id=?") + .setParameter(0, vid).executeUpdate(); + session.flush(); + session.getTransaction().commit(); + } catch (Exception exception) { + exception.printStackTrace(); + } + return null; + } + }); - /** - * 灏嗘病鏈夋坊鍔犺繘鍒嗚瑙嗛鐨勮棰戝姞鍏ユ潅绫� - */ - public void addNOAddToCategoryVideo() { - videoInfoDao.excute(new HibernateCallback() { - public Object doInHibernate(Session session) throws HibernateException { - try { - session.getTransaction().begin(); - List list = session - .createSQLQuery( - "SELECT DISTINCT(v.`id`) FROM wk_video_video v LEFT JOIN wk_category_video cv ON cv.`videoid`=v.`id` WHERE cv.`id` IS NULL") - .setFirstResult(0).setMaxResults(10000).list(); - for (int i = 0; i < list.size(); i++) { - String videoId = list.get(i) + ""; - session.createSQLQuery( - "INSERT INTO wk_category_video(videoid,videotypeid) VALUES(" + videoId + ",299)") - .executeUpdate(); - } - session.flush(); - session.getTransaction().commit(); - } catch (Exception exception) { - exception.printStackTrace(); - } - return null; - } - }); + } - } + public void addCategoryVideo(CategoryVideo cv) { + categoryVideoDao.save(cv); + } - @Cacheable(value = "guessLikeCache", key = "'guessLike'+'-'+#page") - public List<VideoInfo> guessLike(int page) { - List<VideoInfo> list = videoInfoDao.list( - "select cv.video from CategoryVideo cv where (cv.videoType= 216) and cv.video.show=1 order by cv.id desc", - (page - 1) * Constant.pageCount, Constant.pageCount, null); - String where = ""; - for (VideoInfo vi : list) { - where += String.format(" rv.video.id=%s or", vi.getId()); - } - if (where.endsWith("or")) - where = where.substring(0, where.length() - 2); + /** + * 灏嗘病鏈夋坊鍔犺繘鍒嗚瑙嗛鐨勮棰戝姞鍏ユ潅绫� + */ + public void addNOAddToCategoryVideo() { + videoInfoDao.excute(new HibernateCallback() { + public Object doInHibernate(Session session) throws HibernateException { + try { + session.getTransaction().begin(); + List list = session + .createSQLQuery( + "SELECT DISTINCT(v.`id`) FROM wk_video_video v LEFT JOIN wk_category_video cv ON cv.`videoid`=v.`id` WHERE cv.`id` IS NULL") + .setFirstResult(0).setMaxResults(10000).list(); + for (int i = 0; i < list.size(); i++) { + String videoId = list.get(i) + ""; + session.createSQLQuery( + "INSERT INTO wk_category_video(videoid,videotypeid) VALUES(" + videoId + ",299)") + .executeUpdate(); + } + session.flush(); + session.getTransaction().commit(); + } catch (Exception exception) { + exception.printStackTrace(); + } + return null; + } + }); - // 鏌ヨ鏉ユ簮 - List<VideoResource> resourceList = videoResourceDao.list(String.format("from VideoResource")); - Map<String, VideoResource> map = new HashMap<>(); - for (VideoResource rv : resourceList) - map.put(rv.getName(), rv); + } - // 鏉ユ簮璧嬪�� + @Cacheable(value = "guessLikeCache", key = "'guessLike'+'-'+#page") + public List<VideoInfo> guessLike(int page) { + List<VideoInfo> list = videoInfoDao.list( + "select cv.video from CategoryVideo cv where (cv.videoType= 216) and cv.video.show=1 order by cv.id desc", + (page - 1) * Constant.pageCount, Constant.pageCount, null); + String where = ""; + for (VideoInfo vi : list) { + where += String.format(" rv.video.id=%s or", vi.getId()); + } + if (where.endsWith("or")) + where = where.substring(0, where.length() - 2); - for (VideoInfo video : list) { - List<VideoResource> rsList = new ArrayList<>(); - if (video.getPicture().contains("juhe")) { - rsList.add(map.get("鐖卞鑹�")); - } else if (video.getPicture().contains("aixifan")) { - rsList.add(map.get("AcFun")); - } else if (video.getPicture().contains("funshion")) { - rsList.add(map.get("椋庤")); - } else { - VideoResource vr = new VideoResource(); - vr.setPicture(""); - vr.setName(""); - rsList.add(vr); - } - video.setResourceList(rsList); - } - return list; - } + // 鏌ヨ鏉ユ簮 + List<VideoResource> resourceList = videoResourceDao.list(String.format("from VideoResource")); + Map<String, VideoResource> map = new HashMap<>(); + for (VideoResource rv : resourceList) + map.put(rv.getName(), rv); + + // 鏉ユ簮璧嬪�� + + for (VideoInfo video : list) { + List<VideoResource> rsList = new ArrayList<>(); + if (video.getPicture().contains("juhe")) { + rsList.add(map.get("鐖卞鑹�")); + } else if (video.getPicture().contains("aixifan")) { + rsList.add(map.get("AcFun")); + } else if (video.getPicture().contains("funshion")) { + rsList.add(map.get("椋庤")); + } else { + VideoResource vr = new VideoResource(); + vr.setPicture(""); + vr.setName(""); + rsList.add(vr); + } + video.setResourceList(rsList); + } + return list; + } } -- Gitblit v1.8.0