|
@@ -14,6 +14,9 @@ import com.ruoyi.common.core.redis.RedisCache;
|
|
|
import com.ruoyi.common.core.text.Convert;
|
|
|
import com.ruoyi.common.exception.user.ProjectException;
|
|
|
import com.ruoyi.common.utils.*;
|
|
|
+import com.ruoyi.common.utils.file.FileUtils;
|
|
|
+import com.ruoyi.common.utils.file.ImageUtils;
|
|
|
+import com.ruoyi.common.utils.file.OssUtils;
|
|
|
import com.ruoyi.common.utils.ip.IpUtils;
|
|
|
import com.ruoyi.generator.domain.Community.*;
|
|
|
import com.ruoyi.generator.mapper.community.*;
|
|
@@ -28,6 +31,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import java.io.File;
|
|
|
import java.text.ParseException;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -191,7 +195,7 @@ public class CommunityArticleController extends BaseController {
|
|
|
|
|
|
//判断当前用户有没有被禁言
|
|
|
SysUser sysUser = sysUserMapper.selectUserById(SecurityUtils.getUserId());
|
|
|
- if (sysUser != null){
|
|
|
+ if (sysUser != null) {
|
|
|
String userState = sysUser.getUserState();
|
|
|
Date reportTime = sysUser.getReportTime();
|
|
|
if ("2".equals(userState) && reportTime != null) {
|
|
@@ -202,7 +206,7 @@ public class CommunityArticleController extends BaseController {
|
|
|
// 检查 reportTime 小于当前时间
|
|
|
if (currentTime.before(reportTime)) {
|
|
|
// 返回封号的提示
|
|
|
- return AjaxResult.success("当前用户已被禁言!");
|
|
|
+ return AjaxResult.success("当前用户已被禁言!");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -219,6 +223,35 @@ public class CommunityArticleController extends BaseController {
|
|
|
return AjaxResult.error(MessageUtils.message("article.content.error"));
|
|
|
}
|
|
|
|
|
|
+ //检查附近是否是需要加水印
|
|
|
+ boolean isWaterMark = communityArticle.isWaterMark();
|
|
|
+ boolean isFillWater = communityArticle.isFillWater();
|
|
|
+ if (isWaterMark) {
|
|
|
+ //获取用户名
|
|
|
+ String nickName = SecurityUtils.getLoginUser().getUser().getNickName();
|
|
|
+ // 添加水印
|
|
|
+ for (CommunityImagesVo image : communityArticle.getImages()) {
|
|
|
+ String fileType = FileUtils.getFileTypeFromUrl(image.getImages());
|
|
|
+ if ("image".equals(fileType)) {
|
|
|
+ // 本地临时水印文件路径
|
|
|
+ String tempWatermarkFile = System.getProperty("java.io.tmpdir") + File.separator + "watermark_" + FileUtils.getName(image.getImages());
|
|
|
+ String tempSourceFile = System.getProperty("java.io.tmpdir") + File.separator + "source_" + FileUtils.getName(image.getImages());
|
|
|
+ OssUtils.downloadFile(image.getImages().replace("http://file.iciyuanshidai.com/", ""), tempSourceFile);
|
|
|
+ ImageUtils.addWatermark(
|
|
|
+ isFillWater,
|
|
|
+ image.getImages().replace("http://file.iciyuanshidai.com/", ""),
|
|
|
+ new File(tempSourceFile),
|
|
|
+ new File(tempWatermarkFile),
|
|
|
+ "@" + nickName,
|
|
|
+ "ACG爱好者社区"
|
|
|
+ );
|
|
|
+ // 上传加水印的文件到OSS
|
|
|
+ String fileNameResult = OssUtils.uploadFile(tempWatermarkFile);
|
|
|
+ image.setImages(fileNameResult.replace("https://cysd.oss-cn-shanghai.aliyuncs.com", "http://file.iciyuanshidai.com/"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
communityArticleService.insertCommunityArticle(communityArticle);
|
|
|
} catch (Exception e) {
|
|
|
System.out.println(e.getMessage());
|
|
@@ -313,7 +346,7 @@ public class CommunityArticleController extends BaseController {
|
|
|
Long userId = SecurityUtils.getLoginUser().getUserId();
|
|
|
String classId = communityArticleService.selectCommunityUserInfoById(userId, true).getClassId();
|
|
|
|
|
|
- if (classId != null && !classId.isEmpty()){
|
|
|
+ if (classId != null && !classId.isEmpty()) {
|
|
|
List<Long> sortOrder = Arrays.stream(classId.split(","))
|
|
|
.map(String::trim)
|
|
|
.map(Long::parseLong)
|
|
@@ -340,7 +373,7 @@ public class CommunityArticleController extends BaseController {
|
|
|
|
|
|
sortedCommunityClasses.addAll(remainingClasses);
|
|
|
return AjaxResult.success(sortedCommunityClasses);
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
communityClasses = communityClassMapper.selectList(new QueryWrapper<CommunityClass>().orderByAsc("sort"));
|
|
|
|
|
|
}
|
|
@@ -353,7 +386,6 @@ public class CommunityArticleController extends BaseController {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
@GetMapping("/circleList")
|
|
|
@ApiOperation("获取文章圈子列表")
|
|
|
//@Anonymous
|
|
@@ -402,7 +434,7 @@ public class CommunityArticleController extends BaseController {
|
|
|
}
|
|
|
//判断当前用户有没有被禁言
|
|
|
SysUser sysUser = sysUserMapper.selectUserById(SecurityUtils.getUserId());
|
|
|
- if (sysUser != null){
|
|
|
+ if (sysUser != null) {
|
|
|
String userState = sysUser.getUserState();
|
|
|
Date reportTime = sysUser.getReportTime();
|
|
|
if ("2".equals(userState) && reportTime != null) {
|
|
@@ -411,7 +443,7 @@ public class CommunityArticleController extends BaseController {
|
|
|
// 检查 reportTime 小于当前时间
|
|
|
if (currentTime.before(reportTime)) {
|
|
|
// 返回封号的提示
|
|
|
- return AjaxResult.success("当前用户已被禁言!");
|
|
|
+ return AjaxResult.success("当前用户已被禁言!");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -812,7 +844,7 @@ public class CommunityArticleController extends BaseController {
|
|
|
@ApiOperation("获取用户信息")
|
|
|
@GetMapping("/userInfo")
|
|
|
@Anonymous
|
|
|
- public AjaxResult userInfo(@RequestParam(required = false) Long userId,boolean isToken) {
|
|
|
+ public AjaxResult userInfo(@RequestParam(required = false) Long userId, boolean isToken) {
|
|
|
if (Objects.isNull(userId)) {
|
|
|
userId = SecurityUtils.getLoginUser().getUserId();
|
|
|
|
|
@@ -826,7 +858,7 @@ public class CommunityArticleController extends BaseController {
|
|
|
|
|
|
CommunityUserInfoVo communityUserInfoVo = null;
|
|
|
try {
|
|
|
- communityUserInfoVo = communityArticleService.selectCommunityUserInfoById(userId,isToken);
|
|
|
+ communityUserInfoVo = communityArticleService.selectCommunityUserInfoById(userId, isToken);
|
|
|
} catch (Exception e) {
|
|
|
System.out.println(e.getMessage());
|
|
|
throw new ProjectException();
|
|
@@ -1231,7 +1263,7 @@ public class CommunityArticleController extends BaseController {
|
|
|
@ApiOperation("查询用户合集")
|
|
|
@GetMapping("/getCollection")
|
|
|
@Anonymous
|
|
|
- public AjaxResult getCollection(Long collectionId, Long searchType,@RequestParam(required = false) Long userId) {
|
|
|
+ public AjaxResult getCollection(Long collectionId, Long searchType, @RequestParam(required = false) Long userId) {
|
|
|
if (Objects.isNull(collectionId)) {
|
|
|
return AjaxResult.error("合集不存在!");
|
|
|
}
|
|
@@ -1243,7 +1275,7 @@ public class CommunityArticleController extends BaseController {
|
|
|
List<CommunityCollectionArticleVo> collectionArticleVos = null;
|
|
|
JSONArray jsonArray;
|
|
|
try {
|
|
|
- jsonArray = communityCollectionService.selectArticleInfoInCollection(userId,collectionId, searchType);
|
|
|
+ jsonArray = communityCollectionService.selectArticleInfoInCollection(userId, collectionId, searchType);
|
|
|
} catch (Exception e) {
|
|
|
System.out.println(e.getMessage());
|
|
|
throw new ProjectException();
|
|
@@ -1318,6 +1350,7 @@ public class CommunityArticleController extends BaseController {
|
|
|
}
|
|
|
return AjaxResult.success(communityUserPromptVo);
|
|
|
}
|
|
|
+
|
|
|
@ApiOperation("个人未加入集合文章")
|
|
|
@GetMapping("/userNoCo")
|
|
|
@Anonymous
|
|
@@ -1483,13 +1516,13 @@ public class CommunityArticleController extends BaseController {
|
|
|
return AjaxResult.success("文章不属于当前用户,无法置顶");
|
|
|
}
|
|
|
Boolean isTop = toparticle.getIsTop();
|
|
|
- if (!isTop){
|
|
|
+ if (!isTop) {
|
|
|
communityArticleService.update(new UpdateWrapper<CommunityArticle>()
|
|
|
.set("is_top", true)
|
|
|
.set("top_time", DateUtils.parseDate(DateUtils.getTime()))
|
|
|
.eq("id", communityArticle.getId()));
|
|
|
msg = "已置顶";
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
communityArticleService.update(new UpdateWrapper<CommunityArticle>()
|
|
|
.set("is_top", false)
|
|
|
.set("top_time", DateUtils.parseDate(DateUtils.getTime()))
|
|
@@ -1504,7 +1537,7 @@ public class CommunityArticleController extends BaseController {
|
|
|
wrapper.ne("is_delete", 1).or().isNull("is_delete");
|
|
|
}));
|
|
|
if (communityArticles.size() > 3) {
|
|
|
- //大于三条则 排序
|
|
|
+ //大于三条则 排序
|
|
|
communityArticles = communityArticles.stream()
|
|
|
.sorted(Comparator.comparing(CommunityArticle::getTopTime).reversed()) // 降序排列(最新文章排在前面)
|
|
|
.limit(3)
|