zhubaomin
2024-10-21 bc958e6f7341714e40da74722c4f2208f192fe61
pipIrr-platform/pipIrr-global/src/main/resources/mapper/SeClientMapper.xml
@@ -28,7 +28,7 @@
  </resultMap>
  <sql id="Base_Column_List">
    <!--@mbg.generated-->
    id, countyId, townId, villageId, blockId, divideId, `name`, virtualId, clientNum,
    id, countyId, townId, villageId, blockid, divideId, `name`, virtualId, clientNum,
    districtNum, districtTitle, phone, idCard, area, typeId, address, remarks, `operator`, 
    operateDt, disabled, deleted
  </sql>
@@ -56,7 +56,7 @@
      operateDt, disabled, deleted
      )
    values (#{id,jdbcType=BIGINT}, #{countyid,jdbcType=BIGINT}, #{townid,jdbcType=BIGINT}, 
      #{villageid,jdbcType=BIGINT}, #{blockid,jdbcType=BIGINT}, #{divideid,jdbcType=BIGINT},
      #{villageid,jdbcType=BIGINT}, #{blockid,jdbcType=BIGINT}, #{divideid,jdbcType=BIGINT},
      #{name,jdbcType=VARCHAR}, #{virtualid,jdbcType=BIGINT}, #{clientnum,jdbcType=VARCHAR}, 
      #{districtnum,jdbcType=BIGINT}, #{districttitle,jdbcType=VARCHAR}, #{phone,jdbcType=VARCHAR}, 
      #{idcard,jdbcType=VARCHAR}, #{area,jdbcType=DOUBLE}, #{typeid,jdbcType=BIGINT}, 
@@ -286,7 +286,7 @@
      address = #{address,jdbcType=VARCHAR},
      remarks = #{remarks,jdbcType=VARCHAR},
      `operator` = #{operator,jdbcType=BIGINT},
      operateDt = #{operatedt,jdbcType=TIMESTAMP},
      operateDt = #{operatedt,jdbcType=TIMESTAMP}
<!--      disabled = #{disabled,jdbcType=TINYINT},-->
<!--      deleted = #{deleted,jdbcType=TINYINT}-->
    where id = #{id,jdbcType=BIGINT}
@@ -304,22 +304,36 @@
  <!--根据指定条件获取农户记录数-->
  <select id="getRecordCount" parameterType="java.util.Map" resultType="java.lang.Long">
    SELECT
    COUNT(*) AS recordCount
        COUNT(*) AS recordCount
    FROM se_client cli
    , (SELECT @i:=0) AS itable
    <where>
      AND disabled = 0
      AND deleted = 0
      AND cli.disabled = 0
      AND cli.deleted = 0
      <if test = "name != null and name !=''">
        AND name like CONCAT('%',#{name},'%')
        AND cli.name like CONCAT('%',#{name},'%')
      </if>
      <if test = "num != null and num !=''">
        AND clientNum like CONCAT('%',#{num},'%')
      <if test = "clientNum != null and clientNum !=''">
        AND cli.clientNum like CONCAT('%',#{clientNum},'%')
      </if>
      <if test = "phone != null and phone !=''">
        AND phone like CONCAT('%',#{phone},'%')
        AND cli.phone like CONCAT('%',#{phone},'%')
      </if>
      <if test = "address != null and address !=''">
        AND cli.address like CONCAT('%',#{address},'%')
      </if>
      <if test = "villageId != null and villageId !=''">
        AND cli.villageId =  #{villageId}
      </if>
      <if test = "blockId != null and blockId !=''">
        AND cli.blockId =  #{blockId}
      </if>
      <if test = "divideId != null and divideId !=''">
        AND cli.divideId =  #{divideId}
      </if>
    </where>
@@ -329,49 +343,90 @@
  <!--根据指定条件获取农户数据-->
  <select id="getClients" resultType="com.dy.pipIrrGlobal.voSe.VoClient">
    SELECT
    (@i:=@i+1) AS id,
    name,
    clientNum,
    phone,
    idCard,
    (SELECT COUNT(*) FROM se_client_card WHERE clientNum = cli.clientNum) AS cardCount,
    address,
    operateDt
        CAST(cli.countyId AS char) AS countyId,
        dis_con.name AS countryName,
        CAST(cli.townId AS char) AS townId,
        dis_town.name AS townName,
        CAST(cli.villageId AS char) AS villageId,
        dis_village.name AS villageName,
        CAST(cli.blockId AS char) AS blockId,
        blo.name AS blockName,
        CAST(cli.divideId AS char) AS divideId,
        divi.name AS divideName,
        CAST(cli.typeId AS char) AS typeId,
        wat.typeName AS waterTypeName,
        CAST(cli.id AS char) AS clientId,
        cli.name,
        cli.clientNum,
        cli.phone,
        cli.idCard,
        cli.area,
        (SELECT COUNT(*) FROM se_client_card WHERE clientId = cli.id)+(SELECT COUNT(*) FROM se_virtual_card WHERE client_id = cli.id) AS cardCount,
        cli.address,
        cli.remarks,
        cli.operateDt
    FROM se_client cli
    , (SELECT @i:=0) AS itable
    LEFT JOIN ba_district dis_con ON cli.countyId = dis_con.id
    LEFT JOIN ba_district dis_town ON cli.townId = dis_town.id
    LEFT JOIN ba_district dis_village ON cli.villageId = dis_village.id
    LEFT JOIN ba_block blo ON cli.blockId = blo.id
    LEFT JOIN pr_divide divi ON cli.divideId = divi.id
    LEFT JOIN se_water_type wat ON cli.typeId = wat.id
    <where>
      AND disabled = 0
      AND deleted = 0
      AND cli.disabled = 0
      AND cli.deleted = 0
      <if test = "name != null and name !=''">
        AND name like CONCAT('%',#{name},'%')
        AND cli.name like CONCAT('%',#{name},'%')
      </if>
      <if test = "clientNum != null and clientNum !=''">
        AND clientNum like CONCAT('%',#{clientNum},'%')
        AND cli.clientNum like CONCAT('%',#{clientNum},'%')
      </if>
      <if test = "phone != null and phone !=''">
        AND phone like CONCAT('%',#{phone},'%')
        AND cli.phone like CONCAT('%',#{phone},'%')
      </if>
      <if test = "address != null and address !=''">
        AND address like CONCAT('%',#{address},'%')
        AND cli.address like CONCAT('%',#{address},'%')
      </if>
      <if test = "villageId != null and villageId !=''">
        AND cli.villageId =  #{villageId}
      </if>
      <if test = "blockId != null and blockId !=''">
        AND cli.blockId =  #{blockId}
      </if>
      <if test = "divideId != null and divideId !=''">
        AND cli.divideId =  #{divideId}
      </if>
    </where>
    ORDER BY operateDt DESC
    <if test="pageCurr != null and pageSize != null">
      LIMIT ${pageCurr}, ${pageSize}
    </if>
    ORDER BY cli.operateDt DESC
    <trim prefix="limit " >
      <if test="start != null and count != null">
        #{start,javaType=Integer,jdbcType=INTEGER}, #{count,javaType=Integer,jdbcType=INTEGER}
      </if>
    </trim>
  </select>
  <!--根据农户编号获取5级行政区划代码-->
  <select id="getAreaCodeByNum" resultType="java.lang.Long">
    SELECT districtNum FROM se_client WHERE clientNum = ${clientNum}
    SELECT districtNum FROM se_client WHERE clientNum = #{clientNum} LIMIT 0,1
  </select>
  <!--根据农户编号获取5级行政区划串areaCode,补卡过程中开新卡使用-->
  <select id="getAreaCodeById" resultType="java.lang.Long">
    SELECT districtNum FROM se_client WHERE id = #{clientId}
  </select>
  <!--根据农户编号获取农户ID-->
  <select id="getClientIdByNum" resultType="java.lang.Long">
    SELECT id FROM se_client WHERE clientNum = ${clientNum}
    SELECT id FROM se_client WHERE clientNum = #{clientNum} LIMIT 0,1
  </select>
  <!--根据电话号码获取农户ID-->
  <select id="getClientIdByPhone" resultType="java.lang.Long">
    SELECT id FROM se_client WHERE phone = #{phoneNumber}
  </select>
  <!--根据农户ID逻辑删除农户-->
@@ -379,14 +434,14 @@
    update se_client set deleted = 1
    <where>
      <if test = "id != null and id > 0">
        AND id = ${id}
        AND id = #{id}
      </if>
    </where>
  </update>
  <!--根据主键获取村ID-->
  <select id="getVillageIdById" parameterType="java.lang.Long" resultType="java.lang.Long">
    SELECT villageId FROM se_client WHERE id = ${id}
    SELECT villageId FROM se_client WHERE id = #{id}
  </select>
  <!--获取虚拟卡号最大值-->
@@ -396,6 +451,65 @@
  <!--获取用水方式列表-->
  <select id="getWaterTypes" resultType="java.util.Map">
    SELECT id, typeName from se_water_type
    SELECT CAST(se_water_type.id AS char) AS id, typeName from se_water_type
  </select>
  <!--获取农户基本信息,小程序首页使用-->
  <select id="getSimpleClientInfo" resultType="com.dy.pipIrrGlobal.voSe.VoClientWechat">
    SELECT
      CAST(ope.id AS char) AS sessionId,
      CAST(cli.id AS char)  AS clientId,
      cli.name AS clientName,
      cli.phone,
      CAST(cli.blockId AS char) AS blockId
    FROM se_open_id ope
           INNER JOIN se_client cli ON ope.client_id = cli.id
    <where>
      <if test = "sessionId != null">
        AND ope.id = #{sessionId}
      </if>
      <if test = "openId != null">
        AND ope.open_id = #{openId}
      </if>
    </where>
    LIMIT 0,1
  </select>
  <!--获取指定时间段农户:充值合计、消费合计、余额-->
  <select id="getClientUsagesCount" resultType="java.lang.Long">
    SELECT
      count(*)
    FROM se_client cli
    <where>
      <if test="clientName != null and clientName != ''">
        AND cli.name like CONCAT('%', #{clientName}, '%')
      </if>
      <if test="clientNum != null and clientNum != ''">
        AND cli.clientNum like CONCAT('%', #{clientNum}, '%')
      </if>
    </where>
    </select>
  <!--获取指定时间段农户:充值合计、消费合计、余额-->
  <select id="getClientUsages" resultType="com.dy.pipIrrGlobal.voSt.VoCardUsage">
    SELECT
      cli.name AS clientName,
      (SELECT ROUND(SUM(rch.amount),2) FROM se_recharge_history rch WHERE rch.clientId = cli.id AND rch.operateDt BETWEEN #{timeStart} AND #{timeStop}) AS totalRecharge,
      (SELECT ROUND(SUM(his.cl_this_money),2) FROM rm_open_close_valve_history his WHERE his.client_id = cli.id AND his.cl_dt BETWEEN #{timeStart} AND #{timeStop}) AS totalConsumption,
      (SELECT ROUND(SUM(card.money),2) FROM se_client_card card WHERE card.clientId = cli.id) AS balance
    FROM se_client cli
    <where>
      <if test="clientName != null and clientName != ''">
        AND cli.name like CONCAT('%', #{clientName}, '%')
      </if>
      <if test="clientNum != null and clientNum != ''">
        AND cli.clientNum like CONCAT('%', #{clientNum}, '%')
      </if>
    </where>
    ORDER BY totalConsumption DESC, totalRecharge DESC
    <trim prefix="limit ">
      <if test="start != null and count != null">
        #{start,javaType=Integer,jdbcType=INTEGER}, #{count,javaType=Integer,jdbcType=INTEGER}
      </if>
    </trim>
  </select>
</mapper>