From 8a0ae6d19d78d2295a10b1cc97bfe17e651234ea Mon Sep 17 00:00:00 2001
From: wu <731351411@qq.com>
Date: 星期五, 01 十二月 2023 08:08:28 +0800
Subject: [PATCH] 更新理片笼逻辑

---
 springboot-vue3/src/main/java/com/example/springboot/controller/CategoryController.java |   97 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 97 insertions(+), 0 deletions(-)

diff --git a/springboot-vue3/src/main/java/com/example/springboot/controller/CategoryController.java b/springboot-vue3/src/main/java/com/example/springboot/controller/CategoryController.java
new file mode 100644
index 0000000..3ecf88b
--- /dev/null
+++ b/springboot-vue3/src/main/java/com/example/springboot/controller/CategoryController.java
@@ -0,0 +1,97 @@
+package com.example.springboot.controller;
+
+import cn.hutool.core.collection.CollectionUtil;
+import com.example.springboot.security.util.SecurityUtil;
+import com.example.springboot.service.CategoryService;
+import com.example.springboot.entity.Category;
+import com.example.springboot.entity.vo.CategoryVo;
+import com.example.springboot.entity.vo.Result;
+import com.example.springboot.service.UserService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shiro.authz.annotation.RequiresPermissions;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.List;
+
+@RestController
+@Slf4j
+@Api(tags = "鍒嗙被")
+@RequestMapping("/api/category")
+public class CategoryController {
+    @Autowired
+    private CategoryService categoryService;
+    @Autowired
+    private UserService userService;
+
+    @ApiOperation(value = "鍒嗛〉鏌ヨ鍒嗙被")
+    @GetMapping("/selectPage")
+    @RequiresPermissions({"category:select"})
+    public Result selectPage(CategoryVo categoryVO) {
+        return Result.success(categoryService.selectPage(categoryVO));
+    }
+
+    @ApiOperation(value = "鍗曚釜鍒犻櫎鍒嗙被")
+    @PostMapping("/removeById")
+    @RequiresPermissions({"category:delete"})
+    public Result removeById(@RequestBody CategoryVo categoryVO) {
+        List<Category> categories = categoryService.selectList(categoryVO.getId(), false);
+        if (CollectionUtil.isNotEmpty(categories)) return Result.fail("璇ュ垎绫讳笅鍚湁瀛愰泦,涓嶅彲浠ュ垹闄�");
+        List<Long> longs = userService.selectChild(SecurityUtil.getCurrentUser().getId(), true);
+        boolean remove = categoryService.lambdaUpdate()
+                .in(Category::getCreator, longs)
+                .eq(Category::getId, categoryVO.getId())
+                .remove();
+        if (remove) log.info("鐢ㄦ埛id{}鍒犻櫎鍒嗙被{}", SecurityUtil.getCurrentUser().getId(), categoryVO.getName());
+        return Result.success();
+    }
+
+    @ApiOperation(value = "淇敼鎴栬�呮洿鏂板垎绫�")
+    @PostMapping("/saveOrUpdate")
+    @RequiresPermissions({"category:update", "category:add"})
+    public Result saveOrUpdate(@RequestBody Category category) {
+        List<Long> longs = userService.selectChild(SecurityUtil.getCurrentUser().getId(), true);
+        Integer count = categoryService.lambdaQuery()
+                .eq(Category::getName, category.getName())
+                .in(Category::getCreator, longs)
+                .ne(category.getId() != null, Category::getId, category.getId())
+                .count();
+        if (count > 0) return Result.fail("璇ュ垎绫诲悕绉板凡瀛樺湪");
+        category.setCreator(category.getId() == null ? SecurityUtil.getCurrentUser().getId() : null);
+        categoryService.saveOrUpdate(category);
+        return Result.success();
+    }
+
+    @ApiOperation(value = "鏌ヨ鏌愪汉鍒涘缓鐨勫垎绫伙紝浣嗘槸鎺掗櫎褰撳墠閫変腑鐨勫垎绫伙紝鐢ㄦ埛淇敼鍒嗙被浣跨敤")
+    @GetMapping("/select")
+    @RequiresPermissions({"category:select"})
+    public Result select(Category category) {
+        List<Category> categories = categoryService.lambdaQuery()
+                .ne(category.getId() != null, Category::getId, category.getId())
+                .eq(Category::getCreator, SecurityUtil.getCurrentUser().getId())
+                .list();
+        return Result.success(categories);
+    }
+
+    @ApiOperation(value = "鏌ヨ鍒嗙被锛屽祵濂楁暟鎹粨鏋�")
+    @GetMapping("/selectChilds")
+    @RequiresPermissions({"category:select"})
+    public Result selectChilds(Category category) {
+        return Result.success(categoryService.selectChilds(SecurityUtil.getCurrentUser().getId()));
+    }
+
+    @ApiOperation(value = "閫氳繃id鏌ヨ鍒嗙被")
+    @GetMapping("/getById")
+    @RequiresPermissions({"category:select"})
+    public Result getById(Category category) {
+        Category one = categoryService.lambdaQuery().eq(Category::getCreator, SecurityUtil.getCurrentUser().getId())
+                .eq(Category::getId, category.getId()).one();
+        return Result.success(one);
+    }
+}
\ No newline at end of file

--
Gitblit v1.8.0