|
|
@@ -1,13 +1,16 @@
|
|
|
package com.fs.course.service.impl;
|
|
|
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
import com.fs.common.core.domain.AjaxResult;
|
|
|
+import com.fs.common.exception.CustomException;
|
|
|
import com.fs.common.utils.DateUtils;
|
|
|
+import com.fs.common.utils.StringUtils;
|
|
|
import com.fs.common.utils.poi.ExcelUtil;
|
|
|
import com.fs.course.domain.DuplicateFans;
|
|
|
import com.fs.course.domain.FsUserCourse;
|
|
|
+import com.fs.course.dto.FsCourseCategoryImportDTO;
|
|
|
import com.fs.his.domain.FsExportTask;
|
|
|
import com.fs.his.mapper.FsExportTaskMapper;
|
|
|
import com.fs.his.vo.OptionsVO;
|
|
|
@@ -143,4 +146,89 @@ public class FsUserCourseCategoryServiceImpl implements IFsUserCourseCategorySer
|
|
|
task.setFileUrl(result.get("msg").toString());
|
|
|
fsExportTaskMapper.updateFsExportTask(task);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 课堂分类导入
|
|
|
+ */
|
|
|
+ @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++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ String message = "导入完成!成功" + suCnt + "条,失败" + filCnt + "条。";
|
|
|
+ Map<String, Object> resp = new HashMap<>();
|
|
|
+ resp.put("message", message);
|
|
|
+ resp.put("failList", failedList);
|
|
|
+ return resp;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<OptionsVO> selectFsUserCourseCategoryIsOpenClassList(String isOpenClass) {
|
|
|
+ return fsUserCourseCategoryMapper.selectFsUserCourseCategoryIsOpenClassList(isOpenClass);
|
|
|
+ }
|
|
|
}
|