93 Commits

Author SHA1 Message Date
caojia ee1ad10150 🔥 移除账单导出模板收款账户一致性校验 2026-11-20 14:59:45 +08:00
caojia 213e0b24bb ✨ 汇总账单导出保留收货时间 2026-11-20 13:47:21 +08:00
caojia 7af0feb188 ✨ 支持生成账单时选择收款账户 2026-11-20 13:47:20 +08:00
caojia 2fdd05c631 ✨ 账单明细展示收货时间 2026-11-20 13:47:19 +08:00
caojia 5cb3735cdf 💄 调整应收账单汇总表行边框样式 2026-11-20 13:47:18 +08:00
caojia 8351411121 🐛 统一应收账单汇总模板日期为明细收货日期范围 2026-11-20 13:47:17 +08:00
caojia 6685f8f38b 🐛 更新应收账单模板并兼容模板样式编号变化 2026-11-20 13:47:16 +08:00
caojia 77e407482a ✨ 支持集运应收账单模板导出并保留固定收款信息 2026-11-20 13:47:16 +08:00
caojia d64f343ecd Merge branch 'test' 2026-11-19 17:17:14 +08:00
caojia ec7f97f831 Merge branch 'test' 2026-11-17 16:55:46 +08:00
caojia 32cea1c348 Merge branch 'test' 2026-11-17 16:20:11 +08:00
caojia ad2d8c8b50 Merge branch 'test' 2026-11-17 15:26:23 +08:00
caojia 4ad799719a Merge branch 'test' 2026-11-17 15:01:33 +08:00
caojia c86cad30ec Merge branch 'test' 2026-11-17 11:28:28 +08:00
caojia 33e8a5890a ✨ 应收账单计费重优先取 charge_weight,空值回退 weight 2026-11-17 11:27:19 +08:00
wuweihua 8ede0bb5ec 移除原计费重显示 2026-11-17 11:27:18 +08:00
caojia 366ddff0b3 去掉导出日志功能 2026-11-17 11:27:17 +08:00
caojia e2d123de85 去掉导出日志功能 2026-11-17 11:27:16 +08:00
caojia e22f4bc9d7 ⚡ 优化毛利分析订单查询 2026-11-17 11:27:15 +08:00
wuweihua 7500728c1d 优化计费任务列表状态过滤逻辑,更新计费重和客户确认重字段名称 2026-11-17 11:27:14 +08:00
caojia ea62697b98 ✨ 毛利分析合并订单明细及产品筛选 2026-11-16 20:29:56 +08:00
caojia 9273fcec56 Merge branch 'test' 2026-11-16 15:00:09 +08:00
wuweihua 0400f55838 Merge branch 'test' of https://git.lionquexpress.com/wuweihua/BMS
# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.
2026-11-15 20:47:28 +08:00
wuweihua 2f25a99396 Merge branch 'test' of https://git.lionquexpress.com/wuweihua/BMS
# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.
2026-11-15 09:41:04 +08:00
wuweihua 48b7fbc7cf Merge branch 'master' of D:\wuweihua\BMS with conflicts. 2026-11-15 09:03:49 +08:00
wuweihua 15a72e3503 Merge branch 'test' of https://git.lionquexpress.com/wuweihua/BMS
# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.
2026-11-15 09:02:44 +08:00
wuweihua 99651b6758 Merge branch 'master' of D:\wuweihua\BMS with conflicts. 2026-11-15 00:23:04 +08:00
wuweihua 2342d34194 Merge branch 'test' of https://git.lionquexpress.com/wuweihua/BMS
# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.
2026-11-15 00:22:34 +08:00
wuweihua bcd9c789cb Merge branch 'master' of D:\wuweihua\BMS with conflicts. 2026-11-14 19:57:30 +08:00
wuweihua bf7b46a231 Merge branch 'test' of https://git.lionquexpress.com/wuweihua/BMS
# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.
2026-11-14 19:55:06 +08:00
wuweihua 6f78b813f3 Merge branch 'master' of D:\wuweihua\BMS with conflicts. 2026-11-14 19:29:38 +08:00
wuweihua a71f0a164f Merge branch 'test' of https://git.lionquexpress.com/wuweihua/BMS
# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.
2026-11-14 19:28:58 +08:00
wuweihua f7c7d9fe8b Merge branch 'test' of https://git.lionquexpress.com/wuweihua/BMS
# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.
2026-11-14 19:03:19 +08:00
caojia 2d5ffc4e06 Merge branch 'test' 2026-11-12 18:10:16 +08:00
wuweihua f03aa7be6c Merge branch 'test' of https://git.lionquexpress.com/wuweihua/BMS
# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.
2026-11-12 17:12:21 +08:00
caojia 73ce7f4eae Merge branch 'test' 2026-11-12 15:05:39 +08:00
caojia b49600ab9f Merge branch 'test'
# Conflicts:
#	bms-back/bms-system/src/main/java/com/bms/price/service/impl/PrcOrderBillServiceImpl.java
2026-11-11 17:57:33 +08:00
caojia fb41b2a86c Merge branch 'test' 2026-11-11 11:32:25 +08:00
wuweihua fe30b8576b Merge branch 'master' of https://git.lionquexpress.com/wuweihua/BMS 2026-11-10 19:02:52 +08:00
wuweihua 65fcb6895a 修改计费bug 2026-11-10 19:02:47 +08:00
caojia d4f5bb8a4c Merge branch 'test' 2026-11-10 18:11:49 +08:00
caojia e71103af58 Merge branch 'test' 2026-11-10 18:04:49 +08:00
caojia 79cc524c03 Merge branch 'test'
# Conflicts:
#	bms-back/bms-admin/src/main/java/com/bms/web/controller/price/SrvBillAirController.java
#	bms-back/bms-system/src/main/java/com/bms/price/airbill/domain/SrvBillAirFee.java
#	bms-back/bms-system/src/main/java/com/bms/price/airbill/domain/SrvBillAirFeeLog.java
#	bms-back/bms-system/src/main/java/com/bms/price/mapper/PrcOrderBillMapper.java
#	bms-back/bms-system/src/main/java/com/bms/price/mapper/SrvBillAirFeeMapper.java
#	bms-back/bms-system/src/main/java/com/bms/price/service/ISrvBillAirFeeService.java
#	bms-back/bms-system/src/main/java/com/bms/price/service/impl/SrvBillAirFeeServiceImpl.java
#	bms-back/bms-system/src/main/resources/mapper/price/SrvBillAirFeeMapper.xml
#	bms-back/sql/price/air_bill_menu.sql
#	bms-front/src/api/price/airBill.js
#	bms-front/src/views/price/billing/airBill.vue
#	bms-front/src/views/price/billing/components/AirBillFeeDialog.vue
#	bms-front/src/views/price/billing/components/BillDetail.vue
2026-11-10 17:46:55 +08:00
wuweihua efc7ecbd01 增加计费日志显示 2026-11-09 14:26:37 +08:00
wuweihua b8bbf36767 修改删除逻辑 2026-11-09 14:26:36 +08:00
wuweihua 92cb19fbea 合并套餐 2026-11-09 11:45:35 +08:00
wuweihua 4cb82ec107 修改去空格 2026-11-09 11:45:33 +08:00
liuminghui e0dc755ee3 新增提单费用和费用日志 2026-11-09 11:45:27 +08:00
wuweihua 6a02de8069 增加计费列表收货时间查询 2026-11-09 11:45:26 +08:00
wuweihua 974f12429a 回退代码去掉收货查询 2026-11-09 11:45:25 +08:00
wuweihua e06f07b3dd 去掉监控的价格日志 2026-11-09 11:45:24 +08:00
wuweihua 956fb08bea 增加价格变更日志 2026-11-09 11:45:23 +08:00
wuweihua 8d34f84cbb 增加版本号显示 2026-11-09 11:45:22 +08:00
wuweihua b9cdb6c3f9 增加查看计费历史记录 2026-11-09 11:45:20 +08:00
wuweihua f57af555ea 增加查看价格套餐历史版本的变更 2026-11-09 11:45:20 +08:00
caojia 220b01127b 调整模板 2026-11-09 11:29:34 +08:00
caojia aa61dc2d1c 🐛 修正账单预览导出重量精度 2026-11-09 11:29:34 +08:00
caojia 86ed86fc68 🐛 修正账单预览重量精度显示 2026-11-09 11:29:33 +08:00
caojia fba8b786c0 Merge branch 'test' 2026-11-05 17:21:01 +08:00
caojia a4bda4d636 Merge branch 'test' 2026-11-04 18:32:28 +08:00
caojia 00e36cdf3f Merge branch 'test' 2026-11-04 15:20:56 +08:00
caojia 8eb5dca4f0 Merge branch 'test' 2026-11-04 13:45:59 +08:00
caojia b671ebefae Merge branch 'test' 2026-11-04 13:40:30 +08:00
caojia fb5d6d46a8 Merge branch 'test' 2026-11-04 10:27:30 +08:00
wuweihua 039c0d4858 Merge branch 'test' of https://git.lionquexpress.com/wuweihua/BMS
# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.
2026-11-03 18:16:08 +08:00
caojia 43299e5329 Merge branch 'test' 2026-11-03 17:39:19 +08:00
caojia 3fe34c471c Merge branch 'test' 2026-11-02 16:54:26 +08:00
caojia 134855fc31 Merge branch 'test' 2026-11-02 10:07:19 +08:00
caojia 01cee41301 Merge branch 'test' 2026-11-02 09:17:44 +08:00
caojia 1f0d757e29 🐛 按当天截止时间筛选账单订单 2026-10-30 15:55:12 +08:00
caojia 762cad2c0d ✨ 新增应收账单日期类型筛选 2026-10-30 15:23:20 +08:00
wuweihua 7ef3f40a4f Merge branch 'test' of https://git.lionquexpress.com/wuweihua/BMS
# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.
2026-10-29 18:19:48 +08:00
caojia 58e41b669d Merge branch 'test' 2026-10-29 16:59:06 +08:00
caojia 9a48abbacd Merge branch 'test' 2026-10-28 22:25:05 +08:00
wuweihua f95edbdf0a Merge branch 'master' of D:\wuweihua\BMS with conflicts. 2026-10-28 15:57:58 +08:00
wuweihua b30dfdf675 Merge branch 'test' of https://git.lionquexpress.com/wuweihua/BMS
# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.
2026-10-28 15:56:10 +08:00
wuweihua 9a393fe7dc Merge branch 'master' of D:\wuweihua\BMS with conflicts. 2026-10-28 15:32:21 +08:00
wuweihua a2468099c2 Merge branch 'test' of https://git.lionquexpress.com/wuweihua/BMS
# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.
2026-10-28 15:30:47 +08:00
caojia cbed4dc2a3 Merge branch 'test' 2026-10-28 09:28:14 +08:00
caojia d66b96b2ff Merge branch 'test' 2026-10-27 18:25:18 +08:00
wuweihua cdfc90556d 隐藏修改计费重 2026-10-27 17:51:40 +08:00
wuweihua dfa90d6e33 Merge branch 'master' of D:\wuweihua\BMS with conflicts. 2026-10-27 16:25:11 +08:00
wuweihua 4a34075022 Merge branch 'test' of https://git.lionquexpress.com/wuweihua/BMS
# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.
2026-10-27 16:24:36 +08:00
wuweihua 6a03300f2f Merge branch 'test' of https://git.lionquexpress.com/wuweihua/BMS
# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.
2026-10-27 10:31:58 +08:00
liuminghui 7496f8cbc6 Merge branch 'test' 2026-10-27 10:21:57 +08:00
wuweihua 2f2305825a Merge branch 'test' of https://git.lionquexpress.com/wuweihua/BMS
# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.
2026-10-27 01:10:31 +08:00
wuweihua b79cd6f995 Merge branch 'master' of D:\wuweihua\BMS with conflicts. 2026-10-27 00:17:37 +08:00
wuweihua 70a3c34c20 Merge branch 'test' of https://git.lionquexpress.com/wuweihua/BMS
# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.
2026-10-27 00:16:40 +08:00
caojia 2b5633190e Merge branch 'test' 2026-10-26 18:01:23 +08:00
wuweihua 77dfb4291b Merge remote-tracking branch 'origin/test' 2026-10-26 17:13:44 +08:00
caojia d71b7f04fe Merge branch 'test' 2026-10-26 17:09:01 +08:00
caojia f8ae347846 Merge branch 'test' 2026-10-26 16:39:11 +08:00
wuweihua 94991a1ed3 Merge pull request '修改操作文档' (#1) from test into master
Reviewed-on: #1
2026-10-26 15:23:59 +08:00
18 changed files with 494 additions and 87 deletions
@@ -167,6 +167,13 @@ public class ArBillController extends BaseController {
return success(account);
}
/** 生成账单时选择同币种启用账户,账号只返回脱敏值。 */
@PreAuthorize("@ss.hasPermi('ar:bill:generate')")
@GetMapping("/bank-account-options")
public AjaxResult bankAccountOptions(@RequestParam(defaultValue = "CNY") String currency) {
return success(billService.selectMaskedBankAccounts(currency));
}
/**
* 查询生成账单前的订单计费结果。
*/
@@ -0,0 +1,116 @@
package com.bms.receivable;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import java.sql.Date;
import java.util.List;
import com.bms.common.core.domain.model.LoginUser;
import com.bms.common.exception.ServiceException;
import com.bms.customer.customerinfo.domain.BmsCustomerOption;
import com.bms.customer.customerinfo.mapper.BmsCustomerMapper;
import com.bms.receivable.domain.ArBankAccount;
import com.bms.receivable.domain.ArBill;
import com.bms.receivable.domain.vo.ArBillGenerateRequest;
import com.bms.receivable.mapper.ArBankAccountMapper;
import com.bms.receivable.mapper.ArBillGenerateTaskMapper;
import com.bms.receivable.mapper.ArBillMapper;
import com.bms.receivable.security.ArBillScopeResolver;
import com.bms.receivable.service.IArBillLogService;
import com.bms.receivable.service.impl.ArBillServiceImpl;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.test.util.ReflectionTestUtils;
class ArBillGenerateBankAccountTest {
private final ArBillServiceImpl service = new ArBillServiceImpl();
private final ArBillMapper bills = mock(ArBillMapper.class);
private final ArBankAccountMapper accounts = mock(ArBankAccountMapper.class);
private final ArBillGenerateTaskMapper tasks = mock(ArBillGenerateTaskMapper.class);
private final ArBillScopeResolver scope = mock(ArBillScopeResolver.class);
@BeforeEach
void setUp() {
LoginUser login = new LoginUser();
login.setUserId(1L);
SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken(login, null, List.of()));
ReflectionTestUtils.setField(service, "billMapper", bills);
ReflectionTestUtils.setField(service, "bankAccountMapper", accounts);
ReflectionTestUtils.setField(service, "generateTaskMapper", tasks);
ReflectionTestUtils.setField(service, "billScope", scope);
ReflectionTestUtils.setField(service, "customerMapper", mock(BmsCustomerMapper.class));
ReflectionTestUtils.setField(service, "eventPublisher", mock(ApplicationEventPublisher.class));
ReflectionTestUtils.setField(service, "logService", mock(IArBillLogService.class));
BmsCustomerOption customer = new BmsCustomerOption();
customer.setCustomerCode("C1");
customer.setCustomerName("客户");
when(scope.requireCustomerAccessible(1L)).thenReturn(customer);
}
@AfterEach
void clearLogin() { SecurityContextHolder.clearContext(); }
@Test
void selectedAccountIsValidatedAndSavedAsBillSnapshot() {
ArBankAccount account = account("CNY");
when(accounts.selectEnabledById(9L)).thenReturn(account);
ArBillGenerateRequest request = request();
request.setBankAccountId(9L);
request.setBankAccountNo("前端伪造的账号");
service.generateBill(request, "admin", "request-1");
ArgumentCaptor<ArBill> saved = ArgumentCaptor.forClass(ArBill.class);
verify(bills).insertArBill(saved.capture());
assertEquals(account.getAccountName(), saved.getValue().getBankAccountName());
assertEquals(account.getAccountNo(), saved.getValue().getBankAccountNo());
assertEquals(account.getBankName(), saved.getValue().getBankName());
verify(accounts, never()).selectDefaultByCurrency(anyString());
}
@Test
void missingOrWrongCurrencyAccountCannotCreateBillAndOldRequestsUseDefault() {
ArBillGenerateRequest request = request();
request.setBankAccountId(9L);
assertThrows(ServiceException.class, () -> service.generateBill(request, "admin", "missing"));
when(accounts.selectEnabledById(9L)).thenReturn(account("USD"));
assertThrows(ServiceException.class, () -> service.generateBill(request, "admin", "wrong-currency"));
verify(bills, never()).insertArBill(any());
request.setBankAccountId(null);
when(accounts.selectDefaultByCurrency("CNY")).thenReturn(account("CNY"));
assertDoesNotThrow(() -> service.generateBill(request, "admin", "legacy"));
verify(accounts).selectDefaultByCurrency("CNY");
}
@Test
void bankAccountOptionsMaskNumbersWithoutSpaces() {
ArBankAccount account = account("CNY");
when(accounts.selectEnabledList("CNY")).thenReturn(List.of(account));
assertEquals("****2050", service.selectMaskedBankAccounts("CNY").get(0).getAccountNo());
}
private static ArBankAccount account(String currency) {
ArBankAccount account = new ArBankAccount();
account.setAccountName("收款单位");
account.setAccountNo("8602 1110 0008 9205 0");
account.setBankName("开户行");
account.setCurrency(currency);
return account;
}
private static ArBillGenerateRequest request() {
ArBillGenerateRequest request = new ArBillGenerateRequest();
request.setCustomerId(1L);
request.setBillName("测试账单");
request.setBillPeriodEnd(Date.valueOf("2026-10-31"));
request.setSourceBillIds(List.of(1L));
return request;
}
}
@@ -111,6 +111,23 @@ class ArBillTemplateSelectionTest {
assertEquals("应收账单汇总模板", options.get(0).getTemplateName());
}
@Test
void fixedPayeeTemplatesAllowDifferentBillAccountSnapshots() {
bill.setBankAccountName("其他收款单位");
bill.setBankAccountNo("1234567890");
bill.setBankName("其他银行");
ArExportTemplate guangzhou = template(3L, ArBillWorkbookWriters.GUANGZHOU_TEMPLATE_CODE);
guangzhou.setStorageKey("templates/receivable/ar_bill_template_gz.xlsx");
ArExportTemplate jiyun = template(4L, ArBillWorkbookWriters.JIYUN_TEMPLATE_CODE);
jiyun.setStorageKey("templates/receivable/ar_bill_template_jy.xlsx");
when(templates.selectEnabledById(3L, "AR_BILL", bill.getBillDate())).thenReturn(guangzhou);
when(templates.selectEnabledById(4L, "AR_BILL", bill.getBillDate())).thenReturn(jiyun);
assertEquals(3L, service.exportBill(7L, 3L, "admin", "gz-export").getTemplateId());
assertEquals(4L, service.exportBill(7L, 4L, "admin", "jy-export").getTemplateId());
verify(exports, times(2)).insert(any());
}
@Test
void mapperQueriesEnforceBusinessStatusEffectiveDatesAndTaskTemplate() throws Exception {
Configuration configuration = new Configuration();
@@ -5,14 +5,20 @@ import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.nio.file.Files;
import java.nio.file.Path;
import java.sql.Date;
import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.IntStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import com.bms.receivable.domain.ArBill;
import com.bms.receivable.domain.ArBillDetail;
@@ -20,6 +26,8 @@ import com.bms.receivable.domain.ArExportTemplate;
import com.bms.receivable.mapper.ArBillDetailFeeMapper;
import com.bms.receivable.mapper.ArBillDetailMapper;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.DataFormatter;
import org.apache.poi.ss.usermodel.DateUtil;
import org.apache.poi.ss.usermodel.FormulaEvaluator;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.xssf.usermodel.XSSFSheet;
@@ -31,12 +39,42 @@ class ArBillWorkbookWriterTest {
@TempDir
Path temporary;
@Test
void summaryDetailsKeepReceiptDateTimeAsExcelDateForNormalAndHighlightedRows() throws Exception {
ArBillDetail normal = detail(1, "P1", "1.00");
normal.setReceiveTime(Timestamp.valueOf("2026-10-01 21:32:51"));
ArBillDetail failed = detail(2, "P1", "1.00");
failed.setReceiveTime(Timestamp.valueOf("2026-10-02 00:01:02"));
failed.setBillingFailStatus(2);
ArBillDetail missing = detail(3, "P1", "1.00");
missing.setReceiveTime(null);
Path target = temporary.resolve("summary-receipt-times.xlsx");
summaryWriter(List.of(normal, failed, missing)).write(bill(3, "3.00", "CNY"), summaryTemplate(), target);
try (XSSFWorkbook workbook = new XSSFWorkbook(target.toFile())) {
XSSFSheet sheet = workbook.getSheetAt(1);
var normalCell = sheet.getRow(4).getCell(1);
var failedCell = sheet.getRow(5).getCell(1);
assertEquals(CellType.NUMERIC, normalCell.getCellType());
assertEquals(CellType.NUMERIC, failedCell.getCellType());
assertTrue(DateUtil.isCellDateFormatted(normalCell));
assertTrue(DateUtil.isCellDateFormatted(failedCell));
assertEquals("yyyy/mm/dd", normalCell.getCellStyle().getDataFormatString());
assertEquals("2026/10/01", new DataFormatter().formatCellValue(normalCell));
assertEquals(LocalDateTime.of(2026, 10, 1, 21, 32, 51), normalCell.getLocalDateTimeCellValue());
assertEquals("2026/10/02", new DataFormatter().formatCellValue(failedCell));
assertEquals(LocalDateTime.of(2026, 10, 2, 0, 1, 2), failedCell.getLocalDateTimeCellValue());
assertEquals(IndexedColors.YELLOW.getIndex(), failedCell.getCellStyle().getFillForegroundColor());
assertEquals("", sheet.getRow(6).getCell(1).getStringCellValue());
}
}
@Test
void summaryAndDetailsReconcileSnapshotAmountsAndKeepFreightFormulaAndBlankFields() throws Exception {
ArBill bill = bill(3, "13.20", "CNY");
List<ArBillDetail> details = List.of(detail(1, "P1", "10.12"), detail(2, "P1", "-2.22"),
detail(3, "P2", "5.30"));
// 相同名称的不同产品仍需分组;收货日期也不能替代账单所属期。
// 相同名称的不同产品仍需分组;日期范围统一按本账单明细的收货日期展示。
details.forEach(row -> row.setProductName("相同产品名"));
Path target = temporary.resolve("summary.xlsx");
SummaryArBillWorkbookWriter writer = summaryWriter(details);
@@ -50,7 +88,7 @@ class ArBillWorkbookWriterTest {
assertEquals("客户 & <测试>", summary.getRow(3).getCell(1).getStringCellValue());
assertEquals("相同产品名", summary.getRow(3).getCell(2).getStringCellValue());
assertEquals("相同产品名", summary.getRow(4).getCell(2).getStringCellValue());
assertEquals("20261001-20261031", summary.getRow(3).getCell(3).getStringCellValue());
assertEquals("20261105-20261105", summary.getRow(3).getCell(3).getStringCellValue());
assertEquals("国际货物运输代理服务费", summary.getRow(4).getCell(6).getStringCellValue());
assertEquals(7.90, summary.getRow(3).getCell(4).getNumericCellValue(), 0.00001);
assertEquals(5.30, summary.getRow(4).getCell(4).getNumericCellValue(), 0.00001);
@@ -61,7 +99,7 @@ class ArBillWorkbookWriterTest {
assertTrue(summary.getMergedRegions().stream().anyMatch(region -> "A11:B11".equals(region.formatAsString())));
assertEquals("客户 & <测试>", freight.getRow(2).getCell(1).getStringCellValue());
assertEquals("20261001-20261031", freight.getRow(2).getCell(18).getStringCellValue());
assertEquals("20261105-20261105", freight.getRow(2).getCell(18).getStringCellValue());
assertEquals("0000123", freight.getRow(4).getCell(0).getStringCellValue());
assertEquals("00000001", freight.getRow(4).getCell(2).getStringCellValue());
assertEquals("001234567890123456789", freight.getRow(4).getCell(3).getStringCellValue());
@@ -176,22 +214,152 @@ class ArBillWorkbookWriterTest {
template.setStorageKey("templates/receivable/ar_bill_template.xlsx");
Path target = temporary.resolve("default.xlsx");
writer.write(bill(1, "1.00", "CNY"), template, target);
try (XSSFWorkbook workbook = new XSSFWorkbook(target.toFile())) {
assertEquals(1, workbook.getNumberOfSheets());
try (InputStream input = getClass().getResourceAsStream("/" + template.getStorageKey());
XSSFWorkbook original = new XSSFWorkbook(input);
XSSFWorkbook workbook = new XSSFWorkbook(target.toFile())) {
assertEquals(original.getNumberOfSheets(), workbook.getNumberOfSheets());
assertEquals(1, workbook.getAllPictures().size());
XSSFSheet sheet = workbook.getSheetAt(0);
assertEquals(21, sheet.getRow(4).getLastCellNum());
assertEquals(original.getSheetAt(0).getRow(5).getCell(18).getCellStyle().getBorderBottom(),
sheet.getRow(4).getCell(18).getCellStyle().getBorderBottom());
assertEquals(original.getSheetAt(0).getRow(5).getCell(18).getCellStyle().getFont().getFontHeight(),
sheet.getRow(4).getCell(18).getCellStyle().getFont().getFontHeight());
assertEquals(1, sheet.getRow(4).getCell(18).getNumericCellValue());
assertEquals("备注 & <快照>", sheet.getRow(4).getCell(19).getStringCellValue());
assertEquals(0, sheet.getRow(5).getPhysicalNumberOfCells());
assertEquals("银行信息", sheet.getRow(6).getCell(1).getStringCellValue());
assertEquals("收款账户快照", sheet.getRow(7).getCell(2).getStringCellValue());
}
try (InputStream input = getClass().getResourceAsStream("/" + template.getStorageKey());
XSSFWorkbook original = new XSSFWorkbook(input)) {
if (original.getNumberOfSheets() > 1) {
assertArrayEquals(zipPart(getClass().getResourceAsStream("/" + template.getStorageKey()), "xl/worksheets/sheet2.xml"),
zipPart(Files.newInputStream(target), "xl/worksheets/sheet2.xml"));
}
}
}
@Test
void summaryDatesUseTheWholeBillsReceiveRangeInsteadOfItsStoredPeriod() throws Exception {
ArBill bill = bill(3, "3.00", "CNY");
bill.setBillPeriodStart(Date.valueOf("2026-09-29"));
bill.setBillPeriodEnd(Date.valueOf("2026-10-31"));
ArBillDetail middle = detail(1, "P1", "1.00");
middle.setReceiveTime(Date.valueOf("2026-10-20"));
ArBillDetail earliest = detail(2, "P2", "1.00");
earliest.setReceiveTime(Date.valueOf("2026-10-01"));
ArBillDetail latest = detail(3, "P1", "1.00");
latest.setReceiveTime(Date.valueOf("2026-10-30"));
SummaryArBillWorkbookWriter writer = summaryWriter(List.of(middle, earliest, latest));
when(writer.detailMapper.selectReceiveTimeRangeByBillId(7L)).thenReturn(Map.of(
"minReceiveTime", LocalDateTime.of(2026, 10, 1, 8, 30),
"maxReceiveTime", Timestamp.valueOf("2026-10-30 23:50:00")));
Path target = temporary.resolve("receive-dates.xlsx");
writer.write(bill, summaryTemplate(), target);
try (XSSFWorkbook workbook = new XSSFWorkbook(target.toFile())) {
XSSFSheet summary = workbook.getSheetAt(0);
XSSFSheet freight = workbook.getSheetAt(1);
assertEquals("20261001-20261030", summary.getRow(3).getCell(3).getStringCellValue());
assertEquals("20261001-20261030", summary.getRow(4).getCell(3).getStringCellValue());
assertEquals("20261001-20261030", freight.getRow(2).getCell(18).getStringCellValue());
assertEquals(LocalDateTime.of(2026, 10, 20, 0, 0), freight.getRow(4).getCell(1).getLocalDateTimeCellValue());
assertEquals(LocalDateTime.of(2026, 10, 1, 0, 0), freight.getRow(5).getCell(1).getLocalDateTimeCellValue());
assertEquals(LocalDateTime.of(2026, 10, 30, 0, 0), freight.getRow(6).getCell(1).getLocalDateTimeCellValue());
}
verify(writer.detailMapper, times(1)).selectReceiveTimeRangeByBillId(7L);
assertEquals(Date.valueOf("2026-09-29"), bill.getBillPeriodStart());
assertEquals(Date.valueOf("2026-10-31"), bill.getBillPeriodEnd());
}
@Test
void summaryDatesStayBlankWhenReceiveTimesAreMissing() throws Exception {
ArBillDetail detail = detail(1, "P1", "1.00");
detail.setReceiveTime(null);
SummaryArBillWorkbookWriter writer = summaryWriter(List.of(detail));
when(writer.detailMapper.selectReceiveTimeRangeByBillId(7L)).thenReturn(Map.of());
Path target = temporary.resolve("missing-receive-dates.xlsx");
writer.write(bill(1, "1.00", "CNY"), summaryTemplate(), target);
try (XSSFWorkbook workbook = new XSSFWorkbook(target.toFile())) {
assertEquals("", workbook.getSheetAt(0).getRow(3).getCell(3).getStringCellValue());
assertEquals("", workbook.getSheetAt(1).getRow(2).getCell(18).getStringCellValue());
assertEquals("", workbook.getSheetAt(1).getRow(4).getCell(1).getStringCellValue());
}
}
@Test
void fixedPayeeTemplatesKeepTheirOwnBankDetailsAndSecondSheetWhileFillingOrders() throws Exception {
for (String code : List.of(ArBillWorkbookWriters.GUANGZHOU_TEMPLATE_CODE,
ArBillWorkbookWriters.JIYUN_TEMPLATE_CODE)) {
String suffix = ArBillWorkbookWriters.JIYUN_TEMPLATE_CODE.equals(code) ? "jy" : "gz";
ArExportTemplate template = new ArExportTemplate();
template.setTemplateCode(code);
template.setStorageKey("templates/receivable/ar_bill_template_" + suffix + ".xlsx");
DefaultArBillWorkbookWriter writer = new DefaultArBillWorkbookWriter();
ArBillDetail success = detail(1, "P1", "1.00");
ArBillDetail failed = detail(2, "P2", "2.25");
failed.setBillingFailStatus(2);
writer.detailMapper = mapper(List.of(success, failed));
when(writer.detailMapper.selectReceiveTimeRangeByBillId(7L)).thenReturn(Map.of(
"minReceiveTime", Date.valueOf("2026-11-05"), "maxReceiveTime", Date.valueOf("2026-11-05")));
writer.detailFeeMapper = mock(ArBillDetailFeeMapper.class);
when(writer.detailFeeMapper.selectByDetailIds(anyList())).thenReturn(List.of());
ArBill bill = bill(2, "3.25", "CNY");
bill.setWrittenOffAmount(BigDecimal.ONE);
bill.setUnwrittenAmount(new BigDecimal("2.25"));
Path target = temporary.resolve(suffix + ".xlsx");
writer.write(bill, template, target);
try (InputStream input = getClass().getResourceAsStream("/" + template.getStorageKey());
XSSFWorkbook original = new XSSFWorkbook(input);
XSSFWorkbook exported = new XSSFWorkbook(target.toFile())) {
assertEquals(2, exported.getNumberOfSheets());
assertEquals("运费", exported.getSheetName(0));
assertEquals("汇总表", exported.getSheetName(1));
assertEquals(original.getAllPictures().size(), exported.getAllPictures().size());
XSSFSheet source = original.getSheetAt(0);
XSSFSheet freight = exported.getSheetAt(0);
assertEquals(source.getRow(0).getCell(0).getStringCellValue(), freight.getRow(0).getCell(0).getStringCellValue());
for (int row = 6; row <= 8; row++) {
assertEquals(source.getRow(row).getCell(2).getStringCellValue(),
freight.getRow(row + 2).getCell(2).getStringCellValue());
}
assertEquals("客户 & <测试>", freight.getRow(2).getCell(2).getStringCellValue());
assertEquals("2026-11-05 至 2026-11-05", freight.getRow(2).getCell(14).getStringCellValue());
assertEquals("ORDER1", freight.getRow(4).getCell(2).getStringCellValue());
assertEquals("001234567890123456789", freight.getRow(4).getCell(3).getStringCellValue());
assertEquals(1.00, freight.getRow(4).getCell(18).getNumericCellValue(), 0.00001);
assertEquals(2.25, freight.getRow(5).getCell(18).getNumericCellValue(), 0.00001);
assertEquals("备注 & <快照>", freight.getRow(4).getCell(19).getStringCellValue());
assertEquals("销售价未匹配国家", freight.getRow(5).getCell(20).getStringCellValue());
assertEquals(IndexedColors.YELLOW.getIndex(), freight.getRow(5).getCell(18).getCellStyle().getFillForegroundColor());
assertEquals(0, freight.getRow(6).getPhysicalNumberOfCells());
assertEquals("银行信息", freight.getRow(7).getCell(1).getStringCellValue());
assertEquals(3.25, freight.getRow(7).getCell(18).getNumericCellValue(), 0.00001);
assertEquals(1.00, freight.getRow(8).getCell(18).getNumericCellValue(), 0.00001);
assertEquals("S8-S9", freight.getRow(9).getCell(18).getCellFormula());
assertEquals(2.25, freight.getRow(9).getCell(18).getNumericCellValue(), 0.00001);
assertTrue(freight.getMergedRegions().stream().anyMatch(region -> "C9:E9".equals(region.formatAsString())));
}
assertArrayEquals(zipPart(getClass().getResourceAsStream("/" + template.getStorageKey()), "xl/worksheets/sheet2.xml"),
zipPart(Files.newInputStream(target), "xl/worksheets/sheet2.xml"));
}
}
private byte[] zipPart(InputStream input, String path) throws IOException {
try (ZipInputStream zip = new ZipInputStream(input)) {
for (ZipEntry entry; (entry = zip.getNextEntry()) != null; ) {
if (path.equals(entry.getName())) return zip.readAllBytes();
}
}
throw new IOException("Missing ZIP entry: " + path);
}
private SummaryArBillWorkbookWriter summaryWriter(List<ArBillDetail> details) {
SummaryArBillWorkbookWriter writer = new SummaryArBillWorkbookWriter();
writer.detailMapper = mapper(details);
when(writer.detailMapper.selectReceiveTimeRangeByBillId(7L)).thenReturn(Map.of(
"minReceiveTime", Date.valueOf("2026-11-05"), "maxReceiveTime", Date.valueOf("2026-11-05")));
writer.detailFeeMapper = mock(ArBillDetailFeeMapper.class);
when(writer.detailFeeMapper.selectByDetailIds(anyList())).thenReturn(List.of());
return writer;
@@ -40,6 +40,8 @@ public class ArBillGenerateRequest
@JsonDeserialize(using = StrictDateDeserializer.class)
private Date billDate;
private String currency = "CNY";
/** 收款账户配置 ID;旧调用方未传时沿用币种默认账户。 */
private Long bankAccountId;
/** 订单号、运单号或转单号原始输入,生成时会拆分并再次校验筛选条件。 */
private String orderOrTrackingNo;
private String bankAccountName;
@@ -7,7 +7,12 @@ import java.io.OutputStream;
import java.math.BigDecimal;
import java.nio.file.Files;
import java.nio.file.Path;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -351,6 +356,40 @@ public abstract class ArBillWorkbookSupport implements ArBillWorkbookWriter {
return detail == null ? null : detail.getRegistrationFee();
}
protected String exportReceiveTimeRange(Map<String, Object> receiveTimeRange) {
return exportReceiveTimeRange(receiveTimeRange, "yyyy-MM-dd", " 至 ");
}
/** 所有账单模板使用当前账单明细的收货日期范围,缺失时留空。 */
protected String exportReceiveTimeRange(Map<String, Object> receiveTimeRange, String pattern, String separator) {
if (receiveTimeRange == null) {
return "";
}
String start = formatReceiveDate(receiveTimeRange.get("minReceiveTime"), pattern);
String end = formatReceiveDate(receiveTimeRange.get("maxReceiveTime"), pattern);
return StringUtils.isEmpty(start) || StringUtils.isEmpty(end) ? "" : start + separator + end;
}
private String formatReceiveDate(Object value, String pattern) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);
if (value instanceof LocalDateTime) {
return ((LocalDateTime) value).toLocalDate().format(formatter);
}
if (value instanceof LocalDate) {
return ((LocalDate) value).format(formatter);
}
if (value instanceof java.sql.Date) {
return ((java.sql.Date) value).toLocalDate().format(formatter);
}
if (value instanceof Date) {
return new SimpleDateFormat(pattern).format((Date) value);
}
if (value == null) {
return "";
}
throw new IllegalArgumentException("不支持的收货时间类型: " + value.getClass().getName());
}
protected String exportBankAccountNo(String value) {
if (StringUtils.isEmpty(value)) {
return "";
@@ -8,6 +8,7 @@ import org.springframework.stereotype.Component;
public class ArBillWorkbookWriters {
public static final String SUMMARY_TEMPLATE_CODE = "AR_BILL_SUMMARY";
public static final String GUANGZHOU_TEMPLATE_CODE = "AR_BILL_GZ";
public static final String JIYUN_TEMPLATE_CODE = "AR_BILL_JY";
private final DefaultArBillWorkbookWriter defaultWriter;
private final SummaryArBillWorkbookWriter summaryWriter;
@@ -23,4 +24,5 @@ public class ArBillWorkbookWriters {
public boolean isSummary(ArExportTemplate template) {
return SUMMARY_TEMPLATE_CODE.equals(template.getTemplateCode());
}
}
@@ -8,9 +8,6 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -31,7 +28,7 @@ import com.bms.receivable.domain.ArBillDetail;
import com.bms.receivable.domain.ArBillDetailFee;
import com.bms.receivable.domain.ArExportTemplate;
/** 默认及广州应收账单模板共用的 21 列明细和银行页脚排版。 */
/** 默认、广州及集运应收账单模板共用的 21 列明细和银行页脚排版。 */
@Component
public class DefaultArBillWorkbookWriter extends ArBillWorkbookSupport {
private static final int TEMPLATE_DATA_START_ROW = 5;
@@ -49,7 +46,6 @@ public class DefaultArBillWorkbookWriter extends ArBillWorkbookSupport {
private static final double MIN_TRACKING_NO_COLUMN_WIDTH = MIN_CUSTOMER_ORDER_NO_COLUMN_WIDTH;
private static final double MIN_FORMULA_COLUMN_WIDTH = 17.0;
private static final double MIN_FEE_TYPE_COLUMN_WIDTH = 10.0;
private static final int TEMPLATE_DETAIL_STYLE_INDEX = 31;
private static final String TEMPLATE_SHEET_XML = "xl/worksheets/sheet1.xml";
private static final String TEMPLATE_SHEET_RELATIONSHIPS_XML = "xl/worksheets/_rels/sheet1.xml.rels";
private static final String TEMPLATE_STYLES_XML = "xl/styles.xml";
@@ -79,9 +75,10 @@ public class DefaultArBillWorkbookWriter extends ArBillWorkbookSupport {
public void write(ArBill bill, ArExportTemplate template, Path target) throws IOException {
// 样式表单独读取;不加载整张工作簿,且不依赖 styles.xml 和 sheet1.xml 在 ZIP 中的先后顺序。
StylesTable styles = readExportStyles(template);
boolean guangzhouTemplate = ArBillWorkbookWriters.GUANGZHOU_TEMPLATE_CODE.equals(template.getTemplateCode());
// 广州模板的样式编号与默认模板不同,使用其明细合计单元格的完整边框样式。
int detailStyleIndex = guangzhouTemplate ? readGuangzhouDetailStyleIndex(template) : TEMPLATE_DETAIL_STYLE_INDEX;
boolean preserveTemplatePayee = ArBillWorkbookWriters.GUANGZHOU_TEMPLATE_CODE.equals(template.getTemplateCode())
|| ArBillWorkbookWriters.JIYUN_TEMPLATE_CODE.equals(template.getTemplateCode());
// 所有模板都从实际单元格读取样式,兼容新增 Sheet 或重新保存后变化的样式编号。
int detailStyleIndex = readTemplateDetailStyleIndex(template);
if (detailStyleIndex >= styles.getNumCellStyles()) {
throw new IOException("应收账单导出模板明细样式不存在: " + detailStyleIndex);
}
@@ -157,7 +154,7 @@ public class DefaultArBillWorkbookWriter extends ArBillWorkbookSupport {
}
if (TEMPLATE_SHEET_XML.equals(entry.getName())) {
output.putNextEntry(new ZipEntry(entryName));
int rowOffset = writeOoxmlSheet(readUtf8(templateZip), bill, output, exportStyleIndexes, guangzhouTemplate);
int rowOffset = writeOoxmlSheet(readUtf8(templateZip), bill, output, exportStyleIndexes, preserveTemplatePayee);
output.closeEntry();
replaced = true;
drawingRowOffset = Integer.valueOf(rowOffset);
@@ -184,7 +181,7 @@ public class DefaultArBillWorkbookWriter extends ArBillWorkbookSupport {
}
}
private int readGuangzhouDetailStyleIndex(ArExportTemplate template) throws IOException {
private int readTemplateDetailStyleIndex(ArExportTemplate template) throws IOException {
try (InputStream input = openTemplateStream(template); ZipInputStream zip = new ZipInputStream(input)) {
for (ZipEntry entry; (entry = zip.getNextEntry()) != null; ) {
if (TEMPLATE_SHEET_XML.equals(entry.getName())) {
@@ -199,12 +196,12 @@ public class DefaultArBillWorkbookWriter extends ArBillWorkbookSupport {
}
}
}
throw new IOException("广州应收账单模板缺少 S6 合计单元格样式");
throw new IOException("应收账单模板缺少 S6 合计单元格样式: " + template.getTemplateCode());
}
zip.closeEntry();
}
}
throw new IOException("广州应收账单模板缺少运费工作表");
throw new IOException("应收账单模板缺少运费工作表: " + template.getTemplateCode());
}
private String readTemplateDrawingPartPath(ArExportTemplate template) throws IOException {
@@ -274,7 +271,7 @@ public class DefaultArBillWorkbookWriter extends ArBillWorkbookSupport {
}
private int writeOoxmlSheet(String templateXml, ArBill bill, OutputStream output,
ExportStyleIndexes styleIndexes, boolean guangzhouTemplate) throws IOException {
ExportStyleIndexes styleIndexes, boolean preserveTemplatePayee) throws IOException {
int sheetDataStart = templateXml.indexOf("<sheetData");
int sheetDataOpenEnd = templateXml.indexOf('>', sheetDataStart);
int sheetDataEnd = templateXml.indexOf("</sheetData>", sheetDataOpenEnd);
@@ -288,7 +285,7 @@ public class DefaultArBillWorkbookWriter extends ArBillWorkbookSupport {
removeSheetDimension(templateXml.substring(0, sheetDataOpenEnd + 1)));
writeUtf8(output, prefix);
String headerRow = guangzhouTemplate ? templateRows.get(1) : replaceCellXml(templateRows.get(1), "A1",
String headerRow = preserveTemplatePayee ? templateRows.get(1) : replaceCellXml(templateRows.get(1), "A1",
StringUtils.isEmpty(bill.getBankAccountName()) ? "威狮国际供应链(深圳)有限公司" : bill.getBankAccountName(), false);
writeUtf8(output, headerRow);
writeUtf8(output, templateRows.get(2));
@@ -316,7 +313,7 @@ public class DefaultArBillWorkbookWriter extends ArBillWorkbookSupport {
int rowOffset = lastDetailRow - TEMPLATE_LAST_DETAIL_ROW + EXPORT_FOOTER_GAP_ROWS;
writeUtf8(output, "<row r=\"" + (lastDetailRow + 1) + "\" ht=\""
+ EXPORT_DETAIL_ROW_HEIGHT + "\" customHeight=\"true\"/>");
writeOoxmlFooter(output, templateRows, rowOffset, bill, styleIndexes.generalNumber(), guangzhouTemplate);
writeOoxmlFooter(output, templateRows, rowOffset, bill, styleIndexes.generalNumber(), preserveTemplatePayee);
String suffix = shiftFooterMerges(templateXml.substring(sheetDataEnd), rowOffset);
writeUtf8(output, suffix);
return rowOffset;
@@ -419,7 +416,7 @@ public class DefaultArBillWorkbookWriter extends ArBillWorkbookSupport {
}
private void writeOoxmlFooter(OutputStream output, Map<Integer, String> templateRows, int rowOffset,
ArBill bill, int generalNumberStyleIndex, boolean guangzhouTemplate) throws IOException {
ArBill bill, int generalNumberStyleIndex, boolean preserveTemplatePayee) throws IOException {
String totalAmountFormula = "SUM(S" + TEMPLATE_DATA_START_ROW + ":INDEX(S:S,ROW()-1))";
for (int offset = 0; offset < 4; offset++) {
int sourceRowNumber = TEMPLATE_LAST_DETAIL_ROW + offset + 1;
@@ -432,7 +429,7 @@ public class DefaultArBillWorkbookWriter extends ArBillWorkbookSupport {
nvl(bill.getTotalAmount()), generalNumberStyleIndex);
} else if (offset == 1) {
row = replaceCellXml(row, "B" + targetRowNumber, "开户名", false);
if (!guangzhouTemplate) {
if (!preserveTemplatePayee) {
row = replaceCellXml(row, "C" + targetRowNumber, bill.getBankAccountName(), false);
}
row = replaceCellXml(row, "P" + targetRowNumber, "本期已核销金额", false);
@@ -440,7 +437,7 @@ public class DefaultArBillWorkbookWriter extends ArBillWorkbookSupport {
generalNumberStyleIndex);
} else if (offset == 2) {
row = replaceCellXml(row, "B" + targetRowNumber, "账号", false);
if (!guangzhouTemplate) {
if (!preserveTemplatePayee) {
row = replaceCellXml(row, "C" + targetRowNumber, exportBankAccountNo(bill.getBankAccountNo()), false);
}
row = replaceCellXml(row, "P" + targetRowNumber, "本期未核销金额", false);
@@ -449,7 +446,7 @@ public class DefaultArBillWorkbookWriter extends ArBillWorkbookSupport {
nvl(bill.getUnwrittenAmount()), generalNumberStyleIndex);
} else {
row = replaceCellXml(row, "B" + targetRowNumber, "开户行", false);
if (!guangzhouTemplate) {
if (!preserveTemplatePayee) {
row = replaceCellXml(row, "C" + targetRowNumber, bill.getBankName(), false);
}
}
@@ -534,34 +531,6 @@ public class DefaultArBillWorkbookWriter extends ArBillWorkbookSupport {
return result.toString();
}
private String exportReceiveTimeRange(Map<String, Object> receiveTimeRange) {
if (receiveTimeRange == null) {
return "";
}
String start = formatReceiveDate(receiveTimeRange.get("minReceiveTime"));
String end = formatReceiveDate(receiveTimeRange.get("maxReceiveTime"));
return StringUtils.isEmpty(start) || StringUtils.isEmpty(end) ? "" : start + " 至 " + end;
}
private String formatReceiveDate(Object value) {
if (value instanceof LocalDateTime) {
return ((LocalDateTime) value).toLocalDate().toString();
}
if (value instanceof LocalDate) {
return value.toString();
}
if (value instanceof java.sql.Date) {
return ((java.sql.Date) value).toLocalDate().toString();
}
if (value instanceof Date) {
return new SimpleDateFormat("yyyy-MM-dd").format((Date) value);
}
if (value == null) {
return "";
}
throw new IllegalArgumentException("不支持的收货时间类型: " + value.getClass().getName());
}
private String exportFormula(ArBillDetail detail) {
String formula = joinFeeText(detail.getFees(), true);
if (!StringUtils.isEmpty(formula)) {
@@ -9,7 +9,6 @@ import java.math.BigDecimal;
import java.math.RoundingMode;
import java.nio.file.Files;
import java.nio.file.Path;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
@@ -26,6 +25,8 @@ import com.bms.receivable.domain.ArBillDetail;
import com.bms.receivable.domain.ArBillDetailFee;
import com.bms.receivable.domain.ArExportTemplate;
import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.DateUtil;
import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.xssf.usermodel.XSSFCell;
@@ -55,7 +56,10 @@ public class SummaryArBillWorkbookWriter extends ArBillWorkbookSupport {
Path detailXml = Files.createTempFile("ar-bill-summary-details-", ".xml");
try (InputStream input = openTemplateStream(template); XSSFWorkbook workbook = new XSSFWorkbook(input)) {
validateTemplate(workbook);
prepareTemplate(workbook, bill);
String receiveTimePeriod = exportReceiveTimeRange(
detailMapper.selectReceiveTimeRangeByBillId(bill.getArBillId()), "yyyyMMdd", "-");
prepareTemplate(workbook, bill, receiveTimePeriod);
SummaryStyles summaryStyles = createSummaryStyles(workbook);
DetailStyles detailStyles = createDetailStyles(workbook);
byte[] skeleton = serialize(workbook);
String summaryPath = partPath(workbook.getSheetAt(0));
@@ -92,7 +96,7 @@ public class SummaryArBillWorkbookWriter extends ArBillWorkbookSupport {
for (ZipEntry entry; (entry = zip.getNextEntry()) != null; ) {
output.putNextEntry(new ZipEntry(entry.getName()));
if (summaryPath.equals(entry.getName())) {
writeSummary(summary, bill, groups, result.amount(), output);
writeSummary(summary, bill, groups, result.amount(), receiveTimePeriod, summaryStyles, output);
} else if (detailPath.equals(entry.getName())) {
Files.copy(detailXml, output);
} else {
@@ -133,7 +137,7 @@ public class SummaryArBillWorkbookWriter extends ArBillWorkbookSupport {
return row;
}
private void prepareTemplate(XSSFWorkbook workbook, ArBill bill) throws IOException {
private void prepareTemplate(XSSFWorkbook workbook, ArBill bill, String receiveTimePeriod) throws IOException {
String currency = StringUtils.isEmpty(bill.getCurrency()) ? "CNY" : bill.getCurrency();
String company = StringUtils.isEmpty(bill.getBankAccountName())
? "威狮国际供应链(深圳)有限公司" : bill.getBankAccountName();
@@ -146,7 +150,7 @@ public class SummaryArBillWorkbookWriter extends ArBillWorkbookSupport {
textCell(summary, 11, 1, exportBankAccountNo(bill.getBankAccountNo()));
textCell(summary, 12, 1, bill.getBankName());
textCell(detail, 2, 1, bill.getCustomerName());
textCell(detail, 2, 18, billPeriod(bill));
textCell(detail, 2, 18, receiveTimePeriod);
for (int column : new int[]{11, 12, 13, 15, 16}) {
XSSFCell header = detail.getRow(3).getCell(column);
header.setCellValue(header.getStringCellValue().replace("CNY", currency));
@@ -155,10 +159,11 @@ public class SummaryArBillWorkbookWriter extends ArBillWorkbookSupport {
XSSFCell cell = detail.getRow(4).getCell(column, XSSFRow.MissingCellPolicy.CREATE_NULL_AS_BLANK);
boolean identifier = column == 0 || column == 2 || column == 3 || column == 6;
boolean money = column == 10 || column == 13 || column == 14 || column == 15 || column == 16;
if (!identifier && !money) continue;
boolean receiveDate = column == 1;
if (!identifier && !money && !receiveDate) continue;
XSSFCellStyle style = workbook.createCellStyle();
style.cloneStyleFrom(cell.getCellStyle());
String format = identifier ? "@" : "0.00";
String format = receiveDate ? "yyyy/mm/dd" : identifier ? "@" : "0.00";
style.setDataFormat(workbook.createDataFormat().getFormat(format));
cell.setCellStyle(style);
}
@@ -190,7 +195,28 @@ public class SummaryArBillWorkbookWriter extends ArBillWorkbookSupport {
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
failed[column] = Short.toUnsignedInt(style.getIndex());
}
return new DetailStyles(normal, failed, workbook.getSheetAt(1).getRow(4).getHeightInPoints());
return new DetailStyles(normal, failed, workbook.getSheetAt(1).getRow(4).getHeightInPoints(), workbook.isDate1904());
}
/** 产品行之间不画网格线;最后一行沿用模板底边,组成完整外框。 */
private SummaryStyles createSummaryStyles(XSSFWorkbook workbook) throws IOException {
XSSFRow source = requireRow(workbook.getSheetAt(0), SUMMARY_START_ROW - 1);
int[] normal = new int[7];
int[] last = new int[7];
for (int column = 0; column < normal.length; column++) {
XSSFCellStyle original = source.getCell(column, XSSFRow.MissingCellPolicy.CREATE_NULL_AS_BLANK).getCellStyle();
XSSFCellStyle lastStyle = workbook.createCellStyle();
lastStyle.cloneStyleFrom(original);
lastStyle.setBorderTop(BorderStyle.NONE);
if (column > 0) lastStyle.setBorderLeft(BorderStyle.NONE);
if (column < normal.length - 1) lastStyle.setBorderRight(BorderStyle.NONE);
last[column] = Short.toUnsignedInt(lastStyle.getIndex());
XSSFCellStyle normalStyle = workbook.createCellStyle();
normalStyle.cloneStyleFrom(lastStyle);
normalStyle.setBorderBottom(BorderStyle.NONE);
normal[column] = Short.toUnsignedInt(normalStyle.getIndex());
}
return new SummaryStyles(normal, last);
}
private DetailResult writeDetails(SheetXml sheet, ArBill bill, OutputStream output,
@@ -235,11 +261,16 @@ public class SummaryArBillWorkbookWriter extends ArBillWorkbookSupport {
}
private String detailRow(int rowNumber, ArBill bill, ArBillDetail detail,
DetailAmounts amounts, DetailStyles styles) {
DetailAmounts amounts, DetailStyles styles) throws IOException {
String failure = exportBillingFailDescription(detail.getBillingFailStatus());
Double receiveTime = detail.getReceiveTime() == null ? null
: DateUtil.getExcelDate(detail.getReceiveTime(), styles.use1904());
if (receiveTime != null && !DateUtil.isValidExcelDate(receiveTime)) {
throw new IOException("账单明细收货时间超出 Excel 日期范围,请检查账单");
}
Object[] values = {
bill.getCustomerCode(),
detail.getReceiveTime() == null ? "" : new SimpleDateFormat("yyyy-MM-dd").format(detail.getReceiveTime()),
receiveTime,
detail.getTransferNo(), detail.getTrackingNo(),
StringUtils.isEmpty(detail.getProductName()) ? detail.getProductCode() : detail.getProductName(),
StringUtils.isEmpty(detail.getCountryName()) ? detail.getCountryCode() : detail.getCountryName(),
@@ -305,17 +336,19 @@ public class SummaryArBillWorkbookWriter extends ArBillWorkbookSupport {
}
private void writeSummary(SheetXml sheet, ArBill bill, Map<String, ProductSummary> groups,
BigDecimal total, OutputStream output) throws IOException {
BigDecimal total, String receiveTimePeriod, SummaryStyles styles,
OutputStream output) throws IOException {
writeUtf8(output, sheet.prefix());
for (int row = 1; row <= 3; row++) writeUtf8(output, sheet.rows().get(row));
int rowNumber = SUMMARY_START_ROW;
for (ProductSummary product : groups.values()) {
String row = shiftRowXml(sheet.rows().get(4), rowNumber);
Object[] values = {rowNumber - 3, bill.getCustomerName(), product.name, billPeriod(bill),
int[] rowStyles = rowNumber == SUMMARY_START_ROW + groups.size() - 1 ? styles.last() : styles.normal();
Object[] values = {rowNumber - 3, bill.getCustomerName(), product.name, receiveTimePeriod,
product.amount, bill.getCurrency(), SUMMARY_REMARK};
for (int index = 0; index < values.length; index++) {
row = replaceCellXml(row, (char) ('A' + index) + String.valueOf(rowNumber),
values[index], values[index] instanceof Number);
values[index], values[index] instanceof Number, rowStyles[index]);
}
writeUtf8(output, row);
rowNumber++;
@@ -356,12 +389,6 @@ public class SummaryArBillWorkbookWriter extends ArBillWorkbookSupport {
return FILTER.matcher(suffix).replaceAll("$1" + range + "$2");
}
private String billPeriod(ArBill bill) {
if (bill.getBillPeriodStart() == null || bill.getBillPeriodEnd() == null) return "";
SimpleDateFormat date = new SimpleDateFormat("yyyyMMdd");
return date.format(bill.getBillPeriodStart()) + "-" + date.format(bill.getBillPeriodEnd());
}
private String partPath(XSSFSheet sheet) {
return sheet.getPackagePart().getPartName().getName().substring(1);
}
@@ -390,7 +417,8 @@ public class SummaryArBillWorkbookWriter extends ArBillWorkbookSupport {
private record SheetXml(String prefix, Map<Integer, String> rows, String suffix) { }
private record DetailResult(int count, int lastRow, BigDecimal amount) { }
private record DetailStyles(int[] normal, int[] failed, float rowHeight) { }
private record SummaryStyles(int[] normal, int[] last) { }
private record DetailStyles(int[] normal, int[] failed, float rowHeight, boolean use1904) { }
private record DetailAmounts(BigDecimal freight, BigDecimal processing, BigDecimal remote,
BigDecimal surcharge, BigDecimal romania, BigDecimal total) { }
@@ -42,6 +42,8 @@ public interface IArBillService
List<ArBankAccount> selectEnabledBankAccounts(String currency);
List<ArBankAccount> selectMaskedBankAccounts(String currency);
List<PrcOrderBill> previewBill(ArBillGenerateQuery query);
List<PrcOrderBill> previewBill(ArBillGenerateQuery query, ArBillRowScope scope);
@@ -261,6 +261,13 @@ public class ArBillServiceImpl implements IArBillService {
return accounts;
}
@Override
public List<ArBankAccount> selectMaskedBankAccounts(String currency) {
List<ArBankAccount> accounts = selectEnabledBankAccounts(currency);
accounts.forEach(account -> account.setAccountNo(maskAccount(account.getAccountNo())));
return accounts;
}
/**
* 分页预览可生成订单;多个订单号、运单号或转单号按 OR 条件精确匹配。
*/
@@ -383,10 +390,16 @@ public class ArBillServiceImpl implements IArBillService {
if (generatingBill != null) {
throw new ServiceException("该客户当前账期已有账单正在生成,请稍后再试");
}
ArBankAccount bankAccount = bankAccountMapper.selectDefaultByCurrency(currency);
ArBankAccount bankAccount = request.getBankAccountId() == null
? bankAccountMapper.selectDefaultByCurrency(currency)
: bankAccountMapper.selectEnabledById(request.getBankAccountId());
if (bankAccount == null) {
throw failure(null, ArLogObjectType.BILL, "", ArLogOperationType.GENERATE, null,
"未配置 " + currency + " 币种的公司默认收款账户,请先完成收款账户配置", operator, requestId);
request.getBankAccountId() == null ? "未配置 " + currency + " 币种的公司默认收款账户,请先完成收款账户配置"
: "所选收款账户不存在或已停用,请重新选择", operator, requestId);
}
if (!currency.equalsIgnoreCase(bankAccount.getCurrency())) {
throw new ServiceException("所选收款账户币种与账单币种不一致,请重新选择");
}
Date now = new Date();
@@ -1359,7 +1372,8 @@ public class ArBillServiceImpl implements IArBillService {
private String maskAccount(String value) {
if (StringUtils.isEmpty(value)) return "";
return value.length() <= 4 ? "****" : "****" + value.substring(value.length() - 4);
String normalized = value.replaceAll("[\\s\\p{Z}]+", "");
return normalized.length() <= 4 ? "****" : "****" + normalized.substring(normalized.length() - 4);
}
private String sha256(Path file) throws IOException, NoSuchAlgorithmException {
@@ -0,0 +1,22 @@
-- 集运应收账单模板 v1:适用于已存在 ar_export_template 表的数据库。
-- 执行一次;相同业务类型、模板编码和版本已存在时,唯一索引报错,不覆盖已有配置。
-- 配套部署支持 AR_BILL_JY 的后端代码,导出时保留模板固定公司抬头及收款信息。
INSERT INTO `ar_export_template` (
`template_code`, `template_name`, `business_type`, `template_version`,
`storage_type`, `storage_key`, `file_hash`, `status`, `is_default`,
`effective_start`, `effective_end`, `remark`, `create_by`, `create_time`
) VALUES (
'AR_BILL_JY', '应收账单集运模板', 'AR_BILL', '1.0',
'CLASSPATH', 'templates/receivable/ar_bill_template_jy.xlsx', NULL, 'ENABLED', '0',
NULL, NULL, '威狮国际集运物流(深圳)有限公司应收账单模板',
SUBSTRING_INDEX(CURRENT_USER(), '@', 1), NOW()
);
-- 核对新增记录,正常应返回一条。
SELECT `template_id`, `template_code`, `template_name`, `business_type`,
`template_version`, `storage_type`, `storage_key`, `status`, `is_default`,
`effective_start`, `effective_end`
FROM `ar_export_template`
WHERE `business_type` = 'AR_BILL'
AND `template_code` = 'AR_BILL_JY'
AND `template_version` = '1.0';
+4
View File
@@ -29,6 +29,10 @@ export function getDefaultArBankAccount(currency = 'CNY') {
return request({ url: '/ar/bill/default-bank-account', method: 'get', params: { currency } })
}
export function listArBillBankAccountOptions(currency = 'CNY') {
return request({ url: '/ar/bill/bank-account-options', method: 'get', params: { currency } })
}
export function generateArBill(data) {
return request({ url: '/ar/bill/generate', method: 'post', data, timeout: 30000 })
}
@@ -60,6 +60,7 @@
<el-table-column prop="totalAmount" label="订单金额" width="120" align="right"><template #default="{ row }">{{ money(row.totalAmount) }}</template></el-table-column>
<el-table-column prop="productAmount" label="整单产品价" width="130" align="right"><template #default="{ row }">{{ amount4(row.productAmount) }}</template></el-table-column>
<el-table-column prop="redlineAmount" label="整单红线价" width="130" align="right"><template #default="{ row }">{{ amount4(row.redlineAmount) }}</template></el-table-column>
<el-table-column prop="receiveTime" label="收货时间" width="170"><template #default="{ row }">{{ row.receiveTime || '-' }}</template></el-table-column>
</el-table>
<el-pagination
v-if="detailTotal > 0 || appliedDetailQuery.orderKeyword || appliedDetailQuery.productKeyword"
@@ -32,13 +32,16 @@
</el-row>
</el-form>
<div class="payee-card" v-loading="bankAccountLoading">
<div class="payee-title">收款方信息(按币种自动匹配)</div>
<div class="payee-title">收款方信息</div>
<el-select v-model="selectedBankAccountId" class="payee-select" placeholder="请选择收款账户" :disabled="bankAccountLoading || generateLoading" @change="handleBankAccountChange">
<el-option v-for="account in bankAccounts" :key="account.bankAccountId" :value="String(account.bankAccountId)" :label="`${account.accountName}(${account.accountNo})`" />
</el-select>
<template v-if="bankAccount">
<span><b>开户名:</b>{{ bankAccount.accountName }}</span>
<span><b>开户行:</b>{{ bankAccount.bankName }}</span>
<span><b>账号:</b>{{ bankAccount.accountNo }}</span>
</template>
<span v-else class="payee-empty">当前币种尚未配置公司默认收款账户</span>
<span v-else-if="!bankAccountLoading" class="payee-empty">当前币种尚未配置启用的收款账户</span>
</div>
<div class="preview-toolbar">
<span v-if="previewSearched" class="preview-summary">
@@ -177,7 +180,7 @@
</template>
<script setup name="GenerateBillDialog">
import { listArBillGenerateCustomerOptions, getDefaultArBankAccount, previewArBill, getArBillPreviewAmount, previewExcludedArBill, generateArBill } from '@/api/ar/bill'
import { listArBillGenerateCustomerOptions, listArBillBankAccountOptions, previewArBill, getArBillPreviewAmount, previewExcludedArBill, generateArBill } from '@/api/ar/bill'
import { Download, Refresh, Search, Select } from '@element-plus/icons-vue'
import { AR_BILL_SELECTION_MODE } from '@/constants/ar/enums'
import { exportAsync } from '@/utils/excelExport'
@@ -255,7 +258,10 @@ let excludeRequestSeq = 0
const previewQuery = ref(null)
let syncingPageSelection = false
const bankAccountLoading = ref(false)
const bankAccount = ref(null)
const bankAccounts = ref([])
const selectedBankAccountId = ref('')
const bankAccount = computed(() => bankAccounts.value.find(account => String(account.bankAccountId) === selectedBankAccountId.value) || null)
let bankAccountRequestSeq = 0
const generateRequestId = ref('')
const generateFormRef = ref()
const billNameFormRef = ref()
@@ -288,8 +294,7 @@ function openGenerate() {
Object.assign(billNameForm, { billName: '' })
billNameOpen.value = false
resetPreview()
bankAccount.value = null
loadDefaultBankAccount()
loadBankAccounts()
nextTick(() => generateFormRef.value?.clearValidate())
}
@@ -301,7 +306,7 @@ function handleCustomerChange(_, item) {
function handleCurrencyChange() {
resetPreview()
loadDefaultBankAccount()
loadBankAccounts()
}
// 只清空输入内容,不自动刷新预览;用户点击“查询”后再按新条件查询。
@@ -315,16 +320,25 @@ function clearExcludeIdentifiers() {
invalidateExcludeSearch()
}
function loadDefaultBankAccount() {
function loadBankAccounts() {
const requestSeq = ++bankAccountRequestSeq
bankAccountLoading.value = true
bankAccount.value = null
getDefaultArBankAccount(generateForm.currency).then(res => {
bankAccount.value = res.data || null
bankAccounts.value = []
selectedBankAccountId.value = ''
listArBillBankAccountOptions(generateForm.currency).then(res => {
if (requestSeq !== bankAccountRequestSeq) return
bankAccounts.value = res.data || []
const defaultAccount = bankAccounts.value.find(account => String(account.isDefault) === '1') || bankAccounts.value[0]
selectedBankAccountId.value = defaultAccount ? String(defaultAccount.bankAccountId) : ''
}).finally(() => {
bankAccountLoading.value = false
if (requestSeq === bankAccountRequestSeq) bankAccountLoading.value = false
})
}
function handleBankAccountChange() {
if (!generateLoading.value) generateRequestId.value = ''
}
// 条件变化后清理预览和跨页选中状态;用户点击查询时重新加载第一页。
function resetPreview() {
previewRows.value = []
@@ -363,6 +377,7 @@ function buildGenerateRequest(requestId) {
return {
...(previewQuery.value || buildGenerateQuery()),
billName: billNameForm.billName.trim(),
bankAccountId: selectedBankAccountId.value,
selectionMode: selectionMode.value,
sourceBillIds: selectionMode.value === AR_BILL_SELECTION_MODE.ALL_MATCHED ? [] : selectedRows.value.map(row => String(row.billId)),
excludedSourceBillIds: [],
@@ -673,6 +688,7 @@ function createRequestId() { return globalThis.crypto?.randomUUID?.() || `ar-${D
.order-identifier-clear { position: absolute; top: 4px; right: 6px; z-index: 1; padding: 2px 4px; }
.payee-card { display: flex; align-items: center; flex-wrap: wrap; gap: 16px; min-height: 42px; margin: 4px 0 12px; padding: 9px 12px; border: 1px solid var(--el-border-color-lighter); border-radius: 4px; background: var(--el-fill-color-light); color: var(--el-text-color-regular); font-size: 13px; }
.payee-title { color: var(--el-text-color-primary); font-weight: 600; }
.payee-select { width: 340px; max-width: 100%; }
.payee-empty { color: var(--el-color-danger); }
.preview-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin: 18px 0 10px; padding: 10px 14px; border-radius: 6px; background: var(--el-fill-color-light); color: var(--el-text-color-regular); }
.preview-summary { flex: 1; font-size: 14px; }