<?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.boco.nbd.wios.manage.mapper.def.UserPayBillMapper">
  <resultMap id="BaseResultMap" type="com.boco.nbd.wios.manage.entity.bo.UserPayBill">
    <id column="id" jdbcType="VARCHAR" property="id" />
    <result column="user_id" jdbcType="VARCHAR" property="userId" />
    <result column="user_phone" jdbcType="VARCHAR" property="userPhone" />
    <result column="amount" jdbcType="DECIMAL" property="amount" />
    <result column="info" jdbcType="VARCHAR" property="info" />
    <result column="pay_type" jdbcType="INTEGER" property="payType" />
    <result column="business_type" jdbcType="INTEGER" property="businessType" />
    <result column="pay_account" jdbcType="VARCHAR" property="payAccount" />
    <result column="pay_trade_no" jdbcType="VARCHAR" property="payTradeNo" />
    <result column="pay_time" jdbcType="TIMESTAMP" property="payTime" />
    <result column="ref_id" jdbcType="VARCHAR" property="refId" />
    <result column="status" jdbcType="INTEGER" property="status" />
    <result column="source" jdbcType="INTEGER" property="source" />
    <result column="create_account" jdbcType="VARCHAR" property="createAccount" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="modify_account" jdbcType="VARCHAR" property="modifyAccount" />
    <result column="modify_time" jdbcType="TIMESTAMP" property="modifyTime" />
  </resultMap>
  <sql id="Example_Where_Clause">
    <where>
      <foreach collection="oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Update_By_Example_Where_Clause">
    <where>
      <foreach collection="example.oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Base_Column_List">
    id, user_id, user_phone, amount, info, pay_type, business_type, pay_account, pay_trade_no, 
    pay_time, ref_id, status, source, create_account, create_time, modify_account, modify_time
  </sql>
  <select id="selectByExample" parameterType="com.boco.nbd.wios.manage.entity.bo.UserPayBillCriteria" resultMap="BaseResultMap">
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from t_user_pay_bill
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
  </select>
  <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from t_user_pay_bill
    where id = #{id,jdbcType=VARCHAR}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
    delete from t_user_pay_bill
    where id = #{id,jdbcType=VARCHAR}
  </delete>
  <delete id="deleteByExample" parameterType="com.boco.nbd.wios.manage.entity.bo.UserPayBillCriteria">
    delete from t_user_pay_bill
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.boco.nbd.wios.manage.entity.bo.UserPayBill">
    insert into t_user_pay_bill (id, user_id, user_phone, 
      amount, info, pay_type, 
      business_type, pay_account, pay_trade_no, 
      pay_time, ref_id, status, 
      source, create_account, create_time, 
      modify_account, modify_time)
    values (#{id,jdbcType=VARCHAR}, #{userId,jdbcType=VARCHAR}, #{userPhone,jdbcType=VARCHAR}, 
      #{amount,jdbcType=DECIMAL}, #{info,jdbcType=VARCHAR}, #{payType,jdbcType=INTEGER}, 
      #{businessType,jdbcType=INTEGER}, #{payAccount,jdbcType=VARCHAR}, #{payTradeNo,jdbcType=VARCHAR}, 
      #{payTime,jdbcType=TIMESTAMP}, #{refId,jdbcType=VARCHAR}, #{status,jdbcType=INTEGER}, 
      #{source,jdbcType=INTEGER}, #{createAccount,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, 
      #{modifyAccount,jdbcType=VARCHAR}, #{modifyTime,jdbcType=TIMESTAMP})
  </insert>
  <insert id="insertSelective" parameterType="com.boco.nbd.wios.manage.entity.bo.UserPayBill">
    insert into t_user_pay_bill
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="userId != null">
        user_id,
      </if>
      <if test="userPhone != null">
        user_phone,
      </if>
      <if test="amount != null">
        amount,
      </if>
      <if test="info != null">
        info,
      </if>
      <if test="payType != null">
        pay_type,
      </if>
      <if test="businessType != null">
        business_type,
      </if>
      <if test="payAccount != null">
        pay_account,
      </if>
      <if test="payTradeNo != null">
        pay_trade_no,
      </if>
      <if test="payTime != null">
        pay_time,
      </if>
      <if test="refId != null">
        ref_id,
      </if>
      <if test="status != null">
        status,
      </if>
      <if test="source != null">
        source,
      </if>
      <if test="createAccount != null">
        create_account,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
      <if test="modifyAccount != null">
        modify_account,
      </if>
      <if test="modifyTime != null">
        modify_time,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=VARCHAR},
      </if>
      <if test="userId != null">
        #{userId,jdbcType=VARCHAR},
      </if>
      <if test="userPhone != null">
        #{userPhone,jdbcType=VARCHAR},
      </if>
      <if test="amount != null">
        #{amount,jdbcType=DECIMAL},
      </if>
      <if test="info != null">
        #{info,jdbcType=VARCHAR},
      </if>
      <if test="payType != null">
        #{payType,jdbcType=INTEGER},
      </if>
      <if test="businessType != null">
        #{businessType,jdbcType=INTEGER},
      </if>
      <if test="payAccount != null">
        #{payAccount,jdbcType=VARCHAR},
      </if>
      <if test="payTradeNo != null">
        #{payTradeNo,jdbcType=VARCHAR},
      </if>
      <if test="payTime != null">
        #{payTime,jdbcType=TIMESTAMP},
      </if>
      <if test="refId != null">
        #{refId,jdbcType=VARCHAR},
      </if>
      <if test="status != null">
        #{status,jdbcType=INTEGER},
      </if>
      <if test="source != null">
        #{source,jdbcType=INTEGER},
      </if>
      <if test="createAccount != null">
        #{createAccount,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="modifyAccount != null">
        #{modifyAccount,jdbcType=VARCHAR},
      </if>
      <if test="modifyTime != null">
        #{modifyTime,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.boco.nbd.wios.manage.entity.bo.UserPayBillCriteria" resultType="java.lang.Long">
    select count(*) from t_user_pay_bill
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map">
    update t_user_pay_bill
    <set>
      <if test="record.id != null">
        id = #{record.id,jdbcType=VARCHAR},
      </if>
      <if test="record.userId != null">
        user_id = #{record.userId,jdbcType=VARCHAR},
      </if>
      <if test="record.userPhone != null">
        user_phone = #{record.userPhone,jdbcType=VARCHAR},
      </if>
      <if test="record.amount != null">
        amount = #{record.amount,jdbcType=DECIMAL},
      </if>
      <if test="record.info != null">
        info = #{record.info,jdbcType=VARCHAR},
      </if>
      <if test="record.payType != null">
        pay_type = #{record.payType,jdbcType=INTEGER},
      </if>
      <if test="record.businessType != null">
        business_type = #{record.businessType,jdbcType=INTEGER},
      </if>
      <if test="record.payAccount != null">
        pay_account = #{record.payAccount,jdbcType=VARCHAR},
      </if>
      <if test="record.payTradeNo != null">
        pay_trade_no = #{record.payTradeNo,jdbcType=VARCHAR},
      </if>
      <if test="record.payTime != null">
        pay_time = #{record.payTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.refId != null">
        ref_id = #{record.refId,jdbcType=VARCHAR},
      </if>
      <if test="record.status != null">
        status = #{record.status,jdbcType=INTEGER},
      </if>
      <if test="record.source != null">
        source = #{record.source,jdbcType=INTEGER},
      </if>
      <if test="record.createAccount != null">
        create_account = #{record.createAccount,jdbcType=VARCHAR},
      </if>
      <if test="record.createTime != null">
        create_time = #{record.createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.modifyAccount != null">
        modify_account = #{record.modifyAccount,jdbcType=VARCHAR},
      </if>
      <if test="record.modifyTime != null">
        modify_time = #{record.modifyTime,jdbcType=TIMESTAMP},
      </if>
    </set>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map">
    update t_user_pay_bill
    set id = #{record.id,jdbcType=VARCHAR},
      user_id = #{record.userId,jdbcType=VARCHAR},
      user_phone = #{record.userPhone,jdbcType=VARCHAR},
      amount = #{record.amount,jdbcType=DECIMAL},
      info = #{record.info,jdbcType=VARCHAR},
      pay_type = #{record.payType,jdbcType=INTEGER},
      business_type = #{record.businessType,jdbcType=INTEGER},
      pay_account = #{record.payAccount,jdbcType=VARCHAR},
      pay_trade_no = #{record.payTradeNo,jdbcType=VARCHAR},
      pay_time = #{record.payTime,jdbcType=TIMESTAMP},
      ref_id = #{record.refId,jdbcType=VARCHAR},
      status = #{record.status,jdbcType=INTEGER},
      source = #{record.source,jdbcType=INTEGER},
      create_account = #{record.createAccount,jdbcType=VARCHAR},
      create_time = #{record.createTime,jdbcType=TIMESTAMP},
      modify_account = #{record.modifyAccount,jdbcType=VARCHAR},
      modify_time = #{record.modifyTime,jdbcType=TIMESTAMP}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.boco.nbd.wios.manage.entity.bo.UserPayBill">
    update t_user_pay_bill
    <set>
      <if test="userId != null">
        user_id = #{userId,jdbcType=VARCHAR},
      </if>
      <if test="userPhone != null">
        user_phone = #{userPhone,jdbcType=VARCHAR},
      </if>
      <if test="amount != null">
        amount = #{amount,jdbcType=DECIMAL},
      </if>
      <if test="info != null">
        info = #{info,jdbcType=VARCHAR},
      </if>
      <if test="payType != null">
        pay_type = #{payType,jdbcType=INTEGER},
      </if>
      <if test="businessType != null">
        business_type = #{businessType,jdbcType=INTEGER},
      </if>
      <if test="payAccount != null">
        pay_account = #{payAccount,jdbcType=VARCHAR},
      </if>
      <if test="payTradeNo != null">
        pay_trade_no = #{payTradeNo,jdbcType=VARCHAR},
      </if>
      <if test="payTime != null">
        pay_time = #{payTime,jdbcType=TIMESTAMP},
      </if>
      <if test="refId != null">
        ref_id = #{refId,jdbcType=VARCHAR},
      </if>
      <if test="status != null">
        status = #{status,jdbcType=INTEGER},
      </if>
      <if test="source != null">
        source = #{source,jdbcType=INTEGER},
      </if>
      <if test="createAccount != null">
        create_account = #{createAccount,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="modifyAccount != null">
        modify_account = #{modifyAccount,jdbcType=VARCHAR},
      </if>
      <if test="modifyTime != null">
        modify_time = #{modifyTime,jdbcType=TIMESTAMP},
      </if>
    </set>
    where id = #{id,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.boco.nbd.wios.manage.entity.bo.UserPayBill">
    update t_user_pay_bill
    set user_id = #{userId,jdbcType=VARCHAR},
      user_phone = #{userPhone,jdbcType=VARCHAR},
      amount = #{amount,jdbcType=DECIMAL},
      info = #{info,jdbcType=VARCHAR},
      pay_type = #{payType,jdbcType=INTEGER},
      business_type = #{businessType,jdbcType=INTEGER},
      pay_account = #{payAccount,jdbcType=VARCHAR},
      pay_trade_no = #{payTradeNo,jdbcType=VARCHAR},
      pay_time = #{payTime,jdbcType=TIMESTAMP},
      ref_id = #{refId,jdbcType=VARCHAR},
      status = #{status,jdbcType=INTEGER},
      source = #{source,jdbcType=INTEGER},
      create_account = #{createAccount,jdbcType=VARCHAR},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      modify_account = #{modifyAccount,jdbcType=VARCHAR},
      modify_time = #{modifyTime,jdbcType=TIMESTAMP}
    where id = #{id,jdbcType=VARCHAR}
  </update>


  <select id="list" parameterType="com.boco.nbd.wios.manage.entity.bo.UserPayBill" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from t_user_pay_bill b
    <where>
      <if test="id!=null and id!=''">
        b.id = #{id}
      </if>
      <if test="refId!=null and refId!=''">
        b.ref_id = #{refId}
      </if>
      <if test="userId!=null and userId!=''">
        b.user_id = #{userId}
      </if>
      <if test="userPhone!=null and userPhone!=''">
        b.user_phone = #{userPhone}
      </if>
      <if test="status!=null">
        b.status = #{status}
      </if>
      <if test="businessType!=null">
        b.business_type = #{businessType}
      </if>
      order by b.create_time desc
    </where>
  </select>

  <select id="count" parameterType="com.boco.nbd.wios.manage.entity.bo.UserPayBill" resultType="java.lang.Integer">
    select count(*)
    from t_user_pay_bill b
    <where>
      <if test="id!=null and id!=''">
        b.id = #{id}
      </if>
      <if test="refId!=null and refId!=''">
        b.ref_id = #{refId}
      </if>
      <if test="userId!=null and userId!=''">
        b.user_id = #{userId}
      </if>
      <if test="userPhone!=null and userPhone!=''">
        b.user_phone = #{userPhone}
      </if>
      <if test="status!=null">
        b.status = #{status}
      </if>
      <if test="businessType!=null">
        b.business_type = #{businessType}
      </if>
    </where>
  </select>
  
  <select id="selectList" parameterType="com.boco.nbd.wios.manage.entity.bo.UserPayBill" resultType="com.boco.nbd.wios.manage.entity.bo.UserPayBillVo">
    select b.*,o.status as orderStatus
    from t_user_pay_bill b
    left join t_order o on b.ref_id=o.id
    <where>
      <if test="id!=null and id!=''">
        and b.id = #{id}
      </if>
      <if test="refId!=null and refId!=''">
        and b.ref_id = #{refId}
      </if>
      <if test="userId!=null and userId!=''">
        and b.user_id = #{userId}
      </if>
      <if test="userPhone!=null and userPhone!=''">
        and (o.user_phone = #{userPhone} or o.survey_cams_phone=#{userPhone} or o.install_cams_phone=#{userPhone})
      </if>
      <if test="status!=null">
        and b.status = #{status}
      </if>
      <if test="businessType!=null">
        and b.business_type = #{businessType}
      </if>
      order by b.create_time desc
    </where>
  </select>
  
  <select id="selectListForApp" parameterType="com.boco.nbd.wios.manage.entity.bo.UserPayBill" resultType="com.boco.nbd.wios.manage.entity.bo.UserPayBillVo">
    select b.*,o.status as orderStatus,o.install_finish_time as installFinishTime
    from t_user_pay_bill b
    left join t_order o on b.ref_id=o.id
    <where>
      <if test="id!=null and id!=''">
        and b.id = #{id}
      </if>
      <if test="refId!=null and refId!=''">
        and b.ref_id = #{refId}
      </if>
      <if test="userPhone!=null and userPhone!=''">
        and (o.user_phone = #{userPhone} or o.survey_cams_phone=#{userPhone} or o.install_cams_phone=#{userPhone})
      </if>
      <if test="status!=null">
        and b.status = #{status}
      </if>
      order by b.create_time desc
    </where>
  </select>
</mapper>