feat(archives): 添加视频时长格式化功能

dev
zhaokai 2026-03-11 15:30:33 +08:00
parent 8030a85288
commit 5026b838a0
5 changed files with 34 additions and 3 deletions

View File

@ -14,7 +14,7 @@
培训类型
{{trainTypeName}}
视频学习时长
{{videoTotalTime}}(包含{{videoCount}}个视频课件)
{{videoTotalTimeStr}}(包含{{videoCount}}个视频课件)
培训单位:(盖章)
日期:

View File

@ -6,7 +6,7 @@
课程名称
{{trainSubject}}
视频时长
{{videoTotalTime}}
{{videoTotalTimeStr}}
是否完成
{{stateName}}
签到人脸验证

View File

@ -54,6 +54,7 @@ import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;
import java.io.File;
import java.math.BigDecimal;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.time.format.DateTimeFormatter;
@ -471,6 +472,7 @@ public class ArchivesQueryExe {
// // workItem.put("examSignFacePicture", defaultPicture);
// }
}
BigDecimal videoTotalTime = params.getVideoTotalTime();
String templatePath = "templates/template/studyRecord.docx";
ByteArrayOutputStream outputStream = Tools.renderTemplate(templatePath, workItem);
@ -521,11 +523,11 @@ public class ArchivesQueryExe {
workItem.put("className", params.getClassName());
if(!ObjectUtils.isEmpty(params.getStudentExamRecord().getSignUrl())){
// PictureRenderData signPicture = Pictures.ofUrl(fileUrlConfig.getPrefixUrl() + params.getStudentExamRecord().getSignUrl(), PictureType.JPEG).size(50, 15).create();//网络图片地址
PictureRenderData signPicture = ImageUtil.createWithThumbnailator(fileUrlConfig.getPrefixUrl() + params.getStudentExamRecord(), 50, 15);
PictureRenderData signPicture = ImageUtil.createWithThumbnailator(fileUrlConfig.getPrefixUrl() + params.getStudentExamRecord().getSignUrl(), 50, 15);
workItem.put("signPicture", signPicture);
}
log.info("考试试卷下载转换前,{}",JSONUtil.toJsonStr(params.getStudentExamRecord()));
log.info("考试试卷下载,{}",JSONUtil.toJsonStr(workItem));
// log.info("考试试卷下载转换前,{}",JSONUtil.toJsonStr(params.getStudentExamRecord()));
// log.info("考试试卷下载,{}",JSONUtil.toJsonStr(workItem));
String templatePath = "templates/template/exam.docx";
ByteArrayOutputStream outputStream = Tools.renderTemplate(templatePath, workItem);
return outputStream.toByteArray();

View File

@ -139,6 +139,7 @@ public class PersonArchivesDTO {
@ApiModelProperty(value = "视频时长")
private BigDecimal videoTotalTime;
private String videoTotalTimeStr;
@ApiModelProperty(value = "课件数")
private Integer videoCount;

View File

@ -140,6 +140,7 @@ public class PersonArchivesE extends BaseE {
private String trainSubject;
@ApiModelProperty(value = "视频时长")
private BigDecimal videoTotalTime;
private String videoTotalTimeStr;
@ApiModelProperty(value = "课件数")
private Integer videoCount;
@ApiModelProperty(value = "打卡签到人脸图片路径")
@ -199,7 +200,32 @@ public class PersonArchivesE extends BaseE {
.filter(bigDecimal -> bigDecimal != null) // 过滤null值防止空指针异常
.reduce(BigDecimal.ZERO, BigDecimal::add);
setVideoTotalTime(videoTotalTime);
setVideoTotalTimeStr(getTimeStr(videoTotalTime));
}
public String getTimeStr(BigDecimal decimal) {
if (decimal != null) {
long totalSeconds = decimal.longValue();
long hours = totalSeconds / 3600;
long minutes = (totalSeconds % 3600) / 60;
long seconds = totalSeconds % 60;
StringBuilder timeText = new StringBuilder();
if (hours > 0) {
timeText.append(hours).append("小时");
}
if (minutes > 0) {
timeText.append(minutes).append("分");
}
if (seconds > 0 || timeText.length() == 0) {
timeText.append(seconds).append("秒");
}
return timeText.toString();
}
return "";
}
public void initStudyRecord(StudentE studentE, ClassE classE, List<StudentSignE> studentSignEList, List<ClassCurriculumE> classCurList) {
BeanUtils.copyProperties(studentE, this);
@ -226,6 +252,7 @@ public class PersonArchivesE extends BaseE {
String trainSubject = classCurList.stream().map(ClassCurriculumE::getCurriculumName).collect(Collectors.joining(","));
setTrainSubject(trainSubject);
setVideoTotalTime(videoTotalTime);
setVideoTotalTimeStr(getTimeStr(videoTotalTime));
if (studentSignEList != null && studentSignEList.size() > 0){
for (StudentSignE studentSignE : studentSignEList){
if(studentSignE.getType() == 1
@ -280,6 +307,7 @@ public class PersonArchivesE extends BaseE {
.filter(bigDecimal -> bigDecimal != null) // 过滤null值防止空指针异常
.reduce(BigDecimal.ZERO, BigDecimal::add);
setVideoTotalTime(videoTotalTime);
setVideoTotalTimeStr(getTimeStr(videoTotalTime));
}
if (chapterEList != null && chapterEList.size() > 0){
setVideoCount(chapterEList.size());