Browse Source

update: 更新培训管理部分逻辑

zhongwei
liwen 11 months ago
parent
commit
8865ec63b5
  1. 11
      hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/TrainPlanEntity.java
  2. 10
      hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/TrainRecordEntity.java
  3. 3
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/TrainController.java
  4. 43
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/jobs/TrainJob.java
  5. 9
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/ITrainPlanService.java
  6. 4
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/TestScoreServiceImpl.java
  7. 11
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/TestServiceImpl.java
  8. 20
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/TrainPlanServiceImpl.java
  9. 8
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/TrainRecordServiceImpl.java

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

@ -1,5 +1,7 @@
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;
@ -17,6 +19,7 @@ import java.util.Date;
*/
@Data
@EqualsAndHashCode(callSuper = true)
@ExcelIgnoreUnannotated
@TableName("hzims_train_plan")
@ApiModel(value = "培训计划实体类")
public class TrainPlanEntity extends BaseEntity {
@ -24,24 +27,29 @@ public class TrainPlanEntity extends BaseEntity {
@NotNull
@Size(max = 50, message = "单位字段长度不能超过50")
@ApiModelProperty("单位")
@ExcelProperty(value = "单位", index = 0)
private String unit;
@NotNull
@ApiModelProperty("计划培训开始时间")
@ExcelProperty(value = "计划开始时间", index = 6)
private Date scheduledStartTime;
@NotNull
@ApiModelProperty("计划培训结束时间")
@ExcelProperty(value = "计划结束时间", index = 7)
private Date scheduledEndTime;
@NotNull
@Size(max = 255, message = "单位字段长度不能超过255")
@ApiModelProperty("培训课程")
@ExcelProperty(value = "培训课程", index = 1)
private String lesson;
@NotNull
@Size(max = 255, message = "培训地点字段长度不能超过255")
@ApiModelProperty("培训地点")
@ExcelProperty(value = "培训地点", index = 2)
private String location;
@Size(max = 20, message = "培训方式字段长度不能超过20")
@ -51,14 +59,17 @@ public class TrainPlanEntity extends BaseEntity {
@NotNull
@Size(max = 20, message = "培训讲师字段长度不能超过20")
@ApiModelProperty("培训讲师")
@ExcelProperty(value = "培训讲师", index = 4)
private String teacher;
@NotNull
@Size(max = 20, message = "培训状态字段长度不能超过20")
@ApiModelProperty("培训状态")
@ExcelProperty(value = "培训状态", index = 3)
private String trainStatus;
@NotNull
@ApiModelProperty("关联考试:0-否,1-是")
@ExcelProperty(value = "是否考试", index = 5)
private Integer isTest;
}

10
hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/TrainRecordEntity.java

@ -1,5 +1,7 @@
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;
@ -16,6 +18,7 @@ import java.util.Date;
*/
@Data
@EqualsAndHashCode(callSuper = true)
@ExcelIgnoreUnannotated
@TableName("hzims_train_record")
@ApiModel(value = "培训记录实体类")
public class TrainRecordEntity extends BaseEntity {
@ -25,28 +28,35 @@ 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;
@Size(max = 5000, message = "培训内容字段长度超出限制范围")
@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")

3
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/TrainController.java

@ -250,8 +250,7 @@ public class TrainController extends BladeController {
@GetMapping("/exportTrainRecordData")
@ApiImplicitParams({
@ApiImplicitParam(name = "scheduledStartTime", value = "计划开始时间", dataType = "query", paramType = "string"),
@ApiImplicitParam(name = "scheduledEndTime", value = "计划结束时间", dataType = "query", paramType = "string")
@ApiImplicitParam(name = "trainPlanId", value = "培训计划id", dataType = "query", paramType = "string")
})
@ApiOperation(value = "培训记录数据导出")
@ApiOperationSupport(order = 24)

43
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/jobs/TrainJob.java

@ -0,0 +1,43 @@
package com.hnac.hzims.safeproduct.jobs;
import com.hnac.hzims.safeproduct.entity.TrainPlanEntity;
import com.hnac.hzims.safeproduct.enums.TrainStatusEnum;
import com.hnac.hzims.safeproduct.service.ITrainPlanService;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.springblade.core.tool.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Date;
import java.util.List;
/**
* 演练模块定时任务
*
* @author liwen
* @date 2023-12-27
*/
@Component
public class TrainJob {
@Autowired
ITrainPlanService trainPlanService;
@XxlJob("autoChangeTrainPlanStatus")
public ReturnT<String> autoChangeTrainPlanStatus(String param) {
// 获取时间范围
Date current = DateUtil.now();
Date before = DateUtil.minusDays(current, 1);
String today = DateUtil.format(current, "yyyy-mm-dd hh:MM:ss");
String yesterday = DateUtil.format(before, "yyyy-mm-dd hh:MM:ss");
// 查询前一天的超时未完成培训计划
List<TrainPlanEntity> list = trainPlanService.getWaitingTrainPlanInTimeRange(yesterday, today);
list.forEach(x -> {
x.setTrainStatus(TrainStatusEnum.UNFINISHED.getValue());
});
// 将状态置为未完成
boolean flag = trainPlanService.updateBatchById(list);
return flag ? ReturnT.SUCCESS : ReturnT.FAIL;
}
}

9
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/ITrainPlanService.java

@ -8,6 +8,7 @@ import com.hnac.hzims.safeproduct.vo.TrainYearVO;
import org.springblade.core.mp.support.Query;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;
/**
@ -47,4 +48,12 @@ public interface ITrainPlanService extends IService<TrainPlanEntity> {
* @param response 响应类
*/
void exportTrainPlanData(Map<String, Object> param, HttpServletResponse response);
/**
* 查询时间范围内未开始的培训计划数据
* @param startTime 开始时间
* @param endTime 结束时间
* @return 培训计划数据
*/
List<TrainPlanEntity> getWaitingTrainPlanInTimeRange(String startTime, String endTime);
}

4
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/TestScoreServiceImpl.java

@ -13,6 +13,7 @@ import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* 考试成绩服务实现类
@ -61,7 +62,8 @@ public class TestScoreServiceImpl extends ServiceImpl<TestScoreMapper, TestScore
return true;
}
// 删除关联考试成绩
return this.removeByIds(testScoreList);
List<Long> ids = testScoreList.stream().map(TestScoreEntity::getId).collect(Collectors.toList());
return this.removeByIds(ids);
}
/**

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

@ -115,7 +115,8 @@ public class TestServiceImpl extends ServiceImpl<TestMapper, TestEntity> impleme
return true;
}
// 删除关联考试记录
boolean remove = this.removeByIds(testList);
List<Long> ids = testList.stream().map(TestEntity::getId).collect(Collectors.toList());
boolean remove = this.removeByIds(ids);
// 若删除考试记录成功,删除关联考试成绩
if (remove) {
for (TestEntity test : testList) {
@ -169,9 +170,12 @@ public class TestServiceImpl extends ServiceImpl<TestMapper, TestEntity> impleme
public boolean updateTest(TestEntity testEntity) {
// 判断考试人员是否有变化
TestEntity oldTest = getTestByCode(testEntity.getCode());
// 若不存在变化,更新考试记录
// 更新考试记录
boolean update = this.updateById(testEntity);
if (update) {
// 若不存在人员变化,返回true
if (oldTest.getPeopleName().equals(testEntity.getPeopleName())) {
return this.updateById(testEntity);
return true;
}
// 若存在变化,查询并删除关联考试成绩
List<TestScoreEntity> testScoreList = testScoreService.getRelativeTestScore(testEntity.getId());
@ -190,6 +194,7 @@ public class TestServiceImpl extends ServiceImpl<TestMapper, TestEntity> impleme
}
return testScoreService.saveBatch(res);
}
}
return false;
}

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

@ -6,13 +6,13 @@ import com.alibaba.excel.converters.longconverter.LongStringConverter;
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.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hnac.hzims.safeproduct.dto.AnalysisYearDTO;
import com.hnac.hzims.safeproduct.entity.RehearsalRecordEntity;
import com.hnac.hzims.safeproduct.entity.TrainPlanEntity;
import com.hnac.hzims.safeproduct.entity.TrainRecordEntity;
import com.hnac.hzims.safeproduct.enums.TrainStatusEnum;
import com.hnac.hzims.safeproduct.mapper.TrainPlanMapper;
import com.hnac.hzims.safeproduct.service.ITestService;
import com.hnac.hzims.safeproduct.service.ITrainPlanService;
@ -169,7 +169,7 @@ public class TrainPlanServiceImpl extends ServiceImpl<TrainPlanMapper, TrainPlan
String unit = String.valueOf(param.get("unit"));
String startTime = String.valueOf(param.get("scheduledStartTime"));
String endTime = String.valueOf(param.get("scheduledEndTime"));
List<TrainPlanEntity> rehearsalRecordList = getTrainPlanByUnitAndDate(unit, startTime, endTime);
List<TrainPlanEntity> trainPlanList = getTrainPlanByUnitAndDate(unit, startTime, endTime);
// 设置响应头
// URLEncoder.encode防止中文乱码
String fileName = URLEncoder.encode("培训计划表", "UTF-8");
@ -185,7 +185,7 @@ public class TrainPlanServiceImpl extends ServiceImpl<TrainPlanMapper, TrainPlan
.build();
WriteSheet writeSheet = EasyExcel.writerSheet(1, "培训计划表").head(TrainPlanEntity.class)
.build();
excelWriter.write(rehearsalRecordList, writeSheet);
excelWriter.write(trainPlanList, writeSheet);
excelWriter.finish();
} catch (Exception e) {
// 重置response
@ -205,6 +205,18 @@ public class TrainPlanServiceImpl extends ServiceImpl<TrainPlanMapper, TrainPlan
}
/**
* 查询时间范围内未开始的培训计划数据
*/
@Override
public List<TrainPlanEntity> getWaitingTrainPlanInTimeRange(String startTime, String endTime) {
QueryWrapper<TrainPlanEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(TrainPlanEntity::getTrainStatus, TrainStatusEnum.WAITING.getValue())
.ge(TrainPlanEntity::getScheduledEndTime, startTime)
.lt(TrainPlanEntity::getScheduledEndTime, endTime);
return this.list(queryWrapper);
}
/**
* 根据单位和计划时间查询培训计划数据
* @param unit 单位
* @param startTime 计划开始时间

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

@ -33,6 +33,7 @@ import java.net.URLEncoder;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 培训记录服务实现类
@ -99,7 +100,8 @@ public class TrainRecordServiceImpl extends ServiceImpl<TrainRecordMapper, Train
return true;
}
// 删除关联培训记录
boolean remove = this.removeByIds(trainRecordList);
List<Long> ids = trainRecordList.stream().map(TrainRecordEntity::getId).collect(Collectors.toList());
boolean remove = this.removeByIds(ids);
// 若删除培训记录成功,则删除关联考试记录
if (remove) {
for (TrainRecordEntity trainRecord : trainRecordList) {
@ -154,7 +156,7 @@ public class TrainRecordServiceImpl extends ServiceImpl<TrainRecordMapper, Train
try {
outputStream = response.getOutputStream();
String trainPlanId = String.valueOf(param.get("trainPlanId"));
List<TrainRecordEntity> rehearsalRecordList = getTrainRecordByTrainPlanId(trainPlanId);
List<TrainRecordEntity> trainRecordList = getTrainRecordByTrainPlanId(trainPlanId);
// 设置响应头
// URLEncoder.encode防止中文乱码
String fileName = URLEncoder.encode("培训记录表", "UTF-8");
@ -170,7 +172,7 @@ public class TrainRecordServiceImpl extends ServiceImpl<TrainRecordMapper, Train
.build();
WriteSheet writeSheet = EasyExcel.writerSheet(1, "培训记录表").head(TrainRecordEntity.class)
.build();
excelWriter.write(rehearsalRecordList, writeSheet);
excelWriter.write(trainRecordList, writeSheet);
excelWriter.finish();
} catch (Exception e) {
// 重置response

Loading…
Cancel
Save