From 911bdf17e0b123e033da694ad29e3b8aee79ea94 Mon Sep 17 00:00:00 2001 From: liwen Date: Thu, 14 Dec 2023 16:23:48 +0800 Subject: [PATCH] =?UTF-8?q?add:=20=E6=96=B0=E5=A2=9E=E6=BC=94=E7=BB=83?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hzims/safeproduct/dto/RehearsalYearDTO.java | 23 +++ .../safeproduct/entity/RehearsalRecordEntity.java | 93 +++++++++++ .../safeproduct/enums/RehearsalStatusEnum.java | 32 ++++ .../hzims/safeproduct/vo/RehearsalMonthVO.java | 31 ++++ .../hnac/hzims/safeproduct/vo/RehearsalYearVO.java | 53 ++++++ .../controller/RehearsalRecordController.java | 93 +++++++++++ .../safeproduct/mapper/RehearsalRecordMapper.java | 54 +++++++ .../safeproduct/mapper/RehearsalRecordMapper.xml | 65 ++++++++ .../service/IRehearsalRecordService.java | 40 +++++ .../service/impl/RehearsalRecordServiceImpl.java | 178 +++++++++++++++++++++ .../safeproduct/src/main/resources/db/1.0.1.sql | 30 +++- 11 files changed, 691 insertions(+), 1 deletion(-) create mode 100644 hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/dto/RehearsalYearDTO.java create mode 100644 hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/RehearsalRecordEntity.java create mode 100644 hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/enums/RehearsalStatusEnum.java create mode 100644 hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/RehearsalMonthVO.java create mode 100644 hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/RehearsalYearVO.java create mode 100644 hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/RehearsalRecordController.java create mode 100644 hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/RehearsalRecordMapper.java create mode 100644 hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/RehearsalRecordMapper.xml create mode 100644 hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/IRehearsalRecordService.java create mode 100644 hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/RehearsalRecordServiceImpl.java diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/dto/RehearsalYearDTO.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/dto/RehearsalYearDTO.java new file mode 100644 index 0000000..6ce369d --- /dev/null +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/dto/RehearsalYearDTO.java @@ -0,0 +1,23 @@ +package com.hnac.hzims.safeproduct.dto; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * @author liwen + * @date 2023-12-14 + */ +@Data +@ApiModel(value = "演练年度统计DTO类") +public class RehearsalYearDTO { + + @ApiModelProperty("单位") + private String unit; + + @ApiModelProperty("日期") + private String dateTime; + + @ApiModelProperty("完成数") + private Long finishedNum; +} 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 new file mode 100644 index 0000000..1ae07b8 --- /dev/null +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/RehearsalRecordEntity.java @@ -0,0 +1,93 @@ +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.Max; +import javax.validation.constraints.Min; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import java.util.Date; + +/** + * @author liwen + * @date 2023-12-13 + */ +@Data +@EqualsAndHashCode(callSuper = true) +@TableName("hzims_rehearsal_record") +@ApiModel(value = "演练记录实体类") +public class RehearsalRecordEntity extends BaseEntity { + + @Size(max = 50, message = "编码字段长度不能超过50") + @ApiModelProperty("编码") + private String code; + + @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; + + @Min(value = 0, message = "参演人数不能小于0") + @Max(value = 1000000000, message = "参演人数超出限制范围") + @ApiModelProperty("参演人数") + private Integer peopleNum; + + @NotNull + @Size(max = 10, message = "总指挥字段长度不能超过10") + @ApiModelProperty("总指挥") + private String commander; + + @ApiModelProperty("演练实际开始时间") + private Date actualStartTime; + + @ApiModelProperty("演练实际结束时间") + private Date actualEndTime; + + @Size(max = 250, message = "演练记录字段长度不能超过250") + @ApiModelProperty("演练记录") + private String record; + + @Size(max = 250, message = "演练评价字段长度不能超过250") + @ApiModelProperty("演练评价") + private String comment; + + @Size(max = 20, message = "演练方式字段长度不能超过20") + @ApiModelProperty("演练方式") + private String rehearsalMethod; + + @NotNull + @Size(max = 20, message = "演练状态字段长度不能超过20") + @ApiModelProperty("演练状态") + private String rehearsalStatus; + + @Size(max = 1000, message = "演练图片字段长度不能超过1000") + @ApiModelProperty("演练图片") + private String imgPath; + + @Size(max = 1000, message = "演练附件字段长度不能超过1000") + @ApiModelProperty("演练附件") + private String filePath; +} diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/enums/RehearsalStatusEnum.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/enums/RehearsalStatusEnum.java new file mode 100644 index 0000000..864af73 --- /dev/null +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/enums/RehearsalStatusEnum.java @@ -0,0 +1,32 @@ +package com.hnac.hzims.safeproduct.enums; + +/** + * 演练状态枚举类 + * + * @author liwen + * @date 2023-12-14 + */ +public enum RehearsalStatusEnum { + + WAITING("WAITING", "未开始"), + UNFINISHED("UNFINISHED", "未完成"), + FINISHED("FINISHED", "已完成"); + + private final String value; + + private final String desc; + + RehearsalStatusEnum(String value, String desc) { + this.value = value; + this.desc = desc; + } + + public String getValue() { + return value; + } + + public String getDesc() { + return desc; + } + +} diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/RehearsalMonthVO.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/RehearsalMonthVO.java new file mode 100644 index 0000000..0bc8aaf --- /dev/null +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/RehearsalMonthVO.java @@ -0,0 +1,31 @@ +package com.hnac.hzims.safeproduct.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @author liwen + * @date 2023-12-14 + */ +@Data +@ApiModel(value = "演练月度统计VO类") +public class RehearsalMonthVO { + + @ApiModelProperty("单位") + private String unit; + + @ApiModelProperty("计划任务总数") + private Long scheduledTaskNum; + + @ApiModelProperty("已完成任务/次") + private Long finishedTaskNum; + + @ApiModelProperty("未完成任务/次") + private Long unfinishedTaskNum; + + @ApiModelProperty("任务完成率") + private BigDecimal taskCompletionRate; +} diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/RehearsalYearVO.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/RehearsalYearVO.java new file mode 100644 index 0000000..97556b8 --- /dev/null +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/vo/RehearsalYearVO.java @@ -0,0 +1,53 @@ +package com.hnac.hzims.safeproduct.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * @author liwen + * @date 2023-12-14 + */ +@Data +@ApiModel(value = "演练年度统计VO类") +public class RehearsalYearVO { + + @ApiModelProperty("单位") + private String unit; + + @ApiModelProperty("1月完成数") + private Long januaryNum; + + @ApiModelProperty("2月完成数") + private Long februaryNum; + + @ApiModelProperty("3月完成数") + private Long marchNum; + + @ApiModelProperty("4月完成数") + private Long aprilNum; + + @ApiModelProperty("5月完成数") + private Long mayNum; + + @ApiModelProperty("6月完成数") + private Long juneNum; + + @ApiModelProperty("7月完成数") + private Long julyNum; + + @ApiModelProperty("8月完成数") + private Long augustNum; + + @ApiModelProperty("9月完成数") + private Long septemberNum; + + @ApiModelProperty("10月完成数") + private Long octoberNum; + + @ApiModelProperty("11月完成数") + private Long novemberNum; + + @ApiModelProperty("12月完成数") + private Long decemberNum; +} 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 new file mode 100644 index 0000000..3d81120 --- /dev/null +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/RehearsalRecordController.java @@ -0,0 +1,93 @@ +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.RehearsalRecordEntity; +import com.hnac.hzims.safeproduct.service.IRehearsalRecordService; +import com.hnac.hzims.safeproduct.vo.RehearsalMonthVO; +import com.hnac.hzims.safeproduct.vo.RehearsalYearVO; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; +import lombok.AllArgsConstructor; +import org.springblade.core.boot.ctrl.BladeController; +import org.springblade.core.mp.support.Query; +import org.springblade.core.tool.api.R; +import org.springframework.web.bind.annotation.*; +import springfox.documentation.annotations.ApiIgnore; + +import javax.validation.Valid; +import java.util.Map; + +/** + * 演练记录接口类 + * + * @author liwen + * @date 2023-12-13 + */ +@RestController +@AllArgsConstructor +@RequestMapping("/rehearsal") +@Api(value = "演练记录", tags = "演练记录接口") +public class RehearsalRecordController extends BladeController { + + private final IRehearsalRecordService rehearsalRecordService; + + @PostMapping("/save") + @ApiOperation(value = "新增") + @ApiOperationSupport(order = 1) + public R save(@Valid @RequestBody RehearsalRecordEntity rehearsalRecord) { + return R.status(rehearsalRecordService.saveRehearsal(rehearsalRecord)); + } + + @PostMapping("/update") + @ApiOperation(value = "修改") + @ApiOperationSupport(order = 2) + public R update(@Valid @RequestBody RehearsalRecordEntity rehearsalRecord) { + return R.status(rehearsalRecordService.updateById(rehearsalRecord)); + } + + @PostMapping("/remove") + @ApiOperation(value = "删除") + @ApiOperationSupport(order = 3) + public R remove(@RequestParam Long id) { + return R.status(rehearsalRecordService.removeById(id)); + } + + @GetMapping("/detail") + @ApiOperation(value = "详情") + @ApiOperationSupport(order = 4) + public R detail(@RequestParam Long id) { + return R.data(rehearsalRecordService.getById(id)); + } + + @GetMapping("/page") + @ApiImplicitParams({ + @ApiImplicitParam() + }) + @ApiOperation(value = "分页") + @ApiOperationSupport(order = 5) + public R> page(@ApiIgnore @RequestParam Map param, Query query) { + IPage page = rehearsalRecordService.page(Condition.getPage(query), + Condition.getQueryWrapper(param, RehearsalRecordEntity.class)); + return R.data(page); + } + + @GetMapping("/dataByMonth") + @ApiOperation(value = "月度统计表") + @ApiOperationSupport(order = 6) + public R> dataByMonth(@RequestParam String month, Query query) { + IPage page = rehearsalRecordService.dataByMonth(month, query); + return R.data(page); + } + + @GetMapping("/dataByYear") + @ApiOperation(value = "年度统计表") + @ApiOperationSupport(order = 7) + public R> dataByYear(@RequestParam String year, Query query) { + IPage page = rehearsalRecordService.dataByYear(year, query); + return R.data(page); + } +} 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 new file mode 100644 index 0000000..9d60ecf --- /dev/null +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/RehearsalRecordMapper.java @@ -0,0 +1,54 @@ +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类 + * + * @author liwen + * @date 2023-12-13 + */ +@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 new file mode 100644 index 0000000..fbe9efc --- /dev/null +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/RehearsalRecordMapper.xml @@ -0,0 +1,65 @@ + + + + + + + + + + + + + \ No newline at end of file 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 new file mode 100644 index 0000000..ae85eda --- /dev/null +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/IRehearsalRecordService.java @@ -0,0 +1,40 @@ +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; + +/** + * 演练记录服务类 + * + * @author liwen + * @date 2023-12-13 + */ +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 演练记录实体类 + * @return 新增是否成功 + */ + boolean saveRehearsal(RehearsalRecordEntity rehearsalRecord); +} 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 new file mode 100644 index 0000000..98ed350 --- /dev/null +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/RehearsalRecordServiceImpl.java @@ -0,0 +1,178 @@ +package com.hnac.hzims.safeproduct.service.impl; + +import cn.hutool.core.date.DatePattern; +import com.alibaba.excel.util.CollectionUtils; +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.entity.RehearsalRecordEntity; +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 org.springblade.core.mp.support.Query; +import org.springframework.stereotype.Service; + +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.util.Date; +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; + +/** + * 演练记录服务实现类 + * + * @author liwen + * @date 2023-12-13 + */ +@Service +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 finishedPage = baseMapper.selectFinishedDataByMonth(page, 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; + } + + /** + * 新增演练 + */ + @Override + public boolean saveRehearsal(RehearsalRecordEntity rehearsalRecord) { + // 获取当月时间(yyyymm) + String currentMonth = DatePattern.SIMPLE_MONTH_FORMAT.format(new Date()); + // 查询是否存在同月编号 + String lastCode = getLastCode(currentMonth); + // 若不存在,新增编号 + if (StringUtils.isNull(lastCode)) { + String code = "YLJL" + currentMonth + "001"; + rehearsalRecord.setCode(code); + return this.save(rehearsalRecord); + } + // 若存在,编号递增 + String oldNum = lastCode.substring(lastCode.length() - 3); + int value = Integer.parseInt(oldNum) + 1; + String code; + // 根据数位拼接编号 + if (value < 10) { + code = "YLJL" + currentMonth + "00" + value; + } else if (value < 100) { + code = "YLJL" + currentMonth + "0" + value; + } else { + code = "YLJL" + currentMonth + value; + } + rehearsalRecord.setCode(code); + return this.save(rehearsalRecord); + } + + /** + * 查询是否存在同月编号 + * @param currentMonth 当月 + * @return 存在则返回上一编号,否则返回null + */ + private String getLastCode(String currentMonth) { + String month = currentMonth.substring(currentMonth.length() - 2); + List list = getRehearsalByMonth(month); + if (CollectionUtils.isEmpty(list)) { + return null; + } + return list.get(0).getCode(); + } + + /** + * 查询当月演练记录 + * @param month 当月 + * @return 当月演练数据表 + */ + public List getRehearsalByMonth(String month) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.lambda().like(RehearsalRecordEntity::getCreateTime, month) + .orderByDesc(RehearsalRecordEntity::getCode); + return this.list(queryWrapper); + } +} 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 f63ae4c..4138082 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 @@ -9,4 +9,32 @@ create table document_management update_time datetime default current_timestamp on update current_timestamp comment '更新时间', is_deleted tinyint default 0 comment '逻辑删除' -) comment '文档管理'; \ No newline at end of file +) comment '文档管理'; + +CREATE TABLE `hzims`.`hzims_rehearsal_record` ( + `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 '参演人数', + `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 '创建时间', + `update_user` bigint(20) DEFAULT '-1' COMMENT '更新人', + `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后更新时间', + `status` int(2) NOT NULL DEFAULT '1' COMMENT '状态', + `is_deleted` int(2) NOT NULL DEFAULT '0' COMMENT '逻辑删除状态:0-未删除,1-删除', + PRIMARY KEY (`id`) USING BTREE +) ENGINE=INNODB CHARACTER SET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='演练记录表' ROW_FORMAT=Dynamic; \ No newline at end of file