wangxy 2 days ago
parent
commit
d344502dfc

+ 51 - 0
fs-admin/src/main/java/com/fs/course/controller/FsCourseWatchCommentController.java

@@ -1,13 +1,17 @@
 package com.fs.course.controller;
 
+import java.io.IOException;
+import java.util.ArrayList;
 import java.util.List;
 
 import com.fs.common.core.domain.R;
 import com.fs.course.param.FsCourseWatchCommentPageParam;
+import com.fs.course.vo.CommentImportTemplate;
 import com.fs.course.vo.FsCourseWatchCommentListVO;
 import com.fs.qw.service.IQwExternalContactService;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
+import org.checkerframework.checker.units.qual.A;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -26,6 +30,9 @@ import com.fs.course.domain.FsCourseWatchComment;
 import com.fs.course.service.IFsCourseWatchCommentService;
 import com.fs.common.utils.poi.ExcelUtil;
 import com.fs.common.core.page.TableDataInfo;
+import org.springframework.web.multipart.MultipartFile;
+
+import javax.servlet.http.HttpServletResponse;
 
 /**
  * 看课评论Controller
@@ -145,4 +152,48 @@ public class FsCourseWatchCommentController extends BaseController
         }
     }
 
+    /**
+     * 下载导入模板
+     */
+    @Log(title = "评论导入模板", businessType = BusinessType.EXPORT)
+    @GetMapping("/template")
+    public AjaxResult downloadTemplate() {
+        try {
+            ExcelUtil<CommentImportTemplate> util = new ExcelUtil<>(CommentImportTemplate.class);
+            List<CommentImportTemplate> templateData = new ArrayList<>();
+            CommentImportTemplate example = createExampleRow();
+            templateData.add(example);
+           return  util.exportExcel(templateData, "评论导入模板");
+        } catch (Exception e) {
+            logger.error("下载评论导入模板失败", e);
+        }
+        return AjaxResult.error();
+    }
+
+    /**
+     * 创建示例数据行(用于模板参考)
+     */
+    private CommentImportTemplate createExampleRow() {
+        CommentImportTemplate example = new CommentImportTemplate();
+        example.setUserId(50L);
+        example.setCourseId(20001L);
+        example.setVideoId(30001L);
+        example.setType(1);
+        example.setUserType(2);
+        example.setContent("请输入您的评论内容...");
+        example.setFontSize("14px");
+        example.setMode("normal");
+        example.setColor("#333333");
+        return example;
+    }
+
+    @PostMapping("/import")
+    @Log(title = "导入看课评论", businessType = BusinessType.IMPORT)
+    public  R importData(MultipartFile file) throws Exception {
+        ExcelUtil<CommentImportTemplate> util = new ExcelUtil<>(CommentImportTemplate.class);
+        List<CommentImportTemplate> commentImportTemplates = util.importExcel(file.getInputStream());
+        int i = fsCourseWatchCommentService.insertBatch(commentImportTemplates);
+        return R.ok().put("data", i);
+    }
+
 }

+ 9 - 0
fs-service/src/main/java/com/fs/course/service/IFsCourseWatchCommentService.java

@@ -7,6 +7,7 @@ import com.fs.course.domain.FsCourseWatchComment;
 import com.fs.course.param.FsCourseWatchCommentListParam;
 import com.fs.course.param.FsCourseWatchCommentPageParam;
 import com.fs.course.param.FsCourseWatchCommentSaveParam;
+import com.fs.course.vo.CommentImportTemplate;
 import com.fs.course.vo.FsCourseWatchCommentListVO;
 import com.fs.course.vo.FsCourseWatchCommentVO;
 
@@ -41,6 +42,14 @@ public interface IFsCourseWatchCommentService extends IService<FsCourseWatchComm
      */
     int insertFsCourseWatchComment(FsCourseWatchComment fsCourseWatchComment);
 
+    /**
+     * 批量新增看课评论
+     *
+     * @param list 新增看课评论列表
+     * @return 结果
+     */
+    int insertBatch(List<CommentImportTemplate> list);
+
     /**
      * 修改看课评论
      *

+ 26 - 18
fs-service/src/main/java/com/fs/course/service/impl/FsCourseWatchCommentServiceImpl.java

@@ -2,6 +2,7 @@ package com.fs.course.service.impl;
 
 import java.util.List;
 import java.util.Set;
+import java.util.concurrent.atomic.AtomicInteger;
 import java.util.stream.Collectors;
 
 import com.fs.common.core.domain.R;
@@ -11,6 +12,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.fs.course.param.FsCourseWatchCommentListParam;
 import com.fs.course.param.FsCourseWatchCommentPageParam;
 import com.fs.course.param.FsCourseWatchCommentSaveParam;
+import com.fs.course.vo.CommentImportTemplate;
 import com.fs.course.vo.FsCourseWatchCommentListVO;
 import com.fs.course.vo.FsCourseWatchCommentVO;
 import com.fs.qw.mapper.QwExternalContactMapper;
@@ -42,7 +44,7 @@ public class FsCourseWatchCommentServiceImpl extends ServiceImpl<FsCourseWatchCo
     private QwExternalContactMapper qwExternalContactMapper;
 
     @Autowired
-    public RedisTemplate<String,String> redisTemplate;
+    public RedisTemplate<String, String> redisTemplate;
 
     @Autowired
     private SysKeywordMapper mapper;
@@ -54,8 +56,7 @@ public class FsCourseWatchCommentServiceImpl extends ServiceImpl<FsCourseWatchCo
      * @return 看课评论
      */
     @Override
-    public FsCourseWatchComment selectFsCourseWatchCommentByCommentId(Long commentId)
-    {
+    public FsCourseWatchComment selectFsCourseWatchCommentByCommentId(Long commentId) {
         return baseMapper.selectFsCourseWatchCommentByCommentId(commentId);
     }
 
@@ -66,8 +67,7 @@ public class FsCourseWatchCommentServiceImpl extends ServiceImpl<FsCourseWatchCo
      * @return 看课评论
      */
     @Override
-    public List<FsCourseWatchCommentListVO> selectFsCourseWatchCommentList(FsCourseWatchCommentPageParam fsCourseWatchCommentPageParam)
-    {
+    public List<FsCourseWatchCommentListVO> selectFsCourseWatchCommentList(FsCourseWatchCommentPageParam fsCourseWatchCommentPageParam) {
         return baseMapper.selectFsCourseWatchCommentList(fsCourseWatchCommentPageParam);
     }
 
@@ -78,12 +78,23 @@ public class FsCourseWatchCommentServiceImpl extends ServiceImpl<FsCourseWatchCo
      * @return 结果
      */
     @Override
-    public int insertFsCourseWatchComment(FsCourseWatchComment fsCourseWatchComment)
-    {
+    public int insertFsCourseWatchComment(FsCourseWatchComment fsCourseWatchComment) {
         fsCourseWatchComment.setCreateTime(DateUtils.getNowDate());
         return baseMapper.insertFsCourseWatchComment(fsCourseWatchComment);
     }
 
+    @Override
+    public int insertBatch(List<CommentImportTemplate> list) {
+        AtomicInteger i = new AtomicInteger(0);
+        list.forEach(item -> {
+            FsCourseWatchComment fsCourseWatchComment = new FsCourseWatchComment();
+            BeanUtils.copyProperties(item, fsCourseWatchComment);
+            fsCourseWatchComment.setCreateTime(DateUtils.getNowDate());
+            i.addAndGet(baseMapper.insertFsCourseWatchComment(fsCourseWatchComment));
+        });
+        return i.get();
+    }
+
     /**
      * 修改看课评论
      *
@@ -91,8 +102,7 @@ public class FsCourseWatchCommentServiceImpl extends ServiceImpl<FsCourseWatchCo
      * @return 结果
      */
     @Override
-    public int updateFsCourseWatchComment(FsCourseWatchComment fsCourseWatchComment)
-    {
+    public int updateFsCourseWatchComment(FsCourseWatchComment fsCourseWatchComment) {
         fsCourseWatchComment.setUpdateTime(DateUtils.getNowDate());
         return baseMapper.updateFsCourseWatchComment(fsCourseWatchComment);
     }
@@ -104,8 +114,7 @@ public class FsCourseWatchCommentServiceImpl extends ServiceImpl<FsCourseWatchCo
      * @return 结果
      */
     @Override
-    public int deleteFsCourseWatchCommentByCommentIds(Long[] commentIds)
-    {
+    public int deleteFsCourseWatchCommentByCommentIds(Long[] commentIds) {
         return baseMapper.deleteFsCourseWatchCommentByCommentIds(commentIds);
     }
 
@@ -116,21 +125,20 @@ public class FsCourseWatchCommentServiceImpl extends ServiceImpl<FsCourseWatchCo
      * @return 结果
      */
     @Override
-    public int deleteFsCourseWatchCommentByCommentId(Long commentId)
-    {
+    public int deleteFsCourseWatchCommentByCommentId(Long commentId) {
         return baseMapper.deleteFsCourseWatchCommentByCommentId(commentId);
     }
 
     @Override
     public R saveH5CourseWatchComment(FsCourseWatchCommentSaveParam param) {
         // 需求:查询是否包含关键字,包含则不保存,并且需要将用户标记为黑名单;
-        Set<String>  keywords = redisTemplate.opsForSet().members(REDIS_KEY);
-        if(keywords == null || keywords.isEmpty()){
+        Set<String> keywords = redisTemplate.opsForSet().members(REDIS_KEY);
+        if (keywords == null || keywords.isEmpty()) {
             SysKeyword sysKeywordParam = new SysKeyword();
             List<SysKeyword> sysKeywords = mapper.selectSysKeywordList(sysKeywordParam);
             keywords = sysKeywords.stream().map(SysKeyword::getKeyword).collect(Collectors.toSet());
         }
-        if(!keywords.isEmpty()){
+        if (!keywords.isEmpty()) {
             for (String keyword : keywords) {
                 if (param.getContent().contains(keyword)) {
                     //标记用户为黑名单,并且不保存数据
@@ -153,7 +161,7 @@ public class FsCourseWatchCommentServiceImpl extends ServiceImpl<FsCourseWatchCo
     @Override
     public R revokeH5CourseWatchComment(Long commentId) {
         int i = baseMapper.revokeH5CourseWatchComment(commentId);
-        if (i > 0){
+        if (i > 0) {
             return R.ok();
         } else {
             return R.error();
@@ -162,7 +170,7 @@ public class FsCourseWatchCommentServiceImpl extends ServiceImpl<FsCourseWatchCo
 
     @Override
     public List<FsCourseWatchCommentVO> selectH5CourseWatchComments(FsCourseWatchCommentListParam param) {
-        if(param.getOpenCommentStatus() != null && 2 == param.getOpenCommentStatus()){
+        if (param.getOpenCommentStatus() != null && 2 == param.getOpenCommentStatus()) {
             return baseMapper.selectH5CourseWatchCommentsRound(param);
         } else {
             return baseMapper.selectH5CourseWatchComments(param);

+ 40 - 0
fs-service/src/main/java/com/fs/course/vo/CommentImportTemplate.java

@@ -0,0 +1,40 @@
+package com.fs.course.vo;
+
+import com.fs.common.annotation.Excel;
+import lombok.Data;
+
+@Data
+public class CommentImportTemplate {
+
+    @Excel(name = "用户id", cellType = Excel.ColumnType.NUMERIC)
+    private Long userId;
+
+    @Excel(name = "用户类型")
+    private Integer userType;
+
+    @Excel(name = "课程id", cellType = Excel.ColumnType.NUMERIC)
+    private Long courseId;
+
+    @Excel(name = "视频id", cellType = Excel.ColumnType.NUMERIC)
+    private Long videoId;
+
+    @Excel(name = "评论类型")
+    private Integer type;
+
+    @Excel(name = "父评论id", cellType = Excel.ColumnType.NUMERIC, prompt = "回复时必填,评论时留空")
+    private Long parentId;
+
+    @Excel(name = "评论内容", prompt = "最多500字")
+    private String content;
+
+
+    @Excel(name = "字体大小", prompt = "选填,如:14px")
+    private String fontSize;
+
+    @Excel(name = "展示模式", prompt = "选填")
+    private String mode;
+
+    @Excel(name = "字体颜色", prompt = "选填,如:#333333")
+    private String color;
+
+}