Browse Source

Merge remote-tracking branch 'origin/master'

zhongwei
ty 11 months ago
parent
commit
65414f9564
  1. 3
      hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/constants/SafeProductConstant.java
  2. 11
      hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/TrainPlanEntity.java
  3. 10
      hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/TrainRecordEntity.java
  4. 31
      hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/enums/TrainStatusEnum.java
  5. 3
      hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/TestScoreVO.java
  6. 6
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/TrainController.java
  7. 43
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/jobs/TrainJob.java
  8. 2
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/TestScoreMapper.xml
  9. 12
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/TrainPlanMapper.xml
  10. 9
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/ITrainPlanService.java
  11. 5
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/TestScoreServiceImpl.java
  12. 16
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/TestServiceImpl.java
  13. 20
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/TrainPlanServiceImpl.java
  14. 26
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/TrainRecordServiceImpl.java

3
hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/constants/SafeProductConstant.java

@ -8,6 +8,9 @@ package com.hnac.hzims.safeproduct.constants;
*/ */
public interface SafeProductConstant { public interface SafeProductConstant {
int SUCCESS = 1;
int FAILURE = 0;
int TRAIN_PLAN_HAS_TEST = 1; int TRAIN_PLAN_HAS_TEST = 1;
int TRAIN_PLAN_HAS_NO_TEST = 0; int TRAIN_PLAN_HAS_NO_TEST = 0;
} }

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

@ -0,0 +1,31 @@
package com.hnac.hzims.safeproduct.enums;
/**
* 培训计划状态枚举类
*
* @author liwen
* @date 2023-12-27
*/
public enum TrainStatusEnum {
WAITING("WAITING", "未开始"),
UNFINISHED("UNFINISHED", "未完成"),
FINISHED("FINISHED", "已完成");
private final String value;
private final String desc;
TrainStatusEnum(String value, String desc) {
this.value = value;
this.desc = desc;
}
public String getValue() {
return value;
}
public String getDesc() {
return desc;
}
}

3
hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/TestScoreVO.java

@ -12,6 +12,9 @@ import lombok.Data;
@ApiModel(value = "考试成绩VO类") @ApiModel(value = "考试成绩VO类")
public class TestScoreVO { public class TestScoreVO {
@ApiModelProperty("考试成绩id")
private Long id;
@ApiModelProperty("姓名") @ApiModelProperty("姓名")
private String name; private String name;

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

@ -175,6 +175,7 @@ public class TrainController extends BladeController {
@GetMapping("/testPage") @GetMapping("/testPage")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "trainPlanId", value = "培训计划id", dataType = "query", paramType = "string"),
@ApiImplicitParam(name = "trainRecordId", value = "培训记录id", dataType = "query", paramType = "string") @ApiImplicitParam(name = "trainRecordId", value = "培训记录id", dataType = "query", paramType = "string")
}) })
@ApiOperation(value = "考试记录分页") @ApiOperation(value = "考试记录分页")
@ -203,7 +204,7 @@ public class TrainController extends BladeController {
@PostMapping("/updateBatchScore") @PostMapping("/updateBatchScore")
@ApiOperation(value = "批量填写分数") @ApiOperation(value = "批量填写分数")
@ApiOperationSupport(order = 19) @ApiOperationSupport(order = 19)
public R updateBatchScore(TestScoreDTO testScoreDTO) { public R updateBatchScore(@RequestBody TestScoreDTO testScoreDTO) {
return R.status(testScoreService.updateBatchScore(testScoreDTO)); return R.status(testScoreService.updateBatchScore(testScoreDTO));
} }
@ -249,8 +250,7 @@ public class TrainController extends BladeController {
@GetMapping("/exportTrainRecordData") @GetMapping("/exportTrainRecordData")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "scheduledStartTime", value = "计划开始时间", dataType = "query", paramType = "string"), @ApiImplicitParam(name = "trainPlanId", value = "培训计划id", dataType = "query", paramType = "string")
@ApiImplicitParam(name = "scheduledEndTime", value = "计划结束时间", dataType = "query", paramType = "string")
}) })
@ApiOperation(value = "培训记录数据导出") @ApiOperation(value = "培训记录数据导出")
@ApiOperationSupport(order = 24) @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;
}
}

2
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/TestScoreMapper.xml

@ -4,7 +4,7 @@
<select id="testScoreList" resultType="com.hnac.hzims.safeproduct.vo.TestScoreVO"> <select id="testScoreList" resultType="com.hnac.hzims.safeproduct.vo.TestScoreVO">
SELECT SELECT
name, score id, name, score
FROM FROM
hzims_test_score hzims_test_score
WHERE WHERE

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

@ -9,7 +9,7 @@
hzims_train_plan hzims_train_plan
WHERE WHERE
is_deleted = 0 is_deleted = 0
AND scheduled_train_time like concat('%', #{month}, '%') AND scheduled_end_time like concat('%', #{month}, '%')
GROUP BY GROUP BY
unit unit
ORDER BY ORDER BY
@ -23,7 +23,7 @@
hzims_train_plan hzims_train_plan
WHERE WHERE
is_deleted = 0 is_deleted = 0
AND scheduled_train_time like concat('%', #{month}, '%') AND scheduled_end_time like concat('%', #{month}, '%')
AND train_status = 'FINISHED' AND train_status = 'FINISHED'
GROUP BY GROUP BY
unit unit
@ -38,26 +38,26 @@
hzims_train_plan hzims_train_plan
WHERE WHERE
is_deleted = 0 is_deleted = 0
AND actual_train_time like concat('%', #{year}, '%') AND scheduled_end_time like concat('%', #{year}, '%')
ORDER BY ORDER BY
unit unit
</select> </select>
<select id="selectFinishedDataByUnit" resultType="com.hnac.hzims.safeproduct.dto.AnalysisYearDTO"> <select id="selectFinishedDataByUnit" resultType="com.hnac.hzims.safeproduct.dto.AnalysisYearDTO">
SELECT SELECT
unit, DATE_FORMAT(actual_train_time, '%m') as dateTime, count(1) as finished_num unit, DATE_FORMAT(scheduled_end_time, '%m') as dateTime, count(1) as finished_num
FROM FROM
hzims_train_plan hzims_train_plan
WHERE WHERE
is_deleted = 0 is_deleted = 0
AND actual_train_time like concat('%', #{year}, '%') AND scheduled_end_time like concat('%', #{year}, '%')
AND train_status = 'FINISHED' AND train_status = 'FINISHED'
AND unit in AND unit in
<foreach collection="unitList" item="unit" open="(" close=")" separator=","> <foreach collection="unitList" item="unit" open="(" close=")" separator=",">
#{unit} #{unit}
</foreach> </foreach>
GROUP BY GROUP BY
unit, DATE_FORMAT(actual_train_time, '%m') unit, DATE_FORMAT(scheduled_end_time, '%m')
ORDER BY ORDER BY
unit unit
</select> </select>

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

5
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.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
/** /**
* 考试成绩服务实现类 * 考试成绩服务实现类
@ -41,6 +42,7 @@ public class TestScoreServiceImpl extends ServiceImpl<TestScoreMapper, TestScore
scoreList.forEach(score -> { scoreList.forEach(score -> {
TestScoreEntity testScoreEntity = new TestScoreEntity(); TestScoreEntity testScoreEntity = new TestScoreEntity();
BeanUtils.copyProperties(score, testScoreEntity); BeanUtils.copyProperties(score, testScoreEntity);
testScoreEntity.setTestId(testScoreDTO.getTestId());
testScoreEntities.add(testScoreEntity); testScoreEntities.add(testScoreEntity);
}); });
return this.updateBatchById(testScoreEntities); return this.updateBatchById(testScoreEntities);
@ -60,7 +62,8 @@ public class TestScoreServiceImpl extends ServiceImpl<TestScoreMapper, TestScore
return true; return true;
} }
// 删除关联考试成绩 // 删除关联考试成绩
return this.removeByIds(testScoreList); List<Long> ids = testScoreList.stream().map(TestScoreEntity::getId).collect(Collectors.toList());
return this.removeByIds(ids);
} }
/** /**

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

@ -14,7 +14,6 @@ import com.hnac.hzims.safeproduct.mapper.TestMapper;
import com.hnac.hzims.safeproduct.mapper.TrainPlanMapper; import com.hnac.hzims.safeproduct.mapper.TrainPlanMapper;
import com.hnac.hzims.safeproduct.service.ITestScoreService; import com.hnac.hzims.safeproduct.service.ITestScoreService;
import com.hnac.hzims.safeproduct.service.ITestService; import com.hnac.hzims.safeproduct.service.ITestService;
import com.hnac.hzims.safeproduct.vo.TestScoreVO;
import org.springblade.core.tool.api.R; import org.springblade.core.tool.api.R;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -24,6 +23,7 @@ import javax.annotation.Resource;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
/** /**
* 考试记录服务实现类 * 考试记录服务实现类
@ -115,7 +115,8 @@ public class TestServiceImpl extends ServiceImpl<TestMapper, TestEntity> impleme
return true; 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) { if (remove) {
for (TestEntity test : testList) { for (TestEntity test : testList) {
@ -169,13 +170,17 @@ public class TestServiceImpl extends ServiceImpl<TestMapper, TestEntity> impleme
public boolean updateTest(TestEntity testEntity) { public boolean updateTest(TestEntity testEntity) {
// 判断考试人员是否有变化 // 判断考试人员是否有变化
TestEntity oldTest = getTestByCode(testEntity.getCode()); TestEntity oldTest = getTestByCode(testEntity.getCode());
// 若不存在变化,更新考试记录 // 更新考试记录
boolean update = this.updateById(testEntity);
if (update) {
// 若不存在人员变化,返回true
if (oldTest.getPeopleName().equals(testEntity.getPeopleName())) { if (oldTest.getPeopleName().equals(testEntity.getPeopleName())) {
return this.updateById(testEntity); return true;
} }
// 若存在变化,查询并删除关联考试成绩 // 若存在变化,查询并删除关联考试成绩
List<TestScoreEntity> testScoreList = testScoreService.getRelativeTestScore(testEntity.getId()); List<TestScoreEntity> testScoreList = testScoreService.getRelativeTestScore(testEntity.getId());
boolean removeByIds = testScoreService.removeByIds(testScoreList); List<Long> scoreIds = testScoreList.stream().map(TestScoreEntity::getId).collect(Collectors.toList());
boolean removeByIds = testScoreService.removeByIds(scoreIds);
// 若删除成功,新增新的考试成绩数据 // 若删除成功,新增新的考试成绩数据
if (removeByIds) { if (removeByIds) {
String[] person = testEntity.getPeopleName().split(",|,"); String[] person = testEntity.getPeopleName().split(",|,");
@ -189,6 +194,7 @@ public class TestServiceImpl extends ServiceImpl<TestMapper, TestEntity> impleme
} }
return testScoreService.saveBatch(res); return testScoreService.saveBatch(res);
} }
}
return false; 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.metadata.WriteSheet;
import com.alibaba.excel.write.style.column.SimpleColumnWidthStyleStrategy; import com.alibaba.excel.write.style.column.SimpleColumnWidthStyleStrategy;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; 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.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hnac.hzims.safeproduct.dto.AnalysisYearDTO; 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.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.mapper.TrainPlanMapper;
import com.hnac.hzims.safeproduct.service.ITestService; import com.hnac.hzims.safeproduct.service.ITestService;
import com.hnac.hzims.safeproduct.service.ITrainPlanService; 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 unit = String.valueOf(param.get("unit"));
String startTime = String.valueOf(param.get("scheduledStartTime")); String startTime = String.valueOf(param.get("scheduledStartTime"));
String endTime = String.valueOf(param.get("scheduledEndTime")); String endTime = String.valueOf(param.get("scheduledEndTime"));
List<TrainPlanEntity> rehearsalRecordList = getTrainPlanByUnitAndDate(unit, startTime, endTime); List<TrainPlanEntity> trainPlanList = getTrainPlanByUnitAndDate(unit, startTime, endTime);
// 设置响应头 // 设置响应头
// URLEncoder.encode防止中文乱码 // URLEncoder.encode防止中文乱码
String fileName = URLEncoder.encode("培训计划表", "UTF-8"); String fileName = URLEncoder.encode("培训计划表", "UTF-8");
@ -185,7 +185,7 @@ public class TrainPlanServiceImpl extends ServiceImpl<TrainPlanMapper, TrainPlan
.build(); .build();
WriteSheet writeSheet = EasyExcel.writerSheet(1, "培训计划表").head(TrainPlanEntity.class) WriteSheet writeSheet = EasyExcel.writerSheet(1, "培训计划表").head(TrainPlanEntity.class)
.build(); .build();
excelWriter.write(rehearsalRecordList, writeSheet); excelWriter.write(trainPlanList, writeSheet);
excelWriter.finish(); excelWriter.finish();
} catch (Exception e) { } catch (Exception e) {
// 重置response // 重置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 unit 单位
* @param startTime 计划开始时间 * @param startTime 计划开始时间

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

@ -11,10 +11,12 @@ 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.common.logs.utils.StringUtils; import com.hnac.hzims.common.logs.utils.StringUtils;
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.RehearsalRecordEntity;
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.TrainStatusEnum;
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;
@ -23,6 +25,7 @@ import org.springframework.beans.factory.annotation.Autowired;
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.servlet.ServletOutputStream; import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
@ -30,6 +33,7 @@ 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;
import java.util.stream.Collectors;
/** /**
* 培训记录服务实现类 * 培训记录服务实现类
@ -43,9 +47,13 @@ public class TrainRecordServiceImpl extends ServiceImpl<TrainRecordMapper, Train
@Autowired @Autowired
ITestService testService; ITestService testService;
@Resource
TrainPlanMapper trainPlanMapper;
/** /**
* 新增培训记录 * 新增培训记录
*/ */
@Transactional(rollbackFor = Exception.class)
@Override @Override
public boolean saveTrainRecord(TrainRecordEntity trainRecordEntity) { public boolean saveTrainRecord(TrainRecordEntity trainRecordEntity) {
// 获取当月时间(yyyymm) // 获取当月时间(yyyymm)
@ -69,7 +77,14 @@ public class TrainRecordServiceImpl extends ServiceImpl<TrainRecordMapper, Train
} }
} }
trainRecordEntity.setCode(code); trainRecordEntity.setCode(code);
return this.save(trainRecordEntity); boolean save = this.save(trainRecordEntity);
// 若培训记录新增成功,修改培训计划状态为已完成
if (save) {
TrainPlanEntity trainPlanEntity = trainPlanMapper.selectById(trainRecordEntity.getTrainPlanId());
trainPlanEntity.setTrainStatus(TrainStatusEnum.FINISHED.getValue());
return trainPlanMapper.updateById(trainPlanEntity) == SafeProductConstant.SUCCESS;
}
return false;
} }
/** /**
@ -85,7 +100,8 @@ public class TrainRecordServiceImpl extends ServiceImpl<TrainRecordMapper, Train
return true; 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) { if (remove) {
for (TrainRecordEntity trainRecord : trainRecordList) { for (TrainRecordEntity trainRecord : trainRecordList) {
@ -140,7 +156,7 @@ public class TrainRecordServiceImpl extends ServiceImpl<TrainRecordMapper, Train
try { try {
outputStream = response.getOutputStream(); outputStream = response.getOutputStream();
String trainPlanId = String.valueOf(param.get("trainPlanId")); String trainPlanId = String.valueOf(param.get("trainPlanId"));
List<TrainRecordEntity> rehearsalRecordList = getTrainRecordByTrainPlanId(trainPlanId); List<TrainRecordEntity> trainRecordList = getTrainRecordByTrainPlanId(trainPlanId);
// 设置响应头 // 设置响应头
// URLEncoder.encode防止中文乱码 // URLEncoder.encode防止中文乱码
String fileName = URLEncoder.encode("培训记录表", "UTF-8"); String fileName = URLEncoder.encode("培训记录表", "UTF-8");
@ -156,7 +172,7 @@ public class TrainRecordServiceImpl extends ServiceImpl<TrainRecordMapper, Train
.build(); .build();
WriteSheet writeSheet = EasyExcel.writerSheet(1, "培训记录表").head(TrainRecordEntity.class) WriteSheet writeSheet = EasyExcel.writerSheet(1, "培训记录表").head(TrainRecordEntity.class)
.build(); .build();
excelWriter.write(rehearsalRecordList, writeSheet); excelWriter.write(trainRecordList, writeSheet);
excelWriter.finish(); excelWriter.finish();
} catch (Exception e) { } catch (Exception e) {
// 重置response // 重置response

Loading…
Cancel
Save