lv.wenbin před 11 měsíci
rodič
revize
a8637076a4

+ 57 - 3
ems-cloud/ems-modules/ems-server/src/main/java/com/ruoyi/ems/controller/DeviceController.java

@@ -7,8 +7,16 @@ 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.AreaBuilding;
+import com.ruoyi.ems.domain.AreaBuildingZoning;
 import com.ruoyi.ems.domain.EmsDevice;
+import com.ruoyi.ems.domain.common.AreaTier;
+import com.ruoyi.ems.domain.vo.QueryDevice;
+import com.ruoyi.ems.service.IAreaBuildingService;
+import com.ruoyi.ems.service.IAreaBuildingZoningService;
 import com.ruoyi.ems.service.IEmsDeviceService;
+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;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -20,7 +28,9 @@ 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;
+import java.util.stream.Collectors;
 
 /**
  * 能源设备Controller
@@ -35,6 +45,12 @@ public class DeviceController extends BaseController
     @Autowired
     private IEmsDeviceService deviceService;
 
+    @Autowired
+    private IAreaBuildingService buildingService;
+
+    @Autowired
+    private IAreaBuildingZoningService zoningService;
+
     /**
      * 查询能源设备列表
      */
@@ -50,12 +66,50 @@ public class DeviceController extends BaseController
     /**
      * 查询能源设备列表
      */
-    @RequiresPermissions("basecfg:device:list")
+    //@RequiresPermissions("basecfg:device:list")
     @GetMapping("/listByAreaTree")
-    public TableDataInfo listByAreaTree(EmsDevice emsDevice)
+    public TableDataInfo listByAreaTree(QueryDevice queryDevice)
     {
+        // 层级为区域,需要查询下级建筑,以及建筑下级区块
+        if (StringUtils.equals(queryDevice.getAreaType(), AreaTier.Area.name()) && StringUtils.isNotBlank(
+            queryDevice.getRefArea())) {
+            AreaBuilding param = new AreaBuilding();
+            param.setAreaCode(queryDevice.getRefArea());
+            List<AreaBuilding> buildings = buildingService.selectAreaBuildingList(param);
+            List<String> buildingCodes = buildings.stream().map(AreaBuilding::getBldgCode).collect(Collectors.toList());
+
+            if (CollectionUtils.isNotEmpty(buildings)) {
+                queryDevice.setBuildingCodes(buildingCodes);
+                List<String> zoningCodes = new ArrayList<>();
+
+                for (String buildCode : buildingCodes) {
+                    AreaBuildingZoning zParam = new AreaBuildingZoning();
+                    zParam.setBldgCode(buildCode);
+                    List<AreaBuildingZoning> list = zoningService.selectAreaBuildingZoningList(zParam);
+                    zoningCodes.addAll(
+                        list.stream().map(AreaBuildingZoning::getZoningCode).collect(Collectors.toList()));
+                }
+
+                if (CollectionUtils.isNotEmpty(zoningCodes)) {
+                    queryDevice.setZoningCodes(zoningCodes);
+                }
+            }
+        }
+        else if (StringUtils.equals(queryDevice.getAreaType(), AreaTier.Building.name()) && StringUtils.isNotBlank(
+            queryDevice.getRefArea())) {
+            AreaBuildingZoning zParam = new AreaBuildingZoning();
+            zParam.setBldgCode(queryDevice.getRefArea());
+            List<AreaBuildingZoning> list = zoningService.selectAreaBuildingZoningList(zParam);
+            List<String> zoningCodes = list.stream().map(AreaBuildingZoning::getZoningCode)
+                .collect(Collectors.toList());
+
+            if (CollectionUtils.isNotEmpty(zoningCodes)) {
+                queryDevice.setZoningCodes(zoningCodes);
+            }
+        }
+
         startPage();
-        List<EmsDevice> list = deviceService.selectEmsDeviceList(emsDevice);
+        List<EmsDevice> list = deviceService.selectByAreaTree(queryDevice);
         return getDataTable(list);
     }
 

+ 109 - 0
ems-cloud/ems-modules/ems-server/src/main/java/com/ruoyi/ems/domain/vo/QueryDevice.java

@@ -0,0 +1,109 @@
+/*
+ * 文 件 名:  QueryDevice
+ * 版    权:  浩鲸云计算科技股份有限公司
+ * 描    述:  <描述>
+ * 修 改 人:  lvwenbin
+ * 修改时间:  2024/8/6
+ * 跟踪单号:  <跟踪单号>
+ * 修改单号:  <修改单号>
+ * 修改内容:  <修改内容>
+ */
+package com.ruoyi.ems.domain.vo;
+
+import java.util.List;
+
+/**
+ * 查询设备
+ * <功能详细描述>
+ *
+ * @author lvwenbin
+ * @version [版本号, 2024/8/6]
+ * @see [相关类/方法]
+ * @since [产品/模块版本]
+ */
+public class QueryDevice {
+    /** 设备代码 */
+    private String deviceCode;
+
+    /** 设备名称 */
+    private String deviceName;
+
+    /** 设备类型 */
+    private Long deviceType;
+
+    private String refFacs;
+
+    /** 区域类型 */
+    private String areaType;
+
+    /** 区域代码 */
+    private String refArea;
+
+    private List<String> buildingCodes;
+
+    private List<String> zoningCodes;
+
+    public String getDeviceCode() {
+        return deviceCode;
+    }
+
+    public void setDeviceCode(String deviceCode) {
+        this.deviceCode = deviceCode;
+    }
+
+    public String getDeviceName() {
+        return deviceName;
+    }
+
+    public void setDeviceName(String deviceName) {
+        this.deviceName = deviceName;
+    }
+
+    public Long getDeviceType() {
+        return deviceType;
+    }
+
+    public void setDeviceType(Long deviceType) {
+        this.deviceType = deviceType;
+    }
+
+    public String getRefFacs() {
+        return refFacs;
+    }
+
+    public void setRefFacs(String refFacs) {
+        this.refFacs = refFacs;
+    }
+
+    public String getAreaType() {
+        return areaType;
+    }
+
+    public void setAreaType(String areaType) {
+        this.areaType = areaType;
+    }
+
+    public String getRefArea() {
+        return refArea;
+    }
+
+    public void setRefArea(String refArea) {
+        this.refArea = refArea;
+    }
+
+    public List<String> getBuildingCodes() {
+        return buildingCodes;
+    }
+
+    public void setBuildingCodes(List<String> buildingCodes) {
+        this.buildingCodes = buildingCodes;
+    }
+
+    public List<String> getZoningCodes() {
+        return zoningCodes;
+    }
+
+    public void setZoningCodes(List<String> zoningCodes) {
+        this.zoningCodes = zoningCodes;
+    }
+}

+ 22 - 14
ems-cloud/ems-modules/ems-server/src/main/java/com/ruoyi/ems/mapper/EmsDeviceMapper.java

@@ -1,19 +1,20 @@
 package com.ruoyi.ems.mapper;
 
 import java.util.List;
+
 import com.ruoyi.ems.domain.EmsDevice;
+import com.ruoyi.ems.domain.vo.QueryDevice;
 
 /**
  * 能源设备Mapper接口
- * 
+ *
  * @author ruoyi
  * @date 2024-07-10
  */
-public interface EmsDeviceMapper
-{
+public interface EmsDeviceMapper {
     /**
      * 查询能源设备
-     * 
+     *
      * @param id 能源设备主键
      * @return 能源设备
      */
@@ -21,41 +22,48 @@ public interface EmsDeviceMapper
 
     /**
      * 查询能源设备列表
-     * 
+     *
      * @param emsDevice 能源设备
      * @return 能源设备集合
      */
-     List<EmsDevice> selectEmsDeviceList(EmsDevice emsDevice);
+    List<EmsDevice> selectEmsDeviceList(EmsDevice emsDevice);
+
+    /**
+     * 根据区域树递归查询设备
+     * @param queryDevice 条件
+     * @return 设备列表
+     */
+    List<EmsDevice> selectByAreaTree(QueryDevice queryDevice);
 
     /**
      * 新增能源设备
-     * 
+     *
      * @param emsDevice 能源设备
      * @return 结果
      */
-     int insertEmsDevice(EmsDevice emsDevice);
+    int insertEmsDevice(EmsDevice emsDevice);
 
     /**
      * 修改能源设备
-     * 
+     *
      * @param emsDevice 能源设备
      * @return 结果
      */
-     int updateEmsDevice(EmsDevice emsDevice);
+    int updateEmsDevice(EmsDevice emsDevice);
 
     /**
      * 删除能源设备
-     * 
+     *
      * @param id 能源设备主键
      * @return 结果
      */
-     int deleteEmsDeviceById(Long id);
+    int deleteEmsDeviceById(Long id);
 
     /**
      * 批量删除能源设备
-     * 
+     *
      * @param ids 需要删除的数据主键集合
      * @return 结果
      */
-     int deleteEmsDeviceByIds(Long[] ids);
+    int deleteEmsDeviceByIds(Long[] ids);
 }

+ 10 - 1
ems-cloud/ems-modules/ems-server/src/main/java/com/ruoyi/ems/service/IEmsDeviceService.java

@@ -3,6 +3,7 @@ package com.ruoyi.ems.service;
 import java.util.List;
 
 import com.ruoyi.ems.domain.EmsDevice;
+import com.ruoyi.ems.domain.vo.QueryDevice;
 
 /**
  * 能源设备Service接口
@@ -22,10 +23,18 @@ public interface IEmsDeviceService {
     /**
      * 查询能源设备列表
      *
+     * @param queryDevice 能源设备
+     * @return 能源设备集合
+     */
+    List<EmsDevice> selectEmsDeviceList(EmsDevice queryDevice);
+
+    /**
+     * 查询能源设备列表
+     *
      * @param emsDevice 能源设备
      * @return 能源设备集合
      */
-    List<EmsDevice> selectEmsDeviceList(EmsDevice emsDevice);
+    List<EmsDevice> selectByAreaTree(QueryDevice emsDevice);
 
     /**
      * 新增能源设备

+ 22 - 2
ems-cloud/ems-modules/ems-server/src/main/java/com/ruoyi/ems/service/impl/EmsDeviceServiceImpl.java

@@ -1,13 +1,12 @@
 package com.ruoyi.ems.service.impl;
 
-import java.util.List;
-
 import com.ruoyi.common.core.utils.DateUtils;
 import com.ruoyi.ems.domain.Area;
 import com.ruoyi.ems.domain.AreaBuilding;
 import com.ruoyi.ems.domain.AreaBuildingZoning;
 import com.ruoyi.ems.domain.EmsDevice;
 import com.ruoyi.ems.domain.common.AreaTier;
+import com.ruoyi.ems.domain.vo.QueryDevice;
 import com.ruoyi.ems.mapper.EmsDeviceMapper;
 import com.ruoyi.ems.service.IAreaBuildingService;
 import com.ruoyi.ems.service.IAreaBuildingZoningService;
@@ -18,6 +17,8 @@ import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+
 /**
  * 能源设备Service业务层处理
  *
@@ -75,6 +76,25 @@ public class EmsDeviceServiceImpl implements IEmsDeviceService {
     }
 
     /**
+     * 查询能源设备列表
+     *
+     * @param queryDevice 能源设备
+     * @return 能源设备
+     */
+    @Override
+    public List<EmsDevice> selectByAreaTree(QueryDevice queryDevice) {
+        List<EmsDevice> list = emsDeviceMapper.selectByAreaTree(queryDevice);
+
+        if (CollectionUtils.isNotEmpty(list)) {
+            for (EmsDevice device : list) {
+                fillAreaName(device);
+            }
+        }
+
+        return list;
+    }
+
+    /**
      * 新增能源设备
      *
      * @param emsDevice 能源设备

+ 37 - 0
ems-cloud/ems-modules/ems-server/src/main/resources/mapper/ems/EmsDeviceMapper.xml

@@ -39,6 +39,43 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="refFacs != null  and refFacs != ''"> and d.`ref_facs` = #{refFacs}</if>
         </where>
     </select>
+
+    <select id="selectByAreaTree" parameterType="com.ruoyi.ems.domain.vo.QueryDevice" resultMap="EmsDeviceResult">
+        <include refid="selectEmsDeviceVo"/>
+        <where>
+            <if test="deviceCode != null  and deviceCode != ''"> and d.`device_code` = #{deviceCode}</if>
+            <if test="deviceName != null  and deviceName != ''"> and d.`device_name` like concat('%', #{deviceName}, '%')</if>
+            <if test="deviceType != null "> and d.`device_type` = #{deviceType}</if>
+            <if test="refFacs != null  and refFacs != ''"> and d.`ref_facs` = #{refFacs}</if>
+            <if test="areaType == 'Area' and refArea != null and refArea != ''">
+                and ((d.`area_type` = 'Area' and d.`ref_area` = #{refArea})
+                <if test="buildingCodes != null">
+                   or (d.`area_type` = 'Building' and d.`ref_area` in
+                    <foreach item="buildingCode" collection="buildingCodes" open="(" separator="," close=")">
+                        #{buildingCode}
+                    </foreach>)
+                    <if test="zoningCodes != null">
+                        or (d.`area_type` = 'Zoning' and d.`ref_area` in
+                        <foreach item="zoningCode" collection="zoningCodes" open="(" separator="," close=")">
+                            #{zoningCode}
+                        </foreach>)
+                    </if>
+                </if>)
+            </if>
+            <if test="areaType == 'Building' and refArea != null and refArea != ''">
+                and ((d.`area_type` = 'Building' and d.`ref_area` = #{refArea})
+                <if test="zoningCodes != null">
+                   or (d.`area_type` = 'Zoning' and d.`ref_area` in
+                    <foreach item="zoningCode" collection="zoningCodes" open="(" separator="," close=")">
+                        #{zoningCode}
+                    </foreach>)
+                </if>)
+            </if>
+            <if test="areaType == 'Zoning' and refArea != null and refArea != ''">
+                and d.`area_type` = 'Zoning' and d.`ref_area` = #{refArea}
+            </if>
+        </where>
+    </select>
     
     <select id="selectEmsDeviceById" parameterType="Long" resultMap="EmsDeviceResult">
         <include refid="selectEmsDeviceVo"/>

+ 4 - 2
ems-cloud/sql/ems_server.sql

@@ -275,9 +275,11 @@ create table dim_devc_type (
 INSERT INTO `dim_devc_type` (`type_code`, `type_name`) VALUES (0, '未分类');
 INSERT INTO `dim_devc_type` (`type_code`, `type_name`) VALUES (1, '照明设备');
 INSERT INTO `dim_devc_type` (`type_code`, `type_name`) VALUES (2, '暖通设备');
-INSERT INTO `dim_devc_type` (`type_code`, `type_name`) VALUES (3, '运输设备');
-INSERT INTO `dim_devc_type` (`type_code`, `type_name`) VALUES (4, '服务设备');
+INSERT INTO `dim_devc_type` (`type_code`, `type_name`) VALUES (3, '电气设备');
+INSERT INTO `dim_devc_type` (`type_code`, `type_name`) VALUES (4, '安防设备');
 INSERT INTO `dim_devc_type` (`type_code`, `type_name`) VALUES (5, '信息设备');
+INSERT INTO `dim_devc_type` (`type_code`, `type_name`) VALUES (6, '服务设备');
+INSERT INTO `dim_devc_type` (`type_code`, `type_name`) VALUES (7, '运输设备');
 
 -- ----------------------------
 -- 电价计量分类