绝对值
This commit is contained in:
parent
6904dd78b2
commit
bcbdc79b6c
@ -18,7 +18,8 @@
|
|||||||
- `employeeName` 和 `storeName` 选填;不传或传空字符串时不限制对应条件。
|
- `employeeName` 和 `storeName` 选填;不传或传空字符串时不限制对应条件。
|
||||||
- 日期包含首尾两天,时间范围为开始日 `00:00:00` 至结束日 `23:59:59`。
|
- 日期包含首尾两天,时间范围为开始日 `00:00:00` 至结束日 `23:59:59`。
|
||||||
- 服务按 `businessTypeName`、`efullname`、`ofullname` 精确筛选,并汇总
|
- 服务按 `businessTypeName`、`efullname`、`ofullname` 精确筛选,并汇总
|
||||||
`detailList.currencyDisedTaxedTotal`;缺少明细时使用 `currencyBillTotal`。
|
`detailList.currencyDisedTaxedTotal`;缺少明细时使用 `currencyBillTotal`。销售出库在
|
||||||
|
NGP 原始数据中可能使用负数表示出库方向,接口按页面“销售收入”口径取绝对值后返回正数。
|
||||||
|
|
||||||
## 成功响应
|
## 成功响应
|
||||||
|
|
||||||
|
|||||||
@ -107,12 +107,14 @@ public class NgpSalesIncomeDayLoader {
|
|||||||
|
|
||||||
private long billCents(JsonNode bill) {
|
private long billCents(JsonNode bill) {
|
||||||
JsonNode details = bill.path("detailList");
|
JsonNode details = bill.path("detailList");
|
||||||
if (!details.isArray() || details.isEmpty()) return signedCents(bill.path("currencyBillTotal"));
|
if (!details.isArray() || details.isEmpty()) {
|
||||||
|
return Math.abs(signedCents(bill.path("currencyBillTotal")));
|
||||||
|
}
|
||||||
long result = 0;
|
long result = 0;
|
||||||
for (JsonNode detail : details) {
|
for (JsonNode detail : details) {
|
||||||
JsonNode amount = firstPresent(detail,
|
JsonNode amount = firstPresent(detail,
|
||||||
"currencyDisedTaxedTotal", "currencyDisedTotal", "currencyTotal");
|
"currencyDisedTaxedTotal", "currencyDisedTotal", "currencyTotal");
|
||||||
result += signedCents(amount);
|
result += Math.abs(signedCents(amount));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -54,9 +54,9 @@ public class NgpSalesIncomeService {
|
|||||||
String businessType = request.businessType().trim();
|
String businessType = request.businessType().trim();
|
||||||
String employeeName = clean(request.employeeName());
|
String employeeName = clean(request.employeeName());
|
||||||
String storeName = clean(request.storeName());
|
String storeName = clean(request.storeName());
|
||||||
long totalCents = repository.sum(
|
long totalCents = Math.abs(repository.sum(
|
||||||
request.startDate(), request.endDate(),
|
request.startDate(), request.endDate(),
|
||||||
normalize(businessType), normalize(employeeName), normalize(storeName));
|
normalize(businessType), normalize(employeeName), normalize(storeName)));
|
||||||
BigDecimal amount = BigDecimal.valueOf(totalCents, 2).setScale(2, RoundingMode.UNNECESSARY);
|
BigDecimal amount = BigDecimal.valueOf(totalCents, 2).setScale(2, RoundingMode.UNNECESSARY);
|
||||||
return new NgpSalesIncomeResponse(
|
return new NgpSalesIncomeResponse(
|
||||||
true,
|
true,
|
||||||
|
|||||||
@ -31,7 +31,7 @@ class NgpSalesIncomeDayLoaderTest {
|
|||||||
1, objectMapper.readTree("""
|
1, objectMapper.readTree("""
|
||||||
{"code":0,"data":{"total":4,"list":[
|
{"code":0,"data":{"total":4,"list":[
|
||||||
{"vchcode":"A","businessTypeName":"普通销售","efullname":"蔡少华","ofullname":"国际站","detailList":[
|
{"vchcode":"A","businessTypeName":"普通销售","efullname":"蔡少华","ofullname":"国际站","detailList":[
|
||||||
{"currencyDisedTaxedTotal":"100000.00"},{"currencyDisedTaxedTotal":"2719.35"}]},
|
{"currencyDisedTaxedTotal":"-100000.00"},{"currencyDisedTaxedTotal":"-2719.35"}]},
|
||||||
{"vchcode":"B","businessTypeName":"普通销售","efullname":"其他人","ofullname":"国际站","currencyBillTotal":"8.00","detailList":[]}
|
{"vchcode":"B","businessTypeName":"普通销售","efullname":"其他人","ofullname":"国际站","currencyBillTotal":"8.00","detailList":[]}
|
||||||
]}}
|
]}}
|
||||||
"""),
|
"""),
|
||||||
|
|||||||
@ -43,7 +43,7 @@ class NgpSalesIncomeServiceTest {
|
|||||||
@Test
|
@Test
|
||||||
void returnsOnlyTheRequestedSalesIncomeTotal() {
|
void returnsOnlyTheRequestedSalesIncomeTotal() {
|
||||||
when(repository.findRefreshTime(any())).thenReturn(Optional.of(LocalDateTime.now()));
|
when(repository.findRefreshTime(any())).thenReturn(Optional.of(LocalDateTime.now()));
|
||||||
when(repository.sum(any(), any(), anyString(), anyString(), anyString())).thenReturn(10_271_935L);
|
when(repository.sum(any(), any(), anyString(), anyString(), anyString())).thenReturn(-10_271_935L);
|
||||||
NgpSalesIncomeRequest request = new NgpSalesIncomeRequest(
|
NgpSalesIncomeRequest request = new NgpSalesIncomeRequest(
|
||||||
LocalDate.of(2026, 8, 3), LocalDate.of(2026, 8, 10), "普通销售", "蔡少华", "");
|
LocalDate.of(2026, 8, 3), LocalDate.of(2026, 8, 10), "普通销售", "蔡少华", "");
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user