Browse Source

产品树 添加 单机信息

wanggaokun 1 year ago
parent
commit
2a481e14e7

+ 13 - 0
PHM-admin/phm-manage/src/main/java/com/phm/manage/domain/Product.java

@@ -25,6 +25,11 @@ public class Product extends BaseEntity {
     @Excel(name = "父ID")
     private Long parentId;
 
+    /**
+     * 单机ID
+     */
+    private Long aircraftId;
+
     /**
      * 归属
      */
@@ -71,6 +76,14 @@ public class Product extends BaseEntity {
         return parentId;
     }
 
+    public Long getAircraftId() {
+        return aircraftId;
+    }
+
+    public void setAircraftId(Long aircraftId) {
+        this.aircraftId = aircraftId;
+    }
+
     public void setParentName(String parentName) {
         this.parentName = parentName;
     }

+ 30 - 7
PHM-admin/phm-manage/src/main/resources/mapper/manage/ProductMapper.xml

@@ -7,6 +7,7 @@
     <resultMap type="Product" id="ProductResult">
         <result property="id"    column="id"    />
         <result property="parentId"    column="parent_id"    />
+        <result property="aircraftId"    column="aircraft_id"    />
         <result property="parentName"    column="parent_name"    />
         <result property="ancestors"    column="ancestors"    />
         <result property="name"    column="name"    />
@@ -19,30 +20,50 @@
     </resultMap>
 
     <sql id="selectProductVo">
-        select id, parent_id, parent_name, ancestors, name, sns_id, is_delete, create_by, create_time, update_by, update_time from phm_product
+        select t.id,
+               t.parent_id,
+               t.aircraft_id,
+               (CASE
+                    when t.parent_id = 0 THEN
+                        t2.`name`
+                    ELSE p2.`name`
+                   END) parent_name,
+               t.ancestors,
+               t.name,
+               t.sns_id,
+               t.is_delete,
+               t.create_by,
+               t.create_time,
+               t.update_by,
+               t.update_time
+        FROM phm_product t
+                 LEFT JOIN phm_product p2
+                           ON t.parent_id = p2.id
+                 LEFT JOIN phm_aircraft t2 ON t.aircraft_id = t2.id
     </sql>
 
     <select id="selectProductList" parameterType="Product" resultMap="ProductResult">
         <include refid="selectProductVo"/>
         <where>
-            <if test="parentId != null "> and parent_id = #{parentId}</if>
-            <if test="parentName != null  and parentName != ''"> and parent_name like concat('%', #{parentName}, '%')</if>
-            <if test="ancestors != null  and ancestors != ''"> and ancestors = #{ancestors}</if>
+            <if test="parentId != null "> and t.parent_id = #{parentId}</if>
+            <if test="parentName != null  and parentName != ''"> and t.parent_name like concat('%', #{parentName}, '%')</if>
+            <if test="ancestors != null  and ancestors != ''"> and t.ancestors = #{ancestors}</if>
             <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
-            <if test="snsId != null  and snsId != ''"> and sns_id = #{snsId}</if>
-            <if test="isDelete != null "> and is_delete = #{isDelete}</if>
+            <if test="snsId != null  and snsId != ''"> and t.sns_id = #{snsId}</if>
+            <if test="isDelete != null "> and t.is_delete = #{isDelete}</if>
         </where>
     </select>
 
     <select id="selectProductById" parameterType="Long" resultMap="ProductResult">
         <include refid="selectProductVo"/>
-        where id = #{id}
+        where t.id = #{id}
     </select>
 
     <insert id="insertProduct" parameterType="Product" useGeneratedKeys="true" keyProperty="id">
         insert into phm_product
         <trim prefix="(" suffix=")" suffixOverrides=",">
             <if test="parentId != null">parent_id,</if>
+            <if test="aircraftId != null">aircraft_id,</if>
             <if test="parentName != null">parent_name,</if>
             <if test="ancestors != null">ancestors,</if>
             <if test="name != null">name,</if>
@@ -55,6 +76,7 @@
         </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="parentId != null">#{parentId},</if>
+            <if test="aircraftId != null">#{aircraftId},</if>
             <if test="parentName != null">#{parentName},</if>
             <if test="ancestors != null">#{ancestors},</if>
             <if test="name != null">#{name},</if>
@@ -71,6 +93,7 @@
         update phm_product
         <trim prefix="SET" suffixOverrides=",">
             <if test="parentId != null">parent_id = #{parentId},</if>
+            <if test="aircraftId != null">aircraft_id = #{aircraftId},</if>
             <if test="parentName != null">parent_name = #{parentName},</if>
             <if test="ancestors != null">ancestors = #{ancestors},</if>
             <if test="name != null">name = #{name},</if>