| | |
| | | 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; |
| | | |
| | | /** |
| | | * 店铺 |
| | |
| | | |
| | | 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(); |
| | | } |
| | | |
| | | } |