From 8e0decd25b9ec86b02d58de53dee1451f83d1566 Mon Sep 17 00:00:00 2001 From: huliguo <2023611923@qq.com> Date: 星期四, 10 七月 2025 23:48:35 +0800 Subject: [PATCH] 新增 --- src/main/java/com/linghu/controller/PlatformController.java | 28 ++++++++++++++++++++-------- 1 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/linghu/controller/PlatformController.java b/src/main/java/com/linghu/controller/PlatformController.java index af1e1c6..6cc20bd 100644 --- a/src/main/java/com/linghu/controller/PlatformController.java +++ b/src/main/java/com/linghu/controller/PlatformController.java @@ -3,10 +3,13 @@ import com.alibaba.excel.EasyExcel; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.linghu.mapper.ReferenceMapper; import com.linghu.model.common.ResponseResult; import com.linghu.model.entity.Platform; +import com.linghu.model.entity.Reference; import com.linghu.model.entity.Type; import com.linghu.model.excel.PlatformExcel; +import com.linghu.model.page.CustomPage; import com.linghu.service.PlatformService; import com.linghu.service.TypeService; @@ -38,6 +41,8 @@ private PlatformService platformService; @Autowired private TypeService typeService; + @Autowired + private ReferenceMapper referenceMapper; @PostMapping @ApiOperation(value = "添加平台") @@ -60,6 +65,11 @@ @DeleteMapping("/{platformId}") @ApiOperation(value = "删除平台") public ResponseResult<Void> delete(@PathVariable Integer platformId) { + //平台被引用了没 + Integer count = referenceMapper.selectCount(new LambdaQueryWrapper<Reference>().eq(Reference::getPlatform_id, platformId)); + if (count > 0) { + return ResponseResult.error("该平台被引用中,不能删除"); + } boolean success = platformService.removeById(platformId); if (success) { return ResponseResult.success(); @@ -78,11 +88,9 @@ return ResponseResult.error("平台域名不能为空"); } - boolean success = platformService.updateById(platform); - if (success) { - return ResponseResult.success(); - } - return ResponseResult.error("更新平台失败"); + platformService.updateById(platform); + + return ResponseResult.success(); } @GetMapping("/{platformId}") @@ -97,16 +105,20 @@ @GetMapping("/list") @ApiOperation("查询平台列表,不传页数和大小就查全部") - public ResponseResult<List<Platform>> list( + public ResponseResult<CustomPage<Platform>> list( @RequestParam(required = false) Integer page, @RequestParam(required = false) Integer pageSize) { if (page != null && pageSize != null) { Page<Platform> pageInfo = new Page<>(page, pageSize); Page<Platform> result = platformService.page(pageInfo); - return ResponseResult.success(result.getRecords()); + return ResponseResult.success(new CustomPage<>(result)); } else { List<Platform> list = platformService.list(); - return ResponseResult.success(list); + CustomPage<Platform> customPage = new CustomPage<>(new Page<>()); + customPage.setRecords(list); + customPage.setTotal(list.size()); + return ResponseResult.success(customPage); + } } -- Gitblit v1.7.1