wlzboy
2025-11-10 ae1e467411a786c37fb20b9bce2a7a4da64aa412
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
package com.ruoyi.web.controller.api;
 
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.vo.PriceCalculateVO;
import com.ruoyi.system.service.IPriceCalculateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;
 
/**
 * 价格计算API
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/api/price")
public class PriceCalculateController extends BaseController {
    
    @Autowired
    private IPriceCalculateService priceCalculateService;
    
    /**
     * 计算转运价格
     * 
     * @param vo 计算参数
     * @return 返回计算后的价格
     */
    @PostMapping("/calculate")
    public AjaxResult calculatePrice(@RequestBody PriceCalculateVO vo) {
        logger.info("收到价格计算请求: {}", vo);
        
        // 参数校验
        if (vo.getFromAddress() == null || vo.getFromAddress().trim().isEmpty()) {
            return AjaxResult.error("起始地址不能为空");
        }
        if (vo.getToAddress() == null || vo.getToAddress().trim().isEmpty()) {
            return AjaxResult.error("目的地址不能为空");
        }
        if (vo.getDistance() == null || vo.getDistance().compareTo(BigDecimal.ZERO) <= 0) {
            return AjaxResult.error("距离必须大于0");
        }
        
        // 调用服务计算价格
        BigDecimal price = priceCalculateService.calculateTransferPrice(vo);
        
        // 返回结果
        Map<String, Object> result = new HashMap<>();
        result.put("price", price);
        
        return AjaxResult.success(result);
    }
}