Sfoglia il codice sorgente

服务代码优化

fangzhen 3 mesi fa
parent
commit
5764529e91

+ 4 - 5
ruoyi-generator/src/main/java/com/ruoyi/generator/controller/CommunityArticleController.java

@@ -732,12 +732,11 @@ public class CommunityArticleController extends BaseController {
     @ApiOperation("获取用户信息")
     @GetMapping("/userInfo")
     @Anonymous
-    public AjaxResult userInfo(@RequestParam(required = false) Long userId) {
+    public AjaxResult userInfo(@RequestParam(required = false) Long userId,boolean isToken) {
         if (Objects.isNull(userId)) {
             userId = SecurityUtils.getLoginUser().getUserId();
-        }
-        //如果登录的是本人刷新下IP地址
-        if (userId != null && userId.equals(SecurityUtils.getLoginUser().getUserId())) {
+
+            //是本人刷新下IP地址
             SysUser sysUser = new SysUser();
             sysUser.setUserId(userId);
             sysUser.setLoginIp(IpUtils.getIpAddr());
@@ -747,7 +746,7 @@ public class CommunityArticleController extends BaseController {
 
         CommunityUserInfoVo communityUserInfoVo = null;
         try {
-            communityUserInfoVo = communityArticleService.selectCommunityUserInfoById(userId);
+            communityUserInfoVo = communityArticleService.selectCommunityUserInfoById(userId,isToken);
         } catch (Exception e) {
             System.out.println(e.getMessage());
             throw new ProjectException();

+ 12 - 11
ruoyi-generator/src/main/java/com/ruoyi/generator/service/CommunityArticleServiceImpl.java

@@ -289,7 +289,7 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
                             }));
             if (communityCommentRaffle != null) {
                 BeanUtils.copyProperties(communityCommentRaffle, communityCommentRaffleVo);
-                CommunityUserInfoVo communityUserInfoVo = communityArticleService.selectCommunityUserInfoById(communityCommentRaffle.getUserId());
+                CommunityUserInfoVo communityUserInfoVo = communityArticleService.selectCommunityUserInfoById(communityCommentRaffle.getUserId(),true);
                 communityCommentRaffleVo.setUserName(communityUserInfoVo.getNickName());
                 communityCommentRaffleVo.setUserAvatar(communityUserInfoVo.getAvatar());
                 articleVo.setCommentRaffleVo(communityCommentRaffleVo);
@@ -579,7 +579,7 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
                     .findFirst()
                     .ifPresent(communityCommentRaffle -> {
                         BeanUtils.copyProperties(communityCommentRaffle, communityCommentRaffleVo);
-                        CommunityUserInfoVo communityUserInfoVo = communityArticleService.selectCommunityUserInfoById(communityCommentRaffle.getUserId());
+                        CommunityUserInfoVo communityUserInfoVo = communityArticleService.selectCommunityUserInfoById(communityCommentRaffle.getUserId(),true);
                         communityCommentRaffleVo.setUserName(communityUserInfoVo.getNickName());
                         communityCommentRaffleVo.setUserAvatar(communityUserInfoVo.getAvatar());
                         articleVo.setCommentRaffleVo(communityCommentRaffleVo);
@@ -1163,7 +1163,7 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
      * @return 用户信息
      */
     @Override
-    public CommunityUserInfoVo selectCommunityUserInfoById(Long userId) {
+    public CommunityUserInfoVo selectCommunityUserInfoById(Long userId,boolean isToken) {
         SysUser sysUser = sysUserMapper.selectUserById(userId);
         CommunityUserInfo communityUserInfo = communityUserInfoMapper.selectOne(new QueryWrapper<CommunityUserInfo>().eq("user_id", userId));
         CommunityUserInfoVo communityUserInfoVo = new CommunityUserInfoVo();
@@ -1204,14 +1204,15 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
         communityUserInfoVo.setAddress(address);
         //设置是否被当前登录的用户关注
         communityUserInfoVo.setLike(false);
-        Long loginUserId = SecurityUtils.getLoginUser().getUserId();
-        if (!Objects.equals(userId, loginUserId)) {
-            CommunityUserLike communityUserLike = communityUserLikeMapper.selectOne(new QueryWrapper<CommunityUserLike>().eq("user_id", loginUserId).eq("like_user_id", userId));
-            if (!Objects.isNull(communityUserLike) && !Objects.isNull(communityUserLike.getId())) {
-                communityUserInfoVo.setLike(true);
+        if (isToken) {
+            Long loginUserId = SecurityUtils.getLoginUser().getUserId();
+            if (!Objects.equals(userId, loginUserId)) {
+                CommunityUserLike communityUserLike = communityUserLikeMapper.selectOne(new QueryWrapper<CommunityUserLike>().eq("user_id", loginUserId).eq("like_user_id", userId));
+                if (!Objects.isNull(communityUserLike) && !Objects.isNull(communityUserLike.getId())) {
+                    communityUserInfoVo.setLike(true);
+                }
             }
         }
-
         return communityUserInfoVo;
     }
 
@@ -1671,14 +1672,14 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
             commentRaffle.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
             communityCommentRaffleMapper.insert(commentRaffle);
             BeanUtils.copyProperties(commentRaffle, communityCommentRaffleVo);
-            communityUserInfoVo = communityArticleService.selectCommunityUserInfoById(commentRaffle.getUserId());
+            communityUserInfoVo = communityArticleService.selectCommunityUserInfoById(commentRaffle.getUserId(),true);
             communityCommentRaffleVo.setUserName(communityUserInfoVo.getNickName());
             communityCommentRaffleVo.setUserAvatar(communityUserInfoVo.getAvatar());
             return communityCommentRaffleVo;
         }
 
         BeanUtils.copyProperties(communityCommentRaffle, communityCommentRaffleVo);
-        communityUserInfoVo = communityArticleService.selectCommunityUserInfoById(communityCommentRaffle.getUserId());
+        communityUserInfoVo = communityArticleService.selectCommunityUserInfoById(communityCommentRaffle.getUserId(),true);
         communityCommentRaffleVo.setUserName(communityUserInfoVo.getNickName());
         communityCommentRaffleVo.setUserAvatar(communityUserInfoVo.getAvatar());
         return communityCommentRaffleVo;

+ 1 - 1
ruoyi-generator/src/main/java/com/ruoyi/generator/service/ICommunityArticleService.java

@@ -129,7 +129,7 @@ public interface ICommunityArticleService extends IService<CommunityArticle> {
      * @param userId 用户id
      * @return 用户信息
      */
-    CommunityUserInfoVo selectCommunityUserInfoById(Long userId);
+    CommunityUserInfoVo selectCommunityUserInfoById(Long userId,boolean isToken);
 
     /**
      * 根据搜索值,搜索用户

+ 1 - 1
ruoyi-generator/src/main/java/com/ruoyi/generator/vo/LikeVo.java

@@ -18,8 +18,8 @@ import java.util.Date;
 public class LikeVo {
     @JsonSerialize(using = ToStringSerializer.class)
     private Long id;
-    @JsonSerialize(using = ToStringSerializer.class)
     private Long likeUserId;
+    private Long userId;
     private String avatar;
     private String nickName;
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")

+ 4 - 0
ruoyi-generator/src/main/resources/mapper/community/CommunityArticleCollectMapper.xml

@@ -8,6 +8,7 @@
         from (select car.id,
                      car.article_id,
                      ca.id                                                                 as third_id,
+                     car.user_id,
                      car.create_time,
                      (select su.nick_name from sys_user su where su.user_id = car.user_id) as nick_name,
                      (select su.avatar from sys_user su where su.user_id = car.user_id)    as avatar,
@@ -26,6 +27,7 @@
                      cac.article_id,
                      ca.id                                                                 as third_id,
                      cac.create_time,
+                     cac.user_id,
                      (select su.nick_name from sys_user su where su.user_id = cac.user_id) as nick_name,
                      (select su.avatar from sys_user su where su.user_id = cac.user_id)    as avatar,
                      (select cai.image_url
@@ -42,6 +44,7 @@
               select ccl.id,
                      cac.article_id                                                        as article_id,
                      cac.id                                                                as third_id,
+                     ccl.user_id,
                      ccl.create_time,
                      (select su.nick_name from sys_user su where su.user_id = ccl.user_id) as nick_name,
                      (select su.avatar from sys_user su where su.user_id = ccl.user_id)    as avatar,
@@ -61,6 +64,7 @@
               select ccl.id,
                      cac.article_id                                                        as article_id,
                      ccr.id                                                                as third_id,
+                     ccl.user_id,
                      ccl.create_time,
                      (select su.nick_name from sys_user su where su.user_id = ccl.user_id) as nick_name,
                      (select su.avatar from sys_user su where su.user_id = ccl.user_id)    as avatar,

+ 1 - 0
ruoyi-generator/src/main/resources/mapper/community/CommunityUserLikeMapper.xml

@@ -6,6 +6,7 @@
     <select id="selectLikeByUserId" resultType="com.ruoyi.generator.vo.LikeVo">
         select cul.id,
                cul.create_time,
+               cul.user_id,
                cul.like_user_id,
                (select nick_name from sys_user su where su.user_id = cul.user_id) as nick_name,
                (select avatar from sys_user su where su.user_id = cul.user_id)    as avatar,