Browse Source

Merge branch 'master' of http://116.63.33.55/git/read_opc

FinalYu 2 năm trước cách đây
mục cha
commit
bc7e5e66db
21 tập tin đã thay đổi với 142 bổ sung36 xóa
  1. 26 0
      chaunyi_opc/opc_da/src/main/java/com/example/opc_da/config/InitRunner.java
  2. 12 1
      chaunyi_opc/opc_da/src/main/java/com/example/opc_da/controller/MessageNoticeController.java
  3. 2 0
      chaunyi_opc/opc_da/src/main/java/com/example/opc_da/dao/MessageNoticeDao.java
  4. 4 0
      chaunyi_opc/opc_da/src/main/java/com/example/opc_da/dao/RawDataDao.java
  5. 2 0
      chaunyi_opc/opc_da/src/main/java/com/example/opc_da/service/MessageNoticeService.java
  6. 19 16
      chaunyi_opc/opc_da/src/main/java/com/example/opc_da/service/impl/ItemGroupServiceImpl.java
  7. 12 0
      chaunyi_opc/opc_da/src/main/java/com/example/opc_da/service/impl/MessageNoticeServiceImpl.java
  8. 0 1
      chaunyi_opc/opc_da/src/main/java/com/example/opc_da/util/OpcDaUtil.java
  9. 1 1
      chaunyi_opc/opc_da/src/main/resources/application-dev.yml
  10. 2 2
      chaunyi_opc/opc_da/src/main/resources/application-prod.yml
  11. 1 1
      chaunyi_opc/opc_da/src/main/resources/application.yml
  12. 0 1
      chaunyi_opc/opc_da/src/main/resources/mapper/ItemGroupDao.xml
  13. 6 0
      chaunyi_opc/opc_da/src/main/resources/mapper/MessageNoticeDao.xml
  14. 14 1
      chaunyi_opc/opc_da/src/main/resources/mapper/RawDataDao.xml
  15. 15 0
      chaunyi_opc/opc_ua/src/main/java/com/example/opc_ua/service/impl/ItemGroupServiceImpl.java
  16. 2 2
      chaunyi_opc/opc_ua/src/main/resources/application-dev.yml
  17. 2 2
      chaunyi_opc/opc_ua/src/main/resources/application-prod.yml
  18. 1 1
      chaunyi_opc/opc_ua/src/main/resources/mapper/ItemGroupDao.xml
  19. 1 1
      chaunyi_opc/opc_ua/src/main/resources/mapper/RawDataDao.xml
  20. 14 1
      chuanyi-admin/src/views/dashboard/index.vue
  21. 6 5
      chuanyi-admin/src/views/dashboard/onlineUsers.vue

+ 26 - 0
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/config/InitRunner.java

@@ -1,9 +1,13 @@
 package com.example.opc_da.config;
 
 import com.example.opc_common.entity.DataSource;
+import com.example.opc_common.entity.Item;
+import com.example.opc_common.entity.ItemGroup;
 import com.example.opc_common.enums.DataSourceTypeEnum;
 import com.example.opc_common.util.Blank;
 import com.example.opc_da.dao.DataSourceDao;
+import com.example.opc_da.dao.ItemGroupDao;
+import com.example.opc_da.dao.RawDataDao;
 import com.example.opc_da.task.OpcAsyncTask;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -20,9 +24,15 @@ import java.util.List;
 public class InitRunner {
 
     @Autowired
+    private ItemGroupDao itemGroupDao;
+
+    @Autowired
     private DataSourceDao dataSourceDao;
 
     @Autowired
+    private RawDataDao rawDataDao;
+
+    @Autowired
     private OpcAsyncTask opcAsyncTask;
 
     @PostConstruct
@@ -42,5 +52,21 @@ public class InitRunner {
                 }
             }
         }
+
+        //组装系统挂了没有组装的数据
+        List<Integer> itemGroupIdList = rawDataDao.getRawDataGroupIdList();
+        if (Blank.isNotEmpty(itemGroupIdList)) {
+            for (Integer itemGroupId : itemGroupIdList) {
+                List<String> belongTimeList = rawDataDao.getRawDataBelongTime(itemGroupId);
+                if (Blank.isNotEmpty(belongTimeList)) {
+                    for (int i = 0; i < belongTimeList.size(); i++) {
+                        List<Item> itemList = itemGroupDao.getItemListByGroupId(itemGroupId);
+                        ItemGroup itemGroup = itemGroupDao.getItemGroupById(itemGroupId);
+                        Integer dataSourceId = itemGroup.getDataSourceId();
+                        opcAsyncTask.packageRawDataList(itemList, dataSourceId, belongTimeList.get(i));
+                    }
+                }
+            }
+        }
     }
 }

+ 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);
 }

+ 4 - 0
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/dao/RawDataDao.java

@@ -36,4 +36,8 @@ public interface RawDataDao {
     Integer updateRawData(Integer remainder, RawData rawData);
 
     List<Long> getMeetIndexList(Integer itemGroupId, Integer dataSourceId, List<Item> itemList, String valueBelongTime, Integer notMeetChange);
+
+    List<Integer> getRawDataGroupIdList();
+
+    List<String> getRawDataBelongTime(Integer itemGroupId);
 }

+ 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();
 }

+ 19 - 16
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;
@@ -125,18 +126,18 @@ public class ItemGroupServiceImpl implements ItemGroupService {
             }
             itemGroupDao.delItemByGroupId(id);
             if (Blank.isNotEmpty(itemGroup.getItemList())) {
-                List<Item> itemList = itemGroup.getItemList();
                 if (dataSourceType.getDataSourceTypeKey().equals(DataSourceTypeEnum.OPC_DA_REAL.getValue())) {
-                    itemGroup.setItemList(OpcDaUtil.genReadNameDa(dataSource, itemList));
+                    itemGroup.setItemList(OpcDaUtil.genReadNameDa(dataSource, itemGroup.getItemList()));
                 }
+                List<Item> itemList = itemGroup.getItemList();
                 int count = 0;
                 for (Item item : itemList) {
                     if (Blank.isNotEmpty(item.getTableReportId())) {
-                        count += 1;
+                        count++;
                     }
                 }
                 if (count > 1) {
-                    return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "一个数据组中,最多只能配置一个事件驱动报表");
+                    throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "一个数据组中,最多只能配置一个事件驱动报表");
                 }
                 itemGroupDao.addItem(id, itemList);
             }
@@ -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 = "";
@@ -321,18 +336,6 @@ public class ItemGroupServiceImpl implements ItemGroupService {
         if (itemGroup.getRunState() == ConstantStr.START_UP) {
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "此数据组现在处于运行中,不允许修改");
         }
-        if (Blank.isNotEmpty(item.getTableReportId())) {
-            List<Item> itemList = itemGroupDao.getItemListByGroupId(itemGroup.getId());
-            if (Blank.isNotEmpty(itemList)) {
-                for (Item item2 : itemList) {
-                    if (Blank.isNotEmpty(item2.getTableReportId())) {
-                        if (!item2.getId().equals(item.getId())) {
-                            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "此数据组中有其他项配置了事件驱动报表,修改失败");
-                        }
-                    }
-                }
-            }
-        }
         if (itemGroupDao.updateItem(item) <= 0) {
             return Result.no(ResultEnum.SERVER_ERROR.getRespCode(), "修改item失败");
         }

+ 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("清除成功");
+    }
 }

+ 0 - 1
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/util/OpcDaUtil.java

@@ -297,7 +297,6 @@ public class OpcDaUtil {
             }
         } else if (dataSource.getClsId().toUpperCase().equals(OpcDaDriverEnum.YOKOGAWA.getValue())) {
             for (int i = 0; i < itemList.size(); i++) {
-                int n = itemList.get(i).getItemName().indexOf(".");
                 itemList.get(i).setItemReadName(itemList.get(i).getItemName().replaceFirst("\\.", "!"));
             }
         } else if (dataSource.getClsId().toUpperCase().equals(OpcDaDriverEnum.OPCIFIX.getValue())) {

+ 1 - 1
chaunyi_opc/opc_da/src/main/resources/application-dev.yml

@@ -10,7 +10,7 @@ spring:
       max-request-size: 500MB
   datasource:
     driver-class-name: com.mysql.cj.jdbc.Driver
-    url: jdbc:mysql://localhost:3306/chuanyi?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&serverTimezone=GMT%2B8
+    url: jdbc:mysql://localhost:3306/ei_rptdb?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&serverTimezone=GMT%2B8
     username: root
     password: root
   resources:

+ 2 - 2
chaunyi_opc/opc_da/src/main/resources/application-prod.yml

@@ -10,7 +10,7 @@ spring:
       max-request-size: 500MB
   datasource:
     driver-class-name: com.mysql.cj.jdbc.Driver
-    url: jdbc:mysql://localhost:3306/chuanyi?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&serverTimezone=GMT%2B8
+    url: jdbc:mysql://localhost:3306/ei_rptdb?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&serverTimezone=GMT%2B8
     username: root
     password: root
   resources:
@@ -30,4 +30,4 @@ spring:
 #mybatis:
 #  configuration:
     #开启sql日志文件
-#    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
+#    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl

+ 1 - 1
chaunyi_opc/opc_da/src/main/resources/application.yml

@@ -15,4 +15,4 @@ opc_ua_server:
   address: "http://localhost:8082"
 
 opc_storage:
-  time_format: "yyyy-MM-dd HH"
+  time_format: "yyyy-MM-dd HH"

+ 0 - 1
chaunyi_opc/opc_da/src/main/resources/mapper/ItemGroupDao.xml

@@ -64,7 +64,6 @@
     <update id="updateItem">
         update t_item
         set data_model_id=#{dataModelId},
-            table_report_id=#{tableReportId},
             `describe`=#{describe}
         where id = #{id}
     </update>

+ 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

+ 14 - 1
chaunyi_opc/opc_da/src/main/resources/mapper/RawDataDao.xml

@@ -116,7 +116,7 @@
     </select>
 
     <select id="getCursorRawDataList" resultType="com.example.opc_common.entity.CursorRawData">
-        <if test="itemList!= null and itemList.size() >0">
+        <if test="indexList!= null and indexList.size() >0">
             select
             <include refid="cursorRawData"/>
             from t_raw_data
@@ -161,4 +161,17 @@
         GROUP BY
         data_index;
     </select>
+
+    <select id="getRawDataGroupIdList" resultType="java.lang.Integer">
+        SELECT item_group_id
+        FROM t_raw_data
+        GROUP BY item_group_id;
+    </select>
+
+    <select id="getRawDataBelongTime" resultType="java.lang.String">
+        SELECT value_belong_time
+        FROM t_raw_data
+        WHERE item_group_id = #{itemGroupId}
+        GROUP BY value_belong_time;
+    </select>
 </mapper>

+ 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 = "";

+ 2 - 2
chaunyi_opc/opc_ua/src/main/resources/application-dev.yml

@@ -11,7 +11,7 @@ spring:
       max-request-size: 500MB
   datasource:
     driver-class-name: com.mysql.cj.jdbc.Driver
-    url: jdbc:mysql://localhost:3306/chuanyi?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&serverTimezone=GMT%2B8
+    url: jdbc:mysql://localhost:3306/ei_rptdb?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&serverTimezone=GMT%2B8
     username: root
     password: root
   resources:
@@ -31,4 +31,4 @@ spring:
 mybatis:
   configuration:
     #日志
-    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
+    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl

+ 2 - 2
chaunyi_opc/opc_ua/src/main/resources/application-prod.yml

@@ -11,7 +11,7 @@ spring:
       max-request-size: 500MB
   datasource:
     driver-class-name: com.mysql.cj.jdbc.Driver
-    url: jdbc:mysql://localhost:3306/chuanyi?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&serverTimezone=GMT%2B8
+    url: jdbc:mysql://localhost:3306/ei_rptdb?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&serverTimezone=GMT%2B8
     username: root
     password: root
   resources:
@@ -30,4 +30,4 @@ spring:
 
 #mybatis:
 #  configuration:
-#    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
+#    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl

+ 1 - 1
chaunyi_opc/opc_ua/src/main/resources/mapper/ItemGroupDao.xml

@@ -26,7 +26,7 @@
         <include refid="item"/>
         from t_item
         where item_group_id = #{itemGroupId}
-        order by event_mode DESC,item_name
+        order by item_name
     </select>
 
     <select id="getAllItemGroup" resultType="com.example.opc_common.entity.ItemGroup">

+ 1 - 1
chaunyi_opc/opc_ua/src/main/resources/mapper/RawDataDao.xml

@@ -138,7 +138,7 @@
     </select>
 
     <select id="getCursorRawDataList" resultType="com.example.opc_common.entity.CursorRawData">
-        <if test="itemList!= null and itemList.size() >0">
+        <if test="indexList!= null and indexList.size() >0">
             select
             <include refid="cursorRawData"/>
             from t_raw_data

+ 14 - 1
chuanyi-admin/src/views/dashboard/index.vue

@@ -90,7 +90,11 @@
     </el-row>
 
     <!-- 客户端在线用户数弹框 -->
-    <onlineUsers ref="onUsers" :table-data="onlineUsersTable" />
+    <onlineUsers
+      ref="onUsers"
+      :table-data="onlineUsersTable"
+      @updateOnlineUser="updateOnlineUser"
+    />
   </div>
 </template>
 
@@ -165,6 +169,15 @@ export default {
     // 点击客户端在线用户数
     onlineUsers() {
       this.$refs.onUsers.show()
+    },
+    // 更新客户端在线用户数
+    updateOnlineUser() {
+      getOnlineUser('front').then((res) => {
+        if (res.code === 200) {
+          this.statistics.onlineClientUserNum = res.data.count
+          this.onlineUsersTable = res.data.frontLoginList
+        }
+      })
     }
   }
 }

+ 6 - 5
chuanyi-admin/src/views/dashboard/onlineUsers.vue

@@ -8,10 +8,7 @@
     >
       <el-table-column prop="userName" label="用户名" />
       <el-table-column prop="createTime" label="创建时间" />
-      <el-table-column
-        prop="lastLoginTime"
-        label="最后登录时间"
-      />
+      <el-table-column prop="lastLoginTime" label="最后登录时间" />
       <el-table-column label="操作" align="center">
         <template slot-scope="scope">
           <el-button
@@ -34,7 +31,10 @@
 import { clearLoginSession } from '@/api/dashboard'
 export default {
   props: {
-    tableData: Array
+    tableData: {
+      type: Array,
+      default: () => []
+    }
   },
   data() {
     return {
@@ -63,6 +63,7 @@ export default {
                 message: res.data,
                 type: 'success'
               })
+              this.$emit('updateOnlineUser')
             }
           })
         })