Commit c30637b5 authored by fangxinjiang's avatar fangxinjiang

分布式锁调试

parent f8f9ef51
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
package com.yifu.cloud.plus.v1.yifu.archives.controller; package com.yifu.cloud.plus.v1.yifu.archives.controller;
import com.baomidou.lock.annotation.Lock4j;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yifu.cloud.plus.v1.yifu.archives.entity.TEmpFamily; import com.yifu.cloud.plus.v1.yifu.archives.entity.TEmpFamily;
...@@ -26,6 +27,7 @@ import com.yifu.cloud.plus.v1.yifu.common.core.constant.CommonConstants; ...@@ -26,6 +27,7 @@ import com.yifu.cloud.plus.v1.yifu.common.core.constant.CommonConstants;
import com.yifu.cloud.plus.v1.yifu.common.core.util.Common; import com.yifu.cloud.plus.v1.yifu.common.core.util.Common;
import com.yifu.cloud.plus.v1.yifu.common.core.util.ErrorMessage; import com.yifu.cloud.plus.v1.yifu.common.core.util.ErrorMessage;
import com.yifu.cloud.plus.v1.yifu.common.core.util.R; import com.yifu.cloud.plus.v1.yifu.common.core.util.R;
import com.yifu.cloud.plus.v1.yifu.common.core.util.RedisUtil;
import com.yifu.cloud.plus.v1.yifu.common.dapr.config.DaprCheckProperties; import com.yifu.cloud.plus.v1.yifu.common.dapr.config.DaprCheckProperties;
import com.yifu.cloud.plus.v1.yifu.common.dapr.util.ArchivesDaprUtil; import com.yifu.cloud.plus.v1.yifu.common.dapr.util.ArchivesDaprUtil;
import com.yifu.cloud.plus.v1.yifu.common.log.annotation.SysLog; import com.yifu.cloud.plus.v1.yifu.common.log.annotation.SysLog;
...@@ -60,6 +62,7 @@ public class TEmpFamilyController { ...@@ -60,6 +62,7 @@ public class TEmpFamilyController {
private final TEmpFamilyService tEmpFamilyService; private final TEmpFamilyService tEmpFamilyService;
@Autowired @Autowired
private final ArchivesDaprUtil archivesDaprUtil; private final ArchivesDaprUtil archivesDaprUtil;
int i = 0;
/** /**
* 分页查询 * 分页查询
* @param page 分页对象 * @param page 分页对象
...@@ -173,4 +176,21 @@ public class TEmpFamilyController { ...@@ -173,4 +176,21 @@ public class TEmpFamilyController {
public R<List<ErrorMessage>> importListAdd(@RequestBody MultipartFile file){ public R<List<ErrorMessage>> importListAdd(@RequestBody MultipartFile file){
return tEmpFamilyService.importEmpFamilyDiy(file.getInputStream()); return tEmpFamilyService.importEmpFamilyDiy(file.getInputStream());
} }
@Autowired
private RedisUtil redisUtil;
@Lock4j(keys = {"#tEmpFamily.mId"}, expire = 60000, acquireTimeout = 1000)
@Operation(description = "lockTest")
@GetMapping("/page" )
public R<String> lockTest(Page page, FamilySearchVO tEmpFamily) {
Object obj = redisUtil.get("lockTest");
int lockValue;
if (Common.isNotNull(obj)){
lockValue = (int)obj ;
}else {
lockValue = 1;
}
lockValue = lockValue +1;
redisUtil.set("lockTest",lockValue);
return R.ok(CommonConstants.SUCCESS_MSG_PREFIX,String.valueOf(lockValue));
}
} }
...@@ -110,5 +110,10 @@ ...@@ -110,5 +110,10 @@
<version>4.5.30</version> <version>4.5.30</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>lock4j-redis-template-spring-boot-starter</artifactId>
<version>2.2.4</version>
</dependency>
</dependencies> </dependencies>
</project> </project>
package com.yifu.cloud.plus.v1.yifu.common.core.redis.lock4j;
import com.baomidou.lock.LockFailureStrategy;
import com.baomidou.lock.exception.LockFailureException;
import org.springframework.stereotype.Component;
import java.lang.reflect.Method;
/**
* @Author fxj
* @Date 2023/2/7
* @Description lock4j 分布式锁 异常 自定义异常策略
* @Version 1.0
*/
@Component
public class MyLockFailureStrategy implements LockFailureStrategy {
@Override
public void onLockFailure(String key, Method method, Object[] arguments) {
throw new LockFailureException("业务执行中,请稍后重试");
}
}
...@@ -6,4 +6,5 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ ...@@ -6,4 +6,5 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.yifu.cloud.plus.v1.yifu.common.core.util.SpringContextHolder,\ com.yifu.cloud.plus.v1.yifu.common.core.util.SpringContextHolder,\
com.yifu.cloud.plus.v1.yifu.common.core.config.WebMvcConfiguration,\ com.yifu.cloud.plus.v1.yifu.common.core.config.WebMvcConfiguration,\
com.yifu.cloud.plus.v1.yifu.common.core.util.OSSUtil,\ com.yifu.cloud.plus.v1.yifu.common.core.util.OSSUtil,\
com.yifu.cloud.plus.v1.yifu.common.core.util.RedisUtil com.yifu.cloud.plus.v1.yifu.common.core.util.RedisUtil,\
com.yifu.cloud.plus.v1.yifu.common.core.redis.lock4j.MyLockFailureStrategy
package com.yifu.cloud.plus.v1.yifu.common.security.exception; package com.yifu.cloud.plus.v1.yifu.common.security.exception;
import com.baomidou.lock.exception.LockFailureException;
import com.fasterxml.jackson.databind.exc.InvalidFormatException; import com.fasterxml.jackson.databind.exc.InvalidFormatException;
import com.yifu.cloud.plus.v1.yifu.common.core.exception.ValidateCodeException; import com.yifu.cloud.plus.v1.yifu.common.core.exception.ValidateCodeException;
import com.yifu.cloud.plus.v1.yifu.common.core.util.Common; import com.yifu.cloud.plus.v1.yifu.common.core.util.Common;
...@@ -152,4 +153,17 @@ public class GlobalExceptionHandler { ...@@ -152,4 +153,17 @@ public class GlobalExceptionHandler {
log.error("全局异常信息 触发用户:获取失败 ex={}", exception.getMessage(), exception); log.error("全局异常信息 触发用户:获取失败 ex={}", exception.getMessage(), exception);
} }
} }
/**
* 获取锁异常 lockException
*
* @param e
* @return R
*/
@ExceptionHandler({LockFailureException.class})
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public R lockFailExceptionHandler(Exception e) {
errorLog(e);
R result = R.failed("业务处理锁异常:"+ e.getMessage());
return result;
}
} }
...@@ -292,7 +292,7 @@ public class TSocialFundInfo extends BaseEntity { ...@@ -292,7 +292,7 @@ public class TSocialFundInfo extends BaseEntity {
@ExcelProperty("公积金派增状态" ) @ExcelProperty("公积金派增状态" )
private String fundAddStatus; private String fundAddStatus;
/** /**
* 社保派状态:0待审核、1待办理、2办理成功、3办理失败 4 审核不通过 5 办理中 6部分办理失败 202230231 派减分项办理逻辑 fxj * 社保派状态:0待审核、1待办理、2办理成功、3办理失败 4 审核不通过 5 办理中 6部分办理失败 202230231 派减分项办理逻辑 fxj
*/ */
@ExcelAttribute(name = "社保派减状态", maxLength = 1) @ExcelAttribute(name = "社保派减状态", maxLength = 1)
@Schema(description = "社保派减状态:0待审核、1待办理、2办理成功、3办理失败 4 审核不通过 5 办理中 6 部分办理失败 " ) @Schema(description = "社保派减状态:0待审核、1待办理、2办理成功、3办理失败 4 审核不通过 5 办理中 6 部分办理失败 " )
......
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
<!-- Level: FATAL 0 ERROR 3 WARN 4 INFO 6 DEBUG 7 --> <!-- Level: FATAL 0 ERROR 3 WARN 4 INFO 6 DEBUG 7 -->
<root level="INFO"> <root level="debug">
<appender-ref ref="console"/> <appender-ref ref="console"/>
<appender-ref ref="debug"/> <appender-ref ref="debug"/>
<appender-ref ref="error"/> <appender-ref ref="error"/>
......
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