Parcourir la source

message list 分页

傅行帆 il y a 6 ans
Parent
révision
acc2c6db41

+ 6
- 0
CODE/smart-community/app-api/pom.xml Voir le fichier

@@ -71,6 +71,12 @@
71 71
 			<version>1.3.2</version>
72 72
 		</dependency>
73 73
 
74
+		<dependency>
75
+			<groupId>com.github.pagehelper</groupId>
76
+			<artifactId>pagehelper-spring-boot-starter</artifactId>
77
+			<version>1.2.3</version>
78
+		</dependency>
79
+
74 80
 		<dependency>
75 81
 			<groupId>mysql</groupId>
76 82
 			<artifactId>mysql-connector-java</artifactId>

+ 0
- 6
CODE/smart-community/app-api/src/main/java/com/community/huiju/common/code/impl/PhoneCodeImpl.java Voir le fichier

@@ -1,17 +1,11 @@
1 1
 package com.community.huiju.common.code.impl;
2 2
 
3
-import com.alibaba.fastjson.JSONObject;
4 3
 import com.community.commom.constant.Constant;
5
-import com.community.commom.utils.HttpClientUtils;
6 4
 import com.community.huiju.common.code.ICode;
7
-import com.community.huiju.common.code.entity.CodeEntity;
8
-import lombok.extern.log4j.Log4j;
9 5
 import lombok.extern.slf4j.Slf4j;
10 6
 import okhttp3.*;
11 7
 import org.springframework.beans.factory.annotation.Autowired;
12 8
 import org.springframework.stereotype.Service;
13
-import org.springframework.util.LinkedMultiValueMap;
14
-import org.springframework.util.MultiValueMap;
15 9
 import org.springframework.web.client.RestTemplate;
16 10
 
17 11
 import java.io.IOException;

+ 32
- 4
CODE/smart-community/app-api/src/main/java/com/community/huiju/controller/MessageController.java Voir le fichier

@@ -1,7 +1,9 @@
1 1
 package com.community.huiju.controller;
2 2
 
3
+import com.community.commom.constant.Constant;
3 4
 import com.community.commom.mode.ResponseBean;
4 5
 import com.community.huiju.model.ToCommunities;
6
+import com.community.huiju.model.TpMessage;
5 7
 import com.community.huiju.service.MessageServiceI;
6 8
 import io.swagger.annotations.Api;
7 9
 import io.swagger.annotations.ApiImplicitParam;
@@ -9,6 +11,7 @@ import io.swagger.annotations.ApiImplicitParams;
9 11
 import io.swagger.annotations.ApiOperation;
10 12
 import org.springframework.beans.factory.annotation.Autowired;
11 13
 import org.springframework.cloud.context.config.annotation.RefreshScope;
14
+import org.springframework.web.bind.annotation.PathVariable;
12 15
 import org.springframework.web.bind.annotation.RequestMapping;
13 16
 import org.springframework.web.bind.annotation.RequestMethod;
14 17
 import org.springframework.web.bind.annotation.RequestParam;
@@ -30,12 +33,37 @@ public class MessageController {
30 33
 	@Autowired
31 34
 	private MessageServiceI messageService;
32 35
 	
33
-	@ApiOperation(value = "根据小区名获取小区列表", notes = "根据小区名获取小区列表")
34
-	@RequestMapping(value = "/message/total",method = RequestMethod.GET)
35
-	public ResponseBean getMessageTotal(){
36
+	@ApiOperation(value = "按小区获取消息总数", notes = "按小区获取个人消息总数")
37
+	@ApiImplicitParams({ @ApiImplicitParam(paramType = "path", dataType = "String", name = "communityId", value = "小区Id") })
38
+	@RequestMapping(value = "/message/{communityId}/total",method = RequestMethod.GET)
39
+	public ResponseBean getMessageTotal(@PathVariable Integer communityId){
36 40
 		ResponseBean responseBean = new ResponseBean();
37
-		Map<String,Object> totalMap = messageService.getMessageTotal();
41
+		Map<String,Object> totalMap = messageService.getMessageTotal(communityId);
38 42
 		responseBean.addSuccess(totalMap);
39 43
 		return responseBean;
40 44
 	}
45
+	
46
+	@ApiOperation(value = "按小区获取分页消息", notes = "按小区获取分页消息")
47
+	@ApiImplicitParams({ @ApiImplicitParam(paramType = "path", dataType = "String", name = "communityId", value = "小区Id"),
48
+			@ApiImplicitParam(paramType = "query", dataType = "integer", name = "pageNum", value = "分页第几页"),
49
+			@ApiImplicitParam(paramType = "query", dataType = "integer", name = "pageSize", value = "分页每页长度")})
50
+	@RequestMapping(value = "/message/{communityId}/news",method = RequestMethod.GET)
51
+	public ResponseBean getNews(@PathVariable Integer communityId,@RequestParam Integer pageNum,@RequestParam Integer pageSize){
52
+		ResponseBean responseBean = new ResponseBean();
53
+		List<TpMessage> newsList = messageService.getMessages(communityId,pageNum,pageSize, Constant.MODEL_TYPE_NEWS);
54
+		responseBean.addSuccess(newsList);
55
+		return responseBean;
56
+	}
57
+	
58
+	@ApiOperation(value = "按小区获取分页待办", notes = "按小区获取分页待办")
59
+	@ApiImplicitParams({ @ApiImplicitParam(paramType = "path", dataType = "String", name = "communityId", value = "小区Id"),
60
+			@ApiImplicitParam(paramType = "query", dataType = "integer", name = "pageNum", value = "分页第几页"),
61
+			@ApiImplicitParam(paramType = "query", dataType = "integer", name = "pageSize", value = "分页每页长度")})
62
+	@RequestMapping(value = "/message/{communityId}/upcoming",method = RequestMethod.GET)
63
+	public ResponseBean getUpcoming(@PathVariable Integer communityId,@RequestParam Integer pageNum,@RequestParam Integer pageSize){
64
+		ResponseBean responseBean = new ResponseBean();
65
+		List<TpMessage> upcomingList = messageService.getMessages(communityId,pageNum,pageSize,Constant.MODEL_TYPE_UPCOMING);
66
+		responseBean.addSuccess(upcomingList);
67
+		return responseBean;
68
+	}
41 69
 }

+ 4
- 1
CODE/smart-community/app-api/src/main/java/com/community/huiju/dao/TpMessageMapper.java Voir le fichier

@@ -4,6 +4,7 @@ import com.community.huiju.model.TpMessage;
4 4
 import org.apache.ibatis.annotations.Mapper;
5 5
 import org.apache.ibatis.annotations.Param;
6 6
 
7
+import java.util.List;
7 8
 import java.util.Map;
8 9
 
9 10
 @Mapper
@@ -20,5 +21,7 @@ public interface TpMessageMapper {
20 21
 
21 22
     int updateByPrimaryKey(TpMessage record);
22 23
     
23
-    Map<String, Object> getMessageTotal(@Param(value="userId") Integer userId);
24
+    Map<String, Object> getMessageTotal(@Param(value = "userId") Integer userId,@Param(value = "communityId") Integer communityId);
25
+    
26
+    List<TpMessage> getMessages(@Param(value = "userId") Integer userId,@Param(value = "communityId") Integer communityId, @Param(value = "modelType") Integer modelType);
24 27
 }

+ 19
- 1
CODE/smart-community/app-api/src/main/java/com/community/huiju/service/MessageServiceI.java Voir le fichier

@@ -1,7 +1,25 @@
1 1
 package com.community.huiju.service;
2 2
 
3
+import com.community.huiju.model.TpMessage;
4
+
5
+import java.util.List;
3 6
 import java.util.Map;
4 7
 
5 8
 public interface MessageServiceI {
6
-	Map<String, Object> getMessageTotal();
9
+	/**
10
+	 * 获取消息数量
11
+	 * @param communityId
12
+	 * @return
13
+	 */
14
+	Map<String, Object> getMessageTotal(Integer communityId);
15
+	
16
+	/**
17
+	 * 分页获取消息或待办
18
+	 * @param communityId
19
+	 * @param pageNum
20
+	 * @param pageSize
21
+	 * @param modelType
22
+	 * @return
23
+	 */
24
+	List<TpMessage> getMessages(Integer communityId, Integer pageNum, Integer pageSize,Integer modelType);
7 25
 }

+ 30
- 2
CODE/smart-community/app-api/src/main/java/com/community/huiju/service/impl/MessageServiceImpl.java Voir le fichier

@@ -1,10 +1,13 @@
1 1
 package com.community.huiju.service.impl;
2 2
 
3 3
 import com.community.huiju.dao.TpMessageMapper;
4
+import com.community.huiju.model.TpMessage;
4 5
 import com.community.huiju.service.MessageServiceI;
6
+import com.github.pagehelper.PageHelper;
5 7
 import org.springframework.beans.factory.annotation.Autowired;
6 8
 import org.springframework.stereotype.Service;
7 9
 
10
+import java.util.List;
8 11
 import java.util.Map;
9 12
 
10 13
 /**
@@ -17,9 +20,34 @@ public class MessageServiceImpl implements MessageServiceI {
17 20
 	@Autowired
18 21
 	private TpMessageMapper tpMessageMapper;
19 22
 	
23
+	/**
24
+	 * 获取消息数量
25
+	 * @param communityId
26
+	 * @return
27
+	 */
20 28
 	@Override
21
-	public Map<String, Object> getMessageTotal() {
29
+	public Map<String, Object> getMessageTotal(Integer communityId) {
22 30
 		Integer userId = 1;
23
-		return tpMessageMapper.getMessageTotal(userId);
31
+		return tpMessageMapper.getMessageTotal(userId,communityId);
32
+	}
33
+	
34
+	/**
35
+	 * 分页获取消息或待办
36
+	 * @param communityId
37
+	 * @param pageNum
38
+	 * @param pageSize
39
+	 * @param modelType
40
+	 * @return
41
+	 */
42
+	@Override
43
+	public List<TpMessage> getMessages(Integer communityId, Integer pageNum, Integer pageSize,Integer modelType) {
44
+		Integer userId = 1;
45
+		pageNum = null == pageNum ? 1 : pageNum;
46
+		pageSize = null == pageSize ? 10 : pageSize;
47
+		//使用分页插件
48
+		PageHelper.startPage(pageNum, pageSize);
49
+		// 获取数据
50
+		List<TpMessage> messageList = tpMessageMapper.getMessages(userId,communityId, modelType);
51
+		return messageList;
24 52
 	}
25 53
 }

+ 11
- 1
CODE/smart-community/app-api/src/main/resources/application.yml Voir le fichier

@@ -6,4 +6,14 @@ management:
6 6
 ## Mybatis
7 7
 mybatis:
8 8
   typeAliasesPackage: com.community.huiju.model
9
-  mapperLocations: classpath:mapper/*.xml
9
+  mapperLocations: classpath:mapper/*.xml
10
+# 分页配置
11
+pagehelper:
12
+  helper-dialect: mysql
13
+  reasonable: true
14
+  support-methods-arguments: true
15
+  params: count=countSql
16
+# 打印sql
17
+logging:
18
+  level:
19
+    com.community.huiju.dao: debug

+ 16
- 1
CODE/smart-community/app-api/src/main/resources/mapper/TpMessageMapper.xml Voir le fichier

@@ -233,7 +233,7 @@
233 233
     where id = #{id,jdbcType=INTEGER}
234 234
   </update>
235 235
 
236
-  <select id="getMessageTotal" resultType="map" parameterType="java.lang.Integer" >
236
+  <select id="getMessageTotal" resultType="map">
237 237
     SELECT
238 238
         count( CASE WHEN model_type = 1 AND read_status = 0 THEN 1 ELSE NULL END ) AS messageTotal,
239 239
         count( CASE WHEN model_type = 2 THEN 1 ELSE NULL END ) AS toDoTotal
@@ -241,8 +241,23 @@
241 241
         tp_message
242 242
     WHERE
243 243
         uuid_type = 1
244
+        AND community_id = #{communityId,jdbcType=INTEGER}
244 245
         AND uuid = #{userId,jdbcType=INTEGER}
245 246
         AND STATUS = 1
246 247
         AND advice_type = 1
247 248
   </select>
249
+
250
+  <select id="getMessages" resultMap="BaseResultMap">
251
+    SELECT
252
+      <include refid="Base_Column_List" />
253
+    FROM
254
+        tp_message
255
+    WHERE
256
+        uuid_type = 1
257
+        AND community_id = #{communityId,jdbcType=INTEGER}
258
+        AND uuid = #{userId,jdbcType=INTEGER}
259
+        AND STATUS = 1
260
+        AND advice_type = 1
261
+        AND model_type = #{modelType,jdbcType=INTEGER}
262
+  </select>
248 263
 </mapper>

+ 6
- 2
CODE/smart-community/community-common/src/main/java/com/community/commom/constant/Constant.java Voir le fichier

@@ -23,6 +23,10 @@ public class Constant {
23 23
 
24 24
     /** 请求发送验证码的远程服务器地址 **/
25 25
     public static final String REQUEST_URL = "http://micservice.ycjcjy.com/sms";
26
-
27
-
26
+    
27
+    /** 住户APP端消息 **/
28
+    public static final Integer MODEL_TYPE_NEWS = 1;
29
+    
30
+    /** 住户APP端待办 **/
31
+    public static final Integer MODEL_TYPE_UPCOMING = 2;
28 32
 }

BIN
CODE/smart-community/community-common/target/classes/com/community/commom/constant/Constant.class Voir le fichier