1
This commit is contained in:
@@ -13,8 +13,8 @@ final class FinanceOperatorSnapshot {
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
if (authentication != null && authentication.getPrincipal() instanceof AuthenticatedUser user
|
||||
&& user.userId() != null && user.userId() == operatorId
|
||||
&& StringUtils.hasText(user.username())) {
|
||||
return user.username().trim();
|
||||
&& (StringUtils.hasText(user.displayName()) || StringUtils.hasText(user.username()))) {
|
||||
return StringUtils.hasText(user.displayName()) ? user.displayName().trim() : user.username().trim();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -41,23 +41,26 @@ public class ReceivableStatisticsService {
|
||||
LocalDate from = month.atDay(1);
|
||||
LocalDate to = month.plusMonths(1).atDay(1);
|
||||
StringBuilder sql = new StringBuilder("""
|
||||
SELECT tenant_id, customer_name_snapshot,
|
||||
SUM(total_amount) total_receivable,
|
||||
SUM(paid_amount) total_received,
|
||||
SUM(outstanding_amount) total_outstanding
|
||||
FROM fin_settlement
|
||||
WHERE direction='RECEIVABLE'
|
||||
AND status<>'VOIDED'
|
||||
AND currency_code='CNY'
|
||||
AND generated_date>=?
|
||||
AND generated_date<?
|
||||
SELECT s.tenant_id,
|
||||
COALESCE(p.customer_name_snapshot, MAX(s.customer_name_snapshot)) customer_name_snapshot,
|
||||
SUM(s.total_amount) total_receivable,
|
||||
SUM(s.paid_amount) total_received,
|
||||
SUM(s.outstanding_amount) total_outstanding
|
||||
FROM fin_settlement s
|
||||
LEFT JOIN fin_customer_settlement_profile p
|
||||
ON p.tenant_id=s.tenant_id AND p.status='ACTIVE'
|
||||
WHERE s.direction='RECEIVABLE'
|
||||
AND s.status<>'VOIDED'
|
||||
AND s.currency_code='CNY'
|
||||
AND s.generated_date>=?
|
||||
AND s.generated_date<?
|
||||
""");
|
||||
List<Object> args = new ArrayList<>(List.of(from, to));
|
||||
if (customerId != null) {
|
||||
sql.append(" AND tenant_id=?");
|
||||
sql.append(" AND s.tenant_id=?");
|
||||
args.add(customerId);
|
||||
}
|
||||
sql.append(" GROUP BY tenant_id,customer_name_snapshot ORDER BY customer_name_snapshot,tenant_id");
|
||||
sql.append(" GROUP BY s.tenant_id,p.customer_name_snapshot ORDER BY customer_name_snapshot,s.tenant_id");
|
||||
return jdbc.query(sql.toString(), (rs, rowNum) -> checked(new ReceivableStatisticsRow(
|
||||
rs.getLong("tenant_id"), rs.getString("customer_name_snapshot"), CURRENCY,
|
||||
rs.getBigDecimal("total_receivable"), rs.getBigDecimal("total_received"),
|
||||
|
||||
@@ -40,8 +40,8 @@ class ReceivableStatisticsServiceTest {
|
||||
assertThat(result.records()).containsExactly(rows.get(0));
|
||||
var sql = org.mockito.ArgumentCaptor.forClass(String.class);
|
||||
verify(jdbc).query(sql.capture(), any(RowMapper.class), any(Object[].class));
|
||||
assertThat(sql.getValue()).contains("direction='RECEIVABLE'", "status<>'VOIDED'", "currency_code='CNY'",
|
||||
"generated_date>=?", "generated_date<?", "GROUP BY tenant_id,customer_name_snapshot");
|
||||
assertThat(sql.getValue()).contains("s.direction='RECEIVABLE'", "s.status<>'VOIDED'", "s.currency_code='CNY'",
|
||||
"s.generated_date>=?", "s.generated_date<?", "fin_customer_settlement_profile", "GROUP BY s.tenant_id,p.customer_name_snapshot");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -28,6 +28,16 @@ class FinanceOperatorSnapshotTest {
|
||||
assertThat(FinanceOperatorSnapshot.currentName(72L)).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void prefersAuthenticatedDisplayNameOverLoginUsername() {
|
||||
AuthenticatedUser user = new AuthenticatedUser(71L, null, null, null,
|
||||
"12555214478", "廖万昌", "MERCHANT", "WEB", Set.of(), false, null, null, false);
|
||||
SecurityContextHolder.getContext().setAuthentication(
|
||||
new UsernamePasswordAuthenticationToken(user, null));
|
||||
|
||||
assertThat(FinanceOperatorSnapshot.currentName(71L)).isEqualTo("廖万昌");
|
||||
}
|
||||
|
||||
@Test
|
||||
void labelsSystemGeneratedEntriesWithoutInventingAnOperator() {
|
||||
assertThat(FinanceOperatorSnapshot.currentName(0L)).isEqualTo("系统");
|
||||
|
||||
Reference in New Issue
Block a user