Преглед изворни кода

Merge remote-tracking branch 'origin/master'

chen.cheng пре 4 месеци
родитељ
комит
668d111391
39 измењених фајлова са 820 додато и 433 уклоњено
  1. 2 1
      ems/ems-application/ems-admin/src/main/java/com/ruoyi/web/controller/ems/EmsObjAttrController.java
  2. 41 1
      ems/ems-application/ems-admin/src/main/java/com/ruoyi/web/controller/ems/EmsObjAttrValueController.java
  3. 5 4
      ems/ems-application/ems-admin/src/main/java/com/ruoyi/web/controller/ems/MeterDeviceController.java
  4. 72 0
      ems/ems-cloud/ems-dev-adapter/src/main/java/com/ruoyi/ems/TaskExecutor.java
  5. 2 2
      ems/ems-cloud/ems-dev-adapter/src/main/java/com/ruoyi/ems/controller/CircuitBreakerController.java
  6. 13 11
      ems/ems-cloud/ems-dev-adapter/src/main/java/com/ruoyi/ems/core/ObjectCache.java
  7. 21 142
      ems/ems-cloud/ems-dev-adapter/src/main/java/com/ruoyi/ems/handle/GeekOpenCbHandler.java
  8. 248 30
      ems/ems-cloud/ems-dev-adapter/src/main/java/com/ruoyi/ems/handle/MqttBaseHandler.java
  9. 0 1
      ems/ems-cloud/ems-dev-adapter/src/main/java/com/ruoyi/ems/handle/RootMsgHandler.java
  10. 1 10
      ems/ems-cloud/ems-server/src/main/java/com/ruoyi/ems/controller/AreaController.java
  11. 2 2
      ems/ems-cloud/ems-server/src/main/java/com/ruoyi/ems/controller/EmsObjAbilityController.java
  12. 40 1
      ems/ems-cloud/ems-server/src/main/java/com/ruoyi/ems/controller/EmsObjAttrValueController.java
  13. 7 4
      ems/ems-cloud/ems-server/src/main/java/com/ruoyi/ems/controller/EmsObjLogController.java
  14. 84 6
      ems/ems-cloud/ems-server/src/main/java/com/ruoyi/ems/controller/MeterDeviceController.java
  15. 13 0
      ems/ems-core/src/main/java/com/ruoyi/ems/domain/ElecMeterH.java
  16. 0 12
      ems/ems-core/src/main/java/com/ruoyi/ems/domain/EmsObjAbilityCallLog.java
  17. 5 17
      ems/ems-core/src/main/java/com/ruoyi/ems/domain/EmsObjAttrValue.java
  18. 6 6
      ems/ems-core/src/main/java/com/ruoyi/ems/domain/EmsObjReportLog.java
  19. 15 0
      ems/ems-core/src/main/java/com/ruoyi/ems/mapper/ElecMeterHMapper.java
  20. 4 4
      ems/ems-core/src/main/java/com/ruoyi/ems/mapper/EmsObjAttrValueMapper.java
  21. 9 3
      ems/ems-core/src/main/java/com/ruoyi/ems/mapper/MeterDeviceMapper.java
  22. 0 13
      ems/ems-core/src/main/java/com/ruoyi/ems/model/AbilityPayload.java
  23. 17 1
      ems/ems-core/src/main/java/com/ruoyi/ems/service/IAbilityCallService.java
  24. 15 0
      ems/ems-core/src/main/java/com/ruoyi/ems/service/IElecMeterHService.java
  25. 4 4
      ems/ems-core/src/main/java/com/ruoyi/ems/service/IEmsObjAttrValueService.java
  26. 13 7
      ems/ems-core/src/main/java/com/ruoyi/ems/service/IMeterDeviceService.java
  27. 15 16
      ems/ems-core/src/main/java/com/ruoyi/ems/service/impl/AbilityCallServiceImpl.java
  28. 10 0
      ems/ems-core/src/main/java/com/ruoyi/ems/service/impl/ElecMeterHServiceImpl.java
  29. 5 5
      ems/ems-core/src/main/java/com/ruoyi/ems/service/impl/EmsObjAttrValueServiceImpl.java
  30. 5 5
      ems/ems-core/src/main/java/com/ruoyi/ems/service/impl/MeterDeviceServiceImpl.java
  31. 1 1
      ems/ems-core/src/main/java/com/ruoyi/ems/util/AreaUtils.java
  32. 27 1
      ems/ems-core/src/main/resources/mapper/ems/ElecMeterHMapper.xml
  33. 13 18
      ems/ems-core/src/main/resources/mapper/ems/EmsObjAbilityCallLogMapper.xml
  34. 3 4
      ems/ems-core/src/main/resources/mapper/ems/EmsObjAttrMapper.xml
  35. 6 10
      ems/ems-core/src/main/resources/mapper/ems/EmsObjAttrValueMapper.xml
  36. 29 19
      ems/ems-core/src/main/resources/mapper/ems/EmsObjReportLogMapper.xml
  37. 17 14
      ems/ems-core/src/main/resources/mapper/ems/MeterDeviceMapper.xml
  38. 44 51
      ems/sql/ems_init_data.sql
  39. 6 7
      ems/sql/ems_server.sql

+ 2 - 1
ems/ems-application/ems-admin/src/main/java/com/ruoyi/web/controller/ems/EmsObjAttrController.java

@@ -107,11 +107,12 @@ public class EmsObjAttrController extends BaseController {
             JSONObject json = new JSONObject();
             json.put("objType", objType);
             json.put("objCode", objCode);
+            json.put("modeCode", modeCode);
 
             List<EmsObjAttr> modelAttrs = attrService.selectByModelCode(modeCode);
             json.put("attrs", CollectionUtils.isNotEmpty(modelAttrs) ? modelAttrs : new ArrayList<>());
 
-            List<EmsObjAttrValue> attrValues = objAttrValueService.selectByObjCode(objType, objCode);
+            List<EmsObjAttrValue> attrValues = objAttrValueService.selectByObjCode(modeCode, objCode);
             json.put("attrValues", attrValues);
 
             result = success(json);

+ 41 - 1
ems/ems-application/ems-admin/src/main/java/com/ruoyi/web/controller/ems/EmsObjAttrValueController.java

@@ -4,7 +4,15 @@ import com.huashe.common.domain.AjaxResult;
 import com.ruoyi.common.annotation.Log;
 import com.ruoyi.common.core.controller.BaseController;
 import com.ruoyi.common.enums.BusinessType;
+import com.ruoyi.common.exception.Assert;
+import com.ruoyi.ems.domain.EmsDevice;
+import com.ruoyi.ems.domain.EmsDeviceComponent;
+import com.ruoyi.ems.domain.EmsFacs;
 import com.ruoyi.ems.domain.EmsObjAttrValue;
+import com.ruoyi.ems.enums.DevObjType;
+import com.ruoyi.ems.service.IEmsDeviceComponentService;
+import com.ruoyi.ems.service.IEmsDeviceService;
+import com.ruoyi.ems.service.IEmsFacsService;
 import com.ruoyi.ems.service.IEmsObjAttrValueService;
 import io.swagger.annotations.Api;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -33,6 +41,15 @@ public class EmsObjAttrValueController extends BaseController {
     @Autowired
     private IEmsObjAttrValueService objAttrValueService;
 
+    @Autowired
+    private IEmsDeviceService deviceService;
+
+    @Autowired
+    private IEmsFacsService facsService;
+
+    @Autowired
+    private IEmsDeviceComponentService componentService;
+
     /**
      * 查询能源对象属性值列表
      */
@@ -84,6 +101,29 @@ public class EmsObjAttrValueController extends BaseController {
     @DeleteMapping("/deleteByObj")
     public AjaxResult removeByObj(@RequestParam(name = "objType") Integer objType,
         @RequestParam(name = "objCode") String objCode) {
-        return toAjax(objAttrValueService.deleteByObjCode(objType, objCode));
+
+        String modeCode = null;
+        int cnt = 0;
+
+        if (objType == DevObjType.FACS.getCode()) {
+            EmsFacs facs = facsService.selectEmsFacsByCode(objCode);
+            Assert.notNull(facs, -1, "能源设施不存在");
+            modeCode = facs.getFacsModel();
+            cnt = objAttrValueService.deleteByObjCode(modeCode, objCode);
+        }
+        else if (objType == DevObjType.DEVC.getCode()) {
+            EmsDevice device = deviceService.selectByCode(objCode);
+            Assert.notNull(device, -1, "能源设备不存在");
+            modeCode = device.getDeviceModel();
+            cnt = objAttrValueService.deleteByObjCode(modeCode, objCode);
+        }
+        else if (objType == DevObjType.COMPONENT.getCode()) {
+            EmsDeviceComponent devCompo = componentService.selectByCode(objCode);
+            Assert.notNull(devCompo, -1, "设备部件不存在");
+            modeCode = devCompo.getCompoModel();
+            cnt = objAttrValueService.deleteByObjCode(modeCode, objCode);
+        }
+
+        return toAjax(cnt);
     }
 }

+ 5 - 4
ems/ems-application/ems-admin/src/main/java/com/ruoyi/web/controller/ems/MeterDeviceController.java

@@ -7,6 +7,7 @@ import com.ruoyi.common.core.page.TableDataInfo;
 import com.ruoyi.common.enums.BusinessType;
 import com.ruoyi.common.utils.poi.ExcelUtil;
 import com.ruoyi.ems.domain.MeterDevice;
+import com.ruoyi.ems.model.QueryDevice;
 import com.ruoyi.ems.service.IMeterDeviceService;
 import io.swagger.annotations.Api;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -41,9 +42,9 @@ public class MeterDeviceController extends BaseController {
      */
     @PreAuthorize("@ss.hasPermi('ems:meterdevc:list')")
     @GetMapping("/list")
-    public TableDataInfo list(MeterDevice meterDevice) {
+    public TableDataInfo list(QueryDevice queryDevice) {
         startPage();
-        List<MeterDevice> list = meterDeviceService.selectMeterDeviceList(meterDevice);
+        List<MeterDevice> list = meterDeviceService.selectMeterDeviceList(queryDevice);
         return getDataTable(list);
     }
 
@@ -53,8 +54,8 @@ public class MeterDeviceController extends BaseController {
     @PreAuthorize("@ss.hasPermi('ems:meterdevc:export')")
     @Log(title = "计量设备", businessType = BusinessType.EXPORT)
     @PostMapping("/export")
-    public void export(HttpServletResponse response, MeterDevice meterDevice) {
-        List<MeterDevice> list = meterDeviceService.selectMeterDeviceList(meterDevice);
+    public void export(HttpServletResponse response, QueryDevice queryDevice) {
+        List<MeterDevice> list = meterDeviceService.selectMeterDeviceList(queryDevice);
         ExcelUtil<MeterDevice> util = new ExcelUtil<MeterDevice>(MeterDevice.class);
         util.exportExcel(response, list, "计量设备数据");
     }

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

@@ -0,0 +1,72 @@
+/*
+ * 文 件 名:  TaskHandler
+ * 版    权:  华设设计集团股份有限公司
+ * 描    述:  <描述>
+ * 修 改 人:  lvwenbin
+ * 修改时间:  2025/3/18
+ * 跟踪单号:  <跟踪单号>
+ * 修改单号:  <修改单号>
+ * 修改内容:  <修改内容>
+ */
+package com.ruoyi.ems;
+
+import com.ruoyi.ems.core.ObjectCache;
+import com.ruoyi.ems.handle.MqttBaseHandler;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+
+/**
+ * 任务调度
+ * <功能详细描述>
+ *
+ * @author lvwenbin
+ * @version [版本号, 2025/3/18]
+ * @see [相关类/方法]
+ * @since [产品/模块版本]
+ */
+@Service
+public class TaskExecutor {
+    /**
+     * 日志服务
+     */
+    protected static final Logger log = LoggerFactory.getLogger(TaskExecutor.class);
+
+    @Autowired
+    private ObjectCache objectCache;
+
+    @Qualifier("geekOpenCbHandler")
+    @Resource
+    private MqttBaseHandler geekOpenCbHandler;
+
+    /**
+     * 定时清理过期设备上报响应
+     */
+    @Scheduled(cron = "0 0/5 * * * ?")
+    public void cleanDevResCache() {
+        int cnt = objectCache.cleanDevResCache();
+        log.info("清理过期设备上报响应: {} 条", cnt);
+    }
+
+    /**
+     * 定时刷新设备在线状态
+     */
+    @Scheduled(cron = "0 10 0/1 * * ?")
+    public void refreshOnline() {
+        geekOpenCbHandler.refreshOnline(2 * 60 * 60 * 1000);
+    }
+
+    /**
+     * 每小时产出设备计量数据
+     */
+    @Scheduled(cron = "0 0 0/1 * * ?")
+    public void meterHourProd() {
+        int cnt = geekOpenCbHandler.meterHourProd();
+        log.info("产出设备计量数据: {} 条", cnt);
+    }
+}

+ 2 - 2
ems/ems-cloud/ems-dev-adapter/src/main/java/com/ruoyi/ems/controller/CircuitBreakerController.java

@@ -50,7 +50,7 @@ public class CircuitBreakerController {
 
     @Qualifier("geekOpenCbHandler")
     @Resource
-    private MqttBaseHandler devAdapterService;
+    private MqttBaseHandler geekOpenCbHandler;
 
     /**
      * GeekOpen 断路器能力调用
@@ -66,7 +66,7 @@ public class CircuitBreakerController {
         CallResponse<Void> res = null;
 
         try {
-            res = devAdapterService.call(abilityPayload);
+            res = geekOpenCbHandler.call(abilityPayload);
         }
         catch (Exception e) {
             log.error("geekOpenCbAbilityCall fail!", e);

+ 13 - 11
ems/ems-cloud/ems-dev-adapter/src/main/java/com/ruoyi/ems/core/MessageCache.java → ems/ems-cloud/ems-dev-adapter/src/main/java/com/ruoyi/ems/core/ObjectCache.java

@@ -11,7 +11,6 @@
 package com.ruoyi.ems.core;
 
 import com.ruoyi.ems.model.MqttCacheMsg;
-import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Service;
 
 import java.util.Date;
@@ -29,36 +28,39 @@ import java.util.concurrent.ConcurrentHashMap;
  * @since [产品/模块版本]
  */
 @Service
-public class MessageCache {
+public class ObjectCache {
     /**
      * 消息缓存队列
      */
-    private final static Map<String, MqttCacheMsg> mqttMessageMap = new ConcurrentHashMap<>();
+    private final static Map<String, MqttCacheMsg> devResCache = new ConcurrentHashMap<>();
 
     /**
-     * 定时清理过期的消息
+     * 清理过期的设备响应
      */
-    @Scheduled(cron = "0 0/5 * * * ?")
-    public void cleanUpOldMessages() {
+    public int cleanDevResCache() {
+        int cnt = 0;
         long currentTime = new Date().getTime();
         long threshold = 5 * 60 * 1000; // 分钟
 
-        Iterator<Map.Entry<String, MqttCacheMsg>> iterator = mqttMessageMap.entrySet().iterator();
+        Iterator<Map.Entry<String, MqttCacheMsg>> iterator = devResCache.entrySet().iterator();
         while (iterator.hasNext()) {
             Map.Entry<String, MqttCacheMsg> entry = iterator.next();
             MqttCacheMsg msg = entry.getValue();
             if ((currentTime - msg.getReceiveTime().getTime()) > threshold) {
                 // 删除缓存中的消息
                 iterator.remove();
+                cnt++;
             }
         }
+
+        return cnt;
     }
 
-    public void addMqttMessage(String messageId, MqttCacheMsg mqttMessage) {
-        mqttMessageMap.put(messageId, mqttMessage);
+    public void setDevResCache(String messageId, MqttCacheMsg mqttMessage) {
+        devResCache.put(messageId, mqttMessage);
     }
 
-    public MqttCacheMsg getAndRemoveMqttMessage(String messageId) {
-        return mqttMessageMap.remove(messageId);
+    public MqttCacheMsg readDevResponse(String messageId) {
+        return devResCache.remove(messageId);
     }
 }

+ 21 - 142
ems/ems-cloud/ems-dev-adapter/src/main/java/com/ruoyi/ems/handle/GeekOpenCbHandler.java

@@ -13,41 +13,27 @@ package com.ruoyi.ems.handle;
 import com.alibaba.fastjson2.JSONObject;
 import com.huashe.common.exception.Assert;
 import com.huashe.common.exception.BusinessException;
-import com.huashe.common.utils.DateUtils;
 import com.huashe.common.utils.ThreadUtils;
-import com.ruoyi.ems.core.MessageCache;
-import com.ruoyi.ems.domain.ElecMeterH;
+import com.ruoyi.ems.core.ObjectCache;
 import com.ruoyi.ems.domain.EmsDevice;
 import com.ruoyi.ems.domain.EmsObjAbilityCallLog;
 import com.ruoyi.ems.domain.MeterDevice;
-import com.ruoyi.ems.enums.DevObjType;
 import com.ruoyi.ems.enums.DevOnlineStatus;
 import com.ruoyi.ems.model.AbilityPayload;
 import com.ruoyi.ems.model.CallResponse;
 import com.ruoyi.ems.model.MqttCacheMsg;
-import com.ruoyi.ems.model.Price;
 import com.ruoyi.ems.model.QueryDevice;
-import com.ruoyi.ems.service.IElecMeterHService;
-import com.ruoyi.ems.service.IMeterDeviceService;
-import com.ruoyi.ems.service.IPriceService;
 import com.ruoyi.ems.util.IdUtils;
-import org.apache.commons.collections4.CollectionUtils;
-import org.apache.commons.collections4.MapUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Async;
-import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Service;
 
-import java.math.BigDecimal;
-import java.time.LocalDateTime;
-import java.time.format.DateTimeFormatter;
-import java.time.temporal.ChronoUnit;
+import java.util.Collections;
 import java.util.Date;
 import java.util.List;
-import java.util.Map;
 
 /**
  * GeekOpen 断路器服务层
@@ -63,21 +49,10 @@ public class GeekOpenCbHandler extends MqttBaseHandler {
     private static final Logger log = LoggerFactory.getLogger(GeekOpenCbHandler.class);
 
     @Autowired
-    private MessageCache messageCache;
-
-    @Autowired
-    private IMeterDeviceService meterDeviceService;
-
-    @Autowired
-    private IElecMeterHService elecMeterHService;
-
-    @Autowired
-    private IPriceService priceService;
+    private ObjectCache messageCache;
 
     private static final String TOPIC_PREFIX = "/device/dlq/";
 
-    private static final DateTimeFormatter TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
-
     /**
      * 能力执行
      *
@@ -92,7 +67,7 @@ public class GeekOpenCbHandler extends MqttBaseHandler {
         String type = sendObject.getString("type");
         String system = sendObject.getString("system");
         String deviceCode = abilityParam.getObjCode();
-        String messageId = StringUtils.equals("syncStatistic", type) ? "auto" : ("CALL-" + IdUtils.generateMessageId());
+        String messageId = StringUtils.equals("statistic", type) ? "auto" : ("CALL-" + IdUtils.generateMessageId());
         String msgBody = addMsgId(abilityParam.getAbilityParam(), "messageId", messageId);
 
         // 发送消息到MQTT服务器
@@ -106,7 +81,7 @@ public class GeekOpenCbHandler extends MqttBaseHandler {
             EmsObjAbilityCallLog logItem = saveCallLog(abilityParam, sendTime, 1);
 
             while (true) {
-                MqttCacheMsg cacheMsg = messageCache.getAndRemoveMqttMessage(messageId);
+                MqttCacheMsg cacheMsg = messageCache.readDevResponse(messageId);
 
                 if (null != cacheMsg) {
                     String receiveParam = cacheMsg.getPayload();
@@ -148,18 +123,18 @@ public class GeekOpenCbHandler extends MqttBaseHandler {
                 // 自动上报数据: 1.更新属性值,2.更新电量计量数据
                 if (StringUtils.equals("auto", messageId)) {
                     updateAutoAttr(device, msgBody);
-                    saveReportLog(deviceCode, DevObjType.DEVC.getCode(), "电量上报", payload);
+                    saveReportLog(deviceCode, device.getDeviceModel(), "电量上报", payload);
                 }
                 // 前序调用的响应消息:1.写入消息队列,2.更新属性值
                 else if (StringUtils.isNotEmpty(messageId) && StringUtils.startsWith(messageId, "CALL-")) {
                     MqttCacheMsg mqttCacheMsg = new MqttCacheMsg(messageId, deviceCode, new Date(), payload);
-                    messageCache.addMqttMessage(messageId, mqttCacheMsg);
+                    messageCache.setDevResCache(messageId, mqttCacheMsg);
                     updateBaseAttr(device, msgBody);
                 }
                 // 设备同步数据(INFO类,协议类):更新基础属性值
                 else {
                     updateBaseAttr(device, msgBody);
-                    saveReportLog(deviceCode, DevObjType.DEVC.getCode(), "信息上报", payload);
+                    saveReportLog(deviceCode, device.getDeviceModel(), "信息上报", payload);
                 }
 
                 // 设备消息抵达,将数据库离线状态改为在线
@@ -176,117 +151,24 @@ public class GeekOpenCbHandler extends MqttBaseHandler {
         }
     }
 
-    @Override
-    public int getObjType() {
-        return DevObjType.DEVC.getCode();
-    }
-
     /**
-     * 定时检测在线状态
-     * <br/>每小时执行一次,扫描2个小时无消息的设备,标记为离线状态
+     * 获取设备列表
+     * @return 设备列表
      */
-    @Scheduled(cron = "0 10 0/1 * * ?")
-    public void checkOnlineStatus() {
-        long currentTime = new Date().getTime();
-        long threshold = 2 * 60 * 60 * 1000; // 120分钟
-
+    @Override
+    public List<EmsDevice> getDeviceList() {
         QueryDevice queryDevice = new QueryDevice();
         queryDevice.setDeviceModel("M_W2_QF_GEEKOPEN");
-        List<EmsDevice> deviceList = deviceService.selectList(queryDevice);
-
-        if (CollectionUtils.isNotEmpty(deviceList)) {
-            for (EmsDevice device : deviceList) {
-                Map<String, String> attrMap = attrCache.get(device.getDeviceCode());
-
-                if (MapUtils.isNotEmpty(attrMap)) {
-                    String lastMsgTime = attrMap.get(MQTT_LAST_TIME);
-
-                    if (StringUtils.isNotEmpty(lastMsgTime)
-                        && (currentTime - DateUtils.stringToDate(lastMsgTime, DateUtils.YYYY_MM_DD_HH_MM_SS).getTime())
-                        > threshold) {
-                        refreshStatus(device, DevOnlineStatus.OFFLINE);
-                    }
-                }
-            }
-        }
+        return deviceService.selectList(queryDevice);
     }
 
-    /**
-     * 据根据累计量更新电量计量数
-     *
-     * @param device  设备信息
-     * @param msgBody 消息体
-     */
-    private void syncElecMeterByCumulant(EmsDevice device, JSONObject msgBody) {
-        MeterDevice meterDev = meterDeviceService.selectMeterDeviceByCode(device.getDeviceCode());
-
-        if (null == meterDev) {
-            return;
-        }
-
-        Map<String, String> arrtMap = attrCache.get(device.getDeviceCode());
-
-        // 获取当前时间
-        String currentTime = DateUtils.dateToString(new Date(), "yyyy-MM-dd HH:00:00");
-        LocalDateTime currentLdt = LocalDateTime.parse(currentTime, TIME_FORMATTER);
-        // 获取缓存时间
-        String cacheTime = arrtMap.get("elecMeterHour");
-
-        if (StringUtils.isNotEmpty(cacheTime)) {
-            LocalDateTime cacheLdt = LocalDateTime.parse(cacheTime, TIME_FORMATTER);
-
-            String newEngValue = msgBody.getString("energy");
-
-            long hours = ChronoUnit.HOURS.between(cacheLdt, currentLdt);
-
-            if (hours == 1) {
-                String lastEngValue = arrtMap.get("elecMeterHourValue");
-
-                BigDecimal lastEngValueBig = new BigDecimal(lastEngValue);
-                BigDecimal newEngValueBig = new BigDecimal(newEngValue);
-                BigDecimal diff = newEngValueBig.subtract(lastEngValueBig);
-
-                Date date = DateUtils.stringToDate(cacheTime, "yyyy-MM-dd HH:mm:ss");
-
-                ElecMeterH elecMeterH = new ElecMeterH();
-                elecMeterH.setAreaCode(meterDev.getAreaCode());
-                elecMeterH.setDeviceCode(meterDev.getDeviceCode());
-                elecMeterH.setRecordTime(date);
-                elecMeterH.setDate(date);
-                elecMeterH.setTime(date);
-                elecMeterH.setTimeIndex(getHourIndex(date));
-                elecMeterH.setElecQuantity(diff.doubleValue());
-
-                Price price = priceService.getElecHourPrice(meterDev.getAreaCode(), date);
-
-                if (null != price) {
-                    BigDecimal cost = diff.multiply(new BigDecimal(String.valueOf(price.getPriceValue())));
-                    elecMeterH.setMeterType(price.getMeterType());
-                    elecMeterH.setMeterUnitPrice(price.getPriceValue());
-                    elecMeterH.setUseElecCost(cost.doubleValue());
-                }
-
-                elecMeterHService.insertElecMeterH(elecMeterH);
-                LocalDateTime nextTime = cacheLdt.plusHours(1);
-                String nextHour = nextTime.format(TIME_FORMATTER);
-                arrtMap.put("elecMeterHour", nextHour);
-                arrtMap.put("elecMeterHourValue", newEngValue);
-            }
-            else if (hours == 0) {
-                arrtMap.computeIfAbsent("elecMeterHourValue", key -> newEngValue);
-            }
-            else if (hours > 1) {
-                LocalDateTime nextTime = currentLdt.plusHours(1);
-                String nextHour = nextTime.format(TIME_FORMATTER);
-                arrtMap.put("elecMeterHour", nextHour);
-                arrtMap.remove("elecMeterHourValue");
-            }
-        }
-        else {
-            LocalDateTime nextTime = currentLdt.plusHours(1);
-            String nextHour = nextTime.format(TIME_FORMATTER);
-            arrtMap.put("elecMeterHour", nextHour);
-        }
+    @Override
+    public List<MeterDevice> getMeterDeviceList() {
+        QueryDevice queryDevice = new QueryDevice();
+        queryDevice.setDeviceModel("M_W2_QF_GEEKOPEN");
+        queryDevice.setMeterCls(45);
+        queryDevice.setColMode(0);
+        return meterDeviceService.selectByModel(queryDevice);
     }
 
     /**
@@ -327,10 +209,7 @@ public class GeekOpenCbHandler extends MqttBaseHandler {
         updateAttr(device, jsonBody, "voltage");
         updateAttr(device, jsonBody, "current");
         updateAttr(device, jsonBody, "power");
-
-        if (updateAttr(device, jsonBody, "energy")) {
-            syncElecMeterByCumulant(device, jsonBody);
-        }
+        updateAttr(device, jsonBody, "energy");
     }
 
     private CallResponse<Void> checkResult(JSONObject sendObject, JSONObject receiveObject) {

+ 248 - 30
ems/ems-cloud/ems-dev-adapter/src/main/java/com/ruoyi/ems/handle/MqttBaseHandler.java

@@ -13,19 +13,26 @@ package com.ruoyi.ems.handle;
 import com.alibaba.fastjson2.JSONObject;
 import com.huashe.common.utils.DateUtils;
 import com.ruoyi.ems.core.MqttTemplate;
+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.EmsObjReportLog;
+import com.ruoyi.ems.domain.MeterDevice;
 import com.ruoyi.ems.enums.DevOnlineStatus;
 import com.ruoyi.ems.model.AbilityPayload;
 import com.ruoyi.ems.model.CallResponse;
 import com.ruoyi.ems.model.MqttCacheMsg;
+import com.ruoyi.ems.model.Price;
+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.IEmsObjReportLogService;
+import com.ruoyi.ems.service.IMeterDeviceService;
+import com.ruoyi.ems.service.IPriceService;
 import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.collections4.MapUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -33,6 +40,8 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Qualifier;
 
 import javax.annotation.Resource;
+import java.math.BigDecimal;
+import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Date;
 import java.util.List;
@@ -65,6 +74,8 @@ public abstract class MqttBaseHandler {
      */
     protected static final String MQTT_LAST_TIME = "mqttLastMsgTime";
 
+    protected static final String LAST_HOUR_READING = "lastHourReading";
+
     @Resource
     @Qualifier("mqttTemplate")
     protected MqttTemplate mqttTemplate;
@@ -73,13 +84,22 @@ public abstract class MqttBaseHandler {
     protected IEmsDeviceService deviceService;
 
     @Autowired
+    protected IMeterDeviceService meterDeviceService;
+
+    @Autowired
     protected IEmsObjAttrValueService objAttrValueService;
 
     @Autowired
-    private IEmsObjAbilityCallLogService objAbilityCallLogService;
+    protected IElecMeterHService elecMeterHService;
+
+    @Autowired
+    protected IPriceService priceService;
+
+    @Autowired
+    protected IEmsObjAbilityCallLogService objAbilityCallLogService;
 
     @Autowired
-    private IEmsObjReportLogService objReportLogService;
+    protected IEmsObjReportLogService objReportLogService;
 
     /**
      * 抽象方法,用于能力调用
@@ -99,17 +119,24 @@ public abstract class MqttBaseHandler {
     public abstract void msgHandle(String deviceCode, String payload);
 
     /**
-     * 获取设备对象类型
+     * 获取设备列表
      *
-     * @return 设备对象类型字符串
+     * @return 设备列表
      */
-    public abstract int getObjType();
+    public abstract List<EmsDevice> getDeviceList();
+
+    /**
+     * 获取计量设备列表
+     *
+     * @return 设备列表
+     */
+    public abstract List<MeterDevice> getMeterDeviceList();
 
     /**
      * 添加消息ID到消息中
      *
-     * @param msg
-     * @return
+     * @param msg 消息
+     * @return msgBody
      */
     public String addMsgId(String msg, String msgIdKey, String msgIdValue) {
         JSONObject json = JSONObject.parseObject(msg);
@@ -117,12 +144,211 @@ public abstract class MqttBaseHandler {
         return json.toString();
     }
 
+    /**
+     * 发送MQTT消息
+     *
+     * @param topic    主题
+     * @param payload  负载数据
+     * @param qos      质量服务等级
+     * @param retained 是否保留消息
+     */
     public void sendMqttMsg(String topic, String payload, int qos, boolean retained) {
         log.info("[Send] Topic:{}, message:{}, qos:{}, retained:{}", topic, payload, qos, retained);
         mqttTemplate.send(topic, payload, 2, false);
     }
 
     /**
+     * 更新最后消息时
+     *
+     * @param device    设备
+     * @param timeValue 时间值
+     */
+    public void updateMsgTime(EmsDevice device, Date timeValue) {
+        try {
+            String dateTime = DateUtils.dateToString(timeValue, DateUtils.YYYY_MM_DD_HH_MM_SS);
+
+            attrCache.computeIfAbsent(device.getDeviceCode(), k -> new ConcurrentHashMap<>());
+
+            // 更新缓存
+            updateCacheAfterSuccess(device.getDeviceCode(), MQTT_LAST_TIME, dateTime);
+        }
+        catch (Exception e) {
+            log.error("刷新缓存消息时间失败!", e);
+        }
+    }
+
+    /**
+     * 定时刷新在线状态
+     * <br/>每小时执行一次,扫描2个小时无消息的设备,标记为离线状态
+     */
+    public void refreshOnline(long threshold) {
+        long currentTime = new Date().getTime();
+
+        List<EmsDevice> deviceList = getDeviceList();
+
+        if (CollectionUtils.isNotEmpty(deviceList)) {
+            for (EmsDevice device : deviceList) {
+                Map<String, String> attrMap = attrCache.get(device.getDeviceCode());
+
+                if (MapUtils.isNotEmpty(attrMap) && null != attrMap.get(MQTT_LAST_TIME)) {
+                    String lastMsgTime = attrMap.get(MQTT_LAST_TIME);
+
+                    // 计算最后一次消息至今的时间差
+                    long time =
+                        currentTime - DateUtils.stringToDate(lastMsgTime, DateUtils.YYYY_MM_DD_HH_MM_SS).getTime();
+
+                    if (time > threshold) {
+                        refreshStatus(device, DevOnlineStatus.OFFLINE);
+                    }
+                }
+            }
+        }
+    }
+
+    /**
+     * 产出小时电量计量
+     */
+    public int meterHourProd() {
+        int cnt = 0;
+
+        try {
+            List<MeterDevice> deviceList = getMeterDeviceList();
+            List<ElecMeterH> meterHList = new ArrayList<>();
+            Map<String, Price> priceMap = new ConcurrentHashMap<>();
+            Date date = DateUtils.adjustHour(new Date(), -1);
+
+            for (MeterDevice device : deviceList) {
+                ElecMeterH elecMeterH = meterHourProdSub(device);
+
+                if (null != elecMeterH) {
+                    Price price = priceMap.computeIfAbsent(device.getAreaCode(),
+                        k -> priceService.getElecHourPrice(device.getAreaCode(), date));
+                    completePrice(elecMeterH, price);
+                    meterHList.add(elecMeterH);
+                }
+            }
+
+            if (CollectionUtils.isNotEmpty(meterHList)) {
+                cnt = elecMeterHService.insertBatch(meterHList);
+            }
+        }
+        catch (Exception e) {
+            log.error("定时产出小时电量计量失败!", e);
+        }
+
+        return cnt;
+    }
+
+    private ElecMeterH meterHourProdSub(MeterDevice device) {
+        ElecMeterH elecMeterH = null;
+
+        // 获取设备属性缓存
+        Map<String, String> attrMap = attrCache.computeIfAbsent(device.getDeviceCode(), k -> new ConcurrentHashMap<>());
+
+        String lastMeterReading = attrMap.get(LAST_HOUR_READING);
+        String newMeterReading = attrMap.get("energy");
+
+        // 缓存不为空,使用缓存抄表计算
+        if (StringUtils.isNotEmpty(lastMeterReading)) {
+            elecMeterH = execHourMeter(device, lastMeterReading, newMeterReading);
+        }
+        // 缓存为空,使用数据库记录计算
+        else {
+            ElecMeterH dbElecMeterH = elecMeterHService.selectLatelyItem(device.getDeviceCode());
+
+            if (null != dbElecMeterH && null != dbElecMeterH.getMeterReading()) {
+                elecMeterH = execHourMeter(device, String.valueOf(dbElecMeterH.getMeterReading()), newMeterReading);
+            }
+            else {
+                // 无缓存也无数据库记录,则认为是首次上报
+                if (StringUtils.isNotEmpty(newMeterReading)) {
+                    updateCacheAfterSuccess(device.getDeviceCode(), LAST_HOUR_READING, newMeterReading);
+                }
+            }
+        }
+
+        return elecMeterH;
+    }
+
+    /**
+     * 执行小时抄表计算
+     * @param device 设备信息
+     * @param lastMeterReading 上次抄表值
+     * @param newMeterReading 本次抄表值
+     * @return
+     */
+    private ElecMeterH execHourMeter(MeterDevice device, String lastMeterReading, String newMeterReading) {
+        ElecMeterH elecMeterH = null;
+        BigDecimal lastEngValue = new BigDecimal(lastMeterReading);
+
+        if (StringUtils.isNotEmpty(newMeterReading)) {
+            BigDecimal newEngValue = new BigDecimal(newMeterReading);
+            // 计算电量差值
+            BigDecimal useQuantity = newEngValue.subtract(lastEngValue);
+            // 倍率计算
+            useQuantity = magnification(useQuantity, device.getMagnification());
+            // 更新缓存
+            updateCacheAfterSuccess(device.getDeviceCode(), LAST_HOUR_READING, newMeterReading);
+            // 封装计量对象
+            elecMeterH = buildElecMeterH(device, newEngValue, useQuantity);
+        }
+        else {
+            BigDecimal useQuantity = BigDecimal.ZERO;
+            // 封装计量对象
+            elecMeterH = buildElecMeterH(device, lastEngValue, useQuantity);
+        }
+
+        return elecMeterH;
+    }
+
+    /**
+     * 封装计量对象
+     * @param device 设备信息
+     * @param newEngValue 最新电量值
+     * @param useQuantity 用量差值
+     * @return ElecMeterH 计量对象
+     */
+    private ElecMeterH buildElecMeterH(MeterDevice device, BigDecimal newEngValue, BigDecimal useQuantity) {
+        Date date = DateUtils.adjustHour(new Date(), -1);
+        ElecMeterH elecMeterH = new ElecMeterH();
+        elecMeterH.setAreaCode(device.getAreaCode());
+        elecMeterH.setDeviceCode(device.getDeviceCode());
+        elecMeterH.setRecordTime(date);
+        elecMeterH.setDate(date);
+        elecMeterH.setTime(date);
+        elecMeterH.setTimeIndex(getHourIndex(date));
+        elecMeterH.setElecQuantity(useQuantity.doubleValue());
+        elecMeterH.setMeterReading(newEngValue.doubleValue());
+
+        return elecMeterH;
+    }
+
+    /**
+     * 倍率计算
+     * @param quantity 原始用量
+     * @param magnification 倍率
+     * @return
+     */
+    private BigDecimal magnification(BigDecimal quantity, Integer magnification) {
+        return null != magnification ? quantity.multiply(new BigDecimal(String.valueOf(magnification))) : quantity;
+    }
+
+    /**
+     * 完善价格信息
+     * @param elecMeterH 计量对象
+     * @param price 价格信息
+     */
+    private void completePrice(ElecMeterH elecMeterH, Price price) {
+        if (null != price) {
+            BigDecimal useQuantity = new BigDecimal(String.valueOf(elecMeterH.getElecQuantity()));
+            BigDecimal cost = useQuantity.multiply(new BigDecimal(String.valueOf(price.getPriceValue())));
+            elecMeterH.setMeterType(price.getMeterType());
+            elecMeterH.setMeterUnitPrice(price.getPriceValue());
+            elecMeterH.setUseElecCost(cost.doubleValue());
+        }
+    }
+
+    /**
      * 校验是否需要更新属性值
      *
      * @param jsonBody jsonBody 消息体
@@ -143,7 +369,7 @@ public abstract class MqttBaseHandler {
 
             // 获取缓存
             Map<String, String> attrMap = attrCache.computeIfAbsent(device.getDeviceCode(), k -> {
-                List<EmsObjAttrValue> attrList = objAttrValueService.selectByObjCode(getObjType(), k);
+                List<EmsObjAttrValue> attrList = objAttrValueService.selectByObjCode(device.getDeviceModel(), k);
 
                 if (CollectionUtils.isNotEmpty(attrList)) {
                     return attrList.stream().collect(
@@ -160,12 +386,12 @@ public abstract class MqttBaseHandler {
 
             // 比较属性值是否发生变化
             if (!StringUtils.equals(currentValue, cacheValue)) {
-                EmsObjAttrValue attrValue = new EmsObjAttrValue(device.getDeviceCode(), getObjType(),
-                    device.getDeviceModel(), attrKey, currentValue);
+                EmsObjAttrValue attrValue = new EmsObjAttrValue(device.getDeviceCode(), device.getDeviceModel(),
+                    attrKey, currentValue);
                 // 更新数据库
                 objAttrValueService.mergeObjAttrValue(attrValue);
                 // 更新缓存
-                updateCacheAfterSuccess(device, attrKey, currentValue);
+                updateCacheAfterSuccess(device.getDeviceCode(), attrKey, currentValue);
 
                 flag = true;
             }
@@ -177,22 +403,15 @@ public abstract class MqttBaseHandler {
         return flag;
     }
 
-    public void updateMsgTime(EmsDevice device, Date timeValue) {
-        try {
-            String dateTime = DateUtils.dateToString(timeValue, DateUtils.YYYY_MM_DD_HH_MM_SS);
-
-            attrCache.computeIfAbsent(device.getDeviceCode(), k -> new ConcurrentHashMap<>());
-
-            // 更新缓存
-            updateCacheAfterSuccess(device, MQTT_LAST_TIME, dateTime);
-        }
-        catch (Exception e) {
-            log.error("刷新缓存消息时间失败!", e);
-        }
-    }
-
-    public void updateCacheAfterSuccess(EmsDevice device, String attrKey, String newValue) {
-        attrCache.computeIfPresent(device.getDeviceCode(), (k, attrMap) -> {
+    /**
+     * 更新缓存值
+     *
+     * @param deviceCode 设备信息
+     * @param attrKey    属性值
+     * @param newValue
+     */
+    public void updateCacheAfterSuccess(String deviceCode, String attrKey, String newValue) {
+        attrCache.computeIfPresent(deviceCode, (k, attrMap) -> {
             attrMap.put(attrKey, newValue);
             return attrMap;
         });
@@ -221,7 +440,6 @@ public abstract class MqttBaseHandler {
     protected EmsObjAbilityCallLog saveCallLog(AbilityPayload abilityParam, long sendTime, int callStatus) {
         EmsObjAbilityCallLog objAbilityCallLog = new EmsObjAbilityCallLog();
         objAbilityCallLog.setObjCode(abilityParam.getObjCode());
-        objAbilityCallLog.setObjType(abilityParam.getObjType());
         objAbilityCallLog.setModelCode(abilityParam.getModeCode());
         objAbilityCallLog.setAbilityKey(abilityParam.getAbilityKey());
         objAbilityCallLog.setCallTime(new Date(sendTime));
@@ -238,10 +456,10 @@ public abstract class MqttBaseHandler {
         objAbilityCallLogService.updateLog(objAbilityCallLog);
     }
 
-    protected void saveReportLog(String objCode, int objType, String msgDesc, String payload) {
+    protected void saveReportLog(String objCode, String modelCode, String msgDesc, String payload) {
         EmsObjReportLog objReportLog = new EmsObjReportLog();
         objReportLog.setObjCode(objCode);
-        objReportLog.setObjType(objType);
+        objReportLog.setModelCode(modelCode);
         objReportLog.setMsgDesc(msgDesc);
         objReportLog.setReportPayload(payload);
         objReportLog.setReportTime(new Date());

+ 0 - 1
ems/ems-cloud/ems-dev-adapter/src/main/java/com/ruoyi/ems/handle/RootMsgHandler.java

@@ -11,7 +11,6 @@
 package com.ruoyi.ems.handle;
 
 import com.ruoyi.ems.core.MqttMessageHandler;
-import com.ruoyi.ems.core.MessageCache;
 import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;

+ 1 - 10
ems/ems-cloud/ems-server/src/main/java/com/ruoyi/ems/controller/AreaController.java

@@ -115,18 +115,9 @@ public class AreaController extends BaseController {
             ret = AreaUtils.convertAreaTree(areas);
         }
         else {
-            List<Area> areas = null;
-
-            if (layer == 1) {
-                areas = areaService.selectAreaTree(rootCode, false);
-            }
-            else {
-                areas = areaService.selectAreaTree(rootCode, true);
-            }
-
+            List<Area> areas = areaService.selectAreaTree(rootCode, layer > 1);
             ret = AreaUtils.convertAreaTree(areas, layer);
         }
-
         return success(ret);
     }
 

+ 2 - 2
ems/ems-cloud/ems-server/src/main/java/com/ruoyi/ems/controller/EmsObjAbilityController.java

@@ -49,8 +49,8 @@ public class EmsObjAbilityController extends BaseController {
         AjaxResult ajaxResult = null;
 
         try {
-            String ret = abilityCallService.abilityCall(abilityPayload.getObjCode(), abilityPayload.getObjType(),
-                abilityPayload.getAbilityKey(), abilityPayload.getAbilityParam());
+            String ret = abilityCallService.devAbilityCall(abilityPayload.getObjCode(), abilityPayload.getAbilityKey(),
+                abilityPayload.getAbilityParam());
             ajaxResult = success(ret);
         }
         catch (BusinessException e) {

+ 40 - 1
ems/ems-cloud/ems-server/src/main/java/com/ruoyi/ems/controller/EmsObjAttrValueController.java

@@ -1,10 +1,18 @@
 package com.ruoyi.ems.controller;
 
 import com.huashe.common.domain.AjaxResult;
+import com.huashe.common.exception.Assert;
 import com.ruoyi.common.core.web.controller.BaseController;
 import com.ruoyi.common.log.annotation.Log;
 import com.ruoyi.common.log.enums.BusinessType;
+import com.ruoyi.ems.domain.EmsDevice;
+import com.ruoyi.ems.domain.EmsDeviceComponent;
+import com.ruoyi.ems.domain.EmsFacs;
 import com.ruoyi.ems.domain.EmsObjAttrValue;
+import com.ruoyi.ems.enums.DevObjType;
+import com.ruoyi.ems.service.IEmsDeviceComponentService;
+import com.ruoyi.ems.service.IEmsDeviceService;
+import com.ruoyi.ems.service.IEmsFacsService;
 import com.ruoyi.ems.service.IEmsObjAttrValueService;
 import io.swagger.annotations.Api;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -33,6 +41,15 @@ public class EmsObjAttrValueController extends BaseController {
     @Autowired
     private IEmsObjAttrValueService objAttrValueService;
 
+    @Autowired
+    private IEmsDeviceService deviceService;
+
+    @Autowired
+    private IEmsFacsService facsService;
+
+    @Autowired
+    private IEmsDeviceComponentService componentService;
+
     /**
      * 查询能源对象属性值列表
      */
@@ -84,6 +101,28 @@ public class EmsObjAttrValueController extends BaseController {
     @DeleteMapping("/deleteByObj")
     public AjaxResult removeByObj(@RequestParam(name = "objType") Integer objType,
         @RequestParam(name = "objCode") String objCode) {
-        return toAjax(objAttrValueService.deleteByObjCode(objType, objCode));
+        String modeCode = null;
+        int cnt = 0;
+
+        if (objType == DevObjType.FACS.getCode()) {
+            EmsFacs facs = facsService.selectEmsFacsByCode(objCode);
+            Assert.notNull(facs, -1, "能源设施不存在");
+            modeCode = facs.getFacsModel();
+            cnt = objAttrValueService.deleteByObjCode(modeCode, objCode);
+        }
+        else if (objType == DevObjType.DEVC.getCode()) {
+            EmsDevice device = deviceService.selectByCode(objCode);
+            Assert.notNull(device, -1, "能源设备不存在");
+            modeCode = device.getDeviceModel();
+            cnt = objAttrValueService.deleteByObjCode(modeCode, objCode);
+        }
+        else if (objType == DevObjType.COMPONENT.getCode()) {
+            EmsDeviceComponent devCompo = componentService.selectByCode(objCode);
+            Assert.notNull(devCompo, -1, "设备部件不存在");
+            modeCode = devCompo.getCompoModel();
+            cnt = objAttrValueService.deleteByObjCode(modeCode, objCode);
+        }
+
+        return toAjax(cnt);
     }
 }

+ 7 - 4
ems/ems-cloud/ems-server/src/main/java/com/ruoyi/ems/controller/EmsObjLogController.java

@@ -2,6 +2,7 @@ package com.ruoyi.ems.controller;
 
 import com.huashe.common.domain.AjaxResult;
 import com.ruoyi.common.core.web.controller.BaseController;
+import com.ruoyi.common.core.web.page.TableDataInfo;
 import com.ruoyi.common.log.annotation.Log;
 import com.ruoyi.common.log.enums.BusinessType;
 import com.ruoyi.common.security.annotation.RequiresPermissions;
@@ -59,9 +60,10 @@ public class EmsObjLogController extends BaseController {
      * 查询上报日志列表
      */
     @GetMapping("/reportLog/list")
-    public AjaxResult listReportLog(EmsObjReportLog param) {
+    public TableDataInfo listReportLog(EmsObjReportLog param) {
+        startPage();
         List<EmsObjReportLog> list = reportLogService.selectLog(param);
-        return success(list);
+        return getDataTable(list);
     }
 
     /**
@@ -76,8 +78,9 @@ public class EmsObjLogController extends BaseController {
      * 查询上报日志列表
      */
     @GetMapping("/callLog/list")
-    public AjaxResult listCallLog(EmsObjAbilityCallLog param) {
+    public TableDataInfo listCallLog(EmsObjAbilityCallLog param) {
+        startPage();
         List<EmsObjAbilityCallLog> list = abilityCallLogService.selectLogList(param);
-        return success(list);
+        return getDataTable(list);
     }
 }

+ 84 - 6
ems/ems-cloud/ems-server/src/main/java/com/ruoyi/ems/controller/MeterDeviceController.java

@@ -9,13 +9,14 @@ import com.ruoyi.common.log.annotation.Log;
 import com.ruoyi.common.log.enums.BusinessType;
 import com.ruoyi.common.security.annotation.RequiresPermissions;
 import com.ruoyi.ems.domain.Area;
-import com.ruoyi.ems.domain.EmsDevice;
 import com.ruoyi.ems.domain.MeterDevice;
 import com.ruoyi.ems.model.QueryDevice;
+import com.ruoyi.ems.model.TreeEntity;
 import com.ruoyi.ems.service.IAreaService;
 import com.ruoyi.ems.service.IMeterDeviceService;
 import com.ruoyi.ems.util.AreaUtils;
 import io.swagger.annotations.Api;
+import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.DeleteMapping;
@@ -25,11 +26,14 @@ import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.PutMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.servlet.http.HttpServletResponse;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
 
 /**
  * 计量设备Controller
@@ -52,9 +56,9 @@ public class MeterDeviceController extends BaseController {
      */
     @RequiresPermissions("ems:meterdevc:list")
     @GetMapping("/list")
-    public TableDataInfo list(MeterDevice meterDevice) {
+    public TableDataInfo list(QueryDevice queryDevice) {
         startPage();
-        List<MeterDevice> list = meterDeviceService.selectMeterDeviceList(meterDevice);
+        List<MeterDevice> list = meterDeviceService.selectMeterDeviceList(queryDevice);
         return getDataTable(list);
     }
 
@@ -77,7 +81,7 @@ public class MeterDeviceController extends BaseController {
             }
 
             startPage();
-            List<MeterDevice> list = meterDeviceService.selectByAreaTree(queryDevice);
+            List<MeterDevice> list = meterDeviceService.selectMeterDeviceList(queryDevice);
             tabInfo = getDataTable(list);
         }
         catch (BusinessException e) {
@@ -90,13 +94,87 @@ public class MeterDeviceController extends BaseController {
     }
 
     /**
+     * 根据设施获取设备树结构
+     *
+     * @param parentCode 区域code
+     * @return 树结构
+     */
+    @RequiresPermissions("basecfg:meterdevc:list")
+    @GetMapping("/getTreeByArea")
+    public AjaxResult getTreeByArea(
+        @RequestParam(name = "parentCode", required = false, defaultValue = "0") String parentCode,
+        @RequestParam(value = "meterCls", required = false) Integer meterCls,
+        @RequestParam(value = "colMode", required = false) Integer colMode) {
+        List<TreeEntity> retList = new ArrayList<>();
+
+        // 查询区域树
+        List<Area> areas = areaService.selectAreaTree(parentCode, true);
+
+        // 查询设备列表
+        QueryDevice queryParam = new QueryDevice();
+        queryParam.setMeterCls(meterCls);
+        queryParam.setColMode(colMode);
+        List<MeterDevice> list = meterDeviceService.selectMeterDeviceList(queryParam);
+        Map<String, List<MeterDevice>> groupMap = list.stream()
+            .collect(Collectors.groupingBy(MeterDevice::getLocationRef, Collectors.toList()));
+
+        for (Area area : areas) {
+            List<TreeEntity> childList = new ArrayList<>();
+
+            if (groupMap.containsKey(area.getAreaCode())) {
+                TreeEntity local = new TreeEntity();
+                local.setLabel("本级");
+                local.setChildren(convertToTreeEntity(groupMap.get(area.getAreaCode())));
+                childList.add(local);
+            }
+
+            // 当前层级小于最大层级时,递归处理子节点
+            if (CollectionUtils.isNotEmpty(area.getChildren())) {
+                List<?> childAreas = area.getChildren();
+                for (Object obj : childAreas) {
+                    Area child = (Area) obj;
+                    String childCode = child.getAreaCode();
+                    TreeEntity local = new TreeEntity();
+                    local.setLabel(child.getAreaName());
+
+                    if (null != groupMap.get(childCode)) {
+                        local.setChildren(convertToTreeEntity(groupMap.get(childCode)));
+                    }
+
+                    childList.add(local);
+                }
+            }
+
+            TreeEntity treeNode = new TreeEntity();
+            treeNode.setLabel(area.getAreaName());
+            treeNode.setChildren(childList);
+            retList.add(treeNode);
+        }
+
+        return success(retList);
+    }
+
+    private List<TreeEntity> convertToTreeEntity(List<MeterDevice> devList) {
+        List<TreeEntity> ret = new ArrayList<>();
+
+        for (MeterDevice dev : devList) {
+            TreeEntity entity = new TreeEntity();
+            entity.setId(dev.getDeviceCode());
+            entity.setLabel(dev.getDeviceName());
+            ret.add(entity);
+        }
+
+        return ret;
+    }
+
+    /**
      * 导出计量设备列表
      */
     @RequiresPermissions("ems:meterdevc:export")
     @Log(title = "计量设备", businessType = BusinessType.EXPORT)
     @PostMapping("/export")
-    public void export(HttpServletResponse response, MeterDevice meterDevice) {
-        List<MeterDevice> list = meterDeviceService.selectMeterDeviceList(meterDevice);
+    public void export(HttpServletResponse response, QueryDevice queryDevice) {
+        List<MeterDevice> list = meterDeviceService.selectMeterDeviceList(queryDevice);
         ExcelUtil<MeterDevice> util = new ExcelUtil<MeterDevice>(MeterDevice.class);
         util.exportExcel(response, list, "计量设备数据");
     }

+ 13 - 0
ems/ems-core/src/main/java/com/ruoyi/ems/domain/ElecMeterH.java

@@ -69,6 +69,10 @@ public class ElecMeterH extends BaseEntity
     @Excel(name = "小时电费")
     private Double useElecCost;
 
+    /** 抄表读数 */
+    @Excel(name = "抄表读数")
+    private Double meterReading;
+
     public Long getId() {
         return id;
     }
@@ -173,6 +177,14 @@ public class ElecMeterH extends BaseEntity
         this.useElecCost = useElecCost;
     }
 
+    public Double getMeterReading() {
+        return meterReading;
+    }
+
+    public void setMeterReading(Double meterReading) {
+        this.meterReading = meterReading;
+    }
+
     @Override
     public String toString() {
         return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
@@ -187,6 +199,7 @@ public class ElecMeterH extends BaseEntity
             .append("meterType", getMeterType())
             .append("meterUnitPrice", getMeterUnitPrice())
             .append("useElecCost", getUseElecCost())
+            .append("meterReading", getMeterReading())
             .append("createTime", getCreateTime())
             .toString();
     }

+ 0 - 12
ems/ems-core/src/main/java/com/ruoyi/ems/domain/EmsObjAbilityCallLog.java

@@ -23,9 +23,6 @@ public class EmsObjAbilityCallLog extends BaseEntity
     /** 对象代码 */
     private String objCode;
 
-    /** 对象类型 */
-    private Integer objType;
-
     private String objName;
 
     private String modelCode;
@@ -70,14 +67,6 @@ public class EmsObjAbilityCallLog extends BaseEntity
         this.objCode = objCode;
     }
 
-    public Integer getObjType() {
-        return objType;
-    }
-
-    public void setObjType(Integer objType) {
-        this.objType = objType;
-    }
-
     public String getObjName() {
         return objName;
     }
@@ -163,7 +152,6 @@ public class EmsObjAbilityCallLog extends BaseEntity
         return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
             .append("id", getId())
             .append("objCode", getObjCode())
-            .append("objType", getObjType())
             .append("modelCode", getModelCode())
             .append("abilityKey", getAbilityKey())
             .append("callTime", getCallTime())

+ 5 - 17
ems/ems-core/src/main/java/com/ruoyi/ems/domain/EmsObjAttrValue.java

@@ -23,11 +23,6 @@ public class EmsObjAttrValue {
     private String objCode;
 
     /**
-     * 对象类型
-     */
-    private Integer objType;
-
-    /**
      * 属性标识
      */
     private String attrKey;
@@ -50,9 +45,8 @@ public class EmsObjAttrValue {
     public EmsObjAttrValue() {
     }
 
-    public EmsObjAttrValue(String objCode, Integer objType, String modelCode, String attrKey, String attrValue) {
+    public EmsObjAttrValue(String objCode, String modelCode, String attrKey, String attrValue) {
         this.objCode = objCode;
-        this.objType = objType;
         this.modelCode = modelCode;
         this.attrKey = attrKey;
         this.attrValue = attrValue;
@@ -74,14 +68,6 @@ public class EmsObjAttrValue {
         return objCode;
     }
 
-    public void setObjType(Integer objType) {
-        this.objType = objType;
-    }
-
-    public Integer getObjType() {
-        return objType;
-    }
-
     public void setAttrKey(String attrKey) {
         this.attrKey = attrKey;
     }
@@ -117,8 +103,10 @@ public class EmsObjAttrValue {
     @Override
     public String toString() {
         return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).append("id", getId())
-            .append("objCode", getObjCode()).append("objType", getObjType()).append("attrKey", getAttrKey())
-            .append("attrValue", getAttrValue()).append("modelCode", getModelCode())
+            .append("objCode", getObjCode())
+            .append("attrKey", getAttrKey())
+            .append("attrValue", getAttrValue())
+            .append("modelCode", getModelCode())
             .append("updateTime", getUpdateTime()).toString();
     }
 }

+ 6 - 6
ems/ems-core/src/main/java/com/ruoyi/ems/domain/EmsObjReportLog.java

@@ -31,7 +31,7 @@ public class EmsObjReportLog extends BaseEntity {
     /**
      * 对象类型
      */
-    private Integer objType;
+    private String modelCode;
 
     /**
      * 消息描述
@@ -73,12 +73,12 @@ public class EmsObjReportLog extends BaseEntity {
         this.objName = objName;
     }
 
-    public Integer getObjType() {
-        return objType;
+    public String getModelCode() {
+        return modelCode;
     }
 
-    public void setObjType(Integer objType) {
-        this.objType = objType;
+    public void setModelCode(String modelCode) {
+        this.modelCode = modelCode;
     }
 
     public String getMsgDesc() {
@@ -110,7 +110,7 @@ public class EmsObjReportLog extends BaseEntity {
         return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
             .append("id", getId())
             .append("objCode", getObjCode())
-            .append("objType", getObjType())
+            .append("modelCode", getModelCode())
             .append("msgDesc", getMsgDesc())
             .append("reportTime", getReportTime())
             .append("reportPayload", getReportPayload()).toString();

+ 15 - 0
ems/ems-core/src/main/java/com/ruoyi/ems/mapper/ElecMeterHMapper.java

@@ -31,6 +31,13 @@ public interface ElecMeterHMapper {
     List<ElecMeterH> selectElecMeterByDevs(QueryMeter queryMeter);
 
     /**
+     * 查询最近一条计量
+     * @param deviceCode 设备编码
+     * @return 用电计量
+     */
+    ElecMeterH selectLatelyItem(@Param("deviceCode") String deviceCode);
+
+    /**
      * 查询用电计量-小时列表
      *
      * @param queryMeter 查询计量条件
@@ -47,6 +54,14 @@ public interface ElecMeterHMapper {
     int insertElecMeterH(ElecMeterH elecMeterH);
 
     /**
+     * 新增用电计量-小时
+     *
+     * @param list 用电计量-小时
+     * @return 结果
+     */
+    int insertBatch(List<ElecMeterH> list);
+
+    /**
      * 修改用电计量-小时
      *
      * @param elecMeterH 用电计量-小时

+ 4 - 4
ems/ems-core/src/main/java/com/ruoyi/ems/mapper/EmsObjAttrValueMapper.java

@@ -31,11 +31,11 @@ public interface EmsObjAttrValueMapper {
     /**
      * 查询能源对象属性值列表
      *
-     * @param objType 对象类型
+     * @param modelCode 对象类型
      * @param objCode 对象代码
      * @return 能源对象属性值集合
      */
-    List<EmsObjAttrValue> selectByObjCode(@Param("objType") Integer objType, @Param("objCode") String objCode);
+    List<EmsObjAttrValue> selectByObjCode(@Param("modelCode") String modelCode, @Param("objCode") String objCode);
 
     /**
      * 新增能源对象属性值
@@ -56,11 +56,11 @@ public interface EmsObjAttrValueMapper {
     /**
      * 删除能源对象属性值
      *
-     * @param objType 对象类
+     * @param modelCode 对象模
      * @param objCode 对象代码
      * @return 结果
      */
-    int deleteByObjCode(@Param("objType") Integer objType, @Param("objCode") String objCode);
+    int deleteByObjCode(@Param("modelCode") String modelCode, @Param("objCode") String objCode);
 
     /**
      * 删除能源对象属性值

+ 9 - 3
ems/ems-core/src/main/java/com/ruoyi/ems/mapper/MeterDeviceMapper.java

@@ -36,12 +36,18 @@ public interface MeterDeviceMapper {
     /**
      * 查询计量设备列表
      *
-     * @param meterDevice 计量设备
+     * @param queryDevice 计量设备
      * @return 计量设备集合
      */
-    List<MeterDevice> selectMeterDeviceList(MeterDevice meterDevice);
+    List<MeterDevice> selectMeterDeviceList(QueryDevice queryDevice);
 
-    List<MeterDevice> selectByAreaTree(QueryDevice queryDevice);
+    /**
+     * 查询计量设备列表
+     *
+     * @param queryDevice 计量设备
+     * @return 计量设备集合
+     */
+    List<MeterDevice> selectByModel(QueryDevice queryDevice);
 
     /**
      * 新增计量设备

+ 0 - 13
ems/ems-core/src/main/java/com/ruoyi/ems/model/AbilityPayload.java

@@ -26,11 +26,6 @@ public class AbilityPayload {
     private String objCode;
 
     /**
-     * 对象类型
-     */
-    private Integer objType;
-
-    /**
      * 模型代码
      */
     private String modeCode;
@@ -53,14 +48,6 @@ public class AbilityPayload {
         this.objCode = objCode;
     }
 
-    public Integer getObjType() {
-        return objType;
-    }
-
-    public void setObjType(Integer objType) {
-        this.objType = objType;
-    }
-
     public String getModeCode() {
         return modeCode;
     }

+ 17 - 1
ems/ems-core/src/main/java/com/ruoyi/ems/service/IAbilityCallService.java

@@ -20,5 +20,21 @@ package com.ruoyi.ems.service;
  * @since [产品/模块版本]
  */
 public interface IAbilityCallService {
-    String abilityCall(String objCode, int objType, String abilityKey, String param);
+    /**
+     * 设备能力调用
+     * @param objCode 设备编码
+     * @param abilityKey 能力键
+     * @param param 参数
+     * @return 返回结果
+     */
+    String devAbilityCall(String objCode, String abilityKey, String param);
+
+    /**
+     * 设施能力调用
+     * @param objCode 设备编码
+     * @param abilityKey 能力键
+     * @param param 参数
+     * @return 返回结果
+     */
+    String facsAbilityCall(String objCode, String abilityKey, String param);
 }

+ 15 - 0
ems/ems-core/src/main/java/com/ruoyi/ems/service/IElecMeterHService.java

@@ -38,6 +38,13 @@ public interface IElecMeterHService {
     ElecMeter staByMeterDev(QueryMeter queryMeter);
 
     /**
+     * 查询最近的一条记录
+     * @param deviceCode 设备编码
+     * @return 用电计量-小时集合
+     */
+    ElecMeterH selectLatelyItem(String deviceCode);
+
+    /**
      * 新增用电计量-小时
      *
      * @param elecMeterH 用电计量-小时
@@ -46,6 +53,14 @@ public interface IElecMeterHService {
     int insertElecMeterH(ElecMeterH elecMeterH);
 
     /**
+     * 新增用电计量-小时
+     *
+     * @param list 用电计量-小时
+     * @return 结果
+     */
+    int insertBatch(List<ElecMeterH> list);
+
+    /**
      * 修改用电计量-小时
      *
      * @param elecMeterH 用电计量-小时

+ 4 - 4
ems/ems-core/src/main/java/com/ruoyi/ems/service/IEmsObjAttrValueService.java

@@ -30,11 +30,11 @@ public interface IEmsObjAttrValueService {
     /**
      * 查询能源对象属性值列表
      *
-     * @param objType 对象类型
+     * @param modelCode 对象类型
      * @param objCode 对象代码
      * @return 能源对象属性值集合
      */
-    List<EmsObjAttrValue> selectByObjCode(Integer objType, String objCode);
+    List<EmsObjAttrValue> selectByObjCode(String modelCode, String objCode);
 
     /**
      * 新增能源对象属性值
@@ -71,9 +71,9 @@ public interface IEmsObjAttrValueService {
     /**
      * 删除能源对象属性值
      *
-     * @param objType 对象类
+     * @param modelCode 对象模
      * @param objCode 对象代码
      * @return 结果
      */
-    int deleteByObjCode(Integer objType, String objCode);
+    int deleteByObjCode(String modelCode, String objCode);
 }

+ 13 - 7
ems/ems-core/src/main/java/com/ruoyi/ems/service/IMeterDeviceService.java

@@ -32,20 +32,26 @@ public interface IMeterDeviceService {
     /**
      * 查询计量设备列表
      *
-     * @param meterDevice 计量设备
+     * @param queryDevice 计量设备
      * @return 计量设备集合
      */
-    List<MeterDevice> selectMeterDeviceList(MeterDevice meterDevice);
-
+    List<MeterDevice> selectMeterDeviceList(QueryDevice queryDevice);
 
-    List<MeterDevice> selectByAreaTree(QueryDevice queryDevice);
+    /**
+     * 查询计量设备列表
+     *
+     * @param queryDevice 模型编码
+     * @return 计量设备集合
+     */
+    List<MeterDevice> selectByModel(QueryDevice queryDevice);
 
     /**
      * 查询区域计量表计
-     * @param areaCode 区域代码
-     * @param objType 对象类型
+     *
+     * @param areaCode    区域代码
+     * @param objType     对象类型
      * @param boundaryObj 对象类型
-     * @param meterCls 计量对象分类
+     * @param meterCls    计量对象分类
      * @return 结果
      */
     List<MeterDevice> selectMeterDeviceByObj(String areaCode, MeterObjType objType, String boundaryObj,

+ 15 - 16
ems/ems-core/src/main/java/com/ruoyi/ems/service/impl/AbilityCallServiceImpl.java

@@ -57,14 +57,14 @@ public class AbilityCallServiceImpl implements IAbilityCallService {
     private IEmsObjModelService objModelService;
 
     @Override
-    public String abilityCall(String objCode, int objType, String abilityKey, String param) {
+    public String devAbilityCall(String objCode, String abilityKey, String param) {
         String ret = null;
 
         try {
             Assert.notNull(objCode, -1, "对象代码code不能为空");
             Assert.notNull(abilityKey, -1, "设备模型能力key不能为空");
 
-            String modeCode = getModeCode(objCode, objType);
+            String modeCode = getDevModeCode(objCode);
 
             EmsObjModel objModel = objModelService.selectByModelCode(modeCode);
             Assert.notNull(objModel, -1, "设备模型(" + modeCode + ")不存在");
@@ -77,7 +77,6 @@ public class AbilityCallServiceImpl implements IAbilityCallService {
             AbilityPayload payload = new AbilityPayload();
             payload.setObjCode(objCode);
             payload.setModeCode(modeCode);
-            payload.setObjType(objType);
             payload.setAbilityKey(abilityKey);
             payload.setAbilityParam(param);
             String jsonBody = JSON.toJSONString(payload);
@@ -99,22 +98,22 @@ public class AbilityCallServiceImpl implements IAbilityCallService {
         return ret;
     }
 
-    private String getModeCode(String objCode, int objType) {
-        String modeCode = null;
-
-        if (objType == 2) {
-            // 设备验证
-            EmsDevice device = deviceService.selectByCode(objCode);
-            Assert.notNull(device, -1, "设备不存在");
-            Assert.isTrue(null != device.getDeviceStatus() && device.getDeviceStatus() == 1, -1, "设备不在线");
+    @Override
+    public String facsAbilityCall(String objCode, String abilityKey, String param) {
+        // TODO: 暂不支持
+        throw new UnsupportedOperationException("暂不支持");
+    }
 
-            // 设备模型匹配
-            Assert.notNull(device.getDeviceModel(), -1, "设备未关联模型能力");
+    private String getDevModeCode(String objCode) {
+        // 设备验证
+        EmsDevice device = deviceService.selectByCode(objCode);
+        Assert.notNull(device, -1, "设备不存在");
+        Assert.isTrue(null != device.getDeviceStatus() && device.getDeviceStatus() == 1, -1, "设备不在线");
 
-            modeCode = device.getDeviceModel();
-        }
+        // 设备模型匹配
+        Assert.notNull(device.getDeviceModel(), -1, "设备未关联模型能力");
 
-        return modeCode;
+        return device.getDeviceModel();
     }
 
     private String execPost(String url, String jsonBody) {

+ 10 - 0
ems/ems-core/src/main/java/com/ruoyi/ems/service/impl/ElecMeterHServiceImpl.java

@@ -54,6 +54,11 @@ public class ElecMeterHServiceImpl implements IElecMeterHService {
         return elecMeterHMapper.selectElecMeterSumByDev(queryMeter);
     }
 
+    @Override
+    public ElecMeterH selectLatelyItem(String deviceCode) {
+        return elecMeterHMapper.selectLatelyItem(deviceCode);
+    }
+
     /**
      * 新增用电计量-小时
      *
@@ -65,6 +70,11 @@ public class ElecMeterHServiceImpl implements IElecMeterHService {
         return elecMeterHMapper.insertElecMeterH(elecMeterH);
     }
 
+    @Override
+    public int insertBatch(List<ElecMeterH> list) {
+        return elecMeterHMapper.insertBatch(list);
+    }
+
     /**
      * 修改用电计量-小时
      *

+ 5 - 5
ems/ems-core/src/main/java/com/ruoyi/ems/service/impl/EmsObjAttrValueServiceImpl.java

@@ -42,8 +42,8 @@ public class EmsObjAttrValueServiceImpl implements IEmsObjAttrValueService {
     }
 
     @Override
-    public List<EmsObjAttrValue> selectByObjCode(Integer objType, String objCode) {
-        return objAttrValueMapper.selectByObjCode(objType, objCode);
+    public List<EmsObjAttrValue> selectByObjCode(String modelCode, String objCode) {
+        return objAttrValueMapper.selectByObjCode(modelCode, objCode);
     }
 
     /**
@@ -60,7 +60,7 @@ public class EmsObjAttrValueServiceImpl implements IEmsObjAttrValueService {
     @Override
     public int insertBatch(List<EmsObjAttrValue> list) {
         EmsObjAttrValue objAttrValue = list.get(0);
-        objAttrValueMapper.deleteByObjCode(objAttrValue.getObjType(), objAttrValue.getObjCode());
+        objAttrValueMapper.deleteByObjCode(objAttrValue.getModelCode(), objAttrValue.getObjCode());
         return objAttrValueMapper.insertBatch(list);
     }
 
@@ -87,7 +87,7 @@ public class EmsObjAttrValueServiceImpl implements IEmsObjAttrValueService {
     }
 
     @Override
-    public int deleteByObjCode(Integer objType, String objCode) {
-        return objAttrValueMapper.deleteByObjCode(objType, objCode);
+    public int deleteByObjCode(String modelCode, String objCode) {
+        return objAttrValueMapper.deleteByObjCode(modelCode, objCode);
     }
 }

+ 5 - 5
ems/ems-core/src/main/java/com/ruoyi/ems/service/impl/MeterDeviceServiceImpl.java

@@ -41,17 +41,17 @@ public class MeterDeviceServiceImpl implements IMeterDeviceService {
     /**
      * 查询计量设备列表
      *
-     * @param meterDevice 计量设备
+     * @param queryDevice 计量设备
      * @return 计量设备
      */
     @Override
-    public List<MeterDevice> selectMeterDeviceList(MeterDevice meterDevice) {
-        return meterDeviceMapper.selectMeterDeviceList(meterDevice);
+    public List<MeterDevice> selectMeterDeviceList(QueryDevice queryDevice) {
+        return meterDeviceMapper.selectMeterDeviceList(queryDevice);
     }
 
     @Override
-    public List<MeterDevice> selectByAreaTree(QueryDevice queryDevice) {
-        return meterDeviceMapper.selectByAreaTree(queryDevice);
+    public List<MeterDevice> selectByModel(QueryDevice queryDevice) {
+        return meterDeviceMapper.selectByModel(queryDevice);
     }
 
     @Override

+ 1 - 1
ems/ems-core/src/main/java/com/ruoyi/ems/util/AreaUtils.java

@@ -40,7 +40,7 @@ public abstract class AreaUtils {
         return convertAreaTreeHelper(areas, 1, maxLevel);
     }
 
-    private static List<TreeEntity> convertAreaTreeHelper(List<?> areas, int currentLevel, int maxLevel) {
+    public static List<TreeEntity> convertAreaTreeHelper(List<?> areas, int currentLevel, int maxLevel) {
         List<TreeEntity> retList = new ArrayList<>();
 
         if (CollectionUtils.isEmpty(areas)) {

+ 27 - 1
ems/ems-core/src/main/resources/mapper/ems/ElecMeterHMapper.xml

@@ -17,6 +17,7 @@
         <result property="meterType" column="meter_type"/>
         <result property="meterUnitPrice" column="meter_unit_price"/>
         <result property="useElecCost" column="use_elec_cost"/>
+        <result property="meterReading" column="meter_reading"/>
         <result property="createTime" column="create_time"/>
     </resultMap>
 
@@ -41,6 +42,7 @@
                meter_type,
                meter_unit_price,
                use_elec_cost,
+               meter_reading,
                create_time
         from adm_elec_meter_h
     </sql>
@@ -85,6 +87,12 @@
         ORDER BY m.record_time ${orderFlag}
     </select>
 
+    <select id="selectLatelyItem" parameterType="java.lang.String" resultMap="ElecMeterHResult">
+        <include refid="selectElecMeterHVo"/>
+        where device_code = #{deviceCode}
+        ORDER BY record_time desc limit 1
+    </select>
+
     <select id="selectElecMeterSumByDev" parameterType="com.ruoyi.ems.model.QueryMeter" resultMap="ElecMeterResult">
         select
          area_code,
@@ -122,6 +130,7 @@
             <if test="meterType != null">meter_type,</if>
             <if test="meterUnitPrice != null">meter_unit_price,</if>
             <if test="useElecCost != null">use_elec_cost,</if>
+            <if test="meterReading != null">meter_reading,</if>
         </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="areaCode != null and areaCode != ''">#{areaCode},</if>
@@ -133,10 +142,26 @@
             <if test="elecQuantity != null">#{elecQuantity},</if>
             <if test="meterType != null">#{meterType},</if>
             <if test="meterUnitPrice != null">#{meterUnitPrice},</if>
-            <if test="useElecCost != null">#{useElecCost},</if>
+            <if test="meterReading != null">#{meterReading},</if>
         </trim>
     </insert>
 
+    <insert id="insertRelBatch" parameterType="java.util.List">
+        insert into adm_co_charging_config_rel (price_cfg_id, area_code)
+        values
+        <foreach collection="list" item="item" index="index" separator=",">
+            (#{item.priceCfgId}, #{item.areaCode})
+        </foreach>
+    </insert>
+
+    <insert id="insertBatch" parameterType="java.util.List">
+        insert into adm_elec_meter_h (area_code, device_code, record_time, `date`, `time`, time_index, elec_quantity, meter_type, meter_unit_price, use_elec_cost, meter_reading)
+        values
+        <foreach collection="list" item="item" index="index" separator=",">
+            (#{item.areaCode}, #{item.deviceCode}, #{item.recordTime}, #{item.date}, #{item.time}, #{item.timeIndex}, #{item.elecQuantity}, #{item.meterType}, #{item.meterUnitPrice}, #{item.useElecCost}, #{item.meterReading})
+        </foreach>
+    </insert>
+
     <update id="updateElecMeterH" parameterType="com.ruoyi.ems.domain.ElecMeterH">
         update adm_elec_meter_h
         <trim prefix="SET" suffixOverrides=",">
@@ -150,6 +175,7 @@
             <if test="meterType != null">meter_type = #{meterType},</if>
             <if test="meterUnitPrice != null">meter_unit_price = #{meterUnitPrice},</if>
             <if test="useElecCost != null">use_elec_cost = #{useElecCost},</if>
+            <if test="meterReading != null">meter_reading = #{meterReading},</if>
         </trim>
         where id = #{id}
     </update>

+ 13 - 18
ems/ems-core/src/main/resources/mapper/ems/EmsObjAbilityCallLogMapper.xml

@@ -7,7 +7,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     <resultMap type="com.ruoyi.ems.domain.EmsObjAbilityCallLog" id="objAbilityCallLogResult">
         <result property="id"    column="id"    />
         <result property="objCode"    column="obj_code"    />
-        <result property="objType"    column="obj_type"    />
         <result property="objName"    column="obj_name"    />
         <result property="modelCode"    column="model_code"    />
         <result property="modelName"    column="model_name"    />
@@ -23,26 +22,26 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     <sql id="selectList">
         select l.id, l.obj_code,
                CASE
-                   WHEN l.obj_type = 1 THEN f.facs_name
-                   WHEN l.obj_type = 2 THEN d.device_name
+                   WHEN m.obj_type = 1 THEN f.facs_name
+                   WHEN m.obj_type = 2 THEN d.device_name
                    END as obj_name,
-               l.obj_type, l.model_code, m.model_name, l.ability_key, a.ability_name, l.call_time, l.call_status from adm_ems_obj_ability_call_log l
-        left join adm_ems_facs f on l.obj_code = f.facs_code and l.obj_type = 1
-        left join adm_ems_device d on l.obj_code = d.device_code and l.obj_type = 2
-        left join adm_ems_obj_model m on l.model_code = m.model_code and l.obj_type = m.obj_type
+               l.model_code, m.model_name, l.ability_key, a.ability_name, l.call_time, l.call_status from adm_ems_obj_ability_call_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_ability a on l.ability_key = a.ability_key
     </sql>
 
     <sql id="selectDetail">
         select l.id, l.obj_code,
                case
-                   when l.obj_type = 1 then f.facs_name
-                   when l.obj_type = 2 then d.device_name
-                   end as obj_name,
-               l.obj_type, l.model_code, m.model_name, l.ability_key, a.ability_name, l.call_time, l.call_status, l.call_payload, l.res_time, l.res_payload from adm_ems_obj_ability_call_log l
-        left join adm_ems_facs f on l.obj_code = f.facs_code and l.obj_type = 1
-        left join adm_ems_device d on l.obj_code = d.device_code and l.obj_type = 2
-        left join adm_ems_obj_model m on l.model_code = m.model_code and l.obj_type = m.obj_type
+                   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, m.model_name, l.ability_key, a.ability_name, l.call_time, l.call_status, l.call_payload, l.res_time, l.res_payload from adm_ems_obj_ability_call_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_ability a on l.ability_key = a.ability_key
     </sql>
 
@@ -55,7 +54,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <include refid="selectList"/>
         <where>  
             <if test="objCode != null  and objCode != ''"> and l.obj_code = #{objCode}</if>
-            <if test="objType != null "> and l.obj_type = #{objType}</if>
             <if test="modelCode != null  and modelCode != ''"> and l.model_code = #{modelCode}</if>
             <if test="abilityKey != null  and abilityKey != ''"> and l.ability_key = #{abilityKey}</if>
             <if test="callStatus != null "> and l.call_status = #{callStatus}</if>
@@ -69,7 +67,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         insert into adm_ems_obj_ability_call_log
         <trim prefix="(" suffix=")" suffixOverrides=",">
             <if test="objCode != null and objCode != ''">obj_code,</if>
-            <if test="objType != null">obj_type,</if>
             <if test="modelCode != null and modelCode != ''">model_code,</if>
             <if test="abilityKey != null and abilityKey != ''">ability_key,</if>
             <if test="callTime != null">call_time,</if>
@@ -80,7 +77,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
          </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="objCode != null and objCode != ''">#{objCode},</if>
-            <if test="objType != null">#{objType},</if>
             <if test="modelCode != null and modelCode != ''">#{modelCode},</if>
             <if test="abilityKey != null and abilityKey != ''">#{abilityKey},</if>
             <if test="callTime != null">#{callTime},</if>
@@ -95,7 +91,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         update adm_ems_obj_ability_call_log
         <trim prefix="SET" suffixOverrides=",">
             <if test="objCode != null and objCode != ''">obj_code = #{objCode},</if>
-            <if test="objType != null">obj_type = #{objType},</if>
             <if test="modelCode != null and modelCode != ''">model_code = #{modelCode},</if>
             <if test="abilityKey != null and abilityKey != ''">ability_key = #{abilityKey},</if>
             <if test="callTime != null">call_time = #{callTime},</if>

+ 3 - 4
ems/ems-core/src/main/resources/mapper/ems/EmsObjAttrMapper.xml

@@ -52,11 +52,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
                select
                   attr_key, attr_value, update_time
                from adm_ems_obj_attr_value
-               where model_code = #{modelCode} and obj_type = #{objType} and obj_code = #{objCode}
+               where model_code = #{modelCode} and obj_code = #{objCode}
             ) v on a.attr_key = v.attr_key
-        left join
-            adm_ems_obj_attr_enum e
-           on a.model_code = e.model_code and a.attr_key = e.attr_key and v.attr_value = e.attr_value
+        join adm_ems_obj_model m on a.model_code = m.model_code and m.obj_type = #{objType}
+        left join adm_ems_obj_attr_enum e on a.model_code = e.model_code and a.attr_key = e.attr_key and v.attr_value = e.attr_value
         WHERE a.model_code = #{modelCode}
         order by attr_group, attr_name
     </select>

+ 6 - 10
ems/ems-core/src/main/resources/mapper/ems/EmsObjAttrValueMapper.xml

@@ -6,23 +6,21 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     
     <resultMap type="com.ruoyi.ems.domain.EmsObjAttrValue" id="objAttrValueResult">
         <result property="id"    column="id"    />
+        <result property="modelCode"    column="model_code"    />
         <result property="objCode"    column="obj_code"    />
-        <result property="objType"    column="obj_type"    />
         <result property="attrKey"    column="attr_key"    />
         <result property="attrValue"    column="attr_value"    />
-        <result property="modelCode"    column="model_code"    />
         <result property="updateTime"    column="update_time"    />
     </resultMap>
 
     <sql id="selectObjAttrValueVo">
-        select id, obj_code, obj_type, attr_key, attr_value, model_code, update_time from adm_ems_obj_attr_value
+        select id, model_code, obj_code, attr_key, attr_value, update_time from adm_ems_obj_attr_value
     </sql>
 
     <select id="selectObjAttrValueList" parameterType="com.ruoyi.ems.domain.EmsObjAttrValue" resultMap="objAttrValueResult">
         <include refid="selectObjAttrValueVo"/>
         <where>  
             <if test="objCode != null  and objCode != ''"> and obj_code = #{objCode}</if>
-            <if test="objType != null "> and obj_type = #{objType}</if>
             <if test="attrKey != null  and attrKey != ''"> and attr_key = #{attrKey}</if>
             <if test="modelCode != null  and modelCode != ''"> and model_code = #{modelCode}</if>
         </where>
@@ -30,7 +28,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 
     <select id="selectByObjCode" resultMap="objAttrValueResult">
         <include refid="selectObjAttrValueVo"/>
-        where obj_type = #{objType} and obj_code = #{objCode}
+        where model_code = #{modelCode} and obj_code = #{objCode}
     </select>
 
     <select id="selectObjAttrValueById" parameterType="Long" resultMap="objAttrValueResult">
@@ -42,14 +40,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         replace into adm_ems_obj_attr_value
         <trim prefix="(" suffix=")" suffixOverrides=",">
             <if test="objCode != null and objCode != ''">obj_code,</if>
-            <if test="objType != null">obj_type,</if>
             <if test="modelCode != null">model_code,</if>
             <if test="attrKey != null and attrKey != ''">attr_key,</if>
             <if test="attrValue != null">attr_value,</if>
          </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="objCode != null and objCode != ''">#{objCode},</if>
-            <if test="objType != null">#{objType},</if>
             <if test="modelCode != null">#{modelCode},</if>
             <if test="attrKey != null and attrKey != ''">#{attrKey},</if>
             <if test="attrValue != null">#{attrValue},</if>
@@ -57,10 +53,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </update>
 
     <insert id="insertBatch" parameterType="java.util.List" >
-        insert into adm_ems_obj_attr_value (obj_code, obj_type, model_code, attr_key, attr_value)
+        insert into adm_ems_obj_attr_value (obj_code, model_code, attr_key, attr_value)
         values
         <foreach collection="list" item="item" index="index" separator=",">
-            (#{item.objCode}, #{item.objType},  #{item.modelCode}, #{item.attrKey}, #{item.attrValue})
+            (#{item.objCode}, #{item.modelCode}, #{item.attrKey}, #{item.attrValue})
         </foreach>
     </insert>
 
@@ -69,7 +65,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </delete>
 
     <delete id="deleteByObjCode" >
-        delete from adm_ems_obj_attr_value where obj_type = #{objType} and obj_code = #{objCode}
+        delete from adm_ems_obj_attr_value where model_code = #{modelCode} and obj_code = #{objCode}
     </delete>
 
     <delete id="deleteObjAttrValueByIds" parameterType="String">

+ 29 - 19
ems/ems-core/src/main/resources/mapper/ems/EmsObjReportLogMapper.xml

@@ -5,43 +5,53 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 <mapper namespace="com.ruoyi.ems.mapper.EmsObjReportLogMapper">
     
     <resultMap type="com.ruoyi.ems.domain.EmsObjReportLog" id="objLogResult">
-        <result property="id"    column="id"    />
-        <result property="objCode"    column="obj_code"    />
-        <result property="objName"    column="obj_name"    />
-        <result property="objType"    column="obj_type"    />
-        <result property="msgDesc"    column="msg_desc"    />
-        <result property="reportPayload"    column="report_payload"    />
-        <result property="reportTime"    column="report_time"    />
+        <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="msgDesc"        column="msg_desc"    />
+        <result property="reportPayload"  column="report_payload"    />
+        <result property="reportTime"     column="report_time"    />
     </resultMap>
 
     <sql id="selectList">
         select l.id, l.obj_code,
                CASE
-                   WHEN l.obj_type = 1 THEN f.facs_name
-                   WHEN l.obj_type = 2 THEN d.device_name
+                   WHEN m.obj_type = 1 THEN f.facs_name
+                   WHEN m.obj_type = 2 THEN d.device_name
                    END as obj_name,
-               l.obj_type, l.msg_desc, l.report_time
+               l.model_code, l.msg_desc, l.report_time
         from adm_ems_obj_report_log l
-          left join adm_ems_facs f on l.obj_code = f.facs_code and l.obj_type = 1
-          left join adm_ems_device d on l.obj_code = d.device_code and l.obj_type = 2
+                 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
     </sql>
 
     <sql id="selectDetail">
-        select id, obj_code, obj_type, msg_desc, report_time, report_payload from adm_ems_obj_report_log
+        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.msg_desc, l.report_time, l.report_payload
+        from adm_ems_obj_report_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
     </sql>
 
     <select id="selectLogById" parameterType="java.lang.Long" resultMap="objLogResult">
         <include refid="selectDetail"/>
-        where id = #{id}
+        where l.id = #{id}
     </select>
 
     <select id="selectLog" parameterType="com.ruoyi.ems.domain.EmsObjReportLog" resultMap="objLogResult">
         <include refid="selectList"/>
         <where>  
-            <if test="objCode != null  and objCode != ''"> and obj_code = #{objCode}</if>
-            <if test="objType != null "> and obj_type = #{objType}</if>
+            <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 report_time between #{startRecTime} and #{endRecTime}
+                and l.report_time between #{startRecTime} and #{endRecTime}
             </if>
         </where>
     </select>
@@ -50,14 +60,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         insert into adm_ems_obj_report_log
         <trim prefix="(" suffix=")" suffixOverrides=",">
             <if test="objCode != null and objCode != ''">obj_code,</if>
-            <if test="objType != null">obj_type,</if>
+            <if test="modelCode != null and modelCode != ''">model_code,</if>
             <if test="msgDesc != null and msgDesc != ''">msg_desc,</if>
             <if test="reportTime != null">report_time,</if>
             <if test="reportPayload != null">report_payload,</if>
          </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="objCode != null and objCode != ''">#{objCode},</if>
-            <if test="objType != null">#{objType},</if>
+            <if test="modelCode != null and modelCode != ''">#{modelCode},</if>
             <if test="msgDesc != null and msgDesc != ''">#{msgDesc},</if>
             <if test="reportTime != null">#{reportTime},</if>
             <if test="reportPayload != null">#{reportPayload},</if>

+ 17 - 14
ems/ems-core/src/main/resources/mapper/ems/MeterDeviceMapper.xml

@@ -23,7 +23,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         select id, area_code, device_code, device_name, location, location_ref, meter_cls, obj_tag, col_cycle, col_mode, magnification, spec_desc from adm_meter_device
     </sql>
 
-    <select id="selectMeterDeviceList" parameterType="com.ruoyi.ems.domain.MeterDevice" resultMap="meterDeviceResult">
+    <select id="selectMeterDeviceList" parameterType="com.ruoyi.ems.model.QueryDevice" resultMap="meterDeviceResult">
         <include refid="selectMeterDeviceVo"/>
         <where>
             <if test="deviceCode != null and deviceCode != ''"> and device_code = #{deviceCode}</if>
@@ -32,26 +32,29 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="meterCls != null and meterCls != ''"> and meter_cls = #{meterCls}</if>
             <if test="objTag != null and objTag != ''"> and obj_tag = #{objTag}</if>
             <if test="colMode != null "> and col_mode = #{colMode}</if>
+            <if test="locationRef != null and locationRef != '' and areaCodes != null">
+                and `location_ref` in
+                <foreach item="areaCode" collection="areaCodes" open="(" separator="," close=")">
+                    #{areaCode}
+                </foreach>
+            </if>
         </where>
     </select>
 
-    <select id="selectByAreaTree" parameterType="com.ruoyi.ems.model.QueryDevice" resultMap="meterDeviceResult">
-        <include refid="selectMeterDeviceVo"/>
+    <select id="selectByModel" parameterType="com.ruoyi.ems.model.QueryDevice" resultMap="meterDeviceResult">
+        select
+            m.id, m.area_code, m.device_code, m.device_name, m.location, m.location_ref, m.meter_cls, m.obj_tag, m.col_cycle, m.col_mode, m.magnification, m.spec_desc
+        from adm_meter_device m
+        left join adm_ems_device d on m.device_code = d.device_code
         <where>
-            <if test="deviceCode != null and deviceCode != ''"> and device_code = #{deviceCode}</if>
-            <if test="deviceName != null and deviceName != ''"> and device_name like concat('%', #{deviceName}, '%')</if>
+            d.device_model = #{deviceModel}
+            <if test="areaCode != null and areaCode != ''"> and area_code = #{areaCode}</if>
             <if test="meterCls != null and meterCls != ''"> and meter_cls = #{meterCls}</if>
             <if test="objTag != null and objTag != ''"> and obj_tag = #{objTag}</if>
             <if test="colMode != null "> and col_mode = #{colMode}</if>
-            <if test="locationRef != null and locationRef != '' and areaCodes != null">
-                and `location_ref` in
-                <foreach item="areaCode" collection="areaCodes" open="(" separator="," close=")">
-                    #{areaCode}
-                </foreach>
-            </if>
         </where>
     </select>
-    
+
     <select id="selectMeterDeviceById" parameterType="Long" resultMap="meterDeviceResult">
         <include refid="selectMeterDeviceVo"/>
         where id = #{id}
@@ -84,7 +87,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="locationRef != null and locationRef != ''">location_ref,</if>
             <if test="location != null and location != ''">location,</if>
             <if test="meterCls != null and meterCls != ''">meter_cls,</if>
-            <if test="objTag != null and objTag != ''">obj_tag,</if>
+            <if test="objTag != null">obj_tag,</if>
             <if test="colCycle != null">col_cycle,</if>
             <if test="colMode != null">col_mode,</if>
             <if test="magnification != null">magnification,</if>
@@ -97,7 +100,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="locationRef != null and locationRef != ''">#{locationRef},</if>
             <if test="location != null and location != ''">#{location},</if>
             <if test="meterCls != null and meterCls != ''">#{meterCls},</if>
-            <if test="objTag != null and objTag != ''">#{objTag}</if>
+            <if test="objTag != null">#{objTag}</if>
             <if test="colCycle != null">#{colCycle},</if>
             <if test="colMode != null">#{colMode},</if>
             <if test="magnification != null">#{magnification},</if>

+ 44 - 51
ems/sql/ems_init_data.sql

@@ -288,18 +288,18 @@ INSERT INTO `adm_ems_obj_attr` (`model_code`, `attr_group`, `attr_key`, `attr_na
 
 
 -- 对象属性DEMO数据
-INSERT INTO `adm_ems_obj_attr_value` (`obj_code`, `obj_type`, `model_code`, `attr_key`, `attr_value`, `update_time`) VALUES ('864142073640059', 2, 'M_W2_QF_GEEKOPEN', 'current', '0.050', '2025-03-05 16:07:36');
-INSERT INTO `adm_ems_obj_attr_value` (`obj_code`, `obj_type`, `model_code`, `attr_key`, `attr_value`, `update_time`) VALUES ('864142073640059', 2, 'M_W2_QF_GEEKOPEN', 'energy', '421.787', '2025-03-05 16:02:36');
-INSERT INTO `adm_ems_obj_attr_value` (`obj_code`, `obj_type`, `model_code`, `attr_key`, `attr_value`, `update_time`) VALUES ('864142073640059', 2, 'M_W2_QF_GEEKOPEN', 'iccid', '898604E6192390306801', '2025-03-05 15:51:00');
-INSERT INTO `adm_ems_obj_attr_value` (`obj_code`, `obj_type`, `model_code`, `attr_key`, `attr_value`, `update_time`) VALUES ('864142073640059', 2, 'M_W2_QF_GEEKOPEN', 'key', '1', '2025-03-05 15:57:59');
-INSERT INTO `adm_ems_obj_attr_value` (`obj_code`, `obj_type`, `model_code`, `attr_key`, `attr_value`, `update_time`) VALUES ('864142073640059', 2, 'M_W2_QF_GEEKOPEN', 'keyLock', '0', '2025-03-05 15:51:00');
-INSERT INTO `adm_ems_obj_attr_value` (`obj_code`, `obj_type`, `model_code`, `attr_key`, `attr_value`, `update_time`) VALUES ('864142073640059', 2, 'M_W2_QF_GEEKOPEN', 'onState', '2', '2025-03-05 15:51:00');
-INSERT INTO `adm_ems_obj_attr_value` (`obj_code`, `obj_type`, `model_code`, `attr_key`, `attr_value`, `update_time`) VALUES ('864142073640059', 2, 'M_W2_QF_GEEKOPEN', 'power', '5.108', '2025-03-05 16:07:36');
-INSERT INTO `adm_ems_obj_attr_value` (`obj_code`, `obj_type`, `model_code`, `attr_key`, `attr_value`, `update_time`) VALUES ('864142073640059', 2, 'M_W2_QF_GEEKOPEN', 'resetLock', '0', '2025-03-05 15:51:00');
-INSERT INTO `adm_ems_obj_attr_value` (`obj_code`, `obj_type`, `model_code`, `attr_key`, `attr_value`, `update_time`) VALUES ('864142073640059', 2, 'M_W2_QF_GEEKOPEN', 'signal', '31', '2025-03-05 15:51:00');
-INSERT INTO `adm_ems_obj_attr_value` (`obj_code`, `obj_type`, `model_code`, `attr_key`, `attr_value`, `update_time`) VALUES ('864142073640059', 2, 'M_W2_QF_GEEKOPEN', 'timerEnable', '1', '2025-03-05 15:51:00');
-INSERT INTO `adm_ems_obj_attr_value` (`obj_code`, `obj_type`, `model_code`, `attr_key`, `attr_value`, `update_time`) VALUES ('864142073640059', 2, 'M_W2_QF_GEEKOPEN', 'timerInterval', '300', '2025-03-05 15:51:00');
-INSERT INTO `adm_ems_obj_attr_value` (`obj_code`, `obj_type`, `model_code`, `attr_key`, `attr_value`, `update_time`) VALUES ('864142073640059', 2, 'M_W2_QF_GEEKOPEN', 'version', '1.0.1', '2025-03-05 15:51:00');
+INSERT INTO `adm_ems_obj_attr_value` (`obj_code`, `model_code`, `attr_key`, `attr_value`, `update_time`) VALUES ('864142073640059', 'M_W2_QF_GEEKOPEN', 'current', '0.050', '2025-03-05 16:07:36');
+INSERT INTO `adm_ems_obj_attr_value` (`obj_code`, `model_code`, `attr_key`, `attr_value`, `update_time`) VALUES ('864142073640059', 'M_W2_QF_GEEKOPEN', 'energy', '421.787', '2025-03-05 16:02:36');
+INSERT INTO `adm_ems_obj_attr_value` (`obj_code`, `model_code`, `attr_key`, `attr_value`, `update_time`) VALUES ('864142073640059', 'M_W2_QF_GEEKOPEN', 'iccid', '898604E6192390306801', '2025-03-05 15:51:00');
+INSERT INTO `adm_ems_obj_attr_value` (`obj_code`, `model_code`, `attr_key`, `attr_value`, `update_time`) VALUES ('864142073640059', 'M_W2_QF_GEEKOPEN', 'key', '1', '2025-03-05 15:57:59');
+INSERT INTO `adm_ems_obj_attr_value` (`obj_code`, `model_code`, `attr_key`, `attr_value`, `update_time`) VALUES ('864142073640059', 'M_W2_QF_GEEKOPEN', 'keyLock', '0', '2025-03-05 15:51:00');
+INSERT INTO `adm_ems_obj_attr_value` (`obj_code`, `model_code`, `attr_key`, `attr_value`, `update_time`) VALUES ('864142073640059', 'M_W2_QF_GEEKOPEN', 'onState', '2', '2025-03-05 15:51:00');
+INSERT INTO `adm_ems_obj_attr_value` (`obj_code`, `model_code`, `attr_key`, `attr_value`, `update_time`) VALUES ('864142073640059', 'M_W2_QF_GEEKOPEN', 'power', '5.108', '2025-03-05 16:07:36');
+INSERT INTO `adm_ems_obj_attr_value` (`obj_code`, `model_code`, `attr_key`, `attr_value`, `update_time`) VALUES ('864142073640059', 'M_W2_QF_GEEKOPEN', 'resetLock', '0', '2025-03-05 15:51:00');
+INSERT INTO `adm_ems_obj_attr_value` (`obj_code`, `model_code`, `attr_key`, `attr_value`, `update_time`) VALUES ('864142073640059', 'M_W2_QF_GEEKOPEN', 'signal', '31', '2025-03-05 15:51:00');
+INSERT INTO `adm_ems_obj_attr_value` (`obj_code`, `model_code`, `attr_key`, `attr_value`, `update_time`) VALUES ('864142073640059', 'M_W2_QF_GEEKOPEN', 'timerEnable', '1', '2025-03-05 15:51:00');
+INSERT INTO `adm_ems_obj_attr_value` (`obj_code`, `model_code`, `attr_key`, `attr_value`, `update_time`) VALUES ('864142073640059', 'M_W2_QF_GEEKOPEN', 'timerInterval', '300', '2025-03-05 15:51:00');
+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', '断开');
@@ -558,45 +558,38 @@ INSERT INTO `adm_ems_subsystem` (`system_code`, `system_name`, `short_name`, `ma
 
 -- 能源计量设备DEMO数据
 -- 电表
-INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `location_ref`, `location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3001', 'J-D-B-101', '北区/综合楼B-101', '321283124S300101', '北区综合楼一楼设备间', 45, 1, 4, 1, 1, '智能表');
-INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `location_ref`, `location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3001', 'J-D-B-102', '北区/综合楼B-102', '321283124S300101', '北区综合楼一楼设备间', 45, 1, 4, 1, 1, '智能表');
-INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `location_ref`, `location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3001', 'J-D-B-103', '北区/综合楼B-103', '321283124S300101', '北区综合楼一楼设备间', 45, 1, 4, 1, 1, '智能表');
-INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `location_ref`, `location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3001', 'J-D-B-104', '北区/综合楼B-104', '321283124S300101', '北区综合楼一楼设备间', 45, 1, 4, 1, 1, '智能表');
-INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `location_ref`, `location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3001', 'J-D-B-105', '北区/综合楼B-105', '321283124S300101', '北区综合楼一楼设备间', 45, 1, 4, 1, 1, '智能表');
-INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `location_ref`, `location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3001', 'J-D-B-106', '北区/综合楼B-106', '321283124S300101', '北区综合楼一楼设备间', 45, 1, 4, 1, 1, '智能表');
-INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `location_ref`, `location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3001', 'J-D-B-107', '北区/综合楼B-107', '321283124S300101', '北区综合楼一楼设备间', 45, 1, 4, 1, 1, '智能表');
-INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `location_ref`, `location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3001', 'J-D-B-108', '北区/综合楼B-108', '321283124S300101', '北区综合楼一楼设备间', 45, 1, 4, 1, 1, '智能表');
-INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `location_ref`, `location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3001', 'J-D-B-109', '北区/综合楼B-109', '321283124S300101', '北区综合楼一楼设备间', 45, 1, 4, 1, 1, '智能表');
-INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `location_ref`, `location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3001', 'J-D-B-110', '北区/综合楼B-110', '321283124S300101', '北区综合楼一楼设备间', 45, 1, 4, 1, 1, '智能表');
-INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `location_ref`, `location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3001', 'J-D-B-Z101', '北区/综合楼内照明(Z101)', '321283124S300101', '北区综合楼一楼设备间', 45, 0, 4, 0, 1, '智能表');
-INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `location_ref`, `location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3001', 'J-D-B-Z102', '北区/综合楼室外照明(Z102)', '321283124S300101', '北区综合楼2#箱', 45, 0, 4, 0, 1, '智能表');
-INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `location_ref`, `location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3001', 'J-D-B-Z110', '北区/综合楼公共设施(Z110)', '321283124S300101', '北区综合楼1#箱', 45, 0, 4, 0, 1, '智能表');
-INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `location_ref`, `location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3001', 'J-D-B-Z120', '北区/综合楼空调(Z120)', '321283124S300101', '北区综合楼1#箱', 45, 0, 4, 0, 50, '智能表');
-INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `location_ref`, `location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3001', 'J-D-B-G001', '北区/广场照明', '321283124S300101', '北区广场1#配电柜', 45, 0, 4, 0, 1, '智能表');
-
-INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `location_ref`, `location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3002', 'J-D-N-101', '南区/综合楼N-101', '321283124S300201','南区综合楼一楼设备间', 45, 1, 4, 1, 1, '智能表');
-INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `location_ref`, `location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3002', 'J-D-N-102', '南区/综合楼N-103', '321283124S300201', '南区综合楼一楼设备间', 45, 1, 4, 1, 1, '智能表');
-INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `location_ref`, `location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3002', 'J-D-N-103', '南区/综合楼N-105', '321283124S300201', '南区综合楼一楼设备间', 45, 1, 4, 1, 1, '智能表');
-INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `location_ref`, `location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3002', 'J-D-N-104', '南区/综合楼N-107', '321283124S300201', '南区综合楼一楼设备间', 45, 1, 4, 1, 1, '智能表');
-INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `location_ref`, `location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3002', 'J-D-N-105', '南区/综合楼N-109', '321283124S300201', '南区综合楼一楼设备间', 45, 1, 4, 1, 1, '智能表');
-INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `location_ref`, `location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3002', 'J-D-N-106', '南区/综合楼N-110', '321283124S300201', '南区综合楼一楼设备间', 45, 1, 4, 1, 1, '智能表');
-INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `location_ref`, `location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3002', 'J-D-N-107', '南区/综合楼N-112', '321283124S300201', '南区综合楼一楼设备间', 45, 1, 4, 1, 1, '智能表');
-INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `location_ref`, `location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3002', 'J-D-N-108', '南区/综合楼N-113', '321283124S300201', '南区综合楼一楼设备间', 45, 1, 4, 1, 1, '智能表');
-INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `location_ref`, `location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3002', 'J-D-N-109', '南区/综合楼N-114', '321283124S300201', '南区综合楼一楼设备间', 45, 1, 4, 1, 1, '智能表');
-INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `location_ref`, `location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3002', 'J-D-N-110', '南区/综合楼N-115', '321283124S300201', '南区综合楼一楼设备间', 45, 0, 4, 1, 1, '智能表');
-INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `location_ref`, `location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3002', 'J-D-N-Z201', '南区/综合楼内照明(Z201)', '321283124S300201', '南区综合楼一楼设备间', 45, 0, 4, 0, 1, '智能表');
-INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `location_ref`, `location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3002', 'J-D-N-Z202', '南区/综合楼室外照明(Z202)', '321283124S300201', '南区综合楼2#箱', 45, 0, 4, 0, 1, '智能表');
-INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `location_ref`, `location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3002', 'J-D-N-Z210', '南区/综合楼公共设施(Z210)', '321283124S300201', '南区综合楼1#箱', 45, 0, 4, 0, 1, '智能表');
-INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `location_ref`, `location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3002', 'J-D-N-Z220', '南区/综合楼空调(Z220)', '321283124S300201', '南区综合楼1#箱', 45, 0, 4, 0, 50, '智能表');
-INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `location_ref`, `location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3002', 'J-D-N-G001', '南区/广场照明', '321283124S300201', '南区广场1#配电柜', 45, 0, 4, 0, 1, '智能表');
-
--- 智能断路器
-INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `location_ref`, `location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3001', 'J-D-B-864142073640059', '智能断路器', '321283124S3001','华设C3-开水间', 45, 0, 4, 0, 1, '智能断路器');
-
--- 水表
-INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `location_ref`, `location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3001', 'J-S-B-02', '北区/综合楼B-102', '321283124S3001', '北区综合楼后院1号井', 70, 0, 4, 1, 1, '直采表');
-INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `location_ref`, `location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3001', 'J-S-B-01', '北区/综合楼盥洗室', '321283124S3001', '北区综合楼后院1号井', 70, 0, 4, 0, 1, '直采表');
-INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `location_ref`, `location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3002', 'J-S-N-01', '南区/综合楼盥洗室', '321283124S3001', '南区综合楼后院1号井', 70, 0, 4, 0, 1, '直采表');
+INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `location_ref`, `location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3001', 'J-D-B-101', '北区/综合楼B-101', '321283124S300101', '一楼设备间', 45, 1, NULL, 1, 1, '智能表');
+INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `location_ref`, `location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3001', 'J-D-B-102', '北区/综合楼B-102', '321283124S300101', '一楼设备间', 45, 1, NULL, 1, 1, '智能表');
+INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `location_ref`, `location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3001', 'J-D-B-103', '北区/综合楼B-103', '321283124S300101', '一楼设备间', 45, 1, NULL, 1, 1, '智能表');
+INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `location_ref`, `location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3001', 'J-D-B-104', '北区/综合楼B-104', '321283124S300101', '一楼设备间', 45, 1, NULL, 1, 1, '智能表');
+INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `location_ref`, `location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3001', 'J-D-B-105', '北区/综合楼B-105', '321283124S300101', '一楼设备间', 45, 1, NULL, 1, 1, '智能表');
+INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `location_ref`, `location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3001', 'J-D-B-106', '北区/综合楼B-106', '321283124S300101', '一楼设备间', 45, 1, NULL, 1, 1, '智能表');
+INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `location_ref`, `location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3001', 'J-D-B-107', '北区/综合楼B-107', '321283124S300101', '一楼设备间', 45, 1, NULL, 1, 1, '智能表');
+INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `location_ref`, `location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3001', 'J-D-B-108', '北区/综合楼B-108', '321283124S300101', '一楼设备间', 45, 1, NULL, 1, 1, '智能表');
+INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `location_ref`, `location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3001', 'J-D-B-109', '北区/综合楼B-109', '321283124S300101', '一楼设备间', 45, 1, NULL, 1, 1, '智能表');
+INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `location_ref`, `location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3001', 'J-D-B-110', '北区/综合楼B-110', '321283124S300101', '一楼设备间', 45, 1, NULL, 1, 1, '智能表');
+INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `location_ref`, `location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3001', 'J-D-B-Z101', '北区/综合楼内照明(Z101)', '321283124S300101', '一楼设备间', 45, 0, 3600, 0, 1, '智能表');
+INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `location_ref`, `location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3001', 'J-D-B-Z102', '北区/综合楼室外照明(Z102)', '321283124S300101', '北区综合楼2#箱', 45, 0, 3600, 0, 1, '智能表');
+INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `location_ref`, `location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3001', 'J-D-B-Z110', '北区/综合楼公共设施(Z110)', '321283124S300101', '北区综合楼1#箱', 45, 0, 3600, 0, 1, '智能表');
+INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `location_ref`, `location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3001', 'J-D-B-Z120', '北区/综合楼空调(Z120)', '321283124S300101', '北区综合楼1#箱', 45, 0, 3600, 0, 50, '智能表');
+INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `location_ref`, `location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3001', 'J-D-B-G001', '北区/广场照明', '321283124S300101', '北区广场1#配电柜', 45, 0, 3600, 0, 1, '智能表');
+INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `location_ref`, `location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3002', 'J-D-N-101', '南区/综合楼N-101', '321283124S300201', '一楼设备间', 45, 1, NULL, 1, 1, '智能表');
+INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `location_ref`, `location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3002', 'J-D-N-102', '南区/综合楼N-103', '321283124S300201', '一楼设备间', 45, 1, NULL, 1, 1, '智能表');
+INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `location_ref`, `location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3002', 'J-D-N-103', '南区/综合楼N-105', '321283124S300201', '一楼设备间', 45, 1, NULL, 1, 1, '智能表');
+INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `location_ref`, `location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3002', 'J-D-N-104', '南区/综合楼N-107', '321283124S300201', '一楼设备间', 45, 1, NULL, 1, 1, '智能表');
+INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `location_ref`, `location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3002', 'J-D-N-105', '南区/综合楼N-109', '321283124S300201', '一楼设备间', 45, 1, NULL, 1, 1, '智能表');
+INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `location_ref`, `location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3002', 'J-D-N-106', '南区/综合楼N-110', '321283124S300201', '一楼设备间', 45, 1, NULL, 1, 1, '智能表');
+INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `location_ref`, `location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3002', 'J-D-N-107', '南区/综合楼N-112', '321283124S300201', '一楼设备间', 45, 1, NULL, 1, 1, '智能表');
+INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `location_ref`, `location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3002', 'J-D-N-108', '南区/综合楼N-113', '321283124S300201', '一楼设备间', 45, 1, NULL, 1, 1, '智能表');
+INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `location_ref`, `location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3002', 'J-D-N-109', '南区/综合楼N-114', '321283124S300201', '一楼设备间', 45, 1, NULL, 1, 1, '智能表');
+INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `location_ref`, `location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3002', 'J-D-N-110', '南区/综合楼N-115', '321283124S300201', '一楼设备间', 45, 0, 3600, 1, 1, '智能表');
+INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `location_ref`, `location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3002', 'J-D-N-Z201', '南区/综合楼内照明(Z201)', '321283124S300201', '一楼设备间', 45, 0, 3600, 0, 1, '智能表');
+INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `location_ref`, `location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3002', 'J-D-N-Z202', '南区/综合楼室外照明(Z202)', '321283124S300201', '综合楼2#箱', 45, 0, 3600, 0, 1, '智能表');
+INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `location_ref`, `location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3002', 'J-D-N-Z210', '南区/综合楼公共设施(Z210)', '321283124S300201', '综合楼1#箱', 45, 0, 3600, 0, 1, '智能表');
+INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `location_ref`, `location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3002', 'J-D-N-Z220', '南区/综合楼空调(Z220)', '321283124S300201', '综合楼1#箱', 45, 0, 3600, 0, 50, '智能表');
+INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `location_ref`, `location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3002', 'J-D-N-G001', '南区/广场照明', '321283124S300201', '广场1#配电柜', 45, 0, 3600, 0, 1, '智能表');
+INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `location_ref`, `location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3001', '864142073640059', '智能断路器', '321283124S300101', '综合楼C3-茶水间', 45, 0, 3600, 0, 1, '智能表');
+
 
 -- 表计绑定关系
 INSERT INTO `adm_meter_boundary_rel` (`obj_type`, `boundary_obj`, `meter_cls`, `meter_device`) VALUES (1, 'B-101', 45, 'J-D-B-101');

+ 6 - 7
ems/sql/ems_server.sql

@@ -625,13 +625,12 @@ drop table if exists adm_ems_obj_attr_value;
 create table adm_ems_obj_attr_value  (
   `id`              bigint(20)      not null auto_increment      comment '序号',
   `obj_code`        varchar(64)     not null                     comment '对象代码',
-  `obj_type`        int             not null                     comment '对象类型',
   `model_code`      varchar(64)     not null                     comment '模型code',
   `attr_key`        varchar(128)    not null                     comment '属性标识',
   `attr_value`      varchar(32)     default null                 comment '属性值',
   `update_time`     datetime        default CURRENT_TIMESTAMP    ON UPDATE CURRENT_TIMESTAMP comment '更新时间',
   primary key (`id`),
-  unique key ux_ems_obj_attr_value(`obj_code`, `obj_type`, `model_code`, `attr_key`)
+  unique key ux_ems_obj_attr_value(`obj_code`, `model_code`, `attr_key`)
 ) engine=innodb auto_increment=1 comment = '能源对象属性值表';
 
 
@@ -659,16 +658,15 @@ drop table if exists adm_ems_obj_ability_call_log;
 create table adm_ems_obj_ability_call_log  (
   `id`              bigint(20)      not null auto_increment      comment '序号',
   `obj_code`        varchar(64)     not null                     comment '对象代码',
-  `obj_type`        int             not null                     comment '对象类型',
   `model_code`      varchar(64)     not null                     comment '模型code',
   `ability_key`     varchar(128)    not null                     comment '能力键',
   `call_time`       datetime        not null                     comment '调用时间',
-  `call_payload`      text            default null                 comment '调用参数',
+  `call_payload`    text            default null                 comment '调用参数',
   `call_status`     int             not null                     comment '调用状态',
   `res_time`        datetime        default null                 comment '响应时间',
   `res_payload`       text            default null                 comment '响应内容',
   primary key (`id`),
-  key i_ability_call_log(`obj_code`, `obj_type`, `ability_key`, `call_time`)
+  key i_ability_call_log(`obj_code`, `model_code`, `ability_key`, `call_time`)
 ) engine=innodb auto_increment=1 comment = '能源对象能力调用日志表';
 
 
@@ -679,12 +677,12 @@ drop table if exists adm_ems_obj_report_log;
 create table adm_ems_obj_report_log  (
   `id`              bigint(20)      not null auto_increment      comment '序号',
   `obj_code`        varchar(64)     not null                     comment '对象代码',
-  `obj_type`        int             not null                     comment '对象类型',
+  `model_code`      varchar(64)     not null                     comment '模型code',
   `msg_desc`        varchar(128)    default null                 comment '消息描述',
   `report_time`     datetime        not null                     comment '上报时间',
   `report_payload`  text            default null                 comment '上报参数',
   primary key (`id`),
-  key i_obj_report_log(`obj_code`, `obj_type`, `report_time`)
+  key i_obj_report_log(`obj_code`, `model_code`, `report_time`)
 ) engine=innodb auto_increment=1 comment = '能源对象上报日志表';
 
 
@@ -1164,6 +1162,7 @@ create table adm_elec_meter_h (
   `meter_type`         int             default null                 comment '计量类型 -1:低谷电 0:平峰电 1:高峰电 2:尖峰电',
   `meter_unit_price`   double          default null                 comment '单位电价(1度电)',
   `use_elec_cost`      double          default null                 comment '小时电费',
+  `meter_reading`      double          default null                 comment '抄表示数',
   `create_time`        datetime        default CURRENT_TIMESTAMP    comment '创建时间',
   primary key (`id`),
   unique key ux_elec_meter_h(`device_code`, `record_time`)