彭雪彬
2025-07-15 a7501803a3ca43310e57a5dd912e5047919c2e43
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package com.oying.modules.pc.store.rest;
 
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.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.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.util.List;
import java.util.Optional;
 
/**
 * 店铺
 *
 * @author lzp
 * @date 2025-04-22
 */
@RestController
@RequestMapping("/api/pc/store")
@RequiredArgsConstructor
public class StoreController {
 
    private final StoreService storeService;
 
    @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 = "/page")
    @ApiOperation("查询所有店铺")
    public ResponseEntity<?> getStoresByPage(StoreQueryCriteria criteria) {
        return ResponseEntity.ok(R.success(storeService.queryByPage(criteria)));
    }
 
    @GetMapping(value = "/{storeId}")
    @ApiOperation("查询店铺")
    public ResponseEntity<?> getStoreById(@PathVariable Long storeId) {
        return ResponseEntity.ok(R.success(storeService.getById(storeId)));
    }
 
    @GetMapping(value = "/{storeId}/details")
    public ResponseEntity<?> getStoreDetailsById(@PathVariable("storeId") Long storeId) {
        return ResponseEntity.ok(R.success(storeService.getById(storeId)));
    }
 
    @GetMapping(value = "/{storeId}/name-check")
    public ResponseEntity<?> checkStoreName(@RequestParam String storeName) {
        return ResponseEntity.ok(R.success(storeService.existsStoreName(storeName)));
    }
 
    @PostMapping
    @ApiOperation("创建店铺")
    public ResponseEntity<?> create(@RequestBody StoreCreateRequest request) {
        return ResponseEntity.status(HttpStatus.CREATED).body(R.success(storeService.create(request)));
    }
 
    @PostMapping(value = "/{storeId}")
    @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();
    }
 
}