【线路管理接口;发布图形接口】
This commit is contained in:
parent
a295a59f06
commit
f213530179
@ -8,9 +8,11 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
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.web.bind.annotation.*;
|
||||
|
||||
import java.security.Principal;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@ -22,6 +24,7 @@ import java.security.Principal;
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/lineInfo")
|
||||
@Tag(name = "线路信息管理接口")
|
||||
public class LineInfoController {
|
||||
|
||||
/**
|
||||
@ -47,6 +50,14 @@ public class LineInfoController {
|
||||
return lineInfoRepository.pageQuery(query);
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
@SecurityRequirement(name = "jwt")
|
||||
@Operation(summary = "查询线路信息列表")
|
||||
@ApiResponse(description = "线路信息列表")
|
||||
public List<LineInfo> list(LineInfoQueryDto query) {
|
||||
return lineInfoRepository.list(query);
|
||||
}
|
||||
|
||||
@PostMapping("")
|
||||
@SecurityRequirement(name = "jwt")
|
||||
@Operation(summary = "创建线路")
|
||||
@ -57,9 +68,9 @@ public class LineInfoController {
|
||||
|
||||
@GetMapping("/{id}")
|
||||
@SecurityRequirement(name = "jwt")
|
||||
@Operation(summary = "获取线路数据")
|
||||
@ApiResponse(description = "线路数据")
|
||||
public LineInfo getById(@PathVariable Long id) {
|
||||
@Operation(summary = "获取线路详情数据")
|
||||
@ApiResponse(description = "线路详情数据")
|
||||
public LineInfo getById(@PathVariable Integer id) {
|
||||
return lineInfoRepository.getById(id);
|
||||
}
|
||||
|
||||
@ -67,7 +78,7 @@ public class LineInfoController {
|
||||
@SecurityRequirement(name = "jwt")
|
||||
@Operation(summary = "保存线路数据")
|
||||
@ApiResponse(description = "保存成功失败标识")
|
||||
public boolean updateData(@PathVariable Long id, @RequestBody LineInfo lineInfo) {
|
||||
public boolean updateData(@PathVariable Integer id, @RequestBody LineInfo lineInfo) {
|
||||
return lineInfoService.updateData(id, lineInfo);
|
||||
}
|
||||
|
||||
@ -75,7 +86,7 @@ public class LineInfoController {
|
||||
@SecurityRequirement(name = "jwt")
|
||||
@Operation(summary = "删除线路数据")
|
||||
@ApiResponse(description = "线路数据")
|
||||
public boolean deleteById(@PathVariable Long id) {
|
||||
public boolean deleteById(@PathVariable Integer id) {
|
||||
return lineInfoRepository.removeById(id);
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,19 @@
|
||||
package club.joylink.xiannccda.controller;
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import club.joylink.xiannccda.dto.PublishedGIDto;
|
||||
import club.joylink.xiannccda.dto.PublishedGIQueryDto;
|
||||
import club.joylink.xiannccda.entity.PublishedGi;
|
||||
import club.joylink.xiannccda.repository.IPublishedGiRepository;
|
||||
import club.joylink.xiannccda.service.PublishedGiService;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
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.web.bind.annotation.*;
|
||||
|
||||
import java.security.Principal;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@ -13,6 +25,48 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/publishedGi")
|
||||
@Tag(name = "发布图形管理接口")
|
||||
public class PublishedGiController {
|
||||
|
||||
final IPublishedGiRepository publishedGiRepository;
|
||||
|
||||
final PublishedGiService publishedGiService;
|
||||
|
||||
public PublishedGiController(IPublishedGiRepository publishedGiRepository, PublishedGiService publishedGiService) {
|
||||
this.publishedGiRepository = publishedGiRepository;
|
||||
this.publishedGiService = publishedGiService;
|
||||
}
|
||||
|
||||
@GetMapping("/paging")
|
||||
@SecurityRequirement(name = "jwt")
|
||||
@Operation(summary = "查询分页发布图形数据")
|
||||
@ApiResponse(description = "查询发布图形数据")
|
||||
public Page<PublishedGi> paging(PublishedGIQueryDto query) {
|
||||
return publishedGiRepository.paging(query);
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
@SecurityRequirement(name = "jwt")
|
||||
@Operation(summary = "查询发布图形数据列表")
|
||||
@ApiResponse(description = "查询发布图形数据列表")
|
||||
public List<PublishedGi> list(PublishedGIQueryDto query) {
|
||||
return publishedGiRepository.list(query);
|
||||
}
|
||||
|
||||
@PostMapping("/publish")
|
||||
@SecurityRequirement(name = "jwt")
|
||||
@Operation(summary = "发布草稿图形数据")
|
||||
@ApiResponse(description = "发布草稿图形数据")
|
||||
public PublishedGi publish(Principal user, @RequestBody PublishedGIDto publishedDto) {
|
||||
return publishedGiService.publish(user, publishedDto);
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
@SecurityRequirement(name = "jwt")
|
||||
@Operation(summary = "删除发布图形数据")
|
||||
@ApiResponse(description = "删除发布图形数据")
|
||||
public boolean deleteById(@PathVariable Integer id) {
|
||||
return publishedGiRepository.removeById(id);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -10,12 +10,11 @@ import lombok.Setter;
|
||||
*/
|
||||
@Setter
|
||||
@Getter
|
||||
@Schema(name = "查询线路信息列表参数")
|
||||
public class LineInfoQueryDto extends PageDTO {
|
||||
|
||||
@Schema(description = "线路名")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "线路号")
|
||||
private Integer lineId;
|
||||
|
||||
}
|
||||
|
22
src/main/java/club/joylink/xiannccda/dto/PublishedGIDto.java
Normal file
22
src/main/java/club/joylink/xiannccda/dto/PublishedGIDto.java
Normal file
@ -0,0 +1,22 @@
|
||||
package club.joylink.xiannccda.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Schema(name = "发布参数")
|
||||
public class PublishedGIDto {
|
||||
@Schema(description = "发布图形界面名称")
|
||||
private String name;
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "关联的线路号")
|
||||
private Integer lineId;
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "草稿数据主键")
|
||||
private Integer draftingId;
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package club.joylink.xiannccda.dto;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Schema(name = "查询发布列表参数")
|
||||
public class PublishedGIQueryDto extends PageDTO {
|
||||
|
||||
@Schema(description = "发布图形界面名称")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "图形界面类型")
|
||||
private String type;
|
||||
|
||||
@Schema(description = "关联的线路号")
|
||||
private Integer lineId;
|
||||
}
|
@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.time.LocalDateTime;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.Accessors;
|
||||
@ -54,4 +55,12 @@ public class LineInfo {
|
||||
public static final String CREATED_AT = "created_at";
|
||||
|
||||
public static final String UPDATE_AT = "update_at";
|
||||
|
||||
public interface Creation {
|
||||
|
||||
}
|
||||
|
||||
public interface SaveData {
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
import java.security.Principal;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@ -27,9 +28,9 @@ public interface ILineInfoRepository extends IService<LineInfo> {
|
||||
Page<LineInfo> pageQuery(LineInfoQueryDto query);
|
||||
|
||||
/**
|
||||
* 获取线路详细信息
|
||||
* @param id 线路ID
|
||||
* @return 线路详细信息
|
||||
* 查询线路数据列表
|
||||
* @param query 查询参数
|
||||
* @return 数据列表
|
||||
*/
|
||||
LineInfo getById(Long id);
|
||||
List<LineInfo> list(LineInfoQueryDto query);
|
||||
}
|
||||
|
@ -1,8 +1,12 @@
|
||||
package club.joylink.xiannccda.repository;
|
||||
|
||||
import club.joylink.xiannccda.dto.PublishedGIQueryDto;
|
||||
import club.joylink.xiannccda.entity.PublishedGi;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务类
|
||||
@ -13,4 +17,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||
*/
|
||||
public interface IPublishedGiRepository extends IService<PublishedGi> {
|
||||
|
||||
Page<PublishedGi> paging(PublishedGIQueryDto query);
|
||||
|
||||
List<PublishedGi> list(PublishedGIQueryDto query);
|
||||
}
|
||||
|
@ -11,6 +11,8 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务实现类
|
||||
@ -40,16 +42,16 @@ public class LineInfoRepository extends ServiceImpl<LineInfoMapper, LineInfo> im
|
||||
return page(query, wrapper);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据主键获取线路信息
|
||||
* @param id 线路ID
|
||||
* @return 线路信息
|
||||
*/
|
||||
@Override
|
||||
public LineInfo getById(Long id) {
|
||||
public List<LineInfo> list(LineInfoQueryDto query) {
|
||||
LambdaQueryWrapper<LineInfo> wrapper = Wrappers.lambdaQuery();
|
||||
wrapper.eq(LineInfo::getId, id);
|
||||
return getOne(wrapper);
|
||||
if (StringUtils.isNotEmpty(query.getName())) {
|
||||
wrapper.like(LineInfo::getName, query.getName());
|
||||
}
|
||||
if (query.getLineId() != null) {
|
||||
wrapper.eq(LineInfo::getLineId, query.getLineId());
|
||||
}
|
||||
wrapper.select(LineInfo.class, info -> !info.getColumn().equals("config"));
|
||||
return list(wrapper);
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,19 @@
|
||||
package club.joylink.xiannccda.repository.impl;
|
||||
|
||||
import club.joylink.xiannccda.dto.PublishedGIQueryDto;
|
||||
import club.joylink.xiannccda.entity.LineInfo;
|
||||
import club.joylink.xiannccda.entity.PublishedGi;
|
||||
import club.joylink.xiannccda.mapper.PublishedGiMapper;
|
||||
import club.joylink.xiannccda.repository.IPublishedGiRepository;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务实现类
|
||||
@ -17,4 +25,35 @@ import org.springframework.stereotype.Service;
|
||||
@Service
|
||||
public class PublishedGiRepository extends ServiceImpl<PublishedGiMapper, PublishedGi> implements IPublishedGiRepository {
|
||||
|
||||
@Override
|
||||
public Page<PublishedGi> paging(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());
|
||||
}
|
||||
wrapper.select(PublishedGi.class, publishedGi -> !publishedGi.getColumn().equals("proto"));
|
||||
return page(query, wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PublishedGi> list(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());
|
||||
}
|
||||
wrapper.select(PublishedGi.class, publishedGi -> !publishedGi.getColumn().equals("proto"));
|
||||
return list(wrapper);
|
||||
}
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ public class LineInfoService {
|
||||
* @param lineInfo 提交信息
|
||||
* @return 更新结果
|
||||
*/
|
||||
public boolean updateData(Long id, LineInfo lineInfo) {
|
||||
public boolean updateData(Integer id, LineInfo lineInfo) {
|
||||
LineInfo oldLineInfo = lineInfoRepository.getById(id);
|
||||
if (oldLineInfo == null) {
|
||||
throw BusinessExceptionAssertEnum.DATA_NOT_EXIST.exception(String.format("线路[%s]信息不存在", id));
|
||||
@ -61,9 +61,9 @@ public class LineInfoService {
|
||||
wrapper.eq(LineInfo::getName, lineInfo.getName()).ne(LineInfo::getId, id);
|
||||
long count = lineInfoRepository.count(wrapper);
|
||||
if (count > 0) {
|
||||
throw BusinessExceptionAssertEnum.DATA_ALREADY_EXISTS.exception("线路名称已存在");
|
||||
throw BusinessExceptionAssertEnum.DATA_ALREADY_EXISTS.exception(String.format("线路名称[%s]已存在", lineInfo.getName()));
|
||||
}
|
||||
lineInfo.setId(id.intValue());
|
||||
lineInfo.setId(id);
|
||||
lineInfo.setUpdateAt(LocalDateTime.now());
|
||||
return lineInfoRepository.updateById(lineInfo);
|
||||
}
|
||||
|
@ -0,0 +1,60 @@
|
||||
package club.joylink.xiannccda.service;
|
||||
|
||||
import club.joylink.xiannccda.dto.PublishedGIDto;
|
||||
import club.joylink.xiannccda.entity.Drafting;
|
||||
import club.joylink.xiannccda.entity.PublishedGi;
|
||||
import club.joylink.xiannccda.exception.BusinessExceptionAssertEnum;
|
||||
import club.joylink.xiannccda.repository.IDraftingRepository;
|
||||
import club.joylink.xiannccda.repository.IPublishedGiRepository;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.security.Principal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Service
|
||||
public class PublishedGiService {
|
||||
|
||||
final IPublishedGiRepository publishedGiRepository;
|
||||
|
||||
final IDraftingRepository draftingRepository;
|
||||
|
||||
|
||||
public PublishedGiService(IPublishedGiRepository publishedGiRepository, IDraftingRepository draftingRepository) {
|
||||
this.publishedGiRepository = publishedGiRepository;
|
||||
this.draftingRepository = draftingRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* 发布草稿数据
|
||||
* @param user 用户
|
||||
* @param publishedDto 草稿数据
|
||||
* @return 发布后的实体数据
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public PublishedGi publish(Principal user, PublishedGIDto publishedDto) {
|
||||
// 查询草稿信息
|
||||
Drafting drafting = draftingRepository.getById(publishedDto.getDraftingId());
|
||||
if (drafting == null) {
|
||||
throw BusinessExceptionAssertEnum.DATA_NOT_EXIST.exception(String.format("草稿[%s]信息不存在", publishedDto.getDraftingId()));
|
||||
}
|
||||
// 删除已发布的绘图数据
|
||||
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());
|
||||
publishedGiRepository.remove(wrapper); // 删除发布数据
|
||||
// 保存发布信息
|
||||
PublishedGi publishedGi = new PublishedGi();
|
||||
publishedGi.setName(name);
|
||||
publishedGi.setType(drafting.getType());
|
||||
publishedGi.setLineId(publishedDto.getLineId());
|
||||
publishedGi.setProto(drafting.getProto());
|
||||
publishedGi.setUserId(Integer.valueOf(user.getName()));
|
||||
publishedGi.setPublishAt(LocalDateTime.now());
|
||||
publishedGiRepository.save(publishedGi);
|
||||
return publishedGi;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user