|
|
@@ -5,6 +5,7 @@ import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.alibaba.excel.EasyExcel;
|
|
|
import com.alibaba.excel.ExcelWriter;
|
|
|
+import com.alibaba.excel.read.listener.PageReadListener;
|
|
|
import com.alibaba.excel.write.metadata.WriteSheet;
|
|
|
import com.alibaba.excel.write.metadata.WriteTable;
|
|
|
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
|
|
|
@@ -26,8 +27,15 @@ import com.xjrsoft.common.utils.excel.CustomCellWriteWidthConfig;
|
|
|
import com.xjrsoft.common.utils.excel.ExcelFillCellMergePrevColUtil;
|
|
|
import com.xjrsoft.common.utils.excel.ExcelMergeUtil;
|
|
|
import com.xjrsoft.module.base.entity.BaseClass;
|
|
|
+import com.xjrsoft.module.base.entity.BaseCourseSubject;
|
|
|
+import com.xjrsoft.module.base.entity.BaseGrade;
|
|
|
import com.xjrsoft.module.base.entity.BaseSemester;
|
|
|
+import com.xjrsoft.module.base.mapper.BaseCourseSubjectMapper;
|
|
|
+import com.xjrsoft.module.base.mapper.BaseGradeMapper;
|
|
|
+import com.xjrsoft.module.base.mapper.BaseSemesterMapper;
|
|
|
import com.xjrsoft.module.base.service.IBaseClassService;
|
|
|
+import com.xjrsoft.module.courseTable.entity.CourseTable;
|
|
|
+import com.xjrsoft.module.teacher.entity.BaseTeacher;
|
|
|
import com.xjrsoft.module.teacher.entity.XjrUser;
|
|
|
import com.xjrsoft.module.textbook.dto.*;
|
|
|
import com.xjrsoft.module.textbook.entity.*;
|
|
|
@@ -42,11 +50,13 @@ import org.apache.poi.ss.usermodel.BorderStyle;
|
|
|
import org.apache.poi.ss.usermodel.HorizontalAlignment;
|
|
|
import org.apache.poi.ss.usermodel.IndexedColors;
|
|
|
import org.apache.poi.ss.usermodel.VerticalAlignment;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
@@ -63,6 +73,7 @@ public class TextbookServiceImpl extends MPJBaseServiceImpl<TextbookMapper, Text
|
|
|
private final TextbookMapper textbookTextbookMapper;
|
|
|
|
|
|
private final TextbookClassRelationMapper textbookTextbookClassRelationMapper;
|
|
|
+
|
|
|
private final TextbookSubscriptionRecordMapper textbookTextbookSubscriptionRecordMapper;
|
|
|
|
|
|
private final IWfTextbookSubscriptionService iWfTextbookSubscriptionService;
|
|
|
@@ -77,6 +88,14 @@ public class TextbookServiceImpl extends MPJBaseServiceImpl<TextbookMapper, Text
|
|
|
|
|
|
private final TextbookStudentClaimMapper textbookStudentClaimMapper;
|
|
|
|
|
|
+ private final SubjectGroupMapper subjectGroupMapper;
|
|
|
+
|
|
|
+ private final BaseGradeMapper baseGradeMapper;
|
|
|
+
|
|
|
+ private final BaseCourseSubjectMapper baseCourseSubjectMapper;
|
|
|
+
|
|
|
+ private final BaseSemesterMapper baseSemesterMapper;
|
|
|
+
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@@ -262,18 +281,18 @@ public class TextbookServiceImpl extends MPJBaseServiceImpl<TextbookMapper, Text
|
|
|
textbook.setGradeId(baseClassList.get(0).getGradeId());
|
|
|
}
|
|
|
}
|
|
|
- //插入教材数据
|
|
|
- textbook.setCreateDate(new Date());
|
|
|
- textbookTextbookMapper.insert(textbook);
|
|
|
+ //插入教材数据
|
|
|
+ textbook.setCreateDate(new Date());
|
|
|
+ textbookTextbookMapper.insert(textbook);
|
|
|
|
|
|
- //插入班级和教材关系
|
|
|
- for (Long classId : classIdList) {
|
|
|
- textbookTextbookClassRelationMapper.insert(new TextbookClassRelation() {{
|
|
|
- setCreateDate(new Date());
|
|
|
- setTextbookId(textbook.getId());
|
|
|
- setClassId(classId);
|
|
|
- }});
|
|
|
- }
|
|
|
+ //插入班级和教材关系
|
|
|
+ for (Long classId : classIdList) {
|
|
|
+ textbookTextbookClassRelationMapper.insert(new TextbookClassRelation() {{
|
|
|
+ setCreateDate(new Date());
|
|
|
+ setTextbookId(textbook.getId());
|
|
|
+ setClassId(classId);
|
|
|
+ }});
|
|
|
+ }
|
|
|
|
|
|
//添加教材征订记录
|
|
|
textbookTextbookSubscriptionRecordMapper.insert(new TextbookSubscriptionRecord() {{
|
|
|
@@ -337,10 +356,10 @@ public class TextbookServiceImpl extends MPJBaseServiceImpl<TextbookMapper, Text
|
|
|
Textbook textbook = new Textbook() {{
|
|
|
setIssn("/");
|
|
|
setIsbn("/");
|
|
|
- if(ObjectUtil.isNotNull(wfExerciseBookItem.getSubscriptionType()) && wfExerciseBookItem.getSubscriptionType().equals(ExerciseBookeTypeEnum.ExerciseBook1.getCode())){
|
|
|
+ if (ObjectUtil.isNotNull(wfExerciseBookItem.getSubscriptionType()) && wfExerciseBookItem.getSubscriptionType().equals(ExerciseBookeTypeEnum.ExerciseBook1.getCode())) {
|
|
|
setBookName(ExerciseBookeTypeEnum.ExerciseBook1.getValue());
|
|
|
}
|
|
|
- if(ObjectUtil.isNotNull(wfExerciseBookItem.getSubscriptionType()) && wfExerciseBookItem.getSubscriptionType().equals(ExerciseBookeTypeEnum.ExerciseBook2.getCode())){
|
|
|
+ if (ObjectUtil.isNotNull(wfExerciseBookItem.getSubscriptionType()) && wfExerciseBookItem.getSubscriptionType().equals(ExerciseBookeTypeEnum.ExerciseBook2.getCode())) {
|
|
|
setBookName(ExerciseBookeTypeEnum.ExerciseBook2.getValue());
|
|
|
}
|
|
|
setPublishingHouse("/");
|
|
|
@@ -351,12 +370,12 @@ public class TextbookServiceImpl extends MPJBaseServiceImpl<TextbookMapper, Text
|
|
|
setTextbookType(TextbookTypeEnum.TExerciseBook.getCode());
|
|
|
setSpecificationsModels((ObjectUtil.isNull(wfExerciseBookItem.getSpecificationsModels()) || StringUtils.isBlank(wfExerciseBookItem.getSpecificationsModels())) ? "/" : wfExerciseBookItem.getSpecificationsModels());
|
|
|
//年级id
|
|
|
- if (ObjectUtil.isNotNull(wfExerciseBook.getClassId()) && wfExerciseBook.getClassId() > 0){
|
|
|
+ if (ObjectUtil.isNotNull(wfExerciseBook.getClassId()) && wfExerciseBook.getClassId() > 0) {
|
|
|
LambdaQueryWrapper<BaseClass> queryWrapper1 = new LambdaQueryWrapper<>();
|
|
|
queryWrapper1
|
|
|
.eq(BaseClass::getId, wfExerciseBook.getClassId());
|
|
|
BaseClass baseClass = baseClassService.getOne(queryWrapper1);
|
|
|
- if(ObjectUtil.isNotNull(baseClass)){
|
|
|
+ if (ObjectUtil.isNotNull(baseClass)) {
|
|
|
setGradeId(baseClass.getGradeId());
|
|
|
}
|
|
|
}
|
|
|
@@ -372,7 +391,7 @@ public class TextbookServiceImpl extends MPJBaseServiceImpl<TextbookMapper, Text
|
|
|
textbookTextbookMapper.insert(textbook);
|
|
|
|
|
|
//插入班级和教材关系
|
|
|
- if(ObjectUtil.isNotNull(wfExerciseBook.getClassId()) && wfExerciseBook.getClassId() > 0){
|
|
|
+ if (ObjectUtil.isNotNull(wfExerciseBook.getClassId()) && wfExerciseBook.getClassId() > 0) {
|
|
|
textbookTextbookClassRelationMapper.insert(new TextbookClassRelation() {{
|
|
|
setCreateDate(new Date());
|
|
|
setTextbookId(textbook.getId());
|
|
|
@@ -417,7 +436,7 @@ public class TextbookServiceImpl extends MPJBaseServiceImpl<TextbookMapper, Text
|
|
|
Textbook textbook = this.getById(id);
|
|
|
List<TextbookSubscriptionRecordVo> recordVos = new ArrayList<>();
|
|
|
//是作业本
|
|
|
- if(textbook.getTextbookType().equals(TextbookTypeEnum.TExerciseBook.getCode())){
|
|
|
+ if (textbook.getTextbookType().equals(TextbookTypeEnum.TExerciseBook.getCode())) {
|
|
|
recordVos = textbookTextbookMapper.exerciseBookSubscriptionList(id);
|
|
|
for (TextbookSubscriptionRecordVo recordVo : recordVos) {
|
|
|
recordVo.setIssn("/");
|
|
|
@@ -431,12 +450,12 @@ public class TextbookServiceImpl extends MPJBaseServiceImpl<TextbookMapper, Text
|
|
|
}
|
|
|
}
|
|
|
//是教材或者教辅
|
|
|
- if (textbook.getTextbookType().equals(TextbookTypeEnum.TTextbook.getCode()) || textbook.getTextbookType().equals(TextbookTypeEnum.TMaterials.getCode())){
|
|
|
+ if (textbook.getTextbookType().equals(TextbookTypeEnum.TTextbook.getCode()) || textbook.getTextbookType().equals(TextbookTypeEnum.TMaterials.getCode())) {
|
|
|
recordVos = textbookTextbookMapper.subscriptionList(id);
|
|
|
for (TextbookSubscriptionRecordVo recordVo : recordVos) {
|
|
|
if (ObjectUtil.isNull(recordVo) || StrUtil.isEmpty(recordVo.getClassIds())) {
|
|
|
recordVos.remove(recordVo);
|
|
|
- if(recordVos.isEmpty()){
|
|
|
+ if (recordVos.isEmpty()) {
|
|
|
break;
|
|
|
}
|
|
|
continue;
|
|
|
@@ -465,7 +484,7 @@ public class TextbookServiceImpl extends MPJBaseServiceImpl<TextbookMapper, Text
|
|
|
@Override
|
|
|
public TextbookVo getInfoByissn(String issn) {
|
|
|
TextbookVo infoByissn = textbookTextbookMapper.getInfoByissn(issn);
|
|
|
- if(infoByissn == null){
|
|
|
+ if (infoByissn == null) {
|
|
|
return null;
|
|
|
}
|
|
|
List<TextbookClassRelation> classRelationList = textbookTextbookClassRelationMapper.selectList(
|
|
|
@@ -511,8 +530,8 @@ public class TextbookServiceImpl extends MPJBaseServiceImpl<TextbookMapper, Text
|
|
|
queryIssueRecord
|
|
|
.eq(TextbookIssueRecord::getTextbookId, id)
|
|
|
.eq(TextbookIssueRecord::getIssueMode, "im_teacher");
|
|
|
- List<TextbookIssueRecord> textbookIssueRecordList = textbookIssueRecordMapper.selectJoinList(TextbookIssueRecord.class, queryIssueRecord);
|
|
|
- for(TextbookIssueRecord t : textbookIssueRecordList){
|
|
|
+ List<TextbookIssueRecord> textbookIssueRecordList = textbookIssueRecordMapper.selectJoinList(TextbookIssueRecord.class, queryIssueRecord);
|
|
|
+ for (TextbookIssueRecord t : textbookIssueRecordList) {
|
|
|
MPJLambdaWrapper<TextbookIssueRecord> queryTeaClaimVo = new MPJLambdaWrapper<>();
|
|
|
queryTeaClaimVo
|
|
|
.selectAs(BaseSemester::getName, WfTextbookClaimListVo::getSemesterName)
|
|
|
@@ -523,8 +542,8 @@ public class TextbookServiceImpl extends MPJBaseServiceImpl<TextbookMapper, Text
|
|
|
.leftJoin(WfTextbookClaim.class, WfTextbookClaim::getId, TextbookIssueRecord::getDataId)
|
|
|
.leftJoin(BaseSemester.class, BaseSemester::getId, WfTextbookClaim::getBaseSemesterId)
|
|
|
.eq(TextbookIssueRecord::getId, t.getId());
|
|
|
- WfTextbookClaimListVo wfTextbookClaimListVo = textbookIssueRecordMapper.selectJoinOne(WfTextbookClaimListVo.class, queryTeaClaimVo);
|
|
|
- for (int j = 0; j < t.getIssueNumber(); j++){
|
|
|
+ WfTextbookClaimListVo wfTextbookClaimListVo = textbookIssueRecordMapper.selectJoinOne(WfTextbookClaimListVo.class, queryTeaClaimVo);
|
|
|
+ for (int j = 0; j < t.getIssueNumber(); j++) {
|
|
|
wfTextbookClaimListVo.setClaimIdentity("教师");
|
|
|
wfTextbookClaimListVo.setClassName("/");
|
|
|
result.add(wfTextbookClaimListVo);
|
|
|
@@ -559,22 +578,22 @@ public class TextbookServiceImpl extends MPJBaseServiceImpl<TextbookMapper, Text
|
|
|
public List<TextbookSubscriptionExportQueryVo> listTextbookSubscriptionExportQuery(TextbookSubscriptionExportQueryDto dto) {
|
|
|
List<TextbookSubscriptionExportQueryVo> result = textbookTextbookMapper.listTextbookSubscriptionExportQuery(dto);
|
|
|
//将班级转换为中文
|
|
|
- for(TextbookSubscriptionExportQueryVo to: result){
|
|
|
- if(to != null && to.getClassIds() != null && !("").equals(to.getClassIds())){
|
|
|
+ for (TextbookSubscriptionExportQueryVo to : result) {
|
|
|
+ if (to != null && to.getClassIds() != null && !("").equals(to.getClassIds())) {
|
|
|
List<Long> classIdList = new ArrayList<>();
|
|
|
String[] classIdStrs = to.getClassIds().split(",");
|
|
|
- for (String classIdStr : classIdStrs){
|
|
|
+ for (String classIdStr : classIdStrs) {
|
|
|
classIdList.add(Long.parseLong(classIdStr.trim()));
|
|
|
}
|
|
|
LambdaQueryWrapper<BaseClass> baseClassLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
baseClassLambdaQueryWrapper
|
|
|
.in(BaseClass::getId, classIdList);
|
|
|
List<BaseClass> baseClassList = baseClassService.list(baseClassLambdaQueryWrapper);
|
|
|
- if(baseClassList.size() > 0){
|
|
|
+ if (baseClassList.size() > 0) {
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
- for (int i = 0; i < baseClassList.size(); i++){
|
|
|
+ for (int i = 0; i < baseClassList.size(); i++) {
|
|
|
sb.append(baseClassList.get(i).getName());
|
|
|
- if(i != baseClassList.size()-1) {
|
|
|
+ if (i != baseClassList.size() - 1) {
|
|
|
sb.append(",");
|
|
|
}
|
|
|
}
|
|
|
@@ -620,7 +639,7 @@ public class TextbookServiceImpl extends MPJBaseServiceImpl<TextbookMapper, Text
|
|
|
// 字体
|
|
|
WriteFont headWriteFont = new WriteFont();
|
|
|
headWriteFont.setFontName("宋体");//设置字体名字
|
|
|
- headWriteFont.setFontHeightInPoints((short)14);//设置字体大小
|
|
|
+ headWriteFont.setFontHeightInPoints((short) 14);//设置字体大小
|
|
|
headWriteFont.setBold(true);//字体加粗
|
|
|
headWriteCellStyle.setWriteFont(headWriteFont); //在样式用应用设置的字体;
|
|
|
|
|
|
@@ -654,7 +673,7 @@ public class TextbookServiceImpl extends MPJBaseServiceImpl<TextbookMapper, Text
|
|
|
|
|
|
//sheet的表头
|
|
|
List<List<String>> sheetHeadList = new ArrayList<List<String>>();
|
|
|
- sheetHeadList.add(new ArrayList<String>(){{
|
|
|
+ sheetHeadList.add(new ArrayList<String>() {{
|
|
|
add("铜梁执教中心班级教材教辅发放情况表");
|
|
|
}});
|
|
|
//sheet的表头合并策略
|
|
|
@@ -684,7 +703,7 @@ public class TextbookServiceImpl extends MPJBaseServiceImpl<TextbookMapper, Text
|
|
|
|
|
|
//这是一个table的表头
|
|
|
List<List<String>> tableHeadList = new ArrayList<List<String>>();
|
|
|
- tableHeadList.add(new ArrayList<String>(){{
|
|
|
+ tableHeadList.add(new ArrayList<String>() {{
|
|
|
add("日期:" + v.get(0).getBaseSemesterIdCn() + " 班级:" + v.get(0).getClassIdCn() + " 班主任:" + v.get(0).getHeadTeacherName() + " 教室:" + v.get(0).getClassRoomName() + " ");
|
|
|
}});
|
|
|
//table的表头合并策略
|
|
|
@@ -703,16 +722,16 @@ public class TextbookServiceImpl extends MPJBaseServiceImpl<TextbookMapper, Text
|
|
|
Map.Entry<String, List<TextbookClaimExportQueryVo>> groupedByTextbookTypeEntry = groupedByTextbookTypeIterator.next();
|
|
|
String kk = groupedByTextbookTypeEntry.getKey();
|
|
|
List<TextbookClaimExportQueryVo> vv = groupedByTextbookTypeEntry.getValue();
|
|
|
- if(index == 1){
|
|
|
+ if (index == 1) {
|
|
|
//添加小计
|
|
|
ExcelFillCellMergePrevColUtil subtotalColumn = new ExcelFillCellMergePrevColUtil();
|
|
|
subtotalColumn.add(rowIndex + vv.size() + 2, 1, 4);
|
|
|
BigDecimal subtotal = new BigDecimal("0");
|
|
|
for (TextbookClaimExportQueryVo tv : vv) {
|
|
|
- subtotal = subtotal.add(tv.getSubtotal()==null?new BigDecimal("0"):tv.getSubtotal());
|
|
|
+ subtotal = subtotal.add(tv.getSubtotal() == null ? new BigDecimal("0") : tv.getSubtotal());
|
|
|
}
|
|
|
BigDecimal finalSubtotal = subtotal;
|
|
|
- vv.add(new TextbookClaimExportQueryVo(){{
|
|
|
+ vv.add(new TextbookClaimExportQueryVo() {{
|
|
|
setTextbookTypeCn(vv.get(0).getTextbookTypeCn());
|
|
|
setBookName("小计");
|
|
|
setSubtotal(finalSubtotal);
|
|
|
@@ -730,7 +749,7 @@ public class TextbookServiceImpl extends MPJBaseServiceImpl<TextbookMapper, Text
|
|
|
excelWriter.write(vv, writeSheet, writeContentTable);
|
|
|
|
|
|
rowIndex += (1 + vv.size());
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
//添加小计
|
|
|
ExcelFillCellMergePrevColUtil subtotalColumn = new ExcelFillCellMergePrevColUtil();
|
|
|
subtotalColumn.add(rowIndex + vv.size() + 1, 1, 4);
|
|
|
@@ -739,7 +758,7 @@ public class TextbookServiceImpl extends MPJBaseServiceImpl<TextbookMapper, Text
|
|
|
subtotal = subtotal.add(tv.getSubtotal());
|
|
|
}
|
|
|
BigDecimal finalSubtotal = subtotal;
|
|
|
- vv.add(new TextbookClaimExportQueryVo(){{
|
|
|
+ vv.add(new TextbookClaimExportQueryVo() {{
|
|
|
setTextbookTypeCn(vv.get(0).getTextbookTypeCn());
|
|
|
setBookName("小计");
|
|
|
setSubtotal(finalSubtotal);
|
|
|
@@ -761,7 +780,7 @@ public class TextbookServiceImpl extends MPJBaseServiceImpl<TextbookMapper, Text
|
|
|
//添加合计
|
|
|
BigDecimal finalTotal = total;
|
|
|
List<TextbookClaimExportQueryVo> totalList = new ArrayList<>();
|
|
|
- totalList.add(new TextbookClaimExportQueryVo(){{
|
|
|
+ totalList.add(new TextbookClaimExportQueryVo() {{
|
|
|
setTextbookTypeCn("合计");
|
|
|
setSubtotal(finalTotal);
|
|
|
}});
|
|
|
@@ -776,6 +795,145 @@ public class TextbookServiceImpl extends MPJBaseServiceImpl<TextbookMapper, Text
|
|
|
}
|
|
|
return bot;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public Boolean excelImport(InputStream inputStream) {
|
|
|
+ EasyExcel.read(inputStream, TextbookImportDto.class, new PageReadListener<TextbookImportDto>(dataList -> {
|
|
|
+ if (dataList.isEmpty()) {
|
|
|
+ throw new MyException("导入数据为空");
|
|
|
+ }
|
|
|
+ saveData(dataList);
|
|
|
+ })).sheet().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<BaseGrade> baseGradeList = baseGradeMapper.selectList(new LambdaQueryWrapper<>());
|
|
|
+ Map<String, Long> baseGradeNameAndIdMap = baseGradeList.stream().collect(Collectors.toMap(BaseGrade::getName, BaseGrade::getId, (k1, k2) -> k1));
|
|
|
+
|
|
|
+ //使用班级
|
|
|
+ List<BaseClass> baseClassList = baseClassService.list();
|
|
|
+ Map<String, Long> baseClassNameAndIdMap = baseClassList.stream().collect(Collectors.toMap(BaseClass::getName, BaseClass::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));
|
|
|
+
|
|
|
+ //使用学期
|
|
|
+ List<BaseSemester> baseSemesterList = baseSemesterMapper.selectList(new LambdaQueryWrapper<>());
|
|
|
+ Map<String, Long> baseSemesterNameAndIdMap = baseSemesterList.stream().collect(Collectors.toMap(BaseSemester::getName, BaseSemester::getId, (k1, k2) -> k1));
|
|
|
+
|
|
|
+ //批量插入或更新数据
|
|
|
+ for (TextbookImportDto textbookImportDto : dataList) {
|
|
|
+ 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 useGrade = textbookImportDto.getUseGrade();
|
|
|
+ Long gradeId = Optional.ofNullable(useGrade)
|
|
|
+ .map(baseGradeNameAndIdMap::get)
|
|
|
+ .orElse(null);
|
|
|
+ textbook.setGradeId(gradeId);
|
|
|
+
|
|
|
+ // 处理是否教材计划字段
|
|
|
+ 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);
|
|
|
+
|
|
|
+ // 处理学期映射
|
|
|
+ String useSemester = textbookImportDto.getUseSemester();
|
|
|
+ Long baseSemesterId = Optional.ofNullable(useSemester)
|
|
|
+ .map(baseSemesterNameAndIdMap::get)
|
|
|
+ .orElse(null);
|
|
|
+ textbook.setBaseSemesterId(baseSemesterId);
|
|
|
+
|
|
|
+ // 处理班级映射
|
|
|
+ List<Long> classIdList = Optional.ofNullable(textbookImportDto.getUseClass())
|
|
|
+ .map(classNames -> Arrays.stream(classNames.split(","))
|
|
|
+ .map(String::trim)
|
|
|
+ .map(baseClassNameAndIdMap::get)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .collect(Collectors.toList()))
|
|
|
+ .orElse(Collections.emptyList());
|
|
|
+
|
|
|
+
|
|
|
+ // 判断导入的教材是否已经存在,根据教材的 ISBN 码和使用的学期判断
|
|
|
+ LambdaQueryWrapper<Textbook> textbookLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ textbookLambdaQueryWrapper
|
|
|
+ .eq(Textbook::getIssn, textbook.getIssn())
|
|
|
+ .eq(Textbook::getBaseSemesterId, textbook.getBaseSemesterId())
|
|
|
+ ;
|
|
|
+
|
|
|
+ Textbook oldTextbook = this.getOne(textbookLambdaQueryWrapper);
|
|
|
+
|
|
|
+ // 已经存在,更新数据
|
|
|
+ if (oldTextbook != null) {
|
|
|
+ // 更新教材数据
|
|
|
+ textbookTextbookMapper.updateById(textbook);
|
|
|
+
|
|
|
+ // 先删除使用班级的信息,再新增
|
|
|
+ LambdaQueryWrapper<TextbookClassRelation> textbookClassRelationLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ textbookClassRelationLambdaQueryWrapper
|
|
|
+ .eq(TextbookClassRelation::getTextbookId, textbook.getId());
|
|
|
+
|
|
|
+ textbookTextbookClassRelationMapper.delete(textbookClassRelationLambdaQueryWrapper);
|
|
|
+
|
|
|
+ // 批量插入班级关系
|
|
|
+ for (Long classId : classIdList) {
|
|
|
+ textbookTextbookClassRelationMapper.insert(new TextbookClassRelation() {{
|
|
|
+ setCreateDate(new Date());
|
|
|
+ setTextbookId(textbook.getId());
|
|
|
+ setClassId(classId);
|
|
|
+ }});
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 插入教材数据
|
|
|
+ textbookTextbookMapper.insert(textbook);
|
|
|
+
|
|
|
+ //插入班级和教材关系
|
|
|
+ for (Long classId : classIdList) {
|
|
|
+ textbookTextbookClassRelationMapper.insert(new TextbookClassRelation() {{
|
|
|
+ setCreateDate(new Date());
|
|
|
+ setTextbookId(textbook.getId());
|
|
|
+ setClassId(classId);
|
|
|
+ }});
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public Boolean deliverWarehouse(AddTextbookWarehouseRecordDto dto) {
|
|
|
@@ -789,7 +947,7 @@ public class TextbookServiceImpl extends MPJBaseServiceImpl<TextbookMapper, Text
|
|
|
Double discount = ObjectUtil.isNull(dto.getDiscount()) ? 10 : dto.getDiscount();
|
|
|
BigDecimal subtotal = price.multiply(new BigDecimal(discount / 10));
|
|
|
//更新总的库存数量
|
|
|
- this.updateById(new Textbook(){
|
|
|
+ this.updateById(new Textbook() {
|
|
|
{
|
|
|
setId(textbook.getId());
|
|
|
Integer oldStock = ObjectUtil.isNull(textbook.getStock()) ? 0 : textbook.getStock();
|