设备明细表字段补充

dev2.0
anthonywj 2 years ago
parent fe1f7e92e6
commit 24cd753745

@ -0,0 +1,163 @@
package com.glxp.api.aspect;
import cn.dev33.satoken.SaManager;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import com.glxp.api.annotation.RepeatSubmit;
import com.glxp.api.common.res.BaseResponse;
import com.glxp.api.common.util.ResultVOUtils;
import com.glxp.api.exception.ServiceException;
import com.glxp.api.util.*;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;
import org.springframework.validation.BindingResult;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.time.Duration;
import java.util.Collection;
import java.util.Map;
/**
* (GTIS)
*/
@Slf4j
//@RequiredArgsConstructor
//@Aspect
//@Component
public class RepeatSubmitAspect {
@Resource
RedisUtil redisUtil;
private static final ThreadLocal<String> KEY_CACHE = new ThreadLocal<>();
@Before("@annotation(repeatSubmit)")
public void doBefore(JoinPoint point, RepeatSubmit repeatSubmit) throws Throwable {
// 如果注解不为0 则使用注解数值
long interval = 0;
if (repeatSubmit.interval() > 0) {
interval = repeatSubmit.timeUnit().toMillis(repeatSubmit.interval());
}
log.error("不要重复提交,谢谢--" + interval);
if (interval < 1000) {
log.error("不要重复提交,谢谢");
throw new ServiceException("重复提交间隔时间不能小于'1'秒");
}
HttpServletRequest request = ServletUtils.getRequest();
String nowParams = argsArrayToString(point.getArgs());
// 请求地址作为存放cache的key值
String url = request.getRequestURI();
// 唯一值(没有消息头则使用请求地址)
String submitKey = StringUtils.trimToEmpty(request.getHeader(SaManager.getConfig().getTokenName()));
submitKey = SecureUtil.md5(submitKey + ":" + nowParams);
// 唯一标识指定key + url + 消息头)
String cacheRepeatKey = "REPEAT_SUBMIT_KEY" + url + submitKey;
String key = (String) redisUtil.get(cacheRepeatKey);
if (key == null) {
redisUtil.set(cacheRepeatKey, "", Duration.ofMillis(interval).toMillis());
KEY_CACHE.set(cacheRepeatKey);
} else {
String message = repeatSubmit.message();
// if (StringUtils.startsWith(message, "{") && StringUtils.endsWith(message, "}")) {
// message = MessageUtils.message(StringUtils.substring(message, 1, message.length() - 1));
// }
throw new ServiceException("重复提交", 500);
}
}
/**
*
*
* @param joinPoint
*/
@AfterReturning(pointcut = "@annotation(repeatSubmit)", returning = "jsonResult")
public void doAfterReturning(JoinPoint joinPoint, RepeatSubmit repeatSubmit, Object jsonResult) {
if (jsonResult instanceof BaseResponse) {
try {
BaseResponse<?> r = (BaseResponse<?>) jsonResult;
// 成功则不删除redis数据 保证在有效时间内无法重复提交
if (r.getCode() == 20000) {
return;
}
redisUtil.del(KEY_CACHE.get());
} finally {
KEY_CACHE.remove();
}
}
}
/**
*
*
* @param joinPoint
* @param e
*/
@AfterThrowing(value = "@annotation(repeatSubmit)", throwing = "e")
public void doAfterThrowing(JoinPoint joinPoint, RepeatSubmit repeatSubmit, Exception e) {
if (KEY_CACHE.get() != null) {
redisUtil.del(KEY_CACHE.get());
KEY_CACHE.remove();
}
}
/**
*
*/
private String argsArrayToString(Object[] paramsArray) {
StringBuilder params = new StringBuilder();
if (paramsArray != null && paramsArray.length > 0) {
for (Object o : paramsArray) {
if (ObjectUtil.isNotNull(o) && !isFilterObject(o)) {
try {
params.append(JsonUtils.toJsonString(o)).append(" ");
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
return params.toString().trim();
}
/**
*
*
* @param o
* @return truefalse
*/
@SuppressWarnings("rawtypes")
public boolean isFilterObject(final Object o) {
Class<?> clazz = o.getClass();
if (clazz.isArray()) {
return clazz.getComponentType().isAssignableFrom(MultipartFile.class);
} else if (Collection.class.isAssignableFrom(clazz)) {
Collection collection = (Collection) o;
for (Object value : collection) {
return value instanceof MultipartFile;
}
} else if (Map.class.isAssignableFrom(clazz)) {
Map map = (Map) o;
for (Object value : map.entrySet()) {
Map.Entry entry = (Map.Entry) value;
return entry.getValue() instanceof MultipartFile;
}
}
return o instanceof MultipartFile || o instanceof HttpServletRequest || o instanceof HttpServletResponse
|| o instanceof BindingResult;
}
}

@ -1,5 +1,6 @@
package com.glxp.api.controller;
import com.glxp.api.annotation.RepeatSubmit;
import com.glxp.api.common.res.BaseResponse;
import com.glxp.api.common.util.ResultVOUtils;
import com.glxp.api.req.sync.BasicExportStatusRequest;
@ -25,4 +26,9 @@ public class TestController {
return ResultVOUtils.success("生成成功!" + start + "=====" + end + "\n-------" + (start - end));
}
@RepeatSubmit()
@GetMapping("/test/repeat")
public BaseResponse testRepeat(String message) {
return ResultVOUtils.success("hello");
}
}

@ -116,7 +116,7 @@ public class DeptDeviceDetailEntity {
private String supName;
/**
* 12345
* 123456使7
*/
@TableField(value = "`status`")
private Integer status;
@ -165,4 +165,23 @@ public class DeptDeviceDetailEntity {
@TableField(value = "remark")
private String remark;
}
/**
* 使
*/
@TableField(value = "curUser")
private String curUser;
/**
*
*/
@TableField(value = "location")
private String location;
/**
*
*/
@TableField(value = "detailLocation")
private String detailLocation;
}

@ -238,3 +238,8 @@ CREATE TABLE IF NOT EXISTS `device_asset_usage` (
`updateTime` datetime(0) NULL DEFAULT NULL COMMENT '更新时间',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;
CALL Pro_Temp_ColumnWork('dept_device_detail', 'curUser', 'varchar(255)', 1);
CALL Pro_Temp_ColumnWork('dept_device_detail', 'location', 'varchar(255)', 1);
CALL Pro_Temp_ColumnWork('dept_device_detail', 'detailLocation', 'varchar(255)', 1);

Loading…
Cancel
Save