From cdc3690a0354e01b44852f4c9da3b7204128d2eb Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期五, 13 八月 2021 18:46:36 +0800
Subject: [PATCH] 增加苹果内购回调日志,兼容苹果内购

---
 src/main/java/com/yeshi/buwan/service/imp/AttentionService.java |  351 +++++++++++++++++++++++++++++----------------------------
 1 files changed, 179 insertions(+), 172 deletions(-)

diff --git a/src/main/java/com/yeshi/buwan/service/imp/AttentionService.java b/src/main/java/com/yeshi/buwan/service/imp/AttentionService.java
index 3153fd4..5f6d431 100644
--- a/src/main/java/com/yeshi/buwan/service/imp/AttentionService.java
+++ b/src/main/java/com/yeshi/buwan/service/imp/AttentionService.java
@@ -28,195 +28,202 @@
 
 @Service
 public class AttentionService {
-	@Resource
-	private AttentionDao attentionDao;
-	@Resource
-	private VideoDetailUtil videoDetailUtil;
-	@Resource
-	private LoginUserDao loginUserDao;
+    @Resource
+    private AttentionDao attentionDao;
+    @Resource
+    private VideoDetailUtil videoDetailUtil;
+    @Resource
+    private LoginUserDao loginUserDao;
 
-	@SuppressWarnings("unchecked")
-	@Caching(evict = {
-			@CacheEvict(value = "attentionCache", key = "'isAddAttention'+'-'+#attention.loginUser.id+'-'+#attention.videoInfo.id"),
-			@CacheEvict(value = "attentionCache", key = "'getAttentionVideoListByLoginUid'+'-'+#attention.loginUser.id+'-1'") })
-	public boolean addAttention(final Attention attention) {
-		boolean isS = false;
-		isS = (Boolean) attentionDao.excute(new HibernateCallback<Boolean>() {
-			public Boolean doInHibernate(Session session) throws HibernateException {
-				Boolean isS = false;
-				try {
-					List<Attention> list = session
-							.createQuery("from Attention a where a.videoInfo.id=? and a.loginUser.id=?")
-							.setParameter(0, attention.getVideoInfo().getId())
-							.setParameter(1, attention.getLoginUser().getId()).list();
-					session.getTransaction().begin();
-					if (list != null && list.size() > 0) {
-						list.get(0).setShow(true);
-						list.get(0).setCreatetime(System.currentTimeMillis() + "");
-						session.update(list.get(0));
-					} else {
-						session.persist(attention);
-					}
-					session.flush();
-					session.getTransaction().commit();
-					isS = true;
-				} catch (Exception e) {
-					e.printStackTrace();
-				}
-				return isS;
-			}
-		});
-		return isS;
-	}
+    @SuppressWarnings("unchecked")
+    @Caching(evict = {
+            @CacheEvict(value = "attentionCache", key = "'isAddAttention'+'-'+#attention.loginUser.id+'-'+#attention.videoInfo.id"),
+            @CacheEvict(value = "attentionCache", key = "'getAttentionVideoListByLoginUid'+'-'+#attention.loginUser.id+'-1'")})
+    public boolean addAttention(final Attention attention) {
+        boolean isS = false;
+        isS = (Boolean) attentionDao.excute(new HibernateCallback<Boolean>() {
+            public Boolean doInHibernate(Session session) throws HibernateException {
+                Boolean isS = false;
+                try {
+                    List<Attention> list = session
+                            .createQuery("from Attention a where a.videoInfo.id=? and a.loginUser.id=?")
+                            .setParameter(0, attention.getVideoInfo().getId())
+                            .setParameter(1, attention.getLoginUser().getId()).list();
+                    session.getTransaction().begin();
+                    if (list != null && list.size() > 0) {
+                        list.get(0).setShow(true);
+                        list.get(0).setCreatetime(System.currentTimeMillis() + "");
+                        session.update(list.get(0));
+                    } else {
+                        session.persist(attention);
+                    }
+                    session.flush();
+                    session.getTransaction().commit();
+                    isS = true;
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+                return isS;
+            }
+        });
+        return isS;
+    }
 
-//	@Cacheable(value = "attentionCache", key = "'isAddAttention'+'-'+#loginuid+'-'+#videoid")
-	public boolean isAddAttention(String loginuid, String videoid) {
-		return attentionDao.getCount(
-				"select count(a.id) from Attention a where a.videoInfo.id=? and a.loginUser.id=? and a.show=1",
-				new Serializable[] { videoid, loginuid }) > 0;
-	}
+    //	@Cacheable(value = "attentionCache", key = "'isAddAttention'+'-'+#loginuid+'-'+#videoid")
+    public boolean isAddAttention(String loginuid, String videoid) {
+        return attentionDao.getCount(
+                "select count(a.id) from Attention a where a.videoInfo.id=? and a.loginUser.id=? and a.show=1",
+                new Serializable[]{videoid, loginuid}) > 0;
+    }
 
-	@SuppressWarnings("unchecked")
-	@Caching(evict = {
-			@CacheEvict(value = "attentionCache", key = "'isAddAttention'+'-'+#attention.loginUser.id+'-'+#videoid"),
-			@CacheEvict(value = "attentionCache", key = "'getAttentionVideoListByLoginUid'+'-'+#loginuid+'-1'") })
-	public boolean deleteAttention(final long videoid, final long loginuid) {
-		boolean isS = false;
-		isS = (Boolean) attentionDao.excute(new HibernateCallback<Boolean>() {
-			public Boolean doInHibernate(Session session) throws HibernateException {
-				boolean isS = false;
-				try {
-					List<Attention> list = session
-							.createQuery("from Attention a where a.videoInfo.id=? and a.loginUser.id=?")
-							.setParameter(0, videoid + "").setParameter(1, loginuid + "").list();
-					session.getTransaction().begin();
-					if (list != null && list.size() > 0) {
-						list.get(0).setShow(false);
-						session.update(list.get(0));
-					}
-					session.flush();
-					session.getTransaction().commit();
-					isS = true;
-				} catch (Exception e) {
-					e.printStackTrace();
-				}
-				return isS;
-			}
-		});
-		return isS;
-	}
+    @SuppressWarnings("unchecked")
+    @Caching(evict = {
+            @CacheEvict(value = "attentionCache", key = "'isAddAttention'+'-'+#attention.loginUser.id+'-'+#videoid"),
+            @CacheEvict(value = "attentionCache", key = "'getAttentionVideoListByLoginUid'+'-'+#loginuid+'-1'")})
+    public boolean deleteAttention(final long videoid, final long loginuid) {
+        boolean isS = false;
+        isS = (Boolean) attentionDao.excute(new HibernateCallback<Boolean>() {
+            public Boolean doInHibernate(Session session) throws HibernateException {
+                boolean isS = false;
+                try {
+                    List<Attention> list = session
+                            .createQuery("from Attention a where a.videoInfo.id=? and a.loginUser.id=?")
+                            .setParameter(0, videoid + "").setParameter(1, loginuid + "").list();
+                    session.getTransaction().begin();
+                    if (list != null && list.size() > 0) {
+                        list.get(0).setShow(false);
+                        session.update(list.get(0));
+                    }
+                    session.flush();
+                    session.getTransaction().commit();
+                    isS = true;
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+                return isS;
+            }
+        });
+        return isS;
+    }
 
-	@SuppressWarnings("unchecked")
-	@Caching(evict = {
-			@CacheEvict(value = "attentionCache", key = "'getAttentionVideoListByLoginUid'+'-'+#loginuid+'-1'") })
-	public boolean deleteAttentions(final List<Long> videoList, final long loginuid) {
-		boolean isS = false;
-		isS = (Boolean) attentionDao.excute(new HibernateCallback<Boolean>() {
-			public Boolean doInHibernate(Session session) throws HibernateException {
-				Boolean isS = false;
-				try {
+    @SuppressWarnings("unchecked")
+    @Caching(evict = {
+            @CacheEvict(value = "attentionCache", key = "'getAttentionVideoListByLoginUid'+'-'+#loginuid+'-1'")})
+    public boolean deleteAttentions(final List<Long> videoList, final long loginuid) {
+        boolean isS = false;
+        isS = (Boolean) attentionDao.excute(new HibernateCallback<Boolean>() {
+            public Boolean doInHibernate(Session session) throws HibernateException {
+                Boolean isS = false;
+                try {
 
-					for (Long videoid : videoList) {
-						List<Attention> list = session
-								.createQuery(
-										"from Attention a where a.videoInfo.id=? and a.loginUser.id=? and a.show=1")
-								.setParameter(0, videoid + "").setParameter(1, loginuid + "").list();
+                    for (Long videoid : videoList) {
+                        List<Attention> list = session
+                                .createQuery(
+                                        "from Attention a where a.videoInfo.id=? and a.loginUser.id=? and a.show=1")
+                                .setParameter(0, videoid + "").setParameter(1, loginuid + "").list();
 
-						if (list != null && list.size() > 0) {
-							session.getTransaction().begin();
-							session.createSQLQuery(
-									"update wk_video_attention a set a.show=0 where a.id=" + list.get(0).getId())
-									.executeUpdate();
-							session.flush();
-							session.getTransaction().commit();
-						}
+                        if (list != null && list.size() > 0) {
+                            session.getTransaction().begin();
+                            session.createSQLQuery(
+                                    "update wk_video_attention a set a.show=0 where a.id=" + list.get(0).getId())
+                                    .executeUpdate();
+                            session.flush();
+                            session.getTransaction().commit();
+                        }
 
-					}
+                    }
 
-					isS = true;
-				} catch (Exception e) {
-					isS = false;
-					e.printStackTrace();
-						session.getTransaction().rollback();
-				}
-				return isS;
-			}
-		});
-		return isS;
-	}
+                    isS = true;
+                } catch (Exception e) {
+                    isS = false;
+                    e.printStackTrace();
+                    session.getTransaction().rollback();
+                }
+                return isS;
+            }
+        });
+        return isS;
+    }
 
-	// 鎸夌収Uid鑾峰彇鍏虫敞鍒楄〃
+    // 鎸夌収Uid鑾峰彇鍏虫敞鍒楄〃
 
-	public List<Attention> getAttentionListByLoginUid(long loginUid, int pageIndex) {
-		return attentionDao.list(
-				"from Attention a where a.show=1 and a.videoInfo.show=1 and a.loginUser.id=? order by FROM_UNIXTIME(a.createtime/1000) desc",
-				(pageIndex - 1) * Constant.pageCount, Constant.pageCount, new Serializable[] { loginUid + "" });
-	}
+    public List<Attention> getAttentionListByLoginUid(long loginUid, int pageIndex) {
+        return attentionDao.list(
+                "from Attention a where a.show=1 and a.videoInfo.show=1 and a.loginUser.id=? order by FROM_UNIXTIME(a.createtime/1000) desc",
+                (pageIndex - 1) * Constant.pageCount, Constant.pageCount, new Serializable[]{loginUid + ""});
+    }
 
-	public List<Attention> getAttentionListByLoginUidOrderbyUpdateTime(long loginUid, int pageIndex) {
-		return attentionDao.list(
-				"from Attention a where a.show=1 and a.videoInfo.show=1 and a.loginUser.id=? order by FROM_UNIXTIME(a.videoInfo.updatetime/1000) desc",
-				(pageIndex - 1) * Constant.pageCount, Constant.pageCount, new Serializable[] { loginUid + "" });
-	}
 
-	@SuppressWarnings("unchecked")
-	// 鑾峰彇鍏虫敞瑙嗛鐨勫姩鎬�
-	@Cacheable(value = "attentionCache", key = "'getAttentionVideoListByLoginUid'+'-'+#loginUid+'-'+#pageIndex")
-	public List<Attention> getAttentionVideoListByLoginUid(final long loginUid, final int pageIndex) {
-		final Map<Long, Object> map = new HashMap<Long, Object>();
-		final List<Attention> newList = getAttentionListByLoginUidOrderbyUpdateTime(loginUid, pageIndex);
-		List<Attention> list = (List<Attention>) attentionDao.excute(new HibernateCallback<List<Attention>>() {
-			public List<Attention> doInHibernate(Session session) throws HibernateException {
+    public long getAttentionCountByLoginUid(long loginUid) {
+        return attentionDao.getCount(
+                "select count(*) from Attention a where a.show=1 and a.videoInfo.show=1 and a.loginUser.id=?",
+                new Serializable[]{loginUid + ""});
+    }
 
-				try {
-					for (Attention at : newList) {
-						List<VideoResource> resourceList = session
-								.createQuery(
-										"select rv.resource from ResourceVideo rv where rv.video.id=? order by (15- rv.resource.id)")
-								.setParameter(0, at.getVideoInfo().getId()).list();
-						map.put(at.getId(), resourceList.get(0));
-					}
-				} catch (Exception e) {
-					e.printStackTrace();
-				}
+    public List<Attention> getAttentionListByLoginUidOrderbyUpdateTime(long loginUid, int pageIndex) {
+        return attentionDao.list(
+                "from Attention a where a.show=1 and a.videoInfo.show=1 and a.loginUser.id=? order by FROM_UNIXTIME(a.videoInfo.updatetime/1000) desc",
+                (pageIndex - 1) * Constant.pageCount, Constant.pageCount, new Serializable[]{loginUid + ""});
+    }
 
-				return newList;
-			}
-		});
+    @SuppressWarnings("unchecked")
+    // 鑾峰彇鍏虫敞瑙嗛鐨勫姩鎬�
+    @Cacheable(value = "attentionCache", key = "'getAttentionVideoListByLoginUid'+'-'+#loginUid+'-'+#pageIndex")
+    public List<Attention> getAttentionVideoListByLoginUid(final long loginUid, final int pageIndex) {
+        final Map<Long, Object> map = new HashMap<Long, Object>();
+        final List<Attention> newList = getAttentionListByLoginUidOrderbyUpdateTime(loginUid, pageIndex);
+        List<Attention> list = (List<Attention>) attentionDao.excute(new HibernateCallback<List<Attention>>() {
+            public List<Attention> doInHibernate(Session session) throws HibernateException {
 
-		for (Attention at : list) {
-			if (map.get(at.getId()) != null) {
-				VideoResource vr = (VideoResource) map.get(at.getId());
-				VideoDetailInfo detail = videoDetailUtil.getLatestVideoDetail(at.getVideoInfo().getId(), vr);
-				List<VideoDetailInfo> detailInfos = new ArrayList<>();
-				detailInfos.add(detail);
-				at.getVideoInfo().setVideoDetailList(detailInfos);
-			}
-		}
-		// Comparator<Attention> cm = new Comparator<Attention>() {
-		//
-		// public int compare(Attention o1, Attention o2) {// 鍊掑簭鎺掑垪
-		// return (int) (Long.parseLong(o2.getVideoInfo().getUpdatetime())
-		// - Long.parseLong(o1.getVideoInfo().getUpdatetime()));
-		// }
-		// };
-		// Collections.sort(list, cm);
+                try {
+                    for (Attention at : newList) {
+                        List<VideoResource> resourceList = session
+                                .createQuery(
+                                        "select rv.resource from ResourceVideo rv where rv.video.id=? order by (15- rv.resource.id)")
+                                .setParameter(0, at.getVideoInfo().getId()).list();
+                        map.put(at.getId(), resourceList.get(0));
+                    }
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
 
-		if (list != null) {
-			for (int i = 0; i < list.size(); i++) {
-				list.get(i).getVideoInfo().setAdmin(null);
-				list.get(i).getVideoInfo().setIntroduction("");
-				list.get(i).getVideoInfo().setUpdatetime(
-						TimeUtil.getCommentTime(Long.parseLong(list.get(i).getVideoInfo().getUpdatetime())));
-			}
-		}
+                return newList;
+            }
+        });
 
-		return list;
-	}
+        for (Attention at : list) {
+            if (map.get(at.getId()) != null) {
+                VideoResource vr = (VideoResource) map.get(at.getId());
+                VideoDetailInfo detail = videoDetailUtil.getLatestVideoDetail(at.getVideoInfo().getId(), vr);
+                List<VideoDetailInfo> detailInfos = new ArrayList<>();
+                detailInfos.add(detail);
+                at.getVideoInfo().setVideoDetailList(detailInfos);
+            }
+        }
+        // Comparator<Attention> cm = new Comparator<Attention>() {
+        //
+        // public int compare(Attention o1, Attention o2) {// 鍊掑簭鎺掑垪
+        // return (int) (Long.parseLong(o2.getVideoInfo().getUpdatetime())
+        // - Long.parseLong(o1.getVideoInfo().getUpdatetime()));
+        // }
+        // };
+        // Collections.sort(list, cm);
 
-	// 鏍规嵁VideoId鏌ユ壘鏄皝鍏虫敞鐨�
-	public List<LoginUser> getUserListByAttentionVideo(String videoid) {
-		return loginUserDao.list("select a.loginUser from Attention a where a.videoInfo.id=" + videoid);
-	}
+        if (list != null) {
+            for (int i = 0; i < list.size(); i++) {
+                list.get(i).getVideoInfo().setAdmin(null);
+                list.get(i).getVideoInfo().setIntroduction("");
+                list.get(i).getVideoInfo().setUpdatetime(
+                        TimeUtil.getCommentTime(Long.parseLong(list.get(i).getVideoInfo().getUpdatetime())));
+            }
+        }
+
+        return list;
+    }
+
+    // 鏍规嵁VideoId鏌ユ壘鏄皝鍏虫敞鐨�
+    public List<LoginUser> getUserListByAttentionVideo(String videoid) {
+        return loginUserDao.list("select a.loginUser from Attention a where a.videoInfo.id=" + videoid);
+    }
 
 }

--
Gitblit v1.8.0