Răsfoiți Sursa

设备接口改造

learshaw 4 luni în urmă
părinte
comite
a8e100dc12

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

@@ -66,11 +66,7 @@ public class CircuitBreakerController {
         CallResponse<Void> res = null;
 
         try {
-            String ret = devAdapterService.call(abilityPayload);
-            res = new CallResponse<>(0, ret);
-        }
-        catch (BusinessException e) {
-            res = new CallResponse<>(500, e.getMessage());
+            res = devAdapterService.call(abilityPayload);
         }
         catch (Exception e) {
             log.error("geekOpenCbAbilityCall fail!", e);

+ 41 - 37
ems/ems-cloud/ems-dev-adapter/src/main/java/com/ruoyi/ems/handle/GeekOpenCbHandler.java

@@ -19,16 +19,15 @@ import com.ruoyi.ems.core.MessageCache;
 import com.ruoyi.ems.domain.ElecMeterH;
 import com.ruoyi.ems.domain.EmsDevice;
 import com.ruoyi.ems.domain.EmsObjAbilityCallLog;
-import com.ruoyi.ems.domain.EmsObjReportLog;
 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.IEmsObjAbilityCallLogService;
 import com.ruoyi.ems.service.IMeterDeviceService;
 import com.ruoyi.ems.service.IPriceService;
 import com.ruoyi.ems.util.IdUtils;
@@ -47,7 +46,6 @@ import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
 import java.time.temporal.ChronoUnit;
 import java.util.Date;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
@@ -67,8 +65,6 @@ public class GeekOpenCbHandler extends MqttBaseHandler {
     @Autowired
     private MessageCache messageCache;
 
-
-
     @Autowired
     private IMeterDeviceService meterDeviceService;
 
@@ -89,11 +85,14 @@ public class GeekOpenCbHandler extends MqttBaseHandler {
      * @return 响应
      */
     @Override
-    public String call(AbilityPayload abilityParam) {
-        String retStr = "执行成功!";
+    public CallResponse<Void> call(AbilityPayload abilityParam) {
+        CallResponse<Void> callResponse = null;
+
+        JSONObject sendObject = JSONObject.parseObject(abilityParam.getAbilityParam());
+        String type = sendObject.getString("type");
 
-        String messageId = "CALL-" + IdUtils.generateMessageId();
         String deviceCode = abilityParam.getObjCode();
+        String messageId = StringUtils.equals("syncStatistic", type) ? "auto" : ("CALL-" + IdUtils.generateMessageId());
         String msgBody = addMsgId(abilityParam.getAbilityParam(), "messageId", messageId);
 
         // 发送消息到MQTT服务器
@@ -104,9 +103,6 @@ public class GeekOpenCbHandler extends MqttBaseHandler {
         // 写入日志
         EmsObjAbilityCallLog logItem = saveCallLog(abilityParam, sendTime, 1);
 
-        JSONObject sendObject = JSONObject.parseObject(abilityParam.getAbilityParam());
-        String type = sendObject.getString("type");
-
         if (StringUtils.equals(type, "event") || StringUtils.equals(type, "setting")) {
             while (true) {
                 MqttCacheMsg cacheMsg = messageCache.getAndRemoveMqttMessage(messageId);
@@ -114,15 +110,15 @@ public class GeekOpenCbHandler extends MqttBaseHandler {
                 if (null != cacheMsg) {
                     String receiveParam = cacheMsg.getPayload();
                     JSONObject receiveObject = JSONObject.parseObject(receiveParam);
+                    callResponse = checkResult(sendObject, receiveObject);
 
-                    if (checkResult(sendObject, receiveObject)) {
-                        retStr = "执行成功!";
+                    if (callResponse.getCode() == 0) {
                         updateCallLog(logItem, cacheMsg, 1);
                     }
                     else {
-                        retStr = "执行失败!";
                         updateCallLog(logItem, cacheMsg, 2);
                     }
+
                     break;
                 }
 
@@ -131,13 +127,13 @@ public class GeekOpenCbHandler extends MqttBaseHandler {
                 if (System.currentTimeMillis() - sendTime > 20000) {
                     EmsDevice device = deviceService.selectByCode(deviceCode);
                     refreshStatus(device, DevOnlineStatus.OFFLINE);
-                    retStr = "响应超时!";
+                    callResponse = new CallResponse<>(-1, "响应超时!");
                     break;
                 }
             }
         }
 
-        return retStr;
+        return callResponse;
     }
 
     @Async("msgHandleExecutor")
@@ -338,48 +334,56 @@ public class GeekOpenCbHandler extends MqttBaseHandler {
         }
     }
 
-    private boolean checkResult(JSONObject sendObject, JSONObject receiveObject) {
-        boolean flag = true;
+    private CallResponse<Void> checkResult(JSONObject sendObject, JSONObject receiveObject) {
+        CallResponse<Void> response = new CallResponse<>();
 
         try {
             String type = sendObject.getString("type");
 
             if (StringUtils.equals(type, "event")) {
-                int sendKeyValue = sendObject.getIntValue("key");
-                int receiveKeyValue = receiveObject.getIntValue("key");
-                Assert.isTrue(sendKeyValue == receiveKeyValue, -1, "响应参数key校验失败!");
+                String sendKeyValue = sendObject.getString("key");
+                String receiveKeyValue = receiveObject.getString("key");
+                Assert.isTrue(StringUtils.equals(sendKeyValue, receiveKeyValue), -1, "响应参数key校验失败!");
             }
             else if (StringUtils.equals(type, "setting")) {
                 if (sendObject.containsKey("keyLock")) {
-                    int sendKeyLockValue = sendObject.getIntValue("keyLock");
-                    int receiveKeyLockValue = receiveObject.getIntValue("keyLock");
-                    Assert.isTrue(sendKeyLockValue == receiveKeyLockValue, -1, "响应参数keyLock校验失败!");
+                    String sendKeyLockValue = sendObject.getString("keyLock");
+                    String receiveKeyLockValue = receiveObject.getString("keyLock");
+                    Assert.isTrue(StringUtils.equals(sendKeyLockValue, receiveKeyLockValue), -1,
+                        "响应参数keyLock校验失败!");
                 }
                 else if (sendObject.containsKey("timerEnable") && sendObject.containsKey("timerInterval")) {
-                    int sendTimerEnableValue = sendObject.getIntValue("timerEnable");
-                    int receiveTimerEnableValue = receiveObject.getIntValue("timerEnable");
-                    Assert.isTrue(sendTimerEnableValue == receiveTimerEnableValue, -1, "响应参数timerEnable校验失败!");
-                    int sendTimerIntervalValue = sendObject.getIntValue("keyLock");
-                    int receiveTimerIntervalValue = receiveObject.getIntValue("timerInterval");
-                    Assert.isTrue(sendTimerIntervalValue == receiveTimerIntervalValue, -1,
+                    String sendTimerEnableValue = sendObject.getString("timerEnable");
+                    String receiveTimerEnableValue = receiveObject.getString("timerEnable");
+                    Assert.isTrue(StringUtils.equals(sendTimerEnableValue, receiveTimerEnableValue), -1,
+                        "响应参数timerEnable校验失败!");
+                    String sendTimerIntervalValue = sendObject.getString("keyLock");
+                    String receiveTimerIntervalValue = receiveObject.getString("timerInterval");
+                    Assert.isTrue(StringUtils.equals(sendTimerIntervalValue, receiveTimerIntervalValue), -1,
                         "响应参数timerInterval校验失败!");
                 }
                 else if (sendObject.containsKey("onState")) {
-                    int sendOnStateValue = sendObject.getIntValue("onState");
-                    int receiveOnStateValue = receiveObject.getIntValue("onState");
-                    Assert.isTrue(sendOnStateValue == receiveOnStateValue, -1, "响应参数onState校验失败!");
+                    String sendOnStateValue = sendObject.getString("onState");
+                    String receiveOnStateValue = receiveObject.getString("onState");
+                    Assert.isTrue(StringUtils.equals(sendOnStateValue, receiveOnStateValue), -1,
+                        "响应参数onState校验失败!");
                 }
             }
+
+            response.setCode(0);
+            response.setMessage("执行成功!");
         }
         catch (BusinessException e) {
-            log.info(e.getMessage());
-            flag = false;
+            log.warn(e.getMessage());
+            response.setCode(e.getCode());
+            response.setMessage(e.getMessage());
         }
         catch (Exception e) {
             log.error(e.getMessage(), e);
-            flag = false;
+            response.setCode(-1);
+            response.setMessage("内部错误!");
         }
 
-        return flag;
+        return response;
     }
 }

+ 2 - 1
ems/ems-cloud/ems-dev-adapter/src/main/java/com/ruoyi/ems/handle/MqttBaseHandler.java

@@ -19,6 +19,7 @@ import com.ruoyi.ems.domain.EmsObjAttrValue;
 import com.ruoyi.ems.domain.EmsObjReportLog;
 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.service.IEmsDeviceService;
 import com.ruoyi.ems.service.IEmsObjAbilityCallLogService;
@@ -86,7 +87,7 @@ public abstract class MqttBaseHandler {
      * @param abilityParam 能力参数
      * @return 处理结果字符串
      */
-    public abstract String call(AbilityPayload abilityParam);
+    public abstract CallResponse<Void> call(AbilityPayload abilityParam);
 
     /**
      * 抽象方法,用于消息处理

+ 24 - 5
ems/ems-cloud/ems-server/src/main/java/com/ruoyi/ems/controller/AreaController.java

@@ -75,7 +75,8 @@ public class AreaController extends BaseController {
      */
     @RequiresPermissions("ems:area:list")
     @GetMapping("/getAreaListByTag")
-    public AjaxResult getAreaListByTag(@RequestParam(name = "parentCode", required = false, defaultValue = "0") String parentCode,
+    public AjaxResult getAreaListByTag(
+        @RequestParam(name = "parentCode", required = false, defaultValue = "0") String parentCode,
         @RequestParam(name = "recursion", required = false, defaultValue = "true") boolean recursion,
         @RequestParam(name = "tagCode") String tagCode) {
         // 查询区域树
@@ -106,9 +107,26 @@ public class AreaController extends BaseController {
      */
     @GetMapping(value = "/getAreaTree")
     public AjaxResult getAreaTree(@RequestParam(name = "rootCode") String rootCode,
-        @RequestParam(name = "recursion", required = false) boolean recursion) {
-        List<Area> areas = areaService.selectAreaTree(rootCode, recursion);
-        List<TreeEntity> ret = AreaUtils.convertAreaTree(areas);
+        @RequestParam(name = "layer", required = false) Integer layer) {
+        List<TreeEntity> ret = null;
+
+        if (null == layer) {
+            List<Area> areas = areaService.selectAreaTree(rootCode, true);
+            ret = AreaUtils.convertAreaTree(areas);
+        }
+        else {
+            List<Area> areas = null;
+
+            if (layer == 1) {
+                areas = areaService.selectAreaTree(rootCode, false);
+            }
+            else {
+                areas = areaService.selectAreaTree(rootCode, true);
+            }
+
+            ret = AreaUtils.convertAreaTree(areas, layer);
+        }
+
         return success(ret);
     }
 
@@ -150,7 +168,8 @@ public class AreaController extends BaseController {
      * @return 区域位置树
      */
     @GetMapping(value = "/getAreaTreeByTag")
-    public AjaxResult getAreaTreeByTag(@RequestParam(name = "parentCode", required = false, defaultValue = "0") String parentCode,
+    public AjaxResult getAreaTreeByTag(
+        @RequestParam(name = "parentCode", required = false, defaultValue = "0") String parentCode,
         @RequestParam(name = "recursion", required = false, defaultValue = "true") boolean recursion,
         @RequestParam(name = "tagCode") String tagCode) {
         // 查询区域树

+ 42 - 0
ems/ems-cloud/ems-server/src/main/java/com/ruoyi/ems/controller/MeterDeviceController.java

@@ -1,15 +1,22 @@
 package com.ruoyi.ems.controller;
 
 import com.huashe.common.domain.AjaxResult;
+import com.huashe.common.exception.BusinessException;
 import com.ruoyi.common.core.utils.poi.ExcelUtil;
 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;
+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.service.IAreaService;
 import com.ruoyi.ems.service.IMeterDeviceService;
+import com.ruoyi.ems.util.AreaUtils;
 import io.swagger.annotations.Api;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.DeleteMapping;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -21,6 +28,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.servlet.http.HttpServletResponse;
+import java.util.ArrayList;
 import java.util.List;
 
 /**
@@ -36,6 +44,9 @@ public class MeterDeviceController extends BaseController {
     @Autowired
     private IMeterDeviceService meterDeviceService;
 
+    @Autowired
+    private IAreaService areaService;
+
     /**
      * 查询计量设备列表
      */
@@ -48,6 +59,37 @@ public class MeterDeviceController extends BaseController {
     }
 
     /**
+     * 递归查询 区域 下的设备(分页)
+     */
+    @RequiresPermissions("basecfg:device:list")
+    @GetMapping("/listRecursionByArea")
+    public TableDataInfo listRecursionByArea(QueryDevice queryDevice) {
+        TableDataInfo tabInfo = null;
+
+        try {
+            if (StringUtils.isNotEmpty(queryDevice.getLocationRef())) {
+                List<Area> areaTree = areaService.selectAreaTree(queryDevice.getLocationRef(), true);
+                List<String> areaCodes = new ArrayList<>();
+                areaCodes.add(queryDevice.getLocationRef());
+                // 递归取出区域子节点code做查询条件(需要将子节点区域关联设备一并取出)
+                AreaUtils.getCodeRecursion(areaTree, areaCodes);
+                queryDevice.setAreaCodes(areaCodes);
+            }
+
+            startPage();
+            List<MeterDevice> list = meterDeviceService.selectByAreaTree(queryDevice);
+            tabInfo = getDataTable(list);
+        }
+        catch (BusinessException e) {
+            tabInfo = new TableDataInfo();
+            tabInfo.setCode(e.getCode());
+            tabInfo.setMsg(e.getMessage());
+        }
+
+        return tabInfo;
+    }
+
+    /**
      * 导出计量设备列表
      */
     @RequiresPermissions("ems:meterdevc:export")

+ 28 - 15
ems/ems-core/src/main/java/com/ruoyi/ems/domain/MeterDevice.java

@@ -34,12 +34,17 @@ public class MeterDevice extends BaseEntity {
     /**
      * 设备位置
      */
-    private String deviceLocation;
+    private String locationRef;
+
+    /**
+     * 设备位置
+     */
+    private String location;
 
     /**
      * 计量类别
      */
-    private Long meterCls;
+    private Integer meterCls;
 
     /**
      * 计量对象标记
@@ -49,12 +54,12 @@ public class MeterDevice extends BaseEntity {
     /**
      * 采集周期
      */
-    private Long colCycle;
+    private Integer colCycle;
 
     /**
      * 采集方式
      */
-    private Long colMode;
+    private Integer colMode;
 
     /**
      * 倍率
@@ -98,19 +103,27 @@ public class MeterDevice extends BaseEntity {
         this.deviceName = deviceName;
     }
 
-    public String getDeviceLocation() {
-        return deviceLocation;
+    public String getLocationRef() {
+        return locationRef;
+    }
+
+    public void setLocationRef(String locationRef) {
+        this.locationRef = locationRef;
+    }
+
+    public String getLocation() {
+        return location;
     }
 
-    public void setDeviceLocation(String deviceLocation) {
-        this.deviceLocation = deviceLocation;
+    public void setLocation(String location) {
+        this.location = location;
     }
 
-    public Long getMeterCls() {
+    public Integer getMeterCls() {
         return meterCls;
     }
 
-    public void setMeterCls(Long meterCls) {
+    public void setMeterCls(Integer meterCls) {
         this.meterCls = meterCls;
     }
 
@@ -122,19 +135,19 @@ public class MeterDevice extends BaseEntity {
         this.objTag = objTag;
     }
 
-    public Long getColCycle() {
+    public Integer getColCycle() {
         return colCycle;
     }
 
-    public void setColCycle(Long colCycle) {
+    public void setColCycle(Integer colCycle) {
         this.colCycle = colCycle;
     }
 
-    public Long getColMode() {
+    public Integer getColMode() {
         return colMode;
     }
 
-    public void setColMode(Long colMode) {
+    public void setColMode(Integer colMode) {
         this.colMode = colMode;
     }
 
@@ -157,7 +170,7 @@ public class MeterDevice extends BaseEntity {
     @Override
     public String toString() {
         return "MeterDevice{" + "id=" + id + ", areaCode='" + areaCode + '\'' + ", deviceCode='" + deviceCode + '\''
-            + ", deviceName='" + deviceName + '\'' + ", deviceLocation='" + deviceLocation + '\'' + ", meterCls="
+            + ", deviceName='" + deviceName + '\'' + ", location='" + location + '\'' + ", meterCls="
             + meterCls + ", objTag=" + objTag + ", colCycle=" + colCycle + ", colMode=" + colMode + ", magnification="
             + magnification + ", specDesc='" + specDesc + '\'' + '}';
     }

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

@@ -1,6 +1,7 @@
 package com.ruoyi.ems.mapper;
 
 import com.ruoyi.ems.domain.MeterDevice;
+import com.ruoyi.ems.model.QueryDevice;
 import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
@@ -40,6 +41,8 @@ public interface MeterDeviceMapper {
      */
     List<MeterDevice> selectMeterDeviceList(MeterDevice meterDevice);
 
+    List<MeterDevice> selectByAreaTree(QueryDevice queryDevice);
+
     /**
      * 新增计量设备
      *

+ 39 - 0
ems/ems-core/src/main/java/com/ruoyi/ems/model/QueryDevice.java

@@ -62,6 +62,21 @@ public class QueryDevice {
 
     private String upstreamObjCode;
 
+    /**
+     * 计量类别
+     */
+    private Integer meterCls;
+
+    /**
+     * 采集方式
+     */
+    private Integer colMode;
+
+    /**
+     * 计量对象标记
+     */
+    private Integer objTag;
+
     private List<String> areaCodes;
 
     public String getDeviceCode() {
@@ -176,6 +191,30 @@ public class QueryDevice {
         this.upstreamObjCode = upstreamObjCode;
     }
 
+    public Integer getMeterCls() {
+        return meterCls;
+    }
+
+    public void setMeterCls(Integer meterCls) {
+        this.meterCls = meterCls;
+    }
+
+    public Integer getColMode() {
+        return colMode;
+    }
+
+    public void setColMode(Integer colMode) {
+        this.colMode = colMode;
+    }
+
+    public Integer getObjTag() {
+        return objTag;
+    }
+
+    public void setObjTag(Integer objTag) {
+        this.objTag = objTag;
+    }
+
     public List<String> getAreaCodes() {
         return areaCodes;
     }

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

@@ -2,6 +2,7 @@ package com.ruoyi.ems.service;
 
 import com.ruoyi.ems.domain.MeterDevice;
 import com.ruoyi.ems.enums.MeterObjType;
+import com.ruoyi.ems.model.QueryDevice;
 
 import java.util.List;
 
@@ -36,6 +37,9 @@ public interface IMeterDeviceService {
      */
     List<MeterDevice> selectMeterDeviceList(MeterDevice meterDevice);
 
+
+    List<MeterDevice> selectByAreaTree(QueryDevice queryDevice);
+
     /**
      * 查询区域计量表计
      * @param areaCode 区域代码

+ 7 - 7
ems/ems-core/src/main/java/com/ruoyi/ems/service/impl/EmsDeviceServiceImpl.java

@@ -164,6 +164,13 @@ public class EmsDeviceServiceImpl implements IEmsDeviceService {
         }
     }
 
+    private void fillAreaName(EmsDevice emsDevice) {
+        List<Area> areas = areaService.selectArea(new Area());
+        Map<String, Area> areaMap = areas.stream()
+            .collect(Collectors.toMap(Area::getAreaCode, Function.identity()));
+        fillAreaName(emsDevice, areaMap);
+    }
+
     private void fillAreaName(EmsDevice emsDevice, Map<String, Area> areaMap) {
         String areaCode = emsDevice.getLocationRef();
         String areaNamePath = AreaUtils.getAreaNamePath(areaCode, areaMap);
@@ -172,11 +179,4 @@ public class EmsDeviceServiceImpl implements IEmsDeviceService {
         emsDevice.setLocationRefName(null != area ? area.getAreaName() : "未知");
         emsDevice.setAreaPath(areaNamePath);
     }
-
-    private void fillAreaName(EmsDevice emsDevice) {
-        List<Area> areas = areaService.selectArea(new Area());
-        Map<String, Area> areaMap = areas.stream()
-            .collect(Collectors.toMap(Area::getAreaCode, Function.identity()));
-        fillAreaName(emsDevice, areaMap);
-    }
 }

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

@@ -3,10 +3,12 @@ package com.ruoyi.ems.service.impl;
 import com.ruoyi.ems.domain.MeterDevice;
 import com.ruoyi.ems.enums.MeterObjType;
 import com.ruoyi.ems.mapper.MeterDeviceMapper;
+import com.ruoyi.ems.model.QueryDevice;
 import com.ruoyi.ems.service.IMeterDeviceService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.Collections;
 import java.util.List;
 
 /**
@@ -48,6 +50,11 @@ public class MeterDeviceServiceImpl implements IMeterDeviceService {
     }
 
     @Override
+    public List<MeterDevice> selectByAreaTree(QueryDevice queryDevice) {
+        return meterDeviceMapper.selectByAreaTree(queryDevice);
+    }
+
+    @Override
     public List<MeterDevice> selectMeterDeviceByObj(String areaCode, MeterObjType objType, String boundaryObj,
         Integer meterCls) {
         return meterDeviceMapper.selectMeterDeviceByObj(areaCode, objType.getType(), boundaryObj, meterCls);

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

@@ -31,31 +31,39 @@ import java.util.Set;
  * @since [产品/模块版本]
  */
 public abstract class AreaUtils {
-    /**
-     * 对象转换List<Area> -> List<TreeEntity>
-     *
-     * @param areas 区域树结构
-     * @return TreeEntity 树结构
-     */
+
     public static List<TreeEntity> convertAreaTree(List<?> areas) {
+        return convertAreaTree(areas, Integer.MAX_VALUE);
+    }
+
+    public static List<TreeEntity> convertAreaTree(List<?> areas, int maxLevel) {
+        return convertAreaTreeHelper(areas, 1, maxLevel);
+    }
+
+    private static List<TreeEntity> convertAreaTreeHelper(List<?> areas, int currentLevel, int maxLevel) {
         List<TreeEntity> retList = new ArrayList<>();
 
+        if (CollectionUtils.isEmpty(areas)) {
+            return retList;
+        }
+
         for (Object obj : areas) {
             Area area = (Area) obj;
             TreeEntity tree = new TreeEntity();
             tree.setId(area.getAreaCode());
             tree.setLabel(area.getAreaName());
 
-            if (CollectionUtils.isNotEmpty(area.getChildren())) {
-                tree.setChildren(convertAreaTree(area.getChildren()));
+            // 当当前层级小于最大层级时,递归处理子节点
+            if (currentLevel < maxLevel && CollectionUtils.isNotEmpty(area.getChildren())) {
+                tree.setChildren(convertAreaTreeHelper(area.getChildren(), currentLevel + 1, maxLevel));
             }
 
             retList.add(tree);
         }
-
         return retList;
     }
 
+
     /**
      * 过滤区域树
      * · 遍历树中的每个节点,并调用 filterNode 方法来检查每个节点是否应该被保留。

+ 27 - 7
ems/ems-core/src/main/resources/mapper/ems/MeterDeviceMapper.xml

@@ -9,7 +9,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="areaCode"    column="area_code"    />
         <result property="deviceCode"  column="device_code"    />
         <result property="deviceName"  column="device_name"    />
-        <result property="deviceLocation"  column="device_location"    />
+        <result property="location"    column="location"    />
+        <result property="locationRef"    column="location_ref"    />
         <result property="meterCls"    column="meter_cls"    />
         <result property="objTag"      column="obj_tag"    />
         <result property="colCycle"    column="col_cycle"    />
@@ -19,7 +20,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </resultMap>
 
     <sql id="selectMeterDeviceVo">
-        select id, area_code, device_code, device_name, device_location, meter_cls, obj_tag, col_cycle, col_mode, magnification, spec_desc from adm_meter_device
+        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">
@@ -30,10 +31,26 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <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="colCycle != null "> and col_cycle = #{colCycle}</if>
             <if test="colMode != null "> and col_mode = #{colMode}</if>
         </where>
     </select>
+
+    <select id="selectByAreaTree" parameterType="com.ruoyi.ems.model.QueryDevice" resultMap="meterDeviceResult">
+        <include refid="selectMeterDeviceVo"/>
+        <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>
+            <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"/>
@@ -47,7 +64,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 
     <select id="selectMeterDeviceByObj"  resultMap="meterDeviceResult">
         select
-            m.id, m.area_code, m.device_code, m.device_name, m.device_location, m.meter_cls, m.obj_tag, m.col_cycle, m.col_mode, m.magnification, m.spec_desc
+            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
         where m.area_code = #{areaCode}
           and m.meter_cls = #{meterCls}
@@ -64,7 +81,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="areaCode != null and areaCode != ''">area_code,</if>
             <if test="deviceCode != null and deviceCode != ''">device_code,</if>
             <if test="deviceName != null and deviceName != ''">device_name,</if>
-            <if test="deviceLocation != null and deviceLocation != ''">device_location,</if>
+            <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="colCycle != null">col_cycle,</if>
@@ -76,7 +94,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="areaCode != null and areaCode != ''">#{areaCode},</if>
             <if test="deviceCode != null and deviceCode != ''">#{deviceCode},</if>
             <if test="deviceName != null and deviceName != ''">#{deviceName},</if>
-            <if test="deviceLocation != null and deviceLocation != ''">#{deviceLocation},</if>
+            <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="colCycle != null">#{colCycle},</if>
@@ -92,7 +111,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="areaCode != null and areaCode != ''">area_code = #{areaCode},</if>
             <if test="deviceCode != null and deviceCode != ''">device_code = #{deviceCode},</if>
             <if test="deviceName != null and deviceName != ''">device_name = #{deviceName},</if>
-            <if test="deviceLocation != null and deviceLocation != ''">device_location = #{deviceLocation},</if>
+            <if test="locationRef != null and locationRef != ''">location_ref = #{locationRef},</if>
+            <if test="location != null and location != ''">location = #{location},</if>
             <if test="meterCls != null and meterCls != ''">meter_cls = #{meterCls},</if>
             <if test="objTag != null and objTag != ''">obj_tag = #{objTag},</if>
             <if test="colCycle != null">col_cycle = #{colCycle},</if>

+ 31 - 31
ems/sql/ems_init_data.sql

@@ -558,37 +558,37 @@ INSERT INTO `adm_ems_subsystem` (`system_code`, `system_name`, `short_name`, `ma
 
 -- 能源计量设备DEMO数据
 -- 电表
-INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `device_location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3001', 'J-D-B-101', '北区/综合楼B-101', '北区综合楼一楼设备间', 45, 1, 4, 1, 1, '智能表');
-INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `device_location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3001', 'J-D-B-102', '北区/综合楼B-102', '北区综合楼一楼设备间', 45, 1, 4, 1, 1, '智能表');
-INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `device_location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3001', 'J-D-B-103', '北区/综合楼B-103', '北区综合楼一楼设备间', 45, 1, 4, 1, 1, '智能表');
-INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `device_location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3001', 'J-D-B-104', '北区/综合楼B-104', '北区综合楼一楼设备间', 45, 1, 4, 1, 1, '智能表');
-INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `device_location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3001', 'J-D-B-105', '北区/综合楼B-105', '北区综合楼一楼设备间', 45, 1, 4, 1, 1, '智能表');
-INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `device_location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3001', 'J-D-B-106', '北区/综合楼B-106', '北区综合楼一楼设备间', 45, 1, 4, 1, 1, '智能表');
-INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `device_location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3001', 'J-D-B-107', '北区/综合楼B-107', '北区综合楼一楼设备间', 45, 1, 4, 1, 1, '智能表');
-INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `device_location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3001', 'J-D-B-108', '北区/综合楼B-108', '北区综合楼一楼设备间', 45, 1, 4, 1, 1, '智能表');
-INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `device_location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3001', 'J-D-B-109', '北区/综合楼B-109', '北区综合楼一楼设备间', 45, 1, 4, 1, 1, '智能表');
-INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `device_location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3001', 'J-D-B-110', '北区/综合楼B-110', '北区综合楼一楼设备间', 45, 1, 4, 1, 1, '智能表');
-INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `device_location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3001', 'J-D-B-Z101', '北区/综合楼内照明(Z101)', '北区综合楼一楼设备间', 45, 0, 4, 0, 1, '智能表');
-INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `device_location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3001', 'J-D-B-Z102', '北区/综合楼室外照明(Z102)', '北区综合楼2#箱', 45, 0, 4, 0, 1, '智能表');
-INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `device_location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3001', 'J-D-B-Z110', '北区/综合楼公共设施(Z110)', '北区综合楼1#箱', 45, 0, 4, 0, 1, '智能表');
-INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `device_location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3001', 'J-D-B-Z120', '北区/综合楼空调(Z120)', '北区综合楼1#箱', 45, 0, 4, 0, 50, '智能表');
-INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `device_location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3001', 'J-D-B-G001', '北区/广场照明', '北区广场1#配电柜', 45, 0, 4, 0, 1, '智能表');
-
-INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `device_location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3002', 'J-D-N-101', '南区/综合楼N-101', '南区综合楼一楼设备间', 45, 1, 4, 1, 1, '智能表');
-INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `device_location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3002', 'J-D-N-102', '南区/综合楼N-103', '南区综合楼一楼设备间', 45, 1, 4, 1, 1, '智能表');
-INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `device_location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3002', 'J-D-N-103', '南区/综合楼N-105', '南区综合楼一楼设备间', 45, 1, 4, 1, 1, '智能表');
-INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `device_location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3002', 'J-D-N-104', '南区/综合楼N-107', '南区综合楼一楼设备间', 45, 1, 4, 1, 1, '智能表');
-INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `device_location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3002', 'J-D-N-105', '南区/综合楼N-109', '南区综合楼一楼设备间', 45, 1, 4, 1, 1, '智能表');
-INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `device_location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3002', 'J-D-N-106', '南区/综合楼N-110', '南区综合楼一楼设备间', 45, 1, 4, 1, 1, '智能表');
-INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `device_location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3002', 'J-D-N-107', '南区/综合楼N-112', '南区综合楼一楼设备间', 45, 1, 4, 1, 1, '智能表');
-INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `device_location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3002', 'J-D-N-108', '南区/综合楼N-113', '南区综合楼一楼设备间', 45, 1, 4, 1, 1, '智能表');
-INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `device_location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3002', 'J-D-N-109', '南区/综合楼N-114', '南区综合楼一楼设备间', 45, 1, 4, 1, 1, '智能表');
-INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `device_location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3002', 'J-D-N-110', '南区/综合楼N-115', '南区综合楼一楼设备间', 45, 0, 4, 1, 1, '智能表');
-INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `device_location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3002', 'J-D-N-Z201', '南区/综合楼内照明(Z201)', '南区综合楼一楼设备间', 45, 0, 4, 0, 1, '智能表');
-INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `device_location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3002', 'J-D-N-Z202', '南区/综合楼室外照明(Z202)', '南区综合楼2#箱', 45, 0, 4, 0, 1, '智能表');
-INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `device_location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3002', 'J-D-N-Z210', '南区/综合楼公共设施(Z210)', '南区综合楼1#箱', 45, 0, 4, 0, 1, '智能表');
-INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `device_location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3002', 'J-D-N-Z220', '南区/综合楼空调(Z220)', '南区综合楼1#箱', 45, 0, 4, 0, 50, '智能表');
-INSERT INTO `adm_meter_device` (`area_code`, `device_code`, `device_name`, `device_location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3002', 'J-D-N-G001', '南区/广场照明', '南区广场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-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`, `device_location`, `meter_cls`, `obj_tag`, `col_cycle`, `col_mode`, `magnification`, `spec_desc`) VALUES ('321283124S3001', 'J-D-B-864142073640059', '智能断路器', '华设C3-开水间', 45, 0, 4, 0, 1, '智能断路器');

+ 2 - 1
ems/sql/ems_server.sql

@@ -511,7 +511,8 @@ create table adm_meter_device  (
   `area_code`       varchar(32)     default null                 comment '区域代码',
   `device_code`     varchar(32)     not null                     comment '设备代码',
   `device_name`     varchar(64)     default null                 comment '设备别名',
-  `device_location` varchar(128)    default null                 comment '设备别名',
+  `location_ref`    varchar(64)     default null                 comment '归属子区',
+  `location`        varchar(128)    default null                 comment '安装位置',
   `meter_cls`       int             not null                     comment '计量类别25-天然气 45-电 70-水',
   `obj_tag`         int             default null                 comment '对象标记',
   `col_cycle`       int             default null                 comment '采集周期',