|
|
@ -1,35 +1,28 @@ |
|
|
|
package com.hnac.hzims.safeproduct.service.impl; |
|
|
|
package com.hnac.hzims.safeproduct.service.impl; |
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.date.DatePattern; |
|
|
|
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.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.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
|
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; |
|
|
|
import com.hnac.hzims.safeproduct.entity.TrainRecordEntity; |
|
|
|
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.enums.TrainStatusEnum; |
|
|
|
import com.hnac.hzims.safeproduct.mapper.TrainPlanMapper; |
|
|
|
import com.hnac.hzims.safeproduct.mapper.TrainPlanMapper; |
|
|
|
import com.hnac.hzims.safeproduct.mapper.TrainRecordMapper; |
|
|
|
import com.hnac.hzims.safeproduct.mapper.TrainRecordMapper; |
|
|
|
import com.hnac.hzims.safeproduct.service.ITestService; |
|
|
|
import com.hnac.hzims.safeproduct.service.ITestService; |
|
|
|
import com.hnac.hzims.safeproduct.service.ITrainRecordService; |
|
|
|
import com.hnac.hzims.safeproduct.service.ITrainRecordService; |
|
|
|
import com.hnac.hzims.safeproduct.utils.BaseUtil; |
|
|
|
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.Autowired; |
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import javax.annotation.Resource; |
|
|
|
import javax.servlet.ServletOutputStream; |
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import java.io.IOException; |
|
|
|
|
|
|
|
import java.net.URLEncoder; |
|
|
|
|
|
|
|
import java.util.Date; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Map; |
|
|
@ -50,6 +43,9 @@ public class TrainRecordServiceImpl extends ServiceImpl<TrainRecordMapper, Train |
|
|
|
@Resource |
|
|
|
@Resource |
|
|
|
TrainPlanMapper trainPlanMapper; |
|
|
|
TrainPlanMapper trainPlanMapper; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Value("${hzims.train.savePath}") |
|
|
|
|
|
|
|
private String savePath; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 新增培训记录 |
|
|
|
* 新增培训记录 |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -138,44 +134,30 @@ public class TrainRecordServiceImpl extends ServiceImpl<TrainRecordMapper, Train |
|
|
|
* 培训记录数据导出 |
|
|
|
* 培训记录数据导出 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void exportTrainRecordData(Map<String, Object> param, HttpServletResponse response) { |
|
|
|
public void exportTrainRecordData(Long id, HttpServletResponse response) { |
|
|
|
ServletOutputStream outputStream = null; |
|
|
|
TrainRecordDetailVO trainRecordDetailVO = this.getTrainRecordDetailById(id); |
|
|
|
try { |
|
|
|
// 培训方式字段
|
|
|
|
outputStream = response.getOutputStream(); |
|
|
|
String trainMethod = trainRecordDetailVO.getTrainMethod(); |
|
|
|
String trainPlanId = String.valueOf(param.get("trainPlanId")); |
|
|
|
if (trainMethod.equals(TrainMethodEnum.MIXED.getValue())) { |
|
|
|
List<TrainRecordEntity> trainRecordList = getTrainRecordByTrainPlanId(trainPlanId); |
|
|
|
trainRecordDetailVO.setTrainMethod(TrainMethodEnum.MIXED.getDesc()); |
|
|
|
// 设置响应头
|
|
|
|
} else if (trainMethod.equals(TrainMethodEnum.ONLINE.getValue())) { |
|
|
|
// URLEncoder.encode防止中文乱码
|
|
|
|
trainRecordDetailVO.setTrainMethod(TrainMethodEnum.ONLINE.getDesc()); |
|
|
|
String fileName = URLEncoder.encode("培训记录表", "UTF-8"); |
|
|
|
} else { |
|
|
|
response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx"); |
|
|
|
trainRecordDetailVO.setTrainMethod(TrainMethodEnum.OFFLINE.getDesc()); |
|
|
|
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()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
Map<String, Object> 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<TrainRecordMapper, Train |
|
|
|
.orderByDesc(TrainRecordEntity::getCode); |
|
|
|
.orderByDesc(TrainRecordEntity::getCode); |
|
|
|
return this.list(queryWrapper); |
|
|
|
return this.list(queryWrapper); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 根据培训计划id查询培训记录数据 |
|
|
|
|
|
|
|
* @param trainPlanId 培训计划id |
|
|
|
|
|
|
|
* @return 培训记录列表 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public List<TrainRecordEntity> getTrainRecordByTrainPlanId(String trainPlanId) { |
|
|
|
|
|
|
|
LambdaQueryWrapper<TrainRecordEntity> queryWrapper = new LambdaQueryWrapper<>(); |
|
|
|
|
|
|
|
if (!trainPlanId.equals("null")) { |
|
|
|
|
|
|
|
queryWrapper.ge(TrainRecordEntity::getTrainPlanId, trainPlanId); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
queryWrapper.orderByDesc(TrainRecordEntity::getCreateTime); |
|
|
|
|
|
|
|
return this.list(queryWrapper); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|