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);
|
}
|
}
|