Browse Source

update: 培训管理

zhongwei
liwen 10 months ago
parent
commit
c51829690e
  1. 10
      hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/TrainRecordEntity.java
  2. 31
      hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/enums/TrainMethodEnum.java
  3. 55
      hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/TrainRecordDetailVO.java
  4. 14
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/TrainController.java
  5. 8
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/TrainRecordMapper.java
  6. 12
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/TrainRecordMapper.xml
  7. 13
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/ITrainRecordService.java
  8. 90
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/TrainRecordServiceImpl.java

10
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; 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 com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
@ -18,7 +16,6 @@ import java.util.Date;
*/ */
@Data @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@ExcelIgnoreUnannotated
@TableName("hzims_train_record") @TableName("hzims_train_record")
@ApiModel(value = "培训记录实体类") @ApiModel(value = "培训记录实体类")
public class TrainRecordEntity extends BaseEntity { public class TrainRecordEntity extends BaseEntity {
@ -28,34 +25,27 @@ public class TrainRecordEntity extends BaseEntity {
@Size(max = 50, message = "名称字段长度不能超过50") @Size(max = 50, message = "名称字段长度不能超过50")
@ApiModelProperty("培训记录名称") @ApiModelProperty("培训记录名称")
@ExcelProperty(value = "培训记录名称", index = 1)
private String trainRecordName; private String trainRecordName;
@Size(max = 50, message = "编码字段长度不能超过50") @Size(max = 50, message = "编码字段长度不能超过50")
@ApiModelProperty("编码") @ApiModelProperty("编码")
@ExcelProperty(value = "编码", index = 0)
private String code; private String code;
@Size(max = 5000, message = "培训学员字段长度超出限制范围") @Size(max = 5000, message = "培训学员字段长度超出限制范围")
@ApiModelProperty("培训学员") @ApiModelProperty("培训学员")
@ExcelProperty(value = "培训学员", index = 3)
private String peopleName; private String peopleName;
@ApiModelProperty("培训内容") @ApiModelProperty("培训内容")
@ExcelProperty(value = "培训内容", index = 2)
private String content; private String content;
@ApiModelProperty("实际培训开始时间") @ApiModelProperty("实际培训开始时间")
@ExcelProperty(value = "实际开始时间", index = 5)
private Date actualStartTime; private Date actualStartTime;
@ApiModelProperty("实际培训结束时间") @ApiModelProperty("实际培训结束时间")
@ExcelProperty(value = "实际结束时间", index = 6)
private Date actualEndTime; private Date actualEndTime;
@Size(max = 250, message = "培训评价字段长度不能超过250") @Size(max = 250, message = "培训评价字段长度不能超过250")
@ApiModelProperty("培训评价") @ApiModelProperty("培训评价")
@ExcelProperty(value = "培训评价", index = 4)
private String command; private String command;
@Size(max = 1000, message = "培训图片字段长度不能超过1000") @Size(max = 1000, message = "培训图片字段长度不能超过1000")

31
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;
}
}

55
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;
}

14
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.service.ITrainRecordService;
import com.hnac.hzims.safeproduct.vo.TestScoreVO; import com.hnac.hzims.safeproduct.vo.TestScoreVO;
import com.hnac.hzims.safeproduct.vo.TrainMonthVO; import com.hnac.hzims.safeproduct.vo.TrainMonthVO;
import com.hnac.hzims.safeproduct.vo.TrainRecordDetailVO;
import com.hnac.hzims.safeproduct.vo.TrainYearVO; import com.hnac.hzims.safeproduct.vo.TrainYearVO;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
@ -117,8 +118,8 @@ public class TrainController extends BladeController {
@GetMapping("/trainRecordDetail") @GetMapping("/trainRecordDetail")
@ApiOperation(value = "培训记录详情") @ApiOperation(value = "培训记录详情")
@ApiOperationSupport(order = 9) @ApiOperationSupport(order = 9)
public R<TrainRecordEntity> trainRecordDetail(@RequestParam Long id) { public R<TrainRecordDetailVO> trainRecordDetail(@RequestParam Long id) {
return R.data(trainRecordService.getById(id)); return R.data(trainRecordService.getTrainRecordDetailById(id));
} }
@GetMapping("/trainRecordPage") @GetMapping("/trainRecordPage")
@ -234,12 +235,9 @@ public class TrainController extends BladeController {
} }
@GetMapping("/exportTrainRecordData") @GetMapping("/exportTrainRecordData")
@ApiImplicitParams({ @ApiOperation(value = "培训记录表导出")
@ApiImplicitParam(name = "trainPlanId", value = "培训计划id", dataType = "query", paramType = "string")
})
@ApiOperation(value = "培训记录数据导出")
@ApiOperationSupport(order = 23) @ApiOperationSupport(order = 23)
public void exportTrainRecordData(@ApiIgnore @RequestParam Map<String, Object> param, HttpServletResponse response) { public void exportTrainRecordData(@RequestParam Long id, HttpServletResponse response) {
trainRecordService.exportTrainRecordData(param, response); trainRecordService.exportTrainRecordData(id, response);
} }
} }

8
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.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hnac.hzims.safeproduct.dto.TrainRecordDTO; import com.hnac.hzims.safeproduct.dto.TrainRecordDTO;
import com.hnac.hzims.safeproduct.entity.TrainRecordEntity; import com.hnac.hzims.safeproduct.entity.TrainRecordEntity;
import com.hnac.hzims.safeproduct.vo.TrainRecordDetailVO;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import java.util.List; import java.util.List;
@ -22,4 +23,11 @@ public interface TrainRecordMapper extends BaseMapper<TrainRecordEntity> {
* @return 培训记录名称列表 * @return 培训记录名称列表
*/ */
List<TrainRecordDTO> getTrainRecordNameList(String trainPlanId); List<TrainRecordDTO> getTrainRecordNameList(String trainPlanId);
/**
* 查询培训记录表详情
* @param id 培训记录id
* @return 培训记录表VO类
*/
TrainRecordDetailVO getTrainRecordDetailById(Long id);
} }

12
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/TrainRecordMapper.xml

@ -15,4 +15,16 @@
ORDER BY ORDER BY
create_time DESC create_time DESC
</select> </select>
<select id="getTrainRecordDetailById" resultType="com.hnac.hzims.safeproduct.vo.TrainRecordDetailVO">
SELECT
t1.code, t1.actual_start_time, t1.actual_end_time, t2.unit, t2.location, t2.train_method, t2.teacher, t2.lesson,
t1.people_name, t1.content, t1.img_path, t1.command, t1.file_path
FROM
hzims_train_record t1
LEFT JOIN hzims_train_plan t2 ON t1.train_plan_id = t2.id
WHERE
t1.is_deleted = 0
AND t1.id = #{id}
</select>
</mapper> </mapper>

13
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.baomidou.mybatisplus.extension.service.IService;
import com.hnac.hzims.safeproduct.dto.TrainRecordDTO; import com.hnac.hzims.safeproduct.dto.TrainRecordDTO;
import com.hnac.hzims.safeproduct.entity.TrainRecordEntity; import com.hnac.hzims.safeproduct.entity.TrainRecordEntity;
import com.hnac.hzims.safeproduct.vo.TrainRecordDetailVO;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* 培训记录服务类 * 培训记录服务类
@ -53,8 +53,15 @@ public interface ITrainRecordService extends IService<TrainRecordEntity> {
/** /**
* 培训记录数据导出 * 培训记录数据导出
* @param param 入参 * @param id 培训记录id
* @param response 响应类 * @param response 响应类
*/ */
void exportTrainRecordData(Map<String, Object> param, HttpServletResponse response); void exportTrainRecordData(Long id, HttpServletResponse response);
/**
* 查询培训记录表详情
* @param id 培训记录id
* @return 培训记录表VO类
*/
TrainRecordDetailVO getTrainRecordDetailById(Long id);
} }

90
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; 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);
}
} }

Loading…
Cancel
Save