|
@@ -1,6 +1,7 @@
|
|
|
package com.fs.app.controller;
|
|
package com.fs.app.controller;
|
|
|
|
|
|
|
|
import com.fs.app.annotation.Login;
|
|
import com.fs.app.annotation.Login;
|
|
|
|
|
+import com.fs.app.controller.store.CourseCommentScrmController;
|
|
|
import com.fs.common.annotation.Log;
|
|
import com.fs.common.annotation.Log;
|
|
|
import com.fs.common.core.controller.BaseController;
|
|
import com.fs.common.core.controller.BaseController;
|
|
|
import com.fs.common.core.domain.AjaxResult;
|
|
import com.fs.common.core.domain.AjaxResult;
|
|
@@ -24,6 +25,9 @@ import com.fs.course.param.FsUserCourseCommentUParam;
|
|
|
import com.fs.course.service.IFsUserCourseService;
|
|
import com.fs.course.service.IFsUserCourseService;
|
|
|
import com.fs.config.cloud.CloudHostProper;
|
|
import com.fs.config.cloud.CloudHostProper;
|
|
|
import com.fs.sensitive.ProductionWordFilter;
|
|
import com.fs.sensitive.ProductionWordFilter;
|
|
|
|
|
+import com.fs.course.config.CourseConfig;
|
|
|
|
|
+import com.fs.system.service.ISysConfigService;
|
|
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
import com.fs.course.vo.FsUserCourseCommentListUVO;
|
|
import com.fs.course.vo.FsUserCourseCommentListUVO;
|
|
|
import com.fs.course.vo.FsUserCourseCommentReplyListUVO;
|
|
import com.fs.course.vo.FsUserCourseCommentReplyListUVO;
|
|
|
import com.fs.course.vo.FsUserCourseCommentVO;
|
|
import com.fs.course.vo.FsUserCourseCommentVO;
|
|
@@ -37,6 +41,8 @@ import lombok.Data;
|
|
|
import lombok.Synchronized;
|
|
import lombok.Synchronized;
|
|
|
import me.chanjar.weixin.common.util.DataUtils;
|
|
import me.chanjar.weixin.common.util.DataUtils;
|
|
|
import net.bytebuddy.implementation.bytecode.Throw;
|
|
import net.bytebuddy.implementation.bytecode.Throw;
|
|
|
|
|
+import org.slf4j.Logger;
|
|
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -44,8 +50,15 @@ import org.springframework.util.unit.DataUnit;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
+import com.fs.common.utils.DateUtils;
|
|
|
|
|
+import com.fs.system.oss.CloudStorageService;
|
|
|
|
|
+import com.fs.system.oss.OSSFactory;
|
|
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
+
|
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
+import java.util.UUID;
|
|
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 课堂评论Controller
|
|
* 课堂评论Controller
|
|
@@ -58,6 +71,9 @@ import java.util.List;
|
|
|
@RequestMapping(value="/app/course/comment")
|
|
@RequestMapping(value="/app/course/comment")
|
|
|
public class CourseCommentController extends AppBaseController
|
|
public class CourseCommentController extends AppBaseController
|
|
|
{
|
|
{
|
|
|
|
|
+
|
|
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(CourseCommentController.class);
|
|
|
|
|
+
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private IFsUserCourseCommentService fsUserCourseCommentService;
|
|
private IFsUserCourseCommentService fsUserCourseCommentService;
|
|
|
|
|
|
|
@@ -72,6 +88,9 @@ public class CourseCommentController extends AppBaseController
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private ProductionWordFilter productionWordFilter;
|
|
private ProductionWordFilter productionWordFilter;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private ISysConfigService configService;
|
|
|
/**
|
|
/**
|
|
|
* 查询课堂评论列表
|
|
* 查询课堂评论列表
|
|
|
*/
|
|
*/
|
|
@@ -115,7 +134,10 @@ public class CourseCommentController extends AppBaseController
|
|
|
public R add(@RequestBody FsUserCourseCommentAddParam param)
|
|
public R add(@RequestBody FsUserCourseCommentAddParam param)
|
|
|
{
|
|
{
|
|
|
String content = param.getContent();
|
|
String content = param.getContent();
|
|
|
- if ("北京卓美".equals(cloudHostProper.getCompanyName())) {
|
|
|
|
|
|
|
+ // 判断是否开启评论内容脱敏过滤
|
|
|
|
|
+ String json = configService.selectConfigByKey("course.config");
|
|
|
|
|
+ CourseConfig courseConfig = JSONUtil.toBean(json, CourseConfig.class);
|
|
|
|
|
+ if (courseConfig != null && Boolean.TRUE.equals(courseConfig.getEnableCommentWordFilter())) {
|
|
|
if (content == null) {
|
|
if (content == null) {
|
|
|
content = "";
|
|
content = "";
|
|
|
}
|
|
}
|
|
@@ -145,6 +167,112 @@ public class CourseCommentController extends AppBaseController
|
|
|
return R.ok();
|
|
return R.ok();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 新增课堂评论(含图片视频)
|
|
|
|
|
+ */
|
|
|
|
|
+ @Login
|
|
|
|
|
+ @ApiOperation("新增课堂评论(含图片视频)")
|
|
|
|
|
+ @Transactional
|
|
|
|
|
+ @PostMapping("/addCommentWithMedia")
|
|
|
|
|
+ public R addWithMedia(
|
|
|
|
|
+ @RequestParam(value = "courseId") Long courseId,
|
|
|
|
|
+ @RequestParam(value = "type") Long type,
|
|
|
|
|
+ @RequestParam(value = "parentId", required = false) Long parentId,
|
|
|
|
|
+ @RequestParam(value = "content", required = false) String content,
|
|
|
|
|
+ @RequestParam(value = "toUserId", required = false) Long toUserId,
|
|
|
|
|
+ @RequestParam(value = "imageFiles", required = false) MultipartFile[] imageFiles,
|
|
|
|
|
+ @RequestParam(value = "videoFiles", required = false) MultipartFile[] videoFiles
|
|
|
|
|
+ ) throws Exception {
|
|
|
|
|
+ boolean b = redisCache.setIfAbsent("comment_" + courseId + "_" + getUserId(), 1, 10, TimeUnit.MINUTES);
|
|
|
|
|
+ if (!b) {
|
|
|
|
|
+ return R.error("请勿重复提交");
|
|
|
|
|
+ }
|
|
|
|
|
+ try {
|
|
|
|
|
+ // 判断是否开启评论内容脱敏过滤
|
|
|
|
|
+ String json = configService.selectConfigByKey("course.config");
|
|
|
|
|
+ CourseConfig courseConfig = JSONUtil.toBean(json, CourseConfig.class);
|
|
|
|
|
+ if (courseConfig != null && Boolean.TRUE.equals(courseConfig.getEnableCommentWordFilter())) {
|
|
|
|
|
+ if (content == null) {
|
|
|
|
|
+ content = "";
|
|
|
|
|
+ }
|
|
|
|
|
+ String filtered = productionWordFilter.filter(content).getFilteredText();
|
|
|
|
|
+ if (StringUtils.isEmpty(filtered) && (imageFiles == null || imageFiles.length == 0) && (videoFiles == null || videoFiles.length == 0)) {
|
|
|
|
|
+ return R.error("评论内容无效,请重新输入");
|
|
|
|
|
+ }
|
|
|
|
|
+ content = filtered;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 上传图片,URL拼接到content末尾
|
|
|
|
|
+ if (imageFiles != null && imageFiles.length > 0) {
|
|
|
|
|
+ long imageMaxSize = 50 * 1024 * 1024L; // 50MB
|
|
|
|
|
+ for (MultipartFile imageFile : imageFiles) {
|
|
|
|
|
+ if (imageFile.isEmpty()) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (imageFile.getSize() > imageMaxSize) {
|
|
|
|
|
+ return R.error("图片大小不能超过50MB");
|
|
|
|
|
+ }
|
|
|
|
|
+ String fileName = imageFile.getOriginalFilename();
|
|
|
|
|
+ String suffix = fileName.substring(fileName.lastIndexOf("."));
|
|
|
|
|
+ String datePath = DateUtils.dateTime();
|
|
|
|
|
+ String uuid = UUID.randomUUID().toString().replaceAll("-", "");
|
|
|
|
|
+ String path = "comment/image/" + datePath + "/" + uuid + suffix;
|
|
|
|
|
+ CloudStorageService storage = OSSFactory.build();
|
|
|
|
|
+ String url = storage.upload(imageFile.getBytes(), path);
|
|
|
|
|
+ content = (content == null ? "" : content) + "\n" + url;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 上传视频,URL拼接到content末尾
|
|
|
|
|
+ if (videoFiles != null && videoFiles.length > 0) {
|
|
|
|
|
+ long videoMaxSize = 100 * 1024 * 1024L; // 100MB
|
|
|
|
|
+ for (MultipartFile videoFile : videoFiles) {
|
|
|
|
|
+ if (videoFile.isEmpty()) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (videoFile.getSize() > videoMaxSize) {
|
|
|
|
|
+ return R.error("视频大小不能超过100MB");
|
|
|
|
|
+ }
|
|
|
|
|
+ String fileName = videoFile.getOriginalFilename();
|
|
|
|
|
+ String suffix = fileName.substring(fileName.lastIndexOf("."));
|
|
|
|
|
+ String datePath = DateUtils.dateTime();
|
|
|
|
|
+ String uuid = UUID.randomUUID().toString().replaceAll("-", "");
|
|
|
|
|
+ String path = "comment/video/" + datePath + "/" + uuid + suffix;
|
|
|
|
|
+ CloudStorageService storage = OSSFactory.build();
|
|
|
|
|
+ String url = storage.upload(videoFile.getBytes(), path);
|
|
|
|
|
+ content = (content == null ? "" : content) + "\n" + url;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ FsUserCourseComment fsUserCourseComment = new FsUserCourseComment();
|
|
|
|
|
+ fsUserCourseComment.setUserId(Long.parseLong(getUserId()));
|
|
|
|
|
+ fsUserCourseComment.setCourseId(courseId);
|
|
|
|
|
+ if (StringUtils.isNotEmpty(cloudHostProper.getCommentContentReplaceFrom())) {
|
|
|
|
|
+ content = content.replace(cloudHostProper.getCommentContentReplaceFrom(), cloudHostProper.getCommentContentReplaceTo());
|
|
|
|
|
+ }
|
|
|
|
|
+ fsUserCourseComment.setContent(content);
|
|
|
|
|
+ fsUserCourseComment.setType(type);
|
|
|
|
|
+ if (type == 1) {
|
|
|
|
|
+ fsUserCourseComment.setParentId(0L);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ fsUserCourseComment.setParentId(parentId);
|
|
|
|
|
+ }
|
|
|
|
|
+ fsUserCourseComment.setToUserId(toUserId);
|
|
|
|
|
+ fsUserCourseComment.setCreateTime(new Date());
|
|
|
|
|
+ fsUserCourseCommentService.insertFsUserCourseComment(fsUserCourseComment);
|
|
|
|
|
+ if (type == 2) {
|
|
|
|
|
+ fsUserCourseCommentService.addComment(parentId);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("新增课堂评论失败", e);
|
|
|
|
|
+ }finally {
|
|
|
|
|
+ redisCache.deleteObject("comment_" + courseId + "_" + getUserId());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ return R.ok();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 修改课堂评论
|
|
* 修改课堂评论
|
|
|
*/
|
|
*/
|