20 changed files with 450 additions and 36 deletions
@ -0,0 +1,79 @@ |
|||||
|
package com.epmet.commons.tools.distributedlock; |
||||
|
|
||||
|
import com.epmet.commons.tools.exception.RenException; |
||||
|
import com.epmet.commons.tools.redis.RedisKeys; |
||||
|
import org.apache.commons.lang3.StringUtils; |
||||
|
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; |
||||
|
import java.util.concurrent.atomic.AtomicInteger; |
||||
|
|
||||
|
/** |
||||
|
* @Author zxc |
||||
|
* @DateTime 2020/10/28 9:05 上午 |
||||
|
*/ |
||||
|
@Component |
||||
|
public class DistributedLock { |
||||
|
|
||||
|
@Autowired |
||||
|
private RedissonClient redissonClient; |
||||
|
|
||||
|
/** |
||||
|
* @Description 抢锁🔒 每个锁持有十分钟 |
||||
|
* @Param name |
||||
|
* @author zxc |
||||
|
* @date 2020/10/28 2:52 下午 |
||||
|
*/ |
||||
|
public RLock getLock(String name){ |
||||
|
RLock lock = null; |
||||
|
if (StringUtils.isNotBlank(name)) { |
||||
|
lock = redissonClient.getLock(name); |
||||
|
// 持续时间为 -1 时,直到其明确释放锁才会释放【宕机就完蛋了】,
|
||||
|
lock.lock(10,TimeUnit.MINUTES); |
||||
|
} |
||||
|
return lock; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @Description |
||||
|
* @Param name 锁名 |
||||
|
* @Param leaseTime 持锁时间 单位:min |
||||
|
* @Param waitTime 获取锁最长等待时间 单位:min |
||||
|
* @author zxc |
||||
|
* @date 2020/10/29 9:04 上午 |
||||
|
*/ |
||||
|
public RLock getLock(String name,Long leaseTime,Long waitTime){ |
||||
|
RLock lock = null; |
||||
|
if (StringUtils.isNotBlank(name) && leaseTime > 0 && waitTime > 0 ){ |
||||
|
lock = redissonClient.getLock(name); |
||||
|
Boolean lockStatus; |
||||
|
try { |
||||
|
lockStatus = lock.tryLock(waitTime,leaseTime,TimeUnit.MINUTES); |
||||
|
if (!lockStatus){ |
||||
|
throw new RenException("获取锁🔒失败了......"); |
||||
|
} |
||||
|
} catch (InterruptedException e) { |
||||
|
e.printStackTrace(); |
||||
|
} |
||||
|
} |
||||
|
return lock; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @Description 释放锁🔒 |
||||
|
* @Param rLock |
||||
|
* @author zxc |
||||
|
* @date 2020/10/28 2:52 下午 |
||||
|
*/ |
||||
|
public void unLock(RLock rLock){ |
||||
|
if (null != rLock){ |
||||
|
if (rLock.isHeldByCurrentThread()){ |
||||
|
rLock.unlock(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,12 @@ |
|||||
|
package com.epmet.commons.tools.distributedlock; |
||||
|
|
||||
|
/** |
||||
|
* @Author zxc |
||||
|
* @DateTime 2020/10/28 9:23 上午 |
||||
|
*/ |
||||
|
public interface LockConstants { |
||||
|
|
||||
|
String TEST_LOCK_NAME = "testLock"; |
||||
|
|
||||
|
String STATS_LOCK_NAME = "stats"; |
||||
|
} |
@ -0,0 +1,24 @@ |
|||||
|
package com.epmet.evaluationindex.screen.dto.form; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
|
||||
|
import javax.validation.constraints.NotBlank; |
||||
|
import java.io.Serializable; |
||||
|
|
||||
|
/** |
||||
|
* @Author zxc |
||||
|
* @DateTime 2020/10/27 11:08 上午 |
||||
|
*/ |
||||
|
@Data |
||||
|
public class BranchCountFormDTO implements Serializable { |
||||
|
|
||||
|
private static final long serialVersionUID = -4869326660700557193L; |
||||
|
|
||||
|
public interface BranchCount{} |
||||
|
|
||||
|
/** |
||||
|
* 机关ID |
||||
|
*/ |
||||
|
@NotBlank(message = "机关ID不能为空",groups = {BranchCount.class}) |
||||
|
private String agencyId; |
||||
|
} |
@ -0,0 +1,36 @@ |
|||||
|
package com.epmet.evaluationindex.screen.dto.result; |
||||
|
|
||||
|
import com.fasterxml.jackson.annotation.JsonIgnore; |
||||
|
import lombok.Data; |
||||
|
|
||||
|
import java.io.Serializable; |
||||
|
import java.util.ArrayList; |
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* @Author zxc |
||||
|
* @DateTime 2020/10/27 11:03 上午 |
||||
|
*/ |
||||
|
@Data |
||||
|
public class BranchCountResultDTO implements Serializable { |
||||
|
|
||||
|
private static final long serialVersionUID = -5915969126291502360L; |
||||
|
|
||||
|
private String agencyId; |
||||
|
|
||||
|
/** |
||||
|
* 机关名称 |
||||
|
*/ |
||||
|
private String name; |
||||
|
|
||||
|
@JsonIgnore |
||||
|
private String level; |
||||
|
|
||||
|
private List<SubBranchCountResultDTO> partyDistribution; |
||||
|
|
||||
|
public BranchCountResultDTO() { |
||||
|
this.agencyId = ""; |
||||
|
this.name = ""; |
||||
|
this.partyDistribution = new ArrayList<>(); |
||||
|
} |
||||
|
} |
@ -0,0 +1,52 @@ |
|||||
|
package com.epmet.evaluationindex.screen.dto.result; |
||||
|
|
||||
|
import com.fasterxml.jackson.annotation.JsonIgnore; |
||||
|
import lombok.Data; |
||||
|
|
||||
|
import java.io.Serializable; |
||||
|
|
||||
|
/** |
||||
|
* @Author zxc |
||||
|
* @DateTime 2020/10/27 5:22 下午 |
||||
|
*/ |
||||
|
@Data |
||||
|
public class SubBranchCountResultDTO implements Serializable { |
||||
|
|
||||
|
private static final long serialVersionUID = -4174988002147169566L; |
||||
|
|
||||
|
private String subId; |
||||
|
|
||||
|
/** |
||||
|
* 机关名称 |
||||
|
*/ |
||||
|
private String name; |
||||
|
|
||||
|
/** |
||||
|
* 中心点位 |
||||
|
*/ |
||||
|
private String centerMark; |
||||
|
|
||||
|
/** |
||||
|
* 社区下的党支部数 |
||||
|
*/ |
||||
|
private Integer totalNum; |
||||
|
|
||||
|
/** |
||||
|
* 坐标区域 |
||||
|
*/ |
||||
|
private String areaMarks; |
||||
|
|
||||
|
@JsonIgnore |
||||
|
private String allParentIds; |
||||
|
@JsonIgnore |
||||
|
private String subAgencyId; |
||||
|
|
||||
|
public SubBranchCountResultDTO() { |
||||
|
this.subId = ""; |
||||
|
this.name = ""; |
||||
|
this.centerMark = ""; |
||||
|
this.totalNum = 0; |
||||
|
this.areaMarks = ""; |
||||
|
this.subAgencyId = ""; |
||||
|
} |
||||
|
} |
@ -0,0 +1,21 @@ |
|||||
|
package com.epmet.stats.test.zxc; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
|
||||
|
/** |
||||
|
* @Author zxc |
||||
|
* @DateTime 2020/10/28 3:15 下午 |
||||
|
*/ |
||||
|
@Data |
||||
|
public class ZxcDTO { |
||||
|
|
||||
|
private String a; |
||||
|
private String b; |
||||
|
private String c; |
||||
|
private String d; |
||||
|
private String e; |
||||
|
private Integer f; |
||||
|
private Integer g; |
||||
|
private Integer h; |
||||
|
|
||||
|
} |
Loading…
Reference in new issue