瀏覽代碼

获取论坛活动帖子详情

傅行帆 6 年之前
父節點
當前提交
47937d2a18

+ 1
- 1
CODE/smart-community/app-api/src/main/java/com/community/huiju/controller/SocialController.java 查看文件

@@ -24,7 +24,7 @@ import java.util.List;
24 24
 @RestController
25 25
 @RefreshScope
26 26
 @RequestMapping("/")
27
-@Api("app端论坛相关的API")
27
+@Api(value = "app端论坛相关的API", description = "app端论坛相关的API")
28 28
 public class SocialController {
29 29
 
30 30
     @Autowired

+ 1
- 1
CODE/smart-community/app-api/src/main/java/com/community/huiju/dao/TpActivityMapper.java 查看文件

@@ -15,7 +15,7 @@ public interface TpActivityMapper {
15 15
 
16 16
     int insertSelective(TpActivity record);
17 17
 
18
-    TpActivity selectByPrimaryKey(Integer id);
18
+    TpActivity selectByPrimaryKey(@Param("id") Integer id,@Param("communityId") Integer communityId);
19 19
 
20 20
     int updateByPrimaryKeySelective(TpActivity record);
21 21
 

+ 41
- 12
CODE/smart-community/app-api/src/main/java/com/community/huiju/service/impl/SocialServiceImpl.java 查看文件

@@ -41,19 +41,11 @@ public class SocialServiceImpl implements SocialServiceI {
41 41
     @Override
42 42
     @Transactional
43 43
     public TpAnnouncement findAnnouncementDetail(Integer id, Integer communityId) {
44
-        TpSocialView tpSocialView = new TpSocialView();
45 44
         //TODO
46
-        tpSocialView.setTaUserId(1);
47
-        tpSocialView.setSocialType(Constant.ANNOUNCEMENT);
48
-        tpSocialView.setCommunityId(communityId);
49
-        tpSocialView.setUuid(id);
50
-        Integer viewNum = tpSocialViewMapper.selectViewNum(tpSocialView);
51
-
52
-        if (viewNum == 0){
53
-            tpSocialView.setCreateDate(new Date());
54
-            tpSocialViewMapper.insertSelective(tpSocialView);
55
-            tpSocialView.setTaUserId(null);
56
-            Integer allViewNum = tpSocialViewMapper.selectViewNum(tpSocialView);
45
+        Integer userId = 1;
46
+        //更新此用户的查看次数操作
47
+        Integer allViewNum = updateSocialView(userId,Constant.ANNOUNCEMENT,communityId,id);
48
+        if (null != allViewNum){
57 49
             tpAnnouncementMapper.updateByPrimaryKeySelective(id, allViewNum);
58 50
         }
59 51
         return tpAnnouncementMapper.selectByPrimaryKey(id, communityId);
@@ -113,6 +105,43 @@ public class SocialServiceImpl implements SocialServiceI {
113 105
      */
114 106
     @Override
115 107
     public TpActivity findActivityDetail(Integer activityId, Integer communityId) {
108
+        //TODO
109
+        Integer userId = 1;
110
+        //更新查看次数
111
+        Integer allViewNum = updateSocialView(userId,Constant.ACTIVITY,communityId,activityId);
112
+        if (null != allViewNum){
113
+            TpActivity activity = new TpActivity();
114
+            activity.setId(activityId);
115
+            activity.setViewCount(allViewNum);
116
+            tpActivityMapper.updateByPrimaryKeySelective(activity);
117
+        }
118
+        return tpActivityMapper.selectByPrimaryKey(activityId,communityId);
119
+    }
120
+    
121
+    /**
122
+     * 更新此用户的查看次数操作
123
+     * @param userId
124
+     * @param socialType
125
+     * @param communityId
126
+     * @param uuid
127
+     */
128
+    private Integer updateSocialView(Integer userId,String socialType,Integer communityId,Integer uuid) {
129
+        //检查是否查看过这个帖子
130
+        TpSocialView tpSocialView = new TpSocialView();
131
+        tpSocialView.setTaUserId(userId);
132
+        tpSocialView.setSocialType(socialType);
133
+        tpSocialView.setCommunityId(communityId);
134
+        tpSocialView.setUuid(uuid);
135
+        Integer viewNum = tpSocialViewMapper.selectViewNum(tpSocialView);
136
+    
137
+        //查看过的话查看次数加一
138
+        if (viewNum == 0){
139
+            tpSocialView.setCreateDate(new Date());
140
+            tpSocialViewMapper.insertSelective(tpSocialView);
141
+            tpSocialView.setTaUserId(null);
142
+            Integer allViewNum = tpSocialViewMapper.selectViewNum(tpSocialView);
143
+            return allViewNum;
144
+        }
116 145
         return null;
117 146
     }
118 147
 }

+ 1
- 1
CODE/smart-community/app-api/src/main/resources/mapper/TpActivityMapper.xml 查看文件

@@ -32,7 +32,7 @@
32 32
     select 
33 33
     <include refid="Base_Column_List" />
34 34
     from tp_activity
35
-    where id = #{id,jdbcType=INTEGER}
35
+    where id = #{id,jdbcType=INTEGER} and #{communityId,jdbcType=INTEGER}
36 36
   </select>
37 37
   <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
38 38
     delete from tp_activity

+ 3
- 3
CODE/smart-community/app-api/src/main/resources/mapper/TpSocialViewMapper.xml 查看文件

@@ -117,11 +117,11 @@
117 117
 
118 118
   <select id="selectViewNum" resultType="java.lang.Integer" parameterType="com.community.huiju.model.TpSocialView">
119 119
     select count(*) from tp_social_view
120
-    where
120
+    where 1=1
121 121
     <if test="taUserId != null" >
122
-      ta_user_id = #{taUserId} and
122
+      and ta_user_id = #{taUserId}
123 123
     </if>
124
-    uuid = #{uuid}
124
+    and uuid = #{uuid}
125 125
     and community_id = #{communityId}
126 126
     and social_type = #{socialType}
127 127
   </select>