xin
4 days ago 982313135d1c239fe3b20e4c5664781f92d40aca
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
package com.oying.modules.pc.store.rest;
 
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.ObjectUtil;
import com.oying.exception.BadRequestException;
import com.oying.modules.pc.store.domain.Store;
import com.oying.modules.pc.store.domain.dto.*;
import com.oying.modules.pc.store.domain.enums.StoreStatusEnum;
import com.oying.modules.pc.store.service.*;
import com.oying.modules.pc.store.view.StoreMerchantView;
import com.oying.modules.pc.store.view.StoreSimpleView;
import com.oying.utils.R;
import com.oying.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
 
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
 
/**
 * 店铺
 *
 * @author lzp
 * @date 2025-04-22
 */
@Api(tags = "店铺(商户端)")
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/pc/merchant/store")
public class StoreMerchantController {
 
    private final StoreService storeService;
    private final StoreCreateService storeCreateService;
    private final StoreQualificationService storeQualificationService;
    private final StoreQueryService storeQueryService;
    private final StoreMerchantService storeMerchantService;
 
    @GetMapping(value = "/list")
    @ApiOperation("查询所有店铺")
    //@PreAuthorize("@el.check('merchant:store:list')")
    public ResponseEntity<?> getList() {
        List<Store> stores = Optional.ofNullable(storeService.getUserStores(SecurityUtils.getCurrentUserId())).orElse(ListUtil.empty());
        return ResponseEntity.ok(R.success(stores));
    }
 
    @GetMapping(value = "/simple-list")
    @ApiOperation("查询所有店铺")
    //@PreAuthorize("@el.check('merchant:store:list')")
    public ResponseEntity<?> getSimpleStores() {
        List<Store> stores = Optional.ofNullable(storeService.getUserStores(SecurityUtils.getCurrentUserId())).orElse(ListUtil.empty());
        List<StoreSimpleView> storeViewList = stores.stream().map(i -> {
            StoreSimpleView view = new StoreSimpleView();
            BeanUtil.copyProperties(i, view, CopyOptions.create().setIgnoreNullValue(true));
            return view;
        }).collect(Collectors.toList());
        return ResponseEntity.ok(R.success(storeViewList));
    }
 
    @GetMapping(value = "/{storeId}")
    @ApiOperation("查询店铺")
    //@PreAuthorize("@el.check('merchant:store:getById')")
    public ResponseEntity<?> getStoreById(@PathVariable Long storeId) {
        Store store = storeService.getById(storeId);
        /*StoreMerchantView view = new StoreMerchantView();
        BeanUtils.copyProperties(store, view);*/
        return ResponseEntity.ok(R.success(store));
    }
 
    @GetMapping(value = "/{storeId}/details")
    @ApiOperation("查询店铺")
    //@PreAuthorize("@el.check('merchant:store:getById')")
    public ResponseEntity<?> getStoreDetailsById(@PathVariable Long storeId) {
        Store store = storeService.getById(storeId);
        if (ObjUtil.isNotEmpty(store)) {
            store.setQualifications(storeQualificationService.getByStoreId(storeId));
        }
        return ResponseEntity.ok(R.success(store));
    }
 
    @PostMapping
    @ApiOperation("创建店铺")
    //@PreAuthorize("@el.check('merchant:store:create')")
    public ResponseEntity<?> create(@RequestBody StoreCreateRequest request) {
        return ResponseEntity.status(HttpStatus.CREATED).body(storeMerchantService.createStore(request));
    }
 
    @PostMapping(value = "/{storeId}/audit/submit")
    @ApiOperation("提交审核")
    //@PreAuthorize("@el.check('merchant:store:create')")
    public ResponseEntity<?> submitAudit(@PathVariable Long storeId) {
        storeMerchantService.submitStoreAudit(storeId);
        return ResponseEntity.noContent().build();
    }
 
    /**
     * 修改店铺信息
     */
    @PutMapping(value = "/{storeId}")
    @ApiOperation("修改店铺")
    //@PreAuthorize("@el.check('merchant:store:update')" +
    //        " and @storeMerchantOwnershipService.check(#storeId)")
    public ResponseEntity<?> update(@PathVariable("storeId") Long storeId, @RequestBody StoreUpdateRequest request) {
        request.setStoreId(ObjectUtil.defaultIfNull(request.getStoreId(), storeId));
        storeMerchantService.updateStore(request);
        return ResponseEntity.noContent().build();
    }
 
    /**
     * 修改店铺LOGO
     */
    @PatchMapping(value = "/{storeId}/logo")
    @ApiOperation("修改店铺LOGO")
    //@PreAuthorize("@el.check('merchant:store:list')" +
    //        " and @storeMerchantOwnershipService.check(#storeId)")
    public ResponseEntity<?> updateLogo(@PathVariable("storeId") Long storeId,
                           @Validated(value = StoreFieldUpdateRequest.UpdateStoreLogoImageGroup.class)
                           @RequestBody StoreFieldUpdateRequest request) {
        Long logeImageId = Optional.ofNullable(request.getLogoImageId()).orElse(Long.getLong(request.getLogoImageUploadId()));
        storeService.updateLogo(storeId, logeImageId, request.getVersion());
        return ResponseEntity.noContent().build();
    }
 
    /**
     * 修改店铺名称
     */
    @PatchMapping(value = "/{storeId}/name")
    @ApiOperation("修改店铺名称")
    //@PreAuthorize("@el.check('merchant:store:name')" +
    //        " and @storeMerchantOwnershipService.check(#storeId)")
    public ResponseEntity<?> updateName(@PathVariable("storeId") Long storeId,
                           @Validated(value = StoreFieldUpdateRequest.UpdateStoreNameGroup.class)
                           @RequestBody StoreFieldUpdateRequest request) {
        StoreUpdateRequest updateRequest = new StoreUpdateRequest();
        updateRequest.setStoreId(storeId);
        updateRequest.setStoreName(request.getStoreName());
        storeMerchantService.updateStore(updateRequest);
        //storeMerchantService.saveRevisionStore(request, StoreRevisionTypeEnum.NAME_UPDATE);
        return ResponseEntity.noContent().build();
    }
 
    /**
     * 修改店铺简介
     */
    @PatchMapping(value = "/{storeId}/description")
    @ApiOperation("修改店铺简介")
    //@PreAuthorize("@el.check('merchant:store:description')" +
    //        " and @storeMerchantOwnershipService.check(#storeId)")
    public ResponseEntity<?> updateDescription(@PathVariable("storeId") Long storeId,
                                  @Validated(value = StoreFieldUpdateRequest.UpdateStoreDescriptionGroup.class)
                                  @RequestBody StoreFieldUpdateRequest request) {
        storeService.updateDescription(storeId, request.getDescription(), request.getVersion());
        return ResponseEntity.noContent().build();
    }
 
    /**
     * 修改店铺联系电话
     */
    @PatchMapping(value = "/{storeId}/contactPhone")
    @ApiOperation("修改店铺联系电话")
    /*@PreAuthorize("@el.check('merchant:store:list')" +
            " and @storeMerchantOwnershipService.check(#storeId)")*/
    public ResponseEntity<?> updateContactPhone(@PathVariable("storeId") Long storeId,
                                   @Validated(value = StoreFieldUpdateRequest.UpdateStoreContactPhoneGroup.class)
                                   @RequestBody StoreFieldUpdateRequest request) {
        storeService.updateContactPhone(storeId, request.getContactPhone(), request.getVersion());
        return ResponseEntity.noContent().build();
    }
 
    /**
     * 修改店铺地址
     */
    @PatchMapping(value = "/{storeId}/address")
    @ApiOperation("修改店铺地址")
    /*@PreAuthorize("@el.check('merchant:store:address')" +
            " and @storeMerchantOwnershipService.check(#storeId)")*/
    public ResponseEntity<?> updateAddress(@PathVariable("storeId") Long storeId,
                              @Validated(value = StoreFieldUpdateRequest.UpdateStoreAddressGroup.class)
                              @RequestBody StoreFieldUpdateRequest request) {
        storeService.updateAddress(storeId, request.getAddress(), request.getVersion());
        return ResponseEntity.noContent().build();
    }
 
    /**
     * 修改店铺坐标
     */
    @PatchMapping(value = "/{storeId}/location")
    @ApiOperation("修改店铺坐标")
    /*@PreAuthorize("@el.check('merchant:store:location')" +
            " and @storeMerchantOwnershipService.check(#storeId)")*/
    public ResponseEntity<?> updateLocation(@PathVariable("storeId") Long storeId,
                               @Validated(value = StoreFieldUpdateRequest.UpdateStoreLocationGroup.class)
                               @RequestBody StoreFieldUpdateRequest request) {
        storeService.updateLocation(storeId, request.getLongitude(), request.getLatitude(), request.getVersion());
        return ResponseEntity.noContent().build();
    }
 
    /**
     * 修改店铺配送范围
     */
    @PatchMapping(value = "/{storeId}/radius")
    @ApiOperation("修改店铺配送范围")
    /*@PreAuthorize("@el.check('merchant:store:radius')" +
            " and @storeMerchantOwnershipService.check(#storeId)")*/
    public ResponseEntity<?> updateRadius(@PathVariable("storeId") Long storeId,
                             @Validated(value = StoreFieldUpdateRequest.UpdateStoreRadiusGroup.class)
                             @RequestBody StoreFieldUpdateRequest request) {
        storeService.updateRadius(storeId, request.getRadius(), request.getVersion());
        return ResponseEntity.noContent().build();
    }
 
    /**
     * 修改店铺绑定的经营类目
     */
    @PatchMapping(value = "/{storeId}/platformCategory")
    @ApiOperation("修改店铺绑定的经营类目")
    /*@PreAuthorize("@el.check('merchant:store:platformCategory')" +
            " and @storeMerchantOwnershipService.check(#storeId)")*/
    public ResponseEntity<?> updatePlatformCategory(@PathVariable("storeId") Long storeId,
                                       @Validated(value = StoreFieldUpdateRequest.UpdateStorePlatformCategoryGroup.class)
                                       @RequestBody StoreFieldUpdateRequest request) {
        storeService.updatePlatformCategory(storeId, request.getPlatformCategoryId(), request.getVersion());
        return ResponseEntity.noContent().build();
    }
 
    /**
     * 修改店铺营业时间
     */
    @PatchMapping(value = "/{storeId}/businessHours")
    @ApiOperation("修改店铺营业时间")
    /*@PreAuthorize("@el.check('merchant:store:businessHours')" +
            " and @storeMerchantOwnershipService.check(#storeId)")*/
    public ResponseEntity<?> updateBusinessHours(@PathVariable("storeId") Long storeId,
                                    @Validated(value = StoreFieldUpdateRequest.UpdateStoreBusinessHoursGroup.class)
                                    @RequestBody StoreFieldUpdateRequest request) {
        storeService.updateBusinessHours(storeId, request.getOpenTime(), request.getCloseTime(), request.getVersion());
        return ResponseEntity.noContent().build();
    }
 
    /**
     * 修改起送金额
     */
    @PatchMapping(value = "/{storeId}/deliveryMinimum")
    @ApiOperation("修改起送金额")
    /*@PreAuthorize("@el.check('merchant:store:deliveryMinimum')" +
            " and @storeMerchantOwnershipService.check(#storeId)")*/
    public ResponseEntity<?> updateDeliveryMinimum(@PathVariable("storeId") Long storeId,
                                      @Validated(value = StoreFieldUpdateRequest.UpdateStoreDeliveryMinimumGroup.class)
                                      @RequestBody StoreFieldUpdateRequest request) {
        storeService.updateDeliveryMinimum(storeId, request.getDeliveryMinimum(), request.getVersion());
        return ResponseEntity.noContent().build();
    }
 
    /**
     * 修改配送费用
     */
    @PatchMapping(value = "/{storeId}/deliveryFee")
    @ApiOperation("修改配送费用")
    /*@PreAuthorize("@el.check('merchant:store:deliveryFee')" +
            " and @storeMerchantOwnershipService.check(#storeId)")*/
    public ResponseEntity<?> updateDeliveryFee(@PathVariable("storeId") Long storeId,
                                  @Validated(value = StoreFieldUpdateRequest.UpdateStoreDeliveryFeeGroup.class)
                                  @RequestBody StoreFieldUpdateRequest request) {
        storeService.updateDeliveryFee(storeId, request.getDeliveryFee(), request.getVersion());
        return ResponseEntity.noContent().build();
    }
 
    /**
     * 修改状态
     */
    @PatchMapping(value = "/{storeId}/businessStatus")
    @ApiOperation("修改营业状态")
    /*@PreAuthorize("@el.check('merchant:store:businessStatus')" +
            " and @storeMerchantOwnershipService.check(#storeId)")*/
    public ResponseEntity<?> businessStatus(@PathVariable("storeId") Long storeId,
                               @Validated(value = StoreFieldUpdateRequest.UpdateStoreBusinessStatusGroup.class)
                               @RequestBody StoreFieldUpdateRequest request) {
        //storeService.updateStatus(storeId, request.getBusinessStatus(), request.getVersion());
        Store store = new Store();
        store.setStoreId(storeId);
        store.setStatus(request.getBusinessStatus());
        store.setBusinessStatus(request.getBusinessStatus());
        Set<Integer> statusEnumSet = CollectionUtil.newHashSet(StoreStatusEnum.OPEN.getValue(), StoreStatusEnum.CLOSED.getValue());
        if (!statusEnumSet.contains(request.getBusinessStatus())) {
            throw new BadRequestException("状态错误");
        }
        storeMerchantService.updateBusinessStatus(store);
        return ResponseEntity.noContent().build();
    }
}