✨ 支持应收账单明细按单号和产品搜索
This commit is contained in:
+3
-2
@@ -31,6 +31,7 @@ import com.bms.receivable.domain.ArBillDetailFee;
|
||||
import com.bms.receivable.domain.ArBillGenerateTask;
|
||||
import com.bms.receivable.domain.ArBillLog;
|
||||
import com.bms.receivable.domain.vo.ArBillActionRequest;
|
||||
import com.bms.receivable.domain.vo.ArBillDetailQuery;
|
||||
import com.bms.receivable.domain.vo.ArBillGenerateQuery;
|
||||
import com.bms.receivable.domain.vo.ArBillGenerateRequest;
|
||||
import com.bms.receivable.domain.vo.ArBillListExportRow;
|
||||
@@ -141,9 +142,9 @@ public class ArBillController extends BaseController {
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('ar:bill:query')")
|
||||
@GetMapping("/{arBillId}/details")
|
||||
public TableDataInfo details(@PathVariable Long arBillId) {
|
||||
public TableDataInfo details(@PathVariable Long arBillId, @Valid ArBillDetailQuery query) {
|
||||
startPage();
|
||||
return getDataTable(billService.selectArBillDetails(arBillId));
|
||||
return getDataTable(billService.selectArBillDetails(arBillId, query));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,142 @@
|
||||
package com.bms.receivable;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import com.bms.receivable.domain.ArBillDetail;
|
||||
import com.bms.receivable.domain.vo.ArBillDetailQuery;
|
||||
import com.bms.receivable.mapper.ArBillDetailMapper;
|
||||
import com.bms.receivable.security.ArBillRowScope;
|
||||
import com.bms.receivable.security.ArBillScopeResolver;
|
||||
import com.bms.receivable.service.impl.ArBillServiceImpl;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.parser.defaults.DefaultCountSqlParser;
|
||||
import org.apache.ibatis.builder.xml.XMLMapperBuilder;
|
||||
import org.apache.ibatis.mapping.BoundSql;
|
||||
import org.apache.ibatis.session.Configuration;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
class ArBillDetailSearchTest {
|
||||
@Test
|
||||
void numberSearchUsesExactMatchesAndCannotBypassBillOrPermissionScope() throws Exception {
|
||||
ArBillDetailQuery query = new ArBillDetailQuery();
|
||||
query.setOrderKeyword("00123' OR 1=1 --");
|
||||
BoundSql bound = detailSql(query, scope(false, true));
|
||||
String sql = normalized(bound.getSql());
|
||||
assertTrue(sql.contains("where ar_bill_id = ?"));
|
||||
assertTrue(sql.contains("and (order_no = ? or tracking_no = ? or transfer_no = ?)"));
|
||||
assertTrue(sql.contains("b.ar_bill_id = ar_bill_detail.ar_bill_id"));
|
||||
assertTrue(sql.contains("c.customer_id = b.customer_id"));
|
||||
assertTrue(sql.contains("su.user_id = ?"));
|
||||
assertFalse(sql.contains("order_no like"));
|
||||
assertFalse(sql.contains(query.getOrderKeyword()));
|
||||
assertEquals(3, bound.getParameterMappings().stream()
|
||||
.filter(parameter -> parameter.getProperty().equals("query.orderKeyword")).count());
|
||||
}
|
||||
|
||||
@Test
|
||||
void productSearchAndPaginationCountApplyBothFiltersAndTheSameScope() throws Exception {
|
||||
ArBillDetailQuery query = new ArBillDetailQuery();
|
||||
query.setOrderKeyword("ORDER001");
|
||||
query.setProductKeyword("荷兰");
|
||||
String sql = normalized(detailSql(query, scope(false, true)).getSql());
|
||||
assertTrue(sql.contains("and (product_code like concat('%', ?, '%') or product_name like concat('%', ?, '%'))"));
|
||||
String count = normalized(new DefaultCountSqlParser().getSmartCountSql(sql, "0"));
|
||||
assertTrue(count.startsWith("select count(0)"));
|
||||
assertTrue(count.contains("ar_bill_id = ?"));
|
||||
assertTrue(count.contains("order_no = ?"));
|
||||
assertTrue(count.contains("tracking_no = ?"));
|
||||
assertTrue(count.contains("transfer_no = ?"));
|
||||
assertTrue(count.contains("product_code like"));
|
||||
assertTrue(count.contains("product_name like"));
|
||||
assertTrue(count.contains("su.user_id = ?"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void noSearchKeepsExistingQueryAndDeniedScopeRemainsDenied() throws Exception {
|
||||
for (ArBillDetailQuery query : new ArBillDetailQuery[]{null, new ArBillDetailQuery()}) {
|
||||
String sql = normalized(detailSql(query, scope(false, false)).getSql());
|
||||
assertFalse(sql.contains("order_no = ?"));
|
||||
assertFalse(sql.contains("product_code like"));
|
||||
assertTrue(sql.contains("and 1 = 0"));
|
||||
assertTrue(sql.contains("where ar_bill_id = ?"));
|
||||
assertTrue(sql.endsWith("order by detail_no"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void serviceTrimsSearchAndPreservesPaginationForTheScopedDetailQuery() {
|
||||
ArBillServiceImpl service = new ArBillServiceImpl();
|
||||
ArBillDetailMapper details = mock(ArBillDetailMapper.class);
|
||||
ArBillScopeResolver resolver = mock(ArBillScopeResolver.class);
|
||||
ArBillRowScope scope = mock(ArBillRowScope.class);
|
||||
ReflectionTestUtils.setField(service, "detailMapper", details);
|
||||
ReflectionTestUtils.setField(service, "billScope", resolver);
|
||||
when(resolver.resolve()).thenReturn(scope);
|
||||
List<ArBillDetail> result = List.of(new ArBillDetail());
|
||||
when(details.selectByBillIdScoped(eq(7L), any(), same(scope))).thenAnswer(invocation -> {
|
||||
ArBillDetailQuery query = invocation.getArgument(1);
|
||||
assertEquals("000123", query.getOrderKeyword());
|
||||
assertEquals("荷兰", query.getProductKeyword());
|
||||
assertEquals(3, PageHelper.getLocalPage().getPageNum());
|
||||
return result;
|
||||
});
|
||||
ArBillDetailQuery query = new ArBillDetailQuery();
|
||||
query.setOrderKeyword(" 000123 ");
|
||||
query.setProductKeyword(" 荷兰 ");
|
||||
PageHelper.startPage(3, 10);
|
||||
try {
|
||||
assertSame(result, service.selectArBillDetails(7L, query));
|
||||
verify(details).selectByBillIdScoped(eq(7L), any(), same(scope));
|
||||
verifyNoMoreInteractions(details);
|
||||
} finally {
|
||||
PageHelper.clearPage();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void wholeBillExportQueryDoesNotInheritDetailSearchFilters() throws Exception {
|
||||
String sql = normalized(configuration().getMappedStatement("com.bms.receivable.mapper.ArBillDetailMapper.selectExportPage")
|
||||
.getBoundSql(Map.of("arBillId", 7L, "lastDetailNo", 0, "pageSize", 2000)).getSql());
|
||||
assertTrue(sql.contains("where ar_bill_id = ? and detail_no > ?"));
|
||||
assertFalse(sql.contains("order_no = ?"));
|
||||
assertFalse(sql.contains("product_code like"));
|
||||
assertTrue(sql.endsWith("limit ?"));
|
||||
}
|
||||
|
||||
private BoundSql detailSql(ArBillDetailQuery query, Map<String, Object> scope) throws Exception {
|
||||
Map<String, Object> parameters = new HashMap<>();
|
||||
parameters.put("arBillId", 7L);
|
||||
parameters.put("query", query);
|
||||
parameters.put("scope", scope);
|
||||
return configuration().getMappedStatement("com.bms.receivable.mapper.ArBillDetailMapper.selectByBillIdScoped")
|
||||
.getBoundSql(parameters);
|
||||
}
|
||||
|
||||
private Configuration configuration() throws Exception {
|
||||
Configuration configuration = new Configuration();
|
||||
configuration.getTypeAliasRegistry().registerAlias("ArBillDetail", ArBillDetail.class);
|
||||
for (String resource : List.of("mapper/receivable/ArBillScopeMapper.xml", "mapper/receivable/ArBillDetailMapper.xml")) {
|
||||
try (InputStream input = getClass().getClassLoader().getResourceAsStream(resource)) {
|
||||
new XMLMapperBuilder(input, configuration, resource, configuration.getSqlFragments()).parse();
|
||||
}
|
||||
}
|
||||
return configuration;
|
||||
}
|
||||
|
||||
private Map<String, Object> scope(boolean all, boolean self) {
|
||||
return Map.of("all", all, "self", self, "department", false, "userId", 9L, "deptId", 10L);
|
||||
}
|
||||
|
||||
private String normalized(String sql) {
|
||||
return sql.replaceAll("\\s+", " ").trim().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.bms.receivable.domain.vo;
|
||||
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.Data;
|
||||
|
||||
/** 当前账单内的明细筛选条件;账单范围和数据权限由后端独立传入。 */
|
||||
@Data
|
||||
public class ArBillDetailQuery {
|
||||
/** 完整订单号、运单号或转单号,按等值匹配。 */
|
||||
@Size(max = 64, message = "单号不能超过64个字符")
|
||||
private String orderKeyword;
|
||||
|
||||
/** 产品代码或名称,按包含关系匹配。 */
|
||||
@Size(max = 100, message = "产品搜索条件不能超过100个字符")
|
||||
private String productKeyword;
|
||||
}
|
||||
@@ -7,9 +7,12 @@ import java.util.Map;
|
||||
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import com.bms.receivable.domain.ArBillDetail;
|
||||
import com.bms.receivable.domain.vo.ArBillDetailQuery;
|
||||
|
||||
public interface ArBillDetailMapper {
|
||||
List<ArBillDetail> selectByBillIdScoped(@Param("arBillId") Long arBillId, @Param("scope") ArBillRowScope scope);
|
||||
List<ArBillDetail> selectByBillIdScoped(@Param("arBillId") Long arBillId,
|
||||
@Param("query") ArBillDetailQuery query,
|
||||
@Param("scope") ArBillRowScope scope);
|
||||
|
||||
List<ArBillDetail> selectByBillId(Long arBillId);
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ import com.bms.receivable.domain.vo.ArBillGenerateRequest;
|
||||
import com.bms.receivable.domain.vo.ArBillGenerateQuery;
|
||||
import com.bms.receivable.domain.vo.ArBillActionRequest;
|
||||
import com.bms.receivable.domain.vo.ArBillQuery;
|
||||
import com.bms.receivable.domain.vo.ArBillDetailQuery;
|
||||
import com.bms.receivable.domain.vo.ArBillSummary;
|
||||
import com.bms.receivable.domain.vo.ArBillExportTemplateOption;
|
||||
import com.bms.receivable.security.ArBillRowScope;
|
||||
@@ -33,7 +34,7 @@ public interface IArBillService
|
||||
|
||||
ArBill selectArBillById(Long arBillId);
|
||||
|
||||
List<ArBillDetail> selectArBillDetails(Long arBillId);
|
||||
List<ArBillDetail> selectArBillDetails(Long arBillId, ArBillDetailQuery query);
|
||||
|
||||
List<ArBillDetailFee> selectArBillDetailFees(Long arBillId, Long detailId);
|
||||
|
||||
|
||||
+6
-2
@@ -76,6 +76,7 @@ import com.bms.receivable.domain.vo.ArBillActionRequest;
|
||||
import com.bms.receivable.domain.vo.ArBillGenerateQuery;
|
||||
import com.bms.receivable.domain.vo.ArBillGenerateRequest;
|
||||
import com.bms.receivable.domain.vo.ArBillQuery;
|
||||
import com.bms.receivable.domain.vo.ArBillDetailQuery;
|
||||
import com.bms.receivable.domain.vo.ArBillSummary;
|
||||
import com.bms.receivable.domain.vo.ArBillExportTemplateOption;
|
||||
import com.bms.receivable.export.ArBillWorkbookWriters;
|
||||
@@ -210,9 +211,12 @@ public class ArBillServiceImpl implements IArBillService {
|
||||
* 查询账单明细,分页由 Controller 层的 startPage 统一接管。
|
||||
*/
|
||||
@Override
|
||||
public List<ArBillDetail> selectArBillDetails(Long arBillId) {
|
||||
public List<ArBillDetail> selectArBillDetails(Long arBillId, ArBillDetailQuery query) {
|
||||
long startedAt = System.nanoTime();
|
||||
List<ArBillDetail> details = detailMapper.selectByBillIdScoped(arBillId, billScope.resolve());
|
||||
ArBillDetailQuery normalized = query == null ? new ArBillDetailQuery() : query;
|
||||
normalized.setOrderKeyword(StringUtils.trim(normalized.getOrderKeyword()));
|
||||
normalized.setProductKeyword(StringUtils.trim(normalized.getProductKeyword()));
|
||||
List<ArBillDetail> details = detailMapper.selectByBillIdScoped(arBillId, normalized, billScope.resolve());
|
||||
log.debug("应收账单明细查询完成,arBillId={}, resultCount={}, costMs={}",
|
||||
arBillId, details.size(), elapsedMillis(startedAt));
|
||||
return details;
|
||||
|
||||
@@ -51,7 +51,18 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
product_code, product_name, goods_description, country_code, country_name, dest_postcode,
|
||||
actual_weight, receive_weight, volume_weight, charge_weight, freight_rate, registration_fee, pkg_length, pkg_width, pkg_height,
|
||||
currency, total_amount, product_amount, redline_amount, billing_fail_status, remark, create_by, create_time
|
||||
from ar_bill_detail where ar_bill_id = #{arBillId} AND EXISTS (SELECT 1 FROM ar_bill b WHERE b.ar_bill_id = ar_bill_detail.ar_bill_id <include refid="com.bms.receivable.mapper.ArBillScopeMapper.billScope"/>)
|
||||
from ar_bill_detail
|
||||
where ar_bill_id = #{arBillId}
|
||||
<if test="query != null and query.orderKeyword != null and query.orderKeyword != ''">
|
||||
and (order_no = #{query.orderKeyword}
|
||||
or tracking_no = #{query.orderKeyword}
|
||||
or transfer_no = #{query.orderKeyword})
|
||||
</if>
|
||||
<if test="query != null and query.productKeyword != null and query.productKeyword != ''">
|
||||
and (product_code like concat('%', #{query.productKeyword}, '%')
|
||||
or product_name like concat('%', #{query.productKeyword}, '%'))
|
||||
</if>
|
||||
AND EXISTS (SELECT 1 FROM ar_bill b WHERE b.ar_bill_id = ar_bill_detail.ar_bill_id <include refid="com.bms.receivable.mapper.ArBillScopeMapper.billScope"/>)
|
||||
order by detail_no
|
||||
</select>
|
||||
|
||||
|
||||
@@ -19,6 +19,20 @@
|
||||
|
||||
<!-- 账单明细独立分页;费用明细在展开行时再懒加载。 -->
|
||||
<div class="section-title">账单明细({{ detail.orderCount || 0 }})</div>
|
||||
<el-form :model="detailSearchForm" label-width="44px" size="small" class="detail-search-form" @submit.prevent>
|
||||
<el-form-item label="单号">
|
||||
<el-input v-model="detailSearchForm.orderKeyword" placeholder="订单号、运单号或转单号" clearable
|
||||
:maxlength="64" @keyup.enter="handleDetailSearch" />
|
||||
</el-form-item>
|
||||
<el-form-item label="产品">
|
||||
<el-input v-model="detailSearchForm.productKeyword" placeholder="产品代码或名称" clearable
|
||||
:maxlength="100" @keyup.enter="handleDetailSearch" />
|
||||
</el-form-item>
|
||||
<el-form-item class="detail-search-actions" label-width="0">
|
||||
<el-button type="primary" icon="Search" @click="handleDetailSearch">搜索</el-button>
|
||||
<el-button icon="Refresh" @click="resetDetailSearch">重置</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<el-table v-loading="detailListLoading" :data="detailRows" row-key="detailId" border size="small" @expand-change="handleExpandChange">
|
||||
<el-table-column type="expand">
|
||||
<template #default="{ row }">
|
||||
@@ -48,14 +62,14 @@
|
||||
<el-table-column prop="redlineAmount" label="整单红线价" width="130" align="right"><template #default="{ row }">{{ amount4(row.redlineAmount) }}</template></el-table-column>
|
||||
</el-table>
|
||||
<el-pagination
|
||||
v-if="detailTotal > 0"
|
||||
v-if="detailTotal > 0 || appliedDetailQuery.orderKeyword || appliedDetailQuery.productKeyword"
|
||||
class="detail-pagination"
|
||||
v-model:current-page="detailPageNum"
|
||||
v-model:page-size="detailPageSize"
|
||||
:current-page="detailPageNum"
|
||||
:page-size="detailPageSize"
|
||||
:page-sizes="[10, 20, 50]"
|
||||
layout="total, sizes, prev, pager, next, jumper"
|
||||
:total="detailTotal"
|
||||
@current-change="loadDetails"
|
||||
@current-change="handleDetailPageChange"
|
||||
@size-change="handleDetailSizeChange"
|
||||
/>
|
||||
|
||||
@@ -86,6 +100,9 @@ const detailPageNum = ref(1)
|
||||
// 详情默认每页 10 条,避免几十万条账单明细一次性进入浏览器内存。
|
||||
const detailPageSize = ref(10)
|
||||
const detailListLoading = ref(false)
|
||||
const detailSearchForm = reactive({ orderKeyword: '', productKeyword: '' })
|
||||
// 翻页沿用最后一次搜索的条件,输入中的文本只在点击搜索或回车时应用。
|
||||
const appliedDetailQuery = ref({ orderKeyword: '', productKeyword: '' })
|
||||
let detailRequestSerial = 0
|
||||
|
||||
// 切换账单时重置分页和请求序号,旧账单的慢响应不能覆盖新账单。
|
||||
@@ -94,6 +111,9 @@ watch(() => props.detail?.arBillId, billId => {
|
||||
detailPageNum.value = 1
|
||||
detailTotal.value = 0
|
||||
detailRows.value = []
|
||||
detailListLoading.value = false
|
||||
Object.assign(detailSearchForm, { orderKeyword: '', productKeyword: '' })
|
||||
appliedDetailQuery.value = { orderKeyword: '', productKeyword: '' }
|
||||
if (billId) loadDetails()
|
||||
}, { immediate: true })
|
||||
|
||||
@@ -103,16 +123,45 @@ function loadDetails() {
|
||||
if (!billId) return
|
||||
const serial = ++detailRequestSerial
|
||||
detailListLoading.value = true
|
||||
listArBillDetails(billId, { pageNum: detailPageNum.value, pageSize: detailPageSize.value }).then(res => {
|
||||
listArBillDetails(billId, {
|
||||
...appliedDetailQuery.value,
|
||||
pageNum: detailPageNum.value,
|
||||
pageSize: detailPageSize.value
|
||||
}).then(res => {
|
||||
if (serial !== detailRequestSerial) return
|
||||
detailRows.value = (res.rows || []).map(row => ({ ...row, fees: [], feesLoaded: false, feeLoading: false }))
|
||||
detailTotal.value = Number(res.total) || 0
|
||||
}).catch(() => {
|
||||
if (serial !== detailRequestSerial) return
|
||||
detailRows.value = []
|
||||
detailTotal.value = 0
|
||||
}).finally(() => {
|
||||
if (serial === detailRequestSerial) detailListLoading.value = false
|
||||
})
|
||||
}
|
||||
|
||||
function handleDetailSearch() {
|
||||
appliedDetailQuery.value = {
|
||||
orderKeyword: detailSearchForm.orderKeyword.trim(),
|
||||
productKeyword: detailSearchForm.productKeyword.trim()
|
||||
}
|
||||
detailPageNum.value = 1
|
||||
loadDetails()
|
||||
}
|
||||
|
||||
function resetDetailSearch() {
|
||||
Object.assign(detailSearchForm, { orderKeyword: '', productKeyword: '' })
|
||||
handleDetailSearch()
|
||||
}
|
||||
|
||||
function handleDetailPageChange(page) {
|
||||
if (page === detailPageNum.value) return
|
||||
detailPageNum.value = page
|
||||
loadDetails()
|
||||
}
|
||||
|
||||
function handleDetailSizeChange(size) {
|
||||
if (size === detailPageSize.value) return
|
||||
detailPageSize.value = size
|
||||
detailPageNum.value = 1
|
||||
loadDetails()
|
||||
@@ -151,6 +200,9 @@ function mask(value) { if (!value) return '-'; return value.length <= 4 ? '****'
|
||||
.section-title::before { content: ''; width: 3px; height: 15px; border-radius: 2px; background: var(--el-color-primary); }
|
||||
.export-title { justify-content: space-between; }
|
||||
.export-title::before { margin-right: auto; }
|
||||
.detail-search-form { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 12px; }
|
||||
.detail-search-form :deep(.el-form-item) { flex: 1 1 260px; max-width: 360px; margin: 0; }
|
||||
.detail-search-form :deep(.detail-search-actions) { flex: 0 0 auto; max-width: none; }
|
||||
.detail-pagination { justify-content: flex-end; margin: 12px 0 4px; }
|
||||
.fee-panel { min-height: 54px; padding: 4px 12px 8px 42px; background: #fafafa; }
|
||||
.fee-table { background: #fafafa; }
|
||||
|
||||
Reference in New Issue
Block a user