Browse Source

update: 修改新增、修改演练逻辑

zhongwei
liwen 12 months ago
parent
commit
acc979538f
  1. 95
      hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/dto/RehearsalRecordDTO.java
  2. 6
      hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/RehearsalRecordEntity.java
  3. 31
      hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/enums/RehearsalMethodEnum.java
  4. 18
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/RehearsalRecordController.java
  5. 12
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/IRehearsalRecordService.java
  6. 70
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/RehearsalRecordServiceImpl.java

95
hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/dto/RehearsalRecordDTO.java

@ -0,0 +1,95 @@
package com.hnac.hzims.safeproduct.dto;
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-15
*/
@Data
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "演练记录DTO类")
public class RehearsalRecordDTO 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 = 1000, message = "参演人数字段长度超出限制范围")
@ApiModelProperty("参演人数")
private Integer peopleNum;
@Size(max = 5000, message = "参演人员字段长度超出限制范围")
@ApiModelProperty("参演人员")
private String[] people;
@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[] images;
@Size(max = 1000, message = "演练附件字段长度不能超过1000")
@ApiModelProperty("演练附件")
private String[] files;
}

6
hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/RehearsalRecordEntity.java

@ -51,10 +51,14 @@ public class RehearsalRecordEntity extends BaseEntity {
private String location;
@Min(value = 0, message = "参演人数不能小于0")
@Max(value = 1000000000, message = "参演人数超出限制范围")
@Max(value = 1000, message = "参演人数字段长度超出限制范围")
@ApiModelProperty("参演人数")
private Integer peopleNum;
@Size(max = 5000, message = "参演人员字段长度超出限制范围")
@ApiModelProperty("参演人员")
private String peopleName;
@NotNull
@Size(max = 10, message = "总指挥字段长度不能超过10")
@ApiModelProperty("总指挥")

31
hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/enums/RehearsalMethodEnum.java

@ -0,0 +1,31 @@
package com.hnac.hzims.safeproduct.enums;
/**
* 演练方式枚举类
*
* @author liwen
* @date 2023-12-14
*/
public enum RehearsalMethodEnum {
ONLINE("ONLINE", "线上"),
OFFLINE("OFFLINE", "线下"),
MIXED("MIXED", "线上+线下");
private final String value;
private final String desc;
RehearsalMethodEnum(String value, String desc) {
this.value = value;
this.desc = desc;
}
public String getValue() {
return value;
}
public String getDesc() {
return desc;
}
}

18
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/RehearsalRecordController.java

@ -3,6 +3,7 @@ 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.dto.RehearsalRecordDTO;
import com.hnac.hzims.safeproduct.entity.RehearsalRecordEntity;
import com.hnac.hzims.safeproduct.service.IRehearsalRecordService;
import com.hnac.hzims.safeproduct.vo.RehearsalMonthVO;
@ -38,15 +39,15 @@ public class RehearsalRecordController extends BladeController {
@PostMapping("/save")
@ApiOperation(value = "新增")
@ApiOperationSupport(order = 1)
public R save(@Valid @RequestBody RehearsalRecordEntity rehearsalRecord) {
public R save(@Valid @RequestBody RehearsalRecordDTO 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));
public R update(@Valid @RequestBody RehearsalRecordDTO rehearsalRecord) {
return R.status(rehearsalRecordService.updateRehearsal(rehearsalRecord));
}
@PostMapping("/remove")
@ -65,7 +66,9 @@ public class RehearsalRecordController extends BladeController {
@GetMapping("/page")
@ApiImplicitParams({
@ApiImplicitParam()
@ApiImplicitParam(name = "unit", value = "单位", dataType = "query", paramType = "string"),
@ApiImplicitParam(name = "actualStartTime", value = "实际开始时间", dataType = "query", paramType = "string"),
@ApiImplicitParam(name = "actualEndTime", value = "实际结束时间", dataType = "query", paramType = "string")
})
@ApiOperation(value = "分页")
@ApiOperationSupport(order = 5)
@ -90,4 +93,11 @@ public class RehearsalRecordController extends BladeController {
IPage<RehearsalYearVO> page = rehearsalRecordService.dataByYear(year, query);
return R.data(page);
}
@GetMapping("/exportRehearsalData")
@ApiOperation(value = "导出演练页数据")
@ApiOperationSupport(order = 8)
public void exportRehearsalData() {
}
}

12
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/IRehearsalRecordService.java

@ -2,6 +2,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.dto.RehearsalRecordDTO;
import com.hnac.hzims.safeproduct.entity.RehearsalRecordEntity;
import com.hnac.hzims.safeproduct.vo.RehearsalMonthVO;
import com.hnac.hzims.safeproduct.vo.RehearsalYearVO;
@ -33,8 +34,15 @@ public interface IRehearsalRecordService extends IService<RehearsalRecordEntity>
/**
* 新增演练
* @param rehearsalRecord 演练记录实体
* @param rehearsalRecord 演练记录DTO
* @return 新增是否成功
*/
boolean saveRehearsal(RehearsalRecordEntity rehearsalRecord);
boolean saveRehearsal(RehearsalRecordDTO rehearsalRecord);
/**
* 修改演练
* @param rehearsalRecord 演练记录DTO类
* @return 更新是否成功
*/
boolean updateRehearsal(RehearsalRecordDTO rehearsalRecord);
}

70
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/RehearsalRecordServiceImpl.java

@ -7,6 +7,7 @@ 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.RehearsalRecordDTO;
import com.hnac.hzims.safeproduct.dto.RehearsalYearDTO;
import com.hnac.hzims.safeproduct.entity.RehearsalRecordEntity;
import com.hnac.hzims.safeproduct.mapper.RehearsalRecordMapper;
@ -14,10 +15,12 @@ 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.beans.BeanUtils;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Optional;
@ -37,12 +40,13 @@ public class RehearsalRecordServiceImpl extends ServiceImpl<RehearsalRecordMappe
*/
@Override
public IPage<RehearsalMonthVO> dataByMonth(String month, Query query) {
IPage<RehearsalMonthVO> page = new Page<>(query.getCurrent(), query.getSize());
// 查询当月各单位的演练总数
IPage<RehearsalMonthVO> page = new Page<>(query.getCurrent(), query.getSize());
IPage<RehearsalMonthVO> unitPage = baseMapper.selectByMonth(page, month);
List<RehearsalMonthVO> unitList = unitPage.getRecords();
// 查询当月各单位已完成的演练数据
IPage<RehearsalMonthVO> finishedPage = baseMapper.selectFinishedDataByMonth(page, month);
IPage<RehearsalMonthVO> page1 = new Page<>(query.getCurrent(), query.getSize());
IPage<RehearsalMonthVO> finishedPage = baseMapper.selectFinishedDataByMonth(page1, month);
List<RehearsalMonthVO> finishedList = finishedPage.getRecords();
// 处理统计数据
for (RehearsalMonthVO unit : unitList) {
@ -123,31 +127,41 @@ public class RehearsalRecordServiceImpl extends ServiceImpl<RehearsalRecordMappe
* 新增演练
*/
@Override
public boolean saveRehearsal(RehearsalRecordEntity rehearsalRecord) {
public boolean saveRehearsal(RehearsalRecordDTO 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;
if (StringUtils.isNull(lastCode)) {
code = "YLJL" + currentMonth + "001";
} else { // 若存在,编号递增
String oldNum = lastCode.substring(lastCode.length() - 3);
int value = Integer.parseInt(oldNum) + 1;
// 根据数位拼接编号
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);
// DTO转实体类
RehearsalRecordEntity rehearsalRecordEntity = getStandardRehearsal(rehearsalRecord);
return this.save(rehearsalRecordEntity);
}
/**
* 修改演练
*/
@Override
public boolean updateRehearsal(RehearsalRecordDTO rehearsalRecord) {
// DTO转实体类
RehearsalRecordEntity rehearsalRecordEntity = getStandardRehearsal(rehearsalRecord);
return this.updateById(rehearsalRecordEntity);
}
/**
@ -175,4 +189,22 @@ public class RehearsalRecordServiceImpl extends ServiceImpl<RehearsalRecordMappe
.orderByDesc(RehearsalRecordEntity::getCode);
return this.list(queryWrapper);
}
/**
* 获取标准演练实体类
* @param rehearsalRecord 演练记录DTO类
* @return 演练实体类
*/
private RehearsalRecordEntity getStandardRehearsal(RehearsalRecordDTO rehearsalRecord) {
// DTO转实体类
RehearsalRecordEntity rehearsalRecordEntity = new RehearsalRecordEntity();
BeanUtils.copyProperties(rehearsalRecord, rehearsalRecordEntity);
// 参演人数
rehearsalRecordEntity.setPeopleNum(rehearsalRecord.getPeople().length);
// 数组转字符串
rehearsalRecordEntity.setPeopleName(Arrays.toString(rehearsalRecord.getPeople()));
rehearsalRecordEntity.setImgPath(Arrays.toString(rehearsalRecord.getImages()));
rehearsalRecordEntity.setFilePath(Arrays.toString(rehearsalRecord.getFiles()));
return rehearsalRecordEntity;
}
}

Loading…
Cancel
Save