ProductController.java
1.37 KB
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
package vion.controller;
import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.github.linpeilie.Converter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import vion.Global;
import vion.dto.ProductDTO;
import vion.model.Product;
import vion.service.IProductService;
import vion.vo.ProductVO;
@RestController
@RequestMapping(Global.BASE_URL)
@RequiredArgsConstructor
@Slf4j
public class ProductController {
private final IProductService productService;
private final Converter converter;
@GetMapping("/products")
@SaCheckPermission(value = "product:list", orRole="admin")
public Page<ProductVO> getProductList(ProductDTO productDTO) {
return productService.getProductList(productDTO);
}
@GetMapping("/product")
@SaCheckPermission(value = "product:query", orRole="admin")
public Product getProductByID(@RequestParam Long projectId) {
return productService.getById(projectId);
}
@PostMapping("/products")
@SaCheckPermission(value = "product:editAndSave", orRole="admin")
public String saveOrUpdate(@RequestBody ProductDTO productDTO) {
Product data = converter.convert(productDTO, new Product());
return productService.saveOrUpdate(data) ? "成功" : "失败";
}
}