From 9d9ef76bc9cdeb631322602e9fab078c0bfd0547 Mon Sep 17 00:00:00 2001 From: liwen Date: Wed, 27 Dec 2023 14:10:42 +0800 Subject: [PATCH] =?UTF-8?q?update:=20=E6=9B=B4=E6=96=B0=E6=BC=94=E7=BB=83?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E3=80=81=E5=9F=B9=E8=AE=AD=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hzims/safeproduct/dto/RehearsalExportDTO.java | 55 +++++ .../safeproduct/entity/RehearsalPlanEntity.java | 60 +++++ .../safeproduct/entity/RehearsalRecordEntity.java | 54 +---- .../hzims/safeproduct/entity/TrainPlanEntity.java | 7 +- .../controller/RehearsalRecordController.java | 81 +++++-- .../safeproduct/controller/TrainController.java | 2 +- .../hnac/hzims/safeproduct/jobs/RehearsalJob.java | 10 +- .../safeproduct/mapper/RehearsalPlanMapper.java | 64 +++++ .../safeproduct/mapper/RehearsalPlanMapper.xml | 84 +++++++ .../safeproduct/mapper/RehearsalRecordMapper.java | 38 --- .../safeproduct/mapper/RehearsalRecordMapper.xml | 60 ----- .../safeproduct/service/IRehearsalPlanService.java | 67 ++++++ .../service/IRehearsalRecordService.java | 56 +---- .../safeproduct/service/ITrainPlanService.java | 8 + .../service/impl/RehearsalPlanServiceImpl.java | 259 +++++++++++++++++++++ .../service/impl/RehearsalRecordServiceImpl.java | 213 +++-------------- .../service/impl/TrainPlanServiceImpl.java | 41 ++++ .../safeproduct/src/main/resources/db/1.0.1.sql | 18 +- 18 files changed, 756 insertions(+), 421 deletions(-) create mode 100644 hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/dto/RehearsalExportDTO.java create mode 100644 hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/RehearsalPlanEntity.java create mode 100644 hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/RehearsalPlanMapper.java create mode 100644 hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/RehearsalPlanMapper.xml create mode 100644 hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/IRehearsalPlanService.java create mode 100644 hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/RehearsalPlanServiceImpl.java diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/dto/RehearsalExportDTO.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/dto/RehearsalExportDTO.java new file mode 100644 index 0000000..1f2903b --- /dev/null +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/dto/RehearsalExportDTO.java @@ -0,0 +1,55 @@ +package com.hnac.hzims.safeproduct.dto; + +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.Date; + +/** + * @author liwen + * @date 2023-12-27 + */ +@Data +@ExcelIgnoreUnannotated +@ApiModel(value = "演练数据导出DTO类") +public class RehearsalExportDTO { + + @ApiModelProperty("单位") + @ExcelProperty(value = "单位", index = 0) + private String unit; + + @ApiModelProperty("演练科目") + @ExcelProperty(value = "演练科目", index = 1) + private String subject; + + @ApiModelProperty("演练计划开始时间") + @ExcelProperty(value = "演练计划开始时间", index = 2) + private Date scheduledStartTime; + + @ApiModelProperty("演练计划结束时间") + @ExcelProperty(value = "演练计划结束时间", index = 3) + private Date scheduledEndTime; + + @ApiModelProperty("演练地点") + @ExcelProperty(value = "演练地点", index = 4) + private String location; + + @ApiModelProperty("参演人数") + @ExcelProperty(value = "参演人数", index = 5) + private Integer peopleNum; + + @ApiModelProperty("演练实际开始时间") + @ExcelProperty(value = "演练实际开始时间", index = 6) + private Date actualStartTime; + + @ApiModelProperty("演练实际结束时间") + @ExcelProperty(value = "演练实际结束时间", index = 7) + private Date actualEndTime; + + @ApiModelProperty("演练状态") + @ExcelProperty(value = "演练状态", index = 8) + private String rehearsalStatus; +} diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/RehearsalPlanEntity.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/RehearsalPlanEntity.java new file mode 100644 index 0000000..bdff1a1 --- /dev/null +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/RehearsalPlanEntity.java @@ -0,0 +1,60 @@ +package com.hnac.hzims.safeproduct.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.springblade.core.mp.base.BaseEntity; + +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import java.util.Date; + +/** + * @author liwen + * @date 2023-12-27 + */ +@Data +@EqualsAndHashCode(callSuper = true) +@TableName("hzims_rehearsal_plan") +@ApiModel(value = "演练计划实体类") +public class RehearsalPlanEntity extends BaseEntity { + + @NotNull + @Size(max = 50, message = "单位字段长度不能超过50") + @ApiModelProperty("单位") + private String unit; + + @NotNull + @Size(max = 50, message = "演练科目字段长度不能超过50") + @ApiModelProperty("演练科目") + private String subject; + + @NotNull + @ApiModelProperty("演练计划开始时间") + private Date scheduledStartTime; + + @NotNull + @ApiModelProperty("演练计划结束时间") + private Date scheduledEndTime; + + @NotNull + @Size(max = 255, message = "演练地点字段长度不能超过255") + @ApiModelProperty("演练地点") + private String location; + + @NotNull + @Size(max = 10, message = "总指挥字段长度不能超过10") + @ApiModelProperty("总指挥") + private String commander; + + @Size(max = 20, message = "演练方式字段长度不能超过20") + @ApiModelProperty("演练方式") + private String rehearsalMethod; + + @NotNull + @Size(max = 20, message = "演练状态字段长度不能超过20") + @ApiModelProperty("演练状态") + private String rehearsalStatus; +} diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/RehearsalRecordEntity.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/RehearsalRecordEntity.java index 28d15e8..1bcf594 100644 --- a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/RehearsalRecordEntity.java +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/RehearsalRecordEntity.java @@ -1,7 +1,5 @@ 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; @@ -11,7 +9,6 @@ import org.springblade.core.mp.base.BaseEntity; import javax.validation.constraints.Max; import javax.validation.constraints.Min; -import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; import java.util.Date; @@ -21,65 +18,30 @@ import java.util.Date; */ @Data @EqualsAndHashCode(callSuper = true) -@ExcelIgnoreUnannotated @TableName("hzims_rehearsal_record") @ApiModel(value = "演练记录实体类") public class RehearsalRecordEntity extends BaseEntity { + @ApiModelProperty("演练计划id") + private Long rehearsalPlanId; + @Size(max = 50, message = "编码字段长度不能超过50") @ApiModelProperty("编码") - @ExcelProperty(value = "编码", index = 0) private String code; - @NotNull - @Size(max = 50, message = "单位字段长度不能超过50") - @ApiModelProperty("单位") - @ExcelProperty(value = "单位", index = 1) - private String unit; - - @NotNull - @Size(max = 50, message = "演练科目字段长度不能超过50") - @ApiModelProperty("演练科目") - @ExcelProperty(value = "演练科目", index = 2) - private String subject; - - @NotNull - @ApiModelProperty("演练计划开始时间") - @ExcelProperty(value = "演练计划开始时间", index = 3) - private Date scheduledStartTime; - - @NotNull - @ApiModelProperty("演练计划结束时间") - @ExcelProperty(value = "演练计划结束时间", index = 4) - private Date scheduledEndTime; - - @NotNull - @Size(max = 255, message = "演练地点字段长度不能超过255") - @ApiModelProperty("演练地点") - @ExcelProperty(value = "演练地点", index = 5) - private String location; - @Min(value = 0, message = "参演人数不能小于0") @Max(value = 1000, message = "参演人数字段长度超出限制范围") @ApiModelProperty("参演人数") - @ExcelProperty(value = "参演人数", index = 6) private Integer peopleNum; @Size(max = 5000, message = "参演人员字段长度超出限制范围") @ApiModelProperty("参演人员") private String peopleName; - @NotNull - @Size(max = 10, message = "总指挥字段长度不能超过10") - @ApiModelProperty("总指挥") - private String commander; - @ApiModelProperty("演练实际开始时间") - @ExcelProperty(value = "演练实际开始时间", index = 7) private Date actualStartTime; @ApiModelProperty("演练实际结束时间") - @ExcelProperty(value = "演练实际结束时间", index = 8) private Date actualEndTime; @Size(max = 250, message = "演练记录字段长度不能超过250") @@ -90,16 +52,6 @@ public class RehearsalRecordEntity extends BaseEntity { @ApiModelProperty("演练评价") private String comment; - @Size(max = 20, message = "演练方式字段长度不能超过20") - @ApiModelProperty("演练方式") - private String rehearsalMethod; - - @NotNull - @Size(max = 20, message = "演练状态字段长度不能超过20") - @ApiModelProperty("演练状态") - @ExcelProperty(value = "演练状态", index = 9) - private String rehearsalStatus; - @Size(max = 1000, message = "演练图片字段长度不能超过1000") @ApiModelProperty("演练图片") private String imgPath; 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 09fe232..9b1b0fb 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 @@ -2,6 +2,7 @@ package com.hnac.hzims.safeproduct.entity; import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; import com.alibaba.excel.annotation.ExcelProperty; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; @@ -70,6 +71,10 @@ public class TrainPlanEntity extends BaseEntity { @NotNull @ApiModelProperty("关联考试:0-否,1-是") - @ExcelProperty(value = "是否考试", index = 5) private Integer isTest; + + @TableField(exist = false) + @ApiModelProperty("是否考试") + @ExcelProperty(value = "是否考试", index = 5) + private String hasTest; } diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/RehearsalRecordController.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/RehearsalRecordController.java index 71b375f..f80e0fa 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/RehearsalRecordController.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/RehearsalRecordController.java @@ -3,7 +3,9 @@ package com.hnac.hzims.safeproduct.controller; import com.baomidou.mybatisplus.core.metadata.IPage; import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; import com.hnac.hzims.common.utils.Condition; +import com.hnac.hzims.safeproduct.entity.RehearsalPlanEntity; import com.hnac.hzims.safeproduct.entity.RehearsalRecordEntity; +import com.hnac.hzims.safeproduct.service.IRehearsalPlanService; import com.hnac.hzims.safeproduct.service.IRehearsalRecordService; import com.hnac.hzims.safeproduct.vo.RehearsalMonthVO; import com.hnac.hzims.safeproduct.vo.RehearsalYearVO; @@ -36,32 +38,34 @@ public class RehearsalRecordController extends BladeController { private final IRehearsalRecordService rehearsalRecordService; + private final IRehearsalPlanService rehearsalPlanService; + @PostMapping("/save") - @ApiOperation(value = "新增") + @ApiOperation(value = "新增演练计划") @ApiOperationSupport(order = 1) - public R save(@Valid @RequestBody RehearsalRecordEntity rehearsalRecord) { - return R.status(rehearsalRecordService.saveRehearsal(rehearsalRecord)); + public R save(@Valid @RequestBody RehearsalPlanEntity rehearsalPlan) { + return R.status(rehearsalPlanService.save(rehearsalPlan)); } @PostMapping("/update") - @ApiOperation(value = "修改") + @ApiOperation(value = "修改演练计划") @ApiOperationSupport(order = 2) - public R update(@Valid @RequestBody RehearsalRecordEntity rehearsalRecord) { - return R.status(rehearsalRecordService.updateRehearsal(rehearsalRecord)); + public R update(@Valid @RequestBody RehearsalPlanEntity rehearsalPlan) { + return R.status(rehearsalPlanService.updateById(rehearsalPlan)); } @PostMapping("/remove") - @ApiOperation(value = "删除") + @ApiOperation(value = "删除演练计划") @ApiOperationSupport(order = 3) public R remove(@RequestParam Long id) { - return R.status(rehearsalRecordService.removeById(id)); + return R.status(rehearsalPlanService.removeRehearsalPlan(id)); } @GetMapping("/detail") - @ApiOperation(value = "详情") + @ApiOperation(value = "演练计划详情") @ApiOperationSupport(order = 4) - public R detail(@RequestParam Long id) { - return R.data(rehearsalRecordService.getById(id)); + public R detail(@RequestParam Long id) { + return R.data(rehearsalPlanService.getById(id)); } @GetMapping("/page") @@ -70,9 +74,48 @@ public class RehearsalRecordController extends BladeController { @ApiImplicitParam(name = "scheduledStartTime", value = "计划开始时间", dataType = "query", paramType = "string"), @ApiImplicitParam(name = "scheduledEndTime", value = "计划结束时间", dataType = "query", paramType = "string") }) - @ApiOperation(value = "分页") + @ApiOperation(value = "演练计划分页") @ApiOperationSupport(order = 5) - public R> page(@ApiIgnore @RequestParam Map param, Query query) { + public R> page(@ApiIgnore @RequestParam Map param, Query query) { + IPage page = rehearsalPlanService.rehearsalPlanPage(param, query); + return R.data(page); + } + + @PostMapping("/saveRehearsalRecord") + @ApiOperation(value = "新增演练记录") + @ApiOperationSupport(order = 6) + public R saveRehearsalRecord(@Valid @RequestBody RehearsalRecordEntity rehearsalRecord) { + return R.status(rehearsalRecordService.saveRehearsalRecord(rehearsalRecord)); + } + + @PostMapping("/updateRehearsalRecord") + @ApiOperation(value = "修改演练记录") + @ApiOperationSupport(order = 7) + public R updateRehearsalRecord(@Valid @RequestBody RehearsalRecordEntity rehearsalRecord) { + return R.status(rehearsalRecordService.updateRehearsalRecord(rehearsalRecord)); + } + + @PostMapping("/removeRehearsalRecord") + @ApiOperation(value = "删除演练记录") + @ApiOperationSupport(order = 8) + public R removeRehearsalRecord(@RequestParam Long id) { + return R.status(rehearsalRecordService.removeById(id)); + } + + @GetMapping("/rehearsalRecordDetail") + @ApiOperation(value = "演练记录详情") + @ApiOperationSupport(order = 9) + public R rehearsalRecordDetail(@RequestParam Long id) { + return R.data(rehearsalRecordService.getById(id)); + } + + @GetMapping("/rehearsalRecordPage") + @ApiImplicitParams({ + @ApiImplicitParam(name = "rehearsalPlanId", value = "演练计划id", dataType = "query", paramType = "string") + }) + @ApiOperation(value = "演练记录分页") + @ApiOperationSupport(order = 10) + public R> rehearsalRecordPage(@ApiIgnore @RequestParam Map param, Query query) { IPage page = rehearsalRecordService.page(Condition.getPage(query), Condition.getQueryWrapper(param, RehearsalRecordEntity.class)); return R.data(page); @@ -80,17 +123,17 @@ public class RehearsalRecordController extends BladeController { @GetMapping("/dataByMonth") @ApiOperation(value = "月度统计表") - @ApiOperationSupport(order = 6) + @ApiOperationSupport(order = 11) public R> dataByMonth(@RequestParam String month, Query query) { - IPage page = rehearsalRecordService.dataByMonth(month, query); + IPage page = rehearsalPlanService.dataByMonth(month, query); return R.data(page); } @GetMapping("/dataByYear") @ApiOperation(value = "年度统计表") - @ApiOperationSupport(order = 7) + @ApiOperationSupport(order = 12) public R> dataByYear(@RequestParam String year, Query query) { - IPage page = rehearsalRecordService.dataByYear(year, query); + IPage page = rehearsalPlanService.dataByYear(year, query); return R.data(page); } @@ -101,8 +144,8 @@ public class RehearsalRecordController extends BladeController { @ApiImplicitParam(name = "scheduledEndTime", value = "计划结束时间", dataType = "query", paramType = "string") }) @ApiOperation(value = "演练数据导出") - @ApiOperationSupport(order = 8) + @ApiOperationSupport(order = 13) public void exportRehearsalData(@ApiIgnore @RequestParam Map param, HttpServletResponse response) { - rehearsalRecordService.exportRehearsalData(param, response); + rehearsalPlanService.exportRehearsalPlanData(param, response); } } 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 25fbe27..92d703c 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 @@ -94,7 +94,7 @@ public class TrainController extends BladeController { @ApiOperation(value = "培训计划分页") @ApiOperationSupport(order = 5) public R> trainPlanPage(@ApiIgnore @RequestParam Map param, Query query) { - IPage page = trainPlanService.page(Condition.getPage(query), Condition.getQueryWrapper(param, TrainPlanEntity.class)); + IPage page = trainPlanService.trainPlanPage(param, query); return R.data(page); } diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/jobs/RehearsalJob.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/jobs/RehearsalJob.java index 5b69652..44ff7d8 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/jobs/RehearsalJob.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/jobs/RehearsalJob.java @@ -1,8 +1,8 @@ package com.hnac.hzims.safeproduct.jobs; -import com.hnac.hzims.safeproduct.entity.RehearsalRecordEntity; +import com.hnac.hzims.safeproduct.entity.RehearsalPlanEntity; import com.hnac.hzims.safeproduct.enums.RehearsalStatusEnum; -import com.hnac.hzims.safeproduct.service.IRehearsalRecordService; +import com.hnac.hzims.safeproduct.service.IRehearsalPlanService; import com.xxl.job.core.biz.model.ReturnT; import com.xxl.job.core.handler.annotation.XxlJob; import org.springblade.core.tool.utils.DateUtil; @@ -22,7 +22,7 @@ import java.util.List; public class RehearsalJob { @Autowired - IRehearsalRecordService rehearsalRecordService; + IRehearsalPlanService rehearsalPlanService; @XxlJob("autoChangeRehearsalStatus") public ReturnT autoChangeRehearsalStatus(String param) { @@ -32,12 +32,12 @@ public class RehearsalJob { String today = DateUtil.format(current, "yyyy-mm-dd hh:MM:ss"); String yesterday = DateUtil.format(before, "yyyy-mm-dd hh:MM:ss"); // 查询前一天的超时未完成演练记录 - List list = rehearsalRecordService.getWaitingRehearsalInTimeRange(yesterday, today); + List list = rehearsalPlanService.getWaitingRehearsalInTimeRange(yesterday, today); list.forEach(x -> { x.setRehearsalStatus(RehearsalStatusEnum.UNFINISHED.getValue()); }); // 将状态置为未完成 - boolean flag = rehearsalRecordService.updateBatchById(list); + boolean flag = rehearsalPlanService.updateBatchById(list); return flag ? ReturnT.SUCCESS : ReturnT.FAIL; } } diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/RehearsalPlanMapper.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/RehearsalPlanMapper.java new file mode 100644 index 0000000..990793b --- /dev/null +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/RehearsalPlanMapper.java @@ -0,0 +1,64 @@ +package com.hnac.hzims.safeproduct.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.hnac.hzims.safeproduct.dto.AnalysisYearDTO; +import com.hnac.hzims.safeproduct.dto.RehearsalExportDTO; +import com.hnac.hzims.safeproduct.entity.RehearsalPlanEntity; +import com.hnac.hzims.safeproduct.vo.RehearsalMonthVO; +import com.hnac.hzims.safeproduct.vo.RehearsalYearVO; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * 演练计划Mapper类 + * + * @author liwen + * @date 2023-12-27 + */ +@Mapper +public interface RehearsalPlanMapper extends BaseMapper { + + /** + * 查询当月各单位的演练总数 + * @param page 分页类 + * @param month 月份 + * @return 当月的演练总数据 + */ + IPage selectByMonth(IPage page, String month); + + /** + * 查询当月各单位已完成的演练数据 + * @param page 分页类 + * @param month 月份 + * @return 当月的已完成数据 + */ + IPage selectFinishedDataByMonth(IPage page, String month); + + /** + * 查询当年的所有单位 + * @param page 分页类 + * @param year 年份 + * @return 年度单位数据 + */ + IPage selectUnitByYear(IPage page, @Param("year") String year); + + /** + * 查询各单位全年已完成的演练数据 + * @param unitList 单元列表 + * @param year 年份 + * @return 单位各月的数据列表 + */ + List selectFinishedDataByUnit(@Param("unitList") List unitList, @Param("year") String year); + + /** + * 根据单位和计划时间查询演练数据 + * @param unit 单位 + * @param startTime 计划开始时间 + * @param endTime 计划结束时间 + * @return 演练数据列表 + */ + List getRehearsalByUnitAndDate(String unit, String startTime, String endTime); +} diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/RehearsalPlanMapper.xml b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/RehearsalPlanMapper.xml new file mode 100644 index 0000000..71519a5 --- /dev/null +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/RehearsalPlanMapper.xml @@ -0,0 +1,84 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/RehearsalRecordMapper.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/RehearsalRecordMapper.java index 9d60ecf..1c77f92 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/RehearsalRecordMapper.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/RehearsalRecordMapper.java @@ -1,15 +1,8 @@ package com.hnac.hzims.safeproduct.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.hnac.hzims.safeproduct.dto.RehearsalYearDTO; import com.hnac.hzims.safeproduct.entity.RehearsalRecordEntity; -import com.hnac.hzims.safeproduct.vo.RehearsalMonthVO; -import com.hnac.hzims.safeproduct.vo.RehearsalYearVO; import org.apache.ibatis.annotations.Mapper; -import org.apache.ibatis.annotations.Param; - -import java.util.List; /** * 演练记录Mapper类 @@ -20,35 +13,4 @@ import java.util.List; @Mapper public interface RehearsalRecordMapper extends BaseMapper { - /** - * 查询当月各单位的演练总数 - * @param page 分页类 - * @param month 月份 - * @return 当月的演练总数据 - */ - IPage selectByMonth(IPage page, @Param("month") String month); - - /** - * 查询当月各单位已完成的演练数据 - * @param page 分页类 - * @param month 月份 - * @return 当月的已完成数据 - */ - IPage selectFinishedDataByMonth(IPage page, @Param("month") String month); - - /** - * 查询当年的所有单位 - * @param page 分页类 - * @param year 年份 - * @return 年度单位数据 - */ - IPage selectUnitByYear(IPage page, @Param("year") String year); - - /** - * 查询各单位全年已完成的演练数据 - * @param unitList 单元列表 - * @param year 年份 - * @return 单位各月的数据列表 - */ - List selectFinishedDataByUnit(@Param("unitList") List unitList, @Param("year") String year); } diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/RehearsalRecordMapper.xml b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/RehearsalRecordMapper.xml index fbe9efc..123fddd 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/RehearsalRecordMapper.xml +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/RehearsalRecordMapper.xml @@ -2,64 +2,4 @@ - - - - - - - - \ No newline at end of file diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/IRehearsalPlanService.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/IRehearsalPlanService.java new file mode 100644 index 0000000..cc18cfe --- /dev/null +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/IRehearsalPlanService.java @@ -0,0 +1,67 @@ +package com.hnac.hzims.safeproduct.service; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.service.IService; +import com.hnac.hzims.safeproduct.entity.RehearsalPlanEntity; +import com.hnac.hzims.safeproduct.vo.RehearsalMonthVO; +import com.hnac.hzims.safeproduct.vo.RehearsalYearVO; +import org.springblade.core.mp.support.Query; + +import javax.servlet.http.HttpServletResponse; +import java.util.List; +import java.util.Map; + +/** + * 演练计划服务类 + * + * @author liwen + * @date 2023-12-27 + */ +public interface IRehearsalPlanService extends IService { + + /** + * 删除演练计划 + * @param id 演练计划id + * @return true-成功,false-失败 + */ + boolean removeRehearsalPlan(Long id); + + /** + * 演练月度数据 + * @param month 月份 + * @param query 分页类 + * @return 月度统计分页 + */ + IPage dataByMonth(String month, Query query); + + /** + * 演练年度数据 + * @param year 年份 + * @param query 分页类 + * @return 年度统计分页 + */ + IPage dataByYear(String year, Query query); + + /** + * 演练计划数据导出 + * @param param 入参 + * @param response 响应类 + */ + void exportRehearsalPlanData(Map param, HttpServletResponse response); + + /** + * 查询时间范围内未开始的演练数据 + * @param startTime 开始时间 + * @param endTime 结束时间 + * @return 演练数据 + */ + List getWaitingRehearsalInTimeRange(String startTime, String endTime); + + /** + * 演练计划分页 + * @param param 入参 + * @param query 分页类 + * @return 演练计划数据 + */ + IPage rehearsalPlanPage(Map param, Query query); +} diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/IRehearsalRecordService.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/IRehearsalRecordService.java index 2ee8bbf..0fab88d 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/IRehearsalRecordService.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/IRehearsalRecordService.java @@ -1,15 +1,7 @@ package com.hnac.hzims.safeproduct.service; -import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.IService; import com.hnac.hzims.safeproduct.entity.RehearsalRecordEntity; -import com.hnac.hzims.safeproduct.vo.RehearsalMonthVO; -import com.hnac.hzims.safeproduct.vo.RehearsalYearVO; -import org.springblade.core.mp.support.Query; - -import javax.servlet.http.HttpServletResponse; -import java.util.List; -import java.util.Map; /** * 演练记录服务类 @@ -20,47 +12,23 @@ import java.util.Map; public interface IRehearsalRecordService extends IService { /** - * 演练月度数据 - * @param month 月份 - * @param query 分页类 - * @return 月度统计分页 - */ - IPage dataByMonth(String month, Query query); - - /** - * 演练年度数据 - * @param year 年份 - * @param query 分页类 - * @return 年度统计分页 - */ - IPage dataByYear(String year, Query query); - - /** - * 新增演练 - * @param rehearsalRecord 演练记录DTO类 - * @return 新增是否成功 - */ - boolean saveRehearsal(RehearsalRecordEntity rehearsalRecord); - - /** - * 修改演练 - * @param rehearsalRecord 演练记录DTO类 - * @return 更新是否成功 + * 新增演练记录 + * @param rehearsalRecord 演练记录实体类 + * @return true-成功,false-失败 */ - boolean updateRehearsal(RehearsalRecordEntity rehearsalRecord); + boolean saveRehearsalRecord(RehearsalRecordEntity rehearsalRecord); /** - * 演练数据导出 - * @param param 入参 - * @param response 响应类 + * 修改演练记录 + * @param rehearsalRecord 演练记录实体类 + * @return true-成功,false-失败 */ - void exportRehearsalData(Map param, HttpServletResponse response); + boolean updateRehearsalRecord(RehearsalRecordEntity rehearsalRecord); /** - * 查询时间范围内未开始的演练数据 - * @param startTime 开始时间 - * @param endTime 结束时间 - * @return 演练数据 + * 删除关联演练记录 + * @param rehearsalPlanId 演练计划id + * @return true-成功,false-失败 */ - List getWaitingRehearsalInTimeRange(String startTime, String endTime); + boolean removeRelativeRehearsalRecord(Long rehearsalPlanId); } 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 bfb31ac..50571cc 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 @@ -56,4 +56,12 @@ public interface ITrainPlanService extends IService { * @return 培训计划数据 */ List getWaitingTrainPlanInTimeRange(String startTime, String endTime); + + /** + * 培训计划分页 + * @param param 入参 + * @param query 分页类 + * @return 培训计划数据 + */ + IPage trainPlanPage(Map param, Query query); } diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/RehearsalPlanServiceImpl.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/RehearsalPlanServiceImpl.java new file mode 100644 index 0000000..a3db6d5 --- /dev/null +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/RehearsalPlanServiceImpl.java @@ -0,0 +1,259 @@ +package com.hnac.hzims.safeproduct.service.impl; + +import com.alibaba.excel.EasyExcel; +import com.alibaba.excel.ExcelWriter; +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.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.common.utils.Condition; +import com.hnac.hzims.safeproduct.dto.AnalysisYearDTO; +import com.hnac.hzims.safeproduct.dto.RehearsalExportDTO; +import com.hnac.hzims.safeproduct.entity.RehearsalPlanEntity; +import com.hnac.hzims.safeproduct.enums.RehearsalStatusEnum; +import com.hnac.hzims.safeproduct.mapper.RehearsalPlanMapper; +import com.hnac.hzims.safeproduct.service.IRehearsalPlanService; +import com.hnac.hzims.safeproduct.service.IRehearsalRecordService; +import com.hnac.hzims.safeproduct.vo.RehearsalMonthVO; +import com.hnac.hzims.safeproduct.vo.RehearsalYearVO; +import org.springblade.core.log.exception.ServiceException; +import org.springblade.core.mp.support.Query; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.net.URLEncoder; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.stream.Collectors; + +/** + * 演练计划服务实现类 + * + * @author liwen + * @date 2023-12-27 + */ +@Service +public class RehearsalPlanServiceImpl extends ServiceImpl + implements IRehearsalPlanService { + + @Autowired + IRehearsalRecordService rehearsalRecordService; + + /** + * 删除演练计划 + */ + @Transactional(rollbackFor = Exception.class) + @Override + public boolean removeRehearsalPlan(Long id) { + boolean remove = this.removeById(id); + // 若演练计划删除成功,删除关联演练记录 + if (remove) { + return rehearsalRecordService.removeRelativeRehearsalRecord(id); + } + return false; + } + + /** + * 演练月度数据 + */ + @Override + public IPage dataByMonth(String month, Query query) { + // 查询当月各单位的演练总数 + IPage page = new Page<>(query.getCurrent(), query.getSize()); + IPage unitPage = baseMapper.selectByMonth(page, month); + List unitList = unitPage.getRecords(); + // 查询当月各单位已完成的演练数据 + IPage page1 = new Page<>(query.getCurrent(), query.getSize()); + IPage finishedPage = baseMapper.selectFinishedDataByMonth(page1, month); + List finishedList = finishedPage.getRecords(); + // 处理统计数据 + for (RehearsalMonthVO unit : unitList) { + Long taskNum = unit.getScheduledTaskNum(); + Optional finishedRehearsal = finishedList.stream().filter(x -> x.getUnit().equals(unit.getUnit())).findFirst(); + Long finishedTaskNum = finishedRehearsal.isPresent() ? finishedRehearsal.get().getFinishedTaskNum() : 0L; + unit.setFinishedTaskNum(finishedTaskNum); + unit.setUnfinishedTaskNum(taskNum - finishedTaskNum); + BigDecimal taskDecimal = new BigDecimal(taskNum); + BigDecimal finishedDecimal = new BigDecimal(finishedTaskNum); + unit.setTaskCompletionRate(finishedDecimal.divide(taskDecimal, 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")) + .setScale(2, RoundingMode.HALF_UP)); + } + unitPage.setRecords(unitList); + return unitPage; + } + + /** + * 演练年度数据 + */ + @Override + public IPage dataByYear(String year, Query query) { + IPage page = new Page<>(query.getCurrent(), query.getSize()); + // 查询当年的所有单位 + IPage unitPage = baseMapper.selectUnitByYear(page, year); + List records = unitPage.getRecords(); + // 若无数据,返回空页面 + if (org.springframework.util.CollectionUtils.isEmpty(records)) { + return unitPage; + } + List unitList = records.stream().map(RehearsalYearVO::getUnit).collect(Collectors.toList()); + // 查询各单位全年已完成的演练数据 + List unitMonthDataList = baseMapper.selectFinishedDataByUnit(unitList, year); + // 将各单位每个月的演练数据写入统计列表 + unitMonthDataList.forEach(data -> { + RehearsalYearVO rehearsalYearVO = records.stream().filter(x -> x.getUnit().equals(data.getUnit())) + .collect(Collectors.toList()).get(0); + // 根据月份匹配写入对应字段 + switch (data.getDateTime()) { + case "01": + rehearsalYearVO.setJanuaryNum(data.getFinishedNum()); + break; + case "02": + rehearsalYearVO.setFebruaryNum(data.getFinishedNum()); + break; + case "03": + rehearsalYearVO.setMarchNum(data.getFinishedNum()); + break; + case "04": + rehearsalYearVO.setAprilNum(data.getFinishedNum()); + break; + case "05": + rehearsalYearVO.setMayNum(data.getFinishedNum()); + break; + case "06": + rehearsalYearVO.setJuneNum(data.getFinishedNum()); + break; + case "07": + rehearsalYearVO.setJulyNum(data.getFinishedNum()); + break; + case "08": + rehearsalYearVO.setAugustNum(data.getFinishedNum()); + break; + case "09": + rehearsalYearVO.setSeptemberNum(data.getFinishedNum()); + break; + case "10": + rehearsalYearVO.setOctoberNum(data.getFinishedNum()); + break; + case "11": + rehearsalYearVO.setNovemberNum(data.getFinishedNum()); + break; + case "12": + rehearsalYearVO.setDecemberNum(data.getFinishedNum()); + } + }); + unitPage.setRecords(records); + return unitPage; + } + + /** + * 演练计划数据导出 + */ + @Override + public void exportRehearsalPlanData(Map param, HttpServletResponse response) { + ServletOutputStream outputStream = null; + try { + outputStream = response.getOutputStream(); + String unit = String.valueOf(param.get("unit")); + String startTime = String.valueOf(param.get("scheduledStartTime")); + String endTime = String.valueOf(param.get("scheduledEndTime")); + List rehearsalList = getRehearsalByUnitAndDate(unit, startTime, endTime); + // 处理演练状态信息 + rehearsalList.forEach(record -> { + String status; + if (record.getRehearsalStatus().equals(RehearsalStatusEnum.WAITING.getValue())) { + status = RehearsalStatusEnum.WAITING.getDesc(); + } else if (record.getRehearsalStatus().equals(RehearsalStatusEnum.UNFINISHED.getValue())) { + status = RehearsalStatusEnum.UNFINISHED.getDesc(); + } else { + status = RehearsalStatusEnum.FINISHED.getDesc(); + } + record.setRehearsalStatus(status); + }); + // 设置响应头 + // URLEncoder.encode防止中文乱码 + String fileName = URLEncoder.encode("演练记录表", "UTF-8"); + response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx"); + 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(RehearsalExportDTO.class) + .build(); + excelWriter.write(rehearsalList, 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()); + } + } + } + } + + /** + * 根据单位和计划时间查询演练记录 + * @param unit 单位 + * @param startTime 计划开始时间 + * @param endTime 计划结束时间 + * @return 演练记录列表 + */ + public List getRehearsalByUnitAndDate(String unit, String startTime, String endTime) { + return baseMapper.getRehearsalByUnitAndDate(unit, startTime, endTime); + } + + /** + * 查询时间范围内未开始的演练数据 + */ + @Override + public List getWaitingRehearsalInTimeRange(String startTime, String endTime) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.lambda().eq(RehearsalPlanEntity::getRehearsalStatus, RehearsalStatusEnum.WAITING.getValue()) + .ge(RehearsalPlanEntity::getScheduledEndTime, startTime) + .lt(RehearsalPlanEntity::getScheduledEndTime, endTime); + return this.list(queryWrapper); + } + + /** + * 演练计划分页 + */ + @Override + public IPage rehearsalPlanPage(Map param, Query query) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + String unit = String.valueOf(param.get("unit")); + String startTime = String.valueOf(param.get("startTime")); + String endTime = String.valueOf((param.get("endTime"))); + if (unit.equals("null") || unit.equals("")) { + queryWrapper.lambda().eq(RehearsalPlanEntity::getUnit, unit); + } + if (startTime.equals("null") || startTime.equals("")) { + queryWrapper.lambda().ge(RehearsalPlanEntity::getScheduledStartTime, startTime); + } + if (endTime.equals("null") || endTime.equals("")) { + queryWrapper.lambda().le(RehearsalPlanEntity::getScheduledEndTime, endTime); + } + return this.page(Condition.getPage(query), queryWrapper); + } +} diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/RehearsalRecordServiceImpl.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/RehearsalRecordServiceImpl.java index f1aa1e8..b3a6701 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/RehearsalRecordServiceImpl.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/RehearsalRecordServiceImpl.java @@ -1,37 +1,21 @@ package com.hnac.hzims.safeproduct.service.impl; import cn.hutool.core.date.DatePattern; -import com.alibaba.druid.support.json.JSONUtils; -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.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.common.logs.utils.StringUtils; -import com.hnac.hzims.safeproduct.dto.RehearsalYearDTO; +import com.hnac.hzims.safeproduct.constants.SafeProductConstant; +import com.hnac.hzims.safeproduct.entity.RehearsalPlanEntity; import com.hnac.hzims.safeproduct.entity.RehearsalRecordEntity; import com.hnac.hzims.safeproduct.enums.RehearsalStatusEnum; +import com.hnac.hzims.safeproduct.mapper.RehearsalPlanMapper; import com.hnac.hzims.safeproduct.mapper.RehearsalRecordMapper; import com.hnac.hzims.safeproduct.service.IRehearsalRecordService; -import com.hnac.hzims.safeproduct.vo.RehearsalMonthVO; -import com.hnac.hzims.safeproduct.vo.RehearsalYearVO; import lombok.extern.slf4j.Slf4j; -import org.springblade.core.log.exception.ServiceException; -import org.springblade.core.mp.support.Query; import org.springframework.stereotype.Service; -import javax.servlet.ServletOutputStream; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.math.BigDecimal; -import java.math.RoundingMode; -import java.net.URLEncoder; +import javax.annotation.Resource; import java.util.*; import java.util.stream.Collectors; @@ -45,99 +29,14 @@ import java.util.stream.Collectors; @Slf4j public class RehearsalRecordServiceImpl extends ServiceImpl implements IRehearsalRecordService { - /** - * 演练月度数据 - */ - @Override - public IPage dataByMonth(String month, Query query) { - // 查询当月各单位的演练总数 - IPage page = new Page<>(query.getCurrent(), query.getSize()); - IPage unitPage = baseMapper.selectByMonth(page, month); - List unitList = unitPage.getRecords(); - // 查询当月各单位已完成的演练数据 - IPage page1 = new Page<>(query.getCurrent(), query.getSize()); - IPage finishedPage = baseMapper.selectFinishedDataByMonth(page1, month); - List finishedList = finishedPage.getRecords(); - // 处理统计数据 - for (RehearsalMonthVO unit : unitList) { - Long taskNum = unit.getScheduledTaskNum(); - Optional finishedRehearsal = finishedList.stream().filter(x -> x.getUnit().equals(unit.getUnit())).findFirst(); - Long finishedTaskNum = finishedRehearsal.isPresent() ? finishedRehearsal.get().getFinishedTaskNum() : 0L; - unit.setFinishedTaskNum(finishedTaskNum); - unit.setUnfinishedTaskNum(taskNum - finishedTaskNum); - BigDecimal taskDecimal = new BigDecimal(taskNum); - BigDecimal finishedDecimal = new BigDecimal(finishedTaskNum); - unit.setTaskCompletionRate(finishedDecimal.divide(taskDecimal, RoundingMode.HALF_UP).multiply(new BigDecimal("100")) - .setScale(2, RoundingMode.HALF_UP)); - } - unitPage.setRecords(unitList); - return unitPage; - } - - /** - * 演练年度数据 - */ - @Override - public IPage dataByYear(String year, Query query) { - IPage page = new Page<>(query.getCurrent(), query.getSize()); - // 查询当年的所有单位 - IPage unitPage = baseMapper.selectUnitByYear(page, year); - List records = unitPage.getRecords(); - List unitList = records.stream().map(RehearsalYearVO::getUnit).collect(Collectors.toList()); - // 查询各单位全年已完成的演练数据 - List unitMonthDataList = baseMapper.selectFinishedDataByUnit(unitList, year); - // 将各单位每个月的演练数据写入统计列表 - unitMonthDataList.forEach(data -> { - RehearsalYearVO rehearsalYearVO = records.stream().filter(x -> x.getUnit().equals(data.getUnit())) - .collect(Collectors.toList()).get(0); - // 根据月份匹配写入对应字段 - switch (data.getDateTime()) { - case "01": - rehearsalYearVO.setJanuaryNum(data.getFinishedNum()); - break; - case "02": - rehearsalYearVO.setFebruaryNum(data.getFinishedNum()); - break; - case "03": - rehearsalYearVO.setMarchNum(data.getFinishedNum()); - break; - case "04": - rehearsalYearVO.setAprilNum(data.getFinishedNum()); - break; - case "05": - rehearsalYearVO.setMayNum(data.getFinishedNum()); - break; - case "06": - rehearsalYearVO.setJuneNum(data.getFinishedNum()); - break; - case "07": - rehearsalYearVO.setJulyNum(data.getFinishedNum()); - break; - case "08": - rehearsalYearVO.setAugustNum(data.getFinishedNum()); - break; - case "09": - rehearsalYearVO.setSeptemberNum(data.getFinishedNum()); - break; - case "10": - rehearsalYearVO.setOctoberNum(data.getFinishedNum()); - break; - case "11": - rehearsalYearVO.setNovemberNum(data.getFinishedNum()); - break; - case "12": - rehearsalYearVO.setDecemberNum(data.getFinishedNum()); - } - }); - unitPage.setRecords(records); - return unitPage; - } + @Resource + RehearsalPlanMapper rehearsalPlanMapper; /** * 新增演练 */ @Override - public boolean saveRehearsal(RehearsalRecordEntity rehearsalRecord) { + public boolean saveRehearsalRecord(RehearsalRecordEntity rehearsalRecord) { // 获取当月时间(yyyymm) String currentMonth = DatePattern.SIMPLE_MONTH_FORMAT.format(new Date()); // 查询是否存在同月编号 @@ -165,14 +64,21 @@ public class RehearsalRecordServiceImpl extends ServiceImpl param, HttpServletResponse response) { - ServletOutputStream outputStream = null; - try { - outputStream = response.getOutputStream(); - String unit = String.valueOf(param.get("unit")); - String startTime = String.valueOf(param.get("scheduledStartTime")); - String endTime = String.valueOf(param.get("scheduledEndTime")); - List rehearsalRecordList = getRehearsalByUnitAndDate(unit, startTime, endTime); - // 设置响应头 - // URLEncoder.encode防止中文乱码 - String fileName = URLEncoder.encode("演练记录表", "UTF-8"); - response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx"); - 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(RehearsalRecordEntity.class) - .build(); - excelWriter.write(rehearsalRecordList, 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()); - } - } - } - } - - /** * 查询是否存在同月编号 * @param currentMonth 当月 * @return 存在则返回上一编号,否则返回null @@ -255,37 +115,20 @@ public class RehearsalRecordServiceImpl extends ServiceImpl getRehearsalByUnitAndDate(String unit, String startTime, String endTime) { - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - if (!unit.equals("null")) { - queryWrapper.eq(RehearsalRecordEntity::getUnit, unit); - } - if (!startTime.equals("null")) { - queryWrapper.ge(RehearsalRecordEntity::getScheduledStartTime, startTime); - } - if (!endTime.equals("null")) { - queryWrapper.le(RehearsalRecordEntity::getScheduledEndTime, endTime); - } - queryWrapper.orderByDesc(RehearsalRecordEntity::getScheduledEndTime); - return this.list(queryWrapper); - } - - /** - * 查询时间范围内未开始的演练数据 + * 删除关联演练记录 */ @Override - public List getWaitingRehearsalInTimeRange(String startTime, String endTime) { + public boolean removeRelativeRehearsalRecord(Long rehearsalPlanId) { + // 查询关联演练记录 QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.lambda().eq(RehearsalRecordEntity::getRehearsalStatus, RehearsalStatusEnum.WAITING.getValue()) - .ge(RehearsalRecordEntity::getScheduledEndTime, startTime) - .lt(RehearsalRecordEntity::getScheduledEndTime, endTime); - return this.list(queryWrapper); + queryWrapper.lambda().eq(RehearsalRecordEntity::getRehearsalPlanId, rehearsalPlanId); + List rehearsalRecordList = this.list(queryWrapper); + // 若无关联演练记录,直接返回true + if (CollectionUtils.isEmpty(rehearsalRecordList)) { + return true; + } + // 删除关联演练记录 + List ids = rehearsalRecordList.stream().map(RehearsalRecordEntity::getId).collect(Collectors.toList()); + return this.removeByIds(ids); } - } 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 142b75f..33aec9e 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 @@ -10,8 +10,12 @@ 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.common.utils.Condition; +import com.hnac.hzims.safeproduct.constants.SafeProductConstant; import com.hnac.hzims.safeproduct.dto.AnalysisYearDTO; +import com.hnac.hzims.safeproduct.entity.RehearsalPlanEntity; import com.hnac.hzims.safeproduct.entity.TrainPlanEntity; +import com.hnac.hzims.safeproduct.enums.RehearsalStatusEnum; import com.hnac.hzims.safeproduct.enums.TrainStatusEnum; import com.hnac.hzims.safeproduct.mapper.TrainPlanMapper; import com.hnac.hzims.safeproduct.service.ITestService; @@ -170,6 +174,22 @@ public class TrainPlanServiceImpl extends ServiceImpl trainPlanList = getTrainPlanByUnitAndDate(unit, startTime, endTime); + // 处理字段信息 + trainPlanList.forEach(train -> { + // 培训状态 + String status; + if (train.getTrainStatus().equals(TrainStatusEnum.WAITING.getValue())) { + status = TrainStatusEnum.WAITING.getDesc(); + } else if (train.getTrainStatus().equals(TrainStatusEnum.UNFINISHED.getValue())) { + status = TrainStatusEnum.UNFINISHED.getDesc(); + } else { + status = TrainStatusEnum.FINISHED.getDesc(); + } + train.setTrainStatus(status); + // 是否考试 + String isTest = train.getIsTest().equals(SafeProductConstant.TRAIN_PLAN_HAS_TEST) ? "是" : "否"; + train.setHasTest(isTest); + }); // 设置响应头 // URLEncoder.encode防止中文乱码 String fileName = URLEncoder.encode("培训计划表", "UTF-8"); @@ -217,6 +237,27 @@ public class TrainPlanServiceImpl extends ServiceImpl trainPlanPage(Map param, Query query) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + String unit = String.valueOf(param.get("unit")); + String startTime = String.valueOf(param.get("startTime")); + String endTime = String.valueOf((param.get("endTime"))); + if (unit.equals("null") || unit.equals("")) { + queryWrapper.lambda().eq(TrainPlanEntity::getUnit, unit); + } + if (startTime.equals("null") || startTime.equals("")) { + queryWrapper.lambda().ge(TrainPlanEntity::getScheduledStartTime, startTime); + } + if (endTime.equals("null") || endTime.equals("")) { + queryWrapper.lambda().le(TrainPlanEntity::getScheduledEndTime, endTime); + } + return this.page(Condition.getPage(query), queryWrapper); + } + + /** * 根据单位和计划时间查询培训计划数据 * @param unit 单位 * @param startTime 计划开始时间 diff --git a/hzims-service/safeproduct/src/main/resources/db/1.0.1.sql b/hzims-service/safeproduct/src/main/resources/db/1.0.1.sql index 6d3a340..6bf9836 100644 --- a/hzims-service/safeproduct/src/main/resources/db/1.0.1.sql +++ b/hzims-service/safeproduct/src/main/resources/db/1.0.1.sql @@ -13,23 +13,14 @@ create table document_management CREATE TABLE `hzims_rehearsal_plan` ( `id` bigint(20) NOT NULL COMMENT '主键id', - `code` varchar(50) NOT NULL COMMENT '编号', `unit` varchar(50) NOT NULL COMMENT '单位', `subject` varchar(50) NOT NULL COMMENT '演练科目', `scheduled_start_time` datetime NOT NULL COMMENT '演练计划开始时间', `scheduled_end_time` datetime NOT NULL COMMENT '演练计划结束时间', `location` varchar(255) NOT NULL COMMENT '演练地点', - `people_num` int(10) NOT NULL DEFAULT '0' COMMENT '参演人数', - `people_name` varchar(5000) DEFAULT '' COMMENT '参演人员', `commander` varchar(10) NOT NULL COMMENT '总指挥', - `actual_start_time` datetime DEFAULT NULL COMMENT '演练实际开始时间', - `actual_end_time` datetime DEFAULT NULL COMMENT '演练实际结束时间', - `record` varchar(250) DEFAULT '' COMMENT '演练记录', - `comment` varchar(250) DEFAULT '' DEFAULT '' COMMENT '演练评价', `rehearsal_method` varchar(20) DEFAULT '' COMMENT '演练方式', `rehearsal_status` varchar(20) NOT NULL DEFAULT 'WAITING' COMMENT '演练状态', - `img_path` varchar(1000) NOT NULL DEFAULT '' COMMENT '演练图片', - `file_path` varchar(1000) NOT NULL DEFAULT '' COMMENT '演练附件', `create_user` bigint(20) NOT NULL DEFAULT '-1' COMMENT '创建人', `create_dept` bigint(20) NOT NULL DEFAULT '-1' COMMENT '创建部门', `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', @@ -42,21 +33,14 @@ CREATE TABLE `hzims_rehearsal_plan` ( CREATE TABLE `hzims_rehearsal_record` ( `id` bigint(20) NOT NULL COMMENT '主键id', + `rehearsal_plan_id` bigint(20) NOT NULL COMMENT '演练计划id', `code` varchar(50) NOT NULL COMMENT '编号', - `unit` varchar(50) NOT NULL COMMENT '单位', - `subject` varchar(50) NOT NULL COMMENT '演练科目', - `scheduled_start_time` datetime NOT NULL COMMENT '演练计划开始时间', - `scheduled_end_time` datetime NOT NULL COMMENT '演练计划结束时间', - `location` varchar(255) NOT NULL COMMENT '演练地点', `people_num` int(10) NOT NULL DEFAULT '0' COMMENT '参演人数', `people_name` varchar(5000) DEFAULT '' COMMENT '参演人员', - `commander` varchar(10) NOT NULL COMMENT '总指挥', `actual_start_time` datetime DEFAULT NULL COMMENT '演练实际开始时间', `actual_end_time` datetime DEFAULT NULL COMMENT '演练实际结束时间', `record` varchar(250) DEFAULT '' COMMENT '演练记录', `comment` varchar(250) DEFAULT '' DEFAULT '' COMMENT '演练评价', - `rehearsal_method` varchar(20) DEFAULT '' COMMENT '演练方式', - `rehearsal_status` varchar(20) NOT NULL DEFAULT 'WAITING' COMMENT '演练状态', `img_path` varchar(1000) NOT NULL DEFAULT '' COMMENT '演练图片', `file_path` varchar(1000) NOT NULL DEFAULT '' COMMENT '演练附件', `create_user` bigint(20) NOT NULL DEFAULT '-1' COMMENT '创建人',