New file |
| | |
| | | package com.oying.modules.pc.store.rest; |
| | | |
| | | import cn.hutool.core.collection.ListUtil; |
| | | import cn.hutool.core.lang.tree.Tree; |
| | | import cn.hutool.core.lang.tree.TreeNodeConfig; |
| | | import cn.hutool.core.lang.tree.TreeUtil; |
| | | import cn.hutool.core.util.BooleanUtil; |
| | | import com.oying.annotation.Log; |
| | | import com.oying.utils.R; |
| | | import com.oying.modules.pc.store.domain.StoreCategory; |
| | | import com.oying.modules.pc.store.domain.dto.*; |
| | | import com.oying.modules.pc.store.service.StoreCategoryService; |
| | | import com.oying.modules.pc.store.view.StoreCategoryMerchantView; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import io.swagger.annotations.ApiParam; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.http.HttpStatus; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.List; |
| | | import java.util.Optional; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @author lzp |
| | | * @date 2025-04-24 |
| | | **/ |
| | | @Api(tags = "店铺类目(商户端)") |
| | | @RestController |
| | | @RequiredArgsConstructor |
| | | @RequestMapping("/api/pc/merchant/store/{storeId}/category") |
| | | public class StoreCategoryMerchantController { |
| | | |
| | | private final StoreCategoryService storeCategoryService; |
| | | |
| | | @GetMapping(value = "/list") |
| | | @ApiOperation("查询店铺类目") |
| | | //@PreAuthorize("@el.check('merchant:storeCategory:list')" + |
| | | // " and @storeMerchantOwnershipService.check(#storeId)") |
| | | public ResponseEntity<?> getList(@PathVariable Long storeId, |
| | | @RequestParam(value = "recursive", required = false) Boolean recursive) { |
| | | |
| | | StoreCategoryQueryCriteria criteria = new StoreCategoryQueryCriteria(); |
| | | criteria.setStoreId(storeId); |
| | | List<StoreCategory> storeCategoryList = storeCategoryService.queryAll(criteria); |
| | | List<StoreCategoryMerchantView> viewList = Optional.ofNullable(storeCategoryList).orElse(ListUtil.empty()).stream().map(i -> { |
| | | StoreCategoryMerchantView view = new StoreCategoryMerchantView(); |
| | | BeanUtils.copyProperties(i, view); |
| | | return view; |
| | | }).collect(Collectors.toList()); |
| | | |
| | | if (BooleanUtil.isFalse(recursive)) { |
| | | return ResponseEntity.ok(R.success(viewList)); |
| | | } |
| | | |
| | | TreeNodeConfig config = new TreeNodeConfig(); |
| | | config.setIdKey("categoryId"); |
| | | config.setWeightKey("sortWeight"); |
| | | //config.setDeep(3); |
| | | |
| | | List<Tree<Long>> tree = TreeUtil.build(viewList, 0L, config, (c, treeNode) -> { |
| | | treeNode.setId(c.getCategoryId()); |
| | | treeNode.setParentId(c.getParentId()); |
| | | treeNode.setName(c.getName()); |
| | | treeNode.setWeight(c.getSortWeight()); |
| | | }); |
| | | |
| | | return ResponseEntity.ok(R.success(tree)); |
| | | } |
| | | |
| | | @GetMapping(value = "/{categoryId}") |
| | | @ApiOperation("查询店铺类目") |
| | | //@PreAuthorize("@el.check('merchant:storeCategory:list')" + |
| | | // " and @storeMerchantOwnershipService.check(#storeId)") |
| | | public ResponseEntity<?> getById(@PathVariable Long categoryId, |
| | | @RequestParam(value = "recursive", required = false) Boolean recursive) { |
| | | |
| | | StoreCategory storeCategory = storeCategoryService.getById(categoryId); |
| | | StoreCategoryMerchantView view = new StoreCategoryMerchantView(); |
| | | BeanUtils.copyProperties(storeCategory, view); |
| | | |
| | | /*LambdaQueryWrapper<StoreCategory> wrapper = new LambdaQueryWrapper<StoreCategory>() |
| | | .eq(StoreCategory::getParentId, categoryId); |
| | | List<StoreCategory> subStoreCategoryList = storeCategoryService.list(wrapper);*/ |
| | | |
| | | return ResponseEntity.ok(R.success(view)); |
| | | } |
| | | |
| | | @PostMapping |
| | | @Log("新增店铺类目") |
| | | @ApiOperation("新增店铺类目") |
| | | //@PreAuthorize("@el.check('storeCategory:add')" + |
| | | // " and @storeMerchantOwnershipService.check(#storeId)") |
| | | public ResponseEntity<?> createStoreCategory(@PathVariable Long storeId, |
| | | @Validated @RequestBody StoreCategoryMerchantCreateRequest request) { |
| | | |
| | | StoreCategory resources = new StoreCategory(); |
| | | BeanUtils.copyProperties(request, resources); |
| | | resources.setStoreId(storeId); |
| | | storeCategoryService.create(resources); |
| | | return ResponseEntity.status(HttpStatus.CREATED).build(); |
| | | } |
| | | |
| | | @PutMapping(value = "/{categoryId}") |
| | | @Log("修改店铺类目") |
| | | @ApiOperation("修改店铺类目") |
| | | //@PreAuthorize("@el.check('storeCategory:edit')" + |
| | | // " and @storeMerchantOwnershipService.check(#storeId)") |
| | | public ResponseEntity<?> updateStoreCategory(@PathVariable Long storeId, |
| | | @PathVariable Long categoryId, |
| | | @Validated @RequestBody StoreCategoryMerchantUpdateRequest request) { |
| | | |
| | | StoreCategory resources = new StoreCategory(); |
| | | BeanUtils.copyProperties(request, resources); |
| | | resources.setCategoryId(categoryId); |
| | | resources.setStoreId(storeId); |
| | | storeCategoryService.update(resources); |
| | | return ResponseEntity.noContent().build(); |
| | | } |
| | | |
| | | @DeleteMapping |
| | | @Log("删除店铺类目") |
| | | @ApiOperation("删除店铺类目") |
| | | @PreAuthorize("@el.check('storeCategory:del')" + |
| | | " and @storeMerchantOwnershipService.check(#storeId)") |
| | | public ResponseEntity<?> deleteStoreCategory(@ApiParam(value = "传ID数组[]") @RequestBody List<Long> ids) { |
| | | storeCategoryService.deleteAll(ids); |
| | | return ResponseEntity.noContent().build(); |
| | | } |
| | | } |