package com.oying.modules.pc.category.rest; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.oying.annotation.Log; import com.oying.modules.pc.category.converter.PlatformCategoryViewAssembler; import com.oying.modules.pc.category.domain.PlatformCategory; import com.oying.modules.pc.category.domain.dto.PlatformCategoryCreateRequest; import com.oying.modules.pc.category.domain.dto.PlatformCategoryQueryCriteria; import com.oying.modules.pc.category.domain.dto.PlatformCategoryUpdateDto; import com.oying.modules.pc.category.domain.dto.PlatformCategoryUpdateRequest; import com.oying.modules.pc.category.service.PlatformCategoryService; import com.oying.modules.pc.category.view.PlatformCategoryView; import com.oying.modules.pc.common.core.domain.R; import com.oying.utils.PageResult; 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.ArrayList; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; /** * @author lzp * @date 2025-04-28 **/ @RestController @RequiredArgsConstructor @Api(tags = "平台类目") @RequestMapping("/api/pc/admin/platformCategory") public class PlatformCategoryAdminController { private final PlatformCategoryService categoryService; private final PlatformCategoryViewAssembler assembler; @GetMapping @ApiOperation("查询平台类目(支持分页)") @PreAuthorize("@el.check('admin:platformCategory:list')") public ResponseEntity queryPlatformCategory(PlatformCategoryQueryCriteria criteria) { Page page = new Page<>(criteria.getPage(), criteria.getSize()); PageResult pageResult = categoryService.queryAll(criteria, page); List responseList = Optional.ofNullable(pageResult.getContent()).orElse(new ArrayList<>()).stream().map(assembler::toPlatformCategoryResponse).collect(Collectors.toList()); PageResult responsePageResult = new PageResult<>(responseList, pageResult.getTotalElements()); return ResponseEntity.ok(R.success(responsePageResult)); } @PostMapping @ApiOperation("新增平台类目") //@PreAuthorize("@el.check('admin:platformCategory:create')") public ResponseEntity create(@Validated @RequestBody PlatformCategoryCreateRequest request) { categoryService.create(request); return ResponseEntity.status(HttpStatus.CREATED).build(); } @PutMapping("/{categoryId}") @ApiOperation("修改平台类目") //@PreAuthorize("@el.check('admin:platformCategory:updateById')") public ResponseEntity updateById(@PathVariable Long categoryId, @Validated @RequestBody PlatformCategoryUpdateRequest request) { PlatformCategoryUpdateDto updateDto = new PlatformCategoryUpdateDto(); BeanUtils.copyProperties(request, updateDto); updateDto.setCategoryId(categoryId); categoryService.update(updateDto); return ResponseEntity.noContent().build(); } @DeleteMapping @Log("删除平台类目") @ApiOperation("删除平台类目") //@PreAuthorize("@el.check('admin:platformCategory:batchDel')") public ResponseEntity batchDelete(@ApiParam(value = "传ID数组[]") @RequestBody List ids) { categoryService.deleteAll(ids); return ResponseEntity.noContent().build(); } }