From 8965c567bd070cb80d900a27aba931c86d11f7b7 Mon Sep 17 00:00:00 2001
From: puzhibing <393733352@qq.com>
Date: 星期二, 26 五月 2026 22:05:16 +0800
Subject: [PATCH] 修改车辆添加重复判断逻辑
---
ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/TAppCouponController.java | 2
ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/TAppUserController.java | 164 ++++++++++++++++++++++++++++--------------------------
2 files changed, 87 insertions(+), 79 deletions(-)
diff --git a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/TAppCouponController.java b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/TAppCouponController.java
index 5cc2785..c401464 100644
--- a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/TAppCouponController.java
+++ b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/TAppCouponController.java
@@ -116,7 +116,7 @@
Long userId = tokenService.getLoginUserApplet().getUserId();
RLock lock = redissonClient.getLock("CREATE_CAR:" + userId);
try {
- boolean tryLock = lock.tryLock(10, 10, TimeUnit.SECONDS);
+ boolean tryLock = lock.tryLock(2, 10, TimeUnit.SECONDS);
if(tryLock){
dto.setAppUserId(userId);
TAppUserCar one = appUserCarService.getOne(new LambdaQueryWrapper<TAppUserCar>()
diff --git a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/TAppUserController.java b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/TAppUserController.java
index bcb5e3a..96b4aa9 100644
--- a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/TAppUserController.java
+++ b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/TAppUserController.java
@@ -57,6 +57,8 @@
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.compress.utils.IOUtils;
+import org.redisson.api.RLock;
+import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.validation.annotation.Validated;
@@ -148,6 +150,9 @@
private TInviteUserService inviteUserService;
@Resource
private GiveVipUtil giveVipUtil;
+
+ @Autowired
+ private RedissonClient redissonClient;
/**
* 远程调用 发送邮件
@@ -1270,15 +1275,7 @@
- //积分变化记录用
-// @PostMapping(value = "/user/points/change")
-// public R change(@RequestBody PointChangeDto points) {
-// TAppUser byId = appUserService.getById(points.getUserId());
-// pointDetailUtil.addDetail(byId.getPoints(),byId.getPoints()+points.getPoints(),points.getType(),points.getUserId(),points.getRemark(),"JF");
-// byId.setPoints(byId.getPoints()+points.getPoints());
-// appUserService.updateById(byId);
-// return R.ok();
-// }
+
@PostMapping(value = "/user/points/change/down")
public R changeDown(@RequestBody PointChangeDto points) {
@@ -1294,88 +1291,99 @@
@ApiOperation(value = "添加编辑车辆", tags = {"小程序-个人中心-车辆"})
@PostMapping(value = "/user/car/addOrUpdate")
public R carAdd(@RequestBody TAppUserCar appUserCar) {
+ Long userId = tokenService.getLoginUserApplet().getUserId();
if(null != appUserCar.getId()){
TAppUserCar userCar = appUserCarService.getById(appUserCar.getId());
- Long userId = tokenService.getLoginUserApplet().getUserId();
if(!userCar.getAppUserId().equals(userId)){
return R.fail("权限不足");
}
}
- TAppUserCar one1 = appUserCarService.getOne(new LambdaQueryWrapper<TAppUserCar>().eq(TAppUserCar::getLicensePlate, appUserCar.getLicensePlate())
- .eq(TAppUserCar::getDelFlag, 0));
- if(null != one1){
- return R.fail("车辆已存在");
- }
- LoginUserApplet loginUserApplet = tokenService.getLoginUserApplet();
- Long userId = loginUserApplet.getUserId();
- TAppUser byId = appUserService.getById(userId);
- appUserCar.setAppUserId(userId);
- //判断当前生效的vipDetail
- TAppUserVipDetail one = tAppUserVipDetailService.lambdaQuery().le(TAppUserVipDetail::getStartTime, LocalDateTime.now()).ge(TAppUserVipDetail::getEndTime, LocalDateTime.now()).eq(TAppUserVipDetail::getAppUserId, userId).last("limit 1").one();
- boolean doubleVip = false;
- if (one!=null){
- TVip tVip = JSONObject.parseObject(one.getVipJson(), TVip.class);
- if (tVip.getDoubleIntegration()!=null&&tVip.getDoubleIntegration()==1){
- doubleVip = true;
- }
- }
-
- //如果是第一次添加车辆,增加积分
- Long count = appUserCarService.lambdaQuery().eq(TAppUserCar::getAppUserId, userId).count();
-
-
- if (count==0){
- R<TIntegralRule> set = integralRuleClient.getSet();
- TIntegralRule data = set.getData();
- if(null != data){
- JSONObject jsonObject = JSON.parseObject(data.getAddVehiclesEarnsPoints());
- Integer point = 0;
- //增加车牌50分,必填
- point = point+jsonObject.getInteger("num1");
- if (doubleVip){
- point = point+jsonObject.getInteger("num1");
+ RLock lock = redissonClient.getLock("CREATE_CAR:" + userId);
+ try {
+ boolean tryLock = lock.tryLock(5, 10, TimeUnit.SECONDS);
+ if(tryLock){
+ TAppUserCar one1 = appUserCarService.getOne(new LambdaQueryWrapper<TAppUserCar>()
+ .eq(TAppUserCar::getLicensePlate, appUserCar.getLicensePlate())
+ .eq(TAppUserCar::getAppUserId, userId)
+ .eq(TAppUserCar::getDelFlag, 0));
+ if(null != one1 && null == appUserCar.getId()){
+ return R.fail("车辆已存在");
}
- //增加车型分
- if (StringUtils.isNotEmpty(appUserCar.getVehicleModel())){
- point = point+jsonObject.getInteger("num2");
- if (doubleVip){
- point = point+jsonObject.getInteger("num2");
- }
- }
- //增加车辆用途分
- if (StringUtils.isNotEmpty(appUserCar.getVehicleUse())){
- point = point+jsonObject.getInteger("num3");
- if (doubleVip){
- point = point+jsonObject.getInteger("num3");
- }
- }
- //增加续航分
- if(NumberUtil.isNumber(appUserCar.getEndurance())){
- point = point+jsonObject.getInteger("num4");
- if (doubleVip){
- point = point+jsonObject.getInteger("num4");
+
+ TAppUser byId = appUserService.getById(userId);
+ appUserCar.setAppUserId(userId);
+
+ //判断当前生效的vipDetail
+ TAppUserVipDetail one = tAppUserVipDetailService.lambdaQuery().le(TAppUserVipDetail::getStartTime, LocalDateTime.now()).ge(TAppUserVipDetail::getEndTime, LocalDateTime.now()).eq(TAppUserVipDetail::getAppUserId, userId).last("limit 1").one();
+ boolean doubleVip = false;
+ if (one!=null){
+ TVip tVip = JSONObject.parseObject(one.getVipJson(), TVip.class);
+ if (tVip.getDoubleIntegration()!=null&&tVip.getDoubleIntegration()==1){
+ doubleVip = true;
}
}
- //增加积分记录
- pointDetailUtil.addDetail(byId.getPoints(),byId.getPoints()+point,5,userId,appUserCar.getLicensePlate(),"","");
- byId.setPoints(byId.getPoints()+point);
+ //如果是第一次添加车辆,增加积分
+ Long count = appUserCarService.lambdaQuery().eq(TAppUserCar::getAppUserId, userId).count();
+
+
+ if (count==0){
+ R<TIntegralRule> set = integralRuleClient.getSet();
+ TIntegralRule data = set.getData();
+ if(null != data){
+ JSONObject jsonObject = JSON.parseObject(data.getAddVehiclesEarnsPoints());
+ Integer point = 0;
+ //增加车牌50分,必填
+ point = point+jsonObject.getInteger("num1");
+ if (doubleVip){
+ point = point+jsonObject.getInteger("num1");
+ }
+ //增加车型分
+ if (StringUtils.isNotEmpty(appUserCar.getVehicleModel())){
+ point = point+jsonObject.getInteger("num2");
+ if (doubleVip){
+ point = point+jsonObject.getInteger("num2");
+ }
+ }
+ //增加车辆用途分
+ if (StringUtils.isNotEmpty(appUserCar.getVehicleUse())){
+ point = point+jsonObject.getInteger("num3");
+ if (doubleVip){
+ point = point+jsonObject.getInteger("num3");
+ }
+ }
+ //增加续航分
+ if(NumberUtil.isNumber(appUserCar.getEndurance())){
+ point = point+jsonObject.getInteger("num4");
+ if (doubleVip){
+ point = point+jsonObject.getInteger("num4");
+ }
+ }
+
+ //增加积分记录
+ pointDetailUtil.addDetail(byId.getPoints(),byId.getPoints()+point,5,userId,appUserCar.getLicensePlate(),"","");
+ byId.setPoints(byId.getPoints()+point);
+ }
+ byId.setFirstAdd(1);
+ }
+ CarNumDto carNumDto = CarUtil.carNum(appUserCar.getLicensePlate());
+ if (carNumDto==null){
+ return R.fail("请输入正确的车牌");
+ }
+
+ byId.setCityCode(carNumDto.getAreaCode());
+ byId.setProvinceCode(carNumDto.getAreaCode().substring(0,2)+"0000");
+ appUserService.updateById(byId);
+
+ //
+ appUserCarService.saveOrUpdate(appUserCar);
}
- byId.setFirstAdd(1);
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }finally {
+ lock.unlock();
}
- CarNumDto carNumDto = CarUtil.carNum(appUserCar.getLicensePlate());
- if (carNumDto==null){
- return R.fail("请输入正确的车牌");
- }
-
- byId.setCityCode(carNumDto.getAreaCode());
- byId.setProvinceCode(carNumDto.getAreaCode().substring(0,2)+"0000");
- appUserService.updateById(byId);
-
- //
- appUserCarService.saveOrUpdate(appUserCar);
-
return R.ok();
}
--
Gitblit v1.7.1