Browse Source

综合查询添加分页

bai 3 weeks ago
parent
commit
ced107b77f

+ 57 - 20
blade-service/blade-u9cloud/src/main/java/org/springblade/u9cloud/controller/ComprehensiveQueryController.java

@@ -3,6 +3,8 @@ package org.springblade.u9cloud.controller;
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
@@ -50,10 +52,14 @@ public class ComprehensiveQueryController {
 
 	/**
 	 * 综合查询--发货状态查询(全字段覆盖+复杂查询支持)
-	 * 支持:精准/模糊/日期范围/数值范围/多状态组合查询,返回列表格式结果
+	 * 支持:精准/模糊/日期范围/数值范围/多状态组合查询+分页,返回列表格式结果
 	 */
 	@GetMapping("/ShippingStatusInquiry")
-	@ApiOperation(value = "发货状态综合查询", notes = "支持多条件组合查询,返回发货数据列表")
+	@ApiOperation(value = "发货状态综合查询", notes = "支持多条件组合查询+分页,返回发货数据列表")
+	@ApiImplicitParams({
+		@ApiImplicitParam(name = "pageNum", value = "页码(默认1)", paramType = "query", dataType = "int", defaultValue = "1"),
+		@ApiImplicitParam(name = "pageSize", value = "每页条数(默认10,最大100)", paramType = "query", dataType = "int", defaultValue = "10")
+	})
 	public R<List<ZcrmViewShipSel>> shippingStatusInquiry(
 		// 基础精准查询字段
 		ZcrmViewShipSel zcrmViewShipSel,
@@ -70,14 +76,22 @@ public class ComprehensiveQueryController {
 		@RequestParam(required = false) String fuzzyValue,
 		// 多状态组合查询
 		@RequestParam(required = false) String statusList,
-		@RequestParam(required = false) String lineStatusList
+		@RequestParam(required = false) String lineStatusList,
+		// 分页参数
+		@RequestParam(defaultValue = "1") Integer pageNum,
+		@RequestParam(defaultValue = "10") Integer pageSize
 	) {
 		try {
+			// 分页参数校验与处理
+			pageNum = Math.max(pageNum, 1); // 页码最小为1
+			pageSize = Math.max(Math.min(pageSize, 100), 1); // 每页条数限制1-100
+			int offset = (pageNum - 1) * pageSize; // 计算偏移量
+
 			// 1. 初始化SQL构建器
 			StringBuilder sqlBuilder = new StringBuilder("select * from ZCRM_View_Ship_Sel where 1=1");
 			Map<String, Object> queryParams = new HashMap<>();
 
-			// 2. 拼接各类查询条件
+			// 2. 拼接各类查询条件(原有逻辑不变)
 			appendExactCondition(sqlBuilder, queryParams, "Org_ID", zcrmViewShipSel.getOrgId());
 			appendExactCondition(sqlBuilder, queryParams, "Org_Code", zcrmViewShipSel.getOrgCode());
 			appendExactCondition(sqlBuilder, queryParams, "Org_Name", zcrmViewShipSel.getOrgName());
@@ -108,12 +122,17 @@ public class ComprehensiveQueryController {
 			appendInCondition(sqlBuilder, queryParams, "Status", statusList);
 			appendInCondition(sqlBuilder, queryParams, "LineStatus", lineStatusList);
 
-			// 3. 构建请求URL(与Service层保持一致:静态调用U9cloudConfig)
+			// 3. 拼接分页条件(核心修改点)
+			sqlBuilder.append(" LIMIT :pageSize OFFSET :offset");
+			queryParams.put("pageSize", pageSize);
+			queryParams.put("offset", offset);
+
+			// 4. 构建请求URL(原有逻辑不变)
 			String url = UriComponentsBuilder.fromHttpUrl(U9cloudConfig.BASE_URL + U9cloudConfig.PATH_API)
 				.encode(StandardCharsets.UTF_8)
 				.toUriString();
 
-			// 4. 构建请求体(与Service层格式一致:Map<String, String>)
+			// 5. 构建请求体(原有逻辑不变
 			Map<String, String> requestBody = new HashMap<>();
 			requestBody.put("SqlString", sqlBuilder.toString());
 			try {
@@ -125,7 +144,7 @@ public class ComprehensiveQueryController {
 				throw new ServiceException("参数序列化失败:" + e.getMessage());
 			}
 
-			// 5. 设置请求头(与Service层逻辑一致
+			// 6. 设置请求头(原有逻辑不变
 			HttpHeaders headers = new HttpHeaders();
 			headers.setContentType(MediaType.APPLICATION_JSON);
 			String token = u9cloudGetTokenUtil.getToken();
@@ -135,7 +154,7 @@ public class ComprehensiveQueryController {
 			headers.set("token", token);
 			HttpEntity<Map<String, String>> requestEntity = new HttpEntity<>(requestBody, headers);
 
-			// 6. 发送请求(泛型匹配Service层的ViewApiResponse
+			// 7. 发送请求(原有逻辑不变
 			RestTemplate restTemplate = new RestTemplate();
 			ParameterizedTypeReference<ViewApiResponse<ZcrmViewShipSel>> typeRef =
 				new ParameterizedTypeReference<ViewApiResponse<ZcrmViewShipSel>>() {
@@ -143,7 +162,7 @@ public class ComprehensiveQueryController {
 			ResponseEntity<ViewApiResponse<ZcrmViewShipSel>> response =
 				restTemplate.exchange(url, HttpMethod.POST, requestEntity, typeRef);
 
-			// 7. 处理响应结果(转换为项目统一的R类型
+			// 8. 处理响应结果(原有逻辑不变
 			ViewApiResponse<ZcrmViewShipSel> responseBody = response.getBody();
 			if (responseBody == null) {
 				log.warn("U9云接口返回空响应体");
@@ -157,12 +176,12 @@ public class ComprehensiveQueryController {
 			}
 
 			List<ZcrmViewShipSel> dataList = responseBody.getData();
-			log.info("发货状态查询成功,返回数据条数:{}", Objects.isNull(dataList) ? 0 : dataList.size());
+			log.info("发货状态查询成功,返回数据条数:{},分页参数:页码{},每页条数{}",
+				Objects.isNull(dataList) ? 0 : dataList.size(), pageNum, pageSize);
 			return R.data(dataList);
 
 		} catch (Exception e) {
 			log.error("发货状态查询异常", e);
-			// 修复:异常分支必须返回R类型,且统一错误提示
 			return R.fail("发货状态查询异常:" + e.getMessage());
 		}
 	}
@@ -172,7 +191,11 @@ public class ComprehensiveQueryController {
 	 * 综合查询--应收单状态查询(全字段覆盖+复杂查询支持)
 	 */
 	@GetMapping("/ARBillHeadStatusInquiry")
-	@ApiOperation(value = "应收单状态综合查询", notes = "支持多条件组合查询,返回应收单数据列表")
+	@ApiOperation(value = "应收单状态综合查询", notes = "支持多条件组合查询+分页,返回应收单数据列表")
+	@ApiImplicitParams({
+		@ApiImplicitParam(name = "pageNum", value = "页码(默认1)", paramType = "query", dataType = "int", defaultValue = "1"),
+		@ApiImplicitParam(name = "pageSize", value = "每页条数(默认10,最大100)", paramType = "query", dataType = "int", defaultValue = "10")
+	})
 	public R<List<ZcrmViewARBillHeadSel>> arBillHeadStatusInquiry(
 		// 基础精准查询字段
 		ZcrmViewARBillHeadSel arBillHeadSel,
@@ -190,14 +213,22 @@ public class ComprehensiveQueryController {
 		@RequestParam(required = false) String fuzzyFields,
 		@RequestParam(required = false) String fuzzyValue,
 		// 多状态组合查询
-		@RequestParam(required = false) String docStatusList
+		@RequestParam(required = false) String docStatusList,
+		// 分页参数
+		@RequestParam(defaultValue = "1") Integer pageNum,
+		@RequestParam(defaultValue = "10") Integer pageSize
 	) {
 		try {
+			// 分页参数校验与处理
+			pageNum = Math.max(pageNum, 1); // 页码最小为1
+			pageSize = Math.max(Math.min(pageSize, 100), 1); // 每页条数限制1-100
+			int offset = (pageNum - 1) * pageSize; // 计算偏移量
+
 			// 1. 初始化SQL构建器
 			StringBuilder sqlBuilder = new StringBuilder("select * from ZCRM_View_ARBillHead_Sel where 1=1");
 			Map<String, Object> queryParams = new HashMap<>();
 
-			// 2. 拼接各类查询条件
+			// 2. 拼接各类查询条件(原有逻辑不变)
 			// 组织相关
 			appendExactCondition(sqlBuilder, queryParams, "Org_ID", arBillHeadSel.getOrgId());
 			appendExactCondition(sqlBuilder, queryParams, "Org_Code", arBillHeadSel.getOrgCode());
@@ -236,12 +267,17 @@ public class ComprehensiveQueryController {
 			// 多状态组合(单据状态)
 			appendInCondition(sqlBuilder, queryParams, "DocStatus", docStatusList);
 
-			// 3. 构建请求URL
+			// 3. 拼接分页条件(核心新增逻辑)
+			sqlBuilder.append(" LIMIT :pageSize OFFSET :offset");
+			queryParams.put("pageSize", pageSize);
+			queryParams.put("offset", offset);
+
+			// 4. 构建请求URL(原有逻辑不变)
 			String url = UriComponentsBuilder.fromHttpUrl(U9cloudConfig.BASE_URL + U9cloudConfig.PATH_API)
 				.encode(StandardCharsets.UTF_8)
 				.toUriString();
 
-			// 4. 构建请求体
+			// 5. 构建请求体(原有逻辑不变)
 			Map<String, String> requestBody = new HashMap<>();
 			requestBody.put("SqlString", sqlBuilder.toString());
 			try {
@@ -253,7 +289,7 @@ public class ComprehensiveQueryController {
 				throw new ServiceException("参数序列化失败:" + e.getMessage());
 			}
 
-			// 5. 设置请求头
+			// 6. 设置请求头(原有逻辑不变)
 			HttpHeaders headers = new HttpHeaders();
 			headers.setContentType(MediaType.APPLICATION_JSON);
 			String token = u9cloudGetTokenUtil.getToken();
@@ -263,7 +299,7 @@ public class ComprehensiveQueryController {
 			headers.set("token", token);
 			HttpEntity<Map<String, String>> requestEntity = new HttpEntity<>(requestBody, headers);
 
-			// 6. 发送请求
+			// 7. 发送请求(原有逻辑不变)
 			RestTemplate restTemplate = new RestTemplate();
 			ParameterizedTypeReference<ViewApiResponse<ZcrmViewARBillHeadSel>> typeRef =
 				new ParameterizedTypeReference<ViewApiResponse<ZcrmViewARBillHeadSel>>() {
@@ -271,7 +307,7 @@ public class ComprehensiveQueryController {
 			ResponseEntity<ViewApiResponse<ZcrmViewARBillHeadSel>> response =
 				restTemplate.exchange(url, HttpMethod.POST, requestEntity, typeRef);
 
-			// 7. 处理响应结果
+			// 8. 处理响应结果(原有逻辑不变,优化日志)
 			ViewApiResponse<ZcrmViewARBillHeadSel> responseBody = response.getBody();
 			if (responseBody == null) {
 				log.warn("U9云接口返回空响应体");
@@ -285,7 +321,8 @@ public class ComprehensiveQueryController {
 			}
 
 			List<ZcrmViewARBillHeadSel> dataList = responseBody.getData();
-			log.info("应收单状态查询成功,返回数据条数:{}", Objects.isNull(dataList) ? 0 : dataList.size());
+			log.info("应收单状态查询成功,返回数据条数:{},分页参数:页码{},每页条数{}",
+				Objects.isNull(dataList) ? 0 : dataList.size(), pageNum, pageSize);
 			return R.data(dataList);
 
 		} catch (Exception e) {