【使用注解方式代替构造方法注入】

This commit is contained in:
weizhihong 2023-07-04 13:34:42 +08:00
parent 92b6722334
commit b5e7def287
5 changed files with 128 additions and 124 deletions

View File

@ -10,6 +10,7 @@ import club.joylink.xiannccda.entity.PublishedGi;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.google.protobuf.GeneratedMessageV3.Builder;
import com.google.protobuf.InvalidProtocolBufferException;
import io.swagger.v3.oas.models.security.SecurityScheme.In;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -87,6 +88,11 @@ public class LineGraphicDataRepository {
return List.of();
}
/** 删除线路绘图数据 */
public static void removeLineGraph(Integer id) {
lineGraphMap.remove(id);
}
/**
* 构建程序中的区段信息
*

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 lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
@ -16,9 +17,7 @@ import java.security.Principal;
import java.util.List;
/**
* <p>
* 线路信息 前端控制器
* </p>
*
* @author walker-sheng
* @since 2023-06-06
@ -26,70 +25,63 @@ import java.util.List;
@RestController
@RequestMapping("/api/lineInfo")
@Tag(name = "线路信息管理接口")
@RequiredArgsConstructor
public class LineInfoController {
/**
* 线路持久层简单管理
*/
final ILineInfoRepository lineInfoRepository;
/** 线路持久层简单管理 */
final ILineInfoRepository lineInfoRepository;
/**
* 线路业务处理service
*/
final LineInfoService lineInfoService;
/** 线路业务处理service */
final LineInfoService lineInfoService;
public LineInfoController(ILineInfoRepository lineInfoRepository, LineInfoService lineInfoService) {
this.lineInfoRepository = lineInfoRepository;
this.lineInfoService = lineInfoService;
}
@GetMapping("/paging")
@SecurityRequirement(name = "jwt")
@Operation(summary = "分页查询线路信息")
@ApiResponse(description = "线路信息")
public Page<LineInfo> paging(LineInfoQueryDTO query) {
return lineInfoRepository.pageQuery(query);
}
@GetMapping("/paging")
@SecurityRequirement(name = "jwt")
@Operation(summary = "分页查询线路信息")
@ApiResponse(description = "线路信息")
public Page<LineInfo> paging(LineInfoQueryDTO query) {
return lineInfoRepository.pageQuery(query);
}
@GetMapping("/list")
@SecurityRequirement(name = "jwt")
@Operation(summary = "查询线路信息列表")
@ApiResponse(description = "线路信息列表")
public List<LineInfo> list(LineInfoQueryDTO query) {
return lineInfoRepository.list(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 = "创建线路")
@ApiResponse(description = "线路信息")
public LineInfo create(
Principal user, @RequestBody @Validated(LineInfo.Creation.class) LineInfo lineInfo) {
return lineInfoService.create(user, lineInfo);
}
@PostMapping("")
@SecurityRequirement(name = "jwt")
@Operation(summary = "创建线路")
@ApiResponse(description = "线路信息")
public LineInfo create(Principal user
, @RequestBody @Validated(LineInfo.Creation.class) LineInfo lineInfo) {
return lineInfoService.create(user, lineInfo);
}
@GetMapping("/{id}")
@SecurityRequirement(name = "jwt")
@Operation(summary = "获取线路详情数据")
@ApiResponse(description = "线路详情数据")
public LineInfo getById(@PathVariable Integer id) {
return lineInfoRepository.getById(id);
}
@GetMapping("/{id}")
@SecurityRequirement(name = "jwt")
@Operation(summary = "获取线路详情数据")
@ApiResponse(description = "线路详情数据")
public LineInfo getById(@PathVariable Integer id) {
return lineInfoRepository.getById(id);
}
@PutMapping("/{id}")
@SecurityRequirement(name = "jwt")
@Operation(summary = "更新线路数据")
@ApiResponse(description = "更新成功失败标识")
public boolean updateData(
@PathVariable Integer id,
@RequestBody @Validated(LineInfo.SaveData.class) LineInfo lineInfo) {
return lineInfoService.updateData(id, lineInfo);
}
@PutMapping("/{id}")
@SecurityRequirement(name = "jwt")
@Operation(summary = "更新线路数据")
@ApiResponse(description = "更新成功失败标识")
public boolean updateData(@PathVariable Integer id
, @RequestBody @Validated(LineInfo.SaveData.class) LineInfo lineInfo) {
return lineInfoService.updateData(id, lineInfo);
}
@DeleteMapping("/{id}")
@SecurityRequirement(name = "jwt")
@Operation(summary = "删除线路数据")
@ApiResponse(description = "线路数据")
public boolean deleteById(@PathVariable Integer id) {
return lineInfoRepository.removeById(id);
}
@DeleteMapping("/{id}")
@SecurityRequirement(name = "jwt")
@Operation(summary = "删除线路数据")
@ApiResponse(description = "线路数据")
public boolean deleteById(@PathVariable Integer id) {
return lineInfoRepository.removeById(id);
}
}

View File

@ -1,5 +1,6 @@
package club.joylink.xiannccda.controller;
import club.joylink.xiannccda.ats.cache.LineGraphicDataRepository;
import club.joylink.xiannccda.dto.PublishedGIDTO;
import club.joylink.xiannccda.dto.PublishedGIDTO.LineType;
import club.joylink.xiannccda.dto.PublishedGIQueryDTO;
@ -11,6 +12,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 lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
@ -26,18 +28,13 @@ import java.util.List;
@RestController
@RequestMapping("/api/publishedGi")
@Tag(name = "发布图形管理接口")
@RequiredArgsConstructor
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 = "查询分页发布图形数据")
@ -88,7 +85,7 @@ public class PublishedGiController {
@Operation(summary = "删除发布图形数据")
@ApiResponse(description = "删除发布图形数据")
public boolean deleteById(@PathVariable Integer id) {
return publishedGiRepository.removeById(id);
return publishedGiService.remove(id);
}
@GetMapping("/publish/lineNetwork/info")

View File

@ -9,67 +9,70 @@ import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.security.Principal;
import java.time.LocalDateTime;
/**
* 线路服务
*/
/** 线路服务 */
@Service
@RequiredArgsConstructor
public class LineInfoService {
final ILineInfoRepository lineInfoRepository;
final ILineInfoRepository lineInfoRepository;
public LineInfoService(ILineInfoRepository lineInfoRepository) {
this.lineInfoRepository = lineInfoRepository;
/**
* 创建业务处理方法
*
* @param user 用户
* @param lineInfo 提交信息
* @return 保存后的信息
*/
public LineInfo create(Principal user, LineInfo lineInfo) {
// 可以做权限判断
LambdaQueryWrapper<LineInfo> wrapper = Wrappers.lambdaQuery();
wrapper.eq(LineInfo::getLineId, lineInfo.getLineId());
long count = lineInfoRepository.count(wrapper);
if (count > 0) {
throw BusinessExceptionAssertEnum.DATA_ALREADY_EXISTS.exception(
String.format("线路【%s】已存在", lineInfo.getLineId()));
}
lineInfo.setCreatedAt(LocalDateTime.now());
lineInfo.setUpdateAt(LocalDateTime.now());
lineInfoRepository.save(lineInfo);
return lineInfo;
}
/**
* 创建业务处理方法
* @param user 用户
* @param lineInfo 提交信息
* @return 保存后的信息
*/
public LineInfo create(Principal user, LineInfo lineInfo) {
// 可以做权限判断
LambdaQueryWrapper<LineInfo> wrapper = Wrappers.lambdaQuery();
wrapper.eq(LineInfo::getLineId, lineInfo.getLineId());
long count = lineInfoRepository.count(wrapper);
if (count > 0) {
throw BusinessExceptionAssertEnum.DATA_ALREADY_EXISTS.exception(String.format("线路【%s】已存在", lineInfo.getLineId()));
}
lineInfo.setCreatedAt(LocalDateTime.now());
lineInfo.setUpdateAt(LocalDateTime.now());
lineInfoRepository.save(lineInfo);
return lineInfo;
/**
* 更新线路业务信息
*
* @param id 主键
* @param lineInfo 提交信息
* @return 更新结果
*/
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));
}
/**
* 更新线路业务信息
* @param id 主键
* @param lineInfo 提交信息
* @return 更新结果
*/
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));
}
// if (StringUtils.isNotEmpty(lineInfo.getConfig()) && !JSON.isValid(lineInfo.getConfig())) {
// throw BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.exception(String.format("线路[%s]config非JSON格式", lineInfo.getConfig()));
// }
LambdaQueryWrapper<LineInfo> wrapper = Wrappers.lambdaQuery();
wrapper.eq(LineInfo::getLineId, lineInfo.getLineId()).ne(LineInfo::getId, id);
long count = lineInfoRepository.count(wrapper);
if (count > 0) {
throw BusinessExceptionAssertEnum.DATA_ALREADY_EXISTS.exception(String.format("线路ID[%s]已存在", lineInfo.getLineId()));
}
lineInfo.setId(id);
lineInfo.setUpdateAt(LocalDateTime.now());
return lineInfoRepository.updateById(lineInfo);
// if (StringUtils.isNotEmpty(lineInfo.getConfig()) &&
// !JSON.isValid(lineInfo.getConfig())) {
// throw
// BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.exception(String.format("线路[%s]config非JSON格式",
// lineInfo.getConfig()));
// }
LambdaQueryWrapper<LineInfo> wrapper = Wrappers.lambdaQuery();
wrapper.eq(LineInfo::getLineId, lineInfo.getLineId()).ne(LineInfo::getId, id);
long count = lineInfoRepository.count(wrapper);
if (count > 0) {
throw BusinessExceptionAssertEnum.DATA_ALREADY_EXISTS.exception(
String.format("线路ID[%s]已存在", lineInfo.getLineId()));
}
lineInfo.setId(id);
lineInfo.setUpdateAt(LocalDateTime.now());
return lineInfoRepository.updateById(lineInfo);
}
}

View File

@ -13,6 +13,7 @@ import club.joylink.xiannccda.repository.IPublishedGiRepository;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import java.util.Objects;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -21,6 +22,7 @@ import java.security.Principal;
import java.time.LocalDateTime;
@Service
@RequiredArgsConstructor
public class PublishedGiService {
final IPublishedGiRepository publishedGiRepository;
@ -29,15 +31,6 @@ public class PublishedGiService {
final ILineInfoRepository lineInfoRepository;
public PublishedGiService(
IPublishedGiRepository publishedGiRepository,
IDraftingRepository draftingRepository,
ILineInfoRepository lineInfoRepository) {
this.publishedGiRepository = publishedGiRepository;
this.draftingRepository = draftingRepository;
this.lineInfoRepository = lineInfoRepository;
}
/**
* 发布草稿数据
*
@ -89,4 +82,17 @@ public class PublishedGiService {
LineGraphicDataRepository.putLineGraph(publishedGi); // 发布后更新内存里的数据
return publishedGi;
}
/**
* 移除发布的地图数据
*
* @param id 地图ID
* @return 移除结果
*/
@Transactional(rollbackFor = Exception.class)
public boolean remove(Integer id) {
boolean result = publishedGiRepository.removeById(id);
LineGraphicDataRepository.removeLineGraph(id);
return result;
}
}