From e4d0c4cb3326c0a073ec9d263f2bbffe58463082 Mon Sep 17 00:00:00 2001
From: wty <419034340@qq.com>
Date: Wed, 30 Nov 2022 17:44:41 +0800
Subject: [PATCH 1/2] add qjdq data websocket
---
.idea/codeStyles/Project.xml | 25 +
.idea/codeStyles/codeStyleConfig.xml | 5 +
xiuosiot-backend/pom.xml | 6 +
.../java/com/aiit/xiuos/Utils/BeanUtil.java | 4 +
.../java/com/aiit/xiuos/Utils/CsvUtils.java | 31 ++
.../java/com/aiit/xiuos/Utils/DingUtil.java | 4 +
.../xiuos/dao/mappers/QjdqElectricMapper.java | 17 +
.../com/aiit/xiuos/model/QjdqElectric.java | 136 +++++
.../com/aiit/xiuos/redis/RedisConfig.java | 4 +
.../java/com/aiit/xiuos/redis/RedisUtil.java | 4 +
.../xiuos/service/QjdqElectricService.java | 8 +
.../service/impl/QjdqElectricServiceImpl.java | 22 +
.../xiuos/socket/QJDQWebSocketServer.java | 153 ++++++
.../resources/mappers/QjdqElectricMapper.xml | 509 ++++++++++++++++++
14 files changed, 928 insertions(+)
create mode 100644 .idea/codeStyles/Project.xml
create mode 100644 .idea/codeStyles/codeStyleConfig.xml
create mode 100644 xiuosiot-backend/src/main/java/com/aiit/xiuos/Utils/BeanUtil.java
create mode 100644 xiuosiot-backend/src/main/java/com/aiit/xiuos/Utils/CsvUtils.java
create mode 100644 xiuosiot-backend/src/main/java/com/aiit/xiuos/Utils/DingUtil.java
create mode 100644 xiuosiot-backend/src/main/java/com/aiit/xiuos/dao/mappers/QjdqElectricMapper.java
create mode 100644 xiuosiot-backend/src/main/java/com/aiit/xiuos/model/QjdqElectric.java
create mode 100644 xiuosiot-backend/src/main/java/com/aiit/xiuos/redis/RedisConfig.java
create mode 100644 xiuosiot-backend/src/main/java/com/aiit/xiuos/redis/RedisUtil.java
create mode 100644 xiuosiot-backend/src/main/java/com/aiit/xiuos/service/QjdqElectricService.java
create mode 100644 xiuosiot-backend/src/main/java/com/aiit/xiuos/service/impl/QjdqElectricServiceImpl.java
create mode 100644 xiuosiot-backend/src/main/java/com/aiit/xiuos/socket/QJDQWebSocketServer.java
create mode 100644 xiuosiot-backend/src/main/resources/mappers/QjdqElectricMapper.xml
diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
new file mode 100644
index 0000000..80eafa9
--- /dev/null
+++ b/.idea/codeStyles/Project.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml
new file mode 100644
index 0000000..a55e7a1
--- /dev/null
+++ b/.idea/codeStyles/codeStyleConfig.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/xiuosiot-backend/pom.xml b/xiuosiot-backend/pom.xml
index 8993e6e..f2abbee 100644
--- a/xiuosiot-backend/pom.xml
+++ b/xiuosiot-backend/pom.xml
@@ -113,6 +113,12 @@
spring-boot-starter-mail
+
+ org.apache.spark
+ spark-core_2.12
+ 3.3.1
+
+
diff --git a/xiuosiot-backend/src/main/java/com/aiit/xiuos/Utils/BeanUtil.java b/xiuosiot-backend/src/main/java/com/aiit/xiuos/Utils/BeanUtil.java
new file mode 100644
index 0000000..45405ed
--- /dev/null
+++ b/xiuosiot-backend/src/main/java/com/aiit/xiuos/Utils/BeanUtil.java
@@ -0,0 +1,4 @@
+package com.aiit.xiuos.Utils;
+
+public class BeanUtil {
+}
diff --git a/xiuosiot-backend/src/main/java/com/aiit/xiuos/Utils/CsvUtils.java b/xiuosiot-backend/src/main/java/com/aiit/xiuos/Utils/CsvUtils.java
new file mode 100644
index 0000000..8c4bc3c
--- /dev/null
+++ b/xiuosiot-backend/src/main/java/com/aiit/xiuos/Utils/CsvUtils.java
@@ -0,0 +1,31 @@
+package com.aiit.xiuos.Utils;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import lombok.extern.slf4j.Slf4j;
+
+import java.io.*;
+@Slf4j
+public class CsvUtils {
+ public static StringBuffer FinsJson2CSV(JSONArray jsonArray) {
+ StringBuffer stringBuffer=new StringBuffer();
+// "value_name": "启动",
+// "value_type": 1,
+// "area_char": "W",
+// "data_type": 0,
+// "start_address": 0,
+// "bit_address": 0,
+// "data_length": 1
+ for(int i=0;i webSocketSet = new ConcurrentHashMap();
+
+ public HashMap cntofParam=new HashMap();
+
+ public HashMap numofAccount=new HashMap();
+
+ /**
+ * 与某个客户端的连接会话,需要通过它来给客户端发送数据
+ */
+ private Session session;
+
+ /**
+ * 传过来的id
+ */
+ private String name = "";
+
+ /**
+ * 连接建立成功调用的方法*/
+ @OnOpen
+ public void onOpen(@PathParam(value = "clientId") String clientId, Session session) {
+ //接收到发送消息的人员编号
+ name = clientId;
+ this.session = session;
+ /**加入set中*/
+ webSocketSet.put(clientId,this);
+ /**在线数加1*/
+ addOnlineCount();
+ log.info("有新连接"+clientId+"加入!当前在线人数为" + getOnlineCount());
+ try {
+ sendMessage(clientId+"-连接已建立-");
+ } catch (IOException e) {
+ log.error("IO异常");
+ }
+ }
+
+ /**
+ * 连接关闭调用的方法
+ */
+ @OnClose
+ public void onClose() {
+ if (name != null && name != "") {
+ /** 从set中删除 */
+ webSocketSet.remove(name);
+ /** 在线数减1 */
+ subOnlineCount();
+ log.info("有一连接"+name+"关闭!当前在线人数为" + getOnlineCount());
+ }
+ }
+
+ /**
+ * 收到客户端消息后调用的方法
+ *
+ * @param message 客户端发送过来的消息*/
+ @OnMessage
+ public void onMessage(String message, Session session) {
+ log.info("来自客户端的消息:" + message);
+ try {
+ this.sendMessage("收到!");
+ } catch (IOException e) {
+ log.error(e.getMessage());
+ }
+ }
+
+ /**
+ * 发生错误时调用
+ * **/
+ @OnError
+ public void onError(Session session, Throwable error) {
+ log.error("发生错误");
+ error.printStackTrace();
+ }
+
+
+ public void sendMessage(String message) throws IOException {
+ synchronized (session) {
+ getSession().getBasicRemote().sendText(message);
+ }
+ }
+
+ /**
+ * 给指定的人发送消息
+ * @param message
+ */
+ public void sendToMessageById(String id,String message) {
+ try {
+ if (webSocketSet.get(id) != null) {
+ webSocketSet.get(id).sendMessage(message);
+ } else {
+ System.out.println("webSocketSet中没有此key,不推送消息");
+ log.info("webSocketSet中没有此key,不推送消息");
+ }
+ } catch (IOException e) {
+ log.error(e.getMessage());
+ }
+ }
+
+ /**
+ * 群发自定义消息
+ * */
+ public static void sendInfo(String message) {
+ try {
+ for (Map.Entry entry : webSocketSet.entrySet()) {
+ String name = entry.getKey();
+ log.info("发送信息至客户端:"+name);
+ QJDQWebSocketServer value = entry.getValue();
+ value.sendMessage(message);
+ }
+ }catch(IOException e){
+ log.error(e.getMessage());
+ }
+ }
+
+ public Session getSession() {
+ return session;
+ }
+
+ public static synchronized int getOnlineCount() {
+ return onlineCount;
+ }
+
+ public static synchronized void addOnlineCount() {
+ QJDQWebSocketServer.onlineCount++;
+ }
+
+ public static synchronized void subOnlineCount() {
+ QJDQWebSocketServer.onlineCount--;
+ }
+}
diff --git a/xiuosiot-backend/src/main/resources/mappers/QjdqElectricMapper.xml b/xiuosiot-backend/src/main/resources/mappers/QjdqElectricMapper.xml
new file mode 100644
index 0000000..ee8c46b
--- /dev/null
+++ b/xiuosiot-backend/src/main/resources/mappers/QjdqElectricMapper.xml
@@ -0,0 +1,509 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ id, electric2, electric3, electric4, electric5, electric6, electric7, electric8,
+ electric9, electric10, electric11, electric12, electric13, electric14, electric15,
+ electric16, electric17, electric18, electric19, electric20, electric21, electric22,
+ electric23, electric24, electric25, electric26, electric27, electric28, electric29,
+ electric30, electric31, electric32, electric33, electric34, electric35, electric36,
+ electric37, electric38, electric39, electric40
+
+
+
+ delete from qjdq_electric
+ where id = #{id,jdbcType=INTEGER}
+
+
+ insert into qjdq_electric (id, electric2, electric3,
+ electric4, electric5, electric6,
+ electric7, electric8, electric9,
+ electric10, electric11, electric12,
+ electric13, electric14, electric15,
+ electric16, electric17, electric18,
+ electric19, electric20, electric21,
+ electric22, electric23, electric24,
+ electric25, electric26, electric27,
+ electric28, electric29, electric30,
+ electric31, electric32, electric33,
+ electric34, electric35, electric36,
+ electric37, electric38, electric39,
+ electric40)
+ values (#{id,jdbcType=INTEGER}, #{electric2,jdbcType=NUMERIC}, #{electric3,jdbcType=NUMERIC},
+ #{electric4,jdbcType=NUMERIC}, #{electric5,jdbcType=NUMERIC}, #{electric6,jdbcType=NUMERIC},
+ #{electric7,jdbcType=NUMERIC}, #{electric8,jdbcType=NUMERIC}, #{electric9,jdbcType=NUMERIC},
+ #{electric10,jdbcType=NUMERIC}, #{electric11,jdbcType=NUMERIC}, #{electric12,jdbcType=NUMERIC},
+ #{electric13,jdbcType=NUMERIC}, #{electric14,jdbcType=NUMERIC}, #{electric15,jdbcType=NUMERIC},
+ #{electric16,jdbcType=NUMERIC}, #{electric17,jdbcType=NUMERIC}, #{electric18,jdbcType=NUMERIC},
+ #{electric19,jdbcType=NUMERIC}, #{electric20,jdbcType=NUMERIC}, #{electric21,jdbcType=NUMERIC},
+ #{electric22,jdbcType=NUMERIC}, #{electric23,jdbcType=NUMERIC}, #{electric24,jdbcType=NUMERIC},
+ #{electric25,jdbcType=NUMERIC}, #{electric26,jdbcType=NUMERIC}, #{electric27,jdbcType=NUMERIC},
+ #{electric28,jdbcType=NUMERIC}, #{electric29,jdbcType=NUMERIC}, #{electric30,jdbcType=NUMERIC},
+ #{electric31,jdbcType=NUMERIC}, #{electric32,jdbcType=NUMERIC}, #{electric33,jdbcType=NUMERIC},
+ #{electric34,jdbcType=NUMERIC}, #{electric35,jdbcType=NUMERIC}, #{electric36,jdbcType=NUMERIC},
+ #{electric37,jdbcType=NUMERIC}, #{electric38,jdbcType=NUMERIC}, #{electric39,jdbcType=NUMERIC},
+ #{electric40,jdbcType=NUMERIC})
+
+
+ insert into qjdq_electric
+
+
+ id,
+
+
+ electric2,
+
+
+ electric3,
+
+
+ electric4,
+
+
+ electric5,
+
+
+ electric6,
+
+
+ electric7,
+
+
+ electric8,
+
+
+ electric9,
+
+
+ electric10,
+
+
+ electric11,
+
+
+ electric12,
+
+
+ electric13,
+
+
+ electric14,
+
+
+ electric15,
+
+
+ electric16,
+
+
+ electric17,
+
+
+ electric18,
+
+
+ electric19,
+
+
+ electric20,
+
+
+ electric21,
+
+
+ electric22,
+
+
+ electric23,
+
+
+ electric24,
+
+
+ electric25,
+
+
+ electric26,
+
+
+ electric27,
+
+
+ electric28,
+
+
+ electric29,
+
+
+ electric30,
+
+
+ electric31,
+
+
+ electric32,
+
+
+ electric33,
+
+
+ electric34,
+
+
+ electric35,
+
+
+ electric36,
+
+
+ electric37,
+
+
+ electric38,
+
+
+ electric39,
+
+
+ electric40,
+
+
+
+
+ #{id,jdbcType=INTEGER},
+
+
+ #{electric2,jdbcType=NUMERIC},
+
+
+ #{electric3,jdbcType=NUMERIC},
+
+
+ #{electric4,jdbcType=NUMERIC},
+
+
+ #{electric5,jdbcType=NUMERIC},
+
+
+ #{electric6,jdbcType=NUMERIC},
+
+
+ #{electric7,jdbcType=NUMERIC},
+
+
+ #{electric8,jdbcType=NUMERIC},
+
+
+ #{electric9,jdbcType=NUMERIC},
+
+
+ #{electric10,jdbcType=NUMERIC},
+
+
+ #{electric11,jdbcType=NUMERIC},
+
+
+ #{electric12,jdbcType=NUMERIC},
+
+
+ #{electric13,jdbcType=NUMERIC},
+
+
+ #{electric14,jdbcType=NUMERIC},
+
+
+ #{electric15,jdbcType=NUMERIC},
+
+
+ #{electric16,jdbcType=NUMERIC},
+
+
+ #{electric17,jdbcType=NUMERIC},
+
+
+ #{electric18,jdbcType=NUMERIC},
+
+
+ #{electric19,jdbcType=NUMERIC},
+
+
+ #{electric20,jdbcType=NUMERIC},
+
+
+ #{electric21,jdbcType=NUMERIC},
+
+
+ #{electric22,jdbcType=NUMERIC},
+
+
+ #{electric23,jdbcType=NUMERIC},
+
+
+ #{electric24,jdbcType=NUMERIC},
+
+
+ #{electric25,jdbcType=NUMERIC},
+
+
+ #{electric26,jdbcType=NUMERIC},
+
+
+ #{electric27,jdbcType=NUMERIC},
+
+
+ #{electric28,jdbcType=NUMERIC},
+
+
+ #{electric29,jdbcType=NUMERIC},
+
+
+ #{electric30,jdbcType=NUMERIC},
+
+
+ #{electric31,jdbcType=NUMERIC},
+
+
+ #{electric32,jdbcType=NUMERIC},
+
+
+ #{electric33,jdbcType=NUMERIC},
+
+
+ #{electric34,jdbcType=NUMERIC},
+
+
+ #{electric35,jdbcType=NUMERIC},
+
+
+ #{electric36,jdbcType=NUMERIC},
+
+
+ #{electric37,jdbcType=NUMERIC},
+
+
+ #{electric38,jdbcType=NUMERIC},
+
+
+ #{electric39,jdbcType=NUMERIC},
+
+
+ #{electric40,jdbcType=NUMERIC},
+
+
+
+
+ update qjdq_electric
+
+
+ electric2 = #{electric2,jdbcType=NUMERIC},
+
+
+ electric3 = #{electric3,jdbcType=NUMERIC},
+
+
+ electric4 = #{electric4,jdbcType=NUMERIC},
+
+
+ electric5 = #{electric5,jdbcType=NUMERIC},
+
+
+ electric6 = #{electric6,jdbcType=NUMERIC},
+
+
+ electric7 = #{electric7,jdbcType=NUMERIC},
+
+
+ electric8 = #{electric8,jdbcType=NUMERIC},
+
+
+ electric9 = #{electric9,jdbcType=NUMERIC},
+
+
+ electric10 = #{electric10,jdbcType=NUMERIC},
+
+
+ electric11 = #{electric11,jdbcType=NUMERIC},
+
+
+ electric12 = #{electric12,jdbcType=NUMERIC},
+
+
+ electric13 = #{electric13,jdbcType=NUMERIC},
+
+
+ electric14 = #{electric14,jdbcType=NUMERIC},
+
+
+ electric15 = #{electric15,jdbcType=NUMERIC},
+
+
+ electric16 = #{electric16,jdbcType=NUMERIC},
+
+
+ electric17 = #{electric17,jdbcType=NUMERIC},
+
+
+ electric18 = #{electric18,jdbcType=NUMERIC},
+
+
+ electric19 = #{electric19,jdbcType=NUMERIC},
+
+
+ electric20 = #{electric20,jdbcType=NUMERIC},
+
+
+ electric21 = #{electric21,jdbcType=NUMERIC},
+
+
+ electric22 = #{electric22,jdbcType=NUMERIC},
+
+
+ electric23 = #{electric23,jdbcType=NUMERIC},
+
+
+ electric24 = #{electric24,jdbcType=NUMERIC},
+
+
+ electric25 = #{electric25,jdbcType=NUMERIC},
+
+
+ electric26 = #{electric26,jdbcType=NUMERIC},
+
+
+ electric27 = #{electric27,jdbcType=NUMERIC},
+
+
+ electric28 = #{electric28,jdbcType=NUMERIC},
+
+
+ electric29 = #{electric29,jdbcType=NUMERIC},
+
+
+ electric30 = #{electric30,jdbcType=NUMERIC},
+
+
+ electric31 = #{electric31,jdbcType=NUMERIC},
+
+
+ electric32 = #{electric32,jdbcType=NUMERIC},
+
+
+ electric33 = #{electric33,jdbcType=NUMERIC},
+
+
+ electric34 = #{electric34,jdbcType=NUMERIC},
+
+
+ electric35 = #{electric35,jdbcType=NUMERIC},
+
+
+ electric36 = #{electric36,jdbcType=NUMERIC},
+
+
+ electric37 = #{electric37,jdbcType=NUMERIC},
+
+
+ electric38 = #{electric38,jdbcType=NUMERIC},
+
+
+ electric39 = #{electric39,jdbcType=NUMERIC},
+
+
+ electric40 = #{electric40,jdbcType=NUMERIC},
+
+
+ where id = #{id,jdbcType=INTEGER}
+
+
+ update qjdq_electric
+ set electric2 = #{electric2,jdbcType=NUMERIC},
+ electric3 = #{electric3,jdbcType=NUMERIC},
+ electric4 = #{electric4,jdbcType=NUMERIC},
+ electric5 = #{electric5,jdbcType=NUMERIC},
+ electric6 = #{electric6,jdbcType=NUMERIC},
+ electric7 = #{electric7,jdbcType=NUMERIC},
+ electric8 = #{electric8,jdbcType=NUMERIC},
+ electric9 = #{electric9,jdbcType=NUMERIC},
+ electric10 = #{electric10,jdbcType=NUMERIC},
+ electric11 = #{electric11,jdbcType=NUMERIC},
+ electric12 = #{electric12,jdbcType=NUMERIC},
+ electric13 = #{electric13,jdbcType=NUMERIC},
+ electric14 = #{electric14,jdbcType=NUMERIC},
+ electric15 = #{electric15,jdbcType=NUMERIC},
+ electric16 = #{electric16,jdbcType=NUMERIC},
+ electric17 = #{electric17,jdbcType=NUMERIC},
+ electric18 = #{electric18,jdbcType=NUMERIC},
+ electric19 = #{electric19,jdbcType=NUMERIC},
+ electric20 = #{electric20,jdbcType=NUMERIC},
+ electric21 = #{electric21,jdbcType=NUMERIC},
+ electric22 = #{electric22,jdbcType=NUMERIC},
+ electric23 = #{electric23,jdbcType=NUMERIC},
+ electric24 = #{electric24,jdbcType=NUMERIC},
+ electric25 = #{electric25,jdbcType=NUMERIC},
+ electric26 = #{electric26,jdbcType=NUMERIC},
+ electric27 = #{electric27,jdbcType=NUMERIC},
+ electric28 = #{electric28,jdbcType=NUMERIC},
+ electric29 = #{electric29,jdbcType=NUMERIC},
+ electric30 = #{electric30,jdbcType=NUMERIC},
+ electric31 = #{electric31,jdbcType=NUMERIC},
+ electric32 = #{electric32,jdbcType=NUMERIC},
+ electric33 = #{electric33,jdbcType=NUMERIC},
+ electric34 = #{electric34,jdbcType=NUMERIC},
+ electric35 = #{electric35,jdbcType=NUMERIC},
+ electric36 = #{electric36,jdbcType=NUMERIC},
+ electric37 = #{electric37,jdbcType=NUMERIC},
+ electric38 = #{electric38,jdbcType=NUMERIC},
+ electric39 = #{electric39,jdbcType=NUMERIC},
+ electric40 = #{electric40,jdbcType=NUMERIC}
+ where id = #{id,jdbcType=INTEGER}
+
+
\ No newline at end of file
From 71f0c69ef0c5b259d3536283bce37c7ffc1e3338 Mon Sep 17 00:00:00 2001
From: wty <419034340@qq.com>
Date: Wed, 30 Nov 2022 17:46:07 +0800
Subject: [PATCH 2/2] add log for xiuosiot
---
.../xiuos/Interceptor/AroundLogAspect.java | 24 ++-
.../java/com/aiit/xiuos/Utils/EmailUtil.java | 6 +-
.../com/aiit/xiuos/Utils/HttpClientUtil.java | 97 ++++-----
.../xiuos/controller/LoginController.java | 7 +-
.../ProtocolProductInfoController.java | 7 +-
.../xiuos/dao/mappers/QjdqElectricMapper.java | 2 +
.../xiuos/model/VO/ProtocolProductVo.java | 7 +-
.../com/aiit/xiuos/redis/RedisConfig.java | 71 ++++++-
.../java/com/aiit/xiuos/redis/RedisUtil.java | 187 ++++++++++++++++++
.../aiit/xiuos/scheduled/TaskScheduled.java | 156 ++++++++++++---
.../service/impl/AlarmInfoServiceImpl.java | 5 +
.../aiit/xiuos/socket/WebSocketServer.java | 12 +-
.../src/main/resources/application-local.yml | 4 +-
13 files changed, 482 insertions(+), 103 deletions(-)
diff --git a/xiuosiot-backend/src/main/java/com/aiit/xiuos/Interceptor/AroundLogAspect.java b/xiuosiot-backend/src/main/java/com/aiit/xiuos/Interceptor/AroundLogAspect.java
index 045494f..81a1591 100644
--- a/xiuosiot-backend/src/main/java/com/aiit/xiuos/Interceptor/AroundLogAspect.java
+++ b/xiuosiot-backend/src/main/java/com/aiit/xiuos/Interceptor/AroundLogAspect.java
@@ -17,7 +17,6 @@ import org.springframework.stereotype.Component;
import org.springframework.util.StopWatch;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
-
import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
@@ -37,10 +36,18 @@ public class AroundLogAspect {
public void normalPointcut() {
}
@Pointcut("execution(* com.aiit.xiuos.controller.LoginController.*(..))")
- public void excludePointcut() {
+ public void excludeLogPointcut() {
}
- @Pointcut("normalPointcut() && !excludePointcut()")
+ @Pointcut("execution(* com.aiit.xiuos.controller.UserController.*(..))")
+ public void excludeUserPointcut() {
+ }
+
+ @Pointcut("execution(* com.aiit.xiuos.controller.ExcludeController.*(..))")
+ public void excludeController() {
+ }
+
+ @Pointcut("normalPointcut() && !excludeUserPointcut()&& !excludeLogPointcut()&&!excludeController()")
public void pointCutMethod() {
}
@@ -87,25 +94,26 @@ public class AroundLogAspect {
requestLogInfo.setMethodname(methodName);
//参数名
Parameter[] parameters = method.getParameters();
-
- requestLogInfo.setRequestparam(parameters[0].getName());
+ String param ="";
+ for(int i=0;i list = JSONObject.parseArray(response, Result.class);
- System.out.println(response);
- }
diff --git a/xiuosiot-backend/src/main/java/com/aiit/xiuos/controller/LoginController.java b/xiuosiot-backend/src/main/java/com/aiit/xiuos/controller/LoginController.java
index 0acf340..e7083b6 100644
--- a/xiuosiot-backend/src/main/java/com/aiit/xiuos/controller/LoginController.java
+++ b/xiuosiot-backend/src/main/java/com/aiit/xiuos/controller/LoginController.java
@@ -5,6 +5,7 @@ import com.aiit.xiuos.Utils.MyUtils;
import com.aiit.xiuos.Utils.ResultRespons;
import com.aiit.xiuos.model.UserInfo;
import com.aiit.xiuos.service.UserInfoService;
+import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
@@ -13,7 +14,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
@RestController
-
+@Slf4j
public class LoginController {
@Autowired
private UserInfoService userInfoService;
@@ -24,10 +25,10 @@ public class LoginController {
if(null!=user){
HttpSession session = request.getSession();
session.setAttribute("user",user);//session存用户
- System.out.println("session======="+session.getId());
+ log.info("session======="+session.getId());
String ip = MyUtils.getIp(request);
userInfoService.updateLoginInfo(MyUtils.getTime(),ip,user.getId());
- System.out.println("ip++++++++===="+ip);
+ log.info("ip++++++++===="+ip);
return new ResultRespons(Constant.SUCCESS_CODE,"登录成功");
}
return new ResultRespons(Constant.ERROR_CODE,"登录失败,用户名或密码有误");
diff --git a/xiuosiot-backend/src/main/java/com/aiit/xiuos/controller/ProtocolProductInfoController.java b/xiuosiot-backend/src/main/java/com/aiit/xiuos/controller/ProtocolProductInfoController.java
index 8a8eb34..1ed7bfd 100644
--- a/xiuosiot-backend/src/main/java/com/aiit/xiuos/controller/ProtocolProductInfoController.java
+++ b/xiuosiot-backend/src/main/java/com/aiit/xiuos/controller/ProtocolProductInfoController.java
@@ -8,11 +8,10 @@ import com.aiit.xiuos.model.VO.ProtocolProductVo;
import com.aiit.xiuos.service.DeviceInfoService;
import com.aiit.xiuos.service.ProtocolService;
import com.alibaba.fastjson.JSONArray;
-import com.alibaba.fastjson.JSONObject;
+import lombok.extern.slf4j.Slf4j;
import org.apache.tomcat.util.http.fileupload.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
-import sun.nio.ch.IOUtil;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -22,7 +21,7 @@ import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
-
+@Slf4j
@RestController
@RequestMapping("/protocolProduct")
public class ProtocolProductInfoController {
@@ -116,7 +115,7 @@ public class ProtocolProductInfoController {
outputStream.close();
} catch (IOException e) {
- e.printStackTrace();
+ log.error(e.getMessage());
}
return new ResultRespons(Constant.ERROR_CODE, "导出csv成功!");
}
diff --git a/xiuosiot-backend/src/main/java/com/aiit/xiuos/dao/mappers/QjdqElectricMapper.java b/xiuosiot-backend/src/main/java/com/aiit/xiuos/dao/mappers/QjdqElectricMapper.java
index c0d5741..a0dca2a 100644
--- a/xiuosiot-backend/src/main/java/com/aiit/xiuos/dao/mappers/QjdqElectricMapper.java
+++ b/xiuosiot-backend/src/main/java/com/aiit/xiuos/dao/mappers/QjdqElectricMapper.java
@@ -1,7 +1,9 @@
package com.aiit.xiuos.dao.mappers;
import com.aiit.xiuos.model.QjdqElectric;
+import org.springframework.stereotype.Repository;
+@Repository
public interface QjdqElectricMapper {
int deleteByPrimaryKey(Integer id);
diff --git a/xiuosiot-backend/src/main/java/com/aiit/xiuos/model/VO/ProtocolProductVo.java b/xiuosiot-backend/src/main/java/com/aiit/xiuos/model/VO/ProtocolProductVo.java
index 9afacac..bbe2434 100644
--- a/xiuosiot-backend/src/main/java/com/aiit/xiuos/model/VO/ProtocolProductVo.java
+++ b/xiuosiot-backend/src/main/java/com/aiit/xiuos/model/VO/ProtocolProductVo.java
@@ -28,8 +28,9 @@ public class ProtocolProductVo {
private JSONObject socketConfig;
private String readPeriod;
+ private String org;
- public ProtocolProductVo(String productName, String protocolType, JSONArray readItemList, Date updatetime, String deviceId, String deviceName, JSONObject socketConfig, String readPeriod) {
+ public ProtocolProductVo(String productName, String protocolType, JSONArray readItemList, Date updatetime, String deviceId, String deviceName, JSONObject socketConfig, String readPeriod,String org) {
this.productName = productName;
this.protocolType = protocolType;
this.readItemList = readItemList;
@@ -38,6 +39,7 @@ public class ProtocolProductVo {
this.deviceName = deviceName;
this.socketConfig = socketConfig;
this.readPeriod = readPeriod;
+ this.org =org;
}
public ProtocolProductVo(){
@@ -54,6 +56,7 @@ public class ProtocolProductVo {
protocolProductInfo.setSocketConfig(protocolProductVo.getSocketConfig().toJSONString());
protocolProductInfo.setReadPeriod(protocolProductVo.getReadPeriod());
protocolProductInfo.setUpdatetime(MyUtils.getDateTime());
+ protocolProductInfo.setOrg(protocolProductVo.getOrg());
return protocolProductInfo;
}
@@ -67,7 +70,7 @@ public class ProtocolProductVo {
protocolProductVo.setUpdatetime(protocolProductInfo.getUpdatetime());
protocolProductVo.setSocketConfig((JSONObject) JSONObject.parse(protocolProductInfo.getSocketConfig()));
protocolProductVo.setReadItemList((JSONArray)JSONArray.parse(protocolProductInfo.getReadItemList()));
-
+ protocolProductVo.setOrg(protocolProductInfo.getOrg());
return protocolProductVo;
}
diff --git a/xiuosiot-backend/src/main/java/com/aiit/xiuos/redis/RedisConfig.java b/xiuosiot-backend/src/main/java/com/aiit/xiuos/redis/RedisConfig.java
index 63fd33c..e419fa3 100644
--- a/xiuosiot-backend/src/main/java/com/aiit/xiuos/redis/RedisConfig.java
+++ b/xiuosiot-backend/src/main/java/com/aiit/xiuos/redis/RedisConfig.java
@@ -1,4 +1,73 @@
package com.aiit.xiuos.redis;
+import com.fasterxml.jackson.annotation.JsonAutoDetect;
+import com.fasterxml.jackson.annotation.PropertyAccessor;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.data.redis.connection.RedisConnectionFactory;
+import org.springframework.data.redis.core.*;
+import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
+import org.springframework.data.redis.serializer.StringRedisSerializer;
-public class RedisConfig {
+
+/**
+ * Redis配置
+ */
+@Configuration
+public class RedisConfig {
+
+ @Autowired
+ private RedisConnectionFactory factory;
+
+
+ @Bean
+ public RedisTemplate redisTemplate() {
+ // 创建一个模板类
+ RedisTemplate redisTemplate = new RedisTemplate<>();
+ // 设置key的序列化器
+ redisTemplate.setKeySerializer(new StringRedisSerializer());
+ redisTemplate.setHashKeySerializer(new StringRedisSerializer());
+ redisTemplate.setHashValueSerializer(new StringRedisSerializer());
+ // 设置value的序列化器
+ //使用Jackson2JsonRedisSerializer来序列化和反序列化redis的value值(默认使用JDK的序列化方式)
+ Jackson2JsonRedisSerializer jacksonSeial = new Jackson2JsonRedisSerializer(Object.class);
+ ObjectMapper om = new ObjectMapper();
+ // 指定要序列化的域,field,get和set,以及修饰符范围,ANY是都有包括private和public
+ om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
+ // 指定序列化输入的类型,类必须是非final修饰的,final修饰的类,比如String,Integer等会跑出异常
+ om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
+ jacksonSeial.setObjectMapper(om);
+
+ redisTemplate.setValueSerializer(jacksonSeial);
+ // 将刚才的redis连接工厂设置到模板类中
+ //spring默认帮我们读取application.properties文件并且注册了一个factorybean
+ redisTemplate.setConnectionFactory(factory);
+ return redisTemplate;
+ }
+
+ @Bean
+ public HashOperations hashOperations(RedisTemplate redisTemplate) {
+ return redisTemplate.opsForHash();
+ }
+
+ @Bean
+ public ValueOperations valueOperations(RedisTemplate redisTemplate) {
+ return redisTemplate.opsForValue();
+ }
+
+ @Bean
+ public ListOperations listOperations(RedisTemplate redisTemplate) {
+ return redisTemplate.opsForList();
+ }
+
+ @Bean
+ public SetOperations setOperations(RedisTemplate redisTemplate) {
+ return redisTemplate.opsForSet();
+ }
+
+ @Bean
+ public ZSetOperations zSetOperations(RedisTemplate redisTemplate) {
+ return redisTemplate.opsForZSet();
+ }
}
diff --git a/xiuosiot-backend/src/main/java/com/aiit/xiuos/redis/RedisUtil.java b/xiuosiot-backend/src/main/java/com/aiit/xiuos/redis/RedisUtil.java
index 4415920..9108231 100644
--- a/xiuosiot-backend/src/main/java/com/aiit/xiuos/redis/RedisUtil.java
+++ b/xiuosiot-backend/src/main/java/com/aiit/xiuos/redis/RedisUtil.java
@@ -1,4 +1,191 @@
package com.aiit.xiuos.redis;
+import com.alibaba.fastjson.JSON;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.*;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+
+@Component
public class RedisUtil {
+ @Autowired
+ private RedisTemplate redisTemplate;
+ @Resource(name="redisTemplate")
+ private ValueOperations valueOperations;
+ @Resource(name="redisTemplate")
+ private HashOperations hashOperations;
+ @Resource(name="redisTemplate")
+ private ListOperations listOperations;
+ @Resource(name="redisTemplate")
+ private SetOperations setOperations;
+ @Resource(name="redisTemplate")
+ private ZSetOperations zSetOperations;
+ /** 默认过期时长,单位:秒 */
+ public final static long DEFAULT_EXPIRE = 60 * 60 * 24;
+ /** 不设置过期时长 */
+ public final static long NOT_EXPIRE = -1;
+
+ public void set(String key, Object value, long expire){
+ valueOperations.set(key, toJson(value));
+ if(expire != NOT_EXPIRE){
+ redisTemplate.expire(key, expire, TimeUnit.SECONDS);
+ }
+ }
+
+ public void set(String key, Object value){
+ set(key, value, DEFAULT_EXPIRE);
+ }
+
+ public T get(String key, Class clazz, long expire) {
+ String value = valueOperations.get(key);
+ if(expire != NOT_EXPIRE){
+ redisTemplate.expire(key, expire, TimeUnit.SECONDS);
+ }
+ return value == null ? null : fromJson(value, clazz);
+ }
+
+ public T get(String key, Class clazz) {
+ return get(key, clazz, NOT_EXPIRE);
+ }
+
+ public String get(String key, long expire) {
+ String value = valueOperations.get(key);
+ if(expire != NOT_EXPIRE){
+ redisTemplate.expire(key, expire, TimeUnit.SECONDS);
+ }
+ return value;
+ }
+
+ public String get(String key) {
+ return get(key, NOT_EXPIRE);
+ }
+
+ public void delete(String key) {
+ redisTemplate.delete(key);
+ }
+
+ /**
+ * Object转成JSON数据
+ */
+ private String toJson(Object object){
+ if(object instanceof Integer || object instanceof Long || object instanceof Float ||
+ object instanceof Double || object instanceof Boolean || object instanceof String){
+ return String.valueOf(object);
+ }
+ return JSON.toJSONString(object);
+ }
+
+ /**
+ * JSON数据,转成Object
+ */
+ private T fromJson(String json, Class clazz){
+ return JSON.parseObject(json, clazz);
+ }
+
+
+ /**
+ * listOperations使用
+ */
+ public void lset(String key, List