应付配置增加附加费配置,应付账单新增核销、对账、凭证、审核功能

This commit is contained in:
liuminghui
2026-11-12 18:20:32 +08:00
parent 1ba431540d
commit 6675808dfc
55 changed files with 5898 additions and 185 deletions
@@ -1,8 +1,14 @@
package com.bms.web.controller.price;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
@@ -15,6 +21,7 @@ import com.bms.common.core.domain.AjaxResult;
import com.bms.common.core.page.TableDataInfo;
import com.bms.price.domain.PayBill;
import com.bms.price.domain.PayBillCommand;
import com.bms.price.domain.PayBillFile;
import com.bms.price.service.IPayBillService;
/**
@@ -119,4 +126,176 @@ public class PayBillController extends BaseController
payBillService.voidBill(command);
return success();
}
/**
* 草稿提交审核。
*
* @param billId 应付账单ID
*/
@PreAuthorize("@ss.hasAnyPermi('price:payBill:submit,price:payBill:confirm')")
@PutMapping("/submit/{billId}")
public AjaxResult submit(@PathVariable Long billId)
{
payBillService.submit(billId);
return success();
}
/**
* 审核通过。蓝字账单需要先有凭证。
*
* @param billId 应付账单ID
*/
@PreAuthorize("@ss.hasAnyPermi('price:payBill:approve,price:payBill:confirm')")
@PutMapping("/approve/{billId}")
public AjaxResult approve(@PathVariable Long billId)
{
payBillService.approve(billId);
return success();
}
/**
* 审核驳回。
*
* @param command 账单ID和驳回意见
*/
@PreAuthorize("@ss.hasAnyPermi('price:payBill:approve,price:payBill:confirm')")
@PutMapping("/reject")
public AjaxResult reject(@RequestBody PayBillCommand command)
{
payBillService.reject(command);
return success();
}
/**
* 草稿登记对方金额。
*
* @param command 账单和费用行
*/
@PreAuthorize("@ss.hasAnyPermi('price:payBill:add,price:payBill:submit')")
@PutMapping("/diff")
public AjaxResult diff(@RequestBody PayBillCommand command)
{
payBillService.saveSupplierAmounts(command);
return success();
}
/**
* 接受我方或接受对方金额。
*
* @param command 费用行和处理方式
*/
@PreAuthorize("@ss.hasAnyPermi('price:payBill:add,price:payBill:submit')")
@PutMapping("/diff/accept")
public AjaxResult accept(@RequestBody PayBillCommand command)
{
payBillService.acceptDiff(command);
return success();
}
/**
* 从草稿剔除一条费用。
*
* @param command 账单ID和行ID
*/
@PreAuthorize("@ss.hasAnyPermi('price:payBill:add,price:payBill:submit')")
@PutMapping("/line/remove")
public AjaxResult removeLine(@RequestBody PayBillCommand command)
{
payBillService.removeLine(command);
return success();
}
/**
* 上传应付凭证。
*
* @param file 凭证
*/
@PreAuthorize("@ss.hasAnyPermi('price:payVoucher:add,price:payBill:add')")
@PostMapping("/file")
public AjaxResult saveFile(@RequestBody PayBillFile file)
{
payBillService.saveFile(file);
return success();
}
/**
* 删除应付凭证。
*
* @param fileId 凭证ID
*/
@PreAuthorize("@ss.hasAnyPermi('price:payVoucher:remove,price:payBill:void')")
@DeleteMapping("/file/{fileId}")
public AjaxResult deleteFile(@PathVariable Long fileId)
{
payBillService.deleteFile(fileId);
return success();
}
/**
* 查询应付凭证。
*
* @param query 账单号、供应商、发票号、类型
*/
@PreAuthorize("@ss.hasAnyPermi('price:payVoucher:list,price:payBill:query')")
@GetMapping("/file/list")
public TableDataInfo fileList(PayBillFile query)
{
startPage();
return getDataTable(payBillService.listFiles(query));
}
/**
* 对未付款的已确认账单开红字。
*
* @param command 原账单和原因
*/
@PreAuthorize("@ss.hasAnyPermi('price:payBill:approve,price:payBill:confirm')")
@PostMapping("/red")
public AjaxResult red(@RequestBody PayBillCommand command)
{
return success(payBillService.redBill(command));
}
/**
* 草稿保存税率和汇率。
*
* @param command 账单、税率、汇率和汇率日期
*/
@PreAuthorize("@ss.hasAnyPermi('price:payBill:add,price:payBill:submit')")
@PutMapping("/finance")
public AjaxResult finance(@RequestBody PayBillCommand command)
{
payBillService.saveFinance(command);
return success();
}
/**
* 导出对账单。
*
* @param billId 应付账单ID
* @param response 文件流
*/
@PreAuthorize("@ss.hasPermi('price:payBill:query')")
@GetMapping("/statement/{billId}")
public void statement(@PathVariable Long billId, HttpServletResponse response) throws Exception
{
String name = URLEncoder.encode("应付对账单.xlsx", StandardCharsets.UTF_8).replace("+", "%20");
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + name);
payBillService.exportStatement(billId, response.getOutputStream());
}
/**
* 导入对方金额。
*
* @param billId 应付账单ID
* @param file 导出的对账单
*/
@PreAuthorize("@ss.hasAnyPermi('price:payBill:add,price:payBill:submit')")
@PostMapping("/diff/import")
public AjaxResult importDiff(@RequestParam Long billId, @RequestParam("file") MultipartFile file)
{
payBillService.importSupplierAmounts(billId, file);
return success();
}
}
@@ -0,0 +1,137 @@
package com.bms.web.controller.price;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.bms.common.core.controller.BaseController;
import com.bms.common.core.domain.AjaxResult;
import com.bms.common.core.page.TableDataInfo;
import com.bms.price.domain.PayPayment;
import com.bms.price.domain.PayPaymentAlloc;
import com.bms.price.service.IPayPaymentService;
/**
* 账单管理下的应付付款。
*/
@RestController
@RequestMapping("/price/payPayment")
public class PayPaymentController extends BaseController
{
@Autowired
private IPayPaymentService payPaymentService;
/**
* 分页查询应付付款。
*
* @param query 付款单号、供应商、状态、币种
* @return 付款单列表
*/
@PreAuthorize("@ss.hasPermi('price:payPayment:list')")
@GetMapping("/list")
public TableDataInfo list(PayPayment query)
{
startPage();
List<PayPayment> list = payPaymentService.selectPayPaymentList(query);
return getDataTable(list);
}
/**
* 付款单详情,含核销明细。
*
* @param paymentId 付款单ID
* @return 付款单
*/
@PreAuthorize("@ss.hasPermi('price:payPayment:query')")
@GetMapping("/{paymentId}")
public AjaxResult detail(@PathVariable Long paymentId)
{
return success(payPaymentService.selectPayPaymentDetail(paymentId));
}
/**
* 查询这个供应商、这个币种下还能核销的账单。
*
* @param supplierId 供应商ID
* @param currency 币种
* @return 未付账单
*/
@PreAuthorize("@ss.hasPermi('price:payPayment:query')")
@GetMapping("/open")
public AjaxResult open(Long supplierId, String currency)
{
List<PayPaymentAlloc> list = payPaymentService.selectOpenBills(supplierId, currency);
return success(list);
}
/**
* 登记草稿付款。确认后才核销账单。
*
* @param payment 付款单和核销明细
* @return 付款单
*/
@PreAuthorize("@ss.hasPermi('price:payPayment:add')")
@PostMapping
public AjaxResult create(@RequestBody PayPayment payment)
{
return success(payPaymentService.create(payment));
}
/**
* 确认付款并核销。
*
* @param paymentId 付款单ID
*/
@PreAuthorize("@ss.hasPermi('price:payPayment:confirm')")
@PutMapping("/confirm/{paymentId}")
public AjaxResult confirm(@PathVariable Long paymentId)
{
payPaymentService.confirm(paymentId);
return success();
}
/**
* 作废草稿付款。已确认的付款不在这里作废。
*
* @param paymentId 付款单ID
*/
@PreAuthorize("@ss.hasPermi('price:payPayment:void')")
@PutMapping("/void/{paymentId}")
public AjaxResult voidPayment(@PathVariable Long paymentId)
{
payPaymentService.voidPayment(paymentId);
return success();
}
/**
* 反核销。账单未付金额恢复。
*
* @param paymentId 付款单ID
*/
@PreAuthorize("@ss.hasPermi('price:payPayment:confirm')")
@PutMapping("/reverse/{paymentId}")
public AjaxResult reverse(@PathVariable Long paymentId)
{
payPaymentService.reverse(paymentId);
return success();
}
/**
* 退款。冲回核销,付款单改为已退款。
*
* @param paymentId 付款单ID
*/
@PreAuthorize("@ss.hasPermi('price:payPayment:confirm')")
@PutMapping("/refund/{paymentId}")
public AjaxResult refund(@PathVariable Long paymentId)
{
payPaymentService.refund(paymentId);
return success();
}
}
@@ -30,8 +30,10 @@ import com.bms.price.domain.PayProduct;
import com.bms.price.domain.PayProductTerm;
import com.bms.price.domain.PaySaveCommand;
import com.bms.price.pay.PayDetailExporter;
import com.bms.price.domain.PaySurchargeRuleSave;
import com.bms.price.service.IPayOrderCostService;
import com.bms.price.service.IPayProductService;
import com.bms.price.service.IPaySurchargeRuleService;
import jakarta.servlet.http.HttpServletResponse;
/**
@@ -47,6 +49,9 @@ public class PayProductController extends BaseController
@Autowired
private IPayOrderCostService payOrderCostService;
@Autowired
private IPaySurchargeRuleService paySurchargeRuleService;
@PreAuthorize("@ss.hasPermi('price:pay:list')")
@GetMapping("/list")
public TableDataInfo list(PayProduct query)
@@ -102,6 +107,31 @@ public class PayProductController extends BaseController
payProductService.writeSource(productId, response.getOutputStream());
}
/** 当前版本的附加费计费条件。同一版本只有一份。 */
@PreAuthorize("@ss.hasAnyPermi('price:pay:query,price:pay:edit')")
@GetMapping("/surchargeRule")
public AjaxResult surchargeRule(@RequestParam Long productId, @RequestParam Long termId)
{
return success(paySurchargeRuleService.list(productId, termId));
}
/** 上一版条件,复制到当前页后再保存。 */
@PreAuthorize("@ss.hasAnyPermi('price:pay:query,price:pay:edit')")
@GetMapping("/surchargeRule/previous")
public AjaxResult previousSurchargeRule(@RequestParam Long productId)
{
return success(paySurchargeRuleService.previous(productId));
}
@PreAuthorize("@ss.hasPermi('price:pay:edit')")
@Log(title = "应付附加费计费条件", businessType = BusinessType.UPDATE)
@PostMapping("/surchargeRule")
public AjaxResult saveSurchargeRule(@RequestBody PaySurchargeRuleSave command)
{
paySurchargeRuleService.save(command);
return success();
}
@PreAuthorize("@ss.hasPermi('price:pay:query')")
@GetMapping("/{productId}")
public AjaxResult getInfo(@PathVariable Long productId)
@@ -0,0 +1,172 @@
package com.bms.price.pay;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.Test;
import com.bms.price.domain.PayOrderCostResult;
import com.bms.price.domain.PayProduct;
import com.bms.price.domain.PaySurcharge;
import com.bms.price.domain.PaySurchargeRule;
import com.bms.price.domain.PayWeightBand;
/** 用 DE-iMile 价卡和附加费配置,按测试订单的重量、尺寸、日期测算。 */
class PaySurchargeConfigCalcTest
{
@Test
void lightOctoberOrderChargesFreightAndCarbonOnly()
{
PayOrderCostResult result = PayCostCalculator.calculate(imile(), new BigDecimal("0.451"),
new BigDecimal("35.70"), new BigDecimal("32.80"), new BigDecimal("4.00"),
null, null, day(2026, 10, 17), 8);
assertTrue(hasFee(result, "基础运费", "2.99"));
assertTrue(hasFee(result, "CO₂附加费", "0.03"));
assertTrue(result.getFees().stream().noneMatch(fee -> fee.getFeeName().contains("超尺寸")));
assertTrue(result.getFees().stream().noneMatch(fee -> fee.getFeeName().contains("旺季")));
assertEquals(new BigDecimal("3.02"), result.getPayTotal());
}
@Test
void heavierOctoberOrderUsesTheNextWeightBand()
{
PayOrderCostResult result = PayCostCalculator.calculate(imile(), new BigDecimal("1.246"),
new BigDecimal("41.10"), new BigDecimal("34.20"), new BigDecimal("6.10"),
null, null, day(2026, 10, 17), 5);
assertTrue(hasFee(result, "基础运费", "3.12"));
assertTrue(hasFee(result, "CO₂附加费", "0.03"));
assertEquals(new BigDecimal("3.15"), result.getPayTotal());
}
@Test
void oversizeAndPeakSeasonUseTheConfiguredRules()
{
PayOrderCostResult oversize = PayCostCalculator.calculate(imile(), new BigDecimal("1.246"),
new BigDecimal("130"), new BigDecimal("70"), new BigDecimal("40"),
null, null, day(2026, 11, 12), 5);
assertTrue(hasFee(oversize, "基础运费", "3.12"));
assertTrue(hasFee(oversize, "CO₂附加费", "0.03"));
assertTrue(hasFee(oversize, "异形件/超尺寸处理费", "3.60"));
assertTrue(hasFee(oversize, "旺季附加费", "0.19"));
assertEquals(new BigDecimal("6.94"), oversize.getPayTotal());
PayOrderCostResult peak = PayCostCalculator.calculate(dhl(), new BigDecimal("0.664"),
new BigDecimal("25.50"), new BigDecimal("18.90"), new BigDecimal("7.80"),
null, null, day(2026, 11, 4), 11);
assertTrue(hasFee(peak, "基础运费", "3.13"));
assertTrue(hasFee(peak, "燃油附加费", "0.15"));
assertTrue(hasFee(peak, "旺季附加费", "0.19"));
assertTrue(peak.getFees().stream().noneMatch(fee -> "高峰旺季附加费".equals(fee.getFeeName())));
assertTrue(peak.getFees().stream().noneMatch(fee -> fee.getFeeName().contains("超尺寸")));
}
private static boolean hasFee(PayOrderCostResult result, String name, String amount)
{
return result.getFees().stream().anyMatch(fee -> name.equals(fee.getFeeName())
&& fee.getAmount().compareTo(new BigDecimal(amount)) == 0);
}
private static Date day(int year, int month, int day)
{
return Date.from(LocalDate.of(year, month, day).atStartOfDay(ZoneId.systemDefault()).toInstant());
}
private static PayProduct imile()
{
PayProduct product = new PayProduct();
product.setProductName("DE-iMile");
product.setCurrency("EUR");
product.setWeightBands(List.of(
band("0", "1", "2.99"),
band("1", "2", "3.12")));
product.setSurcharges(List.of(
fee("CO₂附加费", "0.03", "ALWAYS"),
fee("异形件/超尺寸处理费", "3.60", "SIZE"),
fee("旺季附加费", "0.19", "ALWAYS")));
product.setBillingRules(List.of(
always(null, null, null),
always("旺季附加费", "11-01", "12-31"),
sizeBox()));
return product;
}
private static PayProduct dhl()
{
PayProduct product = new PayProduct();
product.setProductName("德国DHL");
product.setCurrency("EUR");
product.setWeightBands(List.of(band("0", "1", "3.13")));
product.setSurcharges(List.of(
fee("燃油附加费", "0.15", "ALWAYS"),
fee("超尺寸超重费", "14.00", "SIZE"),
fee("旺季附加费", "0.19", "ALWAYS"),
fee("高峰旺季附加费", "0.50", "ALWAYS")));
product.setBillingRules(List.of(
always(null, null, null),
always("旺季附加费", "11-01", "12-31"),
always("高峰旺季附加费", "11-24", "12-07"),
sizeBox()));
return product;
}
private static PaySurchargeRule always(String feeName, String start, String end)
{
PaySurchargeRule rule = new PaySurchargeRule();
rule.setCalcRule("ALWAYS");
rule.setEnabled("1");
Map<String, Object> detail = new LinkedHashMap<>();
if (feeName != null)
{
detail.put("feeName", feeName);
detail.put("periodStart", start);
detail.put("periodEnd", end);
}
rule.setDetail(detail);
return rule;
}
private static PaySurchargeRule sizeBox()
{
PaySurchargeRule rule = new PaySurchargeRule();
rule.setCalcRule("SIZE");
rule.setEnabled("1");
Map<String, Object> detail = new LinkedHashMap<>();
detail.put("matchMode", "ANY");
detail.put("boxMode", "OVER");
detail.put("boxLength", new BigDecimal("120"));
detail.put("boxWidth", new BigDecimal("60"));
detail.put("boxHeight", new BigDecimal("60"));
rule.setDetail(detail);
return rule;
}
private static PayWeightBand band(String min, String max, String price)
{
PayWeightBand band = new PayWeightBand();
band.setWeightMin(new BigDecimal(min));
band.setWeightMax(new BigDecimal(max));
band.setWeightLabel(min + "-" + max);
band.setPrice(new BigDecimal(price));
band.setPriceUnit("EUR/ITEM");
return band;
}
private static PaySurcharge fee(String name, String amount, String rule)
{
PaySurcharge fee = new PaySurcharge();
fee.setFeeName(name);
fee.setAmount(new BigDecimal(amount));
fee.setCurrency("EUR");
fee.setCalcRule(rule);
fee.setChargeText(amount + " EUR/ITEM");
return fee;
}
}