From b7ff8446a58d59e7df8a588104c231c7af7d8573 Mon Sep 17 00:00:00 2001
From: guyue <1721849008@qq.com>
Date: 星期五, 11 七月 2025 14:31:15 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 src/main/java/com/linghu/controller/PlatformController.java |   37 +++++++++++++++++++++++++++----------
 1 files changed, 27 insertions(+), 10 deletions(-)

diff --git a/src/main/java/com/linghu/controller/PlatformController.java b/src/main/java/com/linghu/controller/PlatformController.java
index e71fb80..396a0fb 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;
 
@@ -23,6 +26,7 @@
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 
+import java.time.LocalDateTime;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
@@ -37,6 +41,8 @@
     private PlatformService platformService;
     @Autowired
     private TypeService typeService;
+    @Autowired
+    private ReferenceMapper referenceMapper;
 
     @PostMapping
     @ApiOperation(value = "添加平台")
@@ -57,7 +63,13 @@
     }
 
     @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();
@@ -66,6 +78,7 @@
     }
 
     @PutMapping
+    @ApiOperation(value = "更新平台")
     public ResponseResult<Void> update(@RequestBody Platform platform) {
         // 校验平台名称和域名不能为空
         if (!StringUtils.hasText(platform.getPlatform_name())) {
@@ -75,14 +88,13 @@
             return ResponseResult.error("平台域名不能为空");
         }
 
-        boolean success = platformService.updateById(platform);
-        if (success) {
-            return ResponseResult.success();
-        }
-        return ResponseResult.error("更新平台失败");
+        platformService.updateById(platform);
+
+        return ResponseResult.success();
     }
 
     @GetMapping("/{platformId}")
+    @ApiOperation("根据id获取平台")
     public ResponseResult<Platform> getById(@PathVariable Integer platformId) {
         Platform platform = platformService.getById(platformId);
         if (platform != null) {
@@ -92,16 +104,21 @@
     }
 
     @GetMapping("/list")
-    public ResponseResult<List<Platform>> list(
+    @ApiOperation("查询平台列表,不传页数和大小就查全部")
+    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);
+
         }
     }
 
@@ -165,7 +182,7 @@
                 platform.setType_id(typeByName.getType_id());
 
                 // 设置创建时间(解决之前的数据库错误)
-                platform.setCreate_time(new Date());
+                platform.setCreate_time(LocalDateTime.now());
 
                 platforms.add(platform);
             }
@@ -180,7 +197,7 @@
                 platformService.saveBatch(platforms);
                 return ResponseResult.success("成功导入" + platforms.size() + "条数据");
             } else {
-                return ResponseResult.error("没有有效数据可导入");
+                return ResponseResult.success();
             }
 
         } catch (Exception e) {

--
Gitblit v1.7.1