diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/TrainPlanEntity.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/TrainPlanEntity.java index f6a5d4c..09fe232 100644 --- a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/TrainPlanEntity.java +++ b/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; } 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 f92ae58..24f2e2f 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,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") 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 70ec717..25fbe27 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 @@ -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) diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/jobs/TrainJob.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/jobs/TrainJob.java new file mode 100644 index 0000000..6ed0f71 --- /dev/null +++ b/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 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 list = trainPlanService.getWaitingTrainPlanInTimeRange(yesterday, today); + list.forEach(x -> { + x.setTrainStatus(TrainStatusEnum.UNFINISHED.getValue()); + }); + // 将状态置为未完成 + boolean flag = trainPlanService.updateBatchById(list); + return flag ? ReturnT.SUCCESS : ReturnT.FAIL; + } +} diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/ITrainPlanService.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/ITrainPlanService.java index 3c88648..bfb31ac 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/ITrainPlanService.java +++ b/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 { * @param response 响应类 */ void exportTrainPlanData(Map param, HttpServletResponse response); + + /** + * 查询时间范围内未开始的培训计划数据 + * @param startTime 开始时间 + * @param endTime 结束时间 + * @return 培训计划数据 + */ + List getWaitingTrainPlanInTimeRange(String startTime, String endTime); } diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/TestScoreServiceImpl.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/TestScoreServiceImpl.java index 2607bc8..ed346aa 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/TestScoreServiceImpl.java +++ b/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 ids = testScoreList.stream().map(TestScoreEntity::getId).collect(Collectors.toList()); + return this.removeByIds(ids); } /** diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/TestServiceImpl.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/TestServiceImpl.java index f9d1d66..8ab1dfa 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/TestServiceImpl.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/TestServiceImpl.java @@ -115,7 +115,8 @@ public class TestServiceImpl extends ServiceImpl impleme return true; } // 删除关联考试记录 - boolean remove = this.removeByIds(testList); + List ids = testList.stream().map(TestEntity::getId).collect(Collectors.toList()); + boolean remove = this.removeByIds(ids); // 若删除考试记录成功,删除关联考试成绩 if (remove) { for (TestEntity test : testList) { @@ -169,26 +170,30 @@ public class TestServiceImpl extends ServiceImpl impleme public boolean updateTest(TestEntity testEntity) { // 判断考试人员是否有变化 TestEntity oldTest = getTestByCode(testEntity.getCode()); - // 若不存在变化,更新考试记录 - if (oldTest.getPeopleName().equals(testEntity.getPeopleName())) { - return this.updateById(testEntity); - } - // 若存在变化,查询并删除关联考试成绩 - List testScoreList = testScoreService.getRelativeTestScore(testEntity.getId()); - List scoreIds = testScoreList.stream().map(TestScoreEntity::getId).collect(Collectors.toList()); - boolean removeByIds = testScoreService.removeByIds(scoreIds); - // 若删除成功,新增新的考试成绩数据 - if (removeByIds) { - String[] person = testEntity.getPeopleName().split(",|,"); - // 新增参考人员成绩数据 - List res = new ArrayList<>(); - for (String name : person) { - TestScoreEntity testScoreEntity = new TestScoreEntity(); - testScoreEntity.setTestId(testEntity.getId()); - testScoreEntity.setName(name); - res.add(testScoreEntity); + // 更新考试记录 + boolean update = this.updateById(testEntity); + if (update) { + // 若不存在人员变化,返回true + if (oldTest.getPeopleName().equals(testEntity.getPeopleName())) { + return true; + } + // 若存在变化,查询并删除关联考试成绩 + List testScoreList = testScoreService.getRelativeTestScore(testEntity.getId()); + List scoreIds = testScoreList.stream().map(TestScoreEntity::getId).collect(Collectors.toList()); + boolean removeByIds = testScoreService.removeByIds(scoreIds); + // 若删除成功,新增新的考试成绩数据 + if (removeByIds) { + String[] person = testEntity.getPeopleName().split(",|,"); + // 新增参考人员成绩数据 + List res = new ArrayList<>(); + for (String name : person) { + TestScoreEntity testScoreEntity = new TestScoreEntity(); + testScoreEntity.setTestId(testEntity.getId()); + testScoreEntity.setName(name); + res.add(testScoreEntity); + } + return testScoreService.saveBatch(res); } - return testScoreService.saveBatch(res); } return false; } diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/TrainPlanServiceImpl.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/TrainPlanServiceImpl.java index 6d9840a..142b75f 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/TrainPlanServiceImpl.java +++ b/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 rehearsalRecordList = getTrainPlanByUnitAndDate(unit, startTime, endTime); + List trainPlanList = getTrainPlanByUnitAndDate(unit, startTime, endTime); // 设置响应头 // URLEncoder.encode防止中文乱码 String fileName = URLEncoder.encode("培训计划表", "UTF-8"); @@ -185,7 +185,7 @@ public class TrainPlanServiceImpl extends ServiceImpl getWaitingTrainPlanInTimeRange(String startTime, String endTime) { + QueryWrapper 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 计划开始时间 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 ae3e85f..230a4d2 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 @@ -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 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 rehearsalRecordList = getTrainRecordByTrainPlanId(trainPlanId); + List trainRecordList = getTrainRecordByTrainPlanId(trainPlanId); // 设置响应头 // URLEncoder.encode防止中文乱码 String fileName = URLEncoder.encode("培训记录表", "UTF-8"); @@ -170,7 +172,7 @@ public class TrainRecordServiceImpl extends ServiceImpl