From f34dc97df6dc9f4480e7903016f104388ec1a7ab Mon Sep 17 00:00:00 2001
From: wuzeyu <1223318623@qq.com>
Date: 星期四, 23 五月 2024 11:34:47 +0800
Subject: [PATCH] 田间灌溉项目管理 轮灌组 修改查一个、分页查、轮灌组绑定灌溉单元变物理删除

---
 pipIrr-platform/pipIrr-global/src/main/resources/mapper/PrIntakeMapper.xml |  123 +++++++++++++++++++++++++++++++---------
 1 files changed, 95 insertions(+), 28 deletions(-)

diff --git a/pipIrr-platform/pipIrr-global/src/main/resources/mapper/PrIntakeMapper.xml b/pipIrr-platform/pipIrr-global/src/main/resources/mapper/PrIntakeMapper.xml
index 485f1b5..5a25cea 100644
--- a/pipIrr-platform/pipIrr-global/src/main/resources/mapper/PrIntakeMapper.xml
+++ b/pipIrr-platform/pipIrr-global/src/main/resources/mapper/PrIntakeMapper.xml
@@ -214,12 +214,12 @@
   <select id="getRecordCount" parameterType="java.util.Map" resultType="java.lang.Long">
     SELECT COUNT(*) AS recordCount
     FROM pr_intake ge
-    INNER JOIN ba_divide divi ON ge.divideId = divi.id
+    INNER JOIN pr_divide divi ON ge.divideId = divi.id
     INNER JOIN ba_block blo ON divi.blockId = blo.id
-    INNER JOIN ba_district country ON ge.countyId = country.id
-    INNER JOIN ba_district town ON ge.townId = town.id
-    INNER JOIN ba_district village ON ge.villageId = village.id
-    , (SELECT @i:=0) AS itable
+    LEFT JOIN ba_district country ON ge.countyId = country.id
+    LEFT JOIN ba_district town ON ge.townId = town.id
+    LEFT JOIN ba_district village ON ge.villageId = village.id
+    LEFT JOIN pr_controller cont ON ge.id = cont.intakeId
     <where>
       ge.deleted = 0
       AND divi.deleted = 0
@@ -228,31 +228,57 @@
         AND ge.name LIKE CONCAT('%', #{intakeName}, '%')
       </if>
 
-      <if test="divideName != null and divideName != ''">
-        AND divi.name LIKE CONCAT('%', #{divideName}, '%')
+      <if test = "divideId != null and divideId !=''">
+        AND divi.id = #{divideId}
       </if>
 
-      <if test="blockName != null and blockName != ''">
-        AND blo.name = #{blockName}
+      <if test = "blockId != null and blockId !=''">
+        AND blo.id = #{blockId}
+      </if>
+
+      <if test="isBinded == 0">
+        AND ge.id NOT IN(SELECT intakeId FROM pr_controller where deleted = 0)
+      </if>
+      <if test="isBinded == 1">
+        AND ge.id IN(SELECT intakeId FROM pr_controller where deleted = 0)
+      </if>
+      <if test="isBinded == null">
+
+      </if>
+      <if test="address != null and address != ''">
+        AND CONCAT(country.`name`, town.`name`, village.`name`) LIKE CONCAT('%', #{address}, '%')
       </if>
     </where>
   </select>
 
   <!--鏍规嵁鎸囧畾鏉′欢鑾峰彇鍙栨按鍙h褰�-->
   <select id="getIntakes" resultType="com.dy.pipIrrGlobal.voPr.VoIntake">
-    SELECT (@i:=@i+1)                                          AS id,
+    SELECT
+    CAST(ge.id AS char)                                 AS intakeId,
     ge.`name`                                           AS intakeName,
+    CAST(divi.id AS char)                               AS divideId,
     divi.`name`                                         AS divideName,
+    CAST(blo.id AS char)                                AS blockId,
     blo.`name`                                          AS blockName,
+    CAST(cont.id AS char)                               AS controllerId,
+    cont.rtuAddr                                        AS rtuAddr,
+    ge.lng,
+    ge.lat,
+    ge.remarks,
+    ge.operator,
     ge.operateDt                                        As operateDt,
+    (CASE
+    WHEN ge.id NOT IN(SELECT intakeId FROM pr_controller where deleted = 0)  THEN "鏈粦瀹�"
+    WHEN ge.id IN(SELECT intakeId FROM pr_controller  where deleted = 0)  THEN "宸茬粦瀹�"
+    END) AS isBind,
     CONCAT(country.`name`, town.`name`, village.`name`) AS address
     FROM pr_intake ge
     INNER JOIN pr_divide divi ON ge.divideId = divi.id
     INNER JOIN ba_block blo ON divi.blockId = blo.id
-    INNER JOIN ba_district country ON ge.countyId = country.id
-    INNER JOIN ba_district town ON ge.townId = town.id
-    INNER JOIN ba_district village ON ge.villageId = village.id
-    , (SELECT @i:=0) AS itable
+    LEFT JOIN ba_district country ON ge.countyId = country.id
+    LEFT JOIN ba_district town ON ge.townId = town.id
+    LEFT JOIN ba_district village ON ge.villageId = village.id
+    LEFT JOIN pr_controller cont ON ge.id = cont.intakeId
     <where>
       ge.deleted = 0
       AND divi.deleted = 0
@@ -260,29 +286,35 @@
       <if test="intakeName != null and intakeName != ''">
         AND ge.name LIKE CONCAT('%', #{intakeName}, '%')
       </if>
-      <if test="divideName != null and divideName != ''">
-        AND divi.name LIKE CONCAT('%', #{divideName}, '%')
+
+      <if test = "divideId != null and divideId !=''">
+        AND divi.id = #{divideId}
       </if>
 
-      <if test="blockName != null and blockName != ''">
-        AND blo.name = #{blockName}
+      <if test = "blockId != null and blockId !=''">
+        AND blo.id = #{blockId}
+      </if>
+
+      <if test="isBinded == 0">
+        AND ge.id NOT IN(SELECT intakeId FROM pr_controller where deleted = 0)
+      </if>
+      <if test="isBinded == 1">
+        AND ge.id IN(SELECT intakeId FROM pr_controller where deleted = 0)
+      </if>
+      <if test="isBinded == null">
+
+      </if>
+      <if test="address != null and address != ''">
+        AND CONCAT(country.`name`, town.`name`, village.`name`) LIKE CONCAT('%', #{address}, '%')
       </if>
     </where>
     ORDER BY ge.operateDt DESC
     <if test="pageCurr != null and pageSize != null">
-      LIMIT ${pageCurr}, ${pageSize}
+      LIMIT ${(pageCurr-1)*pageSize}, ${pageSize}
     </if>
   </select>
 
-  <select id="getSupperByvillageId" parameterType="_long" resultType="java.lang.Long">
-    select dis_tow.*
-    from ba_district dis_vil
-    inner join
-    ba_district dis_tow
-    on dis_vil.supperId = dis_tow.id
-    where dis_vil.id = #{vaId,jdbcType=BIGINT}
-  </select>
-
+  <!--鏍规嵁涓嬬骇鑾峰彇涓婁竴绾у湴鍧�-->
   <select id="getSupperByVillageId" parameterType="_long" resultType="java.lang.Long">
     select dis_tow.*
     from ba_district dis_vil
@@ -291,4 +323,39 @@
     on dis_vil.supperId = dis_tow.id
     where dis_vil.id = #{vaId,jdbcType=BIGINT}
   </select>
+
+  <!--鏍规嵁鍙栨按鍙g紪鍙疯幏鍙栨湭鍒犻櫎鐨勫彇姘村彛鏁伴噺-->
+  <select id="getRecordCountOfIntake" resultType="java.lang.Integer">
+    SELECT COUNT(*) AS recordCount FROM pr_intake WHERE deleted = 0 AND id = ${intakeId}
+  </select>
+
+  <!--鏍规嵁鏉慖D鑾峰彇鍏ㄩ儴鍦板潃-->
+  <select id="getAddressByVillageId" parameterType="_long" resultType="java.lang.String">
+    select
+    CONCAT(dis_province.`name`, dis_city.`name`, dis_county.`name`, dis_town.`name`, dis_village.`name`) AS address
+    from ba_district dis_village
+    inner join ba_district dis_town    on dis_village.supperId = dis_town.id
+    inner join ba_district dis_county    on dis_town.supperId = dis_county.id
+    inner join ba_district dis_city    on dis_county.supperId = dis_city.id
+    inner join ba_district dis_province    on dis_city.supperId = dis_province.id
+    where dis_village.id = #{villageId,jdbcType=BIGINT}
+  </select>
+
+  <!--鏍规嵁鍖哄煙Id鑾峰彇鍖哄煙绛夌骇-->
+  <select id="getLevelByRegionId" parameterType="_long" resultType="java.lang.Integer">
+    select
+    region.level
+    from ba_district region
+    where region.id = #{regionId,jdbcType=BIGINT}
+  </select>
+
+  <!--鑾峰彇鏈粦鎺у埗鍣ㄧ殑鍙栨按鍙e垪琛�-->
+  <select id="getNoBindingIntakes" resultType="java.util.HashMap">
+    SELECT
+        CAST(inta.id AS char)AS intakeId,
+        name AS intakeName
+    FROM pr_intake inta
+    WHERE id NOT IN(SELECT intakeId FROM pr_controller) AND deleted = 0
+  </select>
+
 </mapper>
\ No newline at end of file

--
Gitblit v1.8.0