seatonwan9
2025-08-24 5fd8f535ef44ef055d91673740491b9c9177aa89
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
package com.webmanage.controller;
 
import com.webmanage.common.Result;
import com.webmanage.entity.Product;
import com.webmanage.service.ProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.util.List;
 
/**
 * 产品管理控制器
 * 
 * @author webmanage
 * @date 2024-08-07
 */
@Slf4j
@RestController
@RequestMapping("/product")
@Api(tags = "产品管理")
public class ProductController {
 
    @Autowired
    private ProductService productService;
 
    /**
     * 获取产品列表
     */
    @GetMapping("/list")
    @ApiOperation("获取产品列表")
    public Result<List<Product>> getProductList(
            @ApiParam("产品名称") @RequestParam(required = false) String productName,
            @ApiParam("产品类型") @RequestParam(required = false) String productType,
            @ApiParam("产品状态") @RequestParam(required = false) String status,
            @ApiParam("提供者ID") @RequestParam(required = false) Long providerId) {
        
        try {
            List<Product> productList = productService.getProductList(productName, productType, status, providerId);
            return Result.success(productList);
        } catch (Exception e) {
            log.error("获取产品列表失败", e);
            return Result.error("获取产品列表失败: " + e.getMessage());
        }
    }
 
    /**
     * 根据ID获取产品详情
     */
    @GetMapping("/{id}")
    @ApiOperation("根据ID获取产品详情")
    public Result<Product> getProductById(@ApiParam("产品ID") @PathVariable Long id) {
        try {
            Product product = productService.getProductById(id);
            if (product == null) {
                return Result.error("产品不存在");
            }
            return Result.success(product);
        } catch (Exception e) {
            log.error("获取产品详情失败", e);
            return Result.error("获取产品详情失败: " + e.getMessage());
        }
    }
 
    /**
     * 创建产品
     */
    @PostMapping
    @ApiOperation("创建产品")
    public Result<Boolean> createProduct(@RequestBody Product product) {
        try {
            boolean result = productService.createProduct(product);
            if (result) {
                return Result.success("产品创建成功", true);
            } else {
                return Result.error("产品创建失败");
            }
        } catch (Exception e) {
            log.error("创建产品失败", e);
            return Result.error("创建产品失败: " + e.getMessage());
        }
    }
 
    /**
     * 更新产品信息
     */
    @PutMapping("/{id}")
    @ApiOperation("更新产品信息")
    public Result<Boolean> updateProduct(@ApiParam("产品ID") @PathVariable Long id, @RequestBody Product product) {
        try {
            product.setId(id);
            boolean result = productService.updateProduct(product);
            if (result) {
                return Result.success("产品更新成功", true);
            } else {
                return Result.error("产品更新失败");
            }
        } catch (Exception e) {
            log.error("更新产品失败", e);
            return Result.error("更新产品失败: " + e.getMessage());
        }
    }
 
    /**
     * 删除产品
     */
    @DeleteMapping("/{id}")
    @ApiOperation("删除产品")
    public Result<Boolean> deleteProduct(@ApiParam("产品ID") @PathVariable Long id) {
        try {
            boolean result = productService.deleteProduct(id);
            if (result) {
                return Result.success("产品删除成功", true);
            } else {
                return Result.error("产品删除失败");
            }
        } catch (Exception e) {
            log.error("删除产品失败", e);
            return Result.error("删除产品失败: " + e.getMessage());
        }
    }
 
    /**
     * 更新产品状态
     */
    @PutMapping("/{id}/status")
    @ApiOperation("更新产品状态")
    public Result<Boolean> updateProductStatus(
            @ApiParam("产品ID") @PathVariable Long id,
            @ApiParam("产品状态") @RequestParam String status) {
        try {
            boolean result = productService.updateProductStatus(id, status);
            if (result) {
                return Result.success("产品状态更新成功", true);
            } else {
                return Result.error("产品状态更新失败");
            }
        } catch (Exception e) {
            log.error("更新产品状态失败", e);
            return Result.error("更新产品状态失败: " + e.getMessage());
        }
    }
 
    /**
     * 更新产品审核状态
     */
    @PutMapping("/{id}/audit-status")
    @ApiOperation("更新产品审核状态")
    public Result<Boolean> updateProductAuditStatus(
            @ApiParam("产品ID") @PathVariable Long id,
            @ApiParam("审核状态") @RequestParam String auditStatus) {
        try {
            boolean result = productService.updateProductAuditStatus(id, auditStatus);
            if (result) {
                return Result.success("产品审核状态更新成功", true);
            } else {
                return Result.error("产品审核状态更新失败");
            }
        } catch (Exception e) {
            log.error("更新产品审核状态失败", e);
            return Result.error("更新产品审核状态失败: " + e.getMessage());
        }
    }
 
    /**
     * 检查产品编码是否存在
     */
    @GetMapping("/check-code")
    @ApiOperation("检查产品编码是否存在")
    public Result<Boolean> checkProductCodeExists(
            @ApiParam("产品编码") @RequestParam String productCode,
            @ApiParam("排除的产品ID") @RequestParam(required = false) Long excludeId) {
        try {
            boolean exists = productService.checkProductCodeExists(productCode, excludeId);
            return Result.success(exists);
        } catch (Exception e) {
            log.error("检查产品编码失败", e);
            return Result.error("检查产品编码失败: " + e.getMessage());
        }
    }
}