feat: 公司/店铺概览增加自定义税率参数

后端:
- CompanyOverviewQueryDTO / ShopOverviewQueryDTO 增加 taxRate 字段,默认 0.04
- CompanyOverviewServiceImpl / ShopOverviewStatisticsServiceImpl
  替换所有硬编码税率,统一使用请求参数中的税率
前端:
- API DTO 增加 taxRate 可选参数
- 公司概览页 DatePicker 左侧增加税率输入框,localStorage 持久化
- 店铺概览页同样增加税率输入框,localStorage 持久化
This commit is contained in:
小蟑螂
2026-04-15 21:57:58 +08:00
parent 44db767bf1
commit dfbb6e6172
8 changed files with 87 additions and 9 deletions
@@ -5,6 +5,7 @@ import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.Size;
import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List;
@@ -22,5 +23,11 @@ public class CompanyOverviewQueryDTO {
@NotEmpty(message = "日期范围不能为空")
@Size(min = 1, max = 2, message = "日期范围数组必须包含1-2个日期")
private List<LocalDate> dateRange;
/**
* 税率(默认4%)
*/
@Schema(description = "税率,默认为0.04(即4%)", example = "0.04")
private BigDecimal taxRate = new BigDecimal("0.04");
}
@@ -6,6 +6,7 @@ import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List;
@@ -30,5 +31,11 @@ public class ShopOverviewQueryDTO {
@NotEmpty(message = "日期范围不能为空")
@Size(min = 1, max = 2, message = "日期范围数组必须包含1-2个日期")
private List<LocalDate> dateRange;
/**
* 税率(默认4%)
*/
@Schema(description = "税率,默认为0.04(即4%)", example = "0.04")
private BigDecimal taxRate = new BigDecimal("0.04");
}
@@ -36,7 +36,8 @@ import java.util.stream.Collectors;
@Service
public class CompanyOverviewServiceImpl implements CompanyOverviewService {
private static final BigDecimal TAX_RATE = new BigDecimal("0.06"); // 税率6%
private static final BigDecimal DEFAULT_TAX_RATE = new BigDecimal("0.04");
private BigDecimal taxRate = DEFAULT_TAX_RATE;
private final CurrentUserContext currentUserContext;
private final OrderMapper orderMapper;
@@ -64,6 +65,9 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
@Override
public CompanyOverviewVO getCompanyOverview(CompanyOverviewQueryDTO queryDTO) {
// 取请求参数中的税率,默认4%
this.taxRate = queryDTO.getTaxRate() != null ? queryDTO.getTaxRate() : DEFAULT_TAX_RATE;
Long companyId = currentUserContext.getCurrentCompanyId();
// 解析日期范围
@@ -181,7 +185,7 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
// 6. 计算全店总净利(税后)和总税额
BigDecimal totalProfitBeforeTax = calculateTotalProfit(orders);
BigDecimal totalTaxAmount = totalProfitBeforeTax.multiply(TAX_RATE);
BigDecimal totalTaxAmount = totalProfitBeforeTax.multiply(taxRate);
BigDecimal totalNetProfitAfterTax = totalProfitBeforeTax.subtract(totalTaxAmount);
overviewVO.setTotalNetProfitAfterTax(totalNetProfitAfterTax);
overviewVO.setTotalTaxAmount(totalTaxAmount);
@@ -480,7 +484,7 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
BigDecimal profitBeforeTax = salesAmount.subtract(totalCost).subtract(refundAmount);
// 销售额4%税额
BigDecimal salesTaxAmount = salesAmount.multiply(new BigDecimal("0.04"));
BigDecimal salesTaxAmount = salesAmount.multiply(taxRate);
// 税后盈亏(扣除销售额4%税额)
BigDecimal profitAfterTax = profitBeforeTax.subtract(salesTaxAmount);
@@ -614,7 +618,7 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
* 计算店铺净利(税后)
*/
private BigDecimal calculateShopNetProfit(BigDecimal profitBeforeTax) {
BigDecimal taxAmount = profitBeforeTax.multiply(TAX_RATE);
BigDecimal taxAmount = profitBeforeTax.multiply(taxRate);
return profitBeforeTax.subtract(taxAmount);
}
@@ -38,7 +38,8 @@ import java.util.stream.Collectors;
@Service
public class ShopOverviewStatisticsServiceImpl implements ShopOverviewStatisticsService {
private static final BigDecimal SALES_TAX_RATE = new BigDecimal("0.04"); // 销售额4%税额
private static final BigDecimal DEFAULT_TAX_RATE = new BigDecimal("0.04");
private BigDecimal taxRate = DEFAULT_TAX_RATE;
private final CurrentUserContext currentUserContext;
private final OrderMapper orderMapper;
@@ -69,6 +70,9 @@ public class ShopOverviewStatisticsServiceImpl implements ShopOverviewStatistics
@Override
public ShopOverviewStatisticsVO getShopOverviewStatistics(ShopOverviewQueryDTO queryDTO) {
// 取请求参数中的税率,默认4%
this.taxRate = queryDTO.getTaxRate() != null ? queryDTO.getTaxRate() : DEFAULT_TAX_RATE;
Long companyId = currentUserContext.getCurrentCompanyId();
// 解析日期范围
@@ -193,7 +197,7 @@ public class ShopOverviewStatisticsServiceImpl implements ShopOverviewStatistics
// 6. 计算店铺总净利(税后)和总税额
BigDecimal totalProfitBeforeTax = calculateTotalProfit(orders);
BigDecimal totalSalesTaxAmount = totalSalesAmount.multiply(SALES_TAX_RATE);
BigDecimal totalSalesTaxAmount = totalSalesAmount.multiply(taxRate);
BigDecimal totalNetProfitAfterTax = totalProfitBeforeTax.subtract(totalSalesTaxAmount);
overviewVO.setTotalNetProfitAfterTax(totalNetProfitAfterTax);
overviewVO.setTotalTaxAmount(totalSalesTaxAmount);
@@ -389,7 +393,7 @@ public class ShopOverviewStatisticsServiceImpl implements ShopOverviewStatistics
BigDecimal profitBeforeTax = salesAmount.subtract(totalCost).subtract(refundAmount);
// 销售额4%税额
BigDecimal salesTaxAmount = salesAmount.multiply(SALES_TAX_RATE);
BigDecimal salesTaxAmount = salesAmount.multiply(taxRate);
// 税后盈亏(扣除销售额4%税额)
BigDecimal profitAfterTax = profitBeforeTax.subtract(salesTaxAmount);