提交 7058ff2c 作者: 涂茂林

feat:撤离区相关

上级 f6c35a3b
...@@ -39,7 +39,7 @@ public interface AccidentSpotRepository ...@@ -39,7 +39,7 @@ public interface AccidentSpotRepository
* @param name 名称 * @param name 名称
* @return 事故点信息 * @return 事故点信息
*/ */
@Query("SELECT a FROM AccidentSpot a WHERE name like %?1% AND deleted = false") @Query("SELECT a FROM AccidentSpot a WHERE a.name like %?1% AND a.deleted = false")
List<AccidentSpot> findLikeName(String name); List<AccidentSpot> findLikeName(String name);
/** /**
......
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.domain.rehearsal;
import com.yiring.app.domain.video.Video;
import com.yiring.common.domain.BasicEntity;
import java.io.Serial;
import java.io.Serializable;
import javax.persistence.*;
import lombok.*;
import lombok.experimental.FieldNameConstants;
import lombok.experimental.SuperBuilder;
import org.hibernate.annotations.Comment;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.Where;
import org.locationtech.jts.geom.Geometry;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
/**
* @author tml
* @version 1.0
* @date 2022/5/9 9:14
*/
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@ToString
@FieldNameConstants
@Entity
@SuperBuilder(toBuilder = true)
@Where(clause = "deleted = false")
@Table(name = "BS_EVACUATION_ZONE")
@Comment("撤离区信息")
@EntityListeners(AuditingEntityListener.class)
public class EvacuationZone extends BasicEntity implements Serializable {
@Serial
private static final long serialVersionUID = 2069438753104654297L;
@Comment("撤离区名称")
private String name;
@Comment("地图id")
private Long mapId;
@Comment("地图名称")
private String mapName;
@Comment("空间信息")
@Type(type = "jts_geometry")
@Column(columnDefinition = "geometry")
private Geometry geometry;
@Comment("摄像头")
@ManyToOne
@JoinColumn(name = "video_id")
private Video video;
@Comment("超时时间(秒)")
private Integer timeoutDuration;
@Comment("消抖时间(秒)")
private Integer threshold;
@Comment("是否启用")
private Boolean enable;
@Comment(value = "是否删除")
@Column(nullable = false)
private Boolean deleted;
}
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.domain.rehearsal;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Set;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
/**
* @author tml
* @version 1.0
* @date 2022/5/9 9:19
*/
@Repository
public interface EvacuationZoneRepository
extends JpaRepository<EvacuationZone, Serializable>, JpaSpecificationExecutor<EvacuationZone> {
/**
* 判断名称是否存在
* @param name 撤离区名称
* @return true:存在 false:不存在
*/
boolean existsByName(String name);
/**
* 根据名称查询
* @param name 撤离区名称
* @return 撤离区列表
*/
List<EvacuationZone> findAllByName(String name);
/**
* 批量删除
* @param ids id集
* @param now 当前时间
* @return 删除了多少条
*/
@Query("UPDATE EvacuationZone SET deleted = true, updateTime = :now WHERE id in (:ids)")
@Modifying
int removeMany(@Param("ids") Set<Long> ids, @Param("now") LocalDateTime now);
/**
* 名称模糊查询撤离区
* @param name 名称
* @return 撤离区列表
*/
@Query("SELECT e FROM EvacuationZone e WHERE e.deleted = false AND e.name like %?1%")
List<EvacuationZone> findLikeName(String name);
/**
* 批量启用或停用撤离区
* @param enable 启用或停用
* @param ids 撤离区id集
* @param now 当前时间
* @return 改变了几条
*/
@Query("UPDATE EvacuationZone SET enable = :enable, updateTime = :now WHERE id in (:ids) AND deleted = false")
@Modifying
int changeEnable(@Param("enable") boolean enable, @Param("ids") Set<Long> ids, @Param("now") LocalDateTime now);
}
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.param.rehearsal;
import com.yiring.app.domain.rehearsal.EvacuationZone;
import com.yiring.app.domain.video.Video;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serial;
import java.io.Serializable;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.locationtech.jts.geom.Geometry;
/**
* @author tml
* @version 1.0
* @date 2022/5/9 9:29
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@ApiModel("撤离区添加param")
public class EvacuationZoneAddParam implements Serializable {
@Serial
private static final long serialVersionUID = -7802093296111267529L;
@ApiModelProperty(value = "撤离区名称", example = "撤离区1", required = true)
@NotEmpty(message = "撤离区名称不能为空")
private String name;
@ApiModelProperty(value = "地图id", example = "1", required = true)
@NotNull(message = "地图id不能为空")
private Long mapId;
@ApiModelProperty(value = "地图名称", example = "总图", required = true)
@NotEmpty(message = "地图名称不能为空")
private String mapName;
@ApiModelProperty(value = "空间信息", required = true)
@NotNull(message = "空间信息不能为空")
private Geometry geometry;
@ApiModelProperty(value = "摄像头id", example = "1516223754600976384")
private Long videoId;
@ApiModelProperty(value = "超时时间(秒)", example = "20", required = true)
@NotNull(message = "超时时间不能为空")
private Integer timeoutDuration;
@ApiModelProperty(value = "消抖时间(秒)", example = "10", required = true)
@NotNull(message = "消抖时间不能为空")
private Integer threshold;
public EvacuationZone transform() {
Video video = Video.builder().id(videoId).build();
return EvacuationZone
.builder()
.name(name)
.mapId(mapId)
.mapName(mapName)
.geometry(geometry)
.video(video)
.timeoutDuration(timeoutDuration)
.threshold(threshold)
.enable(false)
.deleted(false)
.build();
}
}
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.param.rehearsal;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serial;
import java.io.Serializable;
import javax.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author tml
* @version 1.0
* @date 2022/5/9 9:46
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@ApiModel("撤离区查询条件param")
public class EvacuationZoneConditionParam implements Serializable {
@Serial
private static final long serialVersionUID = -5269335791931545685L;
@ApiModelProperty(value = "事故点名称", example = "工作区域")
private String name;
@ApiModelProperty(value = "地图id", example = "1", required = true)
@NotNull(message = "请选择一个地图")
private Long mapId;
}
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.param.rehearsal;
import com.yiring.app.domain.rehearsal.EvacuationZone;
import com.yiring.app.domain.video.Video;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serial;
import java.io.Serializable;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.locationtech.jts.geom.Geometry;
/**
* @author tml
* @version 1.0
* @date 2022/5/9 9:29
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@ApiModel("撤离区修改param")
public class EvacuationZoneModifyParam implements Serializable {
@Serial
private static final long serialVersionUID = -7802093296111267529L;
@ApiModelProperty(value = "撤离区id", example = "1", required = true)
private Long id;
@ApiModelProperty(value = "撤离区名称", example = "撤离区1")
private String name;
@ApiModelProperty(value = "地图id", example = "1")
private Long mapId;
@ApiModelProperty(value = "地图名称", example = "总图")
private String mapName;
@ApiModelProperty(value = "空间信息")
private Geometry geometry;
@ApiModelProperty(value = "摄像头id", example = "1519550823770624000")
private Long videoId;
@ApiModelProperty(value = "超时时间(秒)", example = "20")
private Integer timeoutDuration;
@ApiModelProperty(value = "消抖时间(秒)", example = "10")
private Integer threshold;
public EvacuationZone transform() {
Video video = Video.builder().id(videoId).build();
return EvacuationZone
.builder()
.id(id)
.name(name)
.mapId(mapId)
.mapName(mapName)
.geometry(geometry)
.video(video)
.timeoutDuration(timeoutDuration)
.threshold(threshold)
.enable(false)
.deleted(false)
.build();
}
}
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.service.rehearsal;
import com.yiring.app.param.rehearsal.EvacuationZoneAddParam;
import com.yiring.app.param.rehearsal.EvacuationZoneConditionParam;
import com.yiring.app.param.rehearsal.EvacuationZoneModifyParam;
import com.yiring.app.vo.IdNameVo;
import com.yiring.app.vo.rehearsal.EvacuationZoneVo;
import com.yiring.common.core.Result;
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
* @version 1.0
* @date 2022/5/9 10:34
*/
public interface EvacuationZoneService {
/**
* 添加一个撤离区信息
* @param param 撤离区信息
* @return 是否成功
*/
Result<String> addOne(EvacuationZoneAddParam param);
/**
* 修改一条撤离区信息
* @param param 撤离区信息
* @return 是否成功
*/
Result<String> modifyOne(EvacuationZoneModifyParam param);
/**
* 删除一条撤离区信息
* @param idParam 撤离区信息id
* @return 是否成功
*/
Result<String> removeOne(IdParam idParam);
/**
* 删除多条撤离区信息
* @param ids 撤离区id集
* @return 成功删除了几条
*/
Result<String> removeMany(Set<Long> ids);
/**
* 查询撤离区下拉框
* @param name 撤离区名称
* @return 撤离区id和名称
*/
Result<PageVo<IdNameVo>> findEvacuationPullDown(String name);
/**
* 查询一条撤离区信息
* @param idParam 撤离区id
* @return 撤离区信息
*/
Result<EvacuationZoneVo> findOne(IdParam idParam);
/**
* 查询撤离区列表
* @param param 地图id和撤离区名称
* @return 撤离区信息
*/
Result<PageVo<EvacuationZoneVo>> findList(EvacuationZoneConditionParam param, PageParam pageParam);
/**
* 启用一个撤离区
* @param idParam 撤离区id
* @return 是否成功
*/
Result<String> enable(@Valid IdParam idParam);
/**
* 停用一个撤离区
* @param idParam 撤离区id
* @return 是否成功
*/
Result<String> unEnable(@Valid IdParam idParam);
/**
* 批量启用撤离区
* @param ids 撤离区id集
* @return 启用了几个撤离区
*/
Result<String> batchEnable(Set<Long> ids);
/**
* 批量停用撤离区
* @param ids 撤离区id集
* @return 停用了几个撤离区
*/
Result<String> batchUnEnable(Set<Long> ids);
}
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.service.rehearsal.impl;
import com.yiring.app.domain.rehearsal.EvacuationZone;
import com.yiring.app.domain.rehearsal.EvacuationZoneRepository;
import com.yiring.app.param.rehearsal.EvacuationZoneAddParam;
import com.yiring.app.param.rehearsal.EvacuationZoneConditionParam;
import com.yiring.app.param.rehearsal.EvacuationZoneModifyParam;
import com.yiring.app.service.rehearsal.EvacuationZoneService;
import com.yiring.app.util.JpaUtil;
import com.yiring.app.vo.IdNameVo;
import com.yiring.app.vo.rehearsal.EvacuationZoneVo;
import com.yiring.common.core.Result;
import com.yiring.common.core.Status;
import com.yiring.common.param.IdParam;
import com.yiring.common.param.PageParam;
import com.yiring.common.vo.PageVo;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import javax.persistence.criteria.Predicate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
/**
* @author tml
* @version 1.0
* @date 2022/5/9 10:42
*/
@Service
@Transactional(rollbackFor = Exception.class)
@Slf4j
public class EvacuationZoneServiceImpl implements EvacuationZoneService {
@Resource
private EvacuationZoneRepository evacuationZoneRepository;
@Override
public Result<String> addOne(EvacuationZoneAddParam param) {
boolean exists = evacuationZoneRepository.existsByName(param.getName());
if (exists) {
return Result.no(Status.EXPECTATION_FAILED, "撤离区名称已存在");
}
evacuationZoneRepository.saveAndFlush(param.transform());
return Result.ok();
}
@Override
public Result<String> modifyOne(EvacuationZoneModifyParam param) {
List<EvacuationZone> allByName = evacuationZoneRepository.findAllByName(param.getName());
if (allByName.size() > 1) {
log.warn("EvacuationZoneServiceImpl.modifyOne查询到多条名称相同的撤离区信息,param:[{}]", param);
}
EvacuationZone evacuationZone = null;
for (EvacuationZone item : allByName) {
if (item.getId().equals(param.getId())) {
evacuationZone = item;
} else {
return Result.no(Status.EXPECTATION_FAILED, "撤离区名称已存在");
}
}
EvacuationZone transform = param.transform();
JpaUtil.copyNotNullProperties(transform, evacuationZone);
return Result.ok();
}
@Override
public Result<String> removeOne(IdParam idParam) {
Optional<EvacuationZone> optional = evacuationZoneRepository.findById(idParam.getId());
if (optional.isEmpty()) {
return Result.no(Status.EXPECTATION_FAILED, "要删除的撤离区不存在");
}
optional.get().setDeleted(true);
return Result.ok();
}
@Override
public Result<String> removeMany(Set<Long> ids) {
int num = evacuationZoneRepository.removeMany(ids, LocalDateTime.now());
return Result.ok("成功删除了" + num + "条撤离区信息");
}
@Override
public Result<PageVo<IdNameVo>> findEvacuationPullDown(String name) {
List<EvacuationZone> likeName = evacuationZoneRepository.findLikeName(name);
List<IdNameVo> voList = likeName
.stream()
.map(e -> new IdNameVo(e.getId(), e.getName()))
.collect(Collectors.toList());
PageVo<IdNameVo> pageVo = PageVo.build(voList, voList.size());
return Result.ok(pageVo);
}
@Override
public Result<EvacuationZoneVo> findOne(IdParam idParam) {
Optional<EvacuationZone> optional = evacuationZoneRepository.findById(idParam.getId());
if (optional.isEmpty()) {
return Result.no(Status.EXPECTATION_FAILED, "要查询的撤离区不存在");
}
EvacuationZoneVo vo = EvacuationZoneVo.transform(optional.get());
return Result.ok(vo);
}
@Override
public Result<PageVo<EvacuationZoneVo>> findList(EvacuationZoneConditionParam param, PageParam pageParam) {
Pageable pageable = PageParam.toPageable(pageParam);
Specification<EvacuationZone> specification = (root, query, criteriaBuilder) -> {
ArrayList<Predicate> list = new ArrayList<>();
if (param.getMapId() != null) {
list.add(criteriaBuilder.equal(root.get(EvacuationZone.Fields.mapId), param.getMapId()));
}
if (param.getName() != null) {
list.add(criteriaBuilder.like(root.get(EvacuationZone.Fields.name), "%" + param.getName() + "%"));
}
Predicate[] array = list.toArray(new Predicate[0]);
return criteriaBuilder.and(array);
};
Page<EvacuationZone> page = evacuationZoneRepository.findAll(specification, pageable);
List<EvacuationZoneVo> list = page.get().map(EvacuationZoneVo::transform).collect(Collectors.toList());
PageVo<EvacuationZoneVo> pageVo = PageVo.build(list, list.size());
return Result.ok(pageVo);
}
@Override
public Result<String> enable(IdParam idParam) {
Optional<EvacuationZone> optional = evacuationZoneRepository.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<EvacuationZone> optional = evacuationZoneRepository.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 = evacuationZoneRepository.changeEnable(true, ids, LocalDateTime.now());
return Result.ok("成功启用了" + num + "个撤离区");
}
@Override
public Result<String> batchUnEnable(Set<Long> ids) {
int num = evacuationZoneRepository.changeEnable(false, ids, LocalDateTime.now());
return Result.ok("成功停用了" + num + "个撤离区");
}
}
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.vo.rehearsal;
import com.yiring.app.domain.rehearsal.EvacuationZone;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serial;
import java.io.Serializable;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.locationtech.jts.geom.Geometry;
/**
* @author tml
* @version 1.0
* @date 2022/5/9 10:04
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@ApiModel("撤离区VO")
public class EvacuationZoneVo implements Serializable {
@Serial
private static final long serialVersionUID = 919152196104921261L;
@ApiModelProperty(value = "撤离区id", example = "1")
private Long id;
@ApiModelProperty(value = "撤离区名称", example = "撤离区1")
private String name;
@ApiModelProperty(value = "地图id", example = "1")
private Long mapId;
@ApiModelProperty(value = "地图名称", example = "总图")
private String mapName;
@ApiModelProperty(value = "空间信息")
private Geometry geometry;
@ApiModelProperty(value = "摄像头id", example = "1")
private Long videoId;
@ApiModelProperty(value = "摄像头名称", example = "摄像头1")
private String videoName;
@ApiModelProperty(value = "超时时间(秒)", example = "100")
private Integer timeoutDuration;
@ApiModelProperty(value = "消抖时间(秒)", example = "100")
private Integer threshold;
@ApiModelProperty(value = "是否启用(true:启用,false:停用)", example = "true")
private Boolean enable;
public static EvacuationZoneVo transform(EvacuationZone evacuationZone) {
return EvacuationZoneVo
.builder()
.id(evacuationZone.getId())
.name(evacuationZone.getName())
.mapId(evacuationZone.getMapId())
.mapName(evacuationZone.getMapName())
.geometry(evacuationZone.getGeometry())
.videoId(evacuationZone.getVideo().getId())
.videoName(evacuationZone.getVideo().getVideoName())
.timeoutDuration(evacuationZone.getTimeoutDuration())
.threshold(evacuationZone.getThreshold())
.enable(evacuationZone.getEnable())
.build();
}
}
/* (C) 2022 YiRing, Inc. */
package com.yiring.app.web.rehearsal;
import com.yiring.app.param.rehearsal.EvacuationZoneAddParam;
import com.yiring.app.param.rehearsal.EvacuationZoneConditionParam;
import com.yiring.app.param.rehearsal.EvacuationZoneModifyParam;
import com.yiring.app.service.rehearsal.EvacuationZoneService;
import com.yiring.app.vo.IdNameVo;
import com.yiring.app.vo.rehearsal.EvacuationZoneVo;
import com.yiring.auth.param.IdsParam;
import com.yiring.common.core.Result;
import com.yiring.common.param.IdParam;
import com.yiring.common.param.PageParam;
import com.yiring.common.vo.PageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.annotation.Resource;
import javax.validation.Valid;
import org.springframework.web.bind.annotation.*;
/**
* @author tml
* @version 1.0
* @date 2022/5/9 10:19
*/
@Api(tags = "EvacuationZone(撤离区)")
@RestController
@RequestMapping("/evacuation/zone")
public class EvacuationZoneController {
@Resource
private EvacuationZoneService evacuationZoneService;
@ApiOperation("添加一条撤离区信息")
@PostMapping("/addOne")
public Result<String> addOne(@Valid @RequestBody EvacuationZoneAddParam param) {
return evacuationZoneService.addOne(param);
}
@ApiOperation("修改一条撤离区信息")
@PostMapping("/modifyOne")
public Result<String> modifyOne(@Valid @RequestBody EvacuationZoneModifyParam param) {
return evacuationZoneService.modifyOne(param);
}
@ApiOperation("删除一条撤离区信息")
@PostMapping("removeOne")
public Result<String> removeOne(@Valid IdParam idParam) {
return evacuationZoneService.removeOne(idParam);
}
@ApiOperation("批量删除撤离区信息")
@PostMapping("/removeMany")
public Result<String> removeMany(@Valid IdsParam idsParam) {
return evacuationZoneService.removeMany(idsParam.toIds());
}
@ApiOperation("查询撤离区下拉框")
@GetMapping("/findEvacuationPullDown")
public Result<PageVo<IdNameVo>> findEvacuationPullDown(String name) {
return evacuationZoneService.findEvacuationPullDown(name);
}
@ApiOperation("查询一条撤离区信息")
@GetMapping("/findOne")
public Result<EvacuationZoneVo> findOne(@Valid IdParam idParam) {
return evacuationZoneService.findOne(idParam);
}
@ApiOperation("查询撤离区信息列表")
@GetMapping("/findList")
public Result<PageVo<EvacuationZoneVo>> findList(
@Valid EvacuationZoneConditionParam conditionParam,
@Valid PageParam pageParam
) {
return evacuationZoneService.findList(conditionParam, pageParam);
}
@ApiOperation("启用一个撤离区")
@PostMapping("/enable")
public Result<String> enable(@Valid IdParam idParam) {
return evacuationZoneService.enable(idParam);
}
@ApiOperation("停用一个撤离区")
@PostMapping("/unEnable")
public Result<String> unEnable(@Valid IdParam idParam) {
return evacuationZoneService.unEnable(idParam);
}
@ApiOperation("批量启用撤离区")
@PostMapping("/batchEnable")
public Result<String> batchEnable(@Valid IdsParam idsParam) {
return evacuationZoneService.batchEnable(idsParam.toIds());
}
@ApiOperation("批量停用撤离区")
@PostMapping("/batchUnEnable")
public Result<String> batchUnEnable(@Valid IdsParam idsParam) {
return evacuationZoneService.batchUnEnable(idsParam.toIds());
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论