Переглянути джерело

feat(training): 添加LDPE培训签到表生成功能

- 新增针对部门ID为10025的培训导出LDPE签到表逻辑- 实现replaceExcelLdpe方法用于渲染LDPE培训人员信息
- 新增replaceLdpeSheet方法支持按班组筛选并填充人员数据
- 支持CTA、CTM、CTS及各班次员工的签到表生成
- 自动排除离职时间早于培训开始时间的员工
- 支持指定人员参与培训的名单合并处理- 完善Excel单元格样式与合并规则以适配签到表格式
jiangbiao 2 місяців тому
батько
коміт
7809dd24f6

+ 202 - 14
master/src/main/java/com/ruoyi/project/training/controller/TTrainingController.java

@@ -1,17 +1,18 @@
 package com.ruoyi.project.training.controller;
 
-import java.io.*;
-import java.net.URLEncoder;
-import java.text.SimpleDateFormat;
-import java.util.*;
-
 import com.alibaba.fastjson.JSON;
 import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.common.utils.DictUtils;
 import com.ruoyi.common.utils.file.ExcelUtils;
 import com.ruoyi.common.utils.file.FileUploadUtils;
 import com.ruoyi.common.utils.poi.CustomXWPFDocument;
+import com.ruoyi.common.utils.poi.ExcelUtil;
+import com.ruoyi.framework.aspectj.lang.annotation.Log;
+import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
 import com.ruoyi.framework.config.RuoYiConfig;
+import com.ruoyi.framework.web.controller.BaseController;
+import com.ruoyi.framework.web.domain.AjaxResult;
+import com.ruoyi.framework.web.page.TableDataInfo;
 import com.ruoyi.project.plant.domain.TStaffmgr;
 import com.ruoyi.project.plant.mapper.TStaffmgrMapper;
 import com.ruoyi.project.plant.service.ITStaffmgrService;
@@ -19,6 +20,7 @@ import com.ruoyi.project.system.domain.SysDept;
 import com.ruoyi.project.system.domain.SysDictData;
 import com.ruoyi.project.system.service.ISysDeptService;
 import com.ruoyi.project.system.service.ISysDictTypeService;
+import com.ruoyi.project.training.domain.TTraining;
 import com.ruoyi.project.training.domain.TTrainingDevice;
 import com.ruoyi.project.training.domain.TTrainingNon;
 import com.ruoyi.project.training.domain.TTrainingRegular;
@@ -26,6 +28,7 @@ import com.ruoyi.project.training.mapper.TTrainingMapper;
 import com.ruoyi.project.training.service.ITTrainingDeviceService;
 import com.ruoyi.project.training.service.ITTrainingNonService;
 import com.ruoyi.project.training.service.ITTrainingRegularService;
+import com.ruoyi.project.training.service.ITTrainingService;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
 import org.apache.poi.ss.usermodel.*;
@@ -33,22 +36,18 @@ import org.apache.poi.ss.util.CellRangeAddress;
 import org.apache.poi.xssf.streaming.SXSSFWorkbook;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.apache.poi.xwpf.usermodel.*;
-import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
-import com.ruoyi.framework.aspectj.lang.annotation.Log;
-import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
-import com.ruoyi.project.training.domain.TTraining;
-import com.ruoyi.project.training.service.ITTrainingService;
-import com.ruoyi.framework.web.controller.BaseController;
-import com.ruoyi.framework.web.domain.AjaxResult;
-import com.ruoyi.common.utils.poi.ExcelUtil;
-import com.ruoyi.framework.web.page.TableDataInfo;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import java.io.*;
+import java.net.URLEncoder;
+import java.text.SimpleDateFormat;
+import java.util.*;
 
 /**
  * 培训计划Controller
@@ -529,6 +528,27 @@ public class TTrainingController extends BaseController {
             } catch (Exception e) {
                 e.printStackTrace();
             }
+        }else if(tTraining.getDeptId() == 10025){
+            try {
+                tempUrl = "static/word/training/signLDPE.xlsx"; // 模板文件
+                InputStream is = null;
+                is = Thread.currentThread().getContextClassLoader().getResourceAsStream(tempUrl);
+                XSSFWorkbook wb = new XSSFWorkbook(is);
+                // 替换excel模板数据
+                replaceExcelLdpe(wb, trainingId);
+                response.setContentType("application/octet-stream");// 下载,默认就是下载
+                response.setCharacterEncoding("UTF-8");
+                response.setHeader("Content-Disposition",
+                        "attachment;fileName=" + URLEncoder.encode(tTraining.getCourse() + ".xlsx", "UTF-8"));
+                // 刷新缓冲
+                response.flushBuffer();
+                OutputStream ouputStream = response.getOutputStream();
+                wb.write(ouputStream);
+                ouputStream.flush();
+                ouputStream.close();
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
         } else {
             try {
                 tempUrl = "static/word/training/signBYX.xlsx"; // 模板文件
@@ -642,6 +662,48 @@ public class TTrainingController extends BaseController {
         cell2.setCellValue(tTraining.getCourse());
     }
 
+    /**LDPE Excel渲染*/
+    private void replaceExcelLdpe(XSSFWorkbook wb, Long trainingId) {
+        TTraining tTraining = tTrainingMapper.selectTTrainingById(trainingId);
+        TStaffmgr tStaffmgr = new TStaffmgr();
+        tStaffmgr.setActualposts(tTraining.getPosition());
+        tStaffmgr.setDeptId(tTraining.getDeptId());
+        List<TStaffmgr> staffmgrList = tStaffmgrMapper.selectAllTStaffmgrList(tStaffmgr);
+        try {
+            //判断离职
+            if (StringUtils.isNotEmpty(tTraining.getYear())) {
+                Iterator<TStaffmgr> iterator = staffmgrList.iterator();
+                while (iterator.hasNext()) {
+                    TStaffmgr t = iterator.next();
+                    if (t.getLeftDate() != null && t.getDelFlag() == 9) {
+                        if (t.getLeftDate().getTime() - tTraining.getStartDate().getTime() < 0l) {
+                            iterator.remove();
+                        }
+                    }
+                }
+            }
+        } catch (Exception ignored) {
+        }
+
+        List<TStaffmgr> staffmgrs = new ArrayList<TStaffmgr>();
+        if (tTraining.getDesignatedStaff() != null) { //判断指定人员
+            String[] staffIds = tTraining.getDesignatedStaff().split(",");
+            for (String staffId : staffIds) {
+                TStaffmgr staffmgr = tStaffmgrMapper.selectTStaffmgrByStaffId(staffId);
+                staffmgrs.add(staffmgr);
+            }
+            staffmgrList.addAll(staffmgrs);
+        }
+        replaceLdpeSheet(wb, "白班", staffmgrList,tTraining);
+        replaceLdpeSheet(wb, "A班", staffmgrList,tTraining);
+        replaceLdpeSheet(wb, "B班", staffmgrList,tTraining);
+        replaceLdpeSheet(wb, "C班", staffmgrList,tTraining);
+        replaceLdpeSheet(wb, "D班", staffmgrList,tTraining);
+        replaceLdpeSheet(wb, "CTM", staffmgrList,tTraining);
+        replaceLdpeSheet(wb, "CTA", staffmgrList,tTraining);
+        replaceLdpeSheet(wb, "CTS", staffmgrList,tTraining);
+    }
+
     //苯乙烯 Excel 渲染
     private void replaceExcel(SXSSFWorkbook wb, Long trainingId) {
         Sheet sheet = wb.getSheet("CTAM");
@@ -821,6 +883,132 @@ public class TTrainingController extends BaseController {
 
     }
 
+    /**LDPE Excel 渲染*/
+    private void replaceLdpeSheet(XSSFWorkbook wb,String sheetName,List<TStaffmgr> staffmgrList,TTraining tTraining) {
+        List<SysDictData> dictList = iSysDictTypeService.selectDictDataByType("STAFF_UNIT");
+        Sheet sheet = wb.getSheet(sheetName);
+        List<TStaffmgr> staffmgrs = new ArrayList<>();
+        if ("CTA".equals(sheetName)) {
+            for (TStaffmgr t : staffmgrList
+            ) {
+                if (t.getUnit().equals("42")) {
+                    staffmgrs.add(t);
+                }
+            }
+        }
+        if ("CTM".equals(sheetName)) {
+            for (TStaffmgr t : staffmgrList
+            ) {
+                if (t.getUnit().equals("40")) {
+                    staffmgrs.add(t);
+                }
+            }
+        }
+        if ("CTS".equals(sheetName)) {
+            for (TStaffmgr t : staffmgrList
+            ) {
+                if (t.getUnit().equals("44")) {
+                    staffmgrs.add(t);
+                }
+            }
+        }
+        if ("白班".equals(sheetName)) {
+            for (TStaffmgr t : staffmgrList
+            ) {
+                if (t.getTeam().equals("18") && t.getUnit().equals("34")) {
+                    staffmgrs.add(t);
+                }
+            }
+        }
+        if ("A班".equals(sheetName)) {
+            for (TStaffmgr t : staffmgrList
+            ) {
+                if (t.getTeam().equals("10")) {
+                    staffmgrs.add(t);
+                }
+            }
+        }
+        if ("B班".equals(sheetName)) {
+            for (TStaffmgr t : staffmgrList
+            ) {
+                if (t.getTeam().equals("12")) {
+                    staffmgrs.add(t);
+                }
+            }
+        }
+        if ("C班".equals(sheetName)) {
+            for (TStaffmgr t : staffmgrList
+            ) {
+                if (t.getTeam().equals("14")) {
+                    staffmgrs.add(t);
+                }
+            }
+        }
+        if ("D班".equals(sheetName)) {
+            for (TStaffmgr t : staffmgrList
+            ) {
+                if (t.getTeam().equals("16")) {
+                    staffmgrs.add(t);
+                }
+            }
+        }
+
+        // 第 2 行
+        Row row1 = sheet.getRow(1);
+        row1.getCell(0).setCellValue("Course Code 课程代码:"+tTraining.getCourseid());
+        row1.getCell(5).setCellValue("Course Title 课程:"+tTraining.getCourse());
+        // 第 3 行
+        Row row2 = sheet.getRow(2);
+        TStaffmgr tStaffmgr = tStaffmgrService.selectTStaffmgrByStaffId(tTraining.getTrainer());
+        row2.getCell(2).setCellValue(tStaffmgr.getName());
+        // 第 4 行
+        Row row3 = sheet.getRow(3);
+        row3.getCell(2).setCellValue(DateUtils.dateTime(tTraining.getCourseStartdate())+"~"+ DateUtils.dateTime(tTraining.getCourseEnddate()));
+        // 第 5 行
+        Row row4 = sheet.getRow(4);
+        row4.getCell(2).setCellValue(tTraining.getDuration());
+        // 第 6 行
+        Row row5 = sheet.getRow(5);
+        row5.getCell(0).setCellValue("培训内容:"+tTraining.getContent());
+
+        Row originalRow = sheet.getRow(8);
+        Cell originalcell = originalRow.getCell(0);
+        // 获取单元格样式
+        CellStyle originalStyle = originalcell.getCellStyle();
+        int rowIndex = 8;
+        int num = 1;
+        for (TStaffmgr t : staffmgrs) {
+            Row row = sheet.createRow(rowIndex);
+            row.setHeight((short) 800);
+            row.createCell(0).setCellValue(num);
+            row.createCell(1).setCellValue(DictUtils.getDictVale(dictList, t.getUnit()));
+            row.createCell(2).setCellValue(t.getStaffid());
+            row.createCell(3).setCellValue(t.getName());
+            row.createCell(4).setCellValue("");
+            row.createCell(5).setCellValue("");
+            row.createCell(6).setCellValue("");
+            row.createCell(7).setCellValue("");
+            row.createCell(8).setCellValue("");
+            row.createCell(9).setCellValue("");
+
+            // 合并第3和第4列 (索引3和4)
+            sheet.addMergedRegion(new CellRangeAddress(rowIndex, rowIndex, 3, 4));
+            // 合并第5、6、7列 (索引5, 6, 7)
+            sheet.addMergedRegion(new CellRangeAddress(rowIndex, rowIndex, 5, 7));
+            // 合并第8和第9列 (索引8, 9)
+            sheet.addMergedRegion(new CellRangeAddress(rowIndex, rowIndex, 8, 9));
+
+
+
+
+            //渲染样式
+            for (int i = 0; i < 10; i++) {
+                row.getCell(i).setCellStyle(originalStyle);
+            }
+            num++;
+            rowIndex++;
+        }
+    }
     /**
      * @Description: 替换段落和表格
      */

BIN
master/src/main/resources/static/word/training/signLDPE.xlsx