|
|
@@ -1,8 +1,14 @@
|
|
|
package com.fs.course.service.impl;
|
|
|
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+import com.fs.common.exception.CustomException;
|
|
|
import com.fs.common.utils.DateUtils;
|
|
|
+import com.fs.common.utils.StringUtils;
|
|
|
+import com.fs.course.dto.FsCourseCategoryImportDTO;
|
|
|
import com.fs.his.vo.OptionsVO;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.fs.course.mapper.FsUserCourseCategoryMapper;
|
|
|
@@ -15,6 +21,7 @@ import com.fs.course.service.IFsUserCourseCategoryService;
|
|
|
* @author fs
|
|
|
* @date 2024-05-15
|
|
|
*/
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
public class FsUserCourseCategoryServiceImpl implements IFsUserCourseCategoryService
|
|
|
{
|
|
|
@@ -118,4 +125,85 @@ public class FsUserCourseCategoryServiceImpl implements IFsUserCourseCategorySer
|
|
|
public List<OptionsVO> selectCateListByPid(Long pid) {
|
|
|
return fsUserCourseCategoryMapper.selectCateListByPid(pid);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 课堂分类导入
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> importData(List<FsCourseCategoryImportDTO> list, Long userId) {
|
|
|
+ int suCnt = 0;
|
|
|
+ int filCnt = 0;
|
|
|
+ List<FsCourseCategoryImportDTO> failedList = new ArrayList<>();
|
|
|
+
|
|
|
+ if (list == null || list.isEmpty()) {
|
|
|
+ throw new CustomException("导入数据不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, List<FsCourseCategoryImportDTO>> rootMap = list.stream()
|
|
|
+ .filter(dto -> StringUtils.isNotBlank(dto.getRootCate()))
|
|
|
+ .collect(Collectors.groupingBy(FsCourseCategoryImportDTO::getRootCate));
|
|
|
+ for (Map.Entry<String, List<FsCourseCategoryImportDTO>> entry : rootMap.entrySet()) {
|
|
|
+ if (StringUtils.isBlank(entry.getKey())) {
|
|
|
+ failedList.addAll(entry.getValue());
|
|
|
+ filCnt += entry.getValue().size();
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ String rootCate = entry.getKey().trim();
|
|
|
+ FsUserCourseCategory root = fsUserCourseCategoryMapper.selectFsUserCourseCategoryByNameAndParentId(rootCate, 0L);
|
|
|
+ if (Objects.isNull(root)) {
|
|
|
+ root = new FsUserCourseCategory();
|
|
|
+ root.setPid(0L);
|
|
|
+ root.setCateName(rootCate);
|
|
|
+ root.setSort(fsUserCourseCategoryMapper.getSortByParentId(0L));
|
|
|
+ root.setIsShow(1);
|
|
|
+ root.setCreateTime(new Date());
|
|
|
+ root.setIsDel(0);
|
|
|
+ root.setUserId(userId);
|
|
|
+ fsUserCourseCategoryMapper.insertFsUserCourseCategory(root);
|
|
|
+ }
|
|
|
+
|
|
|
+ Long parentId = root.getCateId();
|
|
|
+ long curSort = fsUserCourseCategoryMapper.getSortByParentId(root.getCateId());
|
|
|
+ List<FsCourseCategoryImportDTO> subList = entry.getValue();
|
|
|
+ for (FsCourseCategoryImportDTO child : subList) {
|
|
|
+ try {
|
|
|
+ if (StringUtils.isBlank(child.getSubCate())) {
|
|
|
+ failedList.add(child);
|
|
|
+ filCnt++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ String cateName = child.getSubCate().trim();
|
|
|
+ FsUserCourseCategory sub = fsUserCourseCategoryMapper.selectFsUserCourseCategoryByNameAndParentId(cateName, parentId);
|
|
|
+ if (Objects.nonNull(sub)) {
|
|
|
+ failedList.add(child);
|
|
|
+ filCnt++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ sub = new FsUserCourseCategory();
|
|
|
+ sub.setPid(parentId);
|
|
|
+ sub.setCateName(cateName);
|
|
|
+ sub.setSort(curSort++);
|
|
|
+ sub.setIsShow(1);
|
|
|
+ sub.setCreateTime(new Date());
|
|
|
+ sub.setIsDel(0);
|
|
|
+ sub.setUserId(userId);
|
|
|
+ fsUserCourseCategoryMapper.insertFsUserCourseCategory(sub);
|
|
|
+
|
|
|
+ suCnt++;
|
|
|
+ } catch (Exception e) {
|
|
|
+ filCnt++;
|
|
|
+ log.error("导入子分类失败: {}", child, e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ String message = "导入完成!成功" + suCnt + "条,失败" + filCnt + "条。";
|
|
|
+ Map<String, Object> resp = new HashMap<>();
|
|
|
+ resp.put("message", message);
|
|
|
+ resp.put("failList", failedList);
|
|
|
+ return resp;
|
|
|
+ }
|
|
|
}
|