<?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="cn.superdesk.uniorder.dao.mapper.operationCenter.OperationCenterPaymentMapper">
  <resultMap id="BaseResultMap" type="cn.superdesk.uniorder.dao.entity.operationCenter.OperationCenterPayment">
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="is_combined" jdbcType="TINYINT" property="isCombined" />
    <result column="associate_type" jdbcType="TINYINT" property="associateType" />
    <result column="enabled" jdbcType="TINYINT" property="enabled" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="create_user_id" jdbcType="BIGINT" property="createUserId" />
    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
    <result column="update_user_id" jdbcType="BIGINT" property="updateUserId" />
    <result column="deleted" jdbcType="TINYINT" property="deleted" />
  </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, name, is_combined, associate_type, enabled, create_time, create_user_id, update_time, 
    update_user_id, deleted
  </sql>
  <select id="selectByExample" parameterType="cn.superdesk.uniorder.dao.entity.operationCenter.OperationCenterPaymentExample" resultMap="BaseResultMap">
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from tb_operation_center_payment
    <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.Long" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from tb_operation_center_payment
    where id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    delete from tb_operation_center_payment
    where id = #{id,jdbcType=BIGINT}
  </delete>
  <delete id="deleteByExample" parameterType="cn.superdesk.uniorder.dao.entity.operationCenter.OperationCenterPaymentExample">
    delete from tb_operation_center_payment
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="cn.superdesk.uniorder.dao.entity.operationCenter.OperationCenterPayment">
    insert into tb_operation_center_payment (id, name, is_combined, 
      associate_type, enabled, create_time, 
      create_user_id, update_time, update_user_id, 
      deleted)
    values (#{id,jdbcType=BIGINT}, #{name,jdbcType=VARCHAR}, #{isCombined,jdbcType=TINYINT}, 
      #{associateType,jdbcType=TINYINT}, #{enabled,jdbcType=TINYINT}, #{createTime,jdbcType=TIMESTAMP}, 
      #{createUserId,jdbcType=BIGINT}, #{updateTime,jdbcType=TIMESTAMP}, #{updateUserId,jdbcType=BIGINT}, 
      #{deleted,jdbcType=TINYINT})
  </insert>
  <insert id="insertSelective" keyProperty="id" useGeneratedKeys="true" parameterType="cn.superdesk.uniorder.dao.entity.operationCenter.OperationCenterPayment">
    insert into tb_operation_center_payment
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="name != null">
        name,
      </if>
      <if test="isCombined != null">
        is_combined,
      </if>
      <if test="associateType != null">
        associate_type,
      </if>
      <if test="enabled != null">
        enabled,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
      <if test="createUserId != null">
        create_user_id,
      </if>
      <if test="updateTime != null">
        update_time,
      </if>
      <if test="updateUserId != null">
        update_user_id,
      </if>
      <if test="deleted != null">
        deleted,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=BIGINT},
      </if>
      <if test="name != null">
        #{name,jdbcType=VARCHAR},
      </if>
      <if test="isCombined != null">
        #{isCombined,jdbcType=TINYINT},
      </if>
      <if test="associateType != null">
        #{associateType,jdbcType=TINYINT},
      </if>
      <if test="enabled != null">
        #{enabled,jdbcType=TINYINT},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="createUserId != null">
        #{createUserId,jdbcType=BIGINT},
      </if>
      <if test="updateTime != null">
        #{updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateUserId != null">
        #{updateUserId,jdbcType=BIGINT},
      </if>
      <if test="deleted != null">
        #{deleted,jdbcType=TINYINT},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="cn.superdesk.uniorder.dao.entity.operationCenter.OperationCenterPaymentExample" resultType="java.lang.Long">
    select count(*) from tb_operation_center_payment
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map">
    update tb_operation_center_payment
    <set>
      <if test="record.id != null">
        id = #{record.id,jdbcType=BIGINT},
      </if>
      <if test="record.name != null">
        name = #{record.name,jdbcType=VARCHAR},
      </if>
      <if test="record.isCombined != null">
        is_combined = #{record.isCombined,jdbcType=TINYINT},
      </if>
      <if test="record.associateType != null">
        associate_type = #{record.associateType,jdbcType=TINYINT},
      </if>
      <if test="record.enabled != null">
        enabled = #{record.enabled,jdbcType=TINYINT},
      </if>
      <if test="record.createTime != null">
        create_time = #{record.createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.createUserId != null">
        create_user_id = #{record.createUserId,jdbcType=BIGINT},
      </if>
      <if test="record.updateTime != null">
        update_time = #{record.updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.updateUserId != null">
        update_user_id = #{record.updateUserId,jdbcType=BIGINT},
      </if>
      <if test="record.deleted != null">
        deleted = #{record.deleted,jdbcType=TINYINT},
      </if>
    </set>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map">
    update tb_operation_center_payment
    set id = #{record.id,jdbcType=BIGINT},
      name = #{record.name,jdbcType=VARCHAR},
      is_combined = #{record.isCombined,jdbcType=TINYINT},
      associate_type = #{record.associateType,jdbcType=TINYINT},
      enabled = #{record.enabled,jdbcType=TINYINT},
      create_time = #{record.createTime,jdbcType=TIMESTAMP},
      create_user_id = #{record.createUserId,jdbcType=BIGINT},
      update_time = #{record.updateTime,jdbcType=TIMESTAMP},
      update_user_id = #{record.updateUserId,jdbcType=BIGINT},
      deleted = #{record.deleted,jdbcType=TINYINT}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="cn.superdesk.uniorder.dao.entity.operationCenter.OperationCenterPayment">
    update tb_operation_center_payment
    <set>
      <if test="name != null">
        name = #{name,jdbcType=VARCHAR},
      </if>
      <if test="isCombined != null">
        is_combined = #{isCombined,jdbcType=TINYINT},
      </if>
      <if test="associateType != null">
        associate_type = #{associateType,jdbcType=TINYINT},
      </if>
      <if test="enabled != null">
        enabled = #{enabled,jdbcType=TINYINT},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="createUserId != null">
        create_user_id = #{createUserId,jdbcType=BIGINT},
      </if>
      <if test="updateTime != null">
        update_time = #{updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateUserId != null">
        update_user_id = #{updateUserId,jdbcType=BIGINT},
      </if>
      <if test="deleted != null">
        deleted = #{deleted,jdbcType=TINYINT},
      </if>
    </set>
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="cn.superdesk.uniorder.dao.entity.operationCenter.OperationCenterPayment">
    update tb_operation_center_payment
    set name = #{name,jdbcType=VARCHAR},
      is_combined = #{isCombined,jdbcType=TINYINT},
      associate_type = #{associateType,jdbcType=TINYINT},
      enabled = #{enabled,jdbcType=TINYINT},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      create_user_id = #{createUserId,jdbcType=BIGINT},
      update_time = #{updateTime,jdbcType=TIMESTAMP},
      update_user_id = #{updateUserId,jdbcType=BIGINT},
      deleted = #{deleted,jdbcType=TINYINT}
    where id = #{id,jdbcType=BIGINT}
  </update>

  <resultMap id="PaymentMap" type="cn.superdesk.uniorder.dto.vo.operationCenter.payment.OperationCenterPaymentVo">
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="name" jdbcType="VARCHAR" property="payName" />
    <result column="associate_type" jdbcType="TINYINT" property="associateType" />
    <result column="is_combined" jdbcType="TINYINT" property="isCombined" />
    <result column="enabled" jdbcType="TINYINT" property="enabled" />
    <result column="createName" jdbcType="VARCHAR" property="createUserName" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="updateName" jdbcType="VARCHAR" property="updateUserName" />
    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />

    <collection property="operationCenterPaymentBizVoList"
                ofType="cn.superdesk.uniorder.dto.vo.operationCenter.payment.OperationCenterPaymentBizVo">
      <id column="id" property="id"/>
      <result column="biz_platform_name" property="bizPlatformName"/>
      <result column="biz_pay_type_name" property="bizPayTypeName"/>
    </collection>
  </resultMap>
  <select id="getOperationCenterPaymentList" parameterType="cn.superdesk.uniorder.dto.param.operationCenter.payment.OperationCenterPayParam"
         resultMap="PaymentMap" >
    SELECT
      t.id,t.`name`,t.associate_type,t.is_combined,
      t.enabled,t2.fullname createName,t.create_time,
      t3.fullname updateName,t.update_time,
      t1.biz_platform_name,t1.biz_pay_type_name
    FROM tb_operation_center_payment t
           LEFT JOIN
         tb_operation_center_payment_biz t1
         ON
           t.id = t1.payment_id
           LEFT JOIN
         sys_user t2
         ON
           t.create_user_id = t2.id
           LEFT JOIN
         sys_user t3
         on t.update_user_id =t3.id

    <if test="customerId != null and customerId !='' ">
      LEFT JOIN
      unified_payment_customer t4
      on t4.payment_id = t.id
    </if>

    where t.deleted = 0
    <if test="customerId != null and customerId !='' ">
      and ( t4.customer_id = #{customerId} or t.associate_type = 2 )
    </if>
    <if test="enabled != null and enabled !='' ">
      and t.enabled = #{enabled}
    </if>
    <if test="payName != null and payName !='' ">
      and t.Name like concat('%',#{payName},'%')
    </if>
  </select>
  <select id="getPaymentByConditions"
          resultMap="BaseResultMap">
    select *
    from
      tb_operation_center_payment t
     where t.deleted=0
    <if test="payName !=null and payName !=''">
      and  t.NAME=#{payName}
    </if>
    <if test="notContain !=null and notContain !=''">
     and   t.id !=#{notContain}
    </if>
    limit 1

  </select>

  <resultMap id="PaymentCustomerMap" type="cn.superdesk.uniorder.dto.param.operationCenter.operators.OperationCenterPaymentCustomerParam">
    <id column="id" jdbcType="BIGINT" property="paymentId" />
    <result column="name" jdbcType="VARCHAR" property="paymentName" />
    <result column="associate_type" jdbcType="TINYINT" property="associateType" />


    <collection property="operationCenterPaymentCustomerVos"
                ofType="cn.superdesk.uniorder.dto.vo.operationCenter.customer.OperationCenterPaymentCustomerVo">
      <id column="customerId" property="id"/>
      <result column="customer_name" property="customerName"/>
      <result column="customer_sn" property="customerSn"/>
      <result column="status" property="status"/>
      <result column="deleted" property="deleted"/>
    </collection>
  </resultMap>
  <select id="linkCustomerByPaymentId"
          resultMap="PaymentCustomerMap">
    SELECT
    t1.id,
    t1.`name`,
    t1.associate_type,
    t3.id customerId,
    t3.customer_name,
    t3.customer_sn,
    t3.`status`,
    t3.deleted
    FROM
    tb_operation_center_payment t1
    INNER JOIN
    unified_payment_customer t2
    ON
    t1.id=t2.payment_id
    INNER JOIN
    unified_center_customer t3
    ON
    t2.customer_id = t3.id
    where 1=1
    <if test="paymentId !=null and paymentId !=''">
      and t1.id=#{paymentId}
    </if>


  </select>



</mapper>