From b28d46dc105d5891b5767ce2909925dcf29ad39a Mon Sep 17 00:00:00 2001 From: zhongzb <972627721@qq.com> Date: Sat, 13 May 2023 23:35:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/annotation/RedissonLock.java | 2 ++ .../common/aspect/FrequencyControlAspect.java | 2 -- .../main/resources/application-pro.properties | 21 +++++++++++++++++++ .../chat/controller/ChatController.java | 5 +++-- .../chat/service/impl/ChatServiceImpl.java | 2 ++ .../user/service/adapter/UserAdapter.java | 5 ++++- 6 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 mallchat-common/src/main/resources/application-pro.properties diff --git a/mallchat-common/src/main/java/com/abin/mallchat/common/common/annotation/RedissonLock.java b/mallchat-common/src/main/java/com/abin/mallchat/common/common/annotation/RedissonLock.java index eeb7a93..aad905e 100644 --- a/mallchat-common/src/main/java/com/abin/mallchat/common/common/annotation/RedissonLock.java +++ b/mallchat-common/src/main/java/com/abin/mallchat/common/common/annotation/RedissonLock.java @@ -1,5 +1,7 @@ package com.abin.mallchat.common.common.annotation; +import org.springframework.core.annotation.AliasFor; + import java.lang.annotation.*; import java.util.concurrent.TimeUnit; diff --git a/mallchat-common/src/main/java/com/abin/mallchat/common/common/aspect/FrequencyControlAspect.java b/mallchat-common/src/main/java/com/abin/mallchat/common/common/aspect/FrequencyControlAspect.java index c43624f..dfe7ca1 100644 --- a/mallchat-common/src/main/java/com/abin/mallchat/common/common/aspect/FrequencyControlAspect.java +++ b/mallchat-common/src/main/java/com/abin/mallchat/common/common/aspect/FrequencyControlAspect.java @@ -75,6 +75,4 @@ public class FrequencyControlAspect { }); } } - - } diff --git a/mallchat-common/src/main/resources/application-pro.properties b/mallchat-common/src/main/resources/application-pro.properties new file mode 100644 index 0000000..0943abe --- /dev/null +++ b/mallchat-common/src/main/resources/application-pro.properties @@ -0,0 +1,21 @@ +#todo 记得把这些配置信息补充了 +##################mysql配置################## +mallchat.mysql.ip=127.0.0.1 +mallchat.mysql.port=3306 +mallchat.mysql.db=mallchat +mallchat.mysql.username=root +mallchat.mysql.password=123456 +##################redis配置################## +mallchat.redis.host=127.0.0.1 +mallchat.redis.port=6379 +mallchat.redis.password=123456 +##################jwt################## +mallchat.jwt.secret=dsfsdfsdfsdfsd +##################微信公众号信息################## +mallchat.wx.callback=http://127.0.0.1:8080 +mallchat.wx.appId=appid +mallchat.wx.secret=380bfc1c9147fdsf4sf07 +# 接口配置里的Token值 +mallchat.wx.token=sdfsf +# 接口配置里的EncodingAESKey值 +mallchat.wx.aesKey=sha1 \ No newline at end of file diff --git a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/chat/controller/ChatController.java b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/chat/controller/ChatController.java index e9e22b9..86412cf 100644 --- a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/chat/controller/ChatController.java +++ b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/chat/controller/ChatController.java @@ -2,6 +2,7 @@ package com.abin.mallchat.custom.chat.controller; import com.abin.mallchat.common.common.annotation.FrequencyControl; +import com.abin.mallchat.common.common.annotation.FrequencyControlContainer; import com.abin.mallchat.common.common.domain.vo.request.CursorPageBaseReq; import com.abin.mallchat.common.common.domain.vo.response.ApiResult; import com.abin.mallchat.common.common.domain.vo.response.CursorPageBaseResp; @@ -68,14 +69,14 @@ public class ChatController { @FrequencyControl(time = 60, count = 10, target = FrequencyControl.Target.UID) public ApiResult sendMsg(@Valid @RequestBody ChatMessageReq request) { Long msgId = chatService.sendMsg(request, RequestHolder.get().getUid()); - //返回完整消息格式,方便前展示 + //返回完整消息格式,方便前端展示 return ApiResult.success(chatService.getMsgResp(msgId, RequestHolder.get().getUid())); } @PutMapping("/msg/mark") @ApiOperation("消息标记") @FrequencyControl(time = 20, count = 3, target = FrequencyControl.Target.UID) - public ApiResult setMsgMark(@Valid @RequestBody ChatMessageMarkReq request) {//分布式锁 + public ApiResult setMsgMark(@Valid @RequestBody ChatMessageMarkReq request) { chatService.setMsgMark(RequestHolder.get().getUid(), request); return ApiResult.success(); diff --git a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/chat/service/impl/ChatServiceImpl.java b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/chat/service/impl/ChatServiceImpl.java index fee3473..13e75eb 100644 --- a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/chat/service/impl/ChatServiceImpl.java +++ b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/chat/service/impl/ChatServiceImpl.java @@ -10,6 +10,7 @@ import com.abin.mallchat.common.chat.domain.dto.ChatMessageMarkDTO; import com.abin.mallchat.common.chat.domain.entity.Message; import com.abin.mallchat.common.chat.domain.entity.MessageMark; import com.abin.mallchat.common.chat.domain.entity.Room; +import com.abin.mallchat.common.common.annotation.RedissonLock; import com.abin.mallchat.common.common.domain.enums.YesOrNoEnum; import com.abin.mallchat.common.common.domain.vo.request.CursorPageBaseReq; import com.abin.mallchat.common.common.domain.vo.response.CursorPageBaseResp; @@ -168,6 +169,7 @@ public class ChatServiceImpl implements ChatService { } @Override + @RedissonLock(key = "#uid") public void setMsgMark(Long uid, ChatMessageMarkReq request) { //用户对该消息的标记 MessageMark messageMark = messageMarkDao.get(uid, request.getMsgId(), request.getMarkType()); diff --git a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/service/adapter/UserAdapter.java b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/service/adapter/UserAdapter.java index e0c3a38..88a46ae 100644 --- a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/service/adapter/UserAdapter.java +++ b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/service/adapter/UserAdapter.java @@ -12,6 +12,7 @@ import lombok.extern.slf4j.Slf4j; import me.chanjar.weixin.common.bean.WxOAuth2UserInfo; import me.chanjar.weixin.mp.bean.result.WxMpUser; +import java.util.Comparator; import java.util.List; import java.util.Set; import java.util.stream.Collectors; @@ -54,6 +55,8 @@ public class UserAdapter { resp.setObtain(obtainItemSet.contains(a.getId()) ? YesOrNoEnum.YES.getStatus() : YesOrNoEnum.NO.getStatus()); resp.setWearing(ObjectUtil.equal(a.getId(), user.getItemId()) ? YesOrNoEnum.YES.getStatus() : YesOrNoEnum.NO.getStatus()); return resp; - }).collect(Collectors.toList()); + }).sorted(Comparator.comparing(BadgeResp::getWearing, Comparator.reverseOrder()) + .thenComparing(BadgeResp::getObtain, Comparator.reverseOrder())) + .collect(Collectors.toList()); } }