Selaa lähdekoodia

添加清除当前登录人的消息通知接口

zhoupeng 2 vuotta sitten
vanhempi
commit
165ed26464

+ 12 - 1
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/controller/MessageNoticeController.java

@@ -86,7 +86,7 @@ public class MessageNoticeController {
      */
     @PostMapping("/deleteMessageNoticeById")
     @WebLog(ServerEnum = ServerEnum.CLIENT, ModelEnum = ModelEnum.MESSAGENOTICE, OperationEnum = OperationEnum.DELETE)
-    public Result deleteMessageNoticeById(Integer id) {
+    public Result deleteMessageNoticeById(@RequestParam("id") Integer id) {
         if (Blank.isEmpty(id)) {
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
         }
@@ -108,4 +108,15 @@ public class MessageNoticeController {
         return messageNoticeService.delMesNotByIdList(idList);
     }
 
+    /**
+     * 清楚当前登录人的所有消息通知
+     *
+     * @return
+     */
+    @PostMapping("/clearMessage")
+    @WebLog(ServerEnum = ServerEnum.CLIENT, ModelEnum = ModelEnum.MESSAGENOTICE, OperationEnum = OperationEnum.DELETE)
+    public Result clearMessage() {
+        return messageNoticeService.clearMessage();
+    }
+
 }

+ 2 - 0
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/dao/MessageNoticeDao.java

@@ -21,4 +21,6 @@ public interface MessageNoticeDao {
     MessageNotice getMessageNoticeById(Integer id);
 
     Integer delMesNotByIdList(List<Integer> idList);
+
+    Integer clearMessage(String userId);
 }

+ 2 - 0
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/service/MessageNoticeService.java

@@ -17,4 +17,6 @@ public interface MessageNoticeService {
     Result getMessageNoticeById(Integer id);
 
     Result delMesNotByIdList(List<Integer> idList);
+
+    Result clearMessage();
 }

+ 15 - 0
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/service/impl/ItemGroupServiceImpl.java

@@ -19,6 +19,7 @@ import com.example.opc_da.task.OpcDaTask;
 import com.example.opc_da.util.OpcDaUtil;
 import com.example.opc_da.util.RedisUtil;
 import com.example.opc_da.util.UserUtil;
+import org.openscada.opc.lib.da.Server;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.http.HttpEntity;
@@ -210,6 +211,20 @@ public class ItemGroupServiceImpl implements ItemGroupService {
                         clsId.equals(OpcDaDriverEnum.YOKOGAWA.getValue()) ||
                         clsId.equals(OpcDaDriverEnum.PAS300.getValue())
                 ) {
+                    Server server = null;
+                    try {
+                        server = OpcDaUtil.createServer(dataSource);
+                        if (Blank.isEmpty(server)) {
+                            return Result.no(ResultEnum.REQUEST_TIME_OUT.getRespCode(), "创建服务失败");
+                        }
+                        server.connect();
+                    } catch (Exception e) {
+                        throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), OpcDaUtil.genException(e.getMessage()));
+                    } finally {
+                        if (Blank.isNotEmpty(server)) {
+                            server.dispose();
+                        }
+                    }
                     redisUtil.set(ConstantStr.ITEM_GROUP + id, true);
                     //新增定时器任务
                     String cronId = "";

+ 12 - 0
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/service/impl/MessageNoticeServiceImpl.java

@@ -4,6 +4,7 @@ package com.example.opc_da.service.impl;
 import com.alibaba.fastjson.JSONObject;
 import com.example.opc_common.entity.MessageNotice;
 import com.example.opc_common.enums.ResultEnum;
+import com.example.opc_common.util.Blank;
 import com.example.opc_common.util.ConstantStr;
 import com.example.opc_common.util.Result;
 import com.example.opc_da.dao.MessageNoticeDao;
@@ -70,4 +71,15 @@ public class MessageNoticeServiceImpl implements MessageNoticeService {
         messageNoticeDao.delMesNotByIdList(idList);
         return Result.ok("删除成功");
     }
+
+    @Override
+    public Result clearMessage() {
+        String userId = userUtil.getCurrentUserId();
+        if (Blank.isNotEmpty(userId)) {
+            messageNoticeDao.clearMessage(userId);
+        } else {
+            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "登录信息过期,请重新登录");
+        }
+        return Result.ok("清除成功");
+    }
 }

+ 6 - 0
chaunyi_opc/opc_da/src/main/resources/mapper/MessageNoticeDao.xml

@@ -34,6 +34,12 @@
         </if>
     </delete>
 
+    <delete id="clearMessage">
+        delete
+        from t_message_notice
+        where user_id = #{userId}
+    </delete>
+
     <select id="getAllMessageNoticeCount" resultType="java.lang.Long">
         select count(*)
         from t_message_notice

+ 15 - 0
chaunyi_opc/opc_ua/src/main/java/com/example/opc_ua/service/impl/ItemGroupServiceImpl.java

@@ -19,6 +19,7 @@ import com.example.opc_ua.task.OpcAsyncTask;
 import com.example.opc_ua.task.OpcUaTask;
 import com.example.opc_ua.util.OpcUaUtil;
 import com.example.opc_ua.util.RedisUtil;
+import org.eclipse.milo.opcua.sdk.client.OpcUaClient;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -121,6 +122,20 @@ public class ItemGroupServiceImpl implements ItemGroupService {
                         throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "选择不匿名方式,需要填写帐户和密码");
                     }
                 }
+                OpcUaClient opcUaClient = null;
+                try {
+                    opcUaClient = OpcUaUtil.createClient(dataSource);
+                    if (Blank.isEmpty(opcUaClient)) {
+                        return Result.no(ResultEnum.REQUEST_TIME_OUT.getRespCode(), "客户端创建失败");
+                    }
+                    opcUaClient.connect().get();
+                } catch (Exception e) {
+                    throw new CustomException(ResultEnum.REQUEST_TIME_OUT.getRespCode(), OpcUaUtil.genException(e.getMessage()));
+                } finally {
+                    if (Blank.isNotEmpty(opcUaClient)) {
+                        opcUaClient.disconnect();
+                    }
+                }
                 redisUtil.set(ConstantStr.ITEM_GROUP + id, true);
                 //新增定时器任务
                 String cronId = "";