TdBVipCardContractSmapper.xml 8.86 KB
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zteits.order.mapper.smapper.TdBVipCardContractSMapper">

  <resultMap id="BaseResultMap" type="com.zteits.order.domain.TdBVipCardContract">
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="contract_no" jdbcType="VARCHAR" property="contractNo" />
    <result column="detail_id" jdbcType="BIGINT" property="detailId" />
    <result column="order_id" jdbcType="VARCHAR" property="orderId" />
    <result column="pl_no" jdbcType="VARCHAR" property="plNo" />
    <result column="pl_name" jdbcType="VARCHAR" property="plName" />
    <result column="car_number" jdbcType="VARCHAR" property="carNumber" />
    <result column="cust_name" jdbcType="VARCHAR" property="custName" />
    <result column="cust_phone" jdbcType="VARCHAR" property="custPhone" />
    <result column="cust_address" jdbcType="VARCHAR" property="custAddress" />
    <result column="price" jdbcType="BIGINT" property="price" />
    <result column="total_fee" jdbcType="BIGINT" property="totalFee" />
    <result column="eff_date" jdbcType="TIMESTAMP" property="effDate" />
    <result column="exp_date" jdbcType="TIMESTAMP" property="expDate" />
    <result column="detail_create_date" jdbcType="TIMESTAMP" property="detailCreateDate" />
    <result column="contract_year" jdbcType="INTEGER" property="contractYear" />
    <result column="file_name" jdbcType="VARCHAR" property="fileName" />
    <result column="file_key" jdbcType="VARCHAR" property="fileKey" />
    <result column="file_url" jdbcType="VARCHAR" property="fileUrl" />
    <result column="file_size" jdbcType="BIGINT" property="fileSize" />
    <result column="data_state" jdbcType="INTEGER" property="dataState" />
    <result column="create_op" jdbcType="INTEGER" property="createOp" />
    <result column="create_date" jdbcType="TIMESTAMP" property="createDate" />
    <result column="modify_op" jdbcType="INTEGER" property="modifyOp" />
    <result column="modify_date" jdbcType="TIMESTAMP" property="modifyDate" />
  </resultMap>

  <!--
    待归档月卡购买明细:条件与 OrderVipcardDetailSmapper.queryVipCardOrderInfoForPage 完全一致
    (a.data_state=1 and b.data_state=1 and a.order_id=b.order_id and b.order_state in(40,50)),
    只额外投影 a.id / a.order_id / a.pl_no / a.pl_name,并排除已在合同表建档的明细。
  -->
  <select id="selectPendingContractDetails"
          parameterType="com.zteits.clouds.api.dto.order.vipcardcontract.param.QueryPendingContractDetailReq"
          resultType="com.zteits.order.domain.TdBVipCardContract">
    select
        a.id             as detailId,
        a.order_id       as orderId,
        a.pl_no          as plNo,
        a.pl_name        as plName,
        a.car_number     as carNumber,
        a.price          as price,
        a.card_act_amount as totalFee,
        a.eff_date       as effDate,
        a.exp_date       as expDate,
        a.create_date    as detailCreateDate
    from order_vipcard_detail a, order_vipcard b
    where a.data_state = 1
          and b.data_state = 1
          and a.order_id = b.order_id
          and b.order_state in (40,50) /**订单状态 10:待核算、20:待支付、30:支付中,40:已支付、50:已完成*/
          and not exists (select 1 from td_b_vip_card_contract c where c.detail_id = a.id)
    <if test="plNo != null and plNo != ''">
          and a.pl_no = #{plNo}
    </if>
    order by a.id asc
    limit #{limit}
  </select>

  <insert id="insertIgnoreBatch">
    insert ignore into td_b_vip_card_contract
      (contract_no, detail_id, order_id, pl_no, pl_name, car_number, cust_name, cust_phone,
       cust_address, price, total_fee, eff_date, exp_date, detail_create_date, contract_year,
       data_state, create_op, create_date)
    values
    <foreach collection="list" item="item" separator=",">
      (#{item.contractNo}, #{item.detailId}, #{item.orderId}, #{item.plNo}, #{item.plName},
       #{item.carNumber}, #{item.custName}, #{item.custPhone}, #{item.custAddress},
       #{item.price}, #{item.totalFee}, #{item.effDate}, #{item.expDate},
       #{item.detailCreateDate}, #{item.contractYear}, 1, #{item.createOp}, now())
    </foreach>
  </insert>

  <select id="selectUnarchivedContracts"
          parameterType="com.zteits.clouds.api.dto.order.vipcardcontract.param.QueryPendingContractDetailReq"
          resultMap="BaseResultMap">
    select
        id, contract_no, detail_id, order_id, pl_no, pl_name, car_number, cust_name, cust_phone,
        cust_address, price, total_fee, eff_date, exp_date, detail_create_date, contract_year,
        file_name, file_key, file_url, file_size, data_state, create_op, create_date, modify_op,
        modify_date
    from td_b_vip_card_contract
    where data_state = 1
      and (file_key is null or file_key = '')
    <if test="plNo != null and plNo != ''">
      and pl_no = #{plNo}
    </if>
    order by id asc
    limit #{limit}
  </select>

  <select id="selectByYear" resultMap="BaseResultMap">
    select
        id, contract_no, detail_id, order_id, pl_no, pl_name, car_number, cust_name, cust_phone,
        cust_address, price, total_fee, eff_date, exp_date, detail_create_date, contract_year,
        file_name, file_key, file_url, file_size, data_state, create_op, create_date, modify_op,
        modify_date
    from td_b_vip_card_contract
    where data_state = 1
      and contract_year = #{contractYear}
    <if test="plNo != null and plNo != ''">
      and pl_no = #{plNo}
    </if>
    order by detail_create_date asc, id asc
  </select>

  <select id="selectContractForPage"
          parameterType="com.zteits.clouds.api.dto.order.vipcardcontract.param.QueryVipCardContractPageReq"
          resultMap="BaseResultMap">
    select
        id, contract_no, detail_id, order_id, pl_no, pl_name, car_number, cust_name, cust_phone,
        cust_address, price, total_fee, eff_date, exp_date, detail_create_date, contract_year,
        file_name, file_key, file_url, file_size, data_state, create_op, create_date, modify_op,
        modify_date
    from td_b_vip_card_contract
    where data_state = 1
    <if test="plNo != null and plNo != ''">
        and pl_no = #{plNo}
    </if>
    <if test="carNumber != null and carNumber != ''">
        and car_number like concat('%', #{carNumber}, '%')
    </if>
    <if test="contractNo != null and contractNo != ''">
        and contract_no like concat('%', #{contractNo}, '%')
    </if>
    <if test="custName != null and custName != ''">
        and cust_name like concat('%', #{custName}, '%')
    </if>
    <if test="contractYear != null">
        and contract_year = #{contractYear}
    </if>
    <if test="beginDate != null and beginDate != ''">
        <![CDATA[ and eff_date >= #{beginDate} ]]>
    </if>
    <if test="endDate != null and endDate != ''">
        <![CDATA[ and eff_date <= #{endDate} ]]>
    </if>
    order by id desc
  </select>

  <select id="selectByIds" resultMap="BaseResultMap">
    select
        id, contract_no, detail_id, order_id, pl_no, pl_name, car_number, cust_name, cust_phone,
        cust_address, price, total_fee, eff_date, exp_date, detail_create_date, contract_year,
        file_name, file_key, file_url, file_size, data_state, create_op, create_date, modify_op,
        modify_date
    from td_b_vip_card_contract
    where data_state = 1
      and id in
    <foreach collection="ids" open="(" close=")" item="id" separator=",">
      #{id}
    </foreach>
    order by detail_create_date asc, id asc
  </select>

  <select id="selectLedgerYears" resultType="java.lang.String">
    select distinct contract_year
    from td_b_vip_card_contract
    where data_state = 1
      and contract_year is not null
    <if test="plNo != null and plNo != ''">
      and pl_no = #{plNo}
    </if>
    order by contract_year desc
  </select>

  <!-- 单条 SQL 批量回写,避免循环操作数据库 -->
  <update id="batchUpdateArchive">
    update td_b_vip_card_contract
    set modify_date = now(),
        file_name = case id
        <foreach collection="list" item="item">
            when #{item.id} then #{item.fileName}
        </foreach>
        end,
        file_key = case id
        <foreach collection="list" item="item">
            when #{item.id} then #{item.fileKey}
        </foreach>
        end,
        file_url = case id
        <foreach collection="list" item="item">
            when #{item.id} then #{item.fileUrl}
        </foreach>
        end,
        file_size = case id
        <foreach collection="list" item="item">
            when #{item.id} then #{item.fileSize}
        </foreach>
        end,
        modify_op = case id
        <foreach collection="list" item="item">
            when #{item.id} then #{item.opId}
        </foreach>
        end
    where id in
    <foreach collection="list" open="(" close=")" item="item" separator=",">
      #{item.id}
    </foreach>
  </update>

</mapper>