浏览代码

教材征订重构-教材导入

大数据与最优化研究所 1 年之前
父节点
当前提交
914159ef1e

+ 9 - 0
src/main/java/com/xjrsoft/common/enums/TextbookTypeEnum.java

@@ -37,4 +37,13 @@ public enum TextbookTypeEnum {
         this.code = code;
         this.value = message;
     }
+
+    public static String getCode(String value){
+        for (TextbookTypeEnum item : values()) {
+            if (item.getValue().equals(value)) {
+                return  item.getCode();
+            }
+        }
+        return null;
+    }
 }

+ 13 - 9
src/main/java/com/xjrsoft/module/system/controller/FileController.java

@@ -80,15 +80,19 @@ public class FileController {
     @ApiOperation(value = "查询文件列表(不分页)")
     public R list(@Valid FileListDto dto) {
 
-        List<FileListVo> list = fileService.selectJoinList(FileListVo.class, MPJWrappers.<File>lambdaJoin()
-                .like(StrUtil.isNotBlank(dto.getFileName()), File::getFileName, dto.getFileName())
-                .eq(ObjectUtil.isNotNull(dto.getFolderId()), File::getFolderId, dto.getFolderId())
-                .eq(StrUtil.isNotBlank(dto.getProcessId()), File::getProcessId, dto.getProcessId())
-                .select(File::getId)
-                .select(File.class, x -> VoToColumnUtil.fieldsToColumns(FileListVo.class).contains(x.getProperty()))
-                .selectAs(User::getName, FileListVo::getCreateUserName)
-                .leftJoin(User.class, User::getId, File::getCreateUserId)
-                .last(StrUtil.isNotBlank(dto.getField()), GlobalConstant.ORDER_BY + StringPool.SPACE + StrUtil.toUnderlineCase(dto.getField()) + StringPool.SPACE + ConventPage.getOrder(dto.getOrder())));
+        List<FileListVo> list = new ArrayList<>();
+        if(dto.getFolderId() != null || dto.getFileName() != null && dto.getProcessId() != null){
+           list = fileService.selectJoinList(FileListVo.class, MPJWrappers.<File>lambdaJoin()
+                    .like(StrUtil.isNotBlank(dto.getFileName()), File::getFileName, dto.getFileName())
+                    .eq(ObjectUtil.isNotNull(dto.getFolderId()) && StrUtil.isNotBlank(dto.getProcessId()), File::getFolderId, dto.getFolderId())
+                    .eq(StrUtil.isNotBlank(dto.getProcessId()), File::getProcessId, dto.getProcessId())
+                    .select(File::getId)
+                    .select(File.class, x -> VoToColumnUtil.fieldsToColumns(FileListVo.class).contains(x.getProperty()))
+                    .selectAs(User::getName, FileListVo::getCreateUserName)
+                    .leftJoin(User.class, User::getId, File::getCreateUserId)
+                    .last(StrUtil.isNotBlank(dto.getField()), GlobalConstant.ORDER_BY + StringPool.SPACE + StrUtil.toUnderlineCase(dto.getField()) + StringPool.SPACE + ConventPage.getOrder(dto.getOrder())));
+
+        }
 
         return R.ok(list);
     }

+ 12 - 2
src/main/java/com/xjrsoft/module/textbook/controller/TextbookController.java

@@ -6,6 +6,7 @@ import com.alibaba.excel.EasyExcel;
 import com.alibaba.excel.support.ExcelTypeEnum;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.xjrsoft.common.model.result.R;
 import com.xjrsoft.common.model.result.RT;
 import com.xjrsoft.common.page.ConventPage;
 import com.xjrsoft.common.page.PageOutput;
@@ -20,9 +21,12 @@ import io.swagger.annotations.ApiOperation;
 import lombok.AllArgsConstructor;
 import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
 
 import javax.validation.Valid;
 import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -38,7 +42,6 @@ import java.util.List;
 @AllArgsConstructor
 public class TextbookController {
 
-
     private final ITextbookService textbookService;
 
     private final IBaseSemesterService baseSemesterService;
@@ -119,7 +122,6 @@ public class TextbookController {
         return RT.ok(result);
     }
 
-
     @PostMapping
     @ApiOperation(value = "新增教材管理")
     @SaCheckPermission("textbook:add")
@@ -283,4 +285,12 @@ public class TextbookController {
         ByteArrayOutputStream bot = textbookService.listTextbookClaimExportQuery(dto);
         return RT.fileStream(bot.toByteArray(), "TextbookClaim" + ExcelTypeEnum.XLSX.getValue());
     }
+
+    @PostMapping("/excel-import")
+    @ApiOperation(value = "excel教材导入")
+    @SaCheckPermission("coursetable:excelimport")
+    public R excelImport( @RequestParam("file") MultipartFile file) throws IOException {
+        InputStream inputStream = file.getInputStream();
+        return R.ok(textbookService.excelImport(inputStream));
+    }
 }

+ 133 - 0
src/main/java/com/xjrsoft/module/textbook/dto/TextbookImportDto.java

@@ -0,0 +1,133 @@
+package com.xjrsoft.module.textbook.dto;
+
+import com.alibaba.excel.annotation.ExcelProperty;
+import com.alibaba.excel.annotation.write.style.ContentStyle;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+@Data
+public class TextbookImportDto {
+    /**
+     * 国际标准刊号
+     */
+    @ContentStyle(dataFormat = 49)
+    @ExcelProperty("国际标准刊号")
+    @ApiModelProperty("国际标准刊号")
+    private String issn;
+    /**
+     * 书名
+     */
+    @ContentStyle(dataFormat = 49)
+    @ExcelProperty("书名")
+    @ApiModelProperty("书名")
+    private String bookName;
+    /**
+     * 出版社
+     */
+    @ContentStyle(dataFormat = 49)
+    @ExcelProperty("出版社")
+    @ApiModelProperty("出版社")
+    private String publishingHouse;
+    /**
+     * 主编
+     */
+    @ContentStyle(dataFormat = 49)
+    @ExcelProperty("主编")
+    @ApiModelProperty("主编")
+    private String editorInChief;
+    /**
+     * 学科组名称
+     */
+    @ContentStyle(dataFormat = 49)
+    @ExcelProperty("学科组名称")
+    @ApiModelProperty("学科组名称")
+    private String groupName;
+    /**
+     * 使用年级
+     */
+    @ContentStyle(dataFormat = 49)
+    @ExcelProperty("使用年级")
+    @ApiModelProperty("使用年级")
+    private String useGrade;
+    /**
+     * 使用年级
+     */
+    @ContentStyle(dataFormat = 49)
+    @ExcelProperty("使用学期")
+    @ApiModelProperty("使用学期")
+    private String useSemester;
+
+    /**
+     * 使用班级
+     */
+    @ContentStyle(dataFormat = 49)
+    @ExcelProperty("使用班级")
+    @ApiModelProperty("使用班级")
+    private String useClass;
+    /**
+     * 课程
+     */
+    @ContentStyle(dataFormat = 49)
+    @ExcelProperty("对应课程")
+    @ApiModelProperty("对应课程")
+    private String courseName;
+    /**
+     * 是否为规划教材
+     */
+    @ContentStyle(dataFormat = 49)
+    @ExcelProperty("是否为规划教材")
+    @ApiModelProperty("是否为规划教材")
+    private String isTextbookPlanCn;
+
+    /**
+     * 教材类型(xjr_dictionary_item[textbook_type])
+     */
+    @ContentStyle(dataFormat = 49)
+    @ExcelProperty("教材类型")
+    @ApiModelProperty("教材类型-中文")
+    private String textbookTypeCn;
+    /**
+     * 规格型号
+     */
+    @ContentStyle(dataFormat = 49)
+    @ExcelProperty("规格型号")
+    @ApiModelProperty("规格型号")
+    private String specificationsModels;
+    /**
+     * 估价(元)
+     */
+    @ContentStyle(dataFormat = 49)
+    @ExcelProperty("估价(元)")
+    @ApiModelProperty("估价(元)")
+    private BigDecimal appraisalPrice;
+    /**
+     * 定价(元)
+     */
+    @ContentStyle(dataFormat = 49)
+    @ExcelProperty("定价(元)")
+    @ApiModelProperty("定价(元)")
+    private BigDecimal price;
+    /**
+     * 折扣
+     */
+    @ContentStyle(dataFormat = 49)
+    @ExcelProperty("折扣")
+    @ApiModelProperty("折扣")
+    private Double discount;
+    /**
+     * 小计(元)
+     */
+    @ContentStyle(dataFormat = 49)
+    @ExcelProperty("小计(元)")
+    @ApiModelProperty("小计(元)")
+    private BigDecimal subtotal;
+    /**
+     * 库存
+     */
+    @ContentStyle(dataFormat = 49)
+    @ExcelProperty("库存")
+    @ApiModelProperty("库存")
+    private Integer stock;
+}

+ 3 - 0
src/main/java/com/xjrsoft/module/textbook/service/ITextbookService.java

@@ -8,6 +8,7 @@ import com.xjrsoft.module.textbook.entity.TextbookClassRelation;
 import com.xjrsoft.module.textbook.vo.*;
 
 import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
 import java.util.List;
 
 /**
@@ -124,4 +125,6 @@ public interface ITextbookService extends MPJBaseService<Textbook> {
     List<TextbookSubscriptionExportQueryVo> listTextbookSubscriptionExportQuery(TextbookSubscriptionExportQueryDto dto);
 
     ByteArrayOutputStream listTextbookClaimExportQuery(TextbookClaimExportQueryDto dto);
+
+    Boolean excelImport(InputStream inputStream);
 }

+ 198 - 40
src/main/java/com/xjrsoft/module/textbook/service/impl/TextbookServiceImpl.java

@@ -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();

+ 7 - 1
src/main/java/com/xjrsoft/module/textbook/vo/TextbookStandingExportQueryVo.java

@@ -58,7 +58,13 @@ public class TextbookStandingExportQueryVo {
     @ExcelProperty("使用年级")
     @ApiModelProperty("使用年级")
     private String useGrade;
-
+    /**
+     * 使用年级
+     */
+    @ContentStyle(dataFormat = 49)
+    @ExcelProperty("使用学期")
+    @ApiModelProperty("使用学期")
+    private String semesterCn;
     /**
      * 使用班级
      */

+ 25 - 23
src/main/resources/mapper/textbook/TextbookMapper.xml

@@ -158,30 +158,32 @@
     <select id="listTextbookStandingExportQuery" parameterType="com.xjrsoft.module.textbook.dto.TextbookStandingExportQuerytDto"
             resultType="com.xjrsoft.module.textbook.vo.TextbookStandingExportQueryVo">
         SELECT t1.issn,
-               t1.book_name,
-               t1.publishing_house,
-               t1.editor_in_chief,
-               t2.group_name,
-               t6.name                        AS use_grade,
-               (SELECT GROUP_CONCAT(c2.name)
-                FROM textbook_class_relation c1
-                         LEFT JOIN base_class c2 ON c1.class_id = c2.id
-                WHERE c1.textbook_id = t1.id) AS use_class,
-               t4.name                        AS course_name,
-               t7.name                        AS is_textbook_plan_cn,
-               t5.name                        AS textbook_type_cn,
-               t1.specifications_models,
-               t1.appraisal_price,
-               t1.price,
-               t1.discount,
-               t1.subtotal,
-               t1.stock
+            t1.book_name,
+            t1.publishing_house,
+            t1.editor_in_chief,
+            t2.group_name,
+            t6.name                        AS use_grade,
+            (SELECT GROUP_CONCAT(c2.name)
+            FROM textbook_class_relation c1
+            LEFT JOIN base_class c2 ON c1.class_id = c2.id
+            WHERE c1.textbook_id = t1.id) AS use_class,
+            t4.name                        AS course_name,
+            t7.name                        AS is_textbook_plan_cn,
+            t5.name                        AS textbook_type_cn,
+            t1.specifications_models,
+            t1.appraisal_price,
+            t1.price,
+            t1.discount,
+            t1.subtotal,
+            t1.stock,
+            t8.name as use_semester
         FROM textbook t1
-                 LEFT JOIN subject_group t2 ON t1.subject_group_id = t2.id
-                 LEFT JOIN base_course_subject t4 ON t1.course_subject_id = t4.id
-                 LEFT JOIN xjr_dictionary_detail t5 ON t1.textbook_type = t5.code AND t5.item_id = 1739209191193636865
-                 LEFT JOIN base_grade t6 ON t1.grade_id = t6.id
-                 LEFT JOIN xjr_dictionary_detail t7 ON t1.is_textbook_plan = t7.code AND t7.item_id = 1737360269850038273
+            LEFT JOIN subject_group t2 ON t1.subject_group_id = t2.id
+            LEFT JOIN base_course_subject t4 ON t1.course_subject_id = t4.id
+            LEFT JOIN xjr_dictionary_detail t5 ON t1.textbook_type = t5.code AND t5.item_id = 1739209191193636865
+            LEFT JOIN base_grade t6 ON t1.grade_id = t6.id
+            LEFT JOIN xjr_dictionary_detail t7 ON t1.is_textbook_plan = t7.code AND t7.item_id = 1737360269850038273
+            LEFT JOIN base_semester t8 ON t1.base_semester_id = t8.id
         WHERE t1.delete_mark = 0
         <if test="dto.textbookType != null and dto.textbookType != ''">
             and t1.textbook_type = #{dto.textbookType}