Commit eb102d78 authored by fangxinjiang's avatar fangxinjiang

分布式锁

parent a57b9a73
...@@ -19,6 +19,6 @@ public class ResultConstants { ...@@ -19,6 +19,6 @@ public class ResultConstants {
public static final String REQUEST_LOCK_FAIL = "获取锁失败"; public static final String REQUEST_LOCK_FAIL = "获取锁失败";
public static final String DATA_IMPORT_PARSING_RESULT = "数据导入解析!数据行数:"; public static final String DATA_IMPORT_PARSING_RESULT = "数据导入解析!数据行数:";
public static final String NO_SELECT_DATA = "请选择数据"; public static final String NO_SELECT_DATA = "请选择数据";
public static final String NO_GETLOCK_DATA = "获取锁失败,10秒后重试!"; public static final String NO_GETLOCK_DATA = "当前用户操作处理中,请稍后重试!";
public static final String NO_ID = "操作失败,id不能为空!"; public static final String NO_ID = "操作失败,id不能为空!";
} }
...@@ -328,7 +328,13 @@ public class TDispatchInfoController { ...@@ -328,7 +328,13 @@ public class TDispatchInfoController {
throw new RuntimeException(ResultConstants.NO_GETLOCK_DATA+CommonConstants.DOWN_LINE_STRING+e.getMessage()); throw new RuntimeException(ResultConstants.NO_GETLOCK_DATA+CommonConstants.DOWN_LINE_STRING+e.getMessage());
} }
try { try {
if (Common.isNotNull(requestId)) {
Thread.sleep(1000000);
//主动释放锁
return tDispatchInfoService.importDiy(file.getInputStream(),orderId); return tDispatchInfoService.importDiy(file.getInputStream(),orderId);
} else {
return R.failed(ResultConstants.NO_GETLOCK_DATA);
}
}finally { }finally {
//主动释放锁 //主动释放锁
RedisDistributedLock.unlock(key, requestId); RedisDistributedLock.unlock(key, requestId);
...@@ -410,7 +416,12 @@ public class TDispatchInfoController { ...@@ -410,7 +416,12 @@ public class TDispatchInfoController {
throw new RuntimeException(ResultConstants.NO_GETLOCK_DATA+CommonConstants.DOWN_LINE_STRING+e.getMessage()); throw new RuntimeException(ResultConstants.NO_GETLOCK_DATA+CommonConstants.DOWN_LINE_STRING+e.getMessage());
} }
try { try {
if (Common.isNotNull(requestId)) {
//主动释放锁
return tDispatchInfoService.importReduceDiy(file.getInputStream(),orderId); return tDispatchInfoService.importReduceDiy(file.getInputStream(),orderId);
} else {
return R.failed(ResultConstants.NO_GETLOCK_DATA);
}
}finally { }finally {
//主动释放锁 //主动释放锁
RedisDistributedLock.unlock(key, requestId); RedisDistributedLock.unlock(key, requestId);
......
...@@ -168,7 +168,11 @@ public class TPaymentInfoController { ...@@ -168,7 +168,11 @@ public class TPaymentInfoController {
throw new RuntimeException(ResultConstants.NO_GETLOCK_DATA+CommonConstants.DOWN_LINE_STRING+e.getMessage()); throw new RuntimeException(ResultConstants.NO_GETLOCK_DATA+CommonConstants.DOWN_LINE_STRING+e.getMessage());
} }
try { try {
if (Common.isNotNull(requestId)) {
return tPaymentInfoService.importSocialDiy(file.getInputStream()); return tPaymentInfoService.importSocialDiy(file.getInputStream());
} else {
return R.failed(ResultConstants.NO_GETLOCK_DATA);
}
}finally { }finally {
//主动释放锁 //主动释放锁
RedisDistributedLock.unlock(key, requestId); RedisDistributedLock.unlock(key, requestId);
...@@ -200,7 +204,11 @@ public class TPaymentInfoController { ...@@ -200,7 +204,11 @@ public class TPaymentInfoController {
throw new RuntimeException(ResultConstants.NO_GETLOCK_DATA+CommonConstants.DOWN_LINE_STRING+e.getMessage()); throw new RuntimeException(ResultConstants.NO_GETLOCK_DATA+CommonConstants.DOWN_LINE_STRING+e.getMessage());
} }
try { try {
if (Common.isNotNull(requestId)) {
return tPaymentInfoService.importSocialHeFeiDiy(file.getInputStream(), random, type); return tPaymentInfoService.importSocialHeFeiDiy(file.getInputStream(), random, type);
} else {
return R.failed(ResultConstants.NO_GETLOCK_DATA);
}
}finally { }finally {
//主动释放锁 //主动释放锁
RedisDistributedLock.unlock(key, requestId); RedisDistributedLock.unlock(key, requestId);
...@@ -232,7 +240,11 @@ public class TPaymentInfoController { ...@@ -232,7 +240,11 @@ public class TPaymentInfoController {
throw new RuntimeException(ResultConstants.NO_GETLOCK_DATA+CommonConstants.DOWN_LINE_STRING+e.getMessage()); throw new RuntimeException(ResultConstants.NO_GETLOCK_DATA+CommonConstants.DOWN_LINE_STRING+e.getMessage());
} }
try { try {
if (Common.isNotNull(requestId)) {
return tPaymentInfoService.batchImportPaymentFundInfo(file.getInputStream()); return tPaymentInfoService.batchImportPaymentFundInfo(file.getInputStream());
} else {
return R.failed(ResultConstants.NO_GETLOCK_DATA);
}
}finally { }finally {
//主动释放锁 //主动释放锁
RedisDistributedLock.unlock(key, requestId); RedisDistributedLock.unlock(key, requestId);
......
...@@ -250,6 +250,7 @@ public class TPreDispatchInfoController { ...@@ -250,6 +250,7 @@ public class TPreDispatchInfoController {
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(ResultConstants.NO_GETLOCK_DATA+CommonConstants.DOWN_LINE_STRING+e.getMessage()); throw new RuntimeException(ResultConstants.NO_GETLOCK_DATA+CommonConstants.DOWN_LINE_STRING+e.getMessage());
} }
if (Common.isNotNull(requestId)) {
ExcelUtil<TPreDispatchInfo> util1 = null; ExcelUtil<TPreDispatchInfo> util1 = null;
try { try {
jsonString = URLDecoder.decode(jsonString, CommonConstants.UTF8).replace("=", ""); jsonString = URLDecoder.decode(jsonString, CommonConstants.UTF8).replace("=", "");
...@@ -279,6 +280,9 @@ public class TPreDispatchInfoController { ...@@ -279,6 +280,9 @@ public class TPreDispatchInfoController {
//主动释放锁 //主动释放锁
RedisDistributedLock.unlock(key, requestId); RedisDistributedLock.unlock(key, requestId);
} }
} else {
return R.failed(ResultConstants.NO_GETLOCK_DATA);
}
} }
/** /**
......
...@@ -38,7 +38,9 @@ import com.yifu.cloud.plus.v1.yifu.archives.vo.TSettleDomainSelectVo; ...@@ -38,7 +38,9 @@ import com.yifu.cloud.plus.v1.yifu.archives.vo.TSettleDomainSelectVo;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.CacheConstants; import com.yifu.cloud.plus.v1.yifu.common.core.constant.CacheConstants;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.CommonConstants; import com.yifu.cloud.plus.v1.yifu.common.core.constant.CommonConstants;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.ExcelAttributeConstants; import com.yifu.cloud.plus.v1.yifu.common.core.constant.ExcelAttributeConstants;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.ResultConstants;
import com.yifu.cloud.plus.v1.yifu.common.core.exception.ErrorCodes; import com.yifu.cloud.plus.v1.yifu.common.core.exception.ErrorCodes;
import com.yifu.cloud.plus.v1.yifu.common.core.redis.RedisDistributedLock;
import com.yifu.cloud.plus.v1.yifu.common.core.util.*; import com.yifu.cloud.plus.v1.yifu.common.core.util.*;
import com.yifu.cloud.plus.v1.yifu.common.core.vo.ErrorDetailVO; import com.yifu.cloud.plus.v1.yifu.common.core.vo.ErrorDetailVO;
import com.yifu.cloud.plus.v1.yifu.common.core.vo.YifuUser; import com.yifu.cloud.plus.v1.yifu.common.core.vo.YifuUser;
...@@ -270,7 +272,7 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa ...@@ -270,7 +272,7 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa
@Override @Override
public R<Boolean> removeInFoById(String id) { public R<Boolean> removeInFoById(String id) {
YifuUser user = SecurityUtils.getUser(); YifuUser user = SecurityUtils.getUser();
String key = user.getId() + CommonConstants.DOWN_LINE_STRING + CacheConstants.PAYMENT_SOCIAL_PUSH; String key = CacheConstants.PAYMENT_SOCIAL_PUSH + CommonConstants.DOWN_LINE_STRING +user.getId() ;
if (Common.isNotNull(redisUtil.get(key))) { if (Common.isNotNull(redisUtil.get(key))) {
return R.failed("用户正在推送实缴数据中禁止删除!"); return R.failed("用户正在推送实缴数据中禁止删除!");
} }
...@@ -298,7 +300,7 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa ...@@ -298,7 +300,7 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa
return R.failed(CommonConstants.NO_DATA_TO_HANDLE); return R.failed(CommonConstants.NO_DATA_TO_HANDLE);
} }
String key = user.getId() + CommonConstants.DOWN_LINE_STRING + CacheConstants.PAYMENT_SOCIAL_PUSH; String key = CacheConstants.PAYMENT_SOCIAL_PUSH + CommonConstants.DOWN_LINE_STRING +user.getId() ;
if (Common.isNotNull(redisUtil.get(key))) { if (Common.isNotNull(redisUtil.get(key))) {
return R.failed("用户正在推送实缴数据中禁止删除!"); return R.failed("用户正在推送实缴数据中禁止删除!");
} }
...@@ -340,7 +342,7 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa ...@@ -340,7 +342,7 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa
String socialCreateMonth, String socialPayMonth) { String socialCreateMonth, String socialPayMonth) {
YifuUser user = SecurityUtils.getUser(); YifuUser user = SecurityUtils.getUser();
String key = user.getId() + CommonConstants.DOWN_LINE_STRING + CacheConstants.PAYMENT_SOCIAL_PUSH; String key = CacheConstants.PAYMENT_SOCIAL_PUSH + CommonConstants.DOWN_LINE_STRING +user.getId() ;
if (Common.isNotNull(redisUtil.get(key))) { if (Common.isNotNull(redisUtil.get(key))) {
return R.failed("用户正在推送实缴数据中禁止删除!"); return R.failed("用户正在推送实缴数据中禁止删除!");
} }
...@@ -2814,13 +2816,20 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa ...@@ -2814,13 +2816,20 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa
@Override @Override
public R<Boolean> pushPaymentSocialFundInfo(TPaymentInfoSearchVo searchVo) { public R<Boolean> pushPaymentSocialFundInfo(TPaymentInfoSearchVo searchVo) {
YifuUser user = SecurityUtils.getUser(); YifuUser user = SecurityUtils.getUser();
String key = user.getId() + CommonConstants.DOWN_LINE_STRING + CacheConstants.PAYMENT_SOCIAL_PUSH; String key = CacheConstants.PAYMENT_SOCIAL_PUSH + CommonConstants.DOWN_LINE_STRING +user.getId() ;
if (Common.isNotNull(redisUtil.get(key))) { if (Common.isNotNull(redisUtil.get(key))) {
return R.failed("用户正在推送实缴数据中,禁止重复推送!"); return R.failed("用户正在推送实缴数据中,禁止重复推送!");
} else { } else {
redisUtil.set(key, user.getId(), 1200L); redisUtil.set(key, user.getId(), 1200L);
} }
// 获取redis分布式事务锁
String requestId;
try {
requestId = RedisDistributedLock.getLock(key,"10");
} catch (Exception e) {
throw new RuntimeException(ResultConstants.NO_GETLOCK_DATA+CommonConstants.DOWN_LINE_STRING+e.getMessage());
}
if (Common.isNotNull(requestId)) {
Map<String, TSettleDomainSelectVo> mapSelectVo = this.getSelectVoMap(); Map<String, TSettleDomainSelectVo> mapSelectVo = this.getSelectVoMap();
//手动推送未推送的社保公积金明细数据 //手动推送未推送的社保公积金明细数据
createPaymentSocialInfoReal(user, searchVo, mapSelectVo); createPaymentSocialInfoReal(user, searchVo, mapSelectVo);
...@@ -2838,7 +2847,12 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa ...@@ -2838,7 +2847,12 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa
redisUtil.remove(redisKey); redisUtil.remove(redisKey);
} }
redisUtil.remove(key); redisUtil.remove(key);
//主动释放锁
RedisDistributedLock.unlock(key, requestId);
return R.ok(); return R.ok();
}else {
return R.failed(ResultConstants.NO_GETLOCK_DATA);
}
} }
@Override @Override
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment