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
package com.webmanage.controller;
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.webmanage.common.Result;
import com.webmanage.entity.ProductPricing;
import com.webmanage.service.ProductPricingService;
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.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
 
import javax.validation.Valid;
import java.util.List;
 
/**
 * 产品定价管理控制器
 * 
 * @author webmanage
 * @date 2024-08-07
 */
@Slf4j
@RestController
@RequestMapping("/product-pricing")
@Api(tags = "产品定价管理")
@Validated
public class ProductPricingController {
 
    @Autowired
    private ProductPricingService productPricingService;
 
    /**
     * 新增产品定价
     */
    @PostMapping("/add")
    @ApiOperation("新增产品定价")
    public Result<Boolean> addProductPricing(@Valid @RequestBody ProductPricing productPricing) {
        try {
            boolean result = productPricingService.addProductPricing(productPricing);
            return result ? Result.success("新增产品定价成功", true) : Result.error("新增产品定价失败");
        } catch (Exception e) {
            log.error("新增产品定价失败: ", e);
            return Result.error("新增产品定价失败: " + e.getMessage());
        }
    }
 
    /**
     * 编辑产品定价
     */
    @PutMapping("/update")
    @ApiOperation("编辑产品定价")
    public Result<Boolean> updateProductPricing(@Valid @RequestBody ProductPricing productPricing) {
        try {
            if (productPricing.getId() == null) {
                return Result.error("产品定价ID不能为空");
            }
            boolean result = productPricingService.updateProductPricing(productPricing);
            return result ? Result.success("编辑产品定价成功", true) : Result.error("编辑产品定价失败");
        } catch (Exception e) {
            log.error("编辑产品定价失败: ", e);
            return Result.error("编辑产品定价失败: " + e.getMessage());
        }
    }
 
    /**
     * 删除产品定价(逻辑删除)
     */
    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除产品定价")
    public Result<Boolean> deleteProductPricing(@ApiParam("产品定价ID") @PathVariable Long id) {
        try {
            if (id == null) {
                return Result.error("产品定价ID不能为空");
            }
            boolean result = productPricingService.deleteProductPricing(id);
            return result ? Result.success("删除产品定价成功", true) : Result.error("删除产品定价失败");
        } catch (Exception e) {
            log.error("删除产品定价失败: ", e);
            return Result.error("删除产品定价失败: " + e.getMessage());
        }
    }
 
    /**
     * 分页查询产品定价列表
     */
    @GetMapping("/page")
    @ApiOperation("分页查询产品定价列表")
    public Result<IPage<ProductPricing>> getProductPricingPage(
            @ApiParam("页码") @RequestParam(defaultValue = "1") Long pageNum,
            @ApiParam("每页大小") @RequestParam(defaultValue = "10") Long pageSize,
            @ApiParam("产品ID") @RequestParam(required = false) Long productId) {
        try {
            Page<ProductPricing> page = new Page<>(pageNum, pageSize);
            IPage<ProductPricing> result = productPricingService.getProductPricingPage(page, productId);
            return Result.success("查询成功", result);
        } catch (Exception e) {
            log.error("分页查询产品定价失败: ", e);
            return Result.error("分页查询产品定价失败: " + e.getMessage());
        }
    }
 
    /**
     * 根据产品ID查询定价列表
     */
    @GetMapping("/product/{productId}")
    @ApiOperation("根据产品ID查询定价列表")
    public Result<List<ProductPricing>> getPricingByProductId(@ApiParam("产品ID") @PathVariable Long productId) {
        try {
            if (productId == null) {
                return Result.error("产品ID不能为空");
            }
            List<ProductPricing> result = productPricingService.getPricingByProductId(productId);
            return Result.success("查询成功", result);
        } catch (Exception e) {
            log.error("根据产品ID查询定价失败: ", e);
            return Result.error("根据产品ID查询定价失败: " + e.getMessage());
        }
    }
 
    /**
     * 根据条件查询产品定价
     */
    @GetMapping("/condition")
    @ApiOperation("根据条件查询产品定价")
    public Result<List<ProductPricing>> getPricingByCondition(
            @ApiParam("套件名称") @RequestParam(required = false) String suiteName,
            @ApiParam("销售形式") @RequestParam(required = false) String salesForm,
            @ApiParam("客户对象") @RequestParam(required = false) String customerType,
            @ApiParam("价格类型") @RequestParam(required = false) String priceType,
            @ApiParam("启用状态") @RequestParam(required = false) Boolean isActive) {
        try {
            List<ProductPricing> result = productPricingService.getPricingByCondition(
                    suiteName, salesForm, customerType, priceType, isActive);
            return Result.success("查询成功", result);
        } catch (Exception e) {
            log.error("根据条件查询产品定价失败: ", e);
            return Result.error("根据条件查询产品定价失败: " + e.getMessage());
        }
    }
 
    /**
     * 获取产品定价详情
     */
    @GetMapping("/detail/{id}")
    @ApiOperation("获取产品定价详情")
    public Result<ProductPricing> getProductPricingDetail(@ApiParam("产品定价ID") @PathVariable Long id) {
        try {
            if (id == null) {
                return Result.error("产品定价ID不能为空");
            }
            ProductPricing result = productPricingService.getById(id);
            if (result == null) {
                return Result.error("产品定价不存在");
            }
            return Result.success("查询成功", result);
        } catch (Exception e) {
            log.error("获取产品定价详情失败: ", e);
            return Result.error("获取产品定价详情失败: " + e.getMessage());
        }
    }
}