Browse Source

修复理赔综合查询接口-增加get和post接口

bai 1 week ago
parent
commit
7e08f0d545

+ 257 - 25
blade-service/blade-factory/src/main/java/org/springblade/factory/api/controller/ClaimSearchController.java

@@ -21,10 +21,7 @@ import org.springblade.factory.entity.PcBladeClaimAudit;
 import org.springblade.factory.service.PcBladeClaimAttachmentService;
 import org.springblade.factory.service.PcBladeClaimAuditService;
 import org.springblade.factory.service.PcBladeClaimService;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import javax.management.Query;
 import java.math.BigDecimal;
@@ -53,14 +50,14 @@ public class ClaimSearchController {
 	private final PcBladeClaimAuditService pcBladeClaimAuditService;
 
 	/**
-	 * 理赔申请综合查询(实体类接收参数 + 新增字段查询 + 门店名称模糊查询)
+	 * 理赔申请综合查询(严格按实体类标注的精准/模糊规则查询)
 	 */
 	@ApiOperation(value = "理赔申请综合查询", notes = "支持多条件组合查询,返回包含附件和审核记录的完整信息(带数据权限过滤)")
 	@ApiImplicitParams({
 		@ApiImplicitParam(name = "claimSearchParam", value = "理赔查询参数", paramType = "query", dataType = "ClaimSearchParam")
 	})
-	@GetMapping("/comprehensive")
-	public R<IPage<ClaimSearchVO>> comprehensiveSearch(ClaimSearchParam claimSearchParam) {
+	@PostMapping("/PostComprehensive")
+	public R<IPage<ClaimSearchVO>> PostComprehensiveSearch(@RequestBody ClaimSearchParam claimSearchParam) {
 		try {
 			// ========== 1. 登录校验 ==========
 			Long userId = AuthUtil.getUserId();
@@ -128,36 +125,269 @@ public class ClaimSearchController {
 				return R.fail("是否已提交值不合法,可选值:0-未提交 1-已提交");
 			}
 
-			// ========== 5. 构建查询条件 ==========
+			// ========== 5. 构建查询条件(严格按实体类标注的精准/模糊规则) ==========
 			LambdaQueryWrapper<PcBladeClaim> wrapper = new LambdaQueryWrapper<PcBladeClaim>()
-				// 原有精准查询
-				.eq(StringUtils.isNotBlank(claimSearchParam.getClaimNo()), PcBladeClaim::getClaimNo, claimSearchParam.getClaimNo())
+				// -------------------- 精准查询字段(按实体类标注) --------------------
+				.eq(StringUtils.isNotBlank(claimSearchParam.getClaimNo()), PcBladeClaim::getClaimNo, claimSearchParam.getClaimNo()) // 理赔单号(精准)
+				.eq(claimSourceType != null, PcBladeClaim::getClaimSourceType, claimSourceType) // 来源类型(精准)
+				.eq(auditStatus != null, PcBladeClaim::getAuditStatus, auditStatus) // 审核状态(精准)
+				.eq(isSubmitTime != null, PcBladeClaim::getIsSubmitTime, isSubmitTime) // 是否已提交(精准)
+				.eq(claimSearchParam.getTireQuantity() != null, PcBladeClaim::getTireQuantity, claimSearchParam.getTireQuantity()) // 轮胎数量(精准)
+				.eq(StringUtils.isNotBlank(claimSearchParam.getStoreContact()), PcBladeClaim::getStoreContact, claimSearchParam.getStoreContact()) // 门店联系人(精准)
+				.eq(StringUtils.isNotBlank(claimSearchParam.getStorePhone()), PcBladeClaim::getStorePhone, claimSearchParam.getStorePhone()) // 门店联系电话(精准)
+
+				// -------------------- 模糊查询字段(按实体类标注) --------------------
+				.like(StringUtils.isNotBlank(claimSearchParam.getConsumerName()), PcBladeClaim::getConsumerName, "%" + claimSearchParam.getConsumerName() + "%") // 消费者姓名(模糊)
+				.like(StringUtils.isNotBlank(claimSearchParam.getConsumerPhone()), PcBladeClaim::getConsumerPhone, "%" + claimSearchParam.getConsumerPhone() + "%") // 消费者电话(模糊)
+				.like(StringUtils.isNotBlank(claimSearchParam.getTyreNo()), PcBladeClaim::getTyreNo, "%" + claimSearchParam.getTyreNo() + "%") // 胎号(模糊)
+				.like(StringUtils.isNotBlank(claimSearchParam.getTyreSpecs()), PcBladeClaim::getTyreSpecs, "%" + claimSearchParam.getTyreSpecs() + "%") // 规格型号(模糊)
+				.like(StringUtils.isNotBlank(claimSearchParam.getVehicleNumber()), PcBladeClaim::getVehicleNumber, "%" + claimSearchParam.getVehicleNumber() + "%") // 车牌号(模糊)
+				.like(StringUtils.isNotBlank(claimSearchParam.getBrandItem()), PcBladeClaim::getBrandItem, "%" + claimSearchParam.getBrandItem() + "%") // 花纹(模糊)
+				.like(StringUtils.isNotBlank(claimSearchParam.getBrandName()), PcBladeClaim::getBrandName, "%" + claimSearchParam.getBrandName() + "%") // 品牌(模糊)
+				.like(StringUtils.isNotBlank(claimSearchParam.getStoreName()), PcBladeClaim::getStoreName, "%" + claimSearchParam.getStoreName() + "%") // 门店名称(模糊)
+				.like(StringUtils.isNotBlank(claimSearchParam.getStoreAddress()), PcBladeClaim::getStoreAddress, "%" + claimSearchParam.getStoreAddress() + "%") // 门店地址(模糊)
+
+				// -------------------- 范围查询字段 --------------------
+				// 日期范围
+				.ge(purchaseDateStart != null, PcBladeClaim::getPurchaseDate, purchaseDateStart)
+				.le(purchaseDateEnd != null, PcBladeClaim::getPurchaseDate, purchaseDateEnd)
+				// 金额范围
+				.ge(claimAmountMin != null, PcBladeClaim::getClaimAmount, claimAmountMin)
+				.le(claimAmountMax != null, PcBladeClaim::getClaimAmount, claimAmountMax)
+				// 里程范围
+				.ge(runMileageMin != null, PcBladeClaim::getRunMileage, runMileageMin)
+				.le(runMileageMax != null, PcBladeClaim::getRunMileage, runMileageMax)
+
+				// -------------------- 数据权限 + 排序 --------------------
+				.eq(PcBladeClaim::getCreateUser, userId) // 数据权限
+				.orderByDesc(PcBladeClaim::getSubmitTime)
+				.orderByDesc(PcBladeClaim::getCreateTime);
+
+			// ========== 6. 分页查询主表 ==========
+			IPage<PcBladeClaim> page = new Page<>(pageNum, pageSize);
+			page = pcBladeClaimService.page(page, wrapper);
+			List<PcBladeClaim> claimList = page.getRecords();
+
+			if (CollectionUtil.isEmpty(claimList)) {
+				IPage<ClaimSearchVO> emptyPage = new Page<>(pageNum, pageSize, 0);
+				return R.data(emptyPage);
+			}
+
+			// ========== 7. 批量查询关联数据(避免N+1) ==========
+			List<Long> claimIds = claimList.stream().map(PcBladeClaim::getId).collect(Collectors.toList());
+
+			// 查询附件
+			List<PcBladeClaimAttachment> attachmentList = pcBladeClaimAttachmentService.list(
+				new LambdaQueryWrapper<PcBladeClaimAttachment>().in(PcBladeClaimAttachment::getClaimId, claimIds)
+			);
+			Map<Long, List<PcBladeClaimAttachment>> attachmentMap = attachmentList.stream()
+				.collect(Collectors.groupingBy(PcBladeClaimAttachment::getClaimId));
+
+			// 查询审核记录
+			List<PcBladeClaimAudit> auditList = pcBladeClaimAuditService.list(
+				new LambdaQueryWrapper<PcBladeClaimAudit>()
+					.in(PcBladeClaimAudit::getClaimId, claimIds)
+					.orderByDesc(PcBladeClaimAudit::getAuditTime)
+			);
+			Map<Long, List<PcBladeClaimAudit>> auditMap = auditList.stream()
+				.collect(Collectors.groupingBy(PcBladeClaimAudit::getClaimId));
+
+			// ========== 8. 组装返回VO ==========
+			List<ClaimSearchVO> resultVOList = new ArrayList<>();
+			for (PcBladeClaim claim : claimList) {
+				ClaimSearchVO vo = new ClaimSearchVO();
+				vo.setClaimMain(claim);
+				vo.setAttachments(attachmentMap.getOrDefault(claim.getId(), new ArrayList<>()));
+				vo.setAuditRecords(auditMap.getOrDefault(claim.getId(), new ArrayList<>()));
+				resultVOList.add(vo);
+			}
+
+			// ========== 9. 封装分页结果 ==========
+			IPage<ClaimSearchVO> resultPage = new Page<>();
+			resultPage.setCurrent(page.getCurrent());
+			resultPage.setSize(page.getSize());
+			resultPage.setTotal(page.getTotal());
+			resultPage.setPages(page.getPages());
+			resultPage.setRecords(resultVOList);
+
+			return R.data(resultPage);
+
+		} catch (IllegalArgumentException e) {
+			return R.fail("参数错误:" + e.getMessage());
+		} catch (Exception e) {
+			// 生产环境建议添加日志
+			// log.error("理赔综合查询异常", e);
+			return R.fail("查询失败,请稍后重试");
+		}
+	}
+
+
+	/**
+	 * 理赔申请综合查询(直接字段接收参数,按精准/模糊规则查询)
+	 */
+	@ApiOperation(value = "理赔申请综合查询", notes = "支持多条件组合查询,返回包含附件和审核记录的完整信息(带数据权限过滤)")
+	@ApiImplicitParams({
+		// 精准查询参数
+		@ApiImplicitParam(name = "claimNo", value = "理赔单号(精准)", paramType = "query", dataType = "string"),
+		@ApiImplicitParam(name = "claimSourceType", value = "来源类型 1经销商 2门店 3终端消费者(精准)", paramType = "query", dataType = "int"),
+		@ApiImplicitParam(name = "auditStatus", value = "审核状态 0待审核 1审核中 2已通过 3已拒绝(精准)", paramType = "query", dataType = "int"),
+		@ApiImplicitParam(name = "isSubmitTime", value = "是否已提交 0未提交 1已提交(精准)", paramType = "query", dataType = "int"),
+		@ApiImplicitParam(name = "tireQuantity", value = "轮胎数量(精准)", paramType = "query", dataType = "int"),
+		@ApiImplicitParam(name = "storeContact", value = "门店联系人(精准)", paramType = "query", dataType = "string"),
+		@ApiImplicitParam(name = "storePhone", value = "门店联系电话(精准)", paramType = "query", dataType = "string"),
+
+		// 模糊查询参数
+		@ApiImplicitParam(name = "consumerName", value = "消费者姓名(模糊)", paramType = "query", dataType = "string"),
+		@ApiImplicitParam(name = "consumerPhone", value = "消费者电话(模糊)", paramType = "query", dataType = "string"),
+		@ApiImplicitParam(name = "tyreNo", value = "胎号/轮胎宝编号(模糊)", paramType = "query", dataType = "string"),
+		@ApiImplicitParam(name = "tyreSpecs", value = "规格型号(模糊)", paramType = "query", dataType = "string"),
+		@ApiImplicitParam(name = "vehicleNumber", value = "车牌号(模糊)", paramType = "query", dataType = "string"),
+		@ApiImplicitParam(name = "brandItem", value = "花纹(模糊)", paramType = "query", dataType = "string"),
+		@ApiImplicitParam(name = "brandName", value = "品牌(模糊)", paramType = "query", dataType = "string"),
+		@ApiImplicitParam(name = "storeName", value = "门店名称(模糊)", paramType = "query", dataType = "string"),
+		@ApiImplicitParam(name = "storeAddress", value = "门店地址(模糊)", paramType = "query", dataType = "string"),
+
+		// 范围查询参数
+		@ApiImplicitParam(name = "purchaseDateStartStr", value = "购买日期开始(yyyy-MM-dd HH:mm:ss)", paramType = "query", dataType = "string"),
+		@ApiImplicitParam(name = "purchaseDateEndStr", value = "购买日期结束(yyyy-MM-dd HH:mm:ss)", paramType = "query", dataType = "string"),
+		@ApiImplicitParam(name = "claimAmountMin", value = "索赔金额最小值", paramType = "query", dataType = "bigdecimal"),
+		@ApiImplicitParam(name = "claimAmountMax", value = "索赔金额最大值", paramType = "query", dataType = "bigdecimal"),
+		@ApiImplicitParam(name = "runMileageMin", value = "行驶里程最小值(km)", paramType = "query", dataType = "int"),
+		@ApiImplicitParam(name = "runMileageMax", value = "行驶里程最大值(km)", paramType = "query", dataType = "int"),
+
+		// 分页参数
+		@ApiImplicitParam(name = "pageNum", value = "页码(默认1)", paramType = "query", dataType = "int", defaultValue = "1"),
+		@ApiImplicitParam(name = "pageSize", value = "每页条数(默认10,最大100)", paramType = "query", dataType = "int", defaultValue = "10")
+	})
+	@GetMapping("/comprehensive")
+	public R<IPage<ClaimSearchVO>> comprehensiveSearch(
+		// 精准查询参数
+		@RequestParam(required = false) String claimNo,
+		@RequestParam(required = false) Integer claimSourceType,
+		@RequestParam(required = false) Integer auditStatus,
+		@RequestParam(required = false) Integer isSubmitTime,
+		@RequestParam(required = false) Integer tireQuantity,
+		@RequestParam(required = false) String storeContact,
+		@RequestParam(required = false) String storePhone,
+
+		// 模糊查询参数
+		@RequestParam(required = false) String consumerName,
+		@RequestParam(required = false) String consumerPhone,
+		@RequestParam(required = false) String tyreNo,
+		@RequestParam(required = false) String tyreSpecs,
+		@RequestParam(required = false) String vehicleNumber,
+		@RequestParam(required = false) String brandItem,
+		@RequestParam(required = false) String brandName,
+		@RequestParam(required = false) String storeName,
+		@RequestParam(required = false) String storeAddress,
+
+		// 范围查询参数
+		@RequestParam(required = false) String purchaseDateStartStr,
+		@RequestParam(required = false) String purchaseDateEndStr,
+		@RequestParam(required = false) BigDecimal claimAmountMin,
+		@RequestParam(required = false) BigDecimal claimAmountMax,
+		@RequestParam(required = false) Integer runMileageMin,
+		@RequestParam(required = false) Integer runMileageMax,
+
+		// 分页参数
+		@RequestParam(defaultValue = "1") Integer pageNum,
+		@RequestParam(defaultValue = "10") Integer pageSize
+	) {
+		try {
+			// ========== 1. 登录校验 ==========
+			Long userId = AuthUtil.getUserId();
+			if (userId == null) {
+				return R.fail("请先登录后再进行查询");
+			}
+
+			// ========== 2. 分页参数校验 ==========
+			pageNum = Math.max(pageNum, 1);
+			pageSize = Math.max(Math.min(pageSize, 100), 1);
+
+			// ========== 3. 日期转换(兼容所有JDK版本) ==========
+			LocalDateTime purchaseDateStart = null;
+			LocalDateTime purchaseDateEnd = null;
+			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+
+			// 转换开始日期
+			if (StringUtils.isNotBlank(purchaseDateStartStr)) {
+				try {
+					Date startDate = sdf.parse(purchaseDateStartStr);
+					purchaseDateStart = LocalDateTime.ofInstant(startDate.toInstant(), ZoneId.systemDefault());
+				} catch (ParseException e) {
+					return R.fail("购买开始日期格式错误,正确格式:yyyy-MM-dd HH:mm:ss,例如:2025-01-01 12:00:00");
+				}
+			}
+
+			// 转换结束日期
+			if (StringUtils.isNotBlank(purchaseDateEndStr)) {
+				try {
+					Date endDate = sdf.parse(purchaseDateEndStr);
+					purchaseDateEnd = LocalDateTime.ofInstant(endDate.toInstant(), ZoneId.systemDefault());
+				} catch (ParseException e) {
+					return R.fail("购买结束日期格式错误,正确格式:yyyy-MM-dd HH:mm:ss,例如:2025-01-01 12:00:00");
+				}
+			}
+
+			// ========== 4. 业务参数校验 ==========
+			// 日期范围校验
+			if (purchaseDateStart != null && purchaseDateEnd != null && purchaseDateStart.isAfter(purchaseDateEnd)) {
+				return R.fail("购买开始日期不能晚于结束日期");
+			}
+			// 金额范围校验
+			if (claimAmountMin != null && claimAmountMax != null && claimAmountMin.compareTo(claimAmountMax) > 0) {
+				return R.fail("索赔金额最小值不能大于最大值");
+			}
+			// 里程范围校验
+			if (runMileageMin != null && runMileageMax != null && runMileageMin > runMileageMax) {
+				return R.fail("行驶里程最小值不能大于最大值");
+			}
+			// 枚举值校验
+			if (auditStatus != null && !Arrays.asList(0, 1, 2, 3).contains(auditStatus)) {
+				return R.fail("审核状态值不合法,可选值:0-待审核 1-审核中 2-已通过 3-已拒绝");
+			}
+			if (claimSourceType != null && !Arrays.asList(1, 2, 3).contains(claimSourceType)) {
+				return R.fail("来源类型值不合法,可选值:1-经销商 2-门店 3-终端消费者");
+			}
+			if (isSubmitTime != null && !Arrays.asList(0, 1).contains(isSubmitTime)) {
+				return R.fail("是否已提交值不合法,可选值:0-未提交 1-已提交");
+			}
+
+			// ========== 5. 构建查询条件(严格按精准/模糊规则) ==========
+			LambdaQueryWrapper<PcBladeClaim> wrapper = new LambdaQueryWrapper<PcBladeClaim>()
+				// -------------------- 精准查询字段 --------------------
+				.eq(StringUtils.isNotBlank(claimNo), PcBladeClaim::getClaimNo, claimNo)
 				.eq(claimSourceType != null, PcBladeClaim::getClaimSourceType, claimSourceType)
 				.eq(auditStatus != null, PcBladeClaim::getAuditStatus, auditStatus)
 				.eq(isSubmitTime != null, PcBladeClaim::getIsSubmitTime, isSubmitTime)
-				// 原有模糊查询
-				.like(StringUtils.isNotBlank(claimSearchParam.getConsumerName()), PcBladeClaim::getConsumerName, "%" + claimSearchParam.getConsumerName() + "%")
-				.like(StringUtils.isNotBlank(claimSearchParam.getConsumerPhone()), PcBladeClaim::getConsumerPhone, "%" + claimSearchParam.getConsumerPhone() + "%")
-				.like(StringUtils.isNotBlank(claimSearchParam.getTyreNo()), PcBladeClaim::getTyreNo, "%" + claimSearchParam.getTyreNo() + "%")
-				.like(StringUtils.isNotBlank(claimSearchParam.getTyreSpecs()), PcBladeClaim::getTyreSpecs, "%" + claimSearchParam.getTyreSpecs() + "%")
-				// 门店名称模糊查询(核心需求)
-				.like(StringUtils.isNotBlank(claimSearchParam.getStoreName()), PcBladeClaim::getStoreName, "%" + claimSearchParam.getStoreName() + "%")
-				// 新增字段查询:模糊/精准适配
-				.like(StringUtils.isNotBlank(claimSearchParam.getVehicleNumber()), PcBladeClaim::getVehicleNumber, "%" + claimSearchParam.getVehicleNumber() + "%") // 车牌号模糊
-				.eq(claimSearchParam.getTireQuantity() != null, PcBladeClaim::getTireQuantity, claimSearchParam.getTireQuantity()) // 轮胎数量精准
-				.like(StringUtils.isNotBlank(claimSearchParam.getBrandItem()), PcBladeClaim::getBrandItem, "%" + claimSearchParam.getBrandItem() + "%") // 花纹模糊
-				.like(StringUtils.isNotBlank(claimSearchParam.getBrandName()), PcBladeClaim::getBrandName, "%" + claimSearchParam.getBrandName() + "%") // 品牌模糊
+				.eq(tireQuantity != null, PcBladeClaim::getTireQuantity, tireQuantity)
+				.eq(StringUtils.isNotBlank(storeContact), PcBladeClaim::getStoreContact, storeContact)
+				.eq(StringUtils.isNotBlank(storePhone), PcBladeClaim::getStorePhone, storePhone)
+
+				// -------------------- 模糊查询字段 --------------------
+				.like(StringUtils.isNotBlank(consumerName), PcBladeClaim::getConsumerName, "%" + consumerName + "%")
+				.like(StringUtils.isNotBlank(consumerPhone), PcBladeClaim::getConsumerPhone, "%" + consumerPhone + "%")
+				.like(StringUtils.isNotBlank(tyreNo), PcBladeClaim::getTyreNo, "%" + tyreNo + "%")
+				.like(StringUtils.isNotBlank(tyreSpecs), PcBladeClaim::getTyreSpecs, "%" + tyreSpecs + "%")
+				.like(StringUtils.isNotBlank(vehicleNumber), PcBladeClaim::getVehicleNumber, "%" + vehicleNumber + "%")
+				.like(StringUtils.isNotBlank(brandItem), PcBladeClaim::getBrandItem, "%" + brandItem + "%")
+				.like(StringUtils.isNotBlank(brandName), PcBladeClaim::getBrandName, "%" + brandName + "%")
+				.like(StringUtils.isNotBlank(storeName), PcBladeClaim::getStoreName, "%" + storeName + "%")
+				.like(StringUtils.isNotBlank(storeAddress), PcBladeClaim::getStoreAddress, "%" + storeAddress + "%")
+
+				// -------------------- 范围查询字段 --------------------
 				// 日期范围
 				.ge(purchaseDateStart != null, PcBladeClaim::getPurchaseDate, purchaseDateStart)
 				.le(purchaseDateEnd != null, PcBladeClaim::getPurchaseDate, purchaseDateEnd)
-				// 数值范围
+				// 金额范围
 				.ge(claimAmountMin != null, PcBladeClaim::getClaimAmount, claimAmountMin)
 				.le(claimAmountMax != null, PcBladeClaim::getClaimAmount, claimAmountMax)
+				// 里程范围
 				.ge(runMileageMin != null, PcBladeClaim::getRunMileage, runMileageMin)
 				.le(runMileageMax != null, PcBladeClaim::getRunMileage, runMileageMax)
-				// 数据权限
+
+				// -------------------- 数据权限 + 排序 --------------------
 				.eq(PcBladeClaim::getCreateUser, userId)
-				// 排序
 				.orderByDesc(PcBladeClaim::getSubmitTime)
 				.orderByDesc(PcBladeClaim::getCreateTime);
 
@@ -219,6 +449,8 @@ public class ClaimSearchController {
 		}
 	}
 
+
+
 	// 工具类:空值判断
 	private static class StringUtils {
 		public static boolean isNotBlank(String str) {

+ 13 - 0
blade-service/blade-factory/src/main/java/org/springblade/factory/domain/ClaimSearchParam.java

@@ -1,5 +1,6 @@
 package org.springblade.factory.domain;
 
+import com.baomidou.mybatisplus.annotation.TableField;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
@@ -80,4 +81,16 @@ public class ClaimSearchParam {
 	// 门店名称(原有字段,补充到参数类)
 	@ApiModelProperty(value = "门店名称(模糊)")
 	private String storeName;
+
+	/** 门店地址 */
+	@ApiModelProperty(value = "门店地址(模糊)")
+	private String storeAddress;
+
+	/** 门店联系人 */
+	@ApiModelProperty(value = "门店联系人")
+	private String storeContact;
+
+	/** 门店联系电话 */
+	@ApiModelProperty(value = "门店联系电话")
+	private String storePhone;
 }