Your Name 1 год назад
Родитель
Сommit
9edb9a0abb

+ 124 - 0
.idea/uiDesigner.xml

@@ -0,0 +1,124 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="Palette2">
+    <group name="Swing">
+      <item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
+      </item>
+      <item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
+      </item>
+      <item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
+      </item>
+      <item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
+        <default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
+      </item>
+      <item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
+        <initial-values>
+          <property name="text" value="Button" />
+        </initial-values>
+      </item>
+      <item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
+        <initial-values>
+          <property name="text" value="RadioButton" />
+        </initial-values>
+      </item>
+      <item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
+        <initial-values>
+          <property name="text" value="CheckBox" />
+        </initial-values>
+      </item>
+      <item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
+        <initial-values>
+          <property name="text" value="Label" />
+        </initial-values>
+      </item>
+      <item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
+          <preferred-size width="150" height="-1" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
+          <preferred-size width="150" height="-1" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
+          <preferred-size width="150" height="-1" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
+          <preferred-size width="150" height="50" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
+          <preferred-size width="150" height="50" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
+          <preferred-size width="150" height="50" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
+      </item>
+      <item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
+          <preferred-size width="150" height="50" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
+          <preferred-size width="150" height="50" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
+          <preferred-size width="150" height="50" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
+          <preferred-size width="200" height="200" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
+          <preferred-size width="200" height="200" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
+        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
+      </item>
+      <item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
+      </item>
+      <item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
+      </item>
+      <item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
+      </item>
+      <item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
+          <preferred-size width="-1" height="20" />
+        </default-constraints>
+      </item>
+      <item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
+        <default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
+      </item>
+      <item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
+        <default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
+      </item>
+    </group>
+  </component>
+</project>

+ 0 - 0
he1fuh9LSDW12357securemode2authTyperegnwlsignmethodhmacsha256random996instanceIdiot-060a0bgd-sslhe1fuh9LSDWiot-as-mqttcn-shanghaialiyuncscom443/.lck


+ 14 - 10
src/main/java/com/tuoren/forward/aspect/HandleLogAspect.java

@@ -50,7 +50,6 @@ public class HandleLogAspect {
 	@Autowired
 	private LogMapper logMapper;
 	
-	//@Pointcut("execution(* com.tuoren.forward.controller.*.*(..))")
 	@Pointcut("@annotation(com.tuoren.forward.annotation.HandleLog)")
 	public void handleLogPoint() {}
 	
@@ -79,10 +78,10 @@ public class HandleLogAspect {
     public Object handleLogAround(ProceedingJoinPoint joinPoint) throws Throwable {
         HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
         long time = System.currentTimeMillis();
-        Log handleLog = packLog(request,joinPoint);
-        MethodSignature signature = (MethodSignature) joinPoint.getSignature();
-        Method method = signature.getMethod();
-        HandleLog logAnno = method.getAnnotation(HandleLog.class);
+        Log handleLog = packLog(request,joinPoint);//打包日志信息
+        MethodSignature signature = (MethodSignature) joinPoint.getSignature();//获取签名
+        Method method = signature.getMethod();//获取方法
+        HandleLog logAnno = method.getAnnotation(HandleLog.class);//获取注解
 		if(logAnno.value() == HandleLogChoice.RECORD_ANY  || logAnno.value() == HandleLogChoice.RECORD_EXCEPTION) {
 			request.setAttribute(CommonConstant.REQUEST_LOG_ATTR, handleLog);
 	        request.setAttribute(CommonConstant.REQUEST_TIME_ATTR, time);
@@ -130,10 +129,10 @@ public class HandleLogAspect {
 		Log handleLog = new Log();
 		handleLog.setId(UUIDUtil.get32UUID());
 		handleLog.setCreatetime(new Date());
-		handleLog.setIp(request.getRemoteAddr());
-		handleLog.setStyle(request.getMethod());
-		handleLog.setUrl(request.getRequestURI());
-		Map<String,String[]> paramMap = request.getParameterMap();
+		handleLog.setIp(request.getRemoteAddr());//获取ip地址
+		handleLog.setStyle(request.getMethod());//获取请求方法
+		handleLog.setUrl(request.getRequestURI());//获取URL
+		Map<String,String[]> paramMap = request.getParameterMap();//将请求转换为JSON字符串,并限制长度不能超过200字符,然后设置到日志对象中
     	if(paramMap != null&& paramMap.size() > 0) {
     		String paramStr =JSONObject.toJSONString(paramMap);
     		if(paramStr.length() > 200) {
@@ -141,26 +140,31 @@ public class HandleLogAspect {
     		}
     		handleLog.setParam(paramStr);
     	}
+		//获取当前用户信息
     	User user = AccessTokenUtil.getUser();
     	if(user != null) {
     		handleLog.setUserid(user.getId());
     		handleLog.setUsername(user.getUsername());
     	}
+		//获取方法名,并设置方法全名到日志对象中
 		MethodSignature signature = (MethodSignature) joinPoint.getSignature();
 		String methodName = signature.getDeclaringTypeName()+"."+signature.getName();
 		handleLog.setMethod(methodName);
+		//设置模块信息,如果类上有@Tag注解,则设置模块名称到日志对象中
 		Tag tag = (Tag) signature.getDeclaringType().getDeclaredAnnotation(Tag.class);
 		 //设置模块
         if(tag != null) {
         	handleLog.setModule(tag.name());
         }
-        
+
+		//如果方法上有@Operation注解,则设置操作描述到日志对象中。
         Method method = signature.getMethod();
         Operation op = method.getDeclaredAnnotation(Operation.class);
         //设置功能
         if(op != null) {
         	handleLog.setOperation(op.summary());
         }
+		//处理请求体中的参数,如果参数上有@RequestBody注解,则将其转换为JSON字符串,并限制长度不超过200个字符,然后设置到日志对象中。
         Object[] args = joinPoint.getArgs();
         Parameter[] params = method.getParameters();
         for(int i=0;i<params.length;i++) {

+ 114 - 0
src/main/java/com/tuoren/forward/netty/AES.java

@@ -0,0 +1,114 @@
+package com.tuoren.forward.netty;
+
+
+import com.alibaba.fastjson2.JSONObject;
+
+import javax.crypto.Cipher;
+import javax.crypto.spec.SecretKeySpec;
+
+/**
+ * @author Administrator
+ */
+public class AES {
+    /**
+     * @param sSrc 待加密的字符串
+     * @param sKey 加密使用的密钥,长度必须为16位
+     * @return 加密后的字节数组
+     * @throws Exception 如果密钥为空或长度不是16位,则抛出异常
+     */
+    // 加密 
+    public static byte[] encrypt(String sSrc, String sKey) throws Exception {
+        if (sKey == null) {
+            System.out.print("Key为空null");
+            return null;
+        }
+        // 判断Key是否为16位 
+        if (sKey.length() != 16) {
+            System.out.print("Key长度不是16位");
+            return null;
+        }
+        byte[] raw = sKey.getBytes("utf-8");
+        SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
+        Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");//"算法/模式/补码方式" 
+        cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
+        byte[] encrypted = cipher.doFinal(sSrc.getBytes("utf-8"));
+        return encrypted;
+    }
+
+    /**
+     * 使用AES算法解密给定的密文.
+     *
+     * @param encrypted1 密文,需要被解密的字节数组
+     * @param sKey       解密密钥,需为16位
+     * @return 解密后的字符串
+     * @throws Exception 如果密钥不正确或解密过程出错,则抛出异常
+     */
+    // 解密
+    public static String decrypt(byte[] encrypted1, String sKey) throws Exception {
+        try {
+            // 判断Key是否正确
+            if (sKey == null) {
+                System.out.print("Key为空null");
+                return null;
+            }
+            // 判断Key是否为16位
+            if (sKey.length() != 16) {
+                System.out.print("Key长度不是16位");
+                return null;
+            }
+            byte[] raw = sKey.getBytes("utf-8");
+            SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
+            Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
+            cipher.init(Cipher.DECRYPT_MODE, skeySpec);
+            try {
+                byte[] original = cipher.doFinal(encrypted1);// 解密
+                String originalString = new String(original, "utf-8");
+//                String originalString = new String(encrypted1,"utf-8");
+                return originalString;
+            } catch (Exception e) {
+                e.printStackTrace();
+                System.out.println(e.toString());
+                return null;
+            }
+        } catch (Exception ex) {
+            System.out.println(ex.toString());
+            return null;
+        }
+    }
+
+    /**
+     * 程序的主入口点
+     * 此方法演示了如何使用AES-128-ECB加密和解密模式
+     * 使用此模式时,密钥需要为16位
+     *
+     * @param args 命令行参数
+     * @throws Exception 如果发生加密或解密异常
+     */
+
+
+    public static void main(String[] args) throws Exception {
+        /*
+         * 此处使用AES-128-ECB加密模式,key需要为16位。
+         */
+        // 需要加密的字串 
+        String cKey = "tuorenzhinenghua";
+//        String cSrc = "3431228A1936013C&a1xJ4qC587v&"; 
+        JSONObject json = new JSONObject();
+//        json.put("deviceId", "1234567");
+        json.put("deviceId", "7654321");
+        json.put("network", "wifi");
+        json.put("userId", "0001");
+
+        System.out.println(json.toString());
+        // 加密 
+        byte[] enString = AES.encrypt(json.toString(), cKey);
+        for (byte a : enString) {
+            System.out.printf("%02x", a);
+        }
+        String result = AES.decrypt(enString, cKey);
+        System.out.println("\r\naes decrypt:" + result);
+
+
+    }
+} 
+ 

+ 89 - 0
src/main/resources/config/db.setting

@@ -0,0 +1,89 @@
+[dev]
+url = jdbc:mysql://47.101.214.91:7001/nbnetpump?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8
+username = root
+password = Tuoren123.
+## 可选配置
+# 是否在日志中显示执行的SQL
+showSql = true
+# 是否格式化显示的SQL
+formatSql = false
+# 是否显示SQL参数
+showParams = true
+# 打印SQL的日志等级,默认debug,可以是info、warn、error
+sqlLevel = debug
+# 自动提交
+autoCommit = true
+# 等待连接池分配连接的最大时长(毫秒),超过这个时长还没可用的连接则发生SQLException, 缺省:30秒
+connectionTimeout = 30000
+# 一个连接idle状态的最大时长(毫秒),超时则被释放(retired),缺省:10分钟
+idleTimeout = 600000
+# 一个连接的生命时长(毫秒),超时而且没被使用则被释放(retired),缺省:30分钟,建议设置比数据库超时时长少30秒,参考MySQL wait_timeout参数(show variables like '%timeout%';)
+maxLifetime = 1800000
+# 获取连接前的测试SQL
+connectionTestQuery = SELECT 1
+# 最小闲置连接数
+minimumIdle = 1
+# 连接池中允许的最大连接数。缺省值:10;推荐的公式:((core_count * 2) + effective_spindle_count)
+maximumPoolSize = 5
+# 连接只读数据库时配置为true, 保证安全
+readOnly = false
+
+[test]
+url = jdbc:mysql://192.168.100.32:3306/nbnetpump?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8
+username = root
+password = 123456
+## 可选配置
+# 是否在日志中显示执行的SQL
+showSql = true
+# 是否格式化显示的SQL
+formatSql = false
+# 是否显示SQL参数
+showParams = true
+# 打印SQL的日志等级,默认debug,可以是info、warn、error
+sqlLevel = debug
+# 自动提交
+autoCommit = true
+# 等待连接池分配连接的最大时长(毫秒),超过这个时长还没可用的连接则发生SQLException, 缺省:30秒
+connectionTimeout = 30000
+# 一个连接idle状态的最大时长(毫秒),超时则被释放(retired),缺省:10分钟
+idleTimeout = 600000
+# 一个连接的生命时长(毫秒),超时而且没被使用则被释放(retired),缺省:30分钟,建议设置比数据库超时时长少30秒,参考MySQL wait_timeout参数(show variables like '%timeout%';)
+maxLifetime = 1800000
+# 获取连接前的测试SQL
+connectionTestQuery = SELECT 1
+# 最小闲置连接数
+minimumIdle = 10
+# 连接池中允许的最大连接数。缺省值:10;推荐的公式:((core_count * 2) + effective_spindle_count)
+maximumPoolSize = 10
+# 连接只读数据库时配置为true, 保证安全
+readOnly = false
+
+[prod]
+url = jdbc:mysql://47.101.214.91:7001/nbnetpump?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8
+username = root
+password = Tuoren123.
+## 可选配置
+# 是否在日志中显示执行的SQL
+showSql = true
+# 是否格式化显示的SQL
+formatSql = false
+# 是否显示SQL参数
+showParams = true
+# 打印SQL的日志等级,默认debug,可以是info、warn、error
+sqlLevel = debug
+# 自动提交
+autoCommit = true
+# 等待连接池分配连接的最大时长(毫秒),超过这个时长还没可用的连接则发生SQLException, 缺省:30秒
+connectionTimeout = 30000
+# 一个连接idle状态的最大时长(毫秒),超时则被释放(retired),缺省:10分钟
+idleTimeout = 600000
+# 一个连接的生命时长(毫秒),超时而且没被使用则被释放(retired),缺省:30分钟,建议设置比数据库超时时长少30秒,参考MySQL wait_timeout参数(show variables like '%timeout%';)
+maxLifetime = 1800000
+# 获取连接前的测试SQL
+connectionTestQuery = SELECT 1
+# 最小闲置连接数
+minimumIdle = 1
+# 连接池中允许的最大连接数。缺省值:10;推荐的公式:((core_count * 2) + effective_spindle_count)
+maximumPoolSize = 3
+# 连接只读数据库时配置为true, 保证安全
+readOnly = false