浏览代码

轮胎保提交判断修改

纪新园 2 周之前
父节点
当前提交
be2054e813

+ 20 - 1
blade-service/gubersail-shop-app/src/main/java/com/gubersail/shop/app/insurance/service/impl/ShopAppTireInsuranceRegisterServiceImpl.java

@@ -183,7 +183,26 @@ public class ShopAppTireInsuranceRegisterServiceImpl extends ServiceImpl<ShopApp
 		// 1. 创建轮胎保险注册实体并复制属性
 		ShopAppTireInsuranceRegister tireInsuranceRegister = new ShopAppTireInsuranceRegister();
 		BeanUtil.copyProperties(appTireInsuranceRegister, tireInsuranceRegister);
-
+		LocalDateTime currentDate = LocalDateTime.now();
+		Date date = Date.from(currentDate.plusYears(1).atZone(ZoneId.systemDefault()).toInstant());
+		BeanUtil.copyProperties(appTireInsuranceRegister, tireInsuranceRegister);
+		SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
+		LambdaQueryWrapper<ShopAppTireInsuranceRegister> lambdaQueryWrapper = new LambdaQueryWrapper<ShopAppTireInsuranceRegister>()
+			.eq(ShopAppTireInsuranceRegister::getIsDeleted, 0)
+			.eq(ShopAppTireInsuranceRegister::getVehicleNumber, tireInsuranceRegister.getVehicleNumber())
+			.eq(ShopAppTireInsuranceRegister::getConsumerPhone, tireInsuranceRegister.getConsumerPhone())
+			.apply("DATE_FORMAT(insurance_time, '%Y') = " + sdf.format(date));
+		if (ObjectUtils.isNotNull(tireInsuranceRegister.getId())) {
+			lambdaQueryWrapper.ne(ShopAppTireInsuranceRegister::getId, tireInsuranceRegister.getId());
+		}
+		List<ShopAppTireInsuranceRegister> shopAppTireInsuranceRegisterList = baseMapper.selectList(lambdaQueryWrapper);
+		if (!shopAppTireInsuranceRegisterList.isEmpty()) {
+			Integer tireQuantity = shopAppTireInsuranceRegisterList.stream().map(ShopAppTireInsuranceRegister::getTireQuantity)
+				.mapToInt(Integer::intValue).sum();
+			if (tireQuantity + tireInsuranceRegister.getTireQuantity() > 8) {
+				throw new RuntimeException("本自然年注册轮胎数量大于8,请修改数量!");
+			}
+		}
 		// 2. 设置更新信息
 		// 设置更新人ID
 		tireInsuranceRegister.setUpdateUser(AuthUtil.getUserId());