xin
2025-06-03 95dc030ad8e77303207a1a42a3afd9a7a6612d75
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
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.utils.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<Object> page = new Page<>(criteria.getPage(), criteria.getSize());
        PageResult<PlatformCategory> pageResult = categoryService.queryAll(criteria, page);
        List<PlatformCategoryView> responseList = Optional.ofNullable(pageResult.getContent()).orElse(new ArrayList<>()).stream().map(assembler::toPlatformCategoryResponse).collect(Collectors.toList());
        PageResult<PlatformCategoryView> 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<Long> ids) {
        categoryService.deleteAll(ids);
        return ResponseEntity.noContent().build();
    }
}