Explorar el Código

看课评论管理修改

wangxy hace 6 horas
padre
commit
89bc4ca3b9

+ 15 - 4
fs-admin/src/main/java/com/fs/course/controller/FsCourseWatchCommentController.java

@@ -2,6 +2,7 @@ package com.fs.course.controller;
 
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 
 import com.fs.common.core.domain.R;
@@ -157,13 +158,23 @@ public class FsCourseWatchCommentController extends BaseController
      */
     @Log(title = "评论导入模板", businessType = BusinessType.EXPORT)
     @GetMapping("/template")
-    public AjaxResult downloadTemplate() {
+    public AjaxResult downloadTemplate(Integer type) {
         try {
             ExcelUtil<CommentImportTemplate> util = new ExcelUtil<>(CommentImportTemplate.class);
             List<CommentImportTemplate> templateData = new ArrayList<>();
             CommentImportTemplate example = createExampleRow();
             templateData.add(example);
-           return  util.exportExcel(templateData, "评论导入模板");
+            // 根据type参数确定需要导出的字段
+            List<String> selectedFields = new ArrayList<>();
+            if (type != null && type == 1) {
+                // 视频类型,不包含课程列
+                selectedFields.addAll(Arrays.asList("userId", "userType", "videoId", "type", "parentId", "content", "fontSize", "mode", "color"));
+            } else {
+                // 默认课程类型,不包含视频列
+                selectedFields.addAll(Arrays.asList("userId", "userType", "courseId", "type", "parentId", "content", "fontSize", "mode", "color"));
+            }
+
+            return util.exportExcelSelectedColumns(templateData, "评论导入模板", selectedFields);
         } catch (Exception e) {
             logger.error("下载评论导入模板失败", e);
         }
@@ -189,10 +200,10 @@ public class FsCourseWatchCommentController extends BaseController
 
     @PostMapping("/import")
     @Log(title = "导入看课评论", businessType = BusinessType.IMPORT)
-    public  R importData(MultipartFile file) throws Exception {
+    public  R importData(MultipartFile file,Integer type) throws Exception {
         ExcelUtil<CommentImportTemplate> util = new ExcelUtil<>(CommentImportTemplate.class);
         List<CommentImportTemplate> commentImportTemplates = util.importExcel(file.getInputStream());
-        int i = fsCourseWatchCommentService.insertBatch(commentImportTemplates);
+        int i = fsCourseWatchCommentService.insertBatch(commentImportTemplates,type);
         return R.ok().put("data", i);
     }
 

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

@@ -48,7 +48,7 @@ public interface IFsCourseWatchCommentService extends IService<FsCourseWatchComm
      * @param list 新增看课评论列表
      * @return 结果
      */
-    int insertBatch(List<CommentImportTemplate> list);
+    int insertBatch(List<CommentImportTemplate> list,Integer type);
 
     /**
      * 修改看课评论

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

@@ -7,6 +7,7 @@ import java.util.stream.Collectors;
 
 import com.fs.common.core.domain.R;
 import com.fs.common.core.redis.RedisCache;
+import com.fs.common.exception.ServiceException;
 import com.fs.common.utils.DateUtils;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.fs.course.param.FsCourseWatchCommentListParam;
@@ -18,6 +19,7 @@ import com.fs.course.vo.FsCourseWatchCommentVO;
 import com.fs.qw.mapper.QwExternalContactMapper;
 import com.fs.system.domain.SysKeyword;
 import com.fs.system.mapper.SysKeywordMapper;
+import jodd.util.CollectionUtil;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.redis.core.RedisTemplate;
@@ -25,6 +27,7 @@ import org.springframework.stereotype.Service;
 import com.fs.course.mapper.FsCourseWatchCommentMapper;
 import com.fs.course.domain.FsCourseWatchComment;
 import com.fs.course.service.IFsCourseWatchCommentService;
+import org.springframework.util.CollectionUtils;
 
 /**
  * 看课评论Service业务层处理
@@ -84,7 +87,29 @@ public class FsCourseWatchCommentServiceImpl extends ServiceImpl<FsCourseWatchCo
     }
 
     @Override
-    public int insertBatch(List<CommentImportTemplate> list) {
+    public int insertBatch(List<CommentImportTemplate> list, Integer type) {
+        if (CollectionUtils.isEmpty(list)) {
+            throw new ServiceException("导入数据不能为空!");
+        }
+        if (type != null) {
+            if (type == 1) {
+                // 视频类型,检查是否包含视频ID
+                boolean hasValidVideo = list.stream()
+                        .anyMatch(template -> template.getVideoId() != null && template.getVideoId() > 0);
+
+                if (!hasValidVideo) {
+                    throw new ServiceException("请选择课程类型导入课程");
+                }
+            } else {
+                // 课程类型,检查是否包含课程ID
+                boolean hasValidCourse = list.stream()
+                        .anyMatch(template -> template.getCourseId() != null && template.getCourseId() > 0);
+
+                if (!hasValidCourse) {
+                    throw new ServiceException("请选择视频课程导入视频");
+                }
+            }
+        }
         AtomicInteger i = new AtomicInteger(0);
         list.forEach(item -> {
             FsCourseWatchComment fsCourseWatchComment = new FsCourseWatchComment();