diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/TrainRecordEntity.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/TrainRecordEntity.java index b8728dc..ad42f8a 100644 --- a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/TrainRecordEntity.java +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/TrainRecordEntity.java @@ -1,7 +1,5 @@ package com.hnac.hzims.safeproduct.entity; -import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; -import com.alibaba.excel.annotation.ExcelProperty; import com.baomidou.mybatisplus.annotation.TableName; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; @@ -18,7 +16,6 @@ import java.util.Date; */ @Data @EqualsAndHashCode(callSuper = true) -@ExcelIgnoreUnannotated @TableName("hzims_train_record") @ApiModel(value = "培训记录实体类") public class TrainRecordEntity extends BaseEntity { @@ -28,34 +25,27 @@ public class TrainRecordEntity extends BaseEntity { @Size(max = 50, message = "名称字段长度不能超过50") @ApiModelProperty("培训记录名称") - @ExcelProperty(value = "培训记录名称", index = 1) private String trainRecordName; @Size(max = 50, message = "编码字段长度不能超过50") @ApiModelProperty("编码") - @ExcelProperty(value = "编码", index = 0) private String code; @Size(max = 5000, message = "培训学员字段长度超出限制范围") @ApiModelProperty("培训学员") - @ExcelProperty(value = "培训学员", index = 3) private String peopleName; @ApiModelProperty("培训内容") - @ExcelProperty(value = "培训内容", index = 2) private String content; @ApiModelProperty("实际培训开始时间") - @ExcelProperty(value = "实际开始时间", index = 5) private Date actualStartTime; @ApiModelProperty("实际培训结束时间") - @ExcelProperty(value = "实际结束时间", index = 6) private Date actualEndTime; @Size(max = 250, message = "培训评价字段长度不能超过250") @ApiModelProperty("培训评价") - @ExcelProperty(value = "培训评价", index = 4) private String command; @Size(max = 1000, message = "培训图片字段长度不能超过1000") diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/enums/TrainMethodEnum.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/enums/TrainMethodEnum.java new file mode 100644 index 0000000..843244d --- /dev/null +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/enums/TrainMethodEnum.java @@ -0,0 +1,31 @@ +package com.hnac.hzims.safeproduct.enums; + +/** + * 培训方式枚举类 + * + * @author liwen + * @date 2024-01-15 + */ +public enum TrainMethodEnum { + + ONLINE("ONLINE", "线上"), + OFFLINE("OFFLINE", "线下"), + MIXED("MIXED", "线上+线下"); + + private final String value; + + private final String desc; + + TrainMethodEnum(String value, String desc) { + this.value = value; + this.desc = desc; + } + + public String getValue() { + return value; + } + + public String getDesc() { + return desc; + } +} diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/TrainRecordDetailVO.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/TrainRecordDetailVO.java new file mode 100644 index 0000000..ecf6b78 --- /dev/null +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/TrainRecordDetailVO.java @@ -0,0 +1,55 @@ +package com.hnac.hzims.safeproduct.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.Date; + +/** + * @author liwen + * @date 2024-01-15 + */ +@Data +@ApiModel(value = "培训记录表VO类") +public class TrainRecordDetailVO { + + @ApiModelProperty("编码") + private String code; + + @ApiModelProperty("实际培训开始时间") + private Date actualStartTime; + + @ApiModelProperty("实际培训结束时间") + private Date actualEndTime; + + @ApiModelProperty("单位") + private String unit; + + @ApiModelProperty("培训地点") + private String location; + + @ApiModelProperty("培训方式") + private String trainMethod; + + @ApiModelProperty("培训讲师") + private String teacher; + + @ApiModelProperty("培训课程") + private String lesson; + + @ApiModelProperty("培训学员") + private String peopleName; + + @ApiModelProperty("培训内容") + private String content; + + @ApiModelProperty("培训评价") + private String command; + + @ApiModelProperty("培训图片") + private String imgPath; + + @ApiModelProperty("培训附件") + private String filePath; +} diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/TrainController.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/TrainController.java index 8cf7a62..0cd49d3 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/TrainController.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/TrainController.java @@ -15,6 +15,7 @@ import com.hnac.hzims.safeproduct.service.ITrainPlanService; import com.hnac.hzims.safeproduct.service.ITrainRecordService; import com.hnac.hzims.safeproduct.vo.TestScoreVO; import com.hnac.hzims.safeproduct.vo.TrainMonthVO; +import com.hnac.hzims.safeproduct.vo.TrainRecordDetailVO; import com.hnac.hzims.safeproduct.vo.TrainYearVO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; @@ -117,8 +118,8 @@ public class TrainController extends BladeController { @GetMapping("/trainRecordDetail") @ApiOperation(value = "培训记录详情") @ApiOperationSupport(order = 9) - public R trainRecordDetail(@RequestParam Long id) { - return R.data(trainRecordService.getById(id)); + public R trainRecordDetail(@RequestParam Long id) { + return R.data(trainRecordService.getTrainRecordDetailById(id)); } @GetMapping("/trainRecordPage") @@ -234,12 +235,9 @@ public class TrainController extends BladeController { } @GetMapping("/exportTrainRecordData") - @ApiImplicitParams({ - @ApiImplicitParam(name = "trainPlanId", value = "培训计划id", dataType = "query", paramType = "string") - }) - @ApiOperation(value = "培训记录数据导出") + @ApiOperation(value = "培训记录表导出") @ApiOperationSupport(order = 23) - public void exportTrainRecordData(@ApiIgnore @RequestParam Map param, HttpServletResponse response) { - trainRecordService.exportTrainRecordData(param, response); + public void exportTrainRecordData(@RequestParam Long id, HttpServletResponse response) { + trainRecordService.exportTrainRecordData(id, response); } } diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/TrainRecordMapper.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/TrainRecordMapper.java index 2e170c9..a268688 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/TrainRecordMapper.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/TrainRecordMapper.java @@ -3,6 +3,7 @@ package com.hnac.hzims.safeproduct.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.hnac.hzims.safeproduct.dto.TrainRecordDTO; import com.hnac.hzims.safeproduct.entity.TrainRecordEntity; +import com.hnac.hzims.safeproduct.vo.TrainRecordDetailVO; import org.apache.ibatis.annotations.Mapper; import java.util.List; @@ -22,4 +23,11 @@ public interface TrainRecordMapper extends BaseMapper { * @return 培训记录名称列表 */ List getTrainRecordNameList(String trainPlanId); + + /** + * 查询培训记录表详情 + * @param id 培训记录id + * @return 培训记录表VO类 + */ + TrainRecordDetailVO getTrainRecordDetailById(Long id); } diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/TrainRecordMapper.xml b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/TrainRecordMapper.xml index 01f1e58..e4f15af 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/TrainRecordMapper.xml +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/TrainRecordMapper.xml @@ -15,4 +15,16 @@ ORDER BY create_time DESC + + \ No newline at end of file diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/ITrainRecordService.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/ITrainRecordService.java index bd89033..13d443a 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/ITrainRecordService.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/ITrainRecordService.java @@ -3,10 +3,10 @@ package com.hnac.hzims.safeproduct.service; import com.baomidou.mybatisplus.extension.service.IService; import com.hnac.hzims.safeproduct.dto.TrainRecordDTO; import com.hnac.hzims.safeproduct.entity.TrainRecordEntity; +import com.hnac.hzims.safeproduct.vo.TrainRecordDetailVO; import javax.servlet.http.HttpServletResponse; import java.util.List; -import java.util.Map; /** * 培训记录服务类 @@ -53,8 +53,15 @@ public interface ITrainRecordService extends IService { /** * 培训记录数据导出 - * @param param 入参 + * @param id 培训记录id * @param response 响应类 */ - void exportTrainRecordData(Map param, HttpServletResponse response); + void exportTrainRecordData(Long id, HttpServletResponse response); + + /** + * 查询培训记录表详情 + * @param id 培训记录id + * @return 培训记录表VO类 + */ + TrainRecordDetailVO getTrainRecordDetailById(Long id); } diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/TrainRecordServiceImpl.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/TrainRecordServiceImpl.java index c2312e4..f791960 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/TrainRecordServiceImpl.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/TrainRecordServiceImpl.java @@ -1,35 +1,28 @@ package com.hnac.hzims.safeproduct.service.impl; import cn.hutool.core.date.DatePattern; -import com.alibaba.excel.EasyExcel; -import com.alibaba.excel.ExcelWriter; -import com.alibaba.excel.converters.longconverter.LongStringConverter; import com.alibaba.excel.util.CollectionUtils; -import com.alibaba.excel.write.metadata.WriteSheet; -import com.alibaba.excel.write.style.column.SimpleColumnWidthStyleStrategy; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.hnac.hzims.safeproduct.constants.SafeProductConstant; import com.hnac.hzims.safeproduct.dto.TrainRecordDTO; import com.hnac.hzims.safeproduct.entity.TrainPlanEntity; import com.hnac.hzims.safeproduct.entity.TrainRecordEntity; +import com.hnac.hzims.safeproduct.enums.TrainMethodEnum; import com.hnac.hzims.safeproduct.enums.TrainStatusEnum; import com.hnac.hzims.safeproduct.mapper.TrainPlanMapper; import com.hnac.hzims.safeproduct.mapper.TrainRecordMapper; import com.hnac.hzims.safeproduct.service.ITestService; import com.hnac.hzims.safeproduct.service.ITrainRecordService; import com.hnac.hzims.safeproduct.utils.BaseUtil; -import org.springblade.core.log.exception.ServiceException; +import com.hnac.hzims.safeproduct.vo.TrainRecordDetailVO; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; -import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.net.URLEncoder; import java.util.Date; import java.util.List; import java.util.Map; @@ -50,6 +43,9 @@ public class TrainRecordServiceImpl extends ServiceImpl param, HttpServletResponse response) { - ServletOutputStream outputStream = null; - try { - outputStream = response.getOutputStream(); - String trainPlanId = String.valueOf(param.get("trainPlanId")); - List trainRecordList = getTrainRecordByTrainPlanId(trainPlanId); - // 设置响应头 - // URLEncoder.encode防止中文乱码 - String fileName = URLEncoder.encode("培训记录表", "UTF-8"); - response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx"); - response.setContentType("application/vnd.ms-excel"); - response.setCharacterEncoding("UTF-8"); - // ExcelWriter初始化 - ExcelWriter excelWriter = EasyExcel - .write(response.getOutputStream()) - .autoCloseStream(Boolean.TRUE) - .registerConverter(new LongStringConverter()) - .registerWriteHandler(new SimpleColumnWidthStyleStrategy(25)) - .build(); - WriteSheet writeSheet = EasyExcel.writerSheet(1, "培训记录表").head(TrainRecordEntity.class) - .build(); - excelWriter.write(trainRecordList, writeSheet); - excelWriter.finish(); - } catch (Exception e) { - // 重置response - response.reset(); - response.setContentType("application/json"); - response.setCharacterEncoding("utf-8"); - throw new ServiceException("培训记录数据导出异常: " + e.getMessage()); - } finally { - if (outputStream != null) { - try { - outputStream.close(); - } catch (IOException e) { - log.error("培训记录导出响应头输出流关闭异常: " + e.getMessage()); - } - } + public void exportTrainRecordData(Long id, HttpServletResponse response) { + TrainRecordDetailVO trainRecordDetailVO = this.getTrainRecordDetailById(id); + // 培训方式字段 + String trainMethod = trainRecordDetailVO.getTrainMethod(); + if (trainMethod.equals(TrainMethodEnum.MIXED.getValue())) { + trainRecordDetailVO.setTrainMethod(TrainMethodEnum.MIXED.getDesc()); + } else if (trainMethod.equals(TrainMethodEnum.ONLINE.getValue())) { + trainRecordDetailVO.setTrainMethod(TrainMethodEnum.ONLINE.getDesc()); + } else { + trainRecordDetailVO.setTrainMethod(TrainMethodEnum.OFFLINE.getDesc()); } + Map params = BaseUtil.obj2Map(trainRecordDetailVO); + String templateFile = "template/培训记录表" + SafeProductConstant.DOCX_SUFFIX; + String wordPath = savePath + "/培训记录表" + SafeProductConstant.DOCX_SUFFIX; + String pdfPath = savePath + "/培训记录表" + SafeProductConstant.PDF_SUFFIX; + BaseUtil.exportDocument(templateFile, params, wordPath, pdfPath, response); + } + + /** + * 查询培训记录表详情 + */ + @Override + public TrainRecordDetailVO getTrainRecordDetailById(Long id) { + return baseMapper.getTrainRecordDetailById(id); } /** @@ -202,18 +184,4 @@ public class TrainRecordServiceImpl extends ServiceImpl getTrainRecordByTrainPlanId(String trainPlanId) { - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - if (!trainPlanId.equals("null")) { - queryWrapper.ge(TrainRecordEntity::getTrainPlanId, trainPlanId); - } - queryWrapper.orderByDesc(TrainRecordEntity::getCreateTime); - return this.list(queryWrapper); - } }