瀏覽代碼

事件日志

learshaw 4 月之前
父節點
當前提交
d9bd5cec63

+ 3 - 3
ems/ems-cloud/ems-dev-adapter/src/main/java/com/ruoyi/ems/TaskExecutor.java

@@ -47,10 +47,10 @@ public class TaskExecutor {
     /**
      * 定时清理过期设备上报响应
      */
-    @Scheduled(cron = "0 0/5 * * * ?")
+    @Scheduled(cron = "0 0/10 * * * ?")
     public void cleanDevResCache() {
         int cnt = objectCache.cleanDevResCache();
-        log.info("清理过期设备上报响应: {} 条", cnt);
+        log.debug("清理过期设备上报响应: {} 条", cnt);
     }
 
     /**
@@ -67,6 +67,6 @@ public class TaskExecutor {
     @Scheduled(cron = "0 0 0/1 * * ?")
     public void meterHourProd() {
         int cnt = geekOpenCbHandler.meterHourProd();
-        log.info("产出设备计量数据: {} 条", cnt);
+        log.debug("产出设备计量数据: {} 条", cnt);
     }
 }

+ 35 - 6
ems/ems-cloud/ems-dev-adapter/src/main/java/com/ruoyi/ems/handle/MqttBaseHandler.java

@@ -17,6 +17,7 @@ import com.ruoyi.ems.domain.ElecMeterH;
 import com.ruoyi.ems.domain.EmsDevice;
 import com.ruoyi.ems.domain.EmsObjAbilityCallLog;
 import com.ruoyi.ems.domain.EmsObjAttrValue;
+import com.ruoyi.ems.domain.EmsObjEventLog;
 import com.ruoyi.ems.domain.EmsObjReportLog;
 import com.ruoyi.ems.domain.MeterDevice;
 import com.ruoyi.ems.enums.DevOnlineStatus;
@@ -28,6 +29,8 @@ import com.ruoyi.ems.service.IElecMeterHService;
 import com.ruoyi.ems.service.IEmsDeviceService;
 import com.ruoyi.ems.service.IEmsObjAbilityCallLogService;
 import com.ruoyi.ems.service.IEmsObjAttrValueService;
+import com.ruoyi.ems.service.IEmsObjEventLogService;
+import com.ruoyi.ems.service.IEmsObjEventService;
 import com.ruoyi.ems.service.IEmsObjReportLogService;
 import com.ruoyi.ems.service.IMeterDeviceService;
 import com.ruoyi.ems.service.IPriceService;
@@ -101,6 +104,9 @@ public abstract class MqttBaseHandler {
     @Autowired
     protected IEmsObjReportLogService objReportLogService;
 
+    @Autowired
+    protected IEmsObjEventLogService objEventLogService;
+
     /**
      * 抽象方法,用于能力调用
      *
@@ -272,9 +278,10 @@ public abstract class MqttBaseHandler {
 
     /**
      * 执行小时抄表计算
-     * @param device 设备信息
+     *
+     * @param device           设备信息
      * @param lastMeterReading 上次抄表值
-     * @param newMeterReading 本次抄表值
+     * @param newMeterReading  本次抄表值
      * @return
      */
     private ElecMeterH execHourMeter(MeterDevice device, String lastMeterReading, String newMeterReading) {
@@ -303,7 +310,8 @@ public abstract class MqttBaseHandler {
 
     /**
      * 封装计量对象
-     * @param device 设备信息
+     *
+     * @param device      设备信息
      * @param newEngValue 最新电量值
      * @param useQuantity 用量差值
      * @return ElecMeterH 计量对象
@@ -325,7 +333,8 @@ public abstract class MqttBaseHandler {
 
     /**
      * 倍率计算
-     * @param quantity 原始用量
+     *
+     * @param quantity      原始用量
      * @param magnification 倍率
      * @return
      */
@@ -335,8 +344,9 @@ public abstract class MqttBaseHandler {
 
     /**
      * 完善价格信息
+     *
      * @param elecMeterH 计量对象
-     * @param price 价格信息
+     * @param price      价格信息
      */
     private void completePrice(ElecMeterH elecMeterH, Price price) {
         if (null != price) {
@@ -426,10 +436,29 @@ public abstract class MqttBaseHandler {
         if (device.getDeviceStatus() != status.getCode()) {
             device.setDeviceStatus(status.getCode());
             deviceService.updateEmsDevice(device);
-            log.info("设备[{}]{}...", device.getDeviceCode(), status == DevOnlineStatus.ONLINE ? "上线" : "下线");
+            triggerEvent(device, status == DevOnlineStatus.ONLINE ? "online" : "offline", null, new Date());
+            log.debug("设备[{}]{}...", device.getDeviceCode(), status == DevOnlineStatus.ONLINE ? "上线" : "下线");
         }
     }
 
+    /**
+     * 触发设备事件
+     *
+     * @param device   设备信息
+     * @param eventKey 事件标记
+     * @param detail   事件详情
+     * @param date     时间戳
+     */
+    public void triggerEvent(EmsDevice device, String eventKey, String detail, Date date) {
+        EmsObjEventLog eventLog = new EmsObjEventLog();
+        eventLog.setObjCode(device.getDeviceCode());
+        eventLog.setModelCode(device.getDeviceModel());
+        eventLog.setEventKey(eventKey);
+        eventLog.setEventTime(date);
+        eventLog.setEventDetail(detail);
+        objEventLogService.insertLog(eventLog);
+    }
+
     protected static int getHourIndex(Date date) {
         Calendar calendar = Calendar.getInstance();
         calendar.setTime(date);

+ 26 - 0
ems/ems-cloud/ems-server/src/main/java/com/ruoyi/ems/controller/EmsObjLogController.java

@@ -8,9 +8,11 @@ import com.ruoyi.common.log.enums.BusinessType;
 import com.ruoyi.common.security.annotation.RequiresPermissions;
 import com.ruoyi.ems.domain.ElecAttr;
 import com.ruoyi.ems.domain.EmsObjAbilityCallLog;
+import com.ruoyi.ems.domain.EmsObjEventLog;
 import com.ruoyi.ems.domain.EmsObjReportLog;
 import com.ruoyi.ems.service.IElecAttrService;
 import com.ruoyi.ems.service.IEmsObjAbilityCallLogService;
+import com.ruoyi.ems.service.IEmsObjEventLogService;
 import com.ruoyi.ems.service.IEmsObjReportLogService;
 import io.swagger.annotations.Api;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -43,6 +45,12 @@ public class EmsObjLogController extends BaseController {
     private IEmsObjReportLogService reportLogService;
 
     /**
+     * 事件日志
+     */
+    @Autowired
+    private IEmsObjEventLogService eventLogService;
+
+    /**
      * 能力调用日志
      */
     @Autowired
@@ -69,6 +77,24 @@ public class EmsObjLogController extends BaseController {
     /**
      * 获取上报日志详细
      */
+    @GetMapping(value = "/eventLog/{id}")
+    public AjaxResult getEventLogInfo(@PathVariable("id") Long id) {
+        return success(eventLogService.selectLogById(id));
+    }
+
+    /**
+     * 查询上报日志列表
+     */
+    @GetMapping("/eventLog/list")
+    public TableDataInfo listEventLog(EmsObjEventLog param) {
+        startPage();
+        List<EmsObjEventLog> list = eventLogService.selectLog(param);
+        return getDataTable(list);
+    }
+
+    /**
+     * 获取上报日志详细
+     */
     @GetMapping(value = "/callLog/{id}")
     public AjaxResult getCallLogInfo(@PathVariable("id") Long id) {
         return success(abilityCallLogService.selectLogById(id));

+ 0 - 202
ems/ems-core/src/main/java/com/ruoyi/ems/domain/ElecUseH.java

@@ -1,202 +0,0 @@
-package com.ruoyi.ems.domain;
-
-import com.fasterxml.jackson.annotation.JsonFormat;
-import com.huashe.common.annotation.Excel;
-import com.huashe.common.domain.BaseEntity;
-import org.apache.commons.lang3.builder.ToStringBuilder;
-import org.apache.commons.lang3.builder.ToStringStyle;
-
-import java.sql.Time;
-import java.util.Date;
-
-/**
- * 用能计量-小时对象 adm_ems_obj_use_h
- * 
- * @author ruoyi
- * @date 2024-08-15
- */
-@Deprecated
-public class ElecUseH extends BaseEntity
-{
-    private static final long serialVersionUID = 1L;
-
-    /** 序号 */
-    private Long id;
-
-    /** 园区代码 */
-    private String areaCode;
-
-    @Excel(name = "服务区")
-    private String areaName;
-
-    private String areaShortName;
-
-    /** 对象类型 */
-    private Integer objType;
-
-    /** 对象代码 */
-    private String objCode;
-
-    @Excel(name = "对象名称")
-    private String objName;
-
-    /** 设施类型 */
-    @Excel(name = "设施类别")
-    private String facsCategory;
-
-    /** 设施子类 */
-    @Excel(name = "设施子类别")
-    private String facsSubCategory;
-
-    /** 记录时间 */
-    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
-    private Date recordTime;
-
-    /** 日期 yyyy-MM-dd */
-    @JsonFormat(pattern = "yyyy-MM-dd")
-    @Excel(name = "日期 yyyy-MM-dd", width = 30, dateFormat = "yyyy-MM-dd")
-    private Date date;
-
-    /** 时间 HH:mm:ss */
-    @JsonFormat(pattern = "HH:mm:ss")
-    @Excel(name = "时间 HH:mm:ss", width = 30, dateFormat = "HH:mm:ss")
-    private Time time;
-
-    /** 时间序列 */
-    @Excel(name = "时间序列")
-    private Long timeIndex;
-
-
-    /** 用电量 单位:kW-h(千瓦时) */
-    @Excel(name = "用电量 单位:kW·h")
-    private Double elecQuantity;
-
-    public Long getId() {
-        return id;
-    }
-
-    public void setId(Long id) {
-        this.id = id;
-    }
-
-    public String getAreaCode() {
-        return areaCode;
-    }
-
-    public void setAreaCode(String areaCode) {
-        this.areaCode = areaCode;
-    }
-
-    public String getAreaName() {
-        return areaName;
-    }
-
-    public void setAreaName(String areaName) {
-        this.areaName = areaName;
-    }
-
-    public String getAreaShortName() {
-        return areaShortName;
-    }
-
-    public void setAreaShortName(String areaShortName) {
-        this.areaShortName = areaShortName;
-    }
-
-    public Integer getObjType() {
-        return objType;
-    }
-
-    public void setObjType(Integer objType) {
-        this.objType = objType;
-    }
-
-    public String getObjCode() {
-        return objCode;
-    }
-
-    public void setObjCode(String objCode) {
-        this.objCode = objCode;
-    }
-
-    public String getObjName() {
-        return objName;
-    }
-
-    public void setObjName(String objName) {
-        this.objName = objName;
-    }
-
-    public String getFacsCategory() {
-        return facsCategory;
-    }
-
-    public void setFacsCategory(String facsCategory) {
-        this.facsCategory = facsCategory;
-    }
-
-    public String getFacsSubCategory() {
-        return facsSubCategory;
-    }
-
-    public void setFacsSubCategory(String facsSubCategory) {
-        this.facsSubCategory = facsSubCategory;
-    }
-
-    public Date getRecordTime() {
-        return recordTime;
-    }
-
-    public void setRecordTime(Date recordTime) {
-        this.recordTime = recordTime;
-    }
-
-    public Date getDate() {
-        return date;
-    }
-
-    public void setDate(Date date) {
-        this.date = date;
-    }
-
-    public Time getTime() {
-        return time;
-    }
-
-    public void setTime(Time time) {
-        this.time = time;
-    }
-
-    public Long getTimeIndex() {
-        return timeIndex;
-    }
-
-    public void setTimeIndex(Long timeIndex) {
-        this.timeIndex = timeIndex;
-    }
-
-    public Double getElecQuantity() {
-        return elecQuantity;
-    }
-
-    public void setElecQuantity(Double elecQuantity) {
-        this.elecQuantity = elecQuantity;
-    }
-
-    @Override
-    public String toString() {
-        return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
-            .append("id", getId())
-            .append("areaCode", getAreaCode())
-            .append("objType", getObjType())
-            .append("objCode", getObjCode())
-            .append("objName", getObjName())
-            .append("facsCategory", getFacsCategory())
-            .append("facsSubCategory", getFacsSubCategory())
-            .append("date", getDate())
-            .append("time", getTime())
-            .append("timeIndex", getTimeIndex())
-            .append("elecQuantity", getElecQuantity())
-            .toString();
-    }
-}

+ 129 - 0
ems/ems-core/src/main/java/com/ruoyi/ems/domain/EmsObjEventLog.java

@@ -0,0 +1,129 @@
+package com.ruoyi.ems.domain;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.huashe.common.domain.BaseEntity;
+import org.apache.commons.lang3.builder.ToStringBuilder;
+import org.apache.commons.lang3.builder.ToStringStyle;
+
+import java.util.Date;
+
+/**
+ * 能源对象上报日志表 adm_ems_obj_report_log
+ *
+ * @author ruoyi
+ * @date 2025-02-27
+ */
+public class EmsObjEventLog extends BaseEntity {
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 序号
+     */
+    private Long id;
+
+    /**
+     * 对象代码
+     */
+    private String objCode;
+
+    private String objName;
+
+    /**
+     * 对象类型
+     */
+    private String modelCode;
+
+    /**
+     * 事件标识
+     */
+    private String eventKey;
+
+    private String eventName;
+
+    /**
+     * 响应时间
+     */
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private Date eventTime;
+
+    /**
+     * 响应内容
+     */
+    private String eventDetail;
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getObjCode() {
+        return objCode;
+    }
+
+    public void setObjCode(String objCode) {
+        this.objCode = objCode;
+    }
+
+    public String getObjName() {
+        return objName;
+    }
+
+    public void setObjName(String objName) {
+        this.objName = objName;
+    }
+
+    public String getModelCode() {
+        return modelCode;
+    }
+
+    public void setModelCode(String modelCode) {
+        this.modelCode = modelCode;
+    }
+
+    public String getEventKey() {
+        return eventKey;
+    }
+
+    public void setEventKey(String eventKey) {
+        this.eventKey = eventKey;
+    }
+
+    public String getEventName() {
+        return eventName;
+    }
+
+    public void setEventName(String eventName) {
+        this.eventName = eventName;
+    }
+
+    public Date getEventTime() {
+        return eventTime;
+    }
+
+    public void setEventTime(Date eventTime) {
+        this.eventTime = eventTime;
+    }
+
+    public String getEventDetail() {
+        return eventDetail;
+    }
+
+    public void setEventDetail(String eventDetail) {
+        this.eventDetail = eventDetail;
+    }
+
+    @Override
+    public String toString() {
+        return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
+            .append("id", getId())
+            .append("objCode", getObjCode())
+            .append("modelCode", getModelCode())
+            .append("eventKey", getEventKey())
+            .append("eventName", getEventName())
+            .append("eventTime", getEventTime())
+            .append("eventDetail", getEventDetail()).toString();
+    }
+}

+ 37 - 0
ems/ems-core/src/main/java/com/ruoyi/ems/mapper/EmsObjEventLogMapper.java

@@ -0,0 +1,37 @@
+package com.ruoyi.ems.mapper;
+
+import com.ruoyi.ems.domain.EmsObjEventLog;
+
+import java.util.List;
+
+/**
+ * 能源对象能力调用日志Mapper接口
+ *
+ * @author ruoyi
+ * @date 2025-02-27
+ */
+public interface EmsObjEventLogMapper {
+    /**
+     * 查询能源对象能力调用日志
+     *
+     * @param id 能源对象能力调用日志主键
+     * @return 能源对象能力调用日志
+     */
+    EmsObjEventLog selectLogById(Long id);
+
+    /**
+     * 查询能源对象能力调用日志列表
+     *
+     * @param objEventLog 能源对象能力调用日志
+     * @return 能源对象能力调用日志集合
+     */
+    List<EmsObjEventLog> selectLog(EmsObjEventLog objEventLog);
+
+    /**
+     * 新增能源对象能力调用日志
+     *
+     * @param objEventLog 能源对象能力调用日志
+     * @return 结果
+     */
+    int insertLog(EmsObjEventLog objEventLog);
+}

+ 38 - 0
ems/ems-core/src/main/java/com/ruoyi/ems/service/IEmsObjEventLogService.java

@@ -0,0 +1,38 @@
+package com.ruoyi.ems.service;
+
+import com.ruoyi.ems.domain.EmsObjEventLog;
+import com.ruoyi.ems.domain.EmsObjReportLog;
+
+import java.util.List;
+
+/**
+ * 能源对象能力调用日志Mapper接口
+ *
+ * @author ruoyi
+ * @date 2025-02-27
+ */
+public interface IEmsObjEventLogService {
+    /**
+     * 查询能源对象能力调用日志
+     *
+     * @param id 能源对象能力调用日志主键
+     * @return 能源对象能力调用日志
+     */
+    EmsObjEventLog selectLogById(Long id);
+
+    /**
+     * 查询能源对象能力调用日志列表
+     *
+     * @param objEventLog 能源对象能力调用日志
+     * @return 能源对象能力调用日志集合
+     */
+    List<EmsObjEventLog> selectLog(EmsObjEventLog objEventLog);
+
+    /**
+     * 新增能源对象能力调用日志
+     *
+     * @param objEventLog 能源对象能力调用日志
+     * @return 结果
+     */
+    int insertLog(EmsObjEventLog objEventLog);
+}

+ 0 - 8
ems/ems-core/src/main/java/com/ruoyi/ems/service/IEmsObjEventService.java

@@ -68,14 +68,6 @@ public interface IEmsObjEventService {
     int deleteObjEventByIds(Long[] ids);
 
     /**
-     * 删除能源对象事件信息
-     *
-     * @param id 能源对象事件主键
-     * @return 结果
-     */
-    int deleteObjEventById(Long id);
-
-    /**
      * 根据模型编号删除
      *
      * @param modelCode 模型编号

+ 49 - 0
ems/ems-core/src/main/java/com/ruoyi/ems/service/impl/EmsObjEventLogServiceImpl.java

@@ -0,0 +1,49 @@
+/*
+ * 文 件 名:  EmsObjReportLogService
+ * 版    权:  华设设计集团股份有限公司
+ * 描    述:  <描述>
+ * 修 改 人:  lvwenbin
+ * 修改时间:  2025/3/11
+ * 跟踪单号:  <跟踪单号>
+ * 修改单号:  <修改单号>
+ * 修改内容:  <修改内容>
+ */
+package com.ruoyi.ems.service.impl;
+
+import com.ruoyi.ems.domain.EmsObjEventLog;
+import com.ruoyi.ems.mapper.EmsObjEventLogMapper;
+import com.ruoyi.ems.service.IEmsObjEventLogService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+/**
+ * 对象上报日志服务
+ * <功能详细描述>
+ *
+ * @author lvwenbin
+ * @version [版本号, 2025/3/11]
+ * @see [相关类/方法]
+ * @since [产品/模块版本]
+ */
+@Service
+public class EmsObjEventLogServiceImpl implements IEmsObjEventLogService {
+    @Autowired
+    private EmsObjEventLogMapper emsObjEventLogMapper;
+
+    @Override
+    public EmsObjEventLog selectLogById(Long id) {
+        return emsObjEventLogMapper.selectLogById(id);
+    }
+
+    @Override
+    public List<EmsObjEventLog> selectLog(EmsObjEventLog objEventLog) {
+        return emsObjEventLogMapper.selectLog(objEventLog);
+    }
+
+    @Override
+    public int insertLog(EmsObjEventLog objEventLog) {
+        return emsObjEventLogMapper.insertLog(objEventLog);
+    }
+}

+ 0 - 11
ems/ems-core/src/main/java/com/ruoyi/ems/service/impl/EmsObjEventServiceImpl.java

@@ -84,17 +84,6 @@ public class EmsObjEventServiceImpl implements IEmsObjEventService {
         return objEventMapper.deleteObjEventByIds(ids);
     }
 
-    /**
-     * 删除能源对象事件信息
-     *
-     * @param id 能源对象事件主键
-     * @return 结果
-     */
-    @Override
-    public int deleteObjEventById(Long id) {
-        return objEventMapper.deleteObjEventById(id);
-    }
-
     @Override
     public int deleteByModelCode(String modelCode) {
         return objEventMapper.deleteByModelCode(modelCode);

+ 1 - 1
ems/ems-core/src/main/java/com/ruoyi/ems/service/impl/EmsObjReportLogService.java → ems/ems-core/src/main/java/com/ruoyi/ems/service/impl/EmsObjReportLogServiceImpl.java

@@ -28,7 +28,7 @@ import java.util.List;
  * @since [产品/模块版本]
  */
 @Service
-public class EmsObjReportLogService implements IEmsObjReportLogService {
+public class EmsObjReportLogServiceImpl implements IEmsObjReportLogService {
     @Autowired
     private EmsObjReportLogMapper emsObjReportLogMapper;
 

+ 0 - 2
ems/ems-core/src/main/resources/mapper/ems/AreaMapper.xml

@@ -28,8 +28,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="ancestors != null  and ancestors != ''"> and ancestors = #{ancestors}</if>
             <if test="areaName != null  and areaName != ''"> and area_name like concat('%', #{areaName}, '%')</if>
             <if test="shortName != null  and shortName != ''"> and short_name like concat('%', #{shortName}, '%')</if>
-            <if test="desc != null  and desc != ''"> and `desc` = #{desc}</if>
-            <if test="orderNum != null "> and order_num = #{orderNum}</if>
             <if test="status != null "> and status = #{status}</if>
         </where>
     </select>

+ 80 - 0
ems/ems-core/src/main/resources/mapper/ems/EmsObjEventLogMapper.xml

@@ -0,0 +1,80 @@
+<?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.ruoyi.ems.mapper.EmsObjEventLogMapper">
+    
+    <resultMap type="com.ruoyi.ems.domain.EmsObjEventLog" id="objLogResult">
+        <result property="id"             column="id"    />
+        <result property="objCode"        column="obj_code"    />
+        <result property="objName"        column="obj_name"    />
+        <result property="modelCode"      column="model_code"    />
+        <result property="eventKey"       column="event_key"    />
+        <result property="eventName"       column="event_name"    />
+        <result property="eventDetail"    column="event_detail"    />
+        <result property="eventTime"      column="event_time"    />
+    </resultMap>
+
+    <sql id="selectList">
+        select l.id, l.obj_code,
+               CASE
+                   WHEN m.obj_type = 1 THEN f.facs_name
+                   WHEN m.obj_type = 2 THEN d.device_name
+                   END as obj_name,
+               l.model_code, l.event_key, e.event_name, l.event_time
+        from adm_ems_obj_event_log l
+                 left join adm_ems_obj_model m on l.model_code = m.model_code
+                 left join adm_ems_facs f on l.obj_code = f.facs_code and m.obj_type = 1
+                 left join adm_ems_device d on l.obj_code = d.device_code and m.obj_type = 2
+                 left join adm_ems_obj_event e on l.model_code = e.model_code and l.event_key = e.event_key
+    </sql>
+
+    <sql id="selectDetail">
+        select l.id, l.obj_code,
+               CASE
+                   WHEN m.obj_type = 1 THEN f.facs_name
+                   WHEN m.obj_type = 2 THEN d.device_name
+                   END as obj_name,
+               l.model_code, l.event_key, e.event_name, l.event_time, l.event_detail
+        from adm_ems_obj_event_log l
+                 left join adm_ems_obj_model m on l.model_code = m.model_code
+                 left join adm_ems_facs f on l.obj_code = f.facs_code and m.obj_type = 1
+                 left join adm_ems_device d on l.obj_code = d.device_code and m.obj_type = 2
+                 left join adm_ems_obj_event e on l.model_code = e.model_code and l.event_key = e.event_key
+    </sql>
+
+    <select id="selectLogById" parameterType="java.lang.Long" resultMap="objLogResult">
+        <include refid="selectDetail"/>
+        where l.id = #{id}
+    </select>
+
+    <select id="selectLog" parameterType="com.ruoyi.ems.domain.EmsObjEventLog" resultMap="objLogResult">
+        <include refid="selectList"/>
+        <where>  
+            <if test="objCode != null  and objCode != ''"> and l.obj_code = #{objCode}</if>
+            <if test="modelCode != null and modelCode != ''"> and l.model_code = #{modelCode}</if>
+            <if test="startRecTime != null  and startRecTime != '' and endRecTime != null and endRecTime !=''">
+                and l.report_time between #{startRecTime} and #{endRecTime}
+            </if>
+            <if test="eventKey != null and eventKey != ''"> and l.event_key = #{eventKey}</if>
+        </where>
+    </select>
+
+    <insert id="insertLog" parameterType="com.ruoyi.ems.domain.EmsObjEventLog" useGeneratedKeys="true" keyProperty="id">
+        insert into adm_ems_obj_event_log
+        <trim prefix="(" suffix=")" suffixOverrides=",">
+            <if test="objCode != null and objCode != ''">obj_code,</if>
+            <if test="modelCode != null and modelCode != ''">model_code,</if>
+            <if test="eventKey != null and eventKey != ''">event_key,</if>
+            <if test="eventTime != null">event_time,</if>
+            <if test="eventDetail != null">event_detail,</if>
+         </trim>
+        <trim prefix="values (" suffix=")" suffixOverrides=",">
+            <if test="objCode != null and objCode != ''">#{objCode},</if>
+            <if test="modelCode != null and modelCode != ''">#{modelCode},</if>
+            <if test="eventKey != null and eventKey != ''">#{eventKey},</if>
+            <if test="eventTime != null">#{eventTime},</if>
+            <if test="eventDetail != null">#{eventDetail},</if>
+         </trim>
+    </insert>
+</mapper>

+ 2 - 0
ems/ems-core/src/main/resources/mapper/ems/EmsObjModelMapper.xml

@@ -61,7 +61,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="modelName != null and modelName != ''">model_name = #{modelName},</if>
             <if test="objType != null">obj_type = #{objType},</if>
             <if test="abilityHandler != null and abilityHandler !=''">ability_handler = #{abilityHandler},</if>
+            <if test="abilityHandler == null or abilityHandler ==''">ability_handler = null,</if>
             <if test="eventHandler != null and eventHandler !=''">event_handler = #{eventHandler},</if>
+            <if test="eventHandler == null or eventHandler ==''">event_handler = null,</if>
         </trim>
         where id = #{id}
     </update>

+ 10 - 9
ems/sql/ems_init_data.sql

@@ -302,17 +302,18 @@ INSERT INTO `adm_ems_obj_attr_value` (`obj_code`, `model_code`, `attr_key`, `att
 INSERT INTO `adm_ems_obj_attr_value` (`obj_code`, `model_code`, `attr_key`, `attr_value`, `update_time`) VALUES ('864142073640059', 'M_W2_QF_GEEKOPEN', 'version', '1.0.1', '2025-03-05 15:51:00');
 
 -- 对象属性值枚举
-INSERT INTO `adm_ems_obj_attr_enum` (`model_code`, `attr_key`, `attr_value`, `attr_value_name`) VALUES ('M_W2_QF_GEEKOPEN', 'onState', '1', '断开');
-INSERT INTO `adm_ems_obj_attr_enum` (`model_code`, `attr_key`, `attr_value`, `attr_value_name`) VALUES ('M_W2_QF_GEEKOPEN', 'key', '1', '通电');
-INSERT INTO `adm_ems_obj_attr_enum` (`model_code`, `attr_key`, `attr_value`, `attr_value_name`) VALUES ('M_W2_QF_GEEKOPEN', 'key', '0', '断电');
+INSERT INTO `adm_ems_obj_attr_enum` (`model_code`, `attr_key`, `attr_value`, `attr_value_name`) VALUES ('M_W2_QF_GEEKOPEN', 'onState', '0', '记忆');
+INSERT INTO `adm_ems_obj_attr_enum` (`model_code`, `attr_key`, `attr_value`, `attr_value_name`) VALUES ('M_W2_QF_GEEKOPEN', 'onState', '1', '分闸');
+INSERT INTO `adm_ems_obj_attr_enum` (`model_code`, `attr_key`, `attr_value`, `attr_value_name`) VALUES ('M_W2_QF_GEEKOPEN', 'onState', '2', '合闸');
+INSERT INTO `adm_ems_obj_attr_enum` (`model_code`, `attr_key`, `attr_value`, `attr_value_name`) VALUES ('M_W2_QF_GEEKOPEN', 'key', '1', '合闸');
+INSERT INTO `adm_ems_obj_attr_enum` (`model_code`, `attr_key`, `attr_value`, `attr_value_name`) VALUES ('M_W2_QF_GEEKOPEN', 'key', '0', '分闸');
 INSERT INTO `adm_ems_obj_attr_enum` (`model_code`, `attr_key`, `attr_value`, `attr_value_name`) VALUES ('M_W2_QF_GEEKOPEN', 'timerEnable', '0', '关闭');
 INSERT INTO `adm_ems_obj_attr_enum` (`model_code`, `attr_key`, `attr_value`, `attr_value_name`) VALUES ('M_W2_QF_GEEKOPEN', 'timerEnable', '1', '开启');
 INSERT INTO `adm_ems_obj_attr_enum` (`model_code`, `attr_key`, `attr_value`, `attr_value_name`) VALUES ('M_W2_QF_GEEKOPEN', 'keyLock', '0', '关闭');
 INSERT INTO `adm_ems_obj_attr_enum` (`model_code`, `attr_key`, `attr_value`, `attr_value_name`) VALUES ('M_W2_QF_GEEKOPEN', 'keyLock', '1', '开启');
 INSERT INTO `adm_ems_obj_attr_enum` (`model_code`, `attr_key`, `attr_value`, `attr_value_name`) VALUES ('M_W2_QF_GEEKOPEN', 'resetLock', '0', '关闭');
 INSERT INTO `adm_ems_obj_attr_enum` (`model_code`, `attr_key`, `attr_value`, `attr_value_name`) VALUES ('M_W2_QF_GEEKOPEN', 'resetLock', '1', '开启');
-INSERT INTO `adm_ems_obj_attr_enum` (`model_code`, `attr_key`, `attr_value`, `attr_value_name`) VALUES ('M_W2_QF_GEEKOPEN', 'onState', '0', '记忆');
-INSERT INTO `adm_ems_obj_attr_enum` (`model_code`, `attr_key`, `attr_value`, `attr_value_name`) VALUES ('M_W2_QF_GEEKOPEN', 'onState', '2', '通电');
+
 
 -- 对象能力DEMO数据
 INSERT INTO `adm_ems_obj_ability` (`model_code`, `ability_key`, `ability_name`, `ability_desc`, `ability_param`, `hidden_flag`) VALUES ('M_W2_QF_GEEKOPEN', 'Circuit-Closing', '分闸', '控制线路断电', '{\"type\":\"event\",\"key\":0}', 1);
@@ -323,9 +324,9 @@ INSERT INTO `adm_ems_obj_ability` (`model_code`, `ability_key`, `ability_name`,
 INSERT INTO `adm_ems_obj_ability` (`model_code`, `ability_key`, `ability_name`, `ability_desc`, `ability_param`, `hidden_flag`) VALUES ('M_W2_QF_GEEKOPEN', 'settAutoReport', '设置电量信息定时上报', '设置电量信息定时上报(timerEnable:0:关闭上报 1:开启上报) timerInterval: 上报时间间隔单位秒', '{\"type\":\"setting\",\"timerEnable\":1,\"timerInterval\":900}', 0);
 INSERT INTO `adm_ems_obj_ability` (`model_code`, `ability_key`, `ability_name`, `ability_desc`, `ability_param`, `hidden_flag`) VALUES ('M_W2_QF_GEEKOPEN', 'setReset', '重置/恢复出厂', '设备恢复出厂设置固定传\"reset\"', '{\"type\":\"setting\",\"system\":\"reset\"}', 0);
 INSERT INTO `adm_ems_obj_ability` (`model_code`, `ability_key`, `ability_name`, `ability_desc`, `ability_param`, `hidden_flag`) VALUES ('M_W2_QF_GEEKOPEN', 'setOnState', '设置默认上电状态', '0:记忆;1:关闭,即断开;2:开启,即通电,默认=1', '{\"type\":\"setting\",\"onState\":1}', 0);
-INSERT INTO `adm_ems_obj_ability` (`model_code`, `ability_key`, `ability_name`, `ability_desc`, `ability_param`, `hidden_flag`) VALUES ('M_W2_QF_GEEKOPEN', 'syncProtocol', '同步设备通讯信息', '获取设备通讯信息', '{\"type\":\"protocol\"}', 0);
-INSERT INTO `adm_ems_obj_ability` (`model_code`, `ability_key`, `ability_name`, `ability_desc`, `ability_param`, `hidden_flag`) VALUES ('M_W2_QF_GEEKOPEN', 'syncStatistic', '同步设备电量信息', '获取设备电量信息', '{\"type\":\"statistic\"}', 1);
-INSERT INTO `adm_ems_obj_ability` (`model_code`, `ability_key`, `ability_name`, `ability_desc`, `ability_param`, `hidden_flag`) VALUES ('M_W2_QF_GEEKOPEN', 'syncInfo', '同步基础信息', '获取设备状态信息', '{\"type\":\"info\"}', 0);
+INSERT INTO `adm_ems_obj_ability` (`model_code`, `ability_key`, `ability_name`, `ability_desc`, `ability_param`, `hidden_flag`) VALUES ('M_W2_QF_GEEKOPEN', 'syncProtocol', '触发通讯信息同步', '获取设备通讯信息', '{\"type\":\"protocol\"}', 0);
+INSERT INTO `adm_ems_obj_ability` (`model_code`, `ability_key`, `ability_name`, `ability_desc`, `ability_param`, `hidden_flag`) VALUES ('M_W2_QF_GEEKOPEN', 'syncStatistic', '触发电量信息同步', '获取设备电量信息', '{\"type\":\"statistic\"}', 1);
+INSERT INTO `adm_ems_obj_ability` (`model_code`, `ability_key`, `ability_name`, `ability_desc`, `ability_param`, `hidden_flag`) VALUES ('M_W2_QF_GEEKOPEN', 'syncInfo', '触发基础信息同步', '获取设备状态信息', '{\"type\":\"info\"}', 0);
 
 -- 对象事件DEMO数据
 INSERT INTO `adm_ems_obj_event` (`model_code`, `event_type`, `event_key`, `event_name`, `event_desc`, `event_code`, `ext_event_code`) VALUES ('M_W2', 2, 'overload', '过载', '功率过载', 'e-gy-0001', '0x0001');
@@ -535,7 +536,7 @@ INSERT INTO adm_gw_elecprice_config (`cfg_code`, `elec_type`, `voltage_level`, `
 
 -- 峰谷电价策略数据
 -- 默认策略
-INSERT INTO adm_elecprice_strategy (`strategy_code`, `strategy_name`, `strategy_desc`, `repeat_type`, `repeat_param`, `priority`, `edit_flag`) VALUES ('-1', '默认策略', '0:00-24:00 执行平电价', 2, null, 0, 0);
+INSERT INTO adm_elecprice_strategy (`strategy_code`, `strategy_name`, `strategy_desc`, `repeat_type`, `repeat_param`, `priority`, `edit_flag`) VALUES ('-1', '默认策略', '0:00-24:00 执行平电价', 2, null, 0, 0);
 INSERT INTO adm_elecprice_strategy_hour (`strategy_code`, `start_time`, `end_time`, `type`) VALUES ('-1', '00:00:00', '23:59:59', 0);
 
 -- 默认策略

+ 18 - 2
ems/sql/ems_server.sql

@@ -406,7 +406,7 @@ create table adm_area (
   `ancestors`      varchar(1024)   default null               comment '祖籍列表',
   `area_name`      varchar(64)     not null                   comment '区域名称',
   `short_name`     varchar(32)     default null               comment '区域简称',
-  `desc`           varchar(128)    default null               comment '区域简称',
+  `desc`           varchar(128)    default null               comment '区域描述',
   `order_num`      int             default null               comment '显示顺序',
   `status`         int             default null               comment '区域状态',
   primary key (`id`),
@@ -682,7 +682,7 @@ create table adm_ems_obj_report_log  (
   `report_time`     datetime        not null                     comment '上报时间',
   `report_payload`  text            default null                 comment '上报参数',
   primary key (`id`),
-  key i_obj_report_log(`obj_code`, `model_code`, `report_time`)
+  key i_obj_report_log(`obj_code`, `report_time`)
 ) engine=innodb auto_increment=1 comment = '能源对象上报日志表';
 
 
@@ -705,6 +705,22 @@ create table adm_ems_obj_event  (
 
 
 -- ----------------------------
+-- 能源对象能力事件日志表
+-- ----------------------------
+drop table if exists adm_ems_obj_event_log;
+create table adm_ems_obj_event_log  (
+    `id`              bigint(20)      not null auto_increment      comment '序号',
+    `obj_code`        varchar(64)     not null                     comment '对象代码',
+    `model_code`      varchar(64)     not null                     comment '模型code',
+    `event_key`       varchar(128)    not null                     comment '事件标识',
+    `event_time`      datetime        not null                     comment '事件时间',
+    `event_detail`    text            default null                 comment '事件详情',
+    primary key (`id`),
+    key i_obj_event_log(`obj_code`, `event_time`, `event_key`)
+) engine=innodb auto_increment=1 comment = '能源对象事件日志表';
+
+
+-- ----------------------------
 -- 能源子系统表
 -- ----------------------------
 drop table if exists adm_ems_subsystem;