Commit 1e30cfe4 1e30cfe40d8837ef08cbaae5506343088d996c3b by xianghan

1.去除消费任务时的部分查询,直接将消息传递至uce

1 parent 495bb3c6
...@@ -12,6 +12,8 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -12,6 +12,8 @@ import org.springframework.beans.factory.annotation.Autowired;
12 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; 12 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
13 import org.springframework.stereotype.Service; 13 import org.springframework.stereotype.Service;
14 14
15 import java.util.Objects;
16
15 /** 17 /**
16 * 18 *
17 */ 19 */
...@@ -34,8 +36,10 @@ public class ExpOperationServiceImpl implements ExpOperationService { ...@@ -34,8 +36,10 @@ public class ExpOperationServiceImpl implements ExpOperationService {
34 public void asyncExpDetail(ExpDetail expDetail) { 36 public void asyncExpDetail(ExpDetail expDetail) {
35 String code = expDetail.getMemberCode(); 37 String code = expDetail.getMemberCode();
36 MemberDTO memberDTO = this.memberService.findByCode(code); 38 MemberDTO memberDTO = this.memberService.findByCode(code);
37 expDetail.setMemberId(memberDTO.getId()); 39 if (Objects.nonNull(memberDTO.getId())) {
40 expDetail.setMemberId(memberDTO.getId());
41 this.expDetailService.create(expDetail);
42 }
38 43
39 this.expDetailService.create(expDetail);
40 } 44 }
41 } 45 }
......
...@@ -7,29 +7,18 @@ import com.topdraw.business.module.member.service.dto.MemberDTO; ...@@ -7,29 +7,18 @@ import com.topdraw.business.module.member.service.dto.MemberDTO;
7 import com.topdraw.business.module.points.available.domain.PointsAvailable; 7 import com.topdraw.business.module.points.available.domain.PointsAvailable;
8 import com.topdraw.business.module.points.available.service.PointsAvailableService; 8 import com.topdraw.business.module.points.available.service.PointsAvailableService;
9 import com.topdraw.business.module.points.available.service.dto.PointsAvailableDTO; 9 import com.topdraw.business.module.points.available.service.dto.PointsAvailableDTO;
10 import com.topdraw.business.module.points.detail.detailhistory.service.PointsDetailHistoryService;
11 import com.topdraw.business.module.points.detail.domain.PointsDetail; 10 import com.topdraw.business.module.points.detail.domain.PointsDetail;
12 import com.topdraw.business.module.points.detail.service.PointsDetailService; 11 import com.topdraw.business.module.points.detail.service.PointsDetailService;
13 import com.topdraw.business.module.points.service.PointsService;
14 import com.topdraw.business.process.domian.TempPoints;
15 import com.topdraw.business.process.service.PointsOperationService; 12 import com.topdraw.business.process.service.PointsOperationService;
16 import com.topdraw.business.process.service.member.MemberOperationService;
17 import com.topdraw.util.IdWorker;
18 import com.topdraw.util.TimestampUtil;
19 import com.topdraw.utils.StringUtils; 13 import com.topdraw.utils.StringUtils;
20 import lombok.extern.slf4j.Slf4j; 14 import lombok.extern.slf4j.Slf4j;
21 import org.springframework.beans.BeanUtils;
22 import org.springframework.beans.factory.annotation.Autowired; 15 import org.springframework.beans.factory.annotation.Autowired;
23 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; 16 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
24 import org.springframework.stereotype.Service; 17 import org.springframework.stereotype.Service;
25 import org.springframework.transaction.annotation.Propagation; 18 import org.springframework.transaction.annotation.Propagation;
26 import org.springframework.transaction.annotation.Transactional; 19 import org.springframework.transaction.annotation.Transactional;
27 import org.springframework.util.CollectionUtils;
28 20
29 import javax.validation.constraints.NotNull;
30 import java.time.LocalDateTime;
31 import java.util.*; 21 import java.util.*;
32 import java.util.stream.Collectors;
33 22
34 /** 23 /**
35 * 24 *
...@@ -56,22 +45,28 @@ public class PointsOperationServiceImpl implements PointsOperationService { ...@@ -56,22 +45,28 @@ public class PointsOperationServiceImpl implements PointsOperationService {
56 return; 45 return;
57 } 46 }
58 MemberDTO memberDTO = this.memberService.findByCode(code); 47 MemberDTO memberDTO = this.memberService.findByCode(code);
59 member.setId(memberDTO.getId()); 48 if (Objects.nonNull(memberDTO.getId())) {
60 this.memberService.doUpdateMemberPoints(member); 49 member.setId(memberDTO.getId());
50 this.memberService.doUpdateMemberPoints(member);
51 }
61 } 52 }
62 53
63 public void asyncPointsAvailable(PointsAvailable pointsAvailable) { 54 public void asyncPointsAvailable(PointsAvailable pointsAvailable) {
64 String memberCode = pointsAvailable.getMemberCode(); 55 String memberCode = pointsAvailable.getMemberCode();
65 MemberDTO memberDTO = this.memberService.findByCode(memberCode); 56 MemberDTO memberDTO = this.memberService.findByCode(memberCode);
66 pointsAvailable.setMemberId(memberDTO.getId()); 57 if (Objects.nonNull(memberDTO.getId())) {
67 this.pointsAvailableService.create4Custom(pointsAvailable); 58 pointsAvailable.setMemberId(memberDTO.getId());
59 this.pointsAvailableService.create4Custom(pointsAvailable);
60 }
68 } 61 }
69 62
70 public void asyncPointsDetail(PointsDetail pointsDetail) { 63 public void asyncPointsDetail(PointsDetail pointsDetail) {
71 String memberCode = pointsDetail.getMemberCode(); 64 String memberCode = pointsDetail.getMemberCode();
72 MemberDTO memberDTO = this.memberService.findByCode(memberCode); 65 MemberDTO memberDTO = this.memberService.findByCode(memberCode);
73 pointsDetail.setMemberId(memberDTO.getId()); 66 if (Objects.nonNull(memberDTO.getId())) {
74 this.pointsDetailService.create4Custom(pointsDetail); 67 pointsDetail.setMemberId(memberDTO.getId());
68 this.pointsDetailService.create4Custom(pointsDetail);
69 }
75 } 70 }
76 71
77 public void asyncDeletePointsAvailable(PointsAvailable pointsAvailable) { 72 public void asyncDeletePointsAvailable(PointsAvailable pointsAvailable) {
......
1 package com.topdraw.config.redis; 1 package com.topdraw.config;
2 2
3 /** 3 /**
4 * @author : 4 * @author :
5 * @description: 5 * @description:
6 * @function : 6 * @function :
7 * @date :Created in 2022/6/18 17:22 7 * @date :Created in 2022/6/13 11:22
8 * @version: : 8 * @version: :
9 * @modified By: 9 * @modified By:
10 * @since : modified in 2022/6/18 17:22 10 * @since : modified in 2022/6/13 11:22
11 */ 11 */
12 public class RedisKeyConstant { 12 public interface ResponseStatus {
13 13
14 Integer OK = 00000;
14 15
15 public static final String CACHE_PLATFROMACCOUNT_PLAYDURATION = "ucc::play::playduration::";
16 } 16 }
......
1 package com.topdraw.mq.consumer; 1 package com.topdraw.mq.consumer;
2 2
3 import com.alibaba.fastjson.JSON;
4 import com.alibaba.fastjson.JSONObject; 3 import com.alibaba.fastjson.JSONObject;
5 import com.rabbitmq.client.Channel; 4 import com.rabbitmq.client.Channel;
6 import com.topdraw.business.module.member.service.MemberService;
7 import com.topdraw.business.module.member.service.dto.MemberDTO;
8 import com.topdraw.business.module.task.attribute.service.TaskAttrService;
9 import com.topdraw.business.module.task.attribute.service.dto.TaskAttrDTO;
10 import com.topdraw.business.module.task.domain.Task;
11 import com.topdraw.business.module.task.service.TaskService;
12 import com.topdraw.business.module.task.template.constant.TaskEventName; 5 import com.topdraw.business.module.task.template.constant.TaskEventName;
13 import com.topdraw.business.module.task.template.constant.TaskEventType; 6 import com.topdraw.business.module.task.template.constant.TaskEventType;
14 import com.topdraw.business.module.task.template.service.TaskTemplateService;
15 import com.topdraw.business.module.task.template.service.dto.TaskTemplateDTO;
16 import com.topdraw.business.module.user.iptv.service.UserTvService;
17 import com.topdraw.business.module.user.iptv.service.dto.UserTvDTO;
18 import com.topdraw.config.redis.RedisKeyConstant;
19 import com.topdraw.exception.BadRequestException; 7 import com.topdraw.exception.BadRequestException;
20 import com.topdraw.exception.EntityNotFoundException;
21 import com.topdraw.mq.domain.DataSyncMsg; 8 import com.topdraw.mq.domain.DataSyncMsg;
22 import com.topdraw.resttemplate.RestTemplateClient; 9 import com.topdraw.resttemplate.RestTemplateClient;
23 import com.topdraw.util.DateUtil;
24 import com.topdraw.util.FileUtil; 10 import com.topdraw.util.FileUtil;
25 import com.topdraw.util.JSONUtil; 11 import com.topdraw.util.JSONUtil;
26 import com.topdraw.utils.RedisUtils;
27 import lombok.Data; 12 import lombok.Data;
28 import lombok.extern.slf4j.Slf4j; 13 import lombok.extern.slf4j.Slf4j;
29 import org.apache.commons.collections4.CollectionUtils;
30 import org.apache.commons.collections4.MapUtils; 14 import org.apache.commons.collections4.MapUtils;
31 import org.apache.commons.lang3.StringUtils; 15 import org.apache.commons.lang3.StringUtils;
32 import org.springframework.amqp.core.Message; 16 import org.springframework.amqp.core.Message;
33 import org.springframework.amqp.rabbit.annotation.*; 17 import org.springframework.amqp.rabbit.annotation.*;
34 import org.springframework.beans.factory.annotation.Autowired; 18 import org.springframework.beans.factory.annotation.Autowired;
35 import org.springframework.beans.factory.annotation.Value; 19 import org.springframework.beans.factory.annotation.Value;
36 import org.springframework.data.redis.core.RedisTemplate;
37 import org.springframework.stereotype.Component; 20 import org.springframework.stereotype.Component;
38 import org.springframework.web.server.ResponseStatusException;
39 21
40 import java.io.IOException; 22 import java.io.IOException;
41 import java.text.ParseException;
42 import java.time.LocalDate; 23 import java.time.LocalDate;
43 import java.time.LocalDateTime; 24 import java.time.LocalDateTime;
44 import java.util.*; 25 import java.util.*;
...@@ -48,19 +29,7 @@ import java.util.*; ...@@ -48,19 +29,7 @@ import java.util.*;
48 public class UcEventBusIptv2ManagementUcEngine { 29 public class UcEventBusIptv2ManagementUcEngine {
49 30
50 @Autowired 31 @Autowired
51 private TaskService taskService;
52 @Autowired
53 private UserTvService userTvService;
54 @Autowired
55 private MemberService memberService;
56 @Autowired
57 private TaskAttrService taskAttrService;
58 @Autowired
59 private TaskTemplateService taskTemplateService;
60 @Autowired
61 private RestTemplateClient restTemplateClient; 32 private RestTemplateClient restTemplateClient;
62 @Autowired
63 private RedisUtils redisUtils;
64 33
65 @Value("#{rabbitMqErrorLogConfig.getEventBusError()}") 34 @Value("#{rabbitMqErrorLogConfig.getEventBusError()}")
66 private Map<String, String> error; 35 private Map<String, String> error;
...@@ -77,24 +46,57 @@ public class UcEventBusIptv2ManagementUcEngine { ...@@ -77,24 +46,57 @@ public class UcEventBusIptv2ManagementUcEngine {
77 containerFactory = "#{rabbitMqSourceConfig.getEventBusSource()}", 46 containerFactory = "#{rabbitMqSourceConfig.getEventBusSource()}",
78 autoStartup = "#{rabbitMqSourceConfig.getEventBusStartUp()}", 47 autoStartup = "#{rabbitMqSourceConfig.getEventBusStartUp()}",
79 ackMode = "AUTO") 48 ackMode = "AUTO")
80 public void eventBusConsumer(Channel channel, Message message, String content) throws IOException { 49 public void eventBusConsumer(Channel channel, Message message, String content) throws Exception {
81 log.info(" receive dataSync msg , content is : {} ", content); 50 log.info(" receive dataSync msg , content is ==>> {} ", content);
82 try { 51 try {
83 52
84 PlayContent playContent = JSONUtil.parseMsg2Object(content, PlayContent.class); 53 DataSyncMsg dataSyncMsg = JSONUtil.parseMsg2Object(content, DataSyncMsg.class);
85 log.info("解析后的参数 , playContent ==>> {} ", playContent); 54 log.info("解析后的参数 , playContent ==>> {} ", dataSyncMsg);
86 if (Objects.nonNull(playContent)) { 55
87 this.parseContent(playContent); 56 if (Objects.nonNull(dataSyncMsg)) {
88 } 57
58 String evt = dataSyncMsg.getEvt();
59 if (StringUtils.isBlank(evt)) {
60 log.error("eventBus事件类型(evt)为空");
61 throw new BadRequestException("参数错误,事件类型 evt不存在");
62 }
63
64 LocalDateTime time = dataSyncMsg.getTime();
65 if (Objects.isNull(time)) {
66 log.error("参数错误,事件发送时间(time)不存在");
67 throw new BadRequestException("参数错误,事件发送时间(time)不存在");
68 } /*else {
69 if (time.isAfter(LocalDateTime.now()) || time.toLocalDate().compareTo(LocalDate.now()) != 0) {
70 log.error("参数错误,事件发送时间(time)非法 ==>> {}", time);
71 throw new BadRequestException("参数错误,事件发送时间非法 ");
72 }
73 }*/
74
75 String msgData = dataSyncMsg.getMsgData();
76 if (StringUtils.isBlank(msgData)) {
77 log.error("eventBus事件消息体(msgData)为空");
78 throw new BadRequestException("参数错误,事件类型 evt不存在");
79 }
80
81 switch (dataSyncMsg.getEvt().toUpperCase()) {
82
83 // 播放记录
84 case TaskEventName.PLAY:
85 this.doPlayEvent(dataSyncMsg);
86 break;
87
88 default:
89 log.info("无可处理的任务");
90 break;
91 }
89 92
90 // channel.basicAck(message.getMessageProperties().getDeliveryTag(), false); 93 }
91 94
92 } catch (Exception e) { 95 } catch (Exception e) {
93 96
94 log.error("eventBus 消费异常 ==>> {}",e.getMessage()); 97 log.error("eventBus 消费异常 ==>> {}",e.getMessage());
95 98
96 channel.basicReject(message.getMessageProperties().getDeliveryTag(), false); 99 // TODO使用slf4j记录日志
97
98 if (MapUtils.isNotEmpty(error)) { 100 if (MapUtils.isNotEmpty(error)) {
99 String errorStart = this.error.get("start"); 101 String errorStart = this.error.get("start");
100 102
...@@ -111,299 +113,22 @@ public class UcEventBusIptv2ManagementUcEngine { ...@@ -111,299 +113,22 @@ public class UcEventBusIptv2ManagementUcEngine {
111 log.info("eventBusConsumer ====>>>> end"); 113 log.info("eventBusConsumer ====>>>> end");
112 } 114 }
113 115
114
115 /** 116 /**
116 * 数据解析 117 *
117 * @param playContent 118 * @param playContent
118 * @return
119 */ 119 */
120 private void parseContent(PlayContent playContent) throws ParseException { 120 private void doPlayEvent(DataSyncMsg playContent) {
121 PlayContent.MsgData msgData = playContent.getMsgData(); 121 playContent.setEvent(TaskEventType.PLAY);
122 if (Objects.isNull(msgData)) { 122 String msgData = playContent.getMsgData();
123 log.error("eventBus事件消息体为空,msgData ==>> {}", msgData); 123 JSONObject jsonObject = JSONObject.parseObject(msgData, JSONObject.class);
124 return; 124 Object platformAccount = jsonObject.get("platformAccount");
125 } 125 if (Objects.nonNull(platformAccount)) {
126 126 JSONObject response = this.restTemplateClient.dealTask(playContent);
127 String evt = playContent.getEvt(); 127 if (Objects.isNull(response)) {
128 switch (evt.toUpperCase()) { 128 log.error("uc-engine响应超时,请检查uc-engine服务");
129 129 throw new BadRequestException("uc-engine响应超时");
130 case TaskEventName.PLAY:
131 String time = playContent.getTime();
132 String formatDate = DateUtil.formatDate(time);
133 Integer deviceType = playContent.getDeviceType();
134 String platformAccount = msgData.getPlatformAccount();
135 if (StringUtils.isBlank(platformAccount)){
136 log.error("参数错误,platformAccount不得为空, msgData ==>> {}", msgData);
137 return;
138 }
139
140 String mediaCode = msgData.getMediaCode();
141 Long mediaId = msgData.getMediaId();
142 String mediaName = msgData.getMediaName();
143 Integer playDuration = msgData.getPlayDuration();
144 if (Objects.isNull(playDuration) || playDuration == 0) {
145 return;
146 }
147 log.info("playDuration ==>> {}", playDuration);
148
149 DataSyncMsg dataSyncMsg = new DataSyncMsg();
150 dataSyncMsg.setEvt(evt);
151 dataSyncMsg.setEvent(TaskEventType.PLAY);
152 dataSyncMsg.setTime(LocalDateTime.now());
153 dataSyncMsg.setDeviceType(deviceType);
154
155 DataSyncMsg.MsgData msg = new DataSyncMsg.MsgData();
156 msg.setPlatformAccount(platformAccount);
157 msg.setMediaId(mediaId);
158
159 Integer playDurationValueTotal = 0;
160 if (StringUtils.isNotBlank(platformAccount)) {
161
162 Long count = this.userTvService.countByPlatformAccount(platformAccount);
163 log.info("通过大屏账号查询对应记录的条数,==>> {}", count);
164
165 if(count > 0L) {
166 String key = RedisKeyConstant.CACHE_PLATFROMACCOUNT_PLAYDURATION+platformAccount+"|"+formatDate;
167
168 Map<Object, Object> hmget =
169 this.redisUtils.hmget(key);
170
171 if (MapUtils.isEmpty(hmget)) {
172
173 // 初始化播放总时长<total>和第一个播放时间
174 playDurationValueTotal = playDuration;
175 Map<String, Object> map = new HashMap<>();
176 map.put("total", playDurationValueTotal);
177 // 存储时间36小时
178 this.redisUtils.hmset(key, map, 129600);
179
180 } else {
181
182 // 计算播放总时长 total = 播放总时长+当前播放时长
183 Integer total = this.getTotalPlayDurationFromRedis(key);
184 playDurationValueTotal = total + playDuration;
185
186 }
187
188 Map<String, Object> map = new HashMap<>();
189 map.put("total", playDurationValueTotal);
190 this.redisUtils.hmset(key, map);
191
192
193 JSONObject jsonObject1 = new JSONObject();
194 jsonObject1.put("PLAYDURATION",playDurationValueTotal);
195
196 msg.setParam(JSON.toJSONString(jsonObject1));
197
198 dataSyncMsg.setMsgData(JSON.toJSONString(msg));
199 log.info("调用uc-engine的接口 ==>> /uce/taskOperation/dealTask, 参数 ==>> {}",dataSyncMsg);
200 JSONObject response = this.restTemplateClient.dealTask(dataSyncMsg);
201 if (Objects.nonNull(response)) {
202 log.info("uc-engine任务处理接口的响应结果,/uce/taskOperation/dealTask ==>> {}",response);
203 } else {
204 log.error("uc-engine响应超时,请检查uc-engine服务");
205 throw new BadRequestException("uc-engine响应超时");
206 }
207
208 }
209
210 }
211
212 break;
213 }
214
215 //return null;
216 }
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235 private DataSyncMsg checkTask(Integer playDurationValueTotal, String time, Integer deviceType, String mediaCode,
236 Long mediaId, String mediaName, DataSyncMsg dataSyncMsg,
237 DataSyncMsg.MsgData msgData, UserTvDTO userTvDTO) {
238
239 // 检查播放记录任务
240 List<TaskAttrDTO> taskAttrDTOList = new ArrayList<>();
241 // TODO 枚举
242 TaskTemplateDTO taskTemplateDTO = this.taskTemplateService.findByType(8);
243 if (Objects.nonNull(taskTemplateDTO.getId())) {
244 List<Task> taskList = this.taskService.findByTemplateId(taskTemplateDTO.getId());
245 if (CollectionUtils.isNotEmpty(taskList)) {
246
247 for (Task task : taskList) {
248 TaskAttrDTO taskAttrDTO = this.taskAttrService.findByTaskId(task.getId());
249 taskAttrDTOList.add(taskAttrDTO);
250 }
251
252 } else {
253
254 return null;
255
256 }
257
258 } else {
259
260 return null;
261
262 }
263
264 List<List<Integer>> attrList = new ArrayList<>();
265 if (CollectionUtils.isNotEmpty(taskAttrDTOList)) {
266
267 for (TaskAttrDTO taskAttrDTO : taskAttrDTOList) {
268
269 String attrStr = taskAttrDTO.getAttrStr();
270 if (StringUtils.isNotBlank(attrStr)) {
271
272 JSONObject parse = JSONObject.parseObject(attrStr, JSONObject.class);
273 List<Integer> value = (List<Integer>) parse.get("value");
274 attrList.add(value);
275 }
276
277 } 130 }
278
279 } else {
280
281 return null;
282
283 } 131 }
284
285 int size = attrList.size();
286
287 DataSyncMsg dataSyncMsg1 = null;
288
289 if (size > 0) {
290
291 for (int i = size-1; i >= 0; i--) {
292
293 Integer integer = attrList.get(i).get(0);
294
295 if (playDurationValueTotal >= integer) {
296 dataSyncMsg1 = getDataSyncMsg(time, mediaCode, mediaId, mediaName, playDurationValueTotal, dataSyncMsg,
297 msgData, userTvDTO);
298 dataSyncMsg1.setEvt("PLAY");
299 dataSyncMsg1.setEvent(8);
300 dataSyncMsg1.setTime(LocalDateTime.now());
301 dataSyncMsg1.setDeviceType(deviceType);
302 this.taskDeal(dataSyncMsg1);
303 }
304
305 }
306
307 }
308
309 return dataSyncMsg1;
310 } 132 }
311 133
312 private Integer getTotalPlayDurationFromRedis(String key) {
313 Map<Object, Object> total = this.redisUtils.hmget("key");
314 if (Objects.nonNull(total)){
315 Object total1 = total.get("total");
316 if (Objects.nonNull(total1)) {
317 return Integer.valueOf(total1.toString());
318 }
319 }
320
321 return 0;
322 }
323
324 private Integer getRedisTotalKey(Map<Object, Object> hmget) {
325 Set<Object> objects = hmget.keySet();
326 return objects.size();
327 }
328
329 private Integer getRedisTotal(Map<Object, Object> hmget) {
330 Set<Object> objects = hmget.keySet();
331
332 Integer playDurationValueTotal_ = 0;
333
334 for (Object key_ : objects) {
335
336 if (key_.toString().equalsIgnoreCase("total")) {
337 playDurationValueTotal_ = Integer.valueOf(hmget.get(key_).toString());
338 return playDurationValueTotal_;
339
340 } else {
341
342 continue;
343
344 }
345
346 }
347
348 return playDurationValueTotal_;
349
350 }
351
352 private DataSyncMsg getDataSyncMsg(String time, String mediaCode, Long mediaId, String mediaName,
353 Integer playDuration, DataSyncMsg dataSyncMsg, DataSyncMsg.MsgData msgData1, UserTvDTO userTvDTO) {
354 String priorityMemberCode = userTvDTO.getPriorityMemberCode();
355 String memberCode = "";
356 if (StringUtils.isNotBlank(priorityMemberCode)) {
357 memberCode = priorityMemberCode;
358 } else {
359 memberCode = this.memberService.findById(userTvDTO.getMemberId()).getCode();
360 }
361
362 if (StringUtils.isBlank(memberCode))
363 throw new EntityNotFoundException(MemberDTO.class, "memberCode", "memberCode is null");
364
365 msgData1.setMemberCode(memberCode);
366
367 msgData1.setMediaId(mediaId);
368
369 JSONObject param = new JSONObject();
370 // 增量
371 param.put("playDuration", playDuration);
372 msgData1.setParam(JSON.toJSONString(param));
373 JSONObject description = new JSONObject();
374 description.put("mediaId", mediaId);
375 description.put("mediaName", mediaName);
376 description.put("playDuration", playDuration);
377 description.put("mediaCode", mediaCode);
378 description.put("time", time);
379 msgData1.setDescription(JSON.toJSONString(description));
380 dataSyncMsg.setMsgData(JSONObject.toJSONString(msgData1));
381 return dataSyncMsg;
382 }
383
384 /**
385 * 任务处理
386 * @param dataSyncMsg
387 */
388 private void taskDeal(DataSyncMsg dataSyncMsg) {
389 this.restTemplateClient.dealTask(dataSyncMsg);
390 }
391
392 @Data
393 static class PlayContent {
394 private String evt;
395 private Integer event;
396 private Integer deviceType;
397 private String time;
398 private MsgData msgData;
399
400 @Data
401 static class MsgData {
402 private String platformAccount;
403 private Integer playDuration;
404 private Long mediaId;
405 private String mediaCode;
406 private String mediaName;
407 }
408 }
409 } 134 }
......
...@@ -3,10 +3,7 @@ package com.topdraw.mq.consumer; ...@@ -3,10 +3,7 @@ package com.topdraw.mq.consumer;
3 import com.alibaba.fastjson.JSON; 3 import com.alibaba.fastjson.JSON;
4 import com.alibaba.fastjson.JSONObject; 4 import com.alibaba.fastjson.JSONObject;
5 import com.rabbitmq.client.Channel; 5 import com.rabbitmq.client.Channel;
6 import com.topdraw.business.module.member.service.MemberService; 6 import com.topdraw.exception.BadRequestException;
7 import com.topdraw.business.module.member.service.dto.MemberDTO;
8 import com.topdraw.business.module.user.iptv.service.UserTvService;
9 import com.topdraw.business.module.user.iptv.service.dto.UserTvDTO;
10 import com.topdraw.mq.domain.DataSyncMsg; 7 import com.topdraw.mq.domain.DataSyncMsg;
11 import com.topdraw.resttemplate.RestTemplateClient; 8 import com.topdraw.resttemplate.RestTemplateClient;
12 import com.topdraw.util.FileUtil; 9 import com.topdraw.util.FileUtil;
...@@ -19,9 +16,7 @@ import org.springframework.amqp.rabbit.annotation.*; ...@@ -19,9 +16,7 @@ import org.springframework.amqp.rabbit.annotation.*;
19 import org.springframework.beans.factory.annotation.Autowired; 16 import org.springframework.beans.factory.annotation.Autowired;
20 import org.springframework.beans.factory.annotation.Value; 17 import org.springframework.beans.factory.annotation.Value;
21 import org.springframework.stereotype.Component; 18 import org.springframework.stereotype.Component;
22 import org.springframework.util.Assert;
23 19
24 import javax.validation.constraints.NotNull;
25 import java.io.IOException; 20 import java.io.IOException;
26 import java.time.LocalDate; 21 import java.time.LocalDate;
27 import java.util.Map; 22 import java.util.Map;
...@@ -34,21 +29,13 @@ public class UcGatewayIptv2IptvConsumer { ...@@ -34,21 +29,13 @@ public class UcGatewayIptv2IptvConsumer {
34 @Autowired 29 @Autowired
35 RestTemplateClient restTemplateClient; 30 RestTemplateClient restTemplateClient;
36 31
37 @Autowired
38 AutoRoute autoUser;
39
40 @Autowired
41 private MemberService memberService;
42 @Autowired
43 private UserTvService userTvService;
44
45 @Value("#{rabbitMqErrorLogConfig.getUcgError()}") 32 @Value("#{rabbitMqErrorLogConfig.getUcgError()}")
46 private Map<String, String> error; 33 private Map<String, String> error;
47 34
48 /** 35 /**
49 * 事件 36 * 事件
50 * @param content 37 * @param content
51 * @description 基础数据同步 38 * @description 普通权益事件
52 * @author Hongyan Wang 39 * @author Hongyan Wang
53 * @date 2021/9/7 11:26 上午 40 * @date 2021/9/7 11:26 上午
54 */ 41 */
...@@ -56,20 +43,22 @@ public class UcGatewayIptv2IptvConsumer { ...@@ -56,20 +43,22 @@ public class UcGatewayIptv2IptvConsumer {
56 @RabbitListener(queues = "#{rabbitMqSourceConfig.getUcgEventQueue()}", 43 @RabbitListener(queues = "#{rabbitMqSourceConfig.getUcgEventQueue()}",
57 containerFactory = "#{rabbitMqSourceConfig.getUcgEventSource()}", 44 containerFactory = "#{rabbitMqSourceConfig.getUcgEventSource()}",
58 autoStartup = "#{rabbitMqSourceConfig.getUcgEventStartUp()}", 45 autoStartup = "#{rabbitMqSourceConfig.getUcgEventStartUp()}",
59 ackMode = "MANUAL") 46 ackMode = "AUTO")
60 public void eventConsumer(Channel channel, Message message, String content) throws IOException { 47 public void eventConsumer(Channel channel, Message message, String content) throws IOException {
61 log.info(" receive dataSync msg , content is : {} ", content); 48 log.info(" eventConsumer receive dataSync msg , content is : {} ", content);
62 try { 49 try {
63 DataSyncMsg dataSyncMsg = this.parseContent(content); 50 DataSyncMsg dataSyncMsg = JSONUtil.parseMsg2Object(content, DataSyncMsg.class);
51
64 if (Objects.nonNull(dataSyncMsg)) { 52 if (Objects.nonNull(dataSyncMsg)) {
65 this.taskDeal(dataSyncMsg); 53 JSONObject jsonObject = this.restTemplateClient.dealTask(dataSyncMsg);
54 if (Objects.isNull(jsonObject)) {
55 throw new BadRequestException("uce处理任务响应超时");
56 }
66 } 57 }
67 58
68 channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
69
70 } catch (Exception e) { 59 } catch (Exception e) {
71 60
72 channel.basicReject(message.getMessageProperties().getDeliveryTag(), false); 61 log.error("普通权益事件处理异常, ==>> {}", e.getMessage());
73 62
74 if (MapUtils.isNotEmpty(error)) { 63 if (MapUtils.isNotEmpty(error)) {
75 String errorStart = this.error.get("start"); 64 String errorStart = this.error.get("start");
...@@ -83,63 +72,9 @@ public class UcGatewayIptv2IptvConsumer { ...@@ -83,63 +72,9 @@ public class UcGatewayIptv2IptvConsumer {
83 72
84 } 73 }
85 74
86 e.printStackTrace();
87 }
88 log.info("ucEventConsumer ====>>>> end");
89 }
90
91 /**
92 * 数据解析
93 * @param content
94 * @return
95 */
96 private DataSyncMsg parseContent(String content) {
97 DataSyncMsg dataSyncMsg = JSONUtil.parseMsg2Object(content,DataSyncMsg.class);
98 Assert.notNull(dataSyncMsg,"ERROR -->> operationConsumer -->> parseContent -->> 【dataSyncMsg】 not be null !!");
99 String msgDataStr = dataSyncMsg.getMsgData();
100 DataSyncMsg.MsgData msgData = null;
101 if (StringUtils.isNotBlank(msgDataStr)) {
102 msgData = JSONObject.parseObject(msgDataStr, DataSyncMsg.MsgData.class);
103 }else {
104 return null;
105 }
106 Long memberId = msgData.getMemberId();
107 String memberCode = msgData.getMemberCode();
108 if (Objects.nonNull(memberId) && StringUtils.isBlank(memberCode)) {
109 MemberDTO memberDTO = this.memberService.findById(memberId);
110 String code = memberDTO.getCode();
111 msgData.setMemberCode(code);
112 }
113
114 String platformAccount = msgData.getPlatformAccount();
115 if (StringUtils.isNotBlank(platformAccount)) {
116 UserTvDTO userTvDTO = userTvService.findByPlatformAccount(platformAccount);
117 if (Objects.nonNull(userTvDTO)) {
118 String priorityMemberCode = userTvDTO.getPriorityMemberCode();
119 if (StringUtils.isNotBlank(priorityMemberCode)) {
120 msgData.setMemberCode(priorityMemberCode);
121 } else {
122 MemberDTO memberDTO = this.memberService.findById(userTvDTO.getMemberId());
123 msgData.setMemberCode(memberDTO.getCode());
124 }
125 }
126 }
127 75
128 if(Objects.isNull(msgData.getMemberCode()) && Objects.isNull(msgData.getMemberId())) {
129 log.error("会员信息不存在,msgData =>> {}", msgData);
130 return null;
131 } 76 }
132 77 log.info("ucEventConsumer ====>>>> end");
133 dataSyncMsg.setMsgData(JSONObject.toJSONString(msgData));
134 return dataSyncMsg;
135 }
136
137 /**
138 * 任务处理
139 * @param dataSyncMsg
140 */
141 private void taskDeal(DataSyncMsg dataSyncMsg) {
142 this.restTemplateClient.dealTask(dataSyncMsg);
143 } 78 }
144 79
145 80
...@@ -151,7 +86,7 @@ public class UcGatewayIptv2IptvConsumer { ...@@ -151,7 +86,7 @@ public class UcGatewayIptv2IptvConsumer {
151 @RabbitListener(queues = "#{rabbitMqSourceConfig.getUcgCollectionQueue()}", 86 @RabbitListener(queues = "#{rabbitMqSourceConfig.getUcgCollectionQueue()}",
152 containerFactory = "#{rabbitMqSourceConfig.getUcgCollectionSource()}", 87 containerFactory = "#{rabbitMqSourceConfig.getUcgCollectionSource()}",
153 autoStartup = "#{rabbitMqSourceConfig.getUcgCollectionStartUp()}", 88 autoStartup = "#{rabbitMqSourceConfig.getUcgCollectionStartUp()}",
154 ackMode = "MANUAL") 89 ackMode = "AUTO")
155 public void collectionConsumer(Channel channel, Message message, String content) throws IOException { 90 public void collectionConsumer(Channel channel, Message message, String content) throws IOException {
156 log.info("receive UserCollection add message, content {}", content); 91 log.info("receive UserCollection add message, content {}", content);
157 92
...@@ -180,11 +115,9 @@ public class UcGatewayIptv2IptvConsumer { ...@@ -180,11 +115,9 @@ public class UcGatewayIptv2IptvConsumer {
180 } 115 }
181 } 116 }
182 117
183 channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
184
185 } catch (Exception e) { 118 } catch (Exception e) {
186 119
187 channel.basicReject(message.getMessageProperties().getDeliveryTag(), false); 120 log.error("收藏事件处理异常,cause ==>> {}", e.getMessage());
188 121
189 if (MapUtils.isNotEmpty(error)) { 122 if (MapUtils.isNotEmpty(error)) {
190 String errorStart = this.error.get("start"); 123 String errorStart = this.error.get("start");
...@@ -198,7 +131,6 @@ public class UcGatewayIptv2IptvConsumer { ...@@ -198,7 +131,6 @@ public class UcGatewayIptv2IptvConsumer {
198 131
199 } 132 }
200 133
201 e.printStackTrace();
202 } 134 }
203 } 135 }
204 136
...@@ -210,9 +142,9 @@ public class UcGatewayIptv2IptvConsumer { ...@@ -210,9 +142,9 @@ public class UcGatewayIptv2IptvConsumer {
210 @RabbitListener(queues = "#{rabbitMqSourceConfig.getViewRecordQueue()}", 142 @RabbitListener(queues = "#{rabbitMqSourceConfig.getViewRecordQueue()}",
211 containerFactory = "#{rabbitMqSourceConfig.getViewRecordSource()}", 143 containerFactory = "#{rabbitMqSourceConfig.getViewRecordSource()}",
212 autoStartup = "#{rabbitMqSourceConfig.getViewRecordStartUp()}", 144 autoStartup = "#{rabbitMqSourceConfig.getViewRecordStartUp()}",
213 ackMode = "MANUAL") 145 ackMode = "AUTO")
214 public void viewRecordConsumer(Channel channel, Message message, String content) throws IOException { 146 public void viewRecordConsumer(Channel channel, Message message, String content) throws IOException {
215 log.info("receive ViewRecord add message, content {}", content); 147 log.info("viewRecordConsumer receive ViewRecord add message, content {}", content);
216 148
217 try { 149 try {
218 150
...@@ -227,15 +159,11 @@ public class UcGatewayIptv2IptvConsumer { ...@@ -227,15 +159,11 @@ public class UcGatewayIptv2IptvConsumer {
227 break; 159 break;
228 default: 160 default:
229 break; 161 break;
230
231 } 162 }
232 } 163 }
233 164
234 channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
235
236 } catch (Exception e) { 165 } catch (Exception e) {
237 166 log.error("观影事件处理异常,cause ==>> {}", e.getMessage());
238 channel.basicReject(message.getMessageProperties().getDeliveryTag(), false);
239 167
240 if (MapUtils.isNotEmpty(error)) { 168 if (MapUtils.isNotEmpty(error)) {
241 String errorStart = this.error.get("start"); 169 String errorStart = this.error.get("start");
...@@ -249,14 +177,11 @@ public class UcGatewayIptv2IptvConsumer { ...@@ -249,14 +177,11 @@ public class UcGatewayIptv2IptvConsumer {
249 177
250 } 178 }
251 179
252 e.printStackTrace(); 180
253 } 181 }
254 } 182 }
255 183
256 184
257
258
259
260 /** 185 /**
261 * @description 添加收藏记录 186 * @description 添加收藏记录
262 * @param content 消息内容 187 * @param content 消息内容
...@@ -265,7 +190,7 @@ public class UcGatewayIptv2IptvConsumer { ...@@ -265,7 +190,7 @@ public class UcGatewayIptv2IptvConsumer {
265 @RabbitListener(queues = "#{rabbitMqSourceConfig.getUcgCollectionQueueAdd()}", 190 @RabbitListener(queues = "#{rabbitMqSourceConfig.getUcgCollectionQueueAdd()}",
266 containerFactory = "#{rabbitMqSourceConfig.getUcgCollectionSource()}", 191 containerFactory = "#{rabbitMqSourceConfig.getUcgCollectionSource()}",
267 autoStartup = "#{rabbitMqSourceConfig.getUcgCollectionStartUp()}", 192 autoStartup = "#{rabbitMqSourceConfig.getUcgCollectionStartUp()}",
268 ackMode = "MANUAL") 193 ackMode = "AUTO")
269 public void collectionConsumerAdd(Channel channel, Message message, String content) throws IOException { 194 public void collectionConsumerAdd(Channel channel, Message message, String content) throws IOException {
270 log.info("receive collectionConsumerAdd add message, content {}", content); 195 log.info("receive collectionConsumerAdd add message, content {}", content);
271 196
...@@ -294,11 +219,10 @@ public class UcGatewayIptv2IptvConsumer { ...@@ -294,11 +219,10 @@ public class UcGatewayIptv2IptvConsumer {
294 } 219 }
295 } 220 }
296 221
297 // channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
298 222
299 } catch (Exception e) { 223 } catch (Exception e) {
300 224
301 channel.basicReject(message.getMessageProperties().getDeliveryTag(), false); 225 log.error("添加收藏记录事件处理异常,cause ==>> {}", e.getMessage());
302 226
303 if (MapUtils.isNotEmpty(error)) { 227 if (MapUtils.isNotEmpty(error)) {
304 String errorStart = this.error.get("start"); 228 String errorStart = this.error.get("start");
...@@ -312,24 +236,22 @@ public class UcGatewayIptv2IptvConsumer { ...@@ -312,24 +236,22 @@ public class UcGatewayIptv2IptvConsumer {
312 236
313 } 237 }
314 238
315 e.printStackTrace();
316 } 239 }
317 } 240 }
318 241
319 /** 242 /**
320 * @description 添加收藏记录 243 * @description 删除收藏记录
321 * @param content 消息内容 244 * @param content 消息内容
322 */ 245 */
323 @RabbitHandler 246 @RabbitHandler
324 @RabbitListener(queues = "#{rabbitMqSourceConfig.getUcgCollectionQueueDelete()}", 247 @RabbitListener(queues = "#{rabbitMqSourceConfig.getUcgCollectionQueueDelete()}",
325 containerFactory = "#{rabbitMqSourceConfig.getUcgCollectionSource()}", 248 containerFactory = "#{rabbitMqSourceConfig.getUcgCollectionSource()}",
326 autoStartup = "#{rabbitMqSourceConfig.getUcgCollectionStartUp()}", 249 autoStartup = "#{rabbitMqSourceConfig.getUcgCollectionStartUp()}",
327 ackMode = "MANUAL") 250 ackMode = "AUTO")
328 public void collectionConsumerDelete(Channel channel, Message message, String content) throws IOException { 251 public void collectionConsumerDelete(Channel channel, Message message, String content) throws IOException {
329 log.info("receive collectionConsumerDelete add message, content {}", content); 252 log.info("receive collectionConsumerDelete add message, content {}", content);
330 253
331 try { 254 try {
332
333 JSONObject jsonObject = JSON.parseObject(content, JSONObject.class); 255 JSONObject jsonObject = JSON.parseObject(content, JSONObject.class);
334 if (Objects.nonNull(content)) { 256 if (Objects.nonNull(content)) {
335 String evt = jsonObject.get("evt").toString(); 257 String evt = jsonObject.get("evt").toString();
...@@ -353,11 +275,9 @@ public class UcGatewayIptv2IptvConsumer { ...@@ -353,11 +275,9 @@ public class UcGatewayIptv2IptvConsumer {
353 } 275 }
354 } 276 }
355 277
356 // channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
357
358 } catch (Exception e) { 278 } catch (Exception e) {
359 279
360 channel.basicReject(message.getMessageProperties().getDeliveryTag(), false); 280 log.error("删除收藏记录事件处理异常,cause ==>> {}", e.getMessage());
361 281
362 if (MapUtils.isNotEmpty(error)) { 282 if (MapUtils.isNotEmpty(error)) {
363 String errorStart = this.error.get("start"); 283 String errorStart = this.error.get("start");
...@@ -371,12 +291,12 @@ public class UcGatewayIptv2IptvConsumer { ...@@ -371,12 +291,12 @@ public class UcGatewayIptv2IptvConsumer {
371 291
372 } 292 }
373 293
374 e.printStackTrace(); 294
375 } 295 }
376 } 296 }
377 297
378 /** 298 /**
379 * @description 添加收藏记录 299 * @description 删除全部收藏记录
380 * @param content 消息内容 300 * @param content 消息内容
381 */ 301 */
382 @RabbitHandler 302 @RabbitHandler
...@@ -412,11 +332,8 @@ public class UcGatewayIptv2IptvConsumer { ...@@ -412,11 +332,8 @@ public class UcGatewayIptv2IptvConsumer {
412 } 332 }
413 } 333 }
414 334
415 // channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
416
417 } catch (Exception e) { 335 } catch (Exception e) {
418 336 log.error("删除全部收藏记录事件处理异常,cause ==>> {}", e.getMessage());
419 channel.basicReject(message.getMessageProperties().getDeliveryTag(), false);
420 337
421 if (MapUtils.isNotEmpty(error)) { 338 if (MapUtils.isNotEmpty(error)) {
422 String errorStart = this.error.get("start"); 339 String errorStart = this.error.get("start");
...@@ -429,8 +346,6 @@ public class UcGatewayIptv2IptvConsumer { ...@@ -429,8 +346,6 @@ public class UcGatewayIptv2IptvConsumer {
429 } 346 }
430 347
431 } 348 }
432
433 e.printStackTrace();
434 } 349 }
435 } 350 }
436 } 351 }
......
...@@ -28,23 +28,4 @@ public class DataSyncMsg implements Serializable { ...@@ -28,23 +28,4 @@ public class DataSyncMsg implements Serializable {
28 // 消息体 28 // 消息体
29 private String msgData; 29 private String msgData;
30 30
31 /**
32 * 消息体
33 */
34 @Data
35 @AllArgsConstructor
36 @NoArgsConstructor
37 public static class MsgData {
38 private Long memberId; // 会员id
39 private String memberCode;
40 private Long orderId;
41 private Long activityId;
42 private Long mediaId;
43 private Long itemId;
44 private String description;
45
46 private String param;
47 private String platformAccount;
48 }
49
50 } 31 }
......
...@@ -2,11 +2,11 @@ package com.topdraw.resttemplate; ...@@ -2,11 +2,11 @@ package com.topdraw.resttemplate;
2 2
3 import com.alibaba.fastjson.JSON; 3 import com.alibaba.fastjson.JSON;
4 import com.alibaba.fastjson.JSONObject; 4 import com.alibaba.fastjson.JSONObject;
5 import com.topdraw.business.module.member.address.domain.MemberAddress; 5 import com.topdraw.config.ResponseStatus;
6 import com.topdraw.mq.consumer.UcEventBusIptv2ManagementUcEngine;
6 import com.topdraw.mq.domain.DataSyncMsg; 7 import com.topdraw.mq.domain.DataSyncMsg;
7 import com.topdraw.mq.domain.SubscribeBean; 8 import com.topdraw.mq.domain.SubscribeBean;
8 import lombok.extern.slf4j.Slf4j; 9 import lombok.extern.slf4j.Slf4j;
9 import org.apache.commons.lang3.StringUtils;
10 import org.springframework.beans.factory.annotation.Autowired; 10 import org.springframework.beans.factory.annotation.Autowired;
11 import org.springframework.core.env.Environment; 11 import org.springframework.core.env.Environment;
12 import org.springframework.http.ResponseEntity; 12 import org.springframework.http.ResponseEntity;
...@@ -42,156 +42,150 @@ public class RestTemplateClient { ...@@ -42,156 +42,150 @@ public class RestTemplateClient {
42 } 42 }
43 43
44 public JSONObject dealTask(DataSyncMsg dataSyncMsg) { 44 public JSONObject dealTask(DataSyncMsg dataSyncMsg) {
45 JSONObject resultSet = null; 45 try {
46 String url = BASE_URL + "/uce/taskOperation/dealTask"; 46 String url = BASE_URL + "/uce/taskOperation/dealTask";
47 log.info("request uc : url is " + url + ", dataSyncMsg is " + dataSyncMsg); 47 HashMap<Object, Object> objectObjectHashMap = new HashMap<>();
48 String content = JSON.toJSONString(dataSyncMsg); 48 objectObjectHashMap.put("content", JSON.toJSONString(dataSyncMsg));
49 HashMap<Object, Object> objectObjectHashMap = new HashMap<>(); 49
50 objectObjectHashMap.put("content", content); 50 log.info("request url is ==>> {} || param is ==>> {} ", url, objectObjectHashMap);
51 restTemplate.postForEntity(url, objectObjectHashMap, String.class); 51 ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, objectObjectHashMap, String.class);
52 ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, objectObjectHashMap, String.class); 52 log.info("response ==>> {}", responseEntity);
53 if (responseEntity.getStatusCode().is2xxSuccessful()) { 53 return getParseResponseResult(responseEntity);
54 String entityBody = responseEntity.getBody(); 54
55 JSONObject jsonObject = JSONObject.parseObject(entityBody); 55 } catch (Exception e) {
56 if (jsonObject.getInteger("businessCode").equals(ResponseStatusConstant.OK)) { 56 log.error("处理普通权益任务(ApiUti.dealTask)信息时出现异常,cause ==>> {}", e.getMessage());
57 resultSet = jsonObject.getJSONArray("resultSet").getJSONObject(0);
58 }
59 }
60 log.info("uc response: " + resultSet.toJSONString());
61 return resultSet;
62 }
63
64 public JSONObject getMemberInfo(Long memberId) {
65 JSONObject resultSet = null;
66 String url = BASE_URL + "/uce/member/findById/" + memberId;
67 log.info("request uc : url is " + url + ", memberId is " + memberId);
68 ResponseEntity<String> responseEntity = restTemplate.getForEntity(url, String.class);
69 if (responseEntity.getStatusCode().is2xxSuccessful()) {
70 String entityBody = responseEntity.getBody();
71 JSONObject jsonObject = JSONObject.parseObject(entityBody);
72 if (jsonObject.getInteger("businessCode").equals(200)) {
73 resultSet = jsonObject.getJSONArray("resultSet").getJSONObject(0);
74 }
75 } 57 }
76 log.info("uc response: " + resultSet.toJSONString());
77 return resultSet;
78 }
79 58
80 public String createMemberAddress(MemberAddress member) {
81 String url = BASE_URL + "/uce/memberAddress/create";
82 log.info("request uc : url is " + url + ", memberId is " + JSONObject.toJSONString(member));
83 restTemplate.postForEntity(url, member, String.class);
84 /* ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, member, String.class);
85 String entityBody = "";
86 if (responseEntity.getStatusCode().is2xxSuccessful()) {
87 entityBody = responseEntity.getBody();
88 }
89 log.info("uc response: " + entityBody);*/
90 return null; 59 return null;
91 } 60 }
92 61
93 public String unsubscribe(SubscribeBean subscribeBean) { 62 public JSONObject unsubscribe(SubscribeBean subscribeBean) {
94 String url = BASE_URL + "/uce/userOperation/unsubscribe"; 63 try {
95 String content = JSON.toJSONString(subscribeBean); 64 String url = BASE_URL + "/uce/userOperation/unsubscribe";
96 65 String content = JSON.toJSONString(subscribeBean);
97 HashMap<Object, Object> objectObjectHashMap = new HashMap<>(); 66
98 objectObjectHashMap.put("content", content); 67 HashMap<Object, Object> objectObjectHashMap = new HashMap<>();
99 log.info("reobjectObjectHashMap ===>> [{}]",objectObjectHashMap); 68 objectObjectHashMap.put("content", content);
100 restTemplate.postForEntity(url, objectObjectHashMap, String.class); 69
101 log.info("unsubscribe ===>> success"); 70 log.info("request url is ==>> {} || param is ==>> {} ", url, objectObjectHashMap);
102 /*ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, subscribeBean, String.class); 71 ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, objectObjectHashMap, String.class);
103 String entityBody = ""; 72 log.info("response ==>> {}", responseEntity);
104 if (responseEntity.getStatusCode().is2xxSuccessful()) { 73
105 entityBody = responseEntity.getBody(); 74 return getParseResponseResult(responseEntity);
75
76 } catch (Exception e) {
77 log.error("处理微信取关(ApiUti.unsubscribe)信息时出现异常,cause ==>> {}", e.getMessage());
106 } 78 }
107 log.info("uc response: " + entityBody);*/ 79
108 return null; 80 return null;
109 } 81 }
110 82
111 public String subscribe(SubscribeBean subscribeBean) { 83 public JSONObject subscribe(SubscribeBean subscribeBean) {
112 String url = BASE_URL + "/uce/userOperation/subscribe"; 84 try {
113 String content = JSON.toJSONString(subscribeBean); 85 String url = BASE_URL + "/uce/userOperation/subscribe";
114 86 String content = JSON.toJSONString(subscribeBean);
115 HashMap<String, String> objectObjectHashMap = new HashMap<>(); 87
116 objectObjectHashMap.put("content", content); 88 HashMap<String, String> objectObjectHashMap = new HashMap<>();
117 log.info("reobjectObjectHashMap ===>> [{}]",objectObjectHashMap); 89 objectObjectHashMap.put("content", content);
118 restTemplate.postForEntity(url, objectObjectHashMap, String.class); 90
119 log.info("send subscribe request ===>> success"); 91 log.info("request url is ==>> {} || param is ==>> {} ", url, objectObjectHashMap);
120 /*ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, subscribeBean, String.class); 92 ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, subscribeBean, String.class);
121 String entityBody = ""; 93 log.info("response ==>> {}", responseEntity);
122 if (responseEntity.getStatusCode().is2xxSuccessful()) { 94
123 entityBody = responseEntity.getBody(); 95 return getParseResponseResult(responseEntity);
96
97 } catch (Exception e) {
98 log.error("处理微信关注(ApiUti.subscribe)信息时出现异常,cause ==>> {}", e.getMessage());
124 } 99 }
125 log.info("uc response: " + entityBody);*/ 100
126 return null; 101 return null;
127 } 102 }
128 103
129 public String sendQrCodeMessage(String content) { 104 public JSONObject addCollection(String content) {
130 String url = BASE_URL + "/uce/userOperation/sendQrCodeMessage"; 105 try {
131 restTemplate.postForEntity(url, content, String.class); 106 String url = BASE_URL + "/uce/userOperation/addCollection";
132 /* ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, content, String.class); 107 //处理接口调用 中文不显示问题
133 String entityBody = ""; 108 content = new String(Base64.getEncoder().encode(content.getBytes(StandardCharsets.UTF_8)));
134 if (responseEntity.getStatusCode().is2xxSuccessful()) { 109
135 entityBody = responseEntity.getBody(); 110 ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, content, String.class);
111 log.info("response ==>> {}", responseEntity);
112
113 return getParseResponseResult(responseEntity);
114 } catch (Exception e) {
115 log.error("添加观影记录(ApiUti.addCollection)信息时出现异常,cause ==>> {}", e.getMessage());
136 } 116 }
137 log.info("uc response: " + entityBody);*/ 117
138 return null; 118 return null;
139 } 119 }
140 120
141 public String addCollection(String content) { 121 public JSONObject deleteCollection(String content) {
142 String url = BASE_URL + "/uce/userOperation/addCollection"; 122 try {
143 //处理接口调用 中文不显示问题 123 String url = BASE_URL + "/uce/userOperation/deleteCollection";
144 content = new String(Base64.getEncoder().encode(content.getBytes(StandardCharsets.UTF_8))); 124 //处理接口调用 中文不显示问题
125 content = new String(Base64.getEncoder().encode(content.getBytes(StandardCharsets.UTF_8)));
145 126
146 restTemplate.postForEntity(url, content, String.class); 127 ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, content, String.class);
147 /* ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, content, String.class); 128 log.info("response ==>> {}", responseEntity);
148 String entityBody = ""; 129
149 if (responseEntity.getStatusCode().is2xxSuccessful()) { 130 return getParseResponseResult(responseEntity);
150 entityBody = responseEntity.getBody(); 131
132 } catch (Exception e) {
133 log.error("删除一条观影记录(ApiUti.deleteCollection)信息时出现异常,cause ==>> {}", e.getMessage());
151 } 134 }
152 log.info("uc response: " + entityBody);*/ 135
153 return null; 136 return null;
154 } 137 }
155 138
156 public String deleteCollection(String content) { 139 public JSONObject deleteAllCollection(String content) {
157 String url = BASE_URL + "/uce/userOperation/deleteCollection"; 140 try {
158 //处理接口调用 中文不显示问题 141 String url = BASE_URL + "/uce/userOperation/deleteAllCollection";
159 content = new String(Base64.getEncoder().encode(content.getBytes(StandardCharsets.UTF_8)));
160 142
161 restTemplate.postForEntity(url, content, String.class); 143 log.info("request url is ==>> {} || param is ==>> {} ", url, content);
162 /* ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, content, String.class); 144 ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, content, String.class);
163 String entityBody = ""; 145 log.info("response ==>> {}", responseEntity);
164 if (responseEntity.getStatusCode().is2xxSuccessful()) { 146
165 entityBody = responseEntity.getBody(); 147 return getParseResponseResult(responseEntity);
148
149 } catch (Exception e) {
150 log.error("删除所有观影记录(ApiUti.deleteAllCollection)信息时出现异常,cause ==>> {}", e.getMessage());
166 } 151 }
167 log.info("uc response: " + entityBody);*/ 152
168 return null; 153 return null;
169 } 154 }
170 155
171 public String deleteAllCollection(String content) { 156 public JSONObject dealViewRecord(String content) {
172 String url = BASE_URL + "/uce/userOperation/deleteAllCollection"; 157 try {
173 restTemplate.postForEntity(url, content, String.class); 158 String url = BASE_URL + "/uce/userOperation/addCollection";
174 /*ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, content, String.class); 159 //处理接口调用 中文不显示问题
175 String entityBody = ""; 160 content = new String(Base64.getEncoder().encode(content.getBytes(StandardCharsets.UTF_8)));
176 if (responseEntity.getStatusCode().is2xxSuccessful()) { 161 ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, content, String.class);
177 entityBody = responseEntity.getBody(); 162 log.info("response ==>> {}", responseEntity);
163
164 return getParseResponseResult(responseEntity);
165
166 } catch (Exception e) {
167 log.error("处理观影记录(ApiUti.dealViewRecord)信息时出现异常,cause ==>> {}", e.getMessage());
178 } 168 }
179 log.info("uc response: " + entityBody);*/ 169
180 return null; 170 return null;
181 } 171 }
182 172
183 public String dealViewRecord(String content) { 173 /**
184 String url = BASE_URL + "/uce/userOperation/addCollection"; 174 *
185 //处理接口调用 中文不显示问题 175 * @param responseEntity
186 content = new String(Base64.getEncoder().encode(content.getBytes(StandardCharsets.UTF_8))); 176 * @return
177 */
178 private static JSONObject getParseResponseResult(ResponseEntity<String> responseEntity) {
187 179
188 restTemplate.postForEntity(url, content, String.class); 180 JSONObject resultSet = null;
189 /* ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, content, String.class);
190 String entityBody = "";
191 if (responseEntity.getStatusCode().is2xxSuccessful()) { 181 if (responseEntity.getStatusCode().is2xxSuccessful()) {
192 entityBody = responseEntity.getBody(); 182 String entityBody = responseEntity.getBody();
183 JSONObject jsonObject = JSONObject.parseObject(entityBody);
184 if (jsonObject.getInteger("businessCode").equals(ResponseStatus.OK)) {
185 resultSet = jsonObject.getJSONArray("resultSet").getJSONObject(0);
186 }
193 } 187 }
194 log.info("uc response: " + entityBody);*/ 188 log.info("result ==>> {}", resultSet);
195 return null; 189 return resultSet;
196 } 190 }
197 } 191 }
......
...@@ -18,11 +18,6 @@ public class RestTemplateTest extends BaseTest { ...@@ -18,11 +18,6 @@ public class RestTemplateTest extends BaseTest {
18 @Autowired 18 @Autowired
19 RestTemplateClient apiUtil; 19 RestTemplateClient apiUtil;
20 20
21 @Test
22 public void t(){
23 JSONObject memberInfo = this.apiUtil.getMemberInfo(5L);
24 System.out.println(memberInfo);
25 }
26 21
27 @Test 22 @Test
28 public void error(){ 23 public void error(){
......