This commit is contained in:
xzb 2023-06-08 15:14:02 +08:00
commit 78e8c82a46
7 changed files with 57 additions and 6 deletions

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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 {
}
}

View File

@ -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 = "线路配置")

View File

@ -20,4 +20,6 @@ public interface IPublishedGiRepository extends IService<PublishedGi> {
Page<PublishedGi> paging(PublishedGIQueryDto query);
List<PublishedGi> list(PublishedGIQueryDto query);
PublishedGi queryByDto(PublishedGIQueryDto query);
}

View File

@ -56,4 +56,19 @@ public class PublishedGiRepository extends ServiceImpl<PublishedGiMapper, Publis
wrapper.select(PublishedGi.class, publishedGi -> !publishedGi.getColumn().equals("proto"));
return list(wrapper);
}
@Override
public PublishedGi queryByDto(PublishedGIQueryDto query) {
LambdaQueryWrapper<PublishedGi> 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);
}
}

View File

@ -44,7 +44,7 @@ public class PublishedGiService {
// 删除已发布的绘图数据
LambdaQueryWrapper<PublishedGi> 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();