提交 552903ac 作者: 方治民

Merge branch 'dev_tml' of https://gitlab.yiring.com/chemical-kesai/kshg-api into dev_fzm

/* (C) 2022 YiRing, Inc. */
package com.yiring.app.constant.rehearsal;
import com.yiring.app.vo.CodeNameVo;
import java.util.ArrayList;
import java.util.List;
import lombok.Getter;
/**
* 演练计划状态枚举(1:未启动, 2:进行中, 3:已结束)
* @author tml
* @version 1.0
* @date 2022/5/9 17:29
*/
public enum RehearsalPlanStatusEnum {
/**
*未启动
*/
UN_START(1, "未启动"),
/**
*进行中
*/
RUNNING(2, "进行中"),
/**
* 已结束
*/
END(3, "已结束");
@Getter
private final Integer code;
@Getter
private final String name;
private static final List<CodeNameVo> LIST;
static {
LIST = new ArrayList<>();
for (RehearsalPlanStatusEnum item : values()) {
LIST.add(new CodeNameVo(item.getCode(), item.getName()));
}
}
RehearsalPlanStatusEnum(Integer code, String name) {
this.code = code;
this.name = name;
}
public static List<CodeNameVo> getAll() {
return LIST;
}
public static String getByCode(Integer code) {
for (RehearsalPlanStatusEnum item : values()) {
if (item.getCode().equals(code)) {
return item.getName();
}
}
return "未知状态";
}
}
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.constant.rehearsal;
import com.yiring.app.vo.CodeNameVo;
import java.util.ArrayList;
import java.util.List;
import lombok.Getter;
/**
* 演练计划风险等级枚举(1:红色风险, 2:橙色风险, 3:黄色风险, 4:蓝色风险)
* @author tml
* @version 1.0
* @date 2022/5/9 17:28
*/
public enum RiskLevelEnum {
/**
* 红色风险
*/
RED(1, "红色风险"),
/**
* 橙色风险
*/
ORANGE(2, "橙色风险"),
/**
* 黄色风险
*/
YELLOW(3, "黄色风险"),
/**
* 蓝色风险
*/
BLUE(4, "蓝色风险");
@Getter
private final Integer code;
@Getter
private final String name;
private static final List<CodeNameVo> LIST;
static {
LIST = new ArrayList<>();
for (RiskLevelEnum item : values()) {
LIST.add(new CodeNameVo(item.getCode(), item.getName()));
}
}
RiskLevelEnum(Integer code, String name) {
this.code = code;
this.name = name;
}
public static List<CodeNameVo> getAll() {
return LIST;
}
public static String getByCode(Integer code) {
for (RiskLevelEnum item : values()) {
if (item.getCode().equals(code)) {
return item.getName();
}
}
return "未知风险";
}
}
......@@ -43,22 +43,22 @@ public interface AccidentSpotRepository
List<AccidentSpot> findLikeName(String name);
/**
* 批量启用
* @param ids 事故点id集
* 批量删除
* @param ids id集
* @param now 当前时间
* @return 启用了多少条数据
* @return 删除了几条数据
*/
@Query("UPDATE AccidentSpot SET enable = true,updateTime = :now WHERE id in (:ids) AND deleted = false")
@Modifying
int batchEnable(@Param("ids") Set<Long> ids, @Param("now") LocalDateTime now);
@Query("UPDATE AccidentSpot SET deleted = true, updateTime = :now WHERE id IN (:ids)")
int batchRemove(@Param("ids") Set<Long> ids, @Param("now") LocalDateTime now);
/**
* 批量停用
* 批量启用/停用
* @param ids 事故点id集
* @param now 当前时间
* @return 停用了多少条数据
* @param enable true:启用 false:停用
* @return 启用/停用了多少条数据
*/
@Query("UPDATE AccidentSpot SET enable = false ,updateTime = :now WHERE id in (:ids) AND deleted = false")
@Query("UPDATE AccidentSpot SET enable = :enable ,updateTime = :now WHERE id IN (:ids) AND deleted = false")
@Modifying
int batchUnEnable(@Param("ids") Set<Long> ids, @Param("now") LocalDateTime now);
int batchEnable(@Param("ids") Set<Long> ids, @Param("enable") boolean enable, @Param("now") LocalDateTime now);
}
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.domain.rehearsal;
import com.yiring.common.domain.BasicEntity;
import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDateTime;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.FieldNameConstants;
import lombok.experimental.SuperBuilder;
import org.hibernate.annotations.Comment;
import org.hibernate.annotations.Where;
/**
* @author tml
* @version 1.0
* @date 2022/5/9 17:07
*/
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Entity
@FieldNameConstants
@SuperBuilder(toBuilder = true)
@Where(clause = "deleted = false")
@Table(name = "BS_REHEARSAL_PLAN")
@Comment("演练计划信息")
public class RehearsalPlan extends BasicEntity implements Serializable {
@Serial
private static final long serialVersionUID = -5215681932640062553L;
@Comment("演练主题")
private String topical;
@Comment("事故点")
@ManyToOne
@JoinColumn(name = "accident_spot_id")
private AccidentSpot accidentSpot;
@Comment("周边范围(事故点周围多少米)")
private Integer scope;
@Comment("撤离区")
@ManyToOne
@JoinColumn(name = "evacuation_zone_id")
private EvacuationZone evacuationZone;
@Comment("风险程度(1:红色风险, 2:橙色风险, 3:黄色风险, 4:蓝色风险)")
private Integer riskLevel;
@Comment("事故信息")
private String accidentMsg;
@Comment("演练时间")
private LocalDateTime rehearsalTime;
@Comment("推送信息")
private String pushMsg;
@Comment("演练计划的状态(1:未启动, 2:进行中, 3:已结束)")
private Integer status;
@Comment("逻辑删除")
private boolean deleted;
}
......@@ -11,6 +11,7 @@ import com.yiring.common.param.IdParam;
import com.yiring.common.param.PageParam;
import com.yiring.common.vo.PageVo;
import java.util.Set;
import javax.validation.Valid;
/**
* @author tml
......@@ -40,6 +41,13 @@ public interface AccidentSpotService {
Result<String> removeAccidentSpot(IdParam param);
/**
* 批量删除事故点
* @param ids 事故点id集
* @return 是否成功
*/
Result<String> batchRemove(Set<Long> ids);
/**
* 根据id查询事故点信息
* @param param id
* @return 事故点信息
......@@ -62,6 +70,20 @@ public interface AccidentSpotService {
Result<PageVo<IdNameVo>> findAccidentList(String name);
/**
* 启用一个事故点
* @param idParam 事故点id
* @return 是否成功
*/
Result<String> enable(@Valid IdParam idParam);
/**
* 停用一个事故点
* @param idParam 事故点id
* @return 是否成功
*/
Result<String> unEnable(@Valid IdParam idParam);
/**
* 批量启用事故点
* @param ids 事故点id集
* @return 是否成功
......
......@@ -90,6 +90,12 @@ public class AccidentSpotServiceImpl implements AccidentSpotService {
}
@Override
public Result<String> batchRemove(Set<Long> ids) {
int num = accidentSpotRepository.batchRemove(ids, LocalDateTime.now());
return Result.ok("删除了" + num + "个事故点");
}
@Override
public Result<AccidentSpotVo> findById(IdParam param) {
Optional<AccidentSpot> optional = accidentSpotRepository.findById(param.getId());
if (optional.isEmpty()) {
......@@ -137,14 +143,34 @@ public class AccidentSpotServiceImpl implements AccidentSpotService {
}
@Override
public Result<String> enable(IdParam idParam) {
Optional<AccidentSpot> optional = accidentSpotRepository.findById(idParam.getId());
if (optional.isEmpty()) {
return Result.no(Status.EXPECTATION_FAILED, "要启用的事故点不存在");
}
optional.get().setEnable(true);
return Result.ok();
}
@Override
public Result<String> unEnable(IdParam idParam) {
Optional<AccidentSpot> optional = accidentSpotRepository.findById(idParam.getId());
if (optional.isEmpty()) {
return Result.no(Status.EXPECTATION_FAILED, "要停用的事故点不存在");
}
optional.get().setEnable(false);
return Result.ok();
}
@Override
public Result<String> batchEnable(Set<Long> ids) {
int num = accidentSpotRepository.batchEnable(ids, LocalDateTime.now());
int num = accidentSpotRepository.batchEnable(ids, true, LocalDateTime.now());
return Result.ok("启用了" + num + "个事故点");
}
@Override
public Result<String> batchUnEnable(Set<Long> ids) {
int num = accidentSpotRepository.batchUnEnable(ids, LocalDateTime.now());
int num = accidentSpotRepository.batchEnable(ids, false, LocalDateTime.now());
return Result.ok("停用了" + num + "个事故点");
}
}
......@@ -7,6 +7,7 @@ import com.yiring.app.param.rehearsal.AccidentSpotModifyParam;
import com.yiring.app.service.rehearsal.AccidentSpotService;
import com.yiring.app.vo.IdNameVo;
import com.yiring.app.vo.rehearsal.AccidentSpotVo;
import com.yiring.auth.param.IdsParam;
import com.yiring.common.core.Result;
import com.yiring.common.domain.BasicEntity;
import com.yiring.common.param.IdParam;
......@@ -16,10 +17,8 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import java.util.Objects;
import java.util.Set;
import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Sort;
import org.springframework.validation.annotation.Validated;
......@@ -58,6 +57,12 @@ public class AccidentSpotController {
return accidentSpotService.removeAccidentSpot(param);
}
@ApiOperation("批量删除事故点")
@PostMapping("/batchRemove")
public Result<String> batchRemove(@Valid IdsParam idsParam) {
return accidentSpotService.batchRemove(idsParam.toIds());
}
@ApiOperation("根据id查询事故点")
@GetMapping("/findById")
public Result<AccidentSpotVo> findById(@Valid IdParam param) {
......@@ -87,21 +92,27 @@ public class AccidentSpotController {
return accidentSpotService.findAccidentList(name);
}
@ApiOperation("启用一个事故点")
@PostMapping("/enable")
public Result<String> enable(@Valid IdParam idParam) {
return accidentSpotService.enable(idParam);
}
@ApiOperation("停用一个事故点")
@PostMapping("/unEnable")
public Result<String> unEnable(@Valid IdParam idParam) {
return accidentSpotService.unEnable(idParam);
}
@ApiOperation("批量启用")
@ApiImplicitParam(value = "事故点id集", example = "1,2,3", name = "ids")
@GetMapping("/batchEnable")
public Result<String> batchEnable(
@RequestParam(value = "ids", required = false) @NotEmpty(message = "请传入至少一个事故点") Set<Long> ids
) {
return accidentSpotService.batchEnable(ids);
@PostMapping("/batchEnable")
public Result<String> batchEnable(@Valid IdsParam idsParam) {
return accidentSpotService.batchEnable(idsParam.toIds());
}
@ApiOperation("批量停用")
@ApiImplicitParam(value = "事故点id集", example = "1,2,3", name = "ids")
@GetMapping("/batchUnEnable")
public Result<String> batchUnEnable(
@RequestParam(value = "ids", required = false) @NotEmpty(message = "请传入至少一个事故点") Set<Long> ids
) {
return accidentSpotService.batchUnEnable(ids);
@PostMapping("/batchUnEnable")
public Result<String> batchUnEnable(@Valid IdsParam idsParam) {
return accidentSpotService.batchUnEnable(idsParam.toIds());
}
}
......@@ -58,6 +58,9 @@ public class EvacuationZoneController {
@ApiOperation("查询撤离区下拉框")
@GetMapping("/findEvacuationPullDown")
public Result<PageVo<IdNameVo>> findEvacuationPullDown(String name) {
if (name == null) {
name = "";
}
return evacuationZoneService.findEvacuationPullDown(name);
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论