Browse Source

fix: 解决培训管理文件导出图片显示异常的问题

zhongwei
liwen 1 year ago
parent
commit
92b99a680d
  1. 12
      hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/TrainPlanEntity.java
  2. 11
      hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/TrainRecordDetailVO.java
  3. 1
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/TestServiceImpl.java
  4. 6
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/TrainPlanServiceImpl.java
  5. 21
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/TrainRecordServiceImpl.java
  6. BIN
      hzims-service/safeproduct/src/main/resources/template/培训记录表.docx

12
hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/TrainPlanEntity.java

@ -35,13 +35,11 @@ public class TrainPlanEntity extends BaseEntity {
@NotNull @NotNull
@JsonFormat(pattern = "yyyy-MM-dd") @JsonFormat(pattern = "yyyy-MM-dd")
@ApiModelProperty("计划开始时间") @ApiModelProperty("计划开始时间")
@ExcelProperty(value = "计划开始时间", index = 6)
private Date scheduledStartTime; private Date scheduledStartTime;
@NotNull @NotNull
@JsonFormat(pattern = "yyyy-MM-dd") @JsonFormat(pattern = "yyyy-MM-dd")
@ApiModelProperty("计划结束时间") @ApiModelProperty("计划结束时间")
@ExcelProperty(value = "计划结束时间", index = 7)
private Date scheduledEndTime; private Date scheduledEndTime;
@NotNull @NotNull
@ -80,4 +78,14 @@ public class TrainPlanEntity extends BaseEntity {
@ApiModelProperty("是否考试") @ApiModelProperty("是否考试")
@ExcelProperty(value = "是否考试", index = 5) @ExcelProperty(value = "是否考试", index = 5)
private String hasTest; private String hasTest;
@TableField(exist = false)
@ApiModelProperty("计划开始时间")
@ExcelProperty(value = "计划开始时间", index = 6)
private String startTime;
@TableField(exist = false)
@ApiModelProperty("计划结束时间")
@ExcelProperty(value = "计划结束时间", index = 7)
private String endTime;
} }

11
hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/TrainRecordDetailVO.java

@ -1,10 +1,12 @@
package com.hnac.hzims.safeproduct.vo; package com.hnac.hzims.safeproduct.vo;
import cn.afterturn.easypoi.entity.ImageEntity;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import java.util.Date; import java.util.Date;
import java.util.List;
/** /**
* @author liwen * @author liwen
@ -52,4 +54,13 @@ public class TrainRecordDetailVO {
@ApiModelProperty("培训附件") @ApiModelProperty("培训附件")
private String filePath; private String filePath;
@ApiModelProperty("图片列表")
private List<ImageEntity> images;
@ApiModelProperty("年份")
private String year;
@ApiModelProperty("月份")
private String month;
} }

1
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/TestServiceImpl.java

@ -87,6 +87,7 @@ public class TestServiceImpl extends ServiceImpl<TestMapper, TestEntity> impleme
/** /**
* 删除关联考试记录 * 删除关联考试记录
*/ */
@Transactional(rollbackFor = Exception.class)
@Override @Override
public boolean removeRelativeTest(Long trainRecordId) { public boolean removeRelativeTest(Long trainRecordId) {
// 查询关联考试记录 // 查询关联考试记录

6
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/TrainPlanServiceImpl.java

@ -23,6 +23,7 @@ import com.hnac.hzims.safeproduct.vo.TrainMonthVO;
import com.hnac.hzims.safeproduct.vo.TrainYearVO; import com.hnac.hzims.safeproduct.vo.TrainYearVO;
import org.springblade.core.log.exception.ServiceException; import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.mp.support.Query; import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -194,7 +195,7 @@ public class TrainPlanServiceImpl extends ServiceImpl<TrainPlanMapper, TrainPlan
String startTime = String.valueOf(param.get("scheduledStartTime")); String startTime = String.valueOf(param.get("scheduledStartTime"));
String endTime = String.valueOf(param.get("scheduledEndTime")); String endTime = String.valueOf(param.get("scheduledEndTime"));
List<TrainPlanEntity> trainPlanList = getTrainPlanByUnitAndDate(unit, startTime, endTime); List<TrainPlanEntity> trainPlanList = getTrainPlanByUnitAndDate(unit, startTime, endTime);
// 处理字段信息 // 数据处理
trainPlanList.forEach(train -> { trainPlanList.forEach(train -> {
// 培训状态 // 培训状态
String status; String status;
@ -209,6 +210,9 @@ public class TrainPlanServiceImpl extends ServiceImpl<TrainPlanMapper, TrainPlan
// 是否考试 // 是否考试
String isTest = train.getIsTest().equals(SafeProductConstant.TRAIN_PLAN_HAS_TEST) ? "是" : "否"; String isTest = train.getIsTest().equals(SafeProductConstant.TRAIN_PLAN_HAS_TEST) ? "是" : "否";
train.setHasTest(isTest); train.setHasTest(isTest);
// 时间格式
train.setStartTime(DateUtil.format(train.getScheduledStartTime(), DateUtil.PATTERN_DATE));
train.setEndTime(DateUtil.format(train.getScheduledEndTime(), DateUtil.PATTERN_DATE));
}); });
// 设置响应头 // 设置响应头
// URLEncoder.encode防止中文乱码 // URLEncoder.encode防止中文乱码

21
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/TrainRecordServiceImpl.java

@ -1,9 +1,11 @@
package com.hnac.hzims.safeproduct.service.impl; package com.hnac.hzims.safeproduct.service.impl;
import cn.afterturn.easypoi.entity.ImageEntity;
import cn.hutool.core.date.DatePattern; import cn.hutool.core.date.DatePattern;
import com.alibaba.excel.util.CollectionUtils; import com.alibaba.excel.util.CollectionUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hnac.hzims.common.logs.utils.StringUtils;
import com.hnac.hzims.safeproduct.constants.SafeProductConstant; import com.hnac.hzims.safeproduct.constants.SafeProductConstant;
import com.hnac.hzims.safeproduct.dto.TrainRecordDTO; import com.hnac.hzims.safeproduct.dto.TrainRecordDTO;
import com.hnac.hzims.safeproduct.entity.TrainPlanEntity; import com.hnac.hzims.safeproduct.entity.TrainPlanEntity;
@ -23,6 +25,7 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -136,7 +139,8 @@ public class TrainRecordServiceImpl extends ServiceImpl<TrainRecordMapper, Train
@Override @Override
public void exportTrainRecordData(Long id, HttpServletResponse response) { public void exportTrainRecordData(Long id, HttpServletResponse response) {
TrainRecordDetailVO trainRecordDetailVO = this.getTrainRecordDetailById(id); TrainRecordDetailVO trainRecordDetailVO = this.getTrainRecordDetailById(id);
// 培训方式字段 // 数据处理
// 培训方式
String trainMethod = trainRecordDetailVO.getTrainMethod(); String trainMethod = trainRecordDetailVO.getTrainMethod();
if (trainMethod.equals(TrainMethodEnum.MIXED.getValue())) { if (trainMethod.equals(TrainMethodEnum.MIXED.getValue())) {
trainRecordDetailVO.setTrainMethod(TrainMethodEnum.MIXED.getDesc()); trainRecordDetailVO.setTrainMethod(TrainMethodEnum.MIXED.getDesc());
@ -145,6 +149,21 @@ public class TrainRecordServiceImpl extends ServiceImpl<TrainRecordMapper, Train
} else { } else {
trainRecordDetailVO.setTrainMethod(TrainMethodEnum.OFFLINE.getDesc()); trainRecordDetailVO.setTrainMethod(TrainMethodEnum.OFFLINE.getDesc());
} }
// 图片
if (StringUtils.isNotEmpty(trainRecordDetailVO.getImgPath())) {
String[] imgArr = trainRecordDetailVO.getImgPath().split(",");
List<ImageEntity> list = new ArrayList<>();
for (String img : imgArr) {
ImageEntity imageEntity = new ImageEntity(BaseUtil.imgToByte(savePath +
BaseUtil.downloadFileByUrl(img, savePath)), 180, 150);
list.add(imageEntity);
}
trainRecordDetailVO.setImages(list);
}
// 表头年月
String code = trainRecordDetailVO.getCode();
trainRecordDetailVO.setYear(code.substring(4, 8));
trainRecordDetailVO.setMonth(code.substring(8, 10));
Map<String, Object> params = BaseUtil.obj2Map(trainRecordDetailVO); Map<String, Object> params = BaseUtil.obj2Map(trainRecordDetailVO);
String templateFile = "template/培训记录表" + SafeProductConstant.DOCX_SUFFIX; String templateFile = "template/培训记录表" + SafeProductConstant.DOCX_SUFFIX;
String wordPath = savePath + "/培训记录表" + SafeProductConstant.DOCX_SUFFIX; String wordPath = savePath + "/培训记录表" + SafeProductConstant.DOCX_SUFFIX;

BIN
hzims-service/safeproduct/src/main/resources/template/培训记录表.docx

Binary file not shown.
Loading…
Cancel
Save