| | |
| | | import com.ruoyi.common.log.annotation.Log; |
| | | import com.ruoyi.common.log.enums.BusinessType; |
| | | import com.ruoyi.common.log.enums.OperatorType; |
| | | import com.ruoyi.common.redis.service.RedisService; |
| | | import com.ruoyi.common.security.utils.SecurityUtils; |
| | | import com.ruoyi.other.api.vo.CouponListVOVO; |
| | | import com.ruoyi.account.api.vo.ExchangeRecordVO; |
| | |
| | | import com.ruoyi.other.api.feignClient.OtherClient; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.redisson.api.RLock; |
| | | import org.redisson.api.RedissonClient; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.util.StringUtils; |
| | | import org.springframework.web.bind.annotation.*; |
| | |
| | | import javax.annotation.Resource; |
| | | import java.time.LocalDateTime; |
| | | import java.util.*; |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | private TAppUserTagService appUserTagService; |
| | | @Autowired |
| | | private TAppUserService appUserService; |
| | | |
| | | @Autowired |
| | | private RedissonClient redissonClient; |
| | | |
| | | |
| | | /** |
| | |
| | | @ApiOperation(value = "添加车辆", tags = {"小程序-扫一扫"}) |
| | | @PostMapping(value = "/scan/addCar") |
| | | public AjaxResult addCar(@RequestBody TAppUserCar dto) { |
| | | dto.setAppUserId(tokenService.getLoginUserApplet().getUserId()); |
| | | TAppUserCar one = appUserCarService.getOne(new LambdaQueryWrapper<TAppUserCar>().eq(TAppUserCar::getLicensePlate, dto.getLicensePlate()) |
| | | .eq(TAppUserCar::getDelFlag, 0)); |
| | | if(null != one){ |
| | | return AjaxResult.error("车辆已存在"); |
| | | Long userId = tokenService.getLoginUserApplet().getUserId(); |
| | | RLock lock = redissonClient.getLock("CREATE_CAR:" + userId); |
| | | try { |
| | | boolean tryLock = lock.tryLock(10, 10, TimeUnit.SECONDS); |
| | | if(tryLock){ |
| | | dto.setAppUserId(userId); |
| | | TAppUserCar one = appUserCarService.getOne(new LambdaQueryWrapper<TAppUserCar>() |
| | | .eq(TAppUserCar::getLicensePlate, dto.getLicensePlate()) |
| | | .eq(TAppUserCar::getAppUserId, dto.getAppUserId()) |
| | | .eq(TAppUserCar::getDelFlag, 0)); |
| | | if(null != one){ |
| | | return AjaxResult.error("车辆已存在"); |
| | | } |
| | | appUserCarService.save(dto); |
| | | } |
| | | } catch (InterruptedException e) { |
| | | throw new RuntimeException(e); |
| | | }finally { |
| | | lock.unlock(); |
| | | } |
| | | appUserCarService.save(dto); |
| | | return AjaxResult.success(); |
| | | } |
| | | /** |