23 changed files with 320 additions and 188 deletions
@ -0,0 +1,40 @@ |
|||||
|
package com.bnyer.common.redis.configure; |
||||
|
|
||||
|
import org.redisson.Redisson; |
||||
|
import org.redisson.api.RedissonClient; |
||||
|
import org.redisson.config.Config; |
||||
|
import org.springframework.beans.factory.annotation.Value; |
||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; |
||||
|
import org.springframework.boot.context.properties.ConfigurationProperties; |
||||
|
import org.springframework.cloud.context.config.annotation.RefreshScope; |
||||
|
import org.springframework.context.annotation.Bean; |
||||
|
import org.springframework.context.annotation.Configuration; |
||||
|
|
||||
|
/** |
||||
|
* redisson配置 |
||||
|
* @author chengkun |
||||
|
* @date 2022/7/1 11:12 |
||||
|
*/ |
||||
|
@ConfigurationProperties(prefix = "spring.redis") |
||||
|
@Configuration |
||||
|
@RefreshScope |
||||
|
public class RedissonConfig { |
||||
|
|
||||
|
@Value("${spring.redis.host}") |
||||
|
private String host; |
||||
|
|
||||
|
@Value("${spring.redis.port}") |
||||
|
private String port; |
||||
|
|
||||
|
@Value("${spring.redis.password}") |
||||
|
private String password; |
||||
|
|
||||
|
@Bean(destroyMethod = "shutdown") |
||||
|
@ConditionalOnMissingBean(RedissonClient.class) |
||||
|
public RedissonClient redissonClient() |
||||
|
{ |
||||
|
Config config = new Config(); |
||||
|
config.useSingleServer().setAddress("redis://" + host + ":" + port).setPassword(password); |
||||
|
return Redisson.create(config); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,114 @@ |
|||||
|
package com.bnyer.common.redis.service; |
||||
|
|
||||
|
import org.redisson.api.RLock; |
||||
|
import org.redisson.api.RedissonClient; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
|
||||
|
import java.util.concurrent.TimeUnit; |
||||
|
|
||||
|
/** |
||||
|
* redisson锁工具类 |
||||
|
* @author chengkun |
||||
|
* @date 2022/7/1 11:10 |
||||
|
*/ |
||||
|
@Component |
||||
|
public class RedissonService { |
||||
|
|
||||
|
@Autowired |
||||
|
private RedissonClient redissonClient; |
||||
|
|
||||
|
/** |
||||
|
* 获取锁 |
||||
|
* |
||||
|
* @param lockKey 锁实例key |
||||
|
* @return 锁信息 |
||||
|
*/ |
||||
|
public RLock getRLock(String lockKey) |
||||
|
{ |
||||
|
return redissonClient.getLock(lockKey); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 加锁 |
||||
|
* |
||||
|
* @param lockKey 锁实例key |
||||
|
* @return 锁信息 |
||||
|
*/ |
||||
|
public RLock lock(String lockKey) |
||||
|
{ |
||||
|
RLock lock = getRLock(lockKey); |
||||
|
lock.lock(); |
||||
|
return lock; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 加锁 |
||||
|
* |
||||
|
* @param lockKey 锁实例key |
||||
|
* @param leaseTime 上锁后自动释放锁时间 |
||||
|
* @return true=成功;false=失败 |
||||
|
*/ |
||||
|
public Boolean tryLock(String lockKey, long leaseTime) |
||||
|
{ |
||||
|
return tryLock(lockKey, 0, leaseTime, TimeUnit.SECONDS); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 加锁 |
||||
|
* |
||||
|
* @param lockKey 锁实例key |
||||
|
* @param leaseTime 上锁后自动释放锁时间 |
||||
|
* @param unit 时间颗粒度 |
||||
|
* @return true=加锁成功;false=加锁失败 |
||||
|
*/ |
||||
|
public Boolean tryLock(String lockKey, long leaseTime, TimeUnit unit) |
||||
|
{ |
||||
|
return tryLock(lockKey, 0, leaseTime, unit); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 加锁 |
||||
|
* |
||||
|
* @param lockKey 锁实例key |
||||
|
* @param waitTime 最多等待时间 |
||||
|
* @param leaseTime 上锁后自动释放锁时间 |
||||
|
* @param unit 时间颗粒度 |
||||
|
* @return true=加锁成功;false=加锁失败 |
||||
|
*/ |
||||
|
public Boolean tryLock(String lockKey, long waitTime, long leaseTime, TimeUnit unit) |
||||
|
{ |
||||
|
RLock rLock = getRLock(lockKey); |
||||
|
boolean tryLock = false; |
||||
|
try |
||||
|
{ |
||||
|
tryLock = rLock.tryLock(waitTime, leaseTime, unit); |
||||
|
} |
||||
|
catch (InterruptedException e) |
||||
|
{ |
||||
|
return false; |
||||
|
} |
||||
|
return tryLock; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 释放锁 |
||||
|
* |
||||
|
* @param lockKey 锁实例key |
||||
|
*/ |
||||
|
public void unlock(String lockKey) |
||||
|
{ |
||||
|
RLock lock = getRLock(lockKey); |
||||
|
lock.unlock(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 释放锁 |
||||
|
* |
||||
|
* @param lock 锁信息 |
||||
|
*/ |
||||
|
public void unlock(RLock lock) |
||||
|
{ |
||||
|
lock.unlock(); |
||||
|
} |
||||
|
} |
||||
@ -1,33 +0,0 @@ |
|||||
package com.bnyer.img.dto; |
|
||||
|
|
||||
import io.swagger.annotations.ApiModel; |
|
||||
import io.swagger.annotations.ApiModelProperty; |
|
||||
import lombok.Getter; |
|
||||
import lombok.Setter; |
|
||||
|
|
||||
import java.io.Serializable; |
|
||||
|
|
||||
|
|
||||
@Getter |
|
||||
@Setter |
|
||||
@ApiModel("批量更新邀请者收益接收类") |
|
||||
public class BatchUpdateInviteDto implements Serializable { |
|
||||
|
|
||||
@ApiModelProperty(value="艺术家id") |
|
||||
private Long creatorId; |
|
||||
|
|
||||
@ApiModelProperty(value="图片id") |
|
||||
private Long imgId; |
|
||||
|
|
||||
@ApiModelProperty(value="应用类型(0->bnyer壁纸)") |
|
||||
private String appType; |
|
||||
|
|
||||
@ApiModelProperty(value="结算平台(0->抖音;1->快手;2->微信;3->uniapp)") |
|
||||
private String platform; |
|
||||
|
|
||||
@ApiModelProperty(value="收益类型(0->广告浏览;1->邀请;2->会员)") |
|
||||
private String type; |
|
||||
|
|
||||
@ApiModelProperty(value="创建时间") |
|
||||
private String date; |
|
||||
} |
|
||||
Loading…
Reference in new issue