jinlin
2024-01-23 52a302b11c08cbc564ff3931038ae57a305a95d6
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
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.dto.SearchNodesDto;
import com.zt.life.core.mapstruct.ZtProductMapper;
import com.zt.life.core.model.Product;
import com.zt.life.core.model.ZtProduct;
import com.zt.life.core.service.ZtProductService;
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("/ztProduct")
@Api(tags = "CORE_PRODUCT")
public class ZtProductController {
    @Autowired
    private ZtProductService productService;
    @Autowired
    private ZtProductMapper productMapper;
 
    @GetMapping("tree")
    @ApiOperation("树形结构")
    public Result<List<ZtProduct>> tree(
            @RequestParam(value = "parentId", required = false, defaultValue = "0") Long parentId) {
        List<ZtProduct> list = this.productService.getProductTree(parentId);
        return Result.ok(list);
    }
 
    @GetMapping("treeSelect")
    @ApiOperation("树形结构")
    public Result<List<ZtProduct>> treeSelect(
            @RequestParam(value = "parentIds", required = false, defaultValue = "0") String parentIds,
            @RequestParam(value = "showLevel", required = false, defaultValue = "equipment") String showLevel) {
        List<ZtProduct> list = this.productService.getProductTree(parentIds, showLevel);
        //List<ProductDto> result= productMapper.toDto(list);
        return Result.ok(list);
    }
 
    @GetMapping("getTreeNodes")
    @ApiOperation("树节点列表")
    Result<List<ZtProduct>> getTreeNodes(String pid){
        List<ZtProduct> list = this.productService.getTreeNodes(pid);
        return Result.ok(list);
    }
 
    @GetMapping("searchNodes")
    @ApiOperation("树节点列表")
    Result<List<SearchNodesDto>> searchNodes(String pid, String name){
        List<SearchNodesDto> list = this.productService.searchNodes(pid,name);
        return Result.ok(list);
    }
 
    @GetMapping("getShipList")
    @ApiOperation("獲取X号")
    public Result<List<ProductDto>> getShipList(String area) {
        List<ZtProduct> list = this.productService.getShipList(area);
        return Result.ok(productMapper.toDto(list));
    }
    @GetMapping("getSubList")
    @ApiOperation("子节点列表")
    public Result<List<ProductDto>> getSubList(String pid) {
        List<ZtProduct> list = this.productService.getSubList(pid);
        return Result.ok(productMapper.toDto(list));
    }
 
    @GetMapping("getListByIds")
    @ApiOperation("列表")
    public Result<List<ProductDto>> getListByIds(String ids) {
        List<ZtProduct> list = this.productService.getListByIds(ids);
        return Result.ok(productMapper.toDto(list));
    }
    @GetMapping("{id}")
    @ApiOperation("信息")
    public Result<ZtProduct> get(@PathVariable("id") Long id) {
        ZtProduct data = productService.get(id);
 
        return Result.ok(data);
    }
 
    @GetMapping("getByProductId")
    @ApiOperation("根据productId获取信息")
    public Result<ZtProduct> getByProductId(Long productId) {
        ZtProduct data = productService.getByProductId(productId);
        return Result.ok(data);
    }
 
    @PostMapping
    @ApiOperation("新增")
    @LogOperation("新增")
    public Result insert(@RequestBody ZtProduct productTree) {
        // 效验数据
        ValidatorUtils.validateEntity(productTree, AddGroup.class, DefaultGroup.class);
        productService.insert(productTree);
 
        return Result.ok();
    }
 
    @PutMapping
    @ApiOperation("修改")
    @LogOperation("修改")
    public Result update(@RequestBody ZtProduct 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();
    }
 
    @GetMapping("getModelList")
    @ApiOperation("型号列表")
    public Result<List<ZtProduct>> getModelList() {
        List<ZtProduct> data = productService.getLevelList("model");
        return Result.ok(data);
    }
 
}