Эх сурвалжийг харах

修改回去文章和发送短信息

fangzhen 7 сар өмнө
parent
commit
9d53e617ef

+ 7 - 0
ruoyi-generator/pom.xml

@@ -59,6 +59,13 @@
             <version>3.5.2</version>
             <scope>compile</scope>
         </dependency>
+
+        <!--阿里云短信验证码-->
+        <dependency>
+            <groupId>com.aliyun</groupId>
+            <artifactId>alibabacloud-dysmsapi20170525</artifactId>
+            <version>3.0.0</version>
+        </dependency>
     </dependencies>
 
 </project>

+ 18 - 8
ruoyi-generator/src/main/java/com/ruoyi/generator/controller/CommunityArticleController.java

@@ -149,7 +149,7 @@ public class CommunityArticleController extends BaseController {
         boolean isSuccess = true;
         String message = "";
         CommunityArticleCollect collect = communityArticleService.selectCommunityCollectById(communityArticleCollect);
-        if (Objects.isNull(collect)) {
+        if (Objects.isNull(collect) || Objects.isNull(collect.getId())) {
             //新增收藏
             isSuccess = communityArticleService.insertCommunityCollectById(communityArticleCollect);
             message = "收藏成功";
@@ -181,12 +181,12 @@ public class CommunityArticleController extends BaseController {
         boolean isSuccess = true;
         String message = "";
         //查询该评论是否已点赞
-        List<CommunityCommentLike> commentLikes = communityCommentLikeMapper
-                .selectList(new QueryWrapper<CommunityCommentLike>()
+        CommunityCommentLike communityCommentLike = communityCommentLikeMapper
+                .selectOne(new QueryWrapper<CommunityCommentLike>()
                         .eq("comment_id", commentLike.getCommentId())
                         .eq("user_id", userId));
 
-        if (commentLikes.isEmpty()) {
+        if (Objects.isNull(communityCommentLike) || Objects.isNull(communityCommentLike.getId())) {
             //新增点赞
             commentLike.setCreateBy(userId);
             commentLike.setUserId(userId);
@@ -197,7 +197,7 @@ public class CommunityArticleController extends BaseController {
             message = "感谢点赞";
         } else {
             //删除点赞
-            communityCommentLikeMapper.deleteById(commentLike);
+            communityCommentLikeMapper.deleteById(communityCommentLike);
             message = "取消点赞";
         }
 
@@ -299,10 +299,12 @@ public class CommunityArticleController extends BaseController {
         return AjaxResult.success(msg);
     }
 
-    @ApiOperation("获取当前登录用户信息")
+    @ApiOperation("获取用户信息")
     @GetMapping("/userInfo")
-    public AjaxResult userInfo() {
-        Long userId = SecurityUtils.getLoginUser().getUserId();
+    public AjaxResult userInfo(Long userId) {
+        if (Objects.isNull(userId)) {
+            userId = SecurityUtils.getLoginUser().getUserId();
+        }
         return AjaxResult.success(communityArticleService.selectCommunityUserInfoById(userId));
     }
 
@@ -317,4 +319,12 @@ public class CommunityArticleController extends BaseController {
     public AjaxResult userFans() {
         return AjaxResult.success(communityArticleService.selectUserFansList(SecurityUtils.getLoginUser().getUserId()));
     }
+
+    @ApiOperation("发送用户验证码")
+    @GetMapping("/sendSms")
+    //todo
+    public AjaxResult sendSms() {
+        return AjaxResult.success();
+    }
+
 }

+ 10 - 2
ruoyi-generator/src/main/java/com/ruoyi/generator/service/CommunityArticleServiceImpl.java

@@ -86,6 +86,7 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
     public List<CommunityArticleVo> selectCommunityArticleList(CommunityArticle communityArticle, int pageNum, int pageSize) {
         //找出板块下的分类
         Long classId = communityArticle.getClassId();
+        Long userId = SecurityUtils.getUserId();
         List<CommunityClassCircle> classCircles = communityClassCircleMapper.selectList(new QueryWrapper<CommunityClassCircle>().eq("class_id", classId));
         List<Long> circleIds = new ArrayList<>();
         for (CommunityClassCircle classCircle : classCircles) {
@@ -93,10 +94,8 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
         }
         List<CommunityArticleVo> communityArticleVos = new ArrayList<>();
         if (!classCircles.isEmpty()) {
-
             int offset = (pageNum - 1) * pageSize;
             communityArticleVos = communityArticleMapper.selectCommunityArticleList(communityArticle, circleIds, offset, pageSize);
-            Long userId = SecurityUtils.getUserId();
             for (CommunityArticleVo articleVo : communityArticleVos) {
                 List<CommunityArticleImages> imageList = articleVo.getImageList();
                 List<CommunityArticleImages> videoList = new ArrayList<>();
@@ -404,6 +403,15 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
         communityUserInfoVo.setAvatar(sysUser.getAvatar());
         communityUserInfoVo.setNickName(sysUser.getNickName());
         communityUserInfoVo.setUserId(userId);
+
+        //设置关注,粉丝,陪伴数量
+        communityUserInfoVo.setLikeCount(communityUserLikeMapper
+                .selectList(new QueryWrapper<CommunityUserLike>()
+                        .eq("user_id", userId)).size());
+        communityUserInfoVo.setFansCount(communityUserLikeMapper
+                .selectList(new QueryWrapper<CommunityUserLike>()
+                        .eq("like_user_id", userId)).size());
+        communityUserInfoVo.setCompanionCount(0);
         return communityUserInfoVo;
     }
 

+ 56 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/util/SendSms.java

@@ -0,0 +1,56 @@
+package com.ruoyi.generator.util;
+
+import com.aliyun.auth.credentials.Credential;
+import com.aliyun.auth.credentials.provider.StaticCredentialProvider;
+import com.aliyun.sdk.service.dysmsapi20170525.AsyncClient;
+import com.aliyun.sdk.service.dysmsapi20170525.models.SendSmsRequest;
+import com.aliyun.sdk.service.dysmsapi20170525.models.SendSmsResponse;
+import com.google.gson.Gson;
+import com.ruoyi.common.utils.StringUtils;
+import darabonba.core.client.ClientOverrideConfiguration;
+
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+
+public class SendSms {
+    public static void  sendMsg(String signName, String templateCode, String phoneNumbers, String code) throws ExecutionException, InterruptedException {
+        StaticCredentialProvider provider = StaticCredentialProvider.create(Credential.builder()
+                // Please ensure that the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET are set.
+                .accessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
+                .accessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"))
+                //.securityToken(System.getenv("ALIBABA_CLOUD_SECURITY_TOKEN")) // use STS token
+                .build());
+
+        // Configure the Client
+        AsyncClient client = AsyncClient.builder()
+                .region("cn-hangzhou-finance") // Region ID
+                //.httpClient(httpClient) // Use the configured HttpClient, otherwise use the default HttpClient (Apache HttpClient)
+                .credentialsProvider(provider)
+                //.serviceConfiguration(Configuration.create()) // Service-level configuration
+                // Client-level configuration rewrite, can set Endpoint, Http request parameters, etc.
+                .overrideConfiguration(
+                        ClientOverrideConfiguration.create()
+                                // Endpoint 请参考 https://api.aliyun.com/product/Dysmsapi
+                                .setEndpointOverride("dysmsapi.aliyuncs.com")
+                        //.setConnectTimeout(Duration.ofSeconds(30))
+                )
+                .build();
+
+        // Parameter settings for API request
+        SendSmsRequest sendSmsRequest = SendSmsRequest.builder()
+                .signName(StringUtils.nvl(signName, "社区功能"))
+                .templateCode(StringUtils.nvl(templateCode, "SMS_474645121"))
+                .phoneNumbers(StringUtils.nvl(phoneNumbers, "13358039598"))
+                .templateParam("{\"code\":\"" + code + "\"}")
+                // Request-level configuration rewrite, can set Http request parameters, etc.
+                // .requestConfiguration(RequestConfiguration.create().setHttpHeaders(new HttpHeaders()))
+                .build();
+
+        // Asynchronously get the return value of the API request
+        CompletableFuture<SendSmsResponse> response = client.sendSms(sendSmsRequest);
+        // Synchronously get the return value of the API request
+        SendSmsResponse resp = response.get();
+        System.out.println(new Gson().toJson(resp));
+        client.close();
+    }
+}

+ 12 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/vo/CommunityUserInfoVo.java

@@ -40,6 +40,18 @@ public class CommunityUserInfoVo implements Serializable {
      */
     @ApiModelProperty("简介")
     private String profile;
+    /**
+     * 关注数量
+     */
+    private int likeCount;
+    /**
+     * 粉丝数量
+     */
+    private int fansCount;
+    /**
+     * 陪伴数量
+     */
+    private int companionCount;
     /**
     * 创建人
     */

+ 3 - 0
ruoyi-generator/src/main/resources/mapper/community/ArticleMapper.xml

@@ -145,6 +145,9 @@
                     #{circleId}
                 </foreach>
             </if>
+            <if test="communityArticle.userId != null and communityArticle.userId != ''">
+                AND a.user_id = #{communityArticle.userId}
+            </if>
         </where>
         limit #{offset},#{limit}
     </select>