pipIrr-platform/pipIrr-global/src/main/resources/mapper/SeClientCardMapper.xml
@@ -10,6 +10,7 @@
    <result column="clientId" jdbcType="BIGINT" property="clientid" />
    <result column="money" jdbcType="FLOAT" property="money" />
    <result column="state" jdbcType="TINYINT" property="state" />
    <result column="original_card_id" jdbcType="BIGINT" property="originalCardId"/>
    <result column="createDt" jdbcType="TIMESTAMP" property="createdt" />
    <result column="replaceDt" jdbcType="TIMESTAMP" property="replacedt" />
    <result column="rechargeDt" jdbcType="TIMESTAMP" property="rechargedt" />
@@ -24,7 +25,7 @@
  </resultMap>
  <sql id="Base_Column_List">
    <!--@mbg.generated-->
    id, cardAddr, cardNum, clientId, money, `state`, createDt, replaceDt, rechargeDt,
    id, cardAddr, cardNum, clientId, money, `state`, original_card_id, createDt, replaceDt, rechargeDt,
    lossDtDt, cancelDt, unlockDt, reversalDt, refundDt, consumeDt, lastOper, remarks
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
@@ -52,16 +53,25 @@
  <!--根据水卡编号获取水卡表主键及农户编号-->
  <select id="getCardIdAndClientNum" resultType="java.util.Map">
<!--    SELECT id AS cardId, clientNum FROM se_client_card WHERE cardNum = #{cardNum}-->
    <!--    SELECT id AS cardId, clientNum FROM se_client_card WHERE cardNum = #{cardNum}-->
    SELECT
        card.id AS cardId,
        cli.clientNum,
        cli.id AS clientId
    card.id AS cardId,
    cli.clientNum,
    cli.id AS clientId
    FROM se_client_card card
        INNER JOIN se_client cli ON card.clientId = cli.id
    INNER JOIN se_client cli ON card.clientId = cli.id
    WHERE card.cardNum = #{cardNum}
  </select>
  <!-- 根据水卡编号获取水卡对应的农户id和姓名 -->
  <select id="getClientIdAndNameByCardAddrAndCardNo" resultType="java.util.Map">
    SELECT
    cli.id AS clientId,
    cli.name AS clientName
    FROM se_client_card card
    INNER JOIN se_client cli ON card.clientId = cli.id
    WHERE card.cardAddr = #{cardAddr} and  card.cardNum = #{cardNum}
  </select>
  <!--根据行政区划串模糊查询水卡编号-->
  <select id="getCardNumOfMax"  resultType="java.lang.String">
@@ -75,13 +85,13 @@
  <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.dy.pipIrrGlobal.pojoSe.SeClientCard">
    <!--@mbg.generated-->
    insert into se_client_card (id, cardAddr, cardNum, clientId,
      money, `state`, createDt,
      money, `state`, original_card_id, createDt,
      replaceDt, rechargeDt, lossDtDt, 
      cancelDt, unlockDt, reversalDt, refundDt,
      consumeDt, lastOper, remarks
      )
    values (#{id,jdbcType=BIGINT}, #{cardaddr,jdbcType=VARCHAR}, #{cardnum,jdbcType=BIGINT}, #{clientid,jdbcType=BIGINT},
      #{money,jdbcType=FLOAT}, #{state,jdbcType=TINYINT}, #{createdt,jdbcType=TIMESTAMP},
      #{money,jdbcType=FLOAT}, #{state,jdbcType=TINYINT}, #{originalCardId,jdbcType=BIGINT}, #{createdt,jdbcType=TIMESTAMP},
      #{replacedt,jdbcType=TIMESTAMP}, #{rechargedt,jdbcType=TIMESTAMP}, #{lossdtdt,jdbcType=TIMESTAMP}, 
      #{canceldt,jdbcType=TIMESTAMP}, #{unlockdt,jdbcType=TIMESTAMP}, #{reversaldt,jdbcType=TIMESTAMP},
      #{refunddt,jdbcType=TIMESTAMP}, #{consumedt,jdbcType=TIMESTAMP}, #{lastoper,jdbcType=TINYINT}, #{remarks,jdbcType=VARCHAR}
@@ -106,6 +116,9 @@
      </if>
      <if test="state != null">
        `state`,
      </if>
      <if test="originalCardId != null">
        original_card_id,
      </if>
      <if test="createdt != null">
        createDt,
@@ -156,6 +169,9 @@
      </if>
      <if test="state != null">
        #{state,jdbcType=TINYINT},
      </if>
      <if test="originalCardId != null">
        #{originalCardId,jdbcType=BIGINT},
      </if>
      <if test="createdt != null">
        #{createdt,jdbcType=TIMESTAMP},
@@ -211,6 +227,9 @@
      <if test="state != null">
        `state` = #{state,jdbcType=TINYINT},
      </if>
      <if test="originalCardId != null">
        `original_card_id` = #{originalCardId,jdbcType=BIGINT},
      </if>
      <if test="createdt != null">
        createDt = #{createdt,jdbcType=TIMESTAMP},
      </if>
@@ -255,6 +274,7 @@
      clientId = #{clientid,jdbcType=BIGINT},
      money = #{money,jdbcType=FLOAT},
      `state` = #{state,jdbcType=TINYINT},
      original_card_id = #{originalCardId,jdbcType=BIGINT},
      createDt = #{createdt,jdbcType=TIMESTAMP},
      replaceDt = #{replacedt,jdbcType=TIMESTAMP},
      rechargeDt = #{rechargedt,jdbcType=TIMESTAMP},
@@ -387,4 +407,147 @@
      </if>
    </trim>
  </select>
  <!--获取已挂失未补卡的记录数量-->
  <select id="getUnreplacedRecordCount" resultType="java.lang.Long">
    SELECT
        COUNT(*) AS recordCount
    FROM se_client_card card
           INNER JOIN se_client cli ON card.clientId = cli.id
    WHERE card.state = 3 AND NOT EXISTS (SELECT * FROM se_client_card card2 WHERE card2.original_card_id = card.cardNum)
  </select>
  <!--获取已挂失未补卡的记录-->
  <select id="getUnreplaced" resultType="com.dy.pipIrrGlobal.voSe.VoCards">
    SELECT
        cli.clientNum,
        cli.name AS clientName,
        card.cardNum,
        cli.phone,
        cli.idCard,
        card.state AS cardState,
        (CASE
            WHEN card.state = 1 THEN '正常'
            WHEN card.state = 2 THEN '已注销'
            WHEN card.state = 3 THEN '已挂失'
        End) AS stateName,
        '农户卡' AS cardType,
        FORMAT(card.money,2) AS money
    FROM se_client_card card
        INNER JOIN se_client cli ON card.clientId = cli.id
    WHERE card.state = 3 AND NOT EXISTS (SELECT * FROM se_client_card card2 WHERE card2.original_card_id = card.cardNum)
    ORDER BY card.id
    <trim prefix="limit " >
      <if test="start != null and count != null">
        #{start,javaType=Integer,jdbcType=INTEGER}, #{count,javaType=Integer,jdbcType=INTEGER}
      </if>
    </trim>
  </select>
  <!--根据指定水卡编号获取挂失事记录数量(补卡、解锁使用)-->
  <select id="getLostCount" resultType="java.lang.Integer">
    SELECT
        COUNT(*) AS recordCount
    FROM se_client_card card
    <where>
      AND card.state = 3
      <if test = "cardNum != null and cardNum > 0">
        AND card.cardNum = #{cardNum}
      </if>
    </where>
  </select>
  <!--根据指定水卡编号获取已补卡数量(补卡、解锁使用)-->
  <select id="getReplacedCount" resultType="java.lang.Integer">
    SELECT
        COUNT(*) AS recordCount
    FROM se_client_card card
        INNER JOIN se_client_card card2 ON card2.original_card_id = card.id
    <where>
      <if test = "cardNum != null and cardNum > 0">
        AND card.cardNum = #{cardNum}
      </if>
    </where>
  </select>
  <!--根据农户姓名和手机号获取水卡列表记录数,应用程序使用-->
  <select id="getCardsByClientNameAndPhoneCount" resultType="java.lang.Long">
    SELECT
      COUNT(*) AS recordCount
    FROM se_client_card card
    INNER JOIN se_client cli ON card.clientId = cli.id
    <where>
      card.state = 1
      <if test = "clientName != null and clientName !=''">
        AND cli.name like CONCAT('%',#{clientName},'%')
      </if>
      <if test = "phone != null and phone !=''">
        AND cli.phone like CONCAT('%',#{phone},'%')
      </if>
    </where>
    </select>
  <!--根据农户姓名和手机号获取水卡列表,应用程序使用-->
  <select id="getCardsByClientNameAndPhone" resultType="com.dy.pipIrrGlobal.voSe.VoCards2">
    SELECT
    card.id AS clientCardId,
    cli.id AS clientId,
    cli.clientNum,
    cli.name AS clientName,
    card.cardNum,
    cli.phone,
    cli.idCard,
    card.state AS cardState,
    (CASE
    WHEN card.state = 1 THEN '正常'
    WHEN card.state = 2 THEN '已注销'
    WHEN card.state = 3 THEN '已挂失'
    End) AS stateName,
    '农户卡' AS cardType,
    FORMAT(card.money, 2) AS money
    FROM se_client_card card
    INNER JOIN se_client cli ON card.clientId = cli.id
    <where>
      card.state = 1
      <if test = "clientName != null and clientName !=''">
        AND cli.name like CONCAT('%',#{clientName},'%')
      </if>
      <if test = "phone != null and phone !=''">
        AND cli.phone like CONCAT('%',#{phone},'%')
      </if>
    </where>
    ORDER BY card.id
    <trim prefix="limit " >
      <if test="start != null and count != null">
        #{start,javaType=Integer,jdbcType=INTEGER}, #{count,javaType=Integer,jdbcType=INTEGER}
      </if>
    </trim>
  </select>
  <!--根据农户ID查询正常状态的水卡列表,小程序使用-->
  <select id="getCardsByClientID" resultType="com.dy.pipIrrGlobal.voWe.VoCards3">
    SELECT
    card.id AS clientCardId,
    cli.id AS clientId,
    cli.clientNum,
    cli.name AS clientName,
    card.cardNum,
    cli.phone,
    cli.idCard,
    card.state AS cardState,
    (CASE
    WHEN card.state = 1 THEN '正常'
    WHEN card.state = 2 THEN '已注销'
    WHEN card.state = 3 THEN '已挂失'
    End) AS stateName,
    '农户卡' AS cardType,
    FORMAT(card.money, 2) AS money
    FROM se_client_card card
    INNER JOIN se_client cli ON card.clientId = cli.id
    where
      card.state = 1
      AND cli.id like CONCAT('%',#{clientId},'%')
    ORDER BY card.id
  </select>
</mapper>