提交 3e61ad32 authored 作者: 许俊's avatar 许俊

优化

上级 0e5727e6
......@@ -24,6 +24,7 @@ import org.jeecg.common.util.IPUtils;
import org.jeecg.common.util.SpringContextUtils;
import org.jeecg.common.util.oConvertUtils;
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
......@@ -46,6 +47,7 @@ import java.util.Map;
@Aspect
@Component
@Data
@Order(1)
public class AutoLogAspect {
@Resource
......@@ -69,7 +71,7 @@ public class AutoLogAspect {
//保存日志
saveSysLog(point, time, result);
ThreadLocalConfig.remove();
return result;
}
......
package org.jeecg.modules.aspect;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.PropertyFilter;
import lombok.Data;
import org.apache.shiro.SecurityUtils;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.jeecg.common.api.dto.LogDTO;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.constant.enums.ModuleType;
import org.jeecg.common.exception.*;
import org.jeecg.common.util.*;
import org.jeecg.modules.base.service.BaseCommonService;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.iost.ims.entity.ImsPurchaseOrder;
import org.jeecg.modules.iost.ims.entity.Vo.ImsRequestVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Method;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
/**
* 防止短时间内并发提交或者重复提交
*
* @Author scott
* @email jeecgos@163.com
* @Date 2018年1月14日
*/
@Aspect
@Component
@Data
@Order(2)
public class NotCommitRedisLockAspect {
@Resource
private BaseCommonService baseCommonService;
@Pointcut("@annotation(org.jeecg.modules.aspect.annotation.NotCommitRedisLock)")
public void logPointCut() {
}
@Autowired
RedisLock redisLock;
@Around("logPointCut()")
public Object around(ProceedingJoinPoint point) throws Throwable {
Object result=null;
Object[] args = point.getArgs();
for (Object arg : args) {
if(arg instanceof ImsRequestVo)
{
ImsRequestVo request = (ImsRequestVo) arg;
System.out.println("test-----"+request);
String token = redisLock.tryLock(request.getDocType()+request.getData().get(0).get("QUEUE_ID").toString(), 1000 * 60*2);
if(token==null)
{
return Result.fail("操作失败","请勿提交相同数据!",request.getDocType());
}
Map<String,String> map=ThreadLocalConfig.get();
if(map==null)
{
map=new HashMap<>();
}
map.put("key",request.getDocType()+request.getData().get(0).get("QUEUE_ID").toString());
map.put("token",token);
ThreadLocalConfig.set(map);
try{
//执行方法
result = point.proceed();
}finally {
redisLock.unlock(request.getDocType()+request.getData().get(0).get("QUEUE_ID").toString(), token);
}
}
}
return result;
}
}
package org.jeecg.modules.aspect.annotation;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.constant.enums.ModuleType;
import java.lang.annotation.*;
/**
* 防止短时间内并发提交或者重复提交
*
* @Author
* @email
* @Date 2021年12月21日
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface NotCommitRedisLock {
}
......@@ -9,6 +9,7 @@ import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.util.RedisLock;
import org.jeecg.modules.aspect.annotation.NotCommitRedisLock;
import org.jeecg.modules.base.service.BaseCommonService;
import org.jeecg.modules.iost.ims.Dao.CategoryDao;
import org.jeecg.common.exception.ConnectConstant.KingDeeConstant;
......@@ -30,7 +31,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;
import java.text.ParseException;
import java.util.*;
......@@ -126,22 +126,9 @@ public class WebApi {
@AutoLog(value = "第三方通用接口-updateThirdData")
@ApiOperation(value = "第三方通用接口-updateThirdData", notes = "第三方通用接口-updateThirdData")
@PostMapping(value = "/updateThirdData")
@NotCommitRedisLock
public Result<?> updateData(@RequestBody ImsRequestVo request) throws ParseException {
String token = redisLock.tryLock(request.getDocType()+request.getData().get(0).get("QUEUE_ID").toString(), 1000 * 60*2);
if(token==null)
{
return Result.fail("操作失败","请勿提交相同数据!",request.getDocType());
}
Map<String,String> map=ThreadLocalConfig.get();
if(map==null)
{
map=new HashMap<>();
}
map.put("key",request.getDocType()+request.getData().get(0).get("QUEUE_ID").toString());
map.put("token",token);
ThreadLocalConfig.set(map);
String result = new String();
try {
//根据doctype调用不同的业务service
if (request.getDocType().equals("BS0001"))//采购订单收料
{
......@@ -188,11 +175,8 @@ public class WebApi {
result = result.replace("\t", "");
result = result.replace("\r", "");
result = result.replace(" ", "");
ThreadLocalConfig.remove();
return Result.OK(result, request.getDocType());
}finally {
redisLock.unlock(request.getDocType()+request.getData().get(0).get("QUEUE_ID").toString(), token);
}
}
/*List<Map<String,Object>>转换Map<String,Object>*/
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论