|
@@ -2,11 +2,15 @@ package com.xjrsoft.module.textbook.service.impl;
|
|
|
|
|
|
import cn.dev33.satoken.stp.StpUtil;
|
|
import cn.dev33.satoken.stp.StpUtil;
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
|
+import com.alibaba.excel.read.listener.PageReadListener;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.github.yulichang.base.MPJBaseServiceImpl;
|
|
import com.github.yulichang.base.MPJBaseServiceImpl;
|
|
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
|
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
|
import com.xjrsoft.common.enums.DeleteMark;
|
|
import com.xjrsoft.common.enums.DeleteMark;
|
|
|
|
+import com.xjrsoft.common.enums.TextbookTypeEnum;
|
|
|
|
+import com.xjrsoft.common.exception.MyException;
|
|
import com.xjrsoft.common.utils.VoToColumnUtil;
|
|
import com.xjrsoft.common.utils.VoToColumnUtil;
|
|
import com.xjrsoft.module.base.entity.BaseClass;
|
|
import com.xjrsoft.module.base.entity.BaseClass;
|
|
import com.xjrsoft.module.base.entity.BaseCourseSubject;
|
|
import com.xjrsoft.module.base.entity.BaseCourseSubject;
|
|
@@ -29,6 +33,7 @@ import org.springframework.beans.BeanUtils;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
+import java.io.InputStream;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -374,4 +379,86 @@ public class WfTextbookSubscriptionServiceImpl extends MPJBaseServiceImpl<WfText
|
|
}
|
|
}
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Boolean excelImport(InputStream inputStream) {
|
|
|
|
+ EasyExcel.read(inputStream, TextbookImportDto.class, new PageReadListener<TextbookImportDto>(dataList -> {
|
|
|
|
+ if (dataList.isEmpty()) {
|
|
|
|
+ throw new MyException("导入数据为空");
|
|
|
|
+ }
|
|
|
|
+ saveData(dataList);
|
|
|
|
+ })).sheet().headRowNumber(3).doRead();
|
|
|
|
+
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void saveData(List<TextbookImportDto> dataList) {
|
|
|
|
+ /*//查询所有需要的数据
|
|
|
|
+ //学科组
|
|
|
|
+ List<SubjectGroup> subjectGroupList = subjectGroupMapper.selectList(new LambdaQueryWrapper<>());
|
|
|
|
+ Map<String, Long> subjectGroupNameAndIdMap = subjectGroupList.stream().collect(Collectors.toMap(SubjectGroup::getGroupName, SubjectGroup::getId, (k1, k2) -> k1));
|
|
|
|
+
|
|
|
|
+ //使用课程
|
|
|
|
+ List<BaseCourseSubject> baseCourseSubjectList = baseCourseSubjectMapper.selectList(new LambdaQueryWrapper<>());
|
|
|
|
+ Map<String, Long> baseCourseSubjectNameAndIdMap = baseCourseSubjectList.stream().collect(Collectors.toMap(BaseCourseSubject::getName, BaseCourseSubject::getId, (k1, k2) -> k1));
|
|
|
|
+
|
|
|
|
+ //批量插入或更新数据
|
|
|
|
+ for (TextbookImportDto textbookImportDto : dataList) {
|
|
|
|
+ TextbookCoreAttribute textbookCoreAttribute = new TextbookCoreAttribute();
|
|
|
|
+ BeanUtils.copyProperties(textbookImportDto, textbookCoreAttribute);
|
|
|
|
+
|
|
|
|
+ Textbook textbook = new Textbook();
|
|
|
|
+ BeanUtils.copyProperties(textbookImportDto, textbook);
|
|
|
|
+
|
|
|
|
+ // 处理学科组映射
|
|
|
|
+ String groupName = textbookImportDto.getGroupName();
|
|
|
|
+ Long subjectGroupId = Optional.ofNullable(groupName)
|
|
|
|
+ .map(subjectGroupNameAndIdMap::get)
|
|
|
|
+ .orElse(null);
|
|
|
|
+ textbook.setSubjectGroupId(subjectGroupId);
|
|
|
|
+
|
|
|
|
+ // 处理课程映射
|
|
|
|
+ String courseName = textbookImportDto.getCourseName();
|
|
|
|
+ Long courseSubjectId = Optional.ofNullable(courseName)
|
|
|
|
+ .map(baseCourseSubjectNameAndIdMap::get)
|
|
|
|
+ .orElse(null);
|
|
|
|
+ textbook.setCourseSubjectId(courseSubjectId);
|
|
|
|
+
|
|
|
|
+ // 处理是否教材计划字段
|
|
|
|
+ String isTextbookPlanCn = textbookImportDto.getIsTextbookPlanCn();
|
|
|
|
+ String isTextbookPlan = Optional.ofNullable(isTextbookPlanCn)
|
|
|
|
+ .filter("是"::equals)
|
|
|
|
+ .map(s -> "yes")
|
|
|
|
+ .orElse("no");
|
|
|
|
+ textbook.setIsTextbookPlan(isTextbookPlan);
|
|
|
|
+
|
|
|
|
+ // 处理教材类型映射
|
|
|
|
+ String textbookTypeCn = textbookImportDto.getTextbookTypeCn();
|
|
|
|
+ String textbookTypeCode = Optional.ofNullable(textbookTypeCn)
|
|
|
|
+ .map(TextbookTypeEnum::getCode)
|
|
|
|
+ .orElse(null);
|
|
|
|
+ textbook.setTextbookType(textbookTypeCode);
|
|
|
|
+
|
|
|
|
+ // 判断导入的教材是否已经存在,根据教材的 ISBN 码和使用的学期判断
|
|
|
|
+ LambdaQueryWrapper<Textbook> textbookLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
+ textbookLambdaQueryWrapper
|
|
|
|
+ .eq(Textbook::getIssn, textbook.getIssn())
|
|
|
|
+ ;
|
|
|
|
+
|
|
|
|
+ Textbook oldTextbook = this.getOne(textbookLambdaQueryWrapper);
|
|
|
|
+
|
|
|
|
+ // 已经存在,更新数据
|
|
|
|
+ if (oldTextbook != null) {
|
|
|
|
+ // 更新教材数据
|
|
|
|
+ textbook.setId(oldTextbook.getId());
|
|
|
|
+ textbookTextbookMapper.updateById(textbook);
|
|
|
|
+ } else {
|
|
|
|
+ textbookCoreAttributeService.save(textbookCoreAttribute);
|
|
|
|
+
|
|
|
|
+ textbook.setTextbookCoreAttributeId(textbookCoreAttribute.getId());
|
|
|
|
+ // 插入教材数据
|
|
|
|
+ textbookTextbookMapper.insert(textbook);
|
|
|
|
+ }
|
|
|
|
+ }*/
|
|
|
|
+ }
|
|
}
|
|
}
|