Commit e05e40b7 authored by huyuchen's avatar huyuchen

Merge remote-tracking branch 'origin/MVP1.5.2' into MVP1.5.2

parents fe81ce9b 075fea40
......@@ -25,6 +25,7 @@ import com.alibaba.excel.read.listener.ReadListener;
import com.alibaba.excel.read.metadata.holder.ReadRowHolder;
import com.alibaba.excel.util.ListUtils;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.baomidou.lock.annotation.Lock4j;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
......@@ -321,7 +322,8 @@ public class TEmployeeContractInfoServiceImpl extends ServiceImpl<TEmployeeContr
* @return: java.lang.String
**/
@Override
public synchronized String getCode(boolean isNew) {
@Lock4j(expire = 60000, acquireTimeout = 1000)
public String getCode(boolean isNew) {
String nowDay = DateUtil.getThisDay();
int nowNums;
String empCode = null;
......
......@@ -25,6 +25,7 @@ import com.alibaba.excel.read.listener.ReadListener;
import com.alibaba.excel.read.metadata.holder.ReadRowHolder;
import com.alibaba.excel.util.ListUtils;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.baomidou.lock.annotation.Lock4j;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
......@@ -1438,7 +1439,8 @@ public class TEmployeeInfoServiceImpl extends ServiceImpl<TEmployeeInfoMapper, T
* @Date: 2022/6/22 17:52
* @return: java.lang.String
**/
private synchronized String getCode() {
@Lock4j(expire = 60000, acquireTimeout = 1000)
private String getCode() {
String nowDay = DateUtil.getThisDay();
Cache cache = cacheManager.getCache(CacheConstants.EVERYDAY_EMP_CODE);
Object nowNumObj = cache.get(nowDay);
......
......@@ -19,6 +19,6 @@ public class ResultConstants {
public static final String REQUEST_LOCK_FAIL = "获取锁失败";
public static final String DATA_IMPORT_PARSING_RESULT = "数据导入解析!数据行数:";
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不能为空!";
}
local key = KEYS[1];
local threadId = ARGV[1];
local releaseTime = ARGV[2];
if(redis.call('exists', key) == 0) then
redis.call('hset', key, threadId, '1');
redis.call('expire', key, releaseTime);
return 1;
end;
if(redis.call('hexists', key, threadId) == 1) then
redis.call('hincrby', key, threadId, '1');
redis.call('expire', key, releaseTime);
return 1;
end;
return 0;
local key = KEYS[1]; -- 第1个参数,锁的key
local threadId = ARGV[1]; -- 第2个参数,线程唯一标识
local releaseTime = ARGV[2]; -- 第3个参数,锁的自动释放时间
if(redis.call('exists', key) == 0) then -- 判断锁是否已存在
redis.call('hset', key, threadId, '1'); -- 不存在, 则获取锁
redis.call('expire', key, releaseTime); -- 设置有效期
return 1; -- 返回结果
end;
if(redis.call('hexists', key, threadId) == 1) then -- 锁已经存在,判断threadId是否是自己
redis.call('hincrby', key, threadId, '1'); -- 如果是自己,则重入次数+1
redis.call('expire', key, releaseTime); -- 设置有效期
return 1; -- 返回结果
end;
return 0; -- 代码走到这里,说明获取锁的不是自己,获取锁失败
local key = KEYS[1]; -- 第1个参数,锁的key
local threadId = ARGV[1]; -- 第2个参数,线程唯一标识
if (redis.call('HEXISTS', key, threadId) == 0) then -- 判断当前锁是否还是被自己持有
return nil; -- 如果已经不是自己,则直接返回
end;
local count = redis.call('HINCRBY', key, threadId, -1); -- 是自己的锁,则重入次数-1
if (count == 0) then -- 判断是否重入次数是否已经为0
redis.call('DEL', key); -- 等于0说明可以释放锁,直接删除
return nil;
end;
local key = KEYS[1];
local threadId = ARGV[1];
if (redis.call('HEXISTS', key, threadId) == 0) then
return nil;
end;
local count = redis.call('HINCRBY', key, threadId, -1);
if (count == 0) then
redis.call('DEL', key);
return nil;
end;
......@@ -325,10 +325,15 @@ public class TDispatchInfoController {
try {
requestId = RedisDistributedLock.getLock(key,"10");
} catch (Exception e) {
throw new RuntimeException(ResultConstants.NO_GETLOCK_DATA);
throw new RuntimeException(ResultConstants.NO_GETLOCK_DATA+CommonConstants.DOWN_LINE_STRING+e.getMessage());
}
try {
return tDispatchInfoService.importDiy(file.getInputStream(),orderId);
if (Common.isNotNull(requestId)) {
//主动释放锁
return tDispatchInfoService.importDiy(file.getInputStream(),orderId);
} else {
return R.failed(ResultConstants.NO_GETLOCK_DATA);
}
}finally {
//主动释放锁
RedisDistributedLock.unlock(key, requestId);
......@@ -407,10 +412,15 @@ public class TDispatchInfoController {
try {
requestId = RedisDistributedLock.getLock(key,"10");
} catch (Exception e) {
throw new RuntimeException(ResultConstants.NO_GETLOCK_DATA);
throw new RuntimeException(ResultConstants.NO_GETLOCK_DATA+CommonConstants.DOWN_LINE_STRING+e.getMessage());
}
try {
return tDispatchInfoService.importReduceDiy(file.getInputStream(),orderId);
if (Common.isNotNull(requestId)) {
//主动释放锁
return tDispatchInfoService.importReduceDiy(file.getInputStream(),orderId);
} else {
return R.failed(ResultConstants.NO_GETLOCK_DATA);
}
}finally {
//主动释放锁
RedisDistributedLock.unlock(key, requestId);
......
......@@ -165,10 +165,14 @@ public class TPaymentInfoController {
try {
requestId = RedisDistributedLock.getLock(key,"10");
} catch (Exception e) {
throw new RuntimeException(ResultConstants.NO_GETLOCK_DATA);
throw new RuntimeException(ResultConstants.NO_GETLOCK_DATA+CommonConstants.DOWN_LINE_STRING+e.getMessage());
}
try {
return tPaymentInfoService.importSocialDiy(file.getInputStream());
if (Common.isNotNull(requestId)) {
return tPaymentInfoService.importSocialDiy(file.getInputStream());
} else {
return R.failed(ResultConstants.NO_GETLOCK_DATA);
}
}finally {
//主动释放锁
RedisDistributedLock.unlock(key, requestId);
......@@ -197,10 +201,14 @@ public class TPaymentInfoController {
try {
requestId = RedisDistributedLock.getLock(key,"10");
} catch (Exception e) {
throw new RuntimeException(ResultConstants.NO_GETLOCK_DATA);
throw new RuntimeException(ResultConstants.NO_GETLOCK_DATA+CommonConstants.DOWN_LINE_STRING+e.getMessage());
}
try {
return tPaymentInfoService.importSocialHeFeiDiy(file.getInputStream(), random, type);
if (Common.isNotNull(requestId)) {
return tPaymentInfoService.importSocialHeFeiDiy(file.getInputStream(), random, type);
} else {
return R.failed(ResultConstants.NO_GETLOCK_DATA);
}
}finally {
//主动释放锁
RedisDistributedLock.unlock(key, requestId);
......@@ -229,10 +237,14 @@ public class TPaymentInfoController {
try {
requestId = RedisDistributedLock.getLock(key,"10");
} catch (Exception e) {
throw new RuntimeException(ResultConstants.NO_GETLOCK_DATA);
throw new RuntimeException(ResultConstants.NO_GETLOCK_DATA+CommonConstants.DOWN_LINE_STRING+e.getMessage());
}
try {
return tPaymentInfoService.batchImportPaymentFundInfo(file.getInputStream());
if (Common.isNotNull(requestId)) {
return tPaymentInfoService.batchImportPaymentFundInfo(file.getInputStream());
} else {
return R.failed(ResultConstants.NO_GETLOCK_DATA);
}
}finally {
//主动释放锁
RedisDistributedLock.unlock(key, requestId);
......
......@@ -248,36 +248,40 @@ public class TPreDispatchInfoController {
try {
requestId = RedisDistributedLock.getLock(key,"10");
} catch (Exception e) {
throw new RuntimeException(ResultConstants.NO_GETLOCK_DATA);
throw new RuntimeException(ResultConstants.NO_GETLOCK_DATA+CommonConstants.DOWN_LINE_STRING+e.getMessage());
}
ExcelUtil<TPreDispatchInfo> util1 = null;
try {
jsonString = URLDecoder.decode(jsonString, CommonConstants.UTF8).replace("=", "");
util1 = new ExcelUtil<>(TPreDispatchInfo.class);
util1.getJsonStringToList(jsonString, null);
List<TPreDispatchInfo> listInfo = util1.getEntityList();
//用于返回错误信息
List<ErrorMessage> errorInfo = new ArrayList<>();
if (null != util1.getErrorInfo() && !util1.getErrorInfo().isEmpty()) {
for (ErrorMessage errorMessage: util1.getErrorInfo()) {
errorInfo.add(errorMessage);
if (Common.isNotNull(requestId)) {
ExcelUtil<TPreDispatchInfo> util1 = null;
try {
jsonString = URLDecoder.decode(jsonString, CommonConstants.UTF8).replace("=", "");
util1 = new ExcelUtil<>(TPreDispatchInfo.class);
util1.getJsonStringToList(jsonString, null);
List<TPreDispatchInfo> listInfo = util1.getEntityList();
//用于返回错误信息
List<ErrorMessage> errorInfo = new ArrayList<>();
if (null != util1.getErrorInfo() && !util1.getErrorInfo().isEmpty()) {
for (ErrorMessage errorMessage: util1.getErrorInfo()) {
errorInfo.add(errorMessage);
}
}
if (null != listInfo && !listInfo.isEmpty()) {
errorInfo = tPreDispatchInfoService.batchSavePreDisPatchAdd(listInfo, user,socialHouse,fundHouse,
departId,errorInfo);
} else {
errorInfo.add(new ErrorMessage(null, CommonConstants.DATA_CAN_NOT_EMPTY));
}
List<ErrorMessage> newErrorList = errorInfo.stream().sorted(Comparator.comparing(ErrorMessage::getLineNum))
.collect(Collectors.toList());
return R.ok(newErrorList);
} catch (Exception e) {
e.printStackTrace();
return R.failed(PreDispatchConstants.DATA_IMPORT_ANALYSIS_ERROR);
}finally {
//主动释放锁
RedisDistributedLock.unlock(key, requestId);
}
if (null != listInfo && !listInfo.isEmpty()) {
errorInfo = tPreDispatchInfoService.batchSavePreDisPatchAdd(listInfo, user,socialHouse,fundHouse,
departId,errorInfo);
} else {
errorInfo.add(new ErrorMessage(null, CommonConstants.DATA_CAN_NOT_EMPTY));
}
List<ErrorMessage> newErrorList = errorInfo.stream().sorted(Comparator.comparing(ErrorMessage::getLineNum))
.collect(Collectors.toList());
return R.ok(newErrorList);
} catch (Exception e) {
e.printStackTrace();
return R.failed(PreDispatchConstants.DATA_IMPORT_ANALYSIS_ERROR);
}finally {
//主动释放锁
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;
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.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.redis.RedisDistributedLock;
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.YifuUser;
......@@ -270,7 +272,7 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa
@Override
public R<Boolean> removeInFoById(String id) {
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))) {
return R.failed("用户正在推送实缴数据中禁止删除!");
}
......@@ -298,7 +300,7 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa
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))) {
return R.failed("用户正在推送实缴数据中禁止删除!");
}
......@@ -340,7 +342,7 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa
String socialCreateMonth, String socialPayMonth) {
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))) {
return R.failed("用户正在推送实缴数据中禁止删除!");
}
......@@ -2814,31 +2816,43 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa
@Override
public R<Boolean> pushPaymentSocialFundInfo(TPaymentInfoSearchVo searchVo) {
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))) {
return R.failed("用户正在推送实缴数据中,禁止重复推送!");
} else {
redisUtil.set(key, user.getId(), 1200L);
}
Map<String, TSettleDomainSelectVo> mapSelectVo = this.getSelectVoMap();
//手动推送未推送的社保公积金明细数据
createPaymentSocialInfoReal(user, searchVo, mapSelectVo);
createPaymentFundInfoReal(user, searchVo, mapSelectVo);
//推送社保公积金收入数据
String redisKey = String.valueOf(UUID.randomUUID()).replaceAll("-", "") + "_incomePush";
createPaymentInfoIncomeReal(user, searchVo, mapSelectVo, redisKey);
createPaymentFundIncomeReal(user, searchVo, mapSelectVo, redisKey);
//推送失败的数据重新推送
if (Common.isNotNull(redisUtil.get(redisKey))) {
List<TIncome> list = (List<TIncome>) redisUtil.get(redisKey);
for (TIncome income : list) {
doJointSocialTask.asynchronousEkpIncomePaymentT(income);
// 获取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();
//手动推送未推送的社保公积金明细数据
createPaymentSocialInfoReal(user, searchVo, mapSelectVo);
createPaymentFundInfoReal(user, searchVo, mapSelectVo);
//推送社保公积金收入数据
String redisKey = String.valueOf(UUID.randomUUID()).replaceAll("-", "") + "_incomePush";
createPaymentInfoIncomeReal(user, searchVo, mapSelectVo, redisKey);
createPaymentFundIncomeReal(user, searchVo, mapSelectVo, redisKey);
//推送失败的数据重新推送
if (Common.isNotNull(redisUtil.get(redisKey))) {
List<TIncome> list = (List<TIncome>) redisUtil.get(redisKey);
for (TIncome income : list) {
doJointSocialTask.asynchronousEkpIncomePaymentT(income);
}
redisUtil.remove(redisKey);
}
redisUtil.remove(redisKey);
redisUtil.remove(key);
//主动释放锁
RedisDistributedLock.unlock(key, requestId);
return R.ok();
}else {
return R.failed(ResultConstants.NO_GETLOCK_DATA);
}
redisUtil.remove(key);
return R.ok();
}
@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