forked from integrated_whb/integrated_whb
137 lines
6.6 KiB
Java
137 lines
6.6 KiB
Java
|
package com.zcloud.util.archivesUtil;
|
|||
|
|
|||
|
import com.zcloud.entity.PageData;
|
|||
|
import com.zcloud.entity.TrainingPlanDao;
|
|||
|
import com.zcloud.mapper.dsno3.eduArchives.ArchivesMapper;
|
|||
|
import com.zcloud.mapper.dsno3.eduStudy.ClassMapper;
|
|||
|
import com.zcloud.service.eduArchives.ArchivesService;
|
|||
|
import com.zcloud.util.Const;
|
|||
|
import com.zcloud.util.DateUtil;
|
|||
|
import com.zcloud.util.WordToPdfUtil;
|
|||
|
import fr.opensagres.xdocreport.document.IXDocReport;
|
|||
|
import fr.opensagres.xdocreport.document.registry.XDocReportRegistry;
|
|||
|
import fr.opensagres.xdocreport.template.IContext;
|
|||
|
import fr.opensagres.xdocreport.template.TemplateEngineKind;
|
|||
|
import fr.opensagres.xdocreport.template.formatter.FieldsMetadata;
|
|||
|
import org.springframework.beans.factory.annotation.Autowired;
|
|||
|
import org.springframework.stereotype.Component;
|
|||
|
|
|||
|
import java.io.File;
|
|||
|
import java.io.FileInputStream;
|
|||
|
import java.io.FileOutputStream;
|
|||
|
import java.io.InputStream;
|
|||
|
import java.util.ArrayList;
|
|||
|
import java.util.List;
|
|||
|
|
|||
|
/**
|
|||
|
* 说明:安全培训教材会审表
|
|||
|
* 作者:wangxuan
|
|||
|
* 官网:www.zcloudchina.com
|
|||
|
*
|
|||
|
* @author wangxuan
|
|||
|
*/
|
|||
|
@Component
|
|||
|
public class AchievementAbsHandler extends AbsHandlerBatchExport {
|
|||
|
@Autowired
|
|||
|
private ClassMapper classMapper;
|
|||
|
|
|||
|
@Autowired
|
|||
|
private ArchivesMapper archivesMapper;
|
|||
|
|
|||
|
/**
|
|||
|
* @Description: 返回pdf路径
|
|||
|
* @Author: dearLin
|
|||
|
* @Date: 2023/3/20/020 10:41
|
|||
|
* @Param: [com.zcloud.entity.PageData] [pageData]
|
|||
|
* @Return: java.lang.String
|
|||
|
*/
|
|||
|
@Override
|
|||
|
public File batchExport(PageData pd, String nowZip) throws Exception {
|
|||
|
String projectPath = pd.getString("projectPath");
|
|||
|
String now = DateUtil.getSdfTimesSSS();
|
|||
|
ArrayList<File> files = new ArrayList<>(); //最外层
|
|||
|
PageData clazz = classMapper.findById(pd);
|
|||
|
List<PageData> studentList = archivesMapper.getStudents(pd);
|
|||
|
|
|||
|
File file = new File(projectPath + Const.FILEPATHWORDTEMPLATE + "traffic-records4.docx");
|
|||
|
InputStream mbwj = new FileInputStream(file);
|
|||
|
//注册xdocreport实例并加载FreeMarker模板引擎
|
|||
|
IXDocReport report = XDocReportRegistry.getRegistry().loadReport(mbwj, TemplateEngineKind.Freemarker);
|
|||
|
//创建xdocreport上下文对象
|
|||
|
IContext context = report.createContext();
|
|||
|
List<TrainingPlanDao> list1 = new ArrayList<>(); //一共多少行
|
|||
|
|
|||
|
for (int i = 0; i < studentList.size(); i++) {
|
|||
|
|
|||
|
if (i % 3 == 0) {
|
|||
|
TrainingPlanDao trainingPlanDao = new TrainingPlanDao(); //每行的内容实体类
|
|||
|
trainingPlanDao.setValue1(String.valueOf(i + 1)); //序号
|
|||
|
trainingPlanDao.setValue2(studentList.get(i).getString("NAME")); //序号
|
|||
|
if ("1".equals(clazz.get("EXAMINATION").toString())) {
|
|||
|
if (Integer.parseInt(String.valueOf(studentList.get(i).get("examnum"))) > 0) {
|
|||
|
trainingPlanDao.setValue3(Double.parseDouble(studentList.get(i).getString("STAGEEXAMSCORE")) > -1 ? studentList.get(i).getString("STAGEEXAMSCORE") : "0分");
|
|||
|
} else {
|
|||
|
trainingPlanDao.setValue3(Double.parseDouble(studentList.get(i).getString("STAGEEXAMSCORE")) > -1 ? studentList.get(i).getString("STAGEEXAMSCORE") : "未参加");
|
|||
|
}
|
|||
|
} else {
|
|||
|
trainingPlanDao.setValue3("不考试");
|
|||
|
}
|
|||
|
|
|||
|
if ((i + 1) < studentList.size()) {
|
|||
|
trainingPlanDao.setValue4(String.valueOf(i + 2)); //序号
|
|||
|
trainingPlanDao.setValue5(studentList.get(i + 1).getString("NAME")); //序号
|
|||
|
if ("1".equals(clazz.get("EXAMINATION").toString())) {
|
|||
|
if (Integer.parseInt(String.valueOf(studentList.get(i + 1).get("examnum"))) > 0) {
|
|||
|
trainingPlanDao.setValue6(Double.parseDouble(studentList.get(i + 1).getString("STAGEEXAMSCORE")) > -1 ? studentList.get(i + 1).getString("STAGEEXAMSCORE") : "0分");
|
|||
|
} else {
|
|||
|
trainingPlanDao.setValue6(Double.parseDouble(studentList.get(i + 1).getString("STAGEEXAMSCORE")) > -1 ? studentList.get(i + 1).getString("STAGEEXAMSCORE") : "未参加");
|
|||
|
}
|
|||
|
} else {
|
|||
|
trainingPlanDao.setValue6("不考试");
|
|||
|
}
|
|||
|
} else {
|
|||
|
trainingPlanDao.setValue4("");
|
|||
|
trainingPlanDao.setValue5("");
|
|||
|
trainingPlanDao.setValue6("");
|
|||
|
}
|
|||
|
|
|||
|
if ((i + 2) < studentList.size()) {
|
|||
|
trainingPlanDao.setValue7(String.valueOf(i + 3)); //序号
|
|||
|
trainingPlanDao.setValue8(studentList.get(i + 2).getString("NAME")); //序号
|
|||
|
if ("1".equals(clazz.get("EXAMINATION").toString())) {
|
|||
|
if (Integer.parseInt(String.valueOf(studentList.get(i + 2).get("examnum"))) > 0) {
|
|||
|
trainingPlanDao.setValue9(Double.parseDouble(studentList.get(i + 2).getString("STAGEEXAMSCORE")) > -1 ? studentList.get(i + 2).getString("STAGEEXAMSCORE") : "0分");
|
|||
|
} else {
|
|||
|
trainingPlanDao.setValue9(Double.parseDouble(studentList.get(i + 2).getString("STAGEEXAMSCORE")) > -1 ? studentList.get(i + 2).getString("STAGEEXAMSCORE") : "未参加");
|
|||
|
}
|
|||
|
} else {
|
|||
|
trainingPlanDao.setValue9("不考试");
|
|||
|
}
|
|||
|
} else {
|
|||
|
trainingPlanDao.setValue7("");
|
|||
|
trainingPlanDao.setValue8("");
|
|||
|
trainingPlanDao.setValue9("");
|
|||
|
}
|
|||
|
|
|||
|
list1.add(trainingPlanDao);
|
|||
|
}
|
|||
|
}
|
|||
|
context.put("list1", list1);
|
|||
|
FieldsMetadata fm = report.createFieldsMetadata();
|
|||
|
fm.load("list1", TrainingPlanDao.class, true);
|
|||
|
//输出到本地目录
|
|||
|
FileOutputStream out = new FileOutputStream(new File(projectPath + Const.FILEPATHFILE + "安全知识培训成绩表-" + now + ".docx"));
|
|||
|
report.process(context, out);
|
|||
|
WordToPdfUtil.docToPdf(projectPath + Const.FILEPATHFILE + "安全知识培训成绩表-" + now + ".docx", projectPath + Const.FILEPATHFILE + "安全知识培训成绩表-" + now + ".pdf");
|
|||
|
//删除本地word pdf
|
|||
|
File word = new File(projectPath + Const.FILEPATHFILE + "安全知识培训成绩表-" + now + ".docx");
|
|||
|
word.delete();
|
|||
|
return new File(projectPath + Const.FILEPATHFILE + "安全知识培训成绩表-" + now + ".pdf");
|
|||
|
}
|
|||
|
|
|||
|
@Override
|
|||
|
public void afterPropertiesSet() throws Exception {
|
|||
|
BatchExportFactory.register("archives113", this);
|
|||
|
}
|
|||
|
}
|