正在显示
17 个修改的文件
包含
541 行增加
和
368 行删除
| @@ -17,4 +17,14 @@ | @@ -17,4 +17,14 @@ | ||
| 17 | <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | 17 | <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |
| 18 | </properties> | 18 | </properties> |
| 19 | 19 | ||
| 20 | + <dependencies> | ||
| 21 | + <dependency> | ||
| 22 | + <groupId>com.zhonglai.luhui</groupId> | ||
| 23 | + <artifactId>ruoyi-common-security</artifactId> | ||
| 24 | + </dependency> | ||
| 25 | + <dependency> | ||
| 26 | + <groupId>org.springframework</groupId> | ||
| 27 | + <artifactId>spring-webmvc</artifactId> | ||
| 28 | + </dependency> | ||
| 29 | + </dependencies> | ||
| 20 | </project> | 30 | </project> |
| 1 | -//package com.zhonglai.luhui.log.aspectj; | ||
| 2 | -// | ||
| 3 | -//import com.alibaba.fastjson.JSON; | ||
| 4 | -//import com.ruoyi.common.annotation.Log; | ||
| 5 | -//import com.ruoyi.common.core.domain.BaseLoginUser; | ||
| 6 | -//import com.ruoyi.common.enums.BusinessStatus; | ||
| 7 | -//import com.ruoyi.common.enums.HttpMethod; | ||
| 8 | -//import com.ruoyi.common.utils.SecurityUtils; | ||
| 9 | -//import com.ruoyi.common.utils.ServletUtils; | ||
| 10 | -//import com.ruoyi.common.utils.StringUtils; | ||
| 11 | -//import com.ruoyi.common.utils.ip.IpUtils; | ||
| 12 | -//import com.ruoyi.system.domain.sys.SysOperLog; | ||
| 13 | -//import org.aspectj.lang.JoinPoint; | ||
| 14 | -//import org.aspectj.lang.annotation.AfterReturning; | ||
| 15 | -//import org.aspectj.lang.annotation.AfterThrowing; | ||
| 16 | -//import org.aspectj.lang.annotation.Aspect; | ||
| 17 | -//import org.slf4j.Logger; | ||
| 18 | -//import org.slf4j.LoggerFactory; | ||
| 19 | -//import org.springframework.stereotype.Component; | ||
| 20 | -//import org.springframework.validation.BindingResult; | ||
| 21 | -//import org.springframework.web.multipart.MultipartFile; | ||
| 22 | -//import org.springframework.web.servlet.HandlerMapping; | ||
| 23 | -// | ||
| 24 | -//import javax.servlet.http.HttpServletRequest; | ||
| 25 | -//import javax.servlet.http.HttpServletResponse; | ||
| 26 | -//import java.util.Collection; | ||
| 27 | -//import java.util.Map; | ||
| 28 | -// | ||
| 29 | -///** | ||
| 30 | -// * 操作日志记录处理 | ||
| 31 | -// * | ||
| 32 | -// * @author ruoyi | ||
| 33 | -// */ | ||
| 34 | -//@Aspect | ||
| 35 | -//@Component | ||
| 36 | -//public class LogAspect | ||
| 37 | -//{ | ||
| 38 | -// private static final Logger log = LoggerFactory.getLogger(LogAspect.class); | ||
| 39 | -// | ||
| 40 | -// /** | ||
| 41 | -// * 处理完请求后执行 | ||
| 42 | -// * | ||
| 43 | -// * @param joinPoint 切点 | ||
| 44 | -// */ | ||
| 45 | -// @AfterReturning(pointcut = "@annotation(controllerLog)", returning = "jsonResult") | ||
| 46 | -// public void doAfterReturning(JoinPoint joinPoint, Log controllerLog, Object jsonResult) | ||
| 47 | -// { | ||
| 48 | -// handleLog(joinPoint, controllerLog, null, jsonResult); | ||
| 49 | -// } | ||
| 50 | -// | ||
| 51 | -// /** | ||
| 52 | -// * 拦截异常操作 | ||
| 53 | -// * | ||
| 54 | -// * @param joinPoint 切点 | ||
| 55 | -// * @param e 异常 | ||
| 56 | -// */ | ||
| 57 | -// @AfterThrowing(value = "@annotation(controllerLog)", throwing = "e") | ||
| 58 | -// public void doAfterThrowing(JoinPoint joinPoint, Log controllerLog, Exception e) | ||
| 59 | -// { | ||
| 60 | -// handleLog(joinPoint, controllerLog, e, null); | ||
| 61 | -// } | ||
| 62 | -// | ||
| 63 | -// protected void handleLog(final JoinPoint joinPoint, Log controllerLog, final Exception e, Object jsonResult) | ||
| 64 | -// { | ||
| 65 | -// try | ||
| 66 | -// { | ||
| 67 | -// // 获取当前的用户 | ||
| 68 | -// BaseLoginUser loginUser = SecurityUtils.getLoginUser(); | ||
| 69 | -// | ||
| 70 | -// // *========数据库日志=========*// | ||
| 71 | -// SysOperLog operLog = new SysOperLog(); | ||
| 72 | -// operLog.setStatus(BusinessStatus.SUCCESS.ordinal()); | ||
| 73 | -// // 请求的地址 | ||
| 74 | -// String ip = IpUtils.getIpAddr(ServletUtils.getRequest()); | ||
| 75 | -// operLog.setOperIp(ip); | ||
| 76 | -// operLog.setOperUrl(ServletUtils.getRequest().getRequestURI()); | ||
| 77 | -// if (loginUser != null) | ||
| 78 | -// { | ||
| 79 | -// operLog.setOperName(loginUser.getUsername()); | ||
| 80 | -// } | ||
| 81 | -// | ||
| 82 | -// if (e != null) | ||
| 83 | -// { | ||
| 84 | -// operLog.setStatus(BusinessStatus.FAIL.ordinal()); | ||
| 85 | -// operLog.setErrorMsg(StringUtils.substring(e.getMessage(), 0, 2000)); | ||
| 86 | -// } | ||
| 87 | -// // 设置方法名称 | ||
| 88 | -// String className = joinPoint.getTarget().getClass().getName(); | ||
| 89 | -// String methodName = joinPoint.getSignature().getName(); | ||
| 90 | -// operLog.setMethod(className + "." + methodName + "()"); | ||
| 91 | -// // 设置请求方式 | ||
| 92 | -// operLog.setRequestMethod(ServletUtils.getRequest().getMethod()); | ||
| 93 | -// // 处理设置注解上的参数 | ||
| 94 | -// getControllerMethodDescription(joinPoint, controllerLog, operLog, jsonResult); | ||
| 95 | -// // 保存数据库 | ||
| 96 | -// AsyncManager.me().execute(AsyncFactory.recordOper(operLog)); | ||
| 97 | -// } | ||
| 98 | -// catch (Exception exp) | ||
| 99 | -// { | ||
| 100 | -// // 记录本地异常日志 | ||
| 101 | -// log.error("==前置通知异常=="); | ||
| 102 | -// log.error("异常信息:{}", exp.getMessage()); | ||
| 103 | -// exp.printStackTrace(); | ||
| 104 | -// } | ||
| 105 | -// } | ||
| 106 | -// | ||
| 107 | -// /** | ||
| 108 | -// * 获取注解中对方法的描述信息 用于Controller层注解 | ||
| 109 | -// * | ||
| 110 | -// * @param log 日志 | ||
| 111 | -// * @param operLog 操作日志 | ||
| 112 | -// * @throws Exception | ||
| 113 | -// */ | ||
| 114 | -// public void getControllerMethodDescription(JoinPoint joinPoint, Log log, SysOperLog operLog, Object jsonResult) throws Exception | ||
| 115 | -// { | ||
| 116 | -// // 设置action动作 | ||
| 117 | -// operLog.setBusinessType(log.businessType().ordinal()); | ||
| 118 | -// // 设置标题 | ||
| 119 | -// operLog.setTitle(log.title()); | ||
| 120 | -// // 设置操作人类别 | ||
| 121 | -// operLog.setOperatorType(log.operatorType().ordinal()); | ||
| 122 | -// // 是否需要保存request,参数和值 | ||
| 123 | -// if (log.isSaveRequestData()) | ||
| 124 | -// { | ||
| 125 | -// // 获取参数的信息,传入到数据库中。 | ||
| 126 | -// setRequestValue(joinPoint, operLog); | ||
| 127 | -// } | ||
| 128 | -// // 是否需要保存response,参数和值 | ||
| 129 | -// if (log.isSaveResponseData() && StringUtils.isNotNull(jsonResult)) | ||
| 130 | -// { | ||
| 131 | -// operLog.setJsonResult(StringUtils.substring(JSON.toJSONString(jsonResult), 0, 2000)); | ||
| 132 | -// } | ||
| 133 | -// } | ||
| 134 | -// | ||
| 135 | -// /** | ||
| 136 | -// * 获取请求的参数,放到log中 | ||
| 137 | -// * | ||
| 138 | -// * @param operLog 操作日志 | ||
| 139 | -// * @throws Exception 异常 | ||
| 140 | -// */ | ||
| 141 | -// private void setRequestValue(JoinPoint joinPoint, SysOperLog operLog) throws Exception | ||
| 142 | -// { | ||
| 143 | -// String requestMethod = operLog.getRequestMethod(); | ||
| 144 | -// if (HttpMethod.PUT.name().equals(requestMethod) || HttpMethod.POST.name().equals(requestMethod)) | ||
| 145 | -// { | ||
| 146 | -// String params = argsArrayToString(joinPoint.getArgs()); | ||
| 147 | -// operLog.setOperParam(StringUtils.substring(params, 0, 2000)); | ||
| 148 | -// } | ||
| 149 | -// else | ||
| 150 | -// { | ||
| 151 | -// Map<?, ?> paramsMap = (Map<?, ?>) ServletUtils.getRequest().getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE); | ||
| 152 | -// operLog.setOperParam(StringUtils.substring(paramsMap.toString(), 0, 2000)); | ||
| 153 | -// } | ||
| 154 | -// } | ||
| 155 | -// | ||
| 156 | -// /** | ||
| 157 | -// * 参数拼装 | ||
| 158 | -// */ | ||
| 159 | -// private String argsArrayToString(Object[] paramsArray) | ||
| 160 | -// { | ||
| 161 | -// String params = ""; | ||
| 162 | -// if (paramsArray != null && paramsArray.length > 0) | ||
| 163 | -// { | ||
| 164 | -// for (Object o : paramsArray) | ||
| 165 | -// { | ||
| 166 | -// if (StringUtils.isNotNull(o) && !isFilterObject(o)) | ||
| 167 | -// { | ||
| 168 | -// try | ||
| 169 | -// { | ||
| 170 | -// Object jsonObj = JSON.toJSON(o); | ||
| 171 | -// params += jsonObj.toString() + " "; | ||
| 172 | -// } | ||
| 173 | -// catch (Exception e) | ||
| 174 | -// { | ||
| 175 | -// } | ||
| 176 | -// } | ||
| 177 | -// } | ||
| 178 | -// } | ||
| 179 | -// return params.trim(); | ||
| 180 | -// } | ||
| 181 | -// | ||
| 182 | -// /** | ||
| 183 | -// * 判断是否需要过滤的对象。 | ||
| 184 | -// * | ||
| 185 | -// * @param o 对象信息。 | ||
| 186 | -// * @return 如果是需要过滤的对象,则返回true;否则返回false。 | ||
| 187 | -// */ | ||
| 188 | -// @SuppressWarnings("rawtypes") | ||
| 189 | -// public boolean isFilterObject(final Object o) | ||
| 190 | -// { | ||
| 191 | -// Class<?> clazz = o.getClass(); | ||
| 192 | -// if (clazz.isArray()) | ||
| 193 | -// { | ||
| 194 | -// return clazz.getComponentType().isAssignableFrom(MultipartFile.class); | ||
| 195 | -// } | ||
| 196 | -// else if (Collection.class.isAssignableFrom(clazz)) | ||
| 197 | -// { | ||
| 198 | -// Collection collection = (Collection) o; | ||
| 199 | -// for (Object value : collection) | ||
| 200 | -// { | ||
| 201 | -// return value instanceof MultipartFile; | ||
| 202 | -// } | ||
| 203 | -// } | ||
| 204 | -// else if (Map.class.isAssignableFrom(clazz)) | ||
| 205 | -// { | ||
| 206 | -// Map map = (Map) o; | ||
| 207 | -// for (Object value : map.entrySet()) | ||
| 208 | -// { | ||
| 209 | -// Map.Entry entry = (Map.Entry) value; | ||
| 210 | -// return entry.getValue() instanceof MultipartFile; | ||
| 211 | -// } | ||
| 212 | -// } | ||
| 213 | -// return o instanceof MultipartFile || o instanceof HttpServletRequest || o instanceof HttpServletResponse | ||
| 214 | -// || o instanceof BindingResult; | ||
| 215 | -// } | ||
| 216 | -//} | 1 | +package com.zhonglai.luhui.log.aspectj; |
| 2 | + | ||
| 3 | +import com.alibaba.fastjson.JSON; | ||
| 4 | +import com.ruoyi.common.annotation.Log; | ||
| 5 | +import com.ruoyi.common.enums.BusinessStatus; | ||
| 6 | +import com.ruoyi.common.enums.HttpMethod; | ||
| 7 | +import com.ruoyi.common.utils.ServletUtils; | ||
| 8 | +import com.ruoyi.common.utils.StringUtils; | ||
| 9 | +import com.ruoyi.common.utils.ip.IpUtils; | ||
| 10 | +import com.ruoyi.system.domain.sys.SysOperLog; | ||
| 11 | +import com.zhonglai.luhui.security.dto.BaseLoginUser; | ||
| 12 | +import com.zhonglai.luhui.security.utils.SecurityUtils; | ||
| 13 | +import com.zhonglai.luhui.sys.manager.AsyncManager; | ||
| 14 | +import com.zhonglai.luhui.sys.manager.factory.AsyncFactory; | ||
| 15 | +import org.aspectj.lang.JoinPoint; | ||
| 16 | +import org.aspectj.lang.annotation.AfterReturning; | ||
| 17 | +import org.aspectj.lang.annotation.AfterThrowing; | ||
| 18 | +import org.aspectj.lang.annotation.Aspect; | ||
| 19 | +import org.slf4j.Logger; | ||
| 20 | +import org.slf4j.LoggerFactory; | ||
| 21 | +import org.springframework.stereotype.Component; | ||
| 22 | +import org.springframework.validation.BindingResult; | ||
| 23 | +import org.springframework.web.multipart.MultipartFile; | ||
| 24 | +import org.springframework.web.servlet.HandlerMapping; | ||
| 25 | + | ||
| 26 | +import javax.servlet.http.HttpServletRequest; | ||
| 27 | +import javax.servlet.http.HttpServletResponse; | ||
| 28 | +import java.util.Collection; | ||
| 29 | +import java.util.Map; | ||
| 30 | + | ||
| 31 | +/** | ||
| 32 | + * 操作日志记录处理 | ||
| 33 | + * | ||
| 34 | + * @author ruoyi | ||
| 35 | + */ | ||
| 36 | +@Aspect | ||
| 37 | +@Component | ||
| 38 | +public class LogAspect | ||
| 39 | +{ | ||
| 40 | + private static final Logger log = LoggerFactory.getLogger(LogAspect.class); | ||
| 41 | + | ||
| 42 | + /** | ||
| 43 | + * 处理完请求后执行 | ||
| 44 | + * | ||
| 45 | + * @param joinPoint 切点 | ||
| 46 | + */ | ||
| 47 | + @AfterReturning(pointcut = "@annotation(controllerLog)", returning = "jsonResult") | ||
| 48 | + public void doAfterReturning(JoinPoint joinPoint, Log controllerLog, Object jsonResult) | ||
| 49 | + { | ||
| 50 | + handleLog(joinPoint, controllerLog, null, jsonResult); | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + /** | ||
| 54 | + * 拦截异常操作 | ||
| 55 | + * | ||
| 56 | + * @param joinPoint 切点 | ||
| 57 | + * @param e 异常 | ||
| 58 | + */ | ||
| 59 | + @AfterThrowing(value = "@annotation(controllerLog)", throwing = "e") | ||
| 60 | + public void doAfterThrowing(JoinPoint joinPoint, Log controllerLog, Exception e) | ||
| 61 | + { | ||
| 62 | + handleLog(joinPoint, controllerLog, e, null); | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + protected void handleLog(final JoinPoint joinPoint, Log controllerLog, final Exception e, Object jsonResult) | ||
| 66 | + { | ||
| 67 | + try | ||
| 68 | + { | ||
| 69 | + // 获取当前的用户 | ||
| 70 | + BaseLoginUser loginUser = SecurityUtils.getLoginUser(); | ||
| 71 | + | ||
| 72 | + // *========数据库日志=========*// | ||
| 73 | + SysOperLog operLog = new SysOperLog(); | ||
| 74 | + operLog.setStatus(BusinessStatus.SUCCESS.ordinal()); | ||
| 75 | + // 请求的地址 | ||
| 76 | + String ip = IpUtils.getIpAddr(ServletUtils.getRequest()); | ||
| 77 | + operLog.setOperIp(ip); | ||
| 78 | + operLog.setOperUrl(ServletUtils.getRequest().getRequestURI()); | ||
| 79 | + if (loginUser != null) | ||
| 80 | + { | ||
| 81 | + operLog.setOperName(loginUser.getUsername()); | ||
| 82 | + operLog.setUserId(Long.valueOf(loginUser.getUserId()).intValue()); | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + if (e != null) | ||
| 86 | + { | ||
| 87 | + operLog.setStatus(BusinessStatus.FAIL.ordinal()); | ||
| 88 | + operLog.setErrorMsg(StringUtils.substring(e.getMessage(), 0, 2000)); | ||
| 89 | + } | ||
| 90 | + // 设置方法名称 | ||
| 91 | + String className = joinPoint.getTarget().getClass().getName(); | ||
| 92 | + String methodName = joinPoint.getSignature().getName(); | ||
| 93 | + operLog.setMethod(className + "." + methodName + "()"); | ||
| 94 | + // 设置请求方式 | ||
| 95 | + operLog.setRequestMethod(ServletUtils.getRequest().getMethod()); | ||
| 96 | + // 处理设置注解上的参数 | ||
| 97 | + getControllerMethodDescription(joinPoint, controllerLog, operLog, jsonResult); | ||
| 98 | + // 保存数据库 | ||
| 99 | + AsyncManager.me().execute(AsyncFactory.recordOper(operLog)); | ||
| 100 | + } | ||
| 101 | + catch (Exception exp) | ||
| 102 | + { | ||
| 103 | + // 记录本地异常日志 | ||
| 104 | + log.error("==前置通知异常=="); | ||
| 105 | + log.error("异常信息:{}", exp.getMessage()); | ||
| 106 | + exp.printStackTrace(); | ||
| 107 | + } | ||
| 108 | + } | ||
| 109 | + | ||
| 110 | + /** | ||
| 111 | + * 获取注解中对方法的描述信息 用于Controller层注解 | ||
| 112 | + * | ||
| 113 | + * @param log 日志 | ||
| 114 | + * @param operLog 操作日志 | ||
| 115 | + * @throws Exception | ||
| 116 | + */ | ||
| 117 | + public void getControllerMethodDescription(JoinPoint joinPoint, Log log, SysOperLog operLog, Object jsonResult) throws Exception | ||
| 118 | + { | ||
| 119 | + // 设置action动作 | ||
| 120 | + operLog.setBusinessType(log.businessType().ordinal()); | ||
| 121 | + // 设置标题 | ||
| 122 | + operLog.setTitle(log.title()); | ||
| 123 | + // 设置操作人类别 | ||
| 124 | + operLog.setOperatorType(log.operatorType().ordinal()); | ||
| 125 | + // 是否需要保存request,参数和值 | ||
| 126 | + if (log.isSaveRequestData()) | ||
| 127 | + { | ||
| 128 | + // 获取参数的信息,传入到数据库中。 | ||
| 129 | + setRequestValue(joinPoint, operLog); | ||
| 130 | + } | ||
| 131 | + // 是否需要保存response,参数和值 | ||
| 132 | + if (log.isSaveResponseData() && StringUtils.isNotNull(jsonResult)) | ||
| 133 | + { | ||
| 134 | + operLog.setJsonResult(StringUtils.substring(JSON.toJSONString(jsonResult), 0, 2000)); | ||
| 135 | + } | ||
| 136 | + } | ||
| 137 | + | ||
| 138 | + /** | ||
| 139 | + * 获取请求的参数,放到log中 | ||
| 140 | + * | ||
| 141 | + * @param operLog 操作日志 | ||
| 142 | + * @throws Exception 异常 | ||
| 143 | + */ | ||
| 144 | + private void setRequestValue(JoinPoint joinPoint, SysOperLog operLog) throws Exception | ||
| 145 | + { | ||
| 146 | + String requestMethod = operLog.getRequestMethod(); | ||
| 147 | + if (HttpMethod.PUT.name().equals(requestMethod) || HttpMethod.POST.name().equals(requestMethod)) | ||
| 148 | + { | ||
| 149 | + String params = argsArrayToString(joinPoint.getArgs()); | ||
| 150 | + operLog.setOperParam(StringUtils.substring(params, 0, 2000)); | ||
| 151 | + } | ||
| 152 | + else | ||
| 153 | + { | ||
| 154 | + Map<?, ?> paramsMap = (Map<?, ?>) ServletUtils.getRequest().getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE); | ||
| 155 | + operLog.setOperParam(StringUtils.substring(paramsMap.toString(), 0, 2000)); | ||
| 156 | + } | ||
| 157 | + } | ||
| 158 | + | ||
| 159 | + /** | ||
| 160 | + * 参数拼装 | ||
| 161 | + */ | ||
| 162 | + private String argsArrayToString(Object[] paramsArray) | ||
| 163 | + { | ||
| 164 | + String params = ""; | ||
| 165 | + if (paramsArray != null && paramsArray.length > 0) | ||
| 166 | + { | ||
| 167 | + for (Object o : paramsArray) | ||
| 168 | + { | ||
| 169 | + if (StringUtils.isNotNull(o) && !isFilterObject(o)) | ||
| 170 | + { | ||
| 171 | + try | ||
| 172 | + { | ||
| 173 | + Object jsonObj = JSON.toJSON(o); | ||
| 174 | + params += jsonObj.toString() + " "; | ||
| 175 | + } | ||
| 176 | + catch (Exception e) | ||
| 177 | + { | ||
| 178 | + } | ||
| 179 | + } | ||
| 180 | + } | ||
| 181 | + } | ||
| 182 | + return params.trim(); | ||
| 183 | + } | ||
| 184 | + | ||
| 185 | + /** | ||
| 186 | + * 判断是否需要过滤的对象。 | ||
| 187 | + * | ||
| 188 | + * @param o 对象信息。 | ||
| 189 | + * @return 如果是需要过滤的对象,则返回true;否则返回false。 | ||
| 190 | + */ | ||
| 191 | + @SuppressWarnings("rawtypes") | ||
| 192 | + public boolean isFilterObject(final Object o) | ||
| 193 | + { | ||
| 194 | + Class<?> clazz = o.getClass(); | ||
| 195 | + if (clazz.isArray()) | ||
| 196 | + { | ||
| 197 | + return clazz.getComponentType().isAssignableFrom(MultipartFile.class); | ||
| 198 | + } | ||
| 199 | + else if (Collection.class.isAssignableFrom(clazz)) | ||
| 200 | + { | ||
| 201 | + Collection collection = (Collection) o; | ||
| 202 | + for (Object value : collection) | ||
| 203 | + { | ||
| 204 | + return value instanceof MultipartFile; | ||
| 205 | + } | ||
| 206 | + } | ||
| 207 | + else if (Map.class.isAssignableFrom(clazz)) | ||
| 208 | + { | ||
| 209 | + Map map = (Map) o; | ||
| 210 | + for (Object value : map.entrySet()) | ||
| 211 | + { | ||
| 212 | + Map.Entry entry = (Map.Entry) value; | ||
| 213 | + return entry.getValue() instanceof MultipartFile; | ||
| 214 | + } | ||
| 215 | + } | ||
| 216 | + return o instanceof MultipartFile || o instanceof HttpServletRequest || o instanceof HttpServletResponse | ||
| 217 | + || o instanceof BindingResult; | ||
| 218 | + } | ||
| 219 | +} |
| @@ -104,6 +104,11 @@ public class SysOperLog extends BaseEntity | @@ -104,6 +104,11 @@ public class SysOperLog extends BaseEntity | ||
| 104 | @Excel(name = "操作时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss") | 104 | @Excel(name = "操作时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss") |
| 105 | private Date operTime; | 105 | private Date operTime; |
| 106 | 106 | ||
| 107 | + | ||
| 108 | + @ApiModelProperty("操作人员id") | ||
| 109 | + @Excel(name = "状态") | ||
| 110 | + private Integer userId; | ||
| 111 | + | ||
| 107 | public Long getOperId() | 112 | public Long getOperId() |
| 108 | { | 113 | { |
| 109 | return operId; | 114 | return operId; |
| @@ -273,4 +278,12 @@ public class SysOperLog extends BaseEntity | @@ -273,4 +278,12 @@ public class SysOperLog extends BaseEntity | ||
| 273 | { | 278 | { |
| 274 | this.operTime = operTime; | 279 | this.operTime = operTime; |
| 275 | } | 280 | } |
| 281 | + | ||
| 282 | + public Integer getUserId() { | ||
| 283 | + return userId; | ||
| 284 | + } | ||
| 285 | + | ||
| 286 | + public void setUserId(Integer userId) { | ||
| 287 | + this.userId = userId; | ||
| 288 | + } | ||
| 276 | } | 289 | } |
| 1 | -package com.zhonglai.luhui.redis.listener; | ||
| 2 | - | ||
| 3 | -import org.springframework.beans.factory.annotation.Autowired; | ||
| 4 | -import org.springframework.context.annotation.Bean; | ||
| 5 | -import org.springframework.data.redis.connection.RedisConnection; | ||
| 6 | -import org.springframework.data.redis.connection.RedisConnectionFactory; | ||
| 7 | -import org.springframework.data.redis.listener.RedisMessageListenerContainer; | ||
| 8 | -import org.springframework.stereotype.Component; | ||
| 9 | -import org.springframework.util.StringUtils; | ||
| 10 | - | ||
| 11 | -import java.util.Properties; | ||
| 12 | - | ||
| 13 | -@Component | ||
| 14 | -public class RedisAllKeyListener { | ||
| 15 | - private String keyspaceNotificationsConfigParameter = "KEA"; | ||
| 16 | - | ||
| 17 | - @Autowired | ||
| 18 | - private RedisDeleteListener redisDeleteListener ; | ||
| 19 | - @Autowired | ||
| 20 | - private RedisExpiredListener redisExpiredListener ; | ||
| 21 | - @Bean | ||
| 22 | - RedisMessageListenerContainer container(RedisConnectionFactory connectionFactory) { | ||
| 23 | - RedisConnection connection = connectionFactory.getConnection(); | ||
| 24 | - Properties config = connection.info("notify-keyspace-events"); | ||
| 25 | - | ||
| 26 | - if (!StringUtils.hasText(config.getProperty("notify-keyspace-events"))) { | ||
| 27 | - connection.setConfig("notify-keyspace-events", keyspaceNotificationsConfigParameter); | ||
| 28 | - } | ||
| 29 | - RedisMessageListenerContainer container = new RedisMessageListenerContainer(); | ||
| 30 | - container.setConnectionFactory(connectionFactory); | ||
| 31 | - //监听所有key的删除事件 | ||
| 32 | - container.addMessageListener(redisDeleteListener,redisDeleteListener.getTopic()); | ||
| 33 | - //监听所有key的过期事件 | ||
| 34 | - container.addMessageListener(redisExpiredListener,redisExpiredListener.getTopic()); | ||
| 35 | - return container; | ||
| 36 | - } | ||
| 37 | -} | 1 | +//package com.zhonglai.luhui.redis.listener; |
| 2 | +// | ||
| 3 | +//import org.springframework.beans.factory.annotation.Autowired; | ||
| 4 | +//import org.springframework.context.annotation.Bean; | ||
| 5 | +//import org.springframework.data.redis.connection.RedisConnection; | ||
| 6 | +//import org.springframework.data.redis.connection.RedisConnectionFactory; | ||
| 7 | +//import org.springframework.data.redis.listener.RedisMessageListenerContainer; | ||
| 8 | +//import org.springframework.stereotype.Component; | ||
| 9 | +//import org.springframework.util.StringUtils; | ||
| 10 | +// | ||
| 11 | +//import java.util.Properties; | ||
| 12 | +// | ||
| 13 | +//@Component | ||
| 14 | +//public class RedisAllKeyListener { | ||
| 15 | +// private String keyspaceNotificationsConfigParameter = "KEA"; | ||
| 16 | +// | ||
| 17 | +// @Autowired | ||
| 18 | +// private RedisDeleteListener redisDeleteListener ; | ||
| 19 | +// @Autowired | ||
| 20 | +// private RedisExpiredListener redisExpiredListener ; | ||
| 21 | +// @Bean | ||
| 22 | +// RedisMessageListenerContainer container(RedisConnectionFactory connectionFactory) { | ||
| 23 | +// RedisConnection connection = connectionFactory.getConnection(); | ||
| 24 | +// Properties config = connection.info("notify-keyspace-events"); | ||
| 25 | +// | ||
| 26 | +// if (!StringUtils.hasText(config.getProperty("notify-keyspace-events"))) { | ||
| 27 | +// connection.setConfig("notify-keyspace-events", keyspaceNotificationsConfigParameter); | ||
| 28 | +// } | ||
| 29 | +// RedisMessageListenerContainer container = new RedisMessageListenerContainer(); | ||
| 30 | +// container.setConnectionFactory(connectionFactory); | ||
| 31 | +// //监听所有key的删除事件 | ||
| 32 | +// container.addMessageListener(redisDeleteListener,redisDeleteListener.getTopic()); | ||
| 33 | +// //监听所有key的过期事件 | ||
| 34 | +// container.addMessageListener(redisExpiredListener,redisExpiredListener.getTopic()); | ||
| 35 | +// return container; | ||
| 36 | +// } | ||
| 37 | +//} |
| 1 | -package com.zhonglai.luhui.redis.listener; | ||
| 2 | - | ||
| 3 | -import org.slf4j.Logger; | ||
| 4 | -import org.slf4j.LoggerFactory; | ||
| 5 | -import org.springframework.data.redis.connection.Message; | ||
| 6 | -import org.springframework.data.redis.connection.MessageListener; | ||
| 7 | -import org.springframework.data.redis.listener.PatternTopic; | ||
| 8 | -import org.springframework.stereotype.Component; | ||
| 9 | - | ||
| 10 | -@Component | ||
| 11 | -public class RedisDeleteListener implements MessageListener { | ||
| 12 | - private static final Logger logger = LoggerFactory.getLogger(RedisDeleteListener.class); | ||
| 13 | - | ||
| 14 | - //监听的主题 | ||
| 15 | - private final PatternTopic topic = new PatternTopic("__keyevent@1__:del"); //#是对db2数据库,key前缀为order所有键的键空间通知 | ||
| 16 | - | ||
| 17 | - @Override | ||
| 18 | - public void onMessage(Message message, byte[] pattern){ | ||
| 19 | - String topic = new String(pattern); | ||
| 20 | - String msg = new String(message.getBody()); | ||
| 21 | - logger.info("收到key删除,消息主题是:"+ topic+",消息内容是:"+msg); | ||
| 22 | - } | ||
| 23 | - | ||
| 24 | - public PatternTopic getTopic() { | ||
| 25 | - return topic; | ||
| 26 | - } | ||
| 27 | -} | 1 | +//package com.zhonglai.luhui.redis.listener; |
| 2 | +// | ||
| 3 | +//import org.slf4j.Logger; | ||
| 4 | +//import org.slf4j.LoggerFactory; | ||
| 5 | +//import org.springframework.data.redis.connection.Message; | ||
| 6 | +//import org.springframework.data.redis.connection.MessageListener; | ||
| 7 | +//import org.springframework.data.redis.listener.PatternTopic; | ||
| 8 | +//import org.springframework.stereotype.Component; | ||
| 9 | +// | ||
| 10 | +//@Component | ||
| 11 | +//public class RedisDeleteListener implements MessageListener { | ||
| 12 | +// private static final Logger logger = LoggerFactory.getLogger(RedisDeleteListener.class); | ||
| 13 | +// | ||
| 14 | +// //监听的主题 | ||
| 15 | +// private final PatternTopic topic = new PatternTopic("__keyevent@1__:del"); //#是对db2数据库,key前缀为order所有键的键空间通知 | ||
| 16 | +// | ||
| 17 | +// @Override | ||
| 18 | +// public void onMessage(Message message, byte[] pattern){ | ||
| 19 | +// String topic = new String(pattern); | ||
| 20 | +// String msg = new String(message.getBody()); | ||
| 21 | +// logger.info("收到key删除,消息主题是:"+ topic+",消息内容是:"+msg); | ||
| 22 | +// } | ||
| 23 | +// | ||
| 24 | +// public PatternTopic getTopic() { | ||
| 25 | +// return topic; | ||
| 26 | +// } | ||
| 27 | +//} |
| 1 | -package com.zhonglai.luhui.redis.listener; | ||
| 2 | - | ||
| 3 | -import org.slf4j.Logger; | ||
| 4 | -import org.slf4j.LoggerFactory; | ||
| 5 | -import org.springframework.data.redis.connection.Message; | ||
| 6 | -import org.springframework.data.redis.connection.MessageListener; | ||
| 7 | -import org.springframework.data.redis.listener.PatternTopic; | ||
| 8 | -import org.springframework.stereotype.Component; | ||
| 9 | - | ||
| 10 | -@Component | ||
| 11 | -public class RedisExpiredListener implements MessageListener { | ||
| 12 | - private static final Logger logger = LoggerFactory.getLogger(RedisExpiredListener.class); | ||
| 13 | - //监听的主题 | ||
| 14 | - private final PatternTopic topic = new PatternTopic("__keyevent@1__:expired"); | ||
| 15 | - | ||
| 16 | - @Override | ||
| 17 | - public void onMessage(Message message, byte[] pattern){ | ||
| 18 | - String topic = new String(pattern); | ||
| 19 | - String msg = new String(message.getBody()); | ||
| 20 | - logger.info("收到key失效,消息主题是:"+ topic+",消息内容是:"+msg); | ||
| 21 | - } | ||
| 22 | - public PatternTopic getTopic() { | ||
| 23 | - return topic; | ||
| 24 | - } | ||
| 25 | -} | ||
| 1 | +//package com.zhonglai.luhui.redis.listener; | ||
| 2 | +// | ||
| 3 | +//import org.slf4j.Logger; | ||
| 4 | +//import org.slf4j.LoggerFactory; | ||
| 5 | +//import org.springframework.data.redis.connection.Message; | ||
| 6 | +//import org.springframework.data.redis.connection.MessageListener; | ||
| 7 | +//import org.springframework.data.redis.listener.PatternTopic; | ||
| 8 | +//import org.springframework.stereotype.Component; | ||
| 9 | +// | ||
| 10 | +//@Component | ||
| 11 | +//public class RedisExpiredListener implements MessageListener { | ||
| 12 | +// private static final Logger logger = LoggerFactory.getLogger(RedisExpiredListener.class); | ||
| 13 | +// //监听的主题 | ||
| 14 | +// private final PatternTopic topic = new PatternTopic("__keyevent@1__:expired"); | ||
| 15 | +// | ||
| 16 | +// @Override | ||
| 17 | +// public void onMessage(Message message, byte[] pattern){ | ||
| 18 | +// String topic = new String(pattern); | ||
| 19 | +// String msg = new String(message.getBody()); | ||
| 20 | +// logger.info("收到key失效,消息主题是:"+ topic+",消息内容是:"+msg); | ||
| 21 | +// } | ||
| 22 | +// public PatternTopic getTopic() { | ||
| 23 | +// return topic; | ||
| 24 | +// } | ||
| 25 | +//} |
| 1 | -package com.zhonglai.luhui.redis.listener; | ||
| 2 | - | ||
| 3 | -import org.springframework.beans.factory.annotation.Autowired; | ||
| 4 | -import org.springframework.data.redis.connection.Message; | ||
| 5 | -import org.springframework.data.redis.listener.KeyExpirationEventMessageListener; | ||
| 6 | -import org.springframework.data.redis.listener.RedisMessageListenerContainer; | ||
| 7 | -import org.springframework.stereotype.Component; | ||
| 8 | - | ||
| 9 | -/** | ||
| 10 | - * 不指定redis数据库(全局监听) | ||
| 11 | - */ | ||
| 12 | -@Component | ||
| 13 | -public class RedisKeyExpirationListener extends KeyExpirationEventMessageListener { | ||
| 14 | - @Autowired | ||
| 15 | - private DataPersistenceService dtaPersistenceService; | ||
| 16 | - | ||
| 17 | - public RedisKeyExpirationListener(RedisMessageListenerContainer listenerContainer) { | ||
| 18 | - super(listenerContainer); | ||
| 19 | - } | ||
| 20 | - | ||
| 21 | - @Override | ||
| 22 | - public void onMessage(Message message, byte[] pattern) { | ||
| 23 | - String expiredKey = message.toString(); | ||
| 24 | - | ||
| 25 | - String devicePath = dtaPersistenceService.getRedicDeviceKeyPath(); | ||
| 26 | - String terminalPath = dtaPersistenceService.getRedicTerminalKeyPath(); | ||
| 27 | - if(expiredKey.startsWith(devicePath)) //如果是主机 | ||
| 28 | - { | ||
| 29 | - String imei = expiredKey.replace(devicePath,"").replace(":",""); | ||
| 30 | - dtaPersistenceService.offLine(imei); | ||
| 31 | - } | ||
| 32 | - | ||
| 33 | - if(expiredKey.startsWith(terminalPath)) //如果是终端 | ||
| 34 | - { | ||
| 35 | - String imei = expiredKey.replace(devicePath,"").replace(":",""); | ||
| 36 | - dtaPersistenceService.offLine(imei); | ||
| 37 | - } | ||
| 38 | - } | ||
| 39 | -} | 1 | +//package com.zhonglai.luhui.redis.listener; |
| 2 | +// | ||
| 3 | +//import org.springframework.beans.factory.annotation.Autowired; | ||
| 4 | +//import org.springframework.data.redis.connection.Message; | ||
| 5 | +//import org.springframework.data.redis.listener.KeyExpirationEventMessageListener; | ||
| 6 | +//import org.springframework.data.redis.listener.RedisMessageListenerContainer; | ||
| 7 | +//import org.springframework.stereotype.Component; | ||
| 8 | +// | ||
| 9 | +///** | ||
| 10 | +// * 不指定redis数据库(全局监听) | ||
| 11 | +// */ | ||
| 12 | +//@Component | ||
| 13 | +//public class RedisKeyExpirationListener extends KeyExpirationEventMessageListener { | ||
| 14 | +// @Autowired | ||
| 15 | +// private DataPersistenceService dtaPersistenceService; | ||
| 16 | +// | ||
| 17 | +// public RedisKeyExpirationListener(RedisMessageListenerContainer listenerContainer) { | ||
| 18 | +// super(listenerContainer); | ||
| 19 | +// } | ||
| 20 | +// | ||
| 21 | +// @Override | ||
| 22 | +// public void onMessage(Message message, byte[] pattern) { | ||
| 23 | +// String expiredKey = message.toString(); | ||
| 24 | +// | ||
| 25 | +// String devicePath = dtaPersistenceService.getRedicDeviceKeyPath(); | ||
| 26 | +// String terminalPath = dtaPersistenceService.getRedicTerminalKeyPath(); | ||
| 27 | +// if(expiredKey.startsWith(devicePath)) //如果是主机 | ||
| 28 | +// { | ||
| 29 | +// String imei = expiredKey.replace(devicePath,"").replace(":",""); | ||
| 30 | +// dtaPersistenceService.offLine(imei); | ||
| 31 | +// } | ||
| 32 | +// | ||
| 33 | +// if(expiredKey.startsWith(terminalPath)) //如果是终端 | ||
| 34 | +// { | ||
| 35 | +// String imei = expiredKey.replace(devicePath,"").replace(":",""); | ||
| 36 | +// dtaPersistenceService.offLine(imei); | ||
| 37 | +// } | ||
| 38 | +// } | ||
| 39 | +//} |
| @@ -7,9 +7,9 @@ import com.ruoyi.common.utils.StringUtils; | @@ -7,9 +7,9 @@ import com.ruoyi.common.utils.StringUtils; | ||
| 7 | import com.ruoyi.common.utils.ip.AddressUtils; | 7 | import com.ruoyi.common.utils.ip.AddressUtils; |
| 8 | import com.ruoyi.common.utils.ip.IpUtils; | 8 | import com.ruoyi.common.utils.ip.IpUtils; |
| 9 | import com.ruoyi.common.utils.uuid.IdUtils; | 9 | import com.ruoyi.common.utils.uuid.IdUtils; |
| 10 | -import com.zhonglai.luhui.security.dto.BaseLoginUser; | 10 | +import com.zhonglai.luhui.dao.service.PublicService; |
| 11 | +import com.zhonglai.luhui.security.dto.*; | ||
| 11 | import com.zhonglai.luhui.redis.service.RedisCache; | 12 | import com.zhonglai.luhui.redis.service.RedisCache; |
| 12 | -import com.zhonglai.luhui.security.dto.SysLoginUser; | ||
| 13 | import eu.bitwalker.useragentutils.UserAgent; | 13 | import eu.bitwalker.useragentutils.UserAgent; |
| 14 | import io.jsonwebtoken.Claims; | 14 | import io.jsonwebtoken.Claims; |
| 15 | import io.jsonwebtoken.Jwts; | 15 | import io.jsonwebtoken.Jwts; |
| @@ -60,6 +60,9 @@ public class TokenService | @@ -60,6 +60,9 @@ public class TokenService | ||
| 60 | @Autowired | 60 | @Autowired |
| 61 | private RedisCache redisCache; | 61 | private RedisCache redisCache; |
| 62 | 62 | ||
| 63 | + @Autowired | ||
| 64 | + private PublicService publicService; | ||
| 65 | + | ||
| 63 | /** | 66 | /** |
| 64 | * 获取用户身份信息 | 67 | * 获取用户身份信息 |
| 65 | * | 68 | * |
| @@ -81,7 +84,7 @@ public class TokenService | @@ -81,7 +84,7 @@ public class TokenService | ||
| 81 | Collection<String> keys = redisCache.keys(userKey); | 84 | Collection<String> keys = redisCache.keys(userKey); |
| 82 | if(null != keys && keys.size() != 0) | 85 | if(null != keys && keys.size() != 0) |
| 83 | { | 86 | { |
| 84 | - SysLoginUser user = redisCache.getCacheObject(keys.stream().findFirst().get()); | 87 | + BaseLoginUser user = redisCache.getCacheObject(keys.stream().findFirst().get()); |
| 85 | return user; | 88 | return user; |
| 86 | } | 89 | } |
| 87 | } | 90 | } |
| @@ -93,6 +96,62 @@ public class TokenService | @@ -93,6 +96,62 @@ public class TokenService | ||
| 93 | return null; | 96 | return null; |
| 94 | } | 97 | } |
| 95 | 98 | ||
| 99 | + | ||
| 100 | + public BaseLoginUser getApiLoginUser(HttpServletRequest request ) | ||
| 101 | + { | ||
| 102 | + // 获取请求携带的令牌 | ||
| 103 | + String token = getToken(request); | ||
| 104 | + if (StringUtils.isNotEmpty(token)) | ||
| 105 | + { | ||
| 106 | + try | ||
| 107 | + { | ||
| 108 | + | ||
| 109 | + if(token.split(".").length==3) | ||
| 110 | + { | ||
| 111 | + Claims claims = parseToken(token); | ||
| 112 | + // 解析对应的权限以及用户信息 | ||
| 113 | + String uuid = (String) claims.get(Constants.LOGIN_USER_KEY); | ||
| 114 | + String userKey = getTokenKey(uuid); | ||
| 115 | + | ||
| 116 | + Collection<String> keys = redisCache.keys(userKey); | ||
| 117 | + if(null != keys && keys.size() != 0) | ||
| 118 | + { | ||
| 119 | + BaseLoginUser user = redisCache.getCacheObject(keys.stream().findFirst().get()); | ||
| 120 | + return user; | ||
| 121 | + } | ||
| 122 | + }else { | ||
| 123 | + // 解析对应的权限以及用户信息 | ||
| 124 | + String userKey = getTokenKey(token); | ||
| 125 | + if(redisCache.hasKey(userKey)) | ||
| 126 | + { | ||
| 127 | + Collection<String> keys = redisCache.keys(userKey); | ||
| 128 | + if(null != keys && keys.size() != 0) | ||
| 129 | + { | ||
| 130 | + BaseLoginUser user = redisCache.getCacheObject(keys.stream().findFirst().get()); | ||
| 131 | + return user; | ||
| 132 | + } | ||
| 133 | + }else{ | ||
| 134 | + LoginToken loginToken = new LoginToken(token); | ||
| 135 | + | ||
| 136 | + Yu2leUserLogin yu2leUserLogin = publicService.getObjectForTableName(Yu2leUserLogin.class,"userId",loginToken.getUserId()+"","`liu_yu_le`.`user_login`"); | ||
| 137 | + Yu2leUserInfo yu2leUserInfo = publicService.getObjectForTableName(Yu2leUserInfo.class,"loginName",loginToken.getUserId()+"","`liu_yu_le`.`user_info`"); | ||
| 138 | + BaseLoginUser baseLoginUser = new ApiLoginUser(yu2leUserInfo, yu2leUserLogin); | ||
| 139 | + baseLoginUser.setToken(token); | ||
| 140 | + setUserAgent(baseLoginUser); | ||
| 141 | + refreshToken(baseLoginUser); | ||
| 142 | + return baseLoginUser; | ||
| 143 | + } | ||
| 144 | + } | ||
| 145 | + | ||
| 146 | + } | ||
| 147 | + catch (Exception e) | ||
| 148 | + { | ||
| 149 | + logger.error("令牌获取登录信息失败",e); | ||
| 150 | + } | ||
| 151 | + } | ||
| 152 | + return null; | ||
| 153 | + } | ||
| 154 | + | ||
| 96 | /** | 155 | /** |
| 97 | * 设置用户身份信息 | 156 | * 设置用户身份信息 |
| 98 | */ | 157 | */ |
| @@ -134,6 +193,17 @@ public class TokenService | @@ -134,6 +193,17 @@ public class TokenService | ||
| 134 | return createToken(claims); | 193 | return createToken(claims); |
| 135 | } | 194 | } |
| 136 | 195 | ||
| 196 | + public String creatApiToken(BaseLoginUser loginUser) | ||
| 197 | + { | ||
| 198 | + LoginToken loginToken = new LoginToken(Long.valueOf(loginUser.getUserId()).intValue(),null,null,null); | ||
| 199 | + String token = loginToken.get(); | ||
| 200 | + loginUser.setToken(token); | ||
| 201 | + setUserAgent(loginUser); | ||
| 202 | + refreshToken(loginUser); | ||
| 203 | + | ||
| 204 | + return token; | ||
| 205 | + | ||
| 206 | + } | ||
| 137 | public void upUser(BaseLoginUser loginUser, SysLogininforType sysLogininforType) | 207 | public void upUser(BaseLoginUser loginUser, SysLogininforType sysLogininforType) |
| 138 | { | 208 | { |
| 139 | String userKey = getTokenKey(loginUser.getToken()); | 209 | String userKey = getTokenKey(loginUser.getToken()); |
| @@ -33,7 +33,7 @@ public abstract class ThingsModelItemBase<T> implements ThingsModelBase<T> | @@ -33,7 +33,7 @@ public abstract class ThingsModelItemBase<T> implements ThingsModelBase<T> | ||
| 33 | break; | 33 | break; |
| 34 | case BOOL: | 34 | case BOOL: |
| 35 | thingsModelItemBase = GsonConstructor.get().fromJson(specs,BoolModelOutput.class); | 35 | thingsModelItemBase = GsonConstructor.get().fromJson(specs,BoolModelOutput.class); |
| 36 | - thingsModelItemBase.setValue(jsonElement.getAsBoolean()); | 36 | + thingsModelItemBase.setValue(Boolean.parseBoolean(jsonElement.getAsString()) || jsonElement.getAsString().equals("1")); |
| 37 | break; | 37 | break; |
| 38 | case ENUM: | 38 | case ENUM: |
| 39 | thingsModelItemBase = GsonConstructor.get().fromJson(specs,EnumModelOutput.class); | 39 | thingsModelItemBase = GsonConstructor.get().fromJson(specs,EnumModelOutput.class); |
| @@ -69,7 +69,7 @@ public abstract class ThingsModelItemBase<T> implements ThingsModelBase<T> | @@ -69,7 +69,7 @@ public abstract class ThingsModelItemBase<T> implements ThingsModelBase<T> | ||
| 69 | } | 69 | } |
| 70 | ThingsModelItemBase thingsModelItemBase = new StringModelOutput(); | 70 | ThingsModelItemBase thingsModelItemBase = new StringModelOutput(); |
| 71 | 71 | ||
| 72 | - ThingsModelDataTypeEnum thingsModelDataTypeEnum = Enum.valueOf(ThingsModelDataTypeEnum.class,type); | 72 | + ThingsModelDataTypeEnum thingsModelDataTypeEnum = Enum.valueOf(ThingsModelDataTypeEnum.class,type.toUpperCase()); |
| 73 | switch (thingsModelDataTypeEnum) | 73 | switch (thingsModelDataTypeEnum) |
| 74 | { | 74 | { |
| 75 | case STRING: | 75 | case STRING: |
| 1 | package com.zhonglai.luhui.device.analysis.comm.util; | 1 | package com.zhonglai.luhui.device.analysis.comm.util; |
| 2 | 2 | ||
| 3 | import java.util.Arrays; | 3 | import java.util.Arrays; |
| 4 | +import java.util.zip.CRC32; | ||
| 5 | +import java.util.zip.Checksum; | ||
| 4 | 6 | ||
| 5 | public class ByteUtil { | 7 | public class ByteUtil { |
| 6 | /** | 8 | /** |
| @@ -106,7 +108,10 @@ public class ByteUtil { | @@ -106,7 +108,10 @@ public class ByteUtil { | ||
| 106 | } | 108 | } |
| 107 | 109 | ||
| 108 | public static void main(String[] args) { | 110 | public static void main(String[] args) { |
| 109 | - System.out.println(ByteUtil.toHexString( ByteUtil.intToBytesASC(2011239256,4))); | 111 | + byte[] bytes = new byte[]{(byte) 0xA5,0x0F,(byte) 0x80,0x21,0x70,0x04 ,(byte) 0xB9 ,0x00 ,0x4D ,0x0F ,(byte) 0x82 ,0x01 , (byte) 0xD2,0x00}; |
| 112 | + long crc = calculateChecksum(bytes); | ||
| 113 | + System.out.println(crc); | ||
| 114 | + System.out.println(verifyChecksum(bytes, (byte) 0x33)); | ||
| 110 | } | 115 | } |
| 111 | 116 | ||
| 112 | /** | 117 | /** |
| @@ -196,4 +201,30 @@ public class ByteUtil { | @@ -196,4 +201,30 @@ public class ByteUtil { | ||
| 196 | return str.length() == 1 ? "0" + str : str.substring(str.length() - 2, str.length()); | 201 | return str.length() == 1 ? "0" + str : str.substring(str.length() - 2, str.length()); |
| 197 | } | 202 | } |
| 198 | } | 203 | } |
| 204 | + | ||
| 205 | + /** | ||
| 206 | + * 计算 byte 数组的和 | ||
| 207 | + * | ||
| 208 | + * @param byteArray 输入的 byte 数组 | ||
| 209 | + * @return 数组中所有字节的和 | ||
| 210 | + */ | ||
| 211 | + public static byte calculateChecksum(byte[] byteArray) { | ||
| 212 | + int sum = 0; | ||
| 213 | + for (byte hex : byteArray) { | ||
| 214 | + sum += hex; | ||
| 215 | + } | ||
| 216 | + return (byte) (sum & 0xFF); | ||
| 217 | + } | ||
| 218 | + | ||
| 219 | + /** | ||
| 220 | + * 验证 byte 数组的和是否等于预期的校验和 | ||
| 221 | + * | ||
| 222 | + * @param byteArray 输入的 byte 数组 | ||
| 223 | + * @param expectedChecksum 预期的校验和 | ||
| 224 | + * @return 如果计算出的和等于预期的校验和,则返回 true;否则返回 false | ||
| 225 | + */ | ||
| 226 | + public static boolean verifyChecksum(byte[] byteArray, byte expectedChecksum) { | ||
| 227 | + long calculatedChecksum = calculateChecksum(byteArray); | ||
| 228 | + return calculatedChecksum == expectedChecksum; | ||
| 229 | + } | ||
| 199 | } | 230 | } |
| @@ -51,64 +51,74 @@ public class TopicUtil { | @@ -51,64 +51,74 @@ public class TopicUtil { | ||
| 51 | */ | 51 | */ |
| 52 | public static String generateRedicKey(Topic topic) | 52 | public static String generateRedicKey(Topic topic) |
| 53 | { | 53 | { |
| 54 | - return generate(topic,":"); | 54 | + return generate(topic,SysParameter.topicconfig); |
| 55 | } | 55 | } |
| 56 | 56 | ||
| 57 | /** | 57 | /** |
| 58 | * 生成发送消息的topic | 58 | * 生成发送消息的topic |
| 59 | * @return | 59 | * @return |
| 60 | */ | 60 | */ |
| 61 | + public static String generateSendMessageTopic(Topic topic,String topicconfig) | ||
| 62 | + { | ||
| 63 | + | ||
| 64 | + return generate(topic,topicconfig); | ||
| 65 | + } | ||
| 66 | + | ||
| 61 | public static String generateSendMessageTopic(Topic topic) | 67 | public static String generateSendMessageTopic(Topic topic) |
| 62 | { | 68 | { |
| 63 | 69 | ||
| 64 | - return "/"+generate(topic,"/"); | 70 | + return generate(topic,SysParameter.topicconfig); |
| 65 | } | 71 | } |
| 66 | 72 | ||
| 67 | /** | 73 | /** |
| 68 | * 生成客户端关键字 | 74 | * 生成客户端关键字 |
| 69 | * @return | 75 | * @return |
| 70 | */ | 76 | */ |
| 77 | + public static String generateClienKey(Topic topic,String topicconfig) | ||
| 78 | + { | ||
| 79 | + return generate(topic,topicconfig); | ||
| 80 | + } | ||
| 71 | public static String generateClienKey(Topic topic) | 81 | public static String generateClienKey(Topic topic) |
| 72 | { | 82 | { |
| 73 | - return "/"+generate(topic,"/"); | 83 | + return generate(topic,SysParameter.topicconfig); |
| 74 | } | 84 | } |
| 75 | 85 | ||
| 76 | - private static String generate(Topic topic,String division) | 86 | + private static String generate(Topic topic,String topicconfig) |
| 77 | { | 87 | { |
| 78 | - String str = SysParameter.topicconfig; | 88 | + String str = topicconfig; |
| 79 | if(StringUtils.isEmpty(topic.getRoleid())) | 89 | if(StringUtils.isEmpty(topic.getRoleid())) |
| 80 | { | 90 | { |
| 81 | topic.setRoleid("2"); | 91 | topic.setRoleid("2"); |
| 82 | } | 92 | } |
| 83 | - str = str.replace("/{{roleid}}",topic.getRoleid()+division); | 93 | + str = str.replace("{{roleid}}",topic.getRoleid()); |
| 84 | 94 | ||
| 85 | if(StringUtils.isEmpty(topic.getUsername())) | 95 | if(StringUtils.isEmpty(topic.getUsername())) |
| 86 | { | 96 | { |
| 87 | topic.setUsername("+"); | 97 | topic.setUsername("+"); |
| 88 | } | 98 | } |
| 89 | - str = str.replace("/{{username}}",topic.getUsername()+division); | 99 | + str = str.replace("{{username}}",topic.getUsername()); |
| 90 | 100 | ||
| 91 | if(StringUtils.isEmpty(topic.getClientid())) | 101 | if(StringUtils.isEmpty(topic.getClientid())) |
| 92 | { | 102 | { |
| 93 | topic.setClientid( "+"); | 103 | topic.setClientid( "+"); |
| 94 | } | 104 | } |
| 95 | - str = str.replace("/{{clientid}}",topic.getClientid()+division); | 105 | + str = str.replace("{{clientid}}",topic.getClientid()); |
| 96 | 106 | ||
| 97 | if(StringUtils.isEmpty(topic.getPayloadtype())) | 107 | if(StringUtils.isEmpty(topic.getPayloadtype())) |
| 98 | { | 108 | { |
| 99 | topic.setPayloadtype( "String"); | 109 | topic.setPayloadtype( "String"); |
| 100 | } | 110 | } |
| 101 | - str = str.replace("/{{payloadtype}}",topic.getPayloadtype()+division); | 111 | + str = str.replace("{{payloadtype}}",topic.getPayloadtype()); |
| 102 | 112 | ||
| 103 | if(StringUtils.isEmpty(topic.getTopicType())) | 113 | if(StringUtils.isEmpty(topic.getTopicType())) |
| 104 | { | 114 | { |
| 105 | topic.setTopicType("PUT"); | 115 | topic.setTopicType("PUT"); |
| 106 | } | 116 | } |
| 107 | - str = str.replace("/{{topicType}}",topic.getTopicType()+division); | 117 | + str = str.replace("{{topicType}}",topic.getTopicType()); |
| 108 | 118 | ||
| 109 | if(StringUtils.isNotEmpty(topic.getMessageid())) | 119 | if(StringUtils.isNotEmpty(topic.getMessageid())) |
| 110 | { | 120 | { |
| 111 | - str = str.replace("/{{messageid}}",topic.getMessageid()); | 121 | + str = str.replace("{{messageid}}",topic.getMessageid()); |
| 112 | } | 122 | } |
| 113 | 123 | ||
| 114 | return str; | 124 | return str; |
| @@ -93,10 +93,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | @@ -93,10 +93,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | ||
| 93 | <if test="used != null">used = #{used},</if> | 93 | <if test="used != null">used = #{used},</if> |
| 94 | <if test="mqtt_username != null and mqtt_username != ''">mqtt_username = #{mqtt_username},</if> | 94 | <if test="mqtt_username != null and mqtt_username != ''">mqtt_username = #{mqtt_username},</if> |
| 95 | <if test="product_name != null and product_name != ''">product_name = #{product_name},</if> | 95 | <if test="product_name != null and product_name != ''">product_name = #{product_name},</if> |
| 96 | - <if test="role_id != null">is_sync_db = #{is_sync_db},</if> | ||
| 97 | - <if test="role_id != null">role_id = #{sync_db},</if> | ||
| 98 | - <if test="role_id != null">analysis_clas = #{analysis_clas},</if> | ||
| 99 | - <if test="role_id != null">purification_clas = #{purification_clas},</if> | 96 | + <if test="is_sync_db != null">is_sync_db = #{is_sync_db},</if> |
| 97 | + <if test="sync_db != null">sync_db = #{sync_db},</if> | ||
| 98 | + <if test="analysis_clas != null">analysis_clas = #{analysis_clas},</if> | ||
| 99 | + <if test="purification_clas != null">purification_clas = #{purification_clas},</if> | ||
| 100 | </trim> | 100 | </trim> |
| 101 | where id = #{id} | 101 | where id = #{id} |
| 102 | </update> | 102 | </update> |
| @@ -21,16 +21,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | @@ -21,16 +21,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | ||
| 21 | <result property="status" column="status" /> | 21 | <result property="status" column="status" /> |
| 22 | <result property="errorMsg" column="error_msg" /> | 22 | <result property="errorMsg" column="error_msg" /> |
| 23 | <result property="operTime" column="oper_time" /> | 23 | <result property="operTime" column="oper_time" /> |
| 24 | + <result property="userId" column="user_id" /> | ||
| 24 | </resultMap> | 25 | </resultMap> |
| 25 | 26 | ||
| 26 | <sql id="selectOperLogVo"> | 27 | <sql id="selectOperLogVo"> |
| 27 | - select oper_id, title, business_type, method, request_method, operator_type, oper_name, dept_name, oper_url, oper_ip, oper_location, oper_param, json_result, status, error_msg, oper_time | 28 | + select oper_id, title, business_type, method, request_method, operator_type, oper_name, dept_name, oper_url, oper_ip, oper_location, oper_param, json_result, status, error_msg, oper_time,user_id |
| 28 | from sys_oper_log | 29 | from sys_oper_log |
| 29 | </sql> | 30 | </sql> |
| 30 | 31 | ||
| 31 | <insert id="insertOperlog" parameterType="SysOperLog"> | 32 | <insert id="insertOperlog" parameterType="SysOperLog"> |
| 32 | - insert into sys_oper_log(title, business_type, method, request_method, operator_type, oper_name, dept_name, oper_url, oper_ip, oper_location, oper_param, json_result, status, error_msg, oper_time) | ||
| 33 | - values (#{title}, #{businessType}, #{method}, #{requestMethod}, #{operatorType}, #{operName}, #{deptName}, #{operUrl}, #{operIp}, #{operLocation}, #{operParam}, #{jsonResult}, #{status}, #{errorMsg}, sysdate()) | 33 | + insert into sys_oper_log(title, business_type, method, request_method, operator_type, oper_name, dept_name, oper_url, oper_ip, oper_location, oper_param, json_result, status, error_msg, oper_time,user_id) |
| 34 | + values (#{title}, #{businessType}, #{method}, #{requestMethod}, #{operatorType}, #{operName}, #{deptName}, #{operUrl}, #{operIp}, #{operLocation}, #{operParam}, #{jsonResult}, #{status}, #{errorMsg}, sysdate(),#{userId}) | ||
| 34 | </insert> | 35 | </insert> |
| 35 | 36 | ||
| 36 | <select id="selectOperLogList" parameterType="SysOperLog" resultMap="SysOperLogResult"> | 37 | <select id="selectOperLogList" parameterType="SysOperLog" resultMap="SysOperLogResult"> |
| @@ -51,6 +52,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | @@ -51,6 +52,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | ||
| 51 | <if test="status != null"> | 52 | <if test="status != null"> |
| 52 | AND status = #{status} | 53 | AND status = #{status} |
| 53 | </if> | 54 | </if> |
| 55 | + <if test="userId != null"> | ||
| 56 | + AND user_id = #{userId} | ||
| 57 | + </if> | ||
| 54 | <if test="operName != null and operName != ''"> | 58 | <if test="operName != null and operName != ''"> |
| 55 | AND oper_name like concat('%', #{operName}, '%') | 59 | AND oper_name like concat('%', #{operName}, '%') |
| 56 | </if> | 60 | </if> |
-
请 注册 或 登录 后发表评论