From 2c3567ff2cc840a62d27565e58b134da830485bc Mon Sep 17 00:00:00 2001 From: weizhihong Date: Thu, 8 Jun 2023 15:07:36 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E5=8F=91=E5=B8=83?= =?UTF-8?q?=E5=9B=BE=E5=BD=A2=E6=8E=A5=E5=8F=A3=E3=80=81=E7=BA=BF=E8=B7=AF?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/LineInfoController.java | 11 +++++---- .../controller/PublishedGiController.java | 23 ++++++++++++++++++- .../joylink/xiannccda/dto/PublishedGIDto.java | 7 ++++++ .../joylink/xiannccda/entity/LineInfo.java | 3 +++ .../repository/IPublishedGiRepository.java | 2 ++ .../impl/PublishedGiRepository.java | 15 ++++++++++++ .../xiannccda/service/PublishedGiService.java | 2 +- 7 files changed, 57 insertions(+), 6 deletions(-) diff --git a/src/main/java/club/joylink/xiannccda/controller/LineInfoController.java b/src/main/java/club/joylink/xiannccda/controller/LineInfoController.java index 975e472..080e2c2 100644 --- a/src/main/java/club/joylink/xiannccda/controller/LineInfoController.java +++ b/src/main/java/club/joylink/xiannccda/controller/LineInfoController.java @@ -9,6 +9,7 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import java.security.Principal; @@ -62,7 +63,8 @@ public class LineInfoController { @SecurityRequirement(name = "jwt") @Operation(summary = "创建线路") @ApiResponse(description = "线路信息") - public LineInfo create(Principal user, @RequestBody LineInfo lineInfo) { + public LineInfo create(Principal user + , @RequestBody @Validated(LineInfo.Creation.class) LineInfo lineInfo) { return lineInfoService.create(user, lineInfo); } @@ -76,9 +78,10 @@ public class LineInfoController { @PutMapping("/{id}") @SecurityRequirement(name = "jwt") - @Operation(summary = "保存线路数据") - @ApiResponse(description = "保存成功失败标识") - public boolean updateData(@PathVariable Integer id, @RequestBody LineInfo lineInfo) { + @Operation(summary = "更新线路数据") + @ApiResponse(description = "更新成功失败标识") + public boolean updateData(@PathVariable Integer id + , @RequestBody @Validated(LineInfo.SaveData.class) LineInfo lineInfo) { return lineInfoService.updateData(id, lineInfo); } diff --git a/src/main/java/club/joylink/xiannccda/controller/PublishedGiController.java b/src/main/java/club/joylink/xiannccda/controller/PublishedGiController.java index ca94995..bdbc9b5 100644 --- a/src/main/java/club/joylink/xiannccda/controller/PublishedGiController.java +++ b/src/main/java/club/joylink/xiannccda/controller/PublishedGiController.java @@ -10,6 +10,7 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import java.security.Principal; @@ -53,11 +54,31 @@ public class PublishedGiController { return publishedGiRepository.list(query); } + @GetMapping("/{id}") + @SecurityRequirement(name = "jwt") + @Operation(summary = "根据主键获取发布图形数据详情") + @ApiResponse(description = "根据主键获取发布图形数据详情") + public PublishedGi queryById(@PathVariable Integer id) { + return publishedGiRepository.getById(id); + } + + @GetMapping("/{type}/{lineId}") + @SecurityRequirement(name = "jwt") + @Operation(summary = "根据线路号和类型获取发布图形数据详情") + @ApiResponse(description = "根据线路号和类型获取发布图形数据详情") + public PublishedGi queryByTypeAndLineId(@PathVariable String type, @PathVariable Integer lineId) { + PublishedGIQueryDto dto = new PublishedGIQueryDto(); + dto.setType(type); + dto.setLineId(lineId); + return publishedGiRepository.queryByDto(dto); + } + + @PostMapping("/publish") @SecurityRequirement(name = "jwt") @Operation(summary = "发布草稿图形数据") @ApiResponse(description = "发布草稿图形数据") - public PublishedGi publish(Principal user, @RequestBody PublishedGIDto publishedDto) { + public PublishedGi publish(Principal user, @RequestBody @Validated(PublishedGIDto.Publish.class) PublishedGIDto publishedDto) { return publishedGiService.publish(user, publishedDto); } diff --git a/src/main/java/club/joylink/xiannccda/dto/PublishedGIDto.java b/src/main/java/club/joylink/xiannccda/dto/PublishedGIDto.java index 837a95c..2b1751e 100644 --- a/src/main/java/club/joylink/xiannccda/dto/PublishedGIDto.java +++ b/src/main/java/club/joylink/xiannccda/dto/PublishedGIDto.java @@ -1,6 +1,7 @@ package club.joylink.xiannccda.dto; import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; import lombok.Getter; import lombok.Setter; @@ -14,9 +15,15 @@ public class PublishedGIDto { @NotNull @Schema(description = "关联的线路号") + @NotBlank(message = "关联线路不能为空", groups = { Publish.class }) private Integer lineId; @NotNull @Schema(description = "草稿数据主键") + @NotBlank(message = "请选择草稿数据", groups = { Publish.class }) private Integer draftingId; + + public interface Publish { + + } } diff --git a/src/main/java/club/joylink/xiannccda/entity/LineInfo.java b/src/main/java/club/joylink/xiannccda/entity/LineInfo.java index f1bcd3f..ccf3ae6 100644 --- a/src/main/java/club/joylink/xiannccda/entity/LineInfo.java +++ b/src/main/java/club/joylink/xiannccda/entity/LineInfo.java @@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.annotation.TableName; import java.time.LocalDateTime; import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotBlank; import lombok.Getter; import lombok.Setter; import lombok.experimental.Accessors; @@ -30,9 +31,11 @@ public class LineInfo { private Integer id; @Schema(description = "线路名") + @NotBlank(message = "线路名不能为空", groups = {Creation.class, SaveData.class}) private String name; @Schema(description = "线路号") + @NotBlank(message = "线路号不能为空", groups = {Creation.class, SaveData.class}) private Integer lineId; @Schema(description = "线路配置") diff --git a/src/main/java/club/joylink/xiannccda/repository/IPublishedGiRepository.java b/src/main/java/club/joylink/xiannccda/repository/IPublishedGiRepository.java index f994a9a..0a574e4 100644 --- a/src/main/java/club/joylink/xiannccda/repository/IPublishedGiRepository.java +++ b/src/main/java/club/joylink/xiannccda/repository/IPublishedGiRepository.java @@ -20,4 +20,6 @@ public interface IPublishedGiRepository extends IService { Page paging(PublishedGIQueryDto query); List list(PublishedGIQueryDto query); + + PublishedGi queryByDto(PublishedGIQueryDto query); } diff --git a/src/main/java/club/joylink/xiannccda/repository/impl/PublishedGiRepository.java b/src/main/java/club/joylink/xiannccda/repository/impl/PublishedGiRepository.java index d58169f..aba38dd 100644 --- a/src/main/java/club/joylink/xiannccda/repository/impl/PublishedGiRepository.java +++ b/src/main/java/club/joylink/xiannccda/repository/impl/PublishedGiRepository.java @@ -56,4 +56,19 @@ public class PublishedGiRepository extends ServiceImpl !publishedGi.getColumn().equals("proto")); return list(wrapper); } + + @Override + public PublishedGi queryByDto(PublishedGIQueryDto query) { + LambdaQueryWrapper wrapper = Wrappers.lambdaQuery(); + if (StringUtils.isNotEmpty(query.getName())) { + wrapper.like(PublishedGi::getName, query.getName()); + } + if (StringUtils.isNotEmpty(query.getType())) { + wrapper.eq(PublishedGi::getType, query.getType()); + } + if (query.getLineId() != null) { + wrapper.eq(PublishedGi::getLineId, query.getLineId()); + } + return getOne(wrapper); + } } diff --git a/src/main/java/club/joylink/xiannccda/service/PublishedGiService.java b/src/main/java/club/joylink/xiannccda/service/PublishedGiService.java index 023cc5f..2e8e50f 100644 --- a/src/main/java/club/joylink/xiannccda/service/PublishedGiService.java +++ b/src/main/java/club/joylink/xiannccda/service/PublishedGiService.java @@ -44,7 +44,7 @@ public class PublishedGiService { // 删除已发布的绘图数据 LambdaQueryWrapper wrapper = Wrappers.lambdaQuery(); String name = StringUtils.isNotEmpty(publishedDto.getName()) ? publishedDto.getName() : drafting.getName(); - wrapper.eq(PublishedGi::getName, name).eq(PublishedGi::getType, drafting.getType()).eq(PublishedGi::getLineId, publishedDto.getLineId()); + wrapper.eq(PublishedGi::getType, drafting.getType()).eq(PublishedGi::getLineId, publishedDto.getLineId()); publishedGiRepository.remove(wrapper); // 删除发布数据 // 保存发布信息 PublishedGi publishedGi = new PublishedGi();