|
|
@@ -7,15 +7,14 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.github.yulichang.base.MPJBaseServiceImpl;
|
|
|
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
|
|
+import com.xjrsoft.common.enums.ArchivesStatusEnum;
|
|
|
import com.xjrsoft.common.enums.ClaimTypeEnum;
|
|
|
import com.xjrsoft.common.enums.RecedeTypeEnum;
|
|
|
import com.xjrsoft.common.exception.MyException;
|
|
|
import com.xjrsoft.common.page.ConventPage;
|
|
|
import com.xjrsoft.common.utils.VoToColumnUtil;
|
|
|
-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.entity.*;
|
|
|
+import com.xjrsoft.module.generator.entity.ImportConfig;
|
|
|
import com.xjrsoft.module.system.entity.DictionaryDetail;
|
|
|
import com.xjrsoft.module.teacher.entity.XjrUser;
|
|
|
import com.xjrsoft.module.textbook.dto.*;
|
|
|
@@ -23,17 +22,22 @@ import com.xjrsoft.module.textbook.entity.*;
|
|
|
import com.xjrsoft.module.textbook.mapper.TextbookIssueRecordMapper;
|
|
|
import com.xjrsoft.module.textbook.service.ITextbookIssueRecordService;
|
|
|
import com.xjrsoft.module.textbook.vo.*;
|
|
|
+import com.xjrsoft.module.veb.util.ImportExcelUtil;
|
|
|
import io.swagger.models.auth.In;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.poi.ss.usermodel.*;
|
|
|
+import org.apache.poi.ss.util.CellRangeAddress;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
+import org.codehaus.groovy.runtime.typehandling.IntegerMath;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
+import java.io.IOException;
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
@@ -306,69 +310,416 @@ public class TextbookIssueRecordServiceImpl extends MPJBaseServiceImpl<TextbookI
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public ByteArrayOutputStream claimRecordExportDataQuery(TextbookClaimRecordExportDto dto) {
|
|
|
+ public ByteArrayOutputStream claimRecordExportDataQuery(TextbookClaimRecordExportDto dto) throws IOException {
|
|
|
MPJLambdaWrapper<TextbookIssueRecord> textbookIssueRecordMPJLambdaWrapper = new MPJLambdaWrapper<>();
|
|
|
textbookIssueRecordMPJLambdaWrapper
|
|
|
.disableSubLogicDel()
|
|
|
.select(TextbookIssueRecord::getId)
|
|
|
- .selectAs(TextbookWarehouseRecord::getPrice, TextbookIssueRecordExcelVo::getPrice)
|
|
|
- .selectAs(TextbookWarehouseRecord::getSubtotal, TextbookIssueRecordExcelVo::getSubtotal)
|
|
|
- .select(TextbookIssueRecord.class, x -> VoToColumnUtil.fieldsToColumns(TextbookIssueRecordExcelVo.class).contains(x.getProperty()))
|
|
|
- .select(Textbook.class, x -> VoToColumnUtil.fieldsToColumns(TextbookIssueRecordExcelVo.class).contains(x.getProperty()))
|
|
|
+ .selectAs(TextbookWarehouseRecord::getPrice, TextbookClaimRecordExportVo::getPrice)
|
|
|
+ .selectAs(TextbookWarehouseRecord::getSubtotal, TextbookClaimRecordExportVo::getSubtotal)
|
|
|
+ .select(TextbookIssueRecord.class, x -> VoToColumnUtil.fieldsToColumns(TextbookClaimRecordExportVo.class).contains(x.getProperty()))
|
|
|
+ .select(Textbook.class, x -> VoToColumnUtil.fieldsToColumns(TextbookClaimRecordExportVo.class).contains(x.getProperty()))
|
|
|
+ .leftJoin(TextbookWarehouseRecord.class, TextbookWarehouseRecord::getId, TextbookIssueRecord::getTextbookWarehouseRecordId)
|
|
|
.leftJoin(BaseSemester.class, BaseSemester::getId, TextbookIssueRecord::getBaseSemesterId,
|
|
|
wrapper -> wrapper
|
|
|
- .selectAs(BaseSemester::getName, TextbookIssueRecordExcelVo::getBaseSemesterIdCn)
|
|
|
- )
|
|
|
- .leftJoin(TextbookWarehouseRecord.class, TextbookWarehouseRecord::getId, TextbookIssueRecord::getTextbookWarehouseRecordId,
|
|
|
- wrapper -> wrapper
|
|
|
- .selectAs(TextbookWarehouseRecord::getOrderNumber, TextbookIssueRecordExcelVo::getWarehouseOrderNumber)
|
|
|
+ .selectAs(BaseSemester::getName, TextbookClaimRecordExportVo::getBaseSemesterIdCn)
|
|
|
)
|
|
|
- .leftJoin(DictionaryDetail.class, DictionaryDetail::getCode, TextbookIssueRecord::getIssueMode,
|
|
|
- wrapper -> wrapper
|
|
|
- .selectAs(DictionaryDetail::getName, TextbookIssueRecordExcelVo::getIssueModeCn)
|
|
|
- )
|
|
|
- .leftJoin(Textbook.class, Textbook::getId, TextbookIssueRecord::getTextbookId,
|
|
|
+ .leftJoin(WfTextbookClaim.class, WfTextbookClaim::getId, TextbookIssueRecord::getDataId,
|
|
|
wrapper -> wrapper
|
|
|
- .leftJoin(BaseCourseSubject.class, BaseCourseSubject::getId, Textbook::getCourseSubjectId,
|
|
|
+ .select("(select " +
|
|
|
+ " count(id) as totalStuNum " +
|
|
|
+ "from base_student_school_roll a " +
|
|
|
+ "where a.class_id = t3.class_id " +
|
|
|
+ "and delete_mark = 0 " +
|
|
|
+ "and archives_status = '" + ArchivesStatusEnum.FB2901.getCode() + "') as totalStuNum ")
|
|
|
+ .selectAs(WfTextbookClaim::getClassId, TextbookClaimRecordExportVo::getClassId)
|
|
|
+ .selectAs(WfTextbookClaim::getClaimType, TextbookClaimRecordExportVo::getClaimType)
|
|
|
+ .leftJoin(BaseClass.class, BaseClass::getId, WfTextbookClaim::getClassId,
|
|
|
wra -> wra
|
|
|
- .selectAs(BaseCourseSubject::getName, TextbookIssueRecordExcelVo::getCourseName)
|
|
|
+ .selectAs(BaseClass::getName, TextbookClaimRecordExportVo::getClassIdCn)
|
|
|
)
|
|
|
- .leftJoin(SubjectGroup.class, SubjectGroup::getId, Textbook::getSubjectGroupId,
|
|
|
+ .leftJoin(XjrUser.class, XjrUser::getId, BaseClass::getTeacherId,
|
|
|
wra -> wra
|
|
|
- .selectAs(SubjectGroup::getGroupName, TextbookIssueRecordExcelVo::getGroupName)
|
|
|
+ .selectAs(XjrUser::getName, TextbookClaimRecordExportVo::getTeacherIdCn)
|
|
|
+ .selectAs(XjrUser::getMobile, TextbookClaimRecordExportVo::getTeacherMobile)
|
|
|
)
|
|
|
- .leftJoin(DictionaryDetail.class, DictionaryDetail::getCode, Textbook::getTextbookType,
|
|
|
+ .leftJoin(BaseClassroom.class, BaseClassroom::getId, BaseClass::getClassroomId,
|
|
|
wra -> wra
|
|
|
- .selectAs(DictionaryDetail::getName, TextbookIssueRecordExcelVo::getTextbookTypeCn)
|
|
|
+ .selectAs(BaseClassroom::getName, TextbookClaimRecordExportVo::getClassroomIdCn)
|
|
|
)
|
|
|
)
|
|
|
- .leftJoin(XjrUser.class, XjrUser::getId, TextbookIssueRecord::getReceiveUserId,
|
|
|
- wrapper -> wrapper
|
|
|
- .selectAs(XjrUser::getName, TextbookIssueRecordExcelVo::getClaimUser)
|
|
|
- )
|
|
|
- .leftJoin(WfTextbookClaim.class, WfTextbookClaim::getId, TextbookIssueRecord::getDataId,
|
|
|
+ .leftJoin(Textbook.class, Textbook::getId, TextbookIssueRecord::getTextbookId,
|
|
|
wrapper -> wrapper
|
|
|
- .leftJoin(DictionaryDetail.class, DictionaryDetail::getCode, WfTextbookClaim::getClaimType,
|
|
|
- wra -> wra
|
|
|
- .selectAs(DictionaryDetail::getName, TextbookIssueRecordExcelVo::getClaimTypeCn)
|
|
|
- )
|
|
|
- .leftJoin(BaseClass.class, BaseClass::getId, WfTextbookClaim::getClassId,
|
|
|
- wra -> wra
|
|
|
- .selectAs(BaseClass::getName, TextbookIssueRecordExcelVo::getClassIdCn)
|
|
|
- )
|
|
|
- .leftJoin(BaseGrade.class, BaseGrade::getId, BaseClass::getGradeId,
|
|
|
+ .leftJoin(DictionaryDetail.class, DictionaryDetail::getCode, Textbook::getTextbookType,
|
|
|
wra -> wra
|
|
|
- .selectAs(BaseGrade::getName, TextbookIssueRecordExcelVo::getGradeIdCn)
|
|
|
+ .selectAs(DictionaryDetail::getName, TextbookClaimRecordExportVo::getTextbookTypeCn)
|
|
|
)
|
|
|
)
|
|
|
- .leftJoin(XjrUser.class, XjrUser::getId, TextbookIssueRecord::getIssueUserId,
|
|
|
- wrapper -> wrapper
|
|
|
- .selectAs(XjrUser::getName, TextbookIssueRecordExcelVo::getIssueUserIdCn)
|
|
|
- )
|
|
|
+ .isNotNull(WfTextbookClaim::getClassId)
|
|
|
;
|
|
|
+ List<TextbookClaimRecordExportVo> dataList = textbookIssueRecordMapper.selectJoinList(TextbookClaimRecordExportVo.class, textbookIssueRecordMPJLambdaWrapper);
|
|
|
|
|
|
- List<TextbookIssueRecordExcelVo> dataList = textbookIssueRecordMapper.selectJoinList(TextbookIssueRecordExcelVo.class, textbookIssueRecordMPJLambdaWrapper);
|
|
|
+ // 处理数据
|
|
|
+ // 将数据根据学期和班级进行拆分
|
|
|
+ Map<String, List<TextbookClaimRecordExportVo>> groupBySemesterAndClassMap = dataList.stream()
|
|
|
+ .filter(t -> ObjectUtils.isNotEmpty(t.getClassId()))
|
|
|
+ .collect(Collectors.groupingBy(t -> t.baseSemesterId + "-" + t.getClassId()));
|
|
|
+
|
|
|
+ // 开始写入
|
|
|
+ Workbook workbook = new XSSFWorkbook();
|
|
|
+ // 创建一个工作表(sheet)
|
|
|
+ String sheetName = "sheet1";
|
|
|
+ Sheet sheet = workbook.createSheet(sheetName);
|
|
|
+
|
|
|
+ // 写大标题
|
|
|
+ int rowNumber = 0;
|
|
|
+ ImportExcelUtil.createBigHead(workbook, sheet, "铜梁执教中心班级教材教辅发放情况表", rowNumber++, 19);
|
|
|
+
|
|
|
+ // 字体内容格式
|
|
|
+ Font font = workbook.createFont();
|
|
|
+ font.setBold(false);// 设置为粗体
|
|
|
+ font.setFontName("宋体");
|
|
|
+ font.setFontHeightInPoints((short)12);
|
|
|
+ CellStyle cellStyle = workbook.createCellStyle();
|
|
|
+ cellStyle.setFont(font); // 将字体应用到样式
|
|
|
+ cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
+ cellStyle.setAlignment(HorizontalAlignment.CENTER);
|
|
|
+
|
|
|
+ // 设置边框样式为细线
|
|
|
+ cellStyle.setBorderTop(BorderStyle.THIN);
|
|
|
+ cellStyle.setTopBorderColor(IndexedColors.BLACK.getIndex()); // 设置顶部边框颜色
|
|
|
+
|
|
|
+ cellStyle.setBorderBottom(BorderStyle.THIN);
|
|
|
+ cellStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex()); // 设置底部边框颜色
|
|
|
+
|
|
|
+ cellStyle.setBorderLeft(BorderStyle.THIN);
|
|
|
+ cellStyle.setLeftBorderColor(IndexedColors.BLACK.getIndex()); // 设置左边框颜色
|
|
|
+
|
|
|
+ cellStyle.setBorderRight(BorderStyle.THIN);
|
|
|
+ cellStyle.setRightBorderColor(IndexedColors.BLACK.getIndex()); // 设置右边框颜色
|
|
|
+
|
|
|
+ // 根据学期和班级开始写入
|
|
|
+ List<ImportConfig> importConfigs = ImportExcelUtil.allFields(new TextbookClaimRecordExportVo());
|
|
|
+ List<ImportConfig> eachImportConfigs;
|
|
|
+ List<TextbookClaimRecordExportVo> result;
|
|
|
+ List<List<String>> resultList;
|
|
|
+ Map<Integer, Integer> numMap;
|
|
|
+ String firstCellContent;
|
|
|
+ String oldFirstCellContent;
|
|
|
+ int mergeStartIndex;
|
|
|
+ BigDecimal totalSubtotal = BigDecimal.ZERO;
|
|
|
+ BigDecimal totalPrice;
|
|
|
+ for (Map.Entry<String, List<TextbookClaimRecordExportVo>> entry : groupBySemesterAndClassMap.entrySet()){
|
|
|
+ String key = entry.getKey();
|
|
|
+ List<TextbookClaimRecordExportVo> value = entry.getValue();
|
|
|
+
|
|
|
+ if(ObjectUtils.isEmpty(value)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理数据
|
|
|
+ result = new ArrayList<>();
|
|
|
+ Map<Integer, String> colNameMap = statistics(value, result);
|
|
|
+ // 使用 TreeMap 对 key 进行排序
|
|
|
+ Map<Integer, String> sortedMap = new TreeMap<>(colNameMap);
|
|
|
+ // 处理动态表头
|
|
|
+ eachImportConfigs = new ArrayList<>(importConfigs);
|
|
|
+ for (Map.Entry<Integer, String> colNameEntry : sortedMap.entrySet()){
|
|
|
+ ImportConfig importConfig = new ImportConfig();
|
|
|
+ importConfig.setFieldName("issue" + colNameEntry.getKey());
|
|
|
+ importConfig.setLabel(colNameEntry.getValue());
|
|
|
+ importConfig.setWidth(0);
|
|
|
+ importConfig.setRequired(false);
|
|
|
+ importConfig.setSortCode(eachImportConfigs.size());
|
|
|
+ eachImportConfigs.add(importConfig);
|
|
|
+ }
|
|
|
+ // 处理后续的列名
|
|
|
+ addImportConfig(eachImportConfigs);
|
|
|
+
|
|
|
+ // 班级信息
|
|
|
+ String classInfoHead = "学期:" + value.get(0).getBaseSemesterIdCn() + " " +
|
|
|
+ "班级:" + value.get(0).getClassIdCn() + " " +
|
|
|
+ "班主任:" + value.get(0).getTeacherIdCn() + " " +
|
|
|
+ "班主任电话:" + value.get(0).getTeacherMobile() + " " +
|
|
|
+ "教室:" + value.get(0).getClassroomIdCn() + " " +
|
|
|
+ "班级人数:" + value.get(0).getTotalStuNum() + " ";
|
|
|
+ ImportExcelUtil.createCautionHead(workbook, sheet, rowNumber++, classInfoHead, eachImportConfigs.size() - 1, 12, IndexedColors.BLACK.getIndex());
|
|
|
+
|
|
|
+
|
|
|
+ // 表头
|
|
|
+ ImportExcelUtil.createHead(workbook, sheet, eachImportConfigs, rowNumber++);
|
|
|
+
|
|
|
+ // 处理每个单元格的内容
|
|
|
+ resultList = new ArrayList<>();
|
|
|
+ for (TextbookClaimRecordExportVo vo : result) {
|
|
|
+ List<String> data = new ArrayList<>();
|
|
|
+ data.add(vo.getTextbookTypeCn());
|
|
|
+ data.add(vo.getBookName());
|
|
|
+ data.add(vo.getIssn());
|
|
|
+ data.add(vo.getEditorInChief());
|
|
|
+ data.add(vo.getPublishingHouse());
|
|
|
+ data.add(vo.getPrice() + "");
|
|
|
+ data.add(vo.getSubtotal() + "");
|
|
|
+ if(ObjectUtils.isEmpty(vo.getSummation())){
|
|
|
+ data.add("0");
|
|
|
+ }else {
|
|
|
+ data.add(vo.getSummation() + "");
|
|
|
+ }
|
|
|
+
|
|
|
+ numMap = vo.getNumMap();
|
|
|
+ if(ObjectUtils.isNotEmpty(numMap)){
|
|
|
+ for (Map.Entry<Integer, String> colNameEntry : sortedMap.entrySet()){
|
|
|
+ Integer issueNUm = numMap.get(colNameEntry.getKey());
|
|
|
+ if(ObjectUtils.isNotEmpty(issueNUm)){
|
|
|
+ data.add(issueNUm + "");
|
|
|
+ }else {
|
|
|
+ data.add(0 + "");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ data.add(vo.getIssueNumber() + "");
|
|
|
+ data.add(vo.getRecedeNumber() + "");
|
|
|
+ data.add(vo.getActualIssueNumber() + "");
|
|
|
+ data.add(vo.getActualTotalPrice() + "");
|
|
|
+ data.add(vo.getRemark());
|
|
|
+
|
|
|
+ resultList.add(data);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 写入内容
|
|
|
+ mergeStartIndex = rowNumber;
|
|
|
+ totalPrice = BigDecimal.ZERO;
|
|
|
+ for (int i = 0; i < resultList.size(); i++) {
|
|
|
+ List<String> rowData = resultList.get(i);
|
|
|
+ Row dataRow = sheet.createRow(rowNumber);
|
|
|
+ for (int j = 0; j < rowData.size(); j ++){
|
|
|
+ String content = rowData.get(j);
|
|
|
+ Cell cell = dataRow.createCell(j);
|
|
|
+ cell.setCellValue(content);
|
|
|
+ cell.setCellStyle(cellStyle);
|
|
|
+ }
|
|
|
+ firstCellContent = rowData.get(0);
|
|
|
+ totalPrice = totalPrice.add(StringUtils.isEmpty(rowData.get(rowData.size() - 2)) ? BigDecimal.ZERO : BigDecimal.valueOf(Double.parseDouble(rowData.get(rowData.size() - 2))));
|
|
|
+ //是否是最后一个元素
|
|
|
+ if((i == resultList.size() - 1)){
|
|
|
+ if(rowNumber - mergeStartIndex > 0){
|
|
|
+ // 合并当前教材类型
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(mergeStartIndex, rowNumber, 0, 0));
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(mergeStartIndex, rowNumber, 7, 7));
|
|
|
+ }
|
|
|
+ totalSubtotal = totalSubtotal.add(ObjectUtils.isNotEmpty(rowData.get(7)) ? BigDecimal.valueOf(Double.parseDouble(rowData.get(7))) : BigDecimal.ZERO);
|
|
|
+ }else {
|
|
|
+ List<String> nextRowData = resultList.get(i + 1);
|
|
|
+ if(ObjectUtils.isEmpty(firstCellContent)
|
|
|
+ && ObjectUtils.isNotEmpty(nextRowData.get(0))
|
|
|
+ ){
|
|
|
+ if(rowNumber - mergeStartIndex > 0){
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(mergeStartIndex, rowNumber, 0, 0));
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(mergeStartIndex, rowNumber, 7, 7));
|
|
|
+ }
|
|
|
+ totalSubtotal = totalSubtotal.add(ObjectUtils.isNotEmpty(rowData.get(7)) ? BigDecimal.valueOf(Double.parseDouble(rowData.get(7))) : BigDecimal.ZERO);
|
|
|
+ mergeStartIndex = rowNumber + 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(ObjectUtils.isNotEmpty(firstCellContent)
|
|
|
+ && ObjectUtils.isEmpty(nextRowData.get(0))
|
|
|
+ ){
|
|
|
+ if(rowNumber - mergeStartIndex > 0){
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(mergeStartIndex, rowNumber, 0, 0));
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(mergeStartIndex, rowNumber, 7, 7));
|
|
|
+ }
|
|
|
+ totalSubtotal = totalSubtotal.add(ObjectUtils.isNotEmpty(rowData.get(7)) ? BigDecimal.valueOf(Double.parseDouble(rowData.get(7))) : BigDecimal.ZERO);
|
|
|
+ mergeStartIndex = rowNumber + 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(ObjectUtils.isNotEmpty(firstCellContent)
|
|
|
+ && ObjectUtils.isNotEmpty(nextRowData.get(0))
|
|
|
+ && !firstCellContent.equals(nextRowData.get(0))
|
|
|
+ ){
|
|
|
+ if(rowNumber - mergeStartIndex > 0){
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(mergeStartIndex, rowNumber, 0, 0));
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(mergeStartIndex, rowNumber, 7, 7));
|
|
|
+ }
|
|
|
+ totalSubtotal = totalSubtotal.add(ObjectUtils.isNotEmpty(rowData.get(7)) ? BigDecimal.valueOf(Double.parseDouble(rowData.get(7))) : BigDecimal.ZERO);
|
|
|
+ mergeStartIndex = rowNumber + 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ rowNumber++;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 写入小计
|
|
|
+ Row totalSubtotalRow = sheet.createRow(rowNumber);
|
|
|
+ Cell totalSubtotalStrCell = totalSubtotalRow.createCell(0);
|
|
|
+ totalSubtotalStrCell.setCellValue("小计");
|
|
|
+ totalSubtotalStrCell.setCellStyle(cellStyle);
|
|
|
+
|
|
|
+ Cell totalSubtotalRowCell = totalSubtotalRow.createCell(7);
|
|
|
+ totalSubtotalRowCell.setCellValue(totalSubtotal.toString());
|
|
|
+ totalSubtotalRowCell.setCellStyle(cellStyle);
|
|
|
+
|
|
|
+ Cell totalPriceRowCell = totalSubtotalRow.createCell(eachImportConfigs.size() - 2);
|
|
|
+ totalPriceRowCell.setCellValue(totalPrice.toString());
|
|
|
+ totalPriceRowCell.setCellStyle(cellStyle);
|
|
|
+
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(rowNumber, rowNumber, 0, 6));
|
|
|
+ rowNumber++;
|
|
|
+
|
|
|
+ // 写入签名
|
|
|
+ Row signatureRow = sheet.createRow(rowNumber);
|
|
|
+ Cell stuSignatureRowCell = signatureRow.createCell(eachImportConfigs.size() - 5);
|
|
|
+ stuSignatureRowCell.setCellValue("学生代表");
|
|
|
+ stuSignatureRowCell.setCellStyle(cellStyle);
|
|
|
+
|
|
|
+ Cell teaSignatureRowCell = signatureRow.createCell(eachImportConfigs.size() - 2);
|
|
|
+ teaSignatureRowCell.setCellValue("班主任");
|
|
|
+ teaSignatureRowCell.setCellStyle(cellStyle);
|
|
|
+
|
|
|
+ rowNumber = rowNumber + 3;
|
|
|
+ }
|
|
|
+ // 自动列宽
|
|
|
+ for (int i = 0; i < importConfigs.size(); i++){
|
|
|
+ sheet.autoSizeColumn(i);
|
|
|
+ }
|
|
|
+
|
|
|
+ ByteArrayOutputStream bot = new ByteArrayOutputStream();
|
|
|
+ workbook.write(bot);
|
|
|
+ return bot;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void addImportConfig(List<ImportConfig> eachImportConfigs){
|
|
|
+ ImportConfig importConfig1 = new ImportConfig();
|
|
|
+ importConfig1.setFieldName("issueNumber");
|
|
|
+ importConfig1.setLabel("学生领取数量");
|
|
|
+ importConfig1.setWidth(0);
|
|
|
+ importConfig1.setRequired(false);
|
|
|
+ importConfig1.setSortCode(eachImportConfigs.size());
|
|
|
+ eachImportConfigs.add(importConfig1);
|
|
|
+
|
|
|
+ ImportConfig importConfig2 = new ImportConfig();
|
|
|
+ importConfig2.setFieldName("recedeNumber");
|
|
|
+ importConfig2.setLabel("退书数量");
|
|
|
+ importConfig2.setWidth(0);
|
|
|
+ importConfig2.setRequired(false);
|
|
|
+ importConfig2.setSortCode(eachImportConfigs.size());
|
|
|
+ eachImportConfigs.add(importConfig2);
|
|
|
+
|
|
|
+ ImportConfig importConfig3 = new ImportConfig();
|
|
|
+ importConfig3.setFieldName("actualIssueNumber");
|
|
|
+ importConfig3.setLabel("实发数量");
|
|
|
+ importConfig3.setWidth(0);
|
|
|
+ importConfig3.setRequired(false);
|
|
|
+ importConfig3.setSortCode(eachImportConfigs.size());
|
|
|
+ eachImportConfigs.add(importConfig3);
|
|
|
+
|
|
|
+ ImportConfig importConfig4 = new ImportConfig();
|
|
|
+ importConfig4.setFieldName("actualTotalPrice");
|
|
|
+ importConfig4.setLabel("总价");
|
|
|
+ importConfig4.setWidth(0);
|
|
|
+ importConfig4.setRequired(false);
|
|
|
+ importConfig4.setSortCode(eachImportConfigs.size());
|
|
|
+ eachImportConfigs.add(importConfig4);
|
|
|
+
|
|
|
+ ImportConfig importConfig5 = new ImportConfig();
|
|
|
+ importConfig4.setFieldName("remark");
|
|
|
+ importConfig5.setLabel("备注");
|
|
|
+ importConfig5.setWidth(0);
|
|
|
+ importConfig5.setRequired(false);
|
|
|
+ importConfig5.setSortCode(eachImportConfigs.size());
|
|
|
+ eachImportConfigs.add(importConfig5);
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<Integer, String> statistics(List<TextbookClaimRecordExportVo> value, List<TextbookClaimRecordExportVo> result){
|
|
|
+ Map<Integer, String> colNameMap = new LinkedHashMap<>();
|
|
|
+ // 进行分组统计
|
|
|
+ // 根据教材类型分组
|
|
|
+ Map<String, List<TextbookClaimRecordExportVo>> groupByTextbookTypeMap = value.stream()
|
|
|
+ .filter(t -> ObjectUtils.isNotEmpty(t.getTextbookType()))
|
|
|
+ .collect(Collectors.groupingBy(TextbookClaimRecordExportVo::getTextbookType));
|
|
|
+
|
|
|
+ BigDecimal summation;
|
|
|
+ Map<Integer, Integer> numMap;
|
|
|
+ int stuClaimNum;
|
|
|
+ int recedeNumber;
|
|
|
+ int actualIssueNumber;
|
|
|
+ // 定义日期格式
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ TextbookClaimRecordExportVo first;
|
|
|
+ List<TextbookClaimRecordExportVo> teypResult;
|
|
|
+ // 遍历教材类型
|
|
|
+ for (Map.Entry<String, List<TextbookClaimRecordExportVo>> en : groupByTextbookTypeMap.entrySet()) {
|
|
|
+ String k = en.getKey();
|
|
|
+ List<TextbookClaimRecordExportVo> v = en.getValue();
|
|
|
+ if(ObjectUtils.isEmpty(v)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ summation = BigDecimal.ZERO;
|
|
|
+ teypResult = new ArrayList<>();
|
|
|
+ // 根据教材分组
|
|
|
+ Map<Long, List<TextbookClaimRecordExportVo>> groupByTextbookIdMap = v.stream()
|
|
|
+ .filter(t -> ObjectUtils.isNotEmpty(t.getTextbookId()))
|
|
|
+ .collect(Collectors.groupingBy(TextbookClaimRecordExportVo::getTextbookId));
|
|
|
+
|
|
|
+ // 遍历教材分组
|
|
|
+ for (Map.Entry<Long, List<TextbookClaimRecordExportVo>> enen : groupByTextbookIdMap.entrySet()) {
|
|
|
+ Long kk = enen.getKey();
|
|
|
+ List<TextbookClaimRecordExportVo> vv = enen.getValue();
|
|
|
+ if(ObjectUtils.isEmpty(vv)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ first = vv.get(0);
|
|
|
+ if(ObjectUtils.isEmpty(first)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ stuClaimNum = 0;
|
|
|
+ recedeNumber = 0;
|
|
|
+ actualIssueNumber = 0;
|
|
|
+ summation = summation.add(first.getSubtotal());
|
|
|
+
|
|
|
+ // 使用 List.sort 进行升序排序
|
|
|
+ vv.sort(Comparator.comparingInt(TextbookClaimRecordExportVo::getIssueTimes));
|
|
|
+
|
|
|
+ numMap = new LinkedHashMap<>();
|
|
|
+
|
|
|
+ for (TextbookClaimRecordExportVo vo : vv){
|
|
|
+ // 处理合计
|
|
|
+ if(!colNameMap.containsKey(vo.getIssueTimes())){
|
|
|
+ colNameMap.put(vo.getIssueTimes(), "第" + vo.getIssueTimes() + "次发放数量(" + sdf.format(vo.getCreateDate()) + ")");
|
|
|
+ }
|
|
|
+
|
|
|
+ if(ClaimTypeEnum.ClaimClass.getCode().equals(vo.getClaimType())){
|
|
|
+ if(numMap.containsKey(vo.getIssueTimes())){
|
|
|
+ numMap.put(vo.getIssueTimes(), numMap.get(vo.getIssueTimes()) + vo.getIssueNumber());
|
|
|
+ }else {
|
|
|
+ numMap.put(vo.getIssueTimes(), vo.getIssueNumber());
|
|
|
+ }
|
|
|
+ recedeNumber += vo.getRecedeNumber();
|
|
|
+ actualIssueNumber += vo.getActualIssueNumber();
|
|
|
+ }
|
|
|
+
|
|
|
+ if(ClaimTypeEnum.ClaimStudent.getCode().equals(vo.getClaimType())){
|
|
|
+ stuClaimNum += vo.getIssueNumber();
|
|
|
+ recedeNumber += vo.getRecedeNumber();
|
|
|
+ actualIssueNumber += vo.getActualIssueNumber();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ first.setIssueNumber(stuClaimNum);
|
|
|
+ first.setRecedeNumber(recedeNumber);
|
|
|
+ first.setActualIssueNumber(actualIssueNumber);
|
|
|
+ first.setActualTotalPrice(first.getSubtotal().multiply(BigDecimal.valueOf(actualIssueNumber)));
|
|
|
+ first.setNumMap(numMap);
|
|
|
+ teypResult.add(first);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 赋值小计
|
|
|
+ for (TextbookClaimRecordExportVo vo : teypResult){
|
|
|
+ vo.setSummation(summation);
|
|
|
+ }
|
|
|
+ result.addAll(teypResult);
|
|
|
+ }
|
|
|
|
|
|
- return null;
|
|
|
+ return colNameMap;
|
|
|
}
|
|
|
}
|