<?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.younike.system.mapper.PersonalMerchantSettleMapper">
  <resultMap id="PersonalMerchantSettleResult" type="com.younike.system.domain.PersonalMerchantSettle">
    <id column="personal_merchant_settle_id" property="personalMerchantSettleId" />
    <result column="year_month" property="yearMonth" />
    <result column="merchant_id" property="merchantId" />
    <result column="merchant_index" property="merchantIndex" />
    <result column="merchant_name" property="merchantName" />
    <result column="actual_income" property="actualIncome" />
    <result column="settle_status" property="settleStatus" />
    <result column="del_flag" property="delFlag" />
    <result column="create_by" property="createBy" />
    <result column="create_time" property="createTime" />
    <result column="update_by" property="updateBy" />
    <result column="update_time" property="updateTime" />
    <result column="remark" property="remark" />
  </resultMap>

  <sql id="Base_Column_List">
    select personal_merchant_settle_id, `year_month`, merchant_id, merchant_index, merchant_name, actual_income, settle_status, del_flag, create_by, create_time, update_by, update_time, remark from personal_merchant_settle
  </sql>

  <select id="selectPersonalMerchantSettleList" parameterType="com.younike.system.domain.PersonalMerchantSettle" resultMap="PersonalMerchantSettleResult">
    <include refid="Base_Column_List"/>
    <where>
      del_flag = '0'
      <if test="merchantId != null"> and merchant_id = #{merchantId}</if>
      <if test="merchantIndex != null  and merchantIndex != ''"> and merchant_index like concat('%', #{merchantIndex}, '%')</if>
      <if test="merchantName != null  and merchantName != ''"> and merchant_name like concat('%', #{merchantName}, '%')</if>
      <if test="settleStatus != null  and settleStatus != ''"> and settle_status = #{settleStatus}</if>
    </where>
  </select>

  <insert id="insertPersonalMerchantSettle" parameterType="com.younike.system.domain.PersonalMerchantSettle" useGeneratedKeys="true" keyProperty="personalMerchantSettleId">
    insert into personal_merchant_settle
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="yearMonth != null and yearMonth != ''">year_month,</if>
      <if test="merchantId != null">merchant_id,</if>
      <if test="merchantIndex != null and merchantIndex != ''">merchant_index,</if>
      <if test="merchantName != null and merchantName != ''">merchant_name,</if>
      <if test="actualIncome != null">actual_income,</if>
      <if test="settleStatus != null and settleStatus != ''">settle_status,</if>
      <if test="delFlag != null">del_flag,</if>
      <if test="createBy != null">create_by,</if>
      <if test="createTime != null">create_time,</if>
      <if test="updateBy != null">update_by,</if>
      <if test="updateTime != null">update_time,</if>
      <if test="remark != null and remark != ''">remark,</if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="yearMonth != null and yearMonth != ''">#{yearMonth},</if>
      <if test="merchantId != null">#{merchantId},</if>
      <if test="merchantIndex != null and merchantIndex != ''">#{merchantIndex},</if>
      <if test="merchantName != null and merchantName != ''">#{merchantName},</if>
      <if test="actualIncome != null">#{actualIncome},</if>
      <if test="settleStatus != null and settleStatus != ''">#{settleStatus},</if>
      <if test="delFlag != null">#{delFlag},</if>
      <if test="createBy != null">#{createBy},</if>
      <if test="createTime != null">#{createTime},</if>
      <if test="updateBy != null">#{updateBy},</if>
      <if test="updateTime != null">#{updateTime},</if>
      <if test="remark != null and remark != ''">#{remark},</if>
    </trim>
  </insert>

  <update id="updatePersonalMerchantSettle" parameterType="com.younike.system.domain.PersonalMerchantSettle">
    update personal_merchant_settle
    <trim prefix="SET" suffixOverrides=",">
      <if test="yearMonth != null and yearMonth != ''">`year_month` = #{yearMonth},</if>
      <if test="merchantId != null">merchant_id = #{merchantId},</if>
      <if test="merchantIndex != null and merchantIndex != ''">merchant_index = #{merchantIndex},</if>
      <if test="merchantName != null and merchantName != ''">merchant_name = #{merchantName},</if>
      <if test="actualIncome != null">actual_income = #{actualIncome},</if>
      <if test="settleStatus != null and settleStatus != ''">settle_status = #{settleStatus},</if>
      <if test="delFlag != null">del_flag = #{delFlag},</if>
      <if test="createBy != null">create_by = #{createBy},</if>
      <if test="createTime != null">create_time = #{createTime},</if>
      <if test="updateBy != null">update_by = #{updateBy},</if>
      <if test="updateTime != null">update_time = #{updateTime},</if>
      <if test="remark != null and remark != ''">remark = #{remark},</if>
    </trim>
    where personal_merchant_settle_id = #{personalMerchantSettleId}
  </update>

  <delete id="deleteByPersonalMerchantSettleId" parameterType="Long">
    delete from personal_merchant_settle where personal_merchant_settle_id = #{personalMerchantSettleId}
  </delete>

</mapper>