mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-12 21:02:08 +08:00
产品明细现价计算错误修复,折扣校验修改,获取明细接口错误结果修复
This commit is contained in:
+2
-3
@@ -58,9 +58,8 @@ public class ProductsDetailController {
|
||||
@Operation(summary = "查询产品明细")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('base:productDetails:query')")
|
||||
public CommonResult<List<ProductsDetailDO>> getProductsDetail(@PathVariable("id") Long id) {
|
||||
List<ProductsDetailDO> productDetailsDO = productDetailsService.get(id);
|
||||
return success(productDetailsDO);
|
||||
public CommonResult<ProductsDetailDO> getProductsDetail(@PathVariable("id") Long id) {
|
||||
return success(productDetailsService.get(id));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
|
||||
+4
-1
@@ -4,6 +4,8 @@ import com.cf.imes.framework.common.validation.NumberValid;
|
||||
import com.cf.imes.module.system.validation.products.ProductType;
|
||||
import com.cf.imes.module.system.validation.products.TimeUnitValid;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.DecimalMax;
|
||||
import jakarta.validation.constraints.DecimalMin;
|
||||
import lombok.Data;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
@@ -51,7 +53,8 @@ public class ProductDetailsSaveReqVO {
|
||||
private BigDecimal originalPrice;
|
||||
|
||||
@Schema(description = "折扣", requiredMode = Schema.RequiredMode.REQUIRED, example = "0.8")
|
||||
@NumberValid(name = "折扣", integer = 4, fraction = 2)
|
||||
@DecimalMax(value = "100", inclusive = false, message = "折扣必须小于100")
|
||||
@DecimalMin(value = "0", inclusive = false, message = "折扣必须大于0")
|
||||
private BigDecimal discount;
|
||||
|
||||
@Schema(description = "产品现价", requiredMode = Schema.RequiredMode.REQUIRED, example = "80")
|
||||
|
||||
+2
-2
@@ -40,11 +40,11 @@ public interface ProductsDetailService {
|
||||
void delete(Long id);
|
||||
|
||||
/**
|
||||
* 获得产品
|
||||
* 获取产品定价
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
List<ProductsDetailDO> get(Long id);
|
||||
ProductsDetailDO get(Long id);
|
||||
|
||||
/**
|
||||
* 获得产品 分页
|
||||
|
||||
+4
-5
@@ -112,9 +112,8 @@ public class ProductsDetailServiceImpl implements ProductsDetailService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ProductsDetailDO> get(Long id) {
|
||||
validateProductDetailsExists(id);
|
||||
return productDetailsMapper.selectList();
|
||||
public ProductsDetailDO get(Long id) {
|
||||
return validateProductDetailsExists(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -219,8 +218,8 @@ public class ProductsDetailServiceImpl implements ProductsDetailService {
|
||||
*/
|
||||
private void calculateDiscount(BigDecimal originalPrice, BigDecimal currentPrice, BigDecimal discount) {
|
||||
// 校验当前价格是否正确
|
||||
// 计算期望现价(保留2位小数,四舍五入)
|
||||
BigDecimal expectedPrice = originalPrice.multiply(discount).setScale(2, RoundingMode.HALF_UP);
|
||||
// 计算期望现价 = 原价 * 折扣 /100(保留2位小数)
|
||||
BigDecimal expectedPrice = originalPrice.multiply(discount).divide(new BigDecimal(100)).setScale(2, RoundingMode.DOWN);
|
||||
|
||||
if (currentPrice.compareTo(expectedPrice) != 0) {
|
||||
throw ServiceExceptionUtil.exception(PRODUCTS_DETAIL_CURRENTPRICE_CALCULATE_ERROR, expectedPrice);
|
||||
|
||||
Reference in New Issue
Block a user