integrated_traffic/src/main/java/com/zcloud/util/archivesUtil/StudentSumTableAbsHandler.java

176 lines
9.2 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package com.zcloud.util.archivesUtil;
import com.zcloud.entity.PageData;
import com.zcloud.service.eduArchives.ArchivesService;
import com.zcloud.service.eduStudy.ClassService;
import com.zcloud.entity.TrainingPlanDao;
import com.zcloud.service.corp.CorpInfoService;
import com.zcloud.util.Const;
import com.zcloud.util.DateUtil;
import com.zcloud.util.Tools;
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 javax.annotation.Resource;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* 说明:学员考核成绩统计表 104
* 作者wangxuan
* 官网www.zcloudchina.com
*/
@Component
public class StudentSumTableAbsHandler extends AbsHandlerBatchExport {
/*
* 同一前缀 archives101
* 同一前缀 archives102
* varList: [{ NAME: '安全培训教材会审表', TYPE: 100 },
{ NAME: '培训日程安排通知/也可称为培训计划', TYPE: 101 },
{ NAME: '安全培训教材或课程讲义', TYPE: 106 },
{ NAME: '安全培训教育记录及签字表', TYPE: 102 },
{ NAME: '培训影像资料', TYPE: 107 },
{ NAME: '培训考核试卷', TYPE: 103 },
{ NAME: '学员考核成绩统计表', TYPE: 104 },
{ NAME: '本期综合考评报告', TYPE: 105 },
{ NAME: '与培训机构签订的服务合同或者协议复印件', TYPE: 6 }],
* */
@Autowired
private ArchivesService archivesService;
@Resource
private ClassService classService;
@Autowired
private CorpInfoService corpinfoService;
@Override
public File batchExport(PageData pd, String now) throws Exception {
String projectPath = pd.getString("projectPath");
PageData clazz = classService.findById(pd);
PageData corpinfo = corpinfoService.findById(pd);
List<PageData> studentList = archivesService.getStudents(pd);
List<PageData> passStudent = new ArrayList<PageData>(); //通过人数
List<PageData> unpassStudent = new ArrayList<PageData>(); //不通过人数
if (studentList.size() > 0) {
if ("1".equals(clazz.get("EXAMINATION").toString())) {
for (PageData studen : studentList) {
if (studen.getString("STAGEEXAMSTATE").equals("3") || studen.getString("STAGEEXAMSTATE").equals("0")) {
passStudent.add(studen);
} else {
unpassStudent.add(studen);
}
}
} else {
for (PageData studen : studentList) {
if ("3".equals(studen.getString("STUDYSTATE"))) {
passStudent.add(studen);
} else {
unpassStudent.add(studen);
}
}
}
}
List<PageData> curList = archivesService.getCurriculums(pd);
List<String> ArrayDATA_IDS = new ArrayList<String>();
for (PageData c : curList) {
ArrayDATA_IDS.add(c.getString("CURRICULUM_ID"));
}
pd.put("ArrayDATA_IDS", ArrayDATA_IDS);
List<PageData> coursewaresList = archivesService.getCoursewares(pd);
double classhour = 0.0;
for (PageData c : coursewaresList) {
if (!Tools.isEmpty(c.get("CLASSHOUR"))) {
classhour += Double.parseDouble(c.get("CLASSHOUR").toString());
}
}
File file = new File(projectPath + Const.FILEPATHWORDTEMPLATE + "studentsumtable.docx");
InputStream mbwj = new FileInputStream(file);
//注册xdocreport实例并加载FreeMarker模板引擎
IXDocReport report = XDocReportRegistry.getRegistry().loadReport(mbwj, TemplateEngineKind.Freemarker);
//创建xdocreport上下文对象
IContext context = report.createContext();
DecimalFormat df = new DecimalFormat("0.0");
SimpleDateFormat formatdate = new SimpleDateFormat("yyyy年MM月dd日");
context.put("value1", corpinfo.getString("NAME")); //平台名称
context.put("value2", clazz.getString("enterpriseName")); //公司名称
context.put("value3", clazz.getString("NAME")); // 任务名称
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date startTime = formatter.parse(clazz.getString("START_TIME"));
Date endTime = formatter.parse(clazz.getString("END_TIME"));
context.put("value4", formatdate.format(startTime) + '至' + formatdate.format(endTime)); //
context.put("value5", "0.0".equals(classhour) ? "0" : df.format(classhour)); // 计划课时
context.put("value6", passStudent.size() + unpassStudent.size());//培训人数
context.put("value7", passStudent.size());//合格人数
context.put("value8", formatdate.format(endTime));//报表日期
List<TrainingPlanDao> list1 = new ArrayList<>(); //一共多少行
for (int i = 0; i < passStudent.size(); i++) {
TrainingPlanDao trainingPlanDao = new TrainingPlanDao(); //每行的内容实体类
trainingPlanDao.setValue1(String.valueOf(i + 1)); //序号
trainingPlanDao.setValue2(passStudent.get(i).get("NAME")!= null ? passStudent.get(i).get("NAME").toString():""); //姓名
trainingPlanDao.setValue3(passStudent.get(i).getString("USER_ID_CARD")); //身份证号
trainingPlanDao.setValue4(passStudent.get(i).getString("PHONE")); //手机号
trainingPlanDao.setValue5(passStudent.get(i).getString("SEX_NAME")); //性别
Double comphour = Double.parseDouble(passStudent.get(i).getString("COMPLETE_CLASSHOUR"));
trainingPlanDao.setValue6(comphour == 0.0 ? "0" : df.format(comphour)); //完成学时
trainingPlanDao.setValue7(Double.parseDouble(passStudent.get(i).getString("STAGEEXAMSCORE")) > -1 ? passStudent.get(i).getString("STAGEEXAMSCORE") : "不考试"); //结业考试成绩
list1.add(trainingPlanDao);
}
context.put("list1", list1);
List<TrainingPlanDao> list2 = new ArrayList<>(); //一共多少行
for (int i = 0; i < unpassStudent.size(); i++) {
TrainingPlanDao trainingPlanDao = new TrainingPlanDao(); //每行的内容实体类
trainingPlanDao.setValue1(String.valueOf(i + 1)); //序号
trainingPlanDao.setValue2(unpassStudent.get(i).get("NAME")!= null ? unpassStudent.get(i).get("NAME").toString():""); //姓名
trainingPlanDao.setValue3(unpassStudent.get(i).getString("USER_ID_CARD")); //身份证号
trainingPlanDao.setValue4(unpassStudent.get(i).getString("PHONE")); //手机号
trainingPlanDao.setValue5(unpassStudent.get(i).getString("SEX_NAME")); //性别
Double comphour = Double.parseDouble(unpassStudent.get(i).getString("COMPLETE_CLASSHOUR"));
trainingPlanDao.setValue6(comphour == 0.0 ? "0" : df.format(comphour)); //完成学时
if ("1".equals(clazz.get("EXAMINATION").toString())) {
if (Integer.parseInt(String.valueOf(unpassStudent.get(i).get("examnum"))) > 0) {
trainingPlanDao.setValue7(Double.parseDouble(unpassStudent.get(i).getString("STAGEEXAMSCORE")) > -1 ? unpassStudent.get(i).getString("STAGEEXAMSCORE") : "0分");
} else {
trainingPlanDao.setValue7(Double.parseDouble(unpassStudent.get(i).getString("STAGEEXAMSCORE")) > -1 ? unpassStudent.get(i).getString("STAGEEXAMSCORE") : "未参加");
}
} else {
trainingPlanDao.setValue7("不考试");
}
list2.add(trainingPlanDao);
}
context.put("list2", list2);
FieldsMetadata fm = report.createFieldsMetadata();
fm.load("list1", TrainingPlanDao.class, true);
fm.load("list2", TrainingPlanDao.class, true);
now = DateUtil.getSdfTimesSSS();
FileOutputStream out = new FileOutputStream(projectPath + Const.TEMPZIPFILES + "学员考核成绩统计表-" + now + ".docx");
report.process(context, out);
out.close();
File word = new File(projectPath + Const.TEMPZIPFILES + "学员考核成绩统计表-" + now + ".docx");
WordToPdfUtil.docToPdf(projectPath + Const.TEMPZIPFILES + "学员考核成绩统计表-" + now + ".docx",
projectPath + Const.TEMPZIPFILES + "学员考核成绩统计表-" + now + ".pdf");
word.delete();
File pdf = new File(projectPath + Const.TEMPZIPFILES + "学员考核成绩统计表-" + now + ".pdf");
return pdf;
}
@Override
public void afterPropertiesSet() throws Exception {
BatchExportFactory.register("archives104", this);
}
}