Administrator
2024-07-13 fbbd05825360b086821660269c1f7baf12d66db2
pipIrr-platform/pipIrr-global/src/main/resources/mapper/PrIntakeMapper.xml
@@ -216,9 +216,10 @@
    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
    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
@@ -227,12 +228,12 @@
        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">
@@ -252,10 +253,19 @@
  <!--根据指定条件获取取水口记录-->
  <select id="getIntakes" resultType="com.dy.pipIrrGlobal.voPr.VoIntake">
    SELECT CAST(ge.id AS char)                             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 "未绑定"
@@ -265,9 +275,10 @@
    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
    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
@@ -276,12 +287,12 @@
        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">
@@ -299,7 +310,7 @@
    </where>
    ORDER BY ge.operateDt DESC
    <if test="pageCurr != null and pageSize != null">
      LIMIT ${pageCurr}, ${pageSize}
      LIMIT ${(pageCurr-1)*pageSize}, ${pageSize}
    </if>
  </select>
@@ -347,4 +358,126 @@
    WHERE id NOT IN(SELECT intakeId FROM pr_controller) AND deleted = 0
  </select>
  <!--获取取水口数量(在线和不在先) 废弃-->
  <select id="getOnLineIntakesCount" resultType="java.lang.Long">
    SELECT
        COUNT(*) AS recordCount
    FROM pr_controller con
        INNER JOIN pr_intake inta ON con.intakeId = inta.id
        left JOIN JSON_TABLE(
        <!--'[{"rtuAddr":"37142501020100215","isOnLine":true},{"rtuAddr":"4000004","isOnLine":true},{"rtuAddr":"dy20240325","isOnLine":false}]',-->
        #{onLineMap},
        '$[*]' COLUMNS(
            rtuAddr VARCHAR(20) PATH '$.rtuAddr',
            isOnLine BOOLEAN PATH '$.isOnLine'
        )
    ) rtus ON con.rtuAddr = rtus.rtuAddr
    <where>
      <if test="isOnLine != null">
        rtus.isOnLine = #{isOnLine}
      </if>
      <if test="intakeNum != null and intakeNum != ''">
        AND inta.name LIKE CONCAT('%', #{intakeNum}, '%')
      </if>
    </where>
  </select>
  <!--获取取水口列表(在线和不在先) 废弃-->
  <select id="getOnLineIntakes" resultType="com.dy.pipIrrGlobal.voPr.VoOnLineIntake">
    SELECT
      con.intakeId,
      con.rtuAddr,
      inta.name AS intakeNum,
      rtus.isOnLine
    FROM pr_controller con
        INNER JOIN pr_intake inta ON con.intakeId = inta.id
        left JOIN JSON_TABLE(
            <!--'[{"rtuAddr":"37142501020100215","isOnLine":true},{"rtuAddr":"4000004","isOnLine":true},{"rtuAddr":"dy20240325","isOnLine":false}]',-->
            #{onLineMap},
            '$[*]' COLUMNS(
                rtuAddr VARCHAR(20) PATH '$.rtuAddr',
              isOnLine BOOLEAN PATH '$.isOnLine'
           )
        ) rtus ON con.rtuAddr = rtus.rtuAddr
    <where>
      <if test="isOnLine != null">
        rtus.isOnLine = #{isOnLine}
      </if>
      <if test="intakeNum != null and intakeNum != ''">
        AND inta.name = #{intakeNum}
      </if>
    </where>
    order by con.id ASC
    <if test="pageCurr != null and pageSize != null">
      LIMIT ${(pageCurr-1)*pageSize}, ${pageSize}
    </if>
  </select>
  <!--根据取水口编号获取取水口对象-->
  <select id="getIntakeByName" resultType="com.dy.pipIrrGlobal.voPr.VoOnLineIntake">
    SELECT
      con.intakeId,
      con.rtuAddr,
      inta.name AS intakeNum,
      rtus.isOnLine
    FROM pr_controller con
      INNER JOIN pr_intake inta ON con.intakeId = inta.id
      left JOIN JSON_TABLE(
        #{onLineMap},
        '$[*]' COLUMNS(
        rtuAddr VARCHAR(20) PATH '$.rtuAddr',
        isOnLine BOOLEAN PATH '$.isOnLine'
        )
      ) rtus ON con.rtuAddr = rtus.rtuAddr
    <where>
      <if test="intakeNum != null and intakeNum != ''">
        AND LOWER(inta.name) = #{intakeNum}
      </if>
    </where>
    LIMIT 0,1
  </select>
  <!--根据操作员获取常用取水口-->
  <select id="getUsedIntakes" resultType="com.dy.pipIrrGlobal.voPr.VoOnLineIntake">
    SELECT
      DISTINCT con.intakeId,
               con.rtuAddr,
               inta.name AS intakeNum,
               rtus.isOnLine
    FROM pr_controller con
           INNER JOIN pr_intake inta ON con.intakeId = inta.id
           INNER JOIN rm_command_history com ON con.rtuAddr = com.rtu_addr
           INNER JOIN JSON_TABLE(
            <!--'[{"rtuAddr":"37142501020100215","isOnLine":true},{"rtuAddr":"4000004","isOnLine":true},{"rtuAddr":"dy20240325","isOnLine":false}]',-->
            #{onLineMap},
            '$[*]' COLUMNS(
                rtuAddr VARCHAR(20) PATH '$.rtuAddr',
              isOnLine BOOLEAN PATH '$.isOnLine'
           )
      ) rtus ON con.rtuAddr = rtus.rtuAddr
    <where>
      <if test="operator != null">
        com.operator = #{operator}
      </if>
    </where>
  </select>
  <!--取水口名称换取水口ID,扫码开阀使用-->
  <select id="getIntakeIdByName" resultType="java.lang.Long">
    SELECT id AS intakeId FROM pr_intake WHERE `name` = #{intakeName}
  </select>
  <!--取水口名称换取水口ID,验证是否重复名称使用-->
  <select id="getIntakeIdsByName" resultType="java.lang.Long">
    SELECT id AS intakeId FROM pr_intake WHERE `name` = #{intakeName}
  </select>
  <!--取水口名称换取水口ID,验证是否重复名称使用-->
  <select id="getIntakeIdByNameExcludeId" resultType="java.lang.Long">
    SELECT id AS intakeId FROM pr_intake WHERE id != #{id} and `name` = #{intakeName}
  </select>
</mapper>