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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package com.zt.life.core.controller;
 
import com.zt.common.annotation.LogOperation;
import com.zt.common.servlet.Result;
import com.zt.common.validator.AssertUtils;
import com.zt.common.validator.ValidatorUtils;
import com.zt.common.validator.group.AddGroup;
import com.zt.common.validator.group.DefaultGroup;
import com.zt.common.validator.group.UpdateGroup;
import com.zt.life.core.dto.ProductDto;
import com.zt.life.core.mapstruct.ProductMapper;
import com.zt.life.core.model.Product;
import com.zt.life.core.service.ProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.util.List;
 
/**
 * CORE_PRODUCT
 *
 * @author zt generator
 * @since 1.0.0 2020-07-15
 */
@RestController
@RequestMapping("/product")
@Api(tags = "CORE_PRODUCT")
public class ProductController {
    @Autowired
    private ProductService productService;
    @Autowired
    private ProductMapper productMapper;
 
    @GetMapping("tree")
    @ApiOperation("树形结构")
    public Result<List<Product>> tree(
            @RequestParam(value = "parentId", required = false, defaultValue = "0") Long parentId) {
        List<Product> list = this.productService.getProductTree(parentId);
        return Result.ok(list);
    }
 
    @GetMapping("treeSelect")
    @ApiOperation("树形结构")
    public Result<List<ProductDto>> treeSelect(
            @RequestParam(value = "parentIds", required = false, defaultValue = "0") String parentIds,
            @RequestParam(value = "showLevel", required = false, defaultValue = "L5") String showLevel,
            @RequestParam(value = "pageCode", required = false) String pageCode){
        List<Product> list = this.productService.getProductTree(parentIds, showLevel,pageCode);
        List<ProductDto> productDtos = productMapper.toDto(list);
        return Result.ok(productDtos);
    }
 
    @GetMapping("treeSelectTest")
    @ApiOperation("树形结构")
    public Result<List<ProductDto>> treeSelectTest(
            @RequestParam(value = "parentIds", required = false, defaultValue = "0") String parentIds,
            @RequestParam(value = "showLevel", required = false, defaultValue = "L5") String showLevel) {
        List<Product> list = this.productService.getProductTree2(parentIds, showLevel);
        return Result.ok(productMapper.toDto(list));
    }
 
    @GetMapping("getShipList")
    @ApiOperation("獲取X号")
    public Result<List<ProductDto>> getShipList() {
        List<Product> list = this.productService.getShipList();
        return Result.ok(productMapper.toDto(list));
    }
    @GetMapping("getSubList")
    @ApiOperation("子节点列表")
    public Result<List<ProductDto>> getSubList(String pid) {
        List<Product> list = this.productService.getSubList(pid);
        return Result.ok(productMapper.toDto(list));
    }
 
    @GetMapping("getListByIds")
    @ApiOperation("列表")
    public Result<List<ProductDto>> getListByIds(String ids) {
        List<Product> list = this.productService.getListByIds(ids);
        return Result.ok(productMapper.toDto(list));
    }
    @GetMapping("{id}")
    @ApiOperation("信息")
    public Result<Product> get(@PathVariable("id") Long id) {
        Product data = productService.get(id);
 
        return Result.ok(data);
    }
 
    @PostMapping
    @ApiOperation("新增")
    @LogOperation("新增")
    public Result insert(@RequestBody Product productTree) {
        // 效验数据
        ValidatorUtils.validateEntity(productTree, AddGroup.class, DefaultGroup.class);
        productService.insert(productTree);
 
        return Result.ok();
    }
 
    @PutMapping
    @ApiOperation("修改")
    @LogOperation("修改")
    public Result update(@RequestBody Product productTree) {
        // 效验数据
        ValidatorUtils.validateEntity(productTree, UpdateGroup.class, DefaultGroup.class);
        productService.update(productTree);
 
        return Result.ok();
    }
 
    @DeleteMapping
    @ApiOperation("删除")
    @LogOperation("删除")
    public Result delete(@RequestBody Long[] ids) {
        // 效验数据
        AssertUtils.isArrayEmpty(ids, "id");
        productService.deleteLogic(ids);
 
        return Result.ok();
    }
 
}