Browse Source

获取论坛活动帖子详情

傅行帆 6 years ago
parent
commit
47937d2a18

+ 1
- 1
CODE/smart-community/app-api/src/main/java/com/community/huiju/controller/SocialController.java View File

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

+ 1
- 1
CODE/smart-community/app-api/src/main/java/com/community/huiju/dao/TpActivityMapper.java View File

15
 
15
 
16
     int insertSelective(TpActivity record);
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
     int updateByPrimaryKeySelective(TpActivity record);
20
     int updateByPrimaryKeySelective(TpActivity record);
21
 
21
 

+ 41
- 12
CODE/smart-community/app-api/src/main/java/com/community/huiju/service/impl/SocialServiceImpl.java View File

41
     @Override
41
     @Override
42
     @Transactional
42
     @Transactional
43
     public TpAnnouncement findAnnouncementDetail(Integer id, Integer communityId) {
43
     public TpAnnouncement findAnnouncementDetail(Integer id, Integer communityId) {
44
-        TpSocialView tpSocialView = new TpSocialView();
45
         //TODO
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
             tpAnnouncementMapper.updateByPrimaryKeySelective(id, allViewNum);
49
             tpAnnouncementMapper.updateByPrimaryKeySelective(id, allViewNum);
58
         }
50
         }
59
         return tpAnnouncementMapper.selectByPrimaryKey(id, communityId);
51
         return tpAnnouncementMapper.selectByPrimaryKey(id, communityId);
113
      */
105
      */
114
     @Override
106
     @Override
115
     public TpActivity findActivityDetail(Integer activityId, Integer communityId) {
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
         return null;
145
         return null;
117
     }
146
     }
118
 }
147
 }

+ 1
- 1
CODE/smart-community/app-api/src/main/resources/mapper/TpActivityMapper.xml View File

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

+ 3
- 3
CODE/smart-community/app-api/src/main/resources/mapper/TpSocialViewMapper.xml View File

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