|
@@ -23,10 +23,7 @@ import org.springframework.stereotype.Service;
|
|
|
import java.net.HttpURLConnection;
|
|
|
import java.net.URL;
|
|
|
import java.text.ParseException;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Objects;
|
|
|
+import java.util.*;
|
|
|
import java.util.concurrent.ExecutionException;
|
|
|
import java.util.regex.Pattern;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -117,6 +114,8 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
|
|
|
@Autowired
|
|
|
private CommunityArticleCollectMapper communityArticleCollectMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private CommunityCommentRaffleMapper communityCommentRaffleMapper;
|
|
|
/**
|
|
|
* 查询文章列表
|
|
|
*
|
|
@@ -1004,6 +1003,56 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
|
|
|
return communityArticleVos;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 开启抽奖
|
|
|
+ * @param articleId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public CommunityCommentRaffleVo selectCommentRaffle(Long articleId) {
|
|
|
+ CommunityCommentRaffle communityCommentRaffle = communityCommentRaffleMapper.selectOne(
|
|
|
+ new QueryWrapper<CommunityCommentRaffle>()
|
|
|
+ .eq("article_id", articleId)
|
|
|
+ .and((wrapper) -> {
|
|
|
+ wrapper.ne("is_delete", true).or().isNull("is_delete");
|
|
|
+ }));
|
|
|
+
|
|
|
+ CommunityCommentRaffleVo communityCommentRaffleVo = new CommunityCommentRaffleVo();
|
|
|
+ CommunityUserInfoVo communityUserInfoVo = null;
|
|
|
+ //如果抽奖表为空则需要插入一条数据
|
|
|
+ if (communityCommentRaffle == null){
|
|
|
+ List<CommunityArticleComment> communityArticleComments = communityArticleCommentMapper.selectList(new QueryWrapper<CommunityArticleComment>()
|
|
|
+ .eq("article_id", articleId)
|
|
|
+ .and((wrapper) -> {
|
|
|
+ wrapper.ne("is_delete", true).or().isNull("is_delete");
|
|
|
+ })
|
|
|
+ );
|
|
|
+ // 使用 Random 类生成一个随机索引
|
|
|
+ Random random = new Random();
|
|
|
+ int randomIndex = random.nextInt(communityArticleComments.size());
|
|
|
+ CommunityArticleComment communityArticleComment = communityArticleComments.get(randomIndex);
|
|
|
+ CommunityCommentRaffle commentRaffle = new CommunityCommentRaffle();
|
|
|
+ commentRaffle.setArticleId(communityArticleComment.getArticleId());
|
|
|
+ commentRaffle.setCommentId(communityArticleComment.getId());
|
|
|
+ commentRaffle.setUserId(communityArticleComment.getUserId());
|
|
|
+ commentRaffle.setCreateBy(SecurityUtils.getUserId());
|
|
|
+ commentRaffle.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
|
|
|
+ communityCommentRaffleMapper.insert(commentRaffle);
|
|
|
+ BeanUtils.copyProperties(commentRaffle, communityCommentRaffleVo);
|
|
|
+ communityUserInfoVo = communityArticleService.selectCommunityUserInfoById(commentRaffle.getUserId());
|
|
|
+ communityCommentRaffleVo.setUserName(communityUserInfoVo.getNickName());
|
|
|
+ communityCommentRaffleVo.setUserAvatar(communityUserInfoVo.getAvatar());
|
|
|
+ return communityCommentRaffleVo;
|
|
|
+ }
|
|
|
+
|
|
|
+ BeanUtils.copyProperties(communityCommentRaffle, communityCommentRaffleVo);
|
|
|
+ communityUserInfoVo = communityArticleService.selectCommunityUserInfoById(communityCommentRaffle.getUserId());
|
|
|
+ communityCommentRaffleVo.setUserName(communityUserInfoVo.getNickName());
|
|
|
+ communityCommentRaffleVo.setUserAvatar(communityUserInfoVo.getAvatar());
|
|
|
+ return communityCommentRaffleVo;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 判断是否是视频文件
|
|
|
*
|