|
@@ -1,16 +1,30 @@
|
|
|
package com.ruoyi.web.controller.branch;
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
+import com.ruoyi.branch.service.ITFileService;
|
|
|
import com.ruoyi.common.annotation.RepeatSubmit;
|
|
|
import com.ruoyi.common.core.domain.entity.SysDictData;
|
|
|
+import com.ruoyi.common.core.domain.entity.SysUser;
|
|
|
+import com.ruoyi.common.core.domain.model.LoginUser;
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
|
+import com.ruoyi.common.utils.file.ExcelUtils;
|
|
|
import com.ruoyi.system.service.ISysDictTypeService;
|
|
|
+import com.ruoyi.system.service.ISysUserService;
|
|
|
import com.ruoyi.web.controller.branch.vo.AddPlanVO;
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFCellStyle;
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFFont;
|
|
|
+import org.apache.poi.hssf.util.HSSFColor;
|
|
|
+import org.apache.poi.ss.usermodel.*;
|
|
|
+import org.apache.poi.ss.util.CellRangeAddress;
|
|
|
+import org.apache.poi.xssf.usermodel.*;
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
@@ -46,6 +60,9 @@ public class TBranchLearningController extends BaseController
|
|
|
@Autowired
|
|
|
private ISysDictTypeService sysDictTypeService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ISysUserService userService;
|
|
|
+
|
|
|
@PutMapping("/updateLearningTimeStudied")
|
|
|
public AjaxResult updateLearningTimeStudied(@RequestBody TBranchLearning tBranchLearning)
|
|
|
{
|
|
@@ -131,17 +148,117 @@ public class TBranchLearningController extends BaseController
|
|
|
@PostMapping("/export")
|
|
|
public void export(HttpServletResponse response, TBranchLearning tBranchLearning)
|
|
|
{
|
|
|
- List<SysDictData> learningStatus = sysDictTypeService.selectDictDataByType("learning_status");
|
|
|
- List<TBranchLearning> list = tBranchLearningService.selectTBranchLearningList(tBranchLearning);
|
|
|
- for (TBranchLearning branchLearning : list) {
|
|
|
- for (SysDictData data : learningStatus) {
|
|
|
- if (data.getDictValue().equals(branchLearning.getLearningStatus())) {
|
|
|
- branchLearning.setLearningStatus(data.getDictLabel());
|
|
|
+ try {
|
|
|
+ List<SysDictData> learningStatus = sysDictTypeService.selectDictDataByType("learning_status");
|
|
|
+ List<TBranchLearning> list = tBranchLearningService.selectTBranchLearningList(tBranchLearning);
|
|
|
+ for (TBranchLearning branchLearning : list) {
|
|
|
+ for (SysDictData data : learningStatus) {
|
|
|
+ if (data.getDictValue().equals(branchLearning.getLearningStatus())) {
|
|
|
+ branchLearning.setLearningStatus(data.getDictLabel());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
+ response.setCharacterEncoding("utf-8");
|
|
|
+ XSSFWorkbook workbook = new XSSFWorkbook();
|
|
|
+ // 创建工作簿
|
|
|
+ XSSFSheet sheet = workbook.createSheet();
|
|
|
+ // 标题样式
|
|
|
+ CellStyle headerStyle = workbook.createCellStyle();
|
|
|
+ headerStyle.setFillForegroundColor(HSSFColor.HSSFColorPredefined.GREY_50_PERCENT.getIndex());//背景颜色
|
|
|
+ headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);//背景颜色填充
|
|
|
+ headerStyle.setAlignment(HorizontalAlignment.CENTER);//居中
|
|
|
+ XSSFFont font = workbook.createFont();//字体
|
|
|
+ font.setBold(true);//粗体显示
|
|
|
+ font.setColor(IndexedColors.WHITE.getIndex());//字体颜色
|
|
|
+ headerStyle.setFont(font);
|
|
|
+ // 单元格样式
|
|
|
+ CellStyle cellStyle = workbook.createCellStyle();
|
|
|
+ cellStyle.setAlignment(HorizontalAlignment.CENTER);//居中
|
|
|
+ // 设置列宽
|
|
|
+ sheet.setColumnWidth(0, 2000);
|
|
|
+ sheet.setColumnWidth(1, 10000);
|
|
|
+ sheet.setColumnWidth(2, 2000);
|
|
|
+ sheet.setColumnWidth(3, 6000);
|
|
|
+ sheet.setColumnWidth(4, 6000);
|
|
|
+ sheet.setColumnWidth(5, 4000);
|
|
|
+ sheet.setColumnWidth(6, 2000);
|
|
|
+ sheet.setColumnWidth(7, 2000);
|
|
|
+ // 表头
|
|
|
+ XSSFRow row0 = sheet.createRow(0);
|
|
|
+ XSSFCell cell0 = row0.createCell(0);
|
|
|
+ cell0.setCellValue("姓名");
|
|
|
+ cell0.setCellStyle(headerStyle);
|
|
|
+ XSSFCell cell1 = row0.createCell(1);
|
|
|
+ cell1.setCellValue("课件名称");
|
|
|
+ cell1.setCellStyle(headerStyle);
|
|
|
+ XSSFCell cell2 = row0.createCell(2);
|
|
|
+ cell2.setCellValue("状态");
|
|
|
+ cell2.setCellStyle(headerStyle);
|
|
|
+ XSSFCell cell3 = row0.createCell(3);
|
|
|
+ cell3.setCellValue("规定学习时长(min)");
|
|
|
+ cell3.setCellStyle(headerStyle);
|
|
|
+ XSSFCell cell4 = row0.createCell(4);
|
|
|
+ cell4.setCellValue("累计学习时长(min)");
|
|
|
+ cell4.setCellStyle(headerStyle);
|
|
|
+ XSSFCell cell5 = row0.createCell(5);
|
|
|
+ cell5.setCellValue("截止日期");
|
|
|
+ cell5.setCellStyle(headerStyle);
|
|
|
+ XSSFCell cell6 = row0.createCell(6);
|
|
|
+ cell6.setCellValue("进度");
|
|
|
+ cell6.setCellStyle(headerStyle);
|
|
|
+ XSSFCell cell7 = row0.createCell(7);
|
|
|
+ cell7.setCellValue("签名");
|
|
|
+ cell7.setCellStyle(headerStyle);
|
|
|
+ // 创建行
|
|
|
+ for (int i = 1; i < list.size() + 1; i++) {
|
|
|
+ XSSFRow row = sheet.createRow(i);
|
|
|
+ // 创建单元格
|
|
|
+ for (int j = 0; j < 8; j++) {
|
|
|
+ XSSFCell cell = row.createCell(j);
|
|
|
+ cell.setCellStyle(cellStyle);
|
|
|
+ switch (j) {
|
|
|
+ case 0:
|
|
|
+ cell.setCellValue(list.get(i - 1).getNickName());
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ cell.setCellValue(list.get(i - 1).getFileName());
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ cell.setCellValue(list.get(i - 1).getLearningStatus());
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ cell.setCellValue(list.get(i - 1).getLearningTimeRequired());
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ cell.setCellValue(list.get(i - 1).getLearningTimeStudied());
|
|
|
+ break;
|
|
|
+ case 5:
|
|
|
+ Date learningDeadline = list.get(i - 1).getLearningDeadline();
|
|
|
+ cell.setCellValue(learningDeadline != null ? new SimpleDateFormat("yyyy-MM-dd").format(learningDeadline) : "");
|
|
|
+ break;
|
|
|
+ case 6:
|
|
|
+ cell.setCellValue(list.get(i - 1).getLearningProgress());
|
|
|
+ break;
|
|
|
+ case 7:
|
|
|
+ String isSigned = list.get(i - 1).getIsSigned();
|
|
|
+ if (isSigned.equals("1")) {
|
|
|
+ SysUser user = userService.selectUserById(list.get(i - 1).getUserId());
|
|
|
+ String signUrl = user.getSignUrl();
|
|
|
+ System.err.println(signUrl);
|
|
|
+ if (StringUtils.isNotEmpty(signUrl))
|
|
|
+ ExcelUtils.insertPicture(workbook, sheet, signUrl, i, 7, 1, 1);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ //返回
|
|
|
+ workbook.write(response.getOutputStream());
|
|
|
+ workbook.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
}
|
|
|
- ExcelUtil<TBranchLearning> util = new ExcelUtil<TBranchLearning>(TBranchLearning.class);
|
|
|
- util.exportExcel(response, list, "签名表数据");
|
|
|
}
|
|
|
|
|
|
/**
|