From 5da53ab90d6152de28b8475cd9ccaa00abba45e8 Mon Sep 17 00:00:00 2001
From: zepengdev <lzpsmith@outlook.com>
Date: Thu, 26 Jun 2025 22:45:18 +0800
Subject: [PATCH] fix: 优化店铺添加,预检查店铺名称,返回添加的店铺信息

---
 oying-system/src/main/java/com/oying/modules/pc/store/rest/StoreController.java |   65 +++++++++++++++++---------------
 1 files changed, 34 insertions(+), 31 deletions(-)

diff --git a/oying-system/src/main/java/com/oying/modules/pc/store/rest/StoreController.java b/oying-system/src/main/java/com/oying/modules/pc/store/rest/StoreController.java
index 36a5a1d..552f567 100644
--- a/oying-system/src/main/java/com/oying/modules/pc/store/rest/StoreController.java
+++ b/oying-system/src/main/java/com/oying/modules/pc/store/rest/StoreController.java
@@ -1,15 +1,21 @@
 package com.oying.modules.pc.store.rest;
 
-import com.oying.modules.pc.common.core.domain.R;
-import com.oying.modules.pc.common.id.StoreIdGenerator;
+import cn.hutool.core.collection.ListUtil;
+import cn.hutool.core.util.ObjectUtil;
 import com.oying.modules.pc.store.domain.Store;
-import com.oying.modules.pc.store.domain.dto.*;
+import com.oying.modules.pc.store.domain.dto.StoreCreateRequest;
+import com.oying.modules.pc.store.domain.dto.StoreQueryCriteria;
+import com.oying.modules.pc.store.domain.dto.StoreUpdateRequest;
 import com.oying.modules.pc.store.service.StoreService;
-import com.oying.utils.SecurityUtils;
+import com.oying.utils.R;
+import io.swagger.annotations.ApiOperation;
 import lombok.RequiredArgsConstructor;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.*;
 
-import java.time.ZonedDateTime;
+import java.util.List;
+import java.util.Optional;
 
 /**
  * 店铺
@@ -24,45 +30,42 @@
 
     private final StoreService storeService;
 
-    @GetMapping(value = "/page")
-    public R<?> getStoresByPage(@RequestBody StoreQueryCriteria criteria) {
-        return R.success(storeService.queryByPage(criteria));
+    @GetMapping(value = "/list")
+    @ApiOperation("查询所有店铺")
+    public ResponseEntity<?> getStores(StoreQueryCriteria criteria) {
+        List<Store> storeList = Optional.ofNullable(storeService.queryAll(criteria)).orElse(ListUtil.empty());
+        return ResponseEntity.ok(R.success(storeList));
     }
 
-    @GetMapping(value = "/list")
-    public R<?> getStores(@RequestBody StoreQueryCriteria criteria) {
-        return R.success(storeService.queryAll(criteria));
+    @GetMapping(value = "/page")
+    @ApiOperation("查询所有店铺")
+    public ResponseEntity<?> getStoresByPage(StoreQueryCriteria criteria) {
+        return ResponseEntity.ok(R.success(storeService.queryByPage(criteria)));
     }
 
     @GetMapping(value = "/{storeId}")
-    public R<?> getStoreById(@PathVariable("storeId") Long storeId) {
-        return R.success(storeService.getById(storeId));
+    @ApiOperation("查询店铺")
+    public ResponseEntity<?> getStoreById(@PathVariable Long storeId) {
+        return ResponseEntity.ok(R.success(storeService.getById(storeId)));
     }
 
     @GetMapping(value = "/{storeId}/details")
-    public R<?> getStoreDetailsById(@PathVariable("storeId") Long storeId) {
-        return R.success(storeService.getById(storeId));
+    public ResponseEntity<?> getStoreDetailsById(@PathVariable("storeId") Long storeId) {
+        return ResponseEntity.ok(R.success(storeService.getById(storeId)));
     }
 
-    @PostMapping(value = "/createEmpty")
-    public R<?> createEmpty(@RequestBody StoreCreateRequest request) {
-        Store store = new Store();
-        store.setStoreId(StoreIdGenerator.getId());
-        store.setMerchantId(SecurityUtils.getCurrentUserId());
-        store.setCreateBy(SecurityUtils.getCurrentUserId());
-        store.setCreateTime(ZonedDateTime.now());
-        storeService.save(store);
-        return R.success();
+    @PostMapping
+    @ApiOperation("创建店铺")
+    public ResponseEntity<?> create(@RequestBody StoreCreateRequest request) {
+        return ResponseEntity.status(HttpStatus.CREATED).body(R.success(storeService.create(request)));
     }
 
-    /**
-     * 修改店铺信息
-     */
     @PostMapping(value = "/{storeId}")
-    public R<?> update(@PathVariable("storeId") Long storeId, @RequestBody Store store) {
-        store.setStoreId(storeId);
-        storeService.updateById(store);
-        return R.success();
+    @ApiOperation("修改店铺")
+    public ResponseEntity<?> update(@PathVariable("storeId") Long storeId, @RequestBody StoreUpdateRequest request) {
+        request.setStoreId(ObjectUtil.defaultIfNull(request.getStoreId(), storeId));
+        storeService.update(request);
+        return ResponseEntity.noContent().build();
     }
 
 }

--
Gitblit v1.9.3