소스 검색

+ 大屏接口研发,《源》

chen.cheng 11 달 전
부모
커밋
2d68b03880

+ 11 - 1
ems-cloud/ems-modules/ems-server/src/main/java/com/ruoyi/ems/domain/EmsDevice.java

@@ -7,7 +7,7 @@ import com.ruoyi.common.core.web.domain.BaseEntity;
 
 /**
  * 能源设备对象 adm_ems_device
- * 
+ *
  * @author ruoyi
  * @date 2024-07-10
  */
@@ -37,6 +37,8 @@ public class EmsDevice extends BaseEntity
     @Excel(name = "设备状态")
     private Long deviceStatus;
 
+   private String  areaAncestors;
+
     /** 区域类型 */
     private String areaType;
 
@@ -176,6 +178,14 @@ public class EmsDevice extends BaseEntity
         this.areaPath = areaPath;
     }
 
+    public String getAreaAncestors() {
+        return areaAncestors;
+    }
+
+    public void setAreaAncestors(String areaAncestors) {
+        this.areaAncestors = areaAncestors;
+    }
+
     @Override
     public String toString() {
         return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)

+ 4 - 0
ems-cloud/ems-modules/ems-server/src/main/java/com/ruoyi/ems/mapper/EmsDeviceMapper.java

@@ -2,6 +2,8 @@ package com.ruoyi.ems.mapper;
 
 import java.util.List;
 
+import org.apache.ibatis.annotations.Param;
+
 import com.ruoyi.ems.domain.EmsDevice;
 import com.ruoyi.ems.domain.vo.QueryDevice;
 
@@ -73,4 +75,6 @@ public interface EmsDeviceMapper {
      * @return 结果
      */
     int deleteEmsDeviceByIds(Long[] ids);
+
+    String selectDevicePath(@Param("areaType") String areaType, @Param("refArea") String areaCode);
 }

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

@@ -227,6 +227,8 @@ public class EmsDeviceServiceImpl implements IEmsDeviceService {
     @Override
     public int insertEmsDevice(EmsDevice emsDevice) {
         emsDevice.setCreateTime(DateUtils.getNowDate());
+        String codePath = emsDeviceMapper.selectDevicePath(emsDevice.getAreaType(), emsDevice.getRefArea());
+        emsDevice.setAreaAncestors(codePath);
         return emsDeviceMapper.insertEmsDevice(emsDevice);
     }
 
@@ -239,6 +241,8 @@ public class EmsDeviceServiceImpl implements IEmsDeviceService {
     @Override
     public int updateEmsDevice(EmsDevice emsDevice) {
         emsDevice.setUpdateTime(DateUtils.getNowDate());
+        String codePath = emsDeviceMapper.selectDevicePath(emsDevice.getAreaType(), emsDevice.getRefArea());
+        emsDevice.setAreaAncestors(codePath);
         return emsDeviceMapper.updateEmsDevice(emsDevice);
     }
 

+ 42 - 6
ems-cloud/ems-modules/ems-server/src/main/resources/mapper/ems/EmsDeviceMapper.xml

@@ -3,7 +3,7 @@
 PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.ruoyi.ems.mapper.EmsDeviceMapper">
-    
+
     <resultMap type="com.ruoyi.ems.domain.EmsDevice" id="EmsDeviceResult">
         <result property="id"    column="id"    />
         <result property="deviceCode"        column="device_code"    />
@@ -32,7 +32,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 
     <select id="selectEmsDeviceList" parameterType="com.ruoyi.ems.domain.EmsDevice" resultMap="EmsDeviceResult">
         <include refid="selectEmsDeviceVo"/>
-        <where>  
+        <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>
@@ -83,7 +83,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         </where>
         ORDER BY d.`area_type`, d.`ref_area`
     </select>
-    
+
     <select id="selectEmsDeviceById" parameterType="Long" resultMap="EmsDeviceResult">
         <include refid="selectEmsDeviceVo"/>
         where d.`id` = #{id}
@@ -93,7 +93,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <include refid="selectEmsDeviceVo"/>
         where d.`device_code` = #{code}
     </select>
-        
+
     <insert id="insertEmsDevice" parameterType="com.ruoyi.ems.domain.EmsDevice" useGeneratedKeys="true" keyProperty="id">
         insert into adm_ems_device
         <trim prefix="(" suffix=")" suffixOverrides=",">
@@ -107,6 +107,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="subsystemCode != null">subsystem_code,</if>
             <if test="createTime != null">create_time,</if>
             <if test="updateTime != null">update_time,</if>
+            <if test="areaAncestors !=null">area_ancestors,</if>
          </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="deviceCode != null and deviceCode != ''">#{deviceCode},</if>
@@ -119,6 +120,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="subsystemCode != null">#{subsystemCode},</if>
             <if test="createTime != null">#{createTime},</if>
             <if test="updateTime != null">#{updateTime},</if>
+            <if test="areaAncestors !=null">#{areaAncestors},</if>
          </trim>
     </insert>
 
@@ -135,6 +137,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="subsystemCode != null">subsystem_code = #{subsystemCode},</if>
             <if test="createTime != null">create_time = #{createTime},</if>
             <if test="updateTime != null">update_time = #{updateTime},</if>
+            <if test="areaAncestors !=null">area_ancestors = #{areaAncestors},</if>
         </trim>
         where id = #{id}
     </update>
@@ -144,9 +147,42 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </delete>
 
     <delete id="deleteEmsDeviceByIds" parameterType="String">
-        delete from adm_ems_device where id in 
+        delete from adm_ems_device where id in
         <foreach item="id" collection="array" open="(" separator="," close=")">
             #{id}
         </foreach>
     </delete>
-</mapper>
+
+    <select id="selectDevicePath" resultType="String">
+        SELECT
+        <if test="areaType == 'Area'">
+            area.area_code path
+        </if>
+        <if test="areaType == 'Building'">
+            CONCAT( area.area_code, ',', building.bldg_code) path
+        </if>
+        <if test="areaType == 'Zoning'">
+            CONCAT( area.area_code, ',', building.bldg_code, ',', zone.zoning_code ) path
+        </if>
+        FROM
+        adm_service_area area
+        <if test="areaType == 'Building' or areaType == 'Zoning'">
+            INNER JOIN adm_area_building building ON area.area_code = building.area_code
+        </if>
+        <if test="areaType == 'Zoning'">
+            INNER JOIN adm_area_building_zoning zone ON building.bldg_code = zone.bldg_code
+        </if>
+        <where>
+            <if test="areaType == 'Area'">
+                area.area_code = #{refArea}
+            </if>
+            <if test="areaType == 'Building'">
+                building.bldg_code = #{refArea}
+            </if>
+            <if test="areaType == 'Zoning'">
+                zone.zoning_code = #{refArea}
+            </if>
+        </where>
+        limit 1
+    </select>
+</mapper>