Parcourir la source

优化opc
1:增加redis缓存
2:增加定时读取redis一分钟,异步,后续补充写入mssql
3:增加序列化redis list操作

hfxc226 il y a 2 ans
Parent
commit
6e9400584b

+ 9 - 4
platform-common/src/main/java/com/platform/common/util/DateUtils.java

@@ -242,6 +242,14 @@ public class DateUtils {
         return (year % 4 == 0 && year % 100 != 0);
 
     }
+    /**
+     * 时间转字符串
+     * @return :
+     */
+    public static String dateToString(Date date) {
+        SimpleDateFormat format= new SimpleDateFormat(PATTERN_YMD_HMS);
+        return format.format(date);
+    }
 
     /**
      * 时间转字符串
@@ -466,10 +474,7 @@ public class DateUtils {
 
     public static void main(String[] args) {
         Calendar calendar = Calendar.getInstance();
-        calendar.set(2022, 11 - 2, 1, 0, 2, 30);
-        getLastMonth(calendar);
-        LocalDate localDate = LocalDate.now();
-        System.out.println(DateUtils.dateToString(localDate, DateUtils.PATTERN_YMD) + " 00:00:00");
+        System.out.println(DateUtils.dateToString(calendar.getTime()));
     }
 
     /**

+ 132 - 0
platform-dao/src/main/java/com/platform/dao/dto/remote/RemoteOpcLogDTO.java

@@ -0,0 +1,132 @@
+package com.platform.dao.dto.remote;
+
+import com.platform.common.bean.BaseDTO;
+import com.platform.common.validation.group.UpdateGroup;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+import javax.persistence.Transient;
+import javax.validation.constraints.NotNull;
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.time.LocalDateTime;
+
+/**
+ * @Description 设备电度记录表DTO
+ * @Author xc
+ * @Date 2022-09-13 14:14:35
+ * @Version Copyright (c) 2020,北京乾元坤和科技有限公司 All rights reserved.
+ */
+@Data
+@Accessors(chain = true)
+@EqualsAndHashCode(callSuper = true)
+public class RemoteOpcLogDTO extends BaseDTO implements Serializable {
+
+    /**
+     * json数据
+     */
+    private String info;
+    /**
+     * id
+     */
+    @NotNull(groups = {UpdateGroup.class}, message = "ID不能为空")
+    private String id;
+    /**
+     * 设备id
+     */
+    private String sbId;
+    /**
+     * 设备名称
+     */
+    private String sbName;
+    /**
+     * 点位
+     */
+    private Integer positionNum;
+    /**
+     * 年
+     */
+    private Integer year;
+    /**
+     * 月
+     */
+    private Integer month;
+    /**
+     * 日
+     */
+    private Integer day;
+    /**
+     * 时
+     */
+    private Integer hour;
+    /**
+     * 分
+     */
+    private Integer minute;
+    /**
+     * 类型
+     */
+    private Integer type;
+    /**
+     * 描述
+     */
+    private String description;
+    /**
+     * 实时数值
+     */
+    private String result;
+    /**
+     * 系数
+     */
+    private BigDecimal ratio;
+    /**
+     * 单位
+     */
+    private String unit;
+    /**
+     * 备注
+     */
+    private String remark;
+    /**
+     * 创建人
+     */
+    private String createdUserId;
+    /**
+     * 更新人
+     */
+    private String updateUserId;
+    /**
+     * 创建日期
+     */
+    private LocalDateTime createdTime;
+    /**
+     * 创建日期开始
+     */
+    private LocalDateTime createdTimeStart;
+    /**
+     * 创建日期结束
+     */
+    private LocalDateTime createdTimeEnd;
+    /**
+     * 更新日期
+     */
+    private LocalDateTime updateTime;
+    /**
+     * 更新日期开始
+     */
+    private LocalDateTime updateTimeStart;
+    /**
+     * 更新日期结束
+     */
+    private LocalDateTime updateTimeEnd;
+    /**
+     * 关键字
+     */
+    private String keyword;
+    /**
+     * 对应设备所属线路,用于分组统计
+     */
+    @Transient
+    private Integer line;
+}

+ 7 - 5
platform-dao/src/main/java/com/platform/dao/entity/operate/Article.java

@@ -6,7 +6,9 @@ import javax.persistence.Id;
 import javax.persistence.Table;
 import java.io.Serializable;
 import java.time.LocalDateTime;
+
 import com.platform.common.bean.DataScope;
+
 import javax.persistence.Transient;
 
 /**
@@ -17,12 +19,12 @@ import javax.persistence.Transient;
  */
 @Table(name = "t_article")
 @Data
-public class Article implements Serializable{
+public class Article implements Serializable {
 
     /**
      * ID
      */
-        @Id
+    @Id
     private String id;
     /**
      * 关联父类文章id
@@ -93,9 +95,9 @@ public class Article implements Serializable{
      */
     private String updateUserName;
 
-   /**
-    * 数据权限
-    */
+    /**
+     * 数据权限
+     */
     @Transient
     private DataScope dataScope;
 

+ 112 - 0
platform-dao/src/main/java/com/platform/dao/entity/remote/RemoteOpcLog.java

@@ -0,0 +1,112 @@
+package com.platform.dao.entity.remote;
+
+import com.platform.common.bean.DataScope;
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+import javax.persistence.Id;
+import javax.persistence.Table;
+import javax.persistence.Transient;
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.time.LocalDateTime;
+
+/**
+ * @Description 设备电度记录表实体类
+ * @Author xc
+ * @Date 2022-09-13 14:14:35
+ * @Version Copyright (c) 2020,北京乾元坤和科技有限公司 All rights reserved.
+ */
+@Data
+@Accessors(chain = true)
+@Table(name = "t_remote_opc_log")
+public class RemoteOpcLog implements Serializable {
+
+    /**
+     * id
+     */
+    @Id
+    private String id;
+    /**
+     * 设备id
+     */
+    private String sbId;
+    /**
+     * 设备名称
+     */
+    private String sbName;
+    /**
+     * 点位
+     */
+    private Integer positionNum;
+    /**
+     * 年
+     */
+    private Integer year;
+    /**
+     * 月
+     */
+    private Integer month;
+    /**
+     * 日
+     */
+    private Integer day;
+    /**
+     * 时
+     */
+    private Integer hour;
+    /**
+     * 分
+     */
+    private Integer minute;
+    /**
+     * 类型
+     */
+    private Integer type;
+    /**
+     * 描述
+     */
+    private String description;
+    /**
+     * 实时数值
+     */
+    private String result;
+    /**
+     * 系数
+     */
+    private BigDecimal ratio;
+    /**
+     * 单位
+     */
+    private String unit;
+    /**
+     * 备注
+     */
+    private String remark;
+    /**
+     * 创建人
+     */
+    private String createdUserId;
+    /**
+     * 更新人
+     */
+    private String updateUserId;
+    /**
+     * 创建日期
+     */
+    private LocalDateTime createdTime;
+    /**
+     * 更新日期
+     */
+    private LocalDateTime updateTime;
+    /**
+     * json数据
+     */
+    private String info;
+    /**
+     * 数据权限
+     */
+    @Transient
+    private DataScope dataScope;
+
+}

+ 27 - 0
platform-dao/src/main/java/com/platform/dao/mapper/remote/RemoteOpcLogMapper.java

@@ -0,0 +1,27 @@
+package com.platform.dao.mapper.remote;
+
+import com.platform.dao.config.MyMapper;
+import com.platform.dao.dto.remote.RemoteOpcLogDTO;
+import com.platform.dao.entity.remote.RemoteOpcLog;
+import com.platform.dao.vo.query.remote.RemoteOpcLogVO;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+
+
+/**
+ * @Description 设备opc记录表 mapper
+ * @Author xc
+ * @Date 2022-09-13 14:14:35
+ * @Version Copyright (c) 2020,北京乾元坤和科技有限公司 All rights reserved.
+ */
+@Component
+public interface RemoteOpcLogMapper extends MyMapper<RemoteOpcLog> {
+    /**
+     * 分页查询
+     * @param dto
+     * @return
+     */
+    List<RemoteOpcLogVO> selectList(RemoteOpcLogDTO dto);
+
+}

+ 126 - 0
platform-dao/src/main/java/com/platform/dao/vo/export/remote/ExportRemoteOpcLogVO.java

@@ -0,0 +1,126 @@
+package com.platform.dao.vo.export.remote;
+
+import com.platform.office.annotation.Excel;
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.time.LocalDateTime;
+
+/**
+ * @Description 设备电度记录表导出VO
+ * @Author xc
+ * @Date 2022-09-13 14:14:35
+ * @Version Copyright (c) 2020,北京乾元坤和科技有限公司 All rights reserved.
+ */
+@Data
+@Accessors(chain = true)
+public class ExportRemoteOpcLogVO implements Serializable {
+
+    /**
+     * id
+     */
+    @Excel(name = "id", orderNum = "1")
+    private String id;
+
+    /**
+     * 设备id
+     */
+    @Excel(name = "设备id", orderNum = "2")
+    private String sbId;
+
+    /**
+     * 设备名称
+     */
+    @Excel(name = "设备名称", orderNum = "3")
+    private String sbName;
+
+    /**
+     * 点位
+     */
+    @Excel(name = "点位", orderNum = "4")
+    private Integer positionNum;
+
+    /**
+     * 类型
+     */
+    @Excel(name = "类型", orderNum = "5")
+    private Integer type;
+
+    /**
+     * 描述
+     */
+    @Excel(name = "描述", orderNum = "6")
+    private String description;
+
+    /**
+     * 实时数值
+     */
+    @Excel(name = "实时数值", orderNum = "7")
+    private String value;
+
+    /**
+     * 年
+     */
+    @Excel(name = "年", orderNum = "8")
+    private Integer year;
+    /**
+     * 月
+     */
+    @Excel(name = "月", orderNum = "9")
+    private Integer month;
+    /**
+     * 日
+     */
+    @Excel(name = "日", orderNum = "10")
+    private Integer day;
+    /**
+     * 时
+     */
+    @Excel(name = "时", orderNum = "11")
+    private Integer hour;
+    /**
+     * 系数
+     */
+    @Excel(name = "系数", orderNum = "12")
+    private BigDecimal ratio;
+
+    /**
+     * 单位
+     */
+    @Excel(name = "单位", orderNum = "13")
+    private String unit;
+
+    /**
+     * 备注
+     */
+    @Excel(name = "备注", orderNum = "14")
+    private String remark;
+
+    /**
+     * 创建人
+     */
+    @Excel(name = "创建人", orderNum = "15")
+    private String createdUserId;
+
+    /**
+     * 更新人
+     */
+    @Excel(name = "更新人", orderNum = "16")
+    private String updateUserId;
+
+    /**
+     * 创建日期
+     */
+    @Excel(name = "创建日期", orderNum = "17")
+    private LocalDateTime createdTime;
+
+    /**
+     * 更新日期
+     */
+    @Excel(name = "更新日期", orderNum = "18")
+    private LocalDateTime updateTime;
+
+
+}

+ 112 - 0
platform-dao/src/main/java/com/platform/dao/vo/query/remote/RemoteOpcLogVO.java

@@ -0,0 +1,112 @@
+package com.platform.dao.vo.query.remote;
+
+import com.platform.common.bean.BaseVO;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.time.LocalDateTime;
+
+/**
+ * @Description 设备电度记录表VO结果类
+ * @Author xc
+ * @Date 2022-09-13 14:14:35
+ * @Version Copyright (c) 2020,北京乾元坤和科技有限公司 All rights reserved.
+ */
+@Data
+@Accessors(chain = true)
+@EqualsAndHashCode(callSuper = true)
+public class RemoteOpcLogVO extends BaseVO implements Serializable {
+
+    /**
+     * json数据
+     */
+    private String info;
+    /**
+     * id
+     */
+    private String id;
+    /**
+     * 设备id
+     */
+    private String sbId;
+    /**
+     * 设备名称
+     */
+    private String sbName;
+    /**
+     * 设备名称
+     */
+    private String sbNo;
+    /**
+     * 点位
+     */
+    private Integer positionNum;
+    /**
+     * 类型:1正向有功,2正向无功
+     */
+    private Integer type;
+    /**
+     * 描述
+     */
+    private String description;
+    /**
+     * 实时数值
+     */
+    private String result;
+    /**
+     * 年
+     */
+    private Integer year;
+    /**
+     * 月
+     */
+    private Integer month;
+    /**
+     * 日
+     */
+    private Integer day;
+    /**
+     * 时
+     */
+    private Integer hour;
+    /**
+     * 分
+     */
+    private Integer minute;
+    /**
+     * 系数
+     */
+    private BigDecimal ratio;
+    /**
+     * 单位
+     */
+    private String unit;
+    /**
+     * 备注:保存原始点位推送的全量数据
+     */
+    private String remark;
+    /**
+     * 创建人
+     */
+    private String createdUserId;
+    /**
+     * 更新人
+     */
+    private String updateUserId;
+    /**
+     * 创建日期
+     */
+    private LocalDateTime createdTime;
+    /**
+     * 更新日期
+     */
+    private LocalDateTime updateTime;
+    /**
+     * 对应设备所属线路,用于分组统计
+     */
+    private Integer line;
+
+}

+ 141 - 0
platform-dao/src/main/resources/mapper/remote/RemoteOpcLogMapper.xml

@@ -0,0 +1,141 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.platform.dao.mapper.remote.RemoteOpcLogMapper">
+    <sql id="Base_Column_List">
+        opc_log
+        .
+        id
+        ,
+                                     opc_log.sb_id,
+                                     opc_log.sb_name,
+                                     opc_log.position_num,
+                                     opc_log.type,
+                                     opc_log.description,
+                                     opc_log.result,
+                                     opc_log.ratio,
+                                     opc_log.unit,
+                                     opc_log.remark,
+                                     opc_log.year,
+                                     opc_log.month,
+                                     opc_log.day,
+                                     opc_log.hour,
+                                     opc_log.minute,
+                                     opc_log.info,
+                                     opc_log.created_user_id,
+                                     opc_log.update_user_id,
+                                     opc_log.created_time,
+                                     opc_log.update_time
+    </sql>
+    <sql id="Ref_Column_List">
+        opc_log
+        .
+        sb_id
+        ,
+                                     opc_log.sb_name,
+                                     opc_log.position_num,
+                                     opc_log.type,
+                                     opc_log.description,
+                                     opc_log.result,
+                                     opc_log.year,
+                                     opc_log.month,
+                                     opc_log.day,
+                                     opc_log.hour,
+                                     opc_log.minute,
+                                     opc_log.info,
+                                     opc_log.ratio,
+                                     opc_log.unit,
+                                     opc_log.remark,
+    </sql>
+    <sql id="List_Condition">
+        <if test="id != null and id != ''">
+            and opc_log.id = #{id}
+        </if>
+        <if test="sbId != null and sbId != ''">
+            and opc_log.sb_id = #{sbId}
+        </if>
+        <if test="year != null">
+            and opc_log.year = #{year}
+        </if>
+        <if test="month != null">
+            and opc_log.month = #{month}
+        </if>
+        <if test="day != null">
+            and opc_log.day = #{day}
+        </if>
+        <if test="hour != null">
+            and opc_log.hour = #{hour}
+        </if>
+        <if test="minute != null">
+            and opc_log.minute = #{minute}
+        </if>
+        <if test="positionNum != null">
+            and opc_log.position_num = #{positionNum}
+        </if>
+        <if test="type != null">
+            and opc_log.type = #{type}
+        </if>
+        <if test="description != null and description != ''">
+            and opc_log.description = #{description}
+        </if>
+        <if test="result != null and result != ''">
+            and opc_log.result = #{result}
+        </if>
+        <if test="ratio != null">
+            and opc_log.ratio = #{ratio}
+        </if>
+        <if test="unit != null and unit != ''">
+            and opc_log.unit = #{unit}
+        </if>
+        <if test="remark != null and remark != ''">
+            and opc_log.remark = #{remark}
+        </if>
+        <if test="createdUserId != null and createdUserId != ''">
+            and opc_log.created_user_id = #{createdUserId}
+        </if>
+        <if test="updateUserId != null and updateUserId != ''">
+            and opc_log.update_user_id = #{updateUserId}
+        </if>
+        <if test="createdTimeStart != null">
+            and opc_log.created_time <![CDATA[>=]]>; #{createdTimeStart}
+        </if>
+        <if test="createdTimeEnd != null">
+            and opc_log.created_time <![CDATA[<=]]> #{createdTimeEnd}
+        </if>
+        <if test="createdTime != null">
+            and opc_log.created_time = #{createdTime}
+        </if>
+        <if test="updateTimeStart != null">
+            and opc_log.update_time <![CDATA[>=]]>; #{updateTimeStart}
+        </if>
+        <if test="updateTimeEnd != null">
+            and opc_log.update_time <![CDATA[<=]]> #{updateTimeEnd}
+        </if>
+        <if test="updateTime != null">
+            and opc_log.update_time = #{updateTime}
+        </if>
+        <if test="keyword != null and keyword != ''">
+            and (
+                opc.sb_name like concat(concat('%',#{keyword}),'%')
+                or opc_log.position_num like concat(concat('%',#{keyword}),'%')
+            )
+        </if>
+        <if test="sbName != null and sbName != ''">
+            and opc.sb_name like concat(concat('%',#{sbName}),'%')
+        </if>
+        <if test="line != null">
+            and opc.line = #{line}
+        </if>
+    </sql>
+    <select id="selectList" parameterType="com.platform.dao.dto.remote.RemoteOpcLogDTO"
+            resultType="com.platform.dao.vo.query.remote.RemoteOpcLogVO">
+        select opc_log.*, opc.sb_name sbName, opc.line line, opc.type
+        from t_remote_opc_log as opc_log
+        left join t_remote_opc opc on opc_log.position_num = opc.position_num
+        <where>
+            <include refid="List_Condition"/>
+            <if test="line != null">
+                and opc.line = #{line}
+            </if>
+        </where>
+    </select>
+</mapper>

+ 6 - 11
platform-iec/src/main/java/com/ydl/iec/util/MySqlUtil.java

@@ -5,15 +5,10 @@ import com.platform.common.exception.BusinessException;
 import com.platform.common.exception.DeniedException;
 import com.platform.common.util.DateUtils;
 import com.platform.common.util.IdGeneratorUtils;
-import com.platform.common.util.SecurityUtils;
 import com.platform.common.util.StringUtils;
-import com.platform.dao.vo.query.qykh.HotspotHelpVO;
-import com.platform.dao.vo.sb.SbInfoScreenDetailVO;
-import com.ydl.iec.iec104.core.Iec104ThreadLocal;
 import com.ydl.iec.iec104.message.MessageDetail;
 import com.ydl.iec.iec104.message.MessageInfo;
 import lombok.extern.slf4j.Slf4j;
-import org.bouncycastle.cms.bc.BcKEKRecipientInfoGenerator;
 import org.springframework.util.CollectionUtils;
 
 import java.math.BigDecimal;
@@ -27,17 +22,17 @@ public class MySqlUtil {
     //是否连接数据库
     public static String mysql_open = "false";
     //数据库连接地址
-    public static String mysql_url = "jdbc:mysql://123.60.19.203:5006/hitch-sb?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&allowMultiQueries=true";
+    //public static String mysql_url = "jdbc:mysql://123.60.19.203:5006/hitch-sb?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&allowMultiQueries=true";
     //用户名
-    public static String mysql_username = "root";
+    //public static String mysql_username = "root";
     //密码
-    public static String mysql_password = "mysql?MYSQLmoniu123";
+    //public static String mysql_password = "mysql?MYSQLmoniu123";
     //数据库连接地址
-    //public static String mysql_url = "jdbc:mysql://192.168.16.222:3306/hitch-sb?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&allowMultiQueries=true";
+    public static String mysql_url = "jdbc:mysql://192.168.16.222:3306/hitch-sb?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&allowMultiQueries=true";
     //用户名
-    //public static String mysql_username = "root";
+    public static String mysql_username = "root";
     //密码
-    //public static String mysql_password = "mydm888";
+    public static String mysql_password = "mydm888";
     //驱动名称
     public static String mysql_driver = "com.mysql.cj.jdbc.Driver";
     // 采集数据,结构:遥测最低,遥测最高;电度最低,电度最高

+ 21 - 0
platform-opc/src/main/java/com/platform/opc/entity/OpcResult.java

@@ -0,0 +1,21 @@
+package com.platform.opc.entity;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+@Data
+public class OpcResult implements Serializable {
+    /**
+     * tag
+     */
+    private String id;
+    /**
+     * value
+     */
+    private String value;
+    /**
+     * time:时间戳
+     */
+    private String time;
+}

+ 23 - 1
platform-opc/src/main/java/com/platform/opc/servie/OpcTaskService.java

@@ -6,6 +6,7 @@ import com.platform.common.util.RedisUtils;
 import com.platform.dao.entity.remote.RemoteOpc;
 import com.platform.dao.mapper.remote.RemoteOpcMapper;
 import com.platform.dao.mapper.upms.SysDictMapper;
+import com.platform.opc.entity.OpcResult;
 import com.platform.opc.util.OpcDAClient;
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
@@ -28,12 +29,33 @@ import java.util.stream.Collectors;
 @EnableAsync
 public class OpcTaskService {
 
+    /**
+     * 1: 分组获取数据
+     *  a:保存到redis,前端页面实时从数据库获取数据,2秒刷新一次
+     */
     @Async
     @Scheduled(fixedDelay = 5000)  //间隔2秒
     public void getValue(){
         log.info("开始定时任务");
-        List<Map<String, Object>> resultList = OpcDAClient.getItemValuesList();
+        List<OpcResult> resultList = OpcDAClient.getItemValuesList();
         log.info("resultList:" + resultList.size());
+        log.info("数据存入redis");
+        RedisUtils.setList("opcList", resultList);
         log.info("结束定时任务");
     }
+
+    /**
+     * 1: 保存获取的数据
+     *  b: 开启新线程,队列写入数据库,每一分钟启动一次
+     */
+    @Async
+    @Scheduled(fixedDelay = 60000)  //间隔60秒
+    public void saveValue(){
+        log.info("开始读取redis");
+        List<OpcResult>  resultList = RedisUtils.getList("opcList", 0 , -1);
+        for(OpcResult result: resultList){
+            log.info("id: " + result.getId() + ", value: " + result.getValue() + ", time: " + result.getTime());
+        }
+        log.info("结束读取redis");
+    }
 }

+ 50 - 16
platform-opc/src/main/java/com/platform/opc/util/OpcDAClient.java

@@ -1,8 +1,10 @@
 package com.platform.opc.util;
 
+import com.platform.common.util.DateUtils;
 import com.platform.common.util.RedisUtils;
 import com.platform.dao.entity.remote.RemoteOpc;
 import com.platform.dao.vo.SysUserVO;
+import com.platform.opc.entity.OpcResult;
 import lombok.extern.slf4j.Slf4j;
 import org.jinterop.dcom.common.JIErrorCodes;
 import org.jinterop.dcom.common.JIException;
@@ -16,6 +18,8 @@ import org.openscada.opc.lib.da.browser.FlatBrowser;
 import org.springframework.util.CollectionUtils;
 
 import java.net.UnknownHostException;
+import java.time.LocalDateTime;
+import java.time.ZoneOffset;
 import java.util.*;
 import java.util.concurrent.Executors;
 import java.util.stream.Collectors;
@@ -213,23 +217,22 @@ public class OpcDAClient {
 
     /**
      * 获取多组数据
-     *
      * @return
      */
-    public static List<Map<String, Object>> getItemValuesList() {
-        List<Map<String, Object>> resultList = new ArrayList<>();
+    /*public static List<Map<String, String>> getItemValuesList() {
+        List<Map<String, String>> resultList = new ArrayList<>();
         try {
             if (!CollectionUtils.isEmpty(groupItemsList)) {
                 log.info("数据获取总组数:", groupItemsList.size());
                 for (int i = 0; i < groupItemsList.size(); i++) {
                     Map<Item, ItemState> resultMap = groupList.get(i).read(true, itemArrList[i]);
                     log.info("数据获取完成。数量:", resultMap.size() + ", 组序号:" + i);
-                    Map<String, Object> result = new HashMap<>();
+                    Map<String, String> result = new HashMap<>();
                     for (Item item : resultMap.keySet()) {
                         ItemState itemMap = resultMap.get(item);
-                        Object value = getVal(itemMap.getValue());
+                        String value = getVal(itemMap.getValue());
                         result.put(item.getId(), value);
-                        log.info("id: " + item.getId() + ", value: " + value);
+                        log.info("id: " + item.getId() + ", value: " + value + ", timestamp: " + itemMap.getTimestamp());
                     }
                     resultList.add(result);
                 }
@@ -239,6 +242,37 @@ public class OpcDAClient {
             log.error("批量获取数据异常:", e);
         }
         return resultList;
+    }*/
+
+    /**
+     * 获取多组数据
+     * @return
+     */
+    public static List<OpcResult> getItemValuesList() {
+        List<OpcResult> resultList = new ArrayList<>();
+        try {
+            if (!CollectionUtils.isEmpty(groupItemsList)) {
+                log.info("数据获取总组数:", groupItemsList.size());
+                for (int i = 0; i < groupItemsList.size(); i++) {
+                    Map<Item, ItemState> resultMap = groupList.get(i).read(true, itemArrList[i]);
+                    //log.info("数据获取完成。数量:", resultMap.size() + ", 组序号:" + i);
+                    OpcResult result = new OpcResult();
+                    for (Item item : resultMap.keySet()) {
+                        ItemState itemMap = resultMap.get(item);
+                        String value = getVal(itemMap.getValue());
+                        result.setId(item.getId());
+                        result.setValue(value);
+                        result.setTime(DateUtils.dateToString(itemMap.getTimestamp().getTime()));
+                        // log.info("id: " + item.getId() + ", value: " + value + ", timestamp: " + itemMap.getTimestamp());
+                        resultList.add(result);
+                    }
+                }
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+            log.error("批量获取数据异常:", e);
+        }
+        return resultList;
     }
 
     /**
@@ -248,34 +282,34 @@ public class OpcDAClient {
      * @return
      * @throws JIException
      */
-    private static Object getVal(JIVariant var) throws JIException {
-        Object value;
+    private static String getVal(JIVariant var) throws JIException {
+        String value;
         int type = var.getType();
         switch (type) {
             case JIVariant.VT_I2:
-                value = var.getObjectAsShort();
+                value = var.getObjectAsShort() + "";
                 break;
             case JIVariant.VT_I4:
-                value = var.getObjectAsInt();
+                value = var.getObjectAsInt() + "";
                 break;
             case JIVariant.VT_I8:
-                value = var.getObjectAsLong();
+                value = var.getObjectAsLong() + "";
                 break;
             case JIVariant.VT_R4:
-                value = var.getObjectAsFloat();
+                value = var.getObjectAsFloat() + "";
                 break;
             case JIVariant.VT_R8:
-                value = var.getObjectAsDouble();
+                value = var.getObjectAsDouble() + "";
                 break;
             case JIVariant.VT_BSTR:
-                value = var.getObjectAsString2();
+                value = var.getObjectAsString2() + "";
                 break;
             case JIVariant.VT_BOOL:
-                value = var.getObjectAsBoolean();
+                value = var.getObjectAsBoolean() + "";
                 break;
             case JIVariant.VT_UI2:
             case JIVariant.VT_UI4:
-                value = var.getObjectAsUnsigned().getValue();
+                value = var.getObjectAsUnsigned().getValue() + "";
                 break;
             case JIVariant.VT_EMPTY:
                 throw new JIException(JIErrorCodes.JI_VARIANT_IS_NULL, "Variant is Empty.");

+ 141 - 0
platform-rest/src/main/java/com/platform/rest/controller/remote/RemoteOpcLogController.java

@@ -0,0 +1,141 @@
+package com.platform.rest.controller.remote;
+
+import com.platform.common.bean.AbstractPageResultBean;
+import com.platform.common.util.BeanConverterUtil;
+import com.platform.common.util.R;
+import com.platform.common.validation.group.AddGroup;
+import com.platform.common.validation.group.UpdateGroup;
+import com.platform.dao.dto.remote.RemoteOpcLogDTO;
+import com.platform.dao.entity.remote.RemoteOpcLog;
+import com.platform.dao.util.ExcelUtil;
+import com.platform.dao.vo.export.remote.ExportRemoteOpcLogVO;
+import com.platform.dao.vo.query.remote.RemoteOpcLogVO;
+import com.platform.rest.log.annotation.SysLog;
+import com.platform.service.remote.RemoteOpcLogService;
+import lombok.AllArgsConstructor;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletResponse;
+import java.util.List;
+
+/**
+ * @Description opc记录表 控制器
+ * @Author xc
+ * @Date 2022-09-13 14:14:35
+ * @Version Copyright (c) 2020,北京乾元坤和科技有限公司 All rights reserved.
+ */
+@RestController
+@AllArgsConstructor
+@RequestMapping("/remote/opc-logs")
+public class RemoteOpcLogController {
+
+    private final RemoteOpcLogService remoteOpcLogService;
+
+    /**
+     * 通过id查询单条记录
+     *
+     * @param id 主键
+     * @return R
+     */
+    @GetMapping("/{id}")
+    public R<RemoteOpcLog> getById(@PathVariable("id") String id) {
+        return new R<>(remoteOpcLogService.getModelById(id));
+    }
+
+    /**
+     * 新增记录
+     *
+     * @param RemoteOpcLogDTO opc记录表DTO
+     * @return R
+     */
+    @SysLog("新增opc记录表")
+    @PostMapping
+    @PreAuthorize("@pms.hasPermission('remote-opc-logs-add')")
+    public R save(@Validated({AddGroup.class}) @RequestBody RemoteOpcLogDTO RemoteOpcLogDTO) {
+        return new R<>(remoteOpcLogService.saveModelByDTO(RemoteOpcLogDTO));
+    }
+
+    /**
+     * 修改记录
+     *
+     * @param RemoteOpcLogDTO opc记录表DTO
+     * @return R
+     */
+    @SysLog("修改opc记录表")
+    @PutMapping("/{id}")
+    @PreAuthorize("@pms.hasPermission('remote-opc-logs-edit')")
+    public R update(@PathVariable("id") String id, @Validated({UpdateGroup.class}) @RequestBody RemoteOpcLogDTO RemoteOpcLogDTO) {
+        remoteOpcLogService.modModelByDTO(RemoteOpcLogDTO);
+        return new R<>();
+    }
+
+
+    /**
+     * 通过id删除一条记录
+     *
+     * @param id 主键
+     * @return R
+     */
+    @SysLog("删除opc记录表")
+    @DeleteMapping("/{id}")
+    @PreAuthorize("@pms.hasPermission('remote-opc-logs-del')")
+    public R removeById(@PathVariable String id) {
+        remoteOpcLogService.deleteByPrimaryKey(id);
+        return new R<>();
+    }
+
+    /**
+     * 批量记录
+     *
+     * @param ids 主键
+     * @return R
+     */
+    @SysLog("批量删除opc记录表")
+    @DeleteMapping("")
+    @PreAuthorize("@pms.hasPermission('remote-opc-logs-del')")
+    public R removeIds(@RequestBody List<String> ids) {
+        remoteOpcLogService.batchDelete(ids);
+        return new R<>();
+    }
+
+    /**
+     * 获取分页
+     *
+     * @param pageNum            当前页码
+     * @param pageSize           每页条数
+     * @param RemoteOpcLogDTO opc记录表DTO
+     * @return R
+     */
+    @GetMapping("/page")
+    public R<AbstractPageResultBean<RemoteOpcLogVO>> query(RemoteOpcLogDTO RemoteOpcLogDTO, @RequestParam(defaultValue = "1") int pageNum, @RequestParam(defaultValue = "20") int pageSize) {
+        return new R<>(remoteOpcLogService.selectPageList(RemoteOpcLogDTO, pageNum, pageSize));
+    }
+
+    /**
+     * 获取列表
+     *
+     * @param RemoteOpcLogDTO opc记录表DTO
+     * @return R
+     */
+    @GetMapping("")
+    public R query(RemoteOpcLogDTO RemoteOpcLogDTO) {
+        return new R<>(remoteOpcLogService.getModelListByDTO(RemoteOpcLogDTO));
+    }
+
+    /**
+     * opc记录表导出
+     *
+     * @param RemoteOpcLogDTO opc记录表DTO
+     * @return R
+     */
+    @GetMapping("/export")
+    @SysLog("opc记录表导出")
+    @PreAuthorize("@pms.hasPermission('remote-opc-logs-export')")
+    public void export(HttpServletResponse response, RemoteOpcLogDTO RemoteOpcLogDTO) {
+        List<RemoteOpcLog> list = remoteOpcLogService.getModelListByDTO(RemoteOpcLogDTO);
+        ExcelUtil.exportResponseDict(response, ExportRemoteOpcLogVO.class, BeanConverterUtil.copyListProperties(list, ExportRemoteOpcLogVO.class), "opc记录表");
+    }
+
+}

+ 45 - 0
platform-service/src/main/java/com/platform/service/remote/RemoteOpcLogService.java

@@ -0,0 +1,45 @@
+package com.platform.service.remote;
+
+import com.platform.common.bean.AbstractPageResultBean;
+import com.platform.dao.dto.remote.RemoteOpcLogDTO;
+import com.platform.dao.entity.remote.RemoteOpcLog;
+import com.platform.dao.vo.query.remote.RemoteOpcLogVO;
+import com.platform.service.base.IBaseService;
+
+import java.util.List;
+
+/**
+ * @Description 设备电度记录表 service
+ * @Author xc
+ * @Date 2022-09-13 14:14:35
+ * @Version Copyright (c) 2020,北京乾元坤和科技有限公司 All rights reserved.
+ */
+public interface RemoteOpcLogService extends IBaseService<RemoteOpcLog, RemoteOpcLogDTO> {
+
+   /**
+    * 批量删除
+    *
+    * @param ids :
+    * @return :
+    */
+    int batchDelete(List<String> ids);
+
+    /**
+     * 分页查询
+     * @param record
+     * @param pageNum
+     * @param pageSize
+     * @return
+     */
+    AbstractPageResultBean<RemoteOpcLogVO> selectPageList(RemoteOpcLogDTO record, int pageNum, int pageSize);
+
+    /**
+     * 根据点位新增电度结果数据
+     *
+     * @param positionNum:
+     * @param result:
+     * @return :
+     */
+    void addByPositionNum(Integer positionNum, String result) ;
+
+}

+ 66 - 0
platform-service/src/main/java/com/platform/service/remote/impl/RemoteOpcLogServiceImpl.java

@@ -0,0 +1,66 @@
+package com.platform.service.remote.impl;
+
+import com.github.pagehelper.PageHelper;
+import com.platform.common.bean.AbstractPageResultBean;
+import com.platform.common.util.IdGeneratorUtils;
+import com.platform.dao.bean.MyPage;
+import com.platform.dao.dto.remote.RemoteOpcLogDTO;
+import com.platform.dao.entity.remote.RemoteOpcLog;
+import com.platform.dao.mapper.remote.RemoteOpcLogMapper;
+import com.platform.dao.mapper.upms.SysDictMapper;
+import com.platform.dao.vo.query.remote.RemoteOpcLogVO;
+import com.platform.service.base.impl.BaseServiceImpl;
+import com.platform.service.remote.RemoteOpcLogService;
+import lombok.AllArgsConstructor;
+import org.springframework.stereotype.Service;
+import tk.mybatis.mapper.weekend.Weekend;
+import tk.mybatis.mapper.weekend.WeekendCriteria;
+
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.util.List;
+
+/**
+ * @Description 设备电度记录表 service 实现类
+ * @Author xc
+ * @Date 2022-09-13 14:14:35
+ * @Version Copyright (c) 2020,北京乾元坤和科技有限公司 All rights reserved.
+ */
+@AllArgsConstructor
+@Service("remoteOpcLogService")
+public class RemoteOpcLogServiceImpl extends BaseServiceImpl<RemoteOpcLogMapper, RemoteOpcLog, RemoteOpcLogDTO> implements RemoteOpcLogService {
+
+    private final SysDictMapper sysDictMapper;
+
+    @Override
+    public int batchDelete(List<String> ids) {
+        Weekend<RemoteOpcLog> weekend = new Weekend<>(RemoteOpcLog.class);
+        WeekendCriteria<RemoteOpcLog, Object> weekendCriteria = weekend.weekendCriteria();
+        weekendCriteria.andIn(RemoteOpcLog::getId, ids);
+        mapper.deleteByExample(weekend);
+        return 1;
+    }
+
+    @Override
+    public AbstractPageResultBean<RemoteOpcLogVO> selectPageList(RemoteOpcLogDTO record, int pageNum, int pageSize) {
+        PageHelper.startPage(pageNum, pageSize);
+        return new MyPage(mapper.selectList(record));
+    }
+
+    @Override
+    public void addByPositionNum(Integer positionNum, String result) {
+        RemoteOpcLog RemoteOpcLog = new RemoteOpcLog();
+        RemoteOpcLog.setPositionNum(positionNum);
+        RemoteOpcLog.setId(IdGeneratorUtils.getObjectId());
+        RemoteOpcLog.setResult(result);
+        RemoteOpcLog.setCreatedTime(LocalDateTime.now());
+        mapper.insert(RemoteOpcLog);
+    }
+
+    @Override
+    public AbstractPageResultBean<RemoteOpcLog> selectPageInfo(RemoteOpcLogDTO record, int pageNum, int pageSize) {
+        PageHelper.startPage(pageNum, pageSize);
+        return new MyPage(mapper.selectList(record));
+    }
+
+}