<?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.kmall.admin.dao.ThirdMerchantBizDao">

    <resultMap type="com.kmall.admin.entity.ThirdMerchantBizEntity" id="thirdMerchantBizMap">
        <result property="thirdMerchSn" column="third_merch_sn"/>
		<result property="merchSn" column="merch_sn"/>
        <result property="thirdPartyMerchCode" column="third_party_merch_code"/>
        <result property="thirdPartyMerchName" column="third_party_merch_name"/>
        <result property="isValid" column="is_valid"/>
        <result property="createrSn" column="creater_sn"/>
        <result property="createTime" column="create_time"/>
        <result property="moderSn" column="moder_sn"/>
        <result property="modTime" column="mod_time"/>
        <result property="tstm" column="tstm"/>
    </resultMap>

	<select id="queryObject" resultType="com.kmall.admin.entity.ThirdMerchantBizEntity">
		select
			`third_merch_sn`,
            `merch_sn`,
			`third_party_merch_code`,
			`third_party_merch_name`,
			`is_valid`,
			`creater_sn`,
			`create_time`,
			`moder_sn`,
			`mod_time`,
			`tstm`
		from third_merchant_biz
		where third_merch_sn = #{id}
	</select>

	<select id="findByMerchSn" resultType="com.kmall.admin.entity.ThirdMerchantBizEntity">
		select
		`third_merch_sn`,
		`merch_sn`,
		`third_party_merch_code`,
		`third_party_merch_name`,
		`is_valid`,
		`creater_sn`,
		`create_time`,
		`moder_sn`,
		`mod_time`,
		`tstm`
		from third_merchant_biz
		where merch_sn = #{value}
	</select>

	<select id="getThirdMerchangByCode" resultType="com.kmall.admin.entity.ThirdMerchantBizEntity">
		select
		`third_merch_sn`,
		`merch_sn`,
		`third_party_merch_code`,
		`third_party_merch_name`,
		`is_valid`,
		`creater_sn`,
		`create_time`,
		`moder_sn`,
		`mod_time`,
		`tstm`
		from third_merchant_biz
		where third_party_merch_code = #{thirdMerchantCode}
	</select>

	<select id="queryList" resultType="com.kmall.admin.entity.ThirdMerchantBizEntity">
		select
    		`third_merch_sn`,
			`merch_sn`,
    		`third_party_merch_code`,
    		`third_party_merch_name`,
    		`is_valid`,
    		`creater_sn`,
    		`create_time`,
    		`moder_sn`,
    		`mod_time`,
    		`tstm`
		from third_merchant_biz
		WHERE 1=1
		<if test="name != null and name.trim() != ''">
			AND name LIKE concat('%',#{name},'%')
		</if>
		<if test="merchSn != null and merchSn.trim() != ''">
			and merch_sn = #{merchSn}
		</if>
		<if test="thirdPartyMerchCode != null and thirdPartyMerchCode.trim() != ''">
			and third_party_merch_code = #{thirdPartyMerchCode}
		</if>
        <choose>
            <when test="sidx != null and sidx.trim() != ''">
                order by ${sidx} ${order}
            </when>
			<otherwise>
                order by third_merch_sn desc
			</otherwise>
        </choose>
		<if test="offset != null and limit != null">
			limit #{offset}, #{limit}
		</if>
	</select>
	
 	<select id="queryTotal" resultType="int">
		select count(*) from third_merchant_biz
		WHERE 1=1
        <if test="name != null and name.trim() != ''">
            AND name LIKE concat('%',#{name},'%')
        </if>
		<if test="merchSn != null and merchSn.trim() != ''">
			and merch_sn = #{merchSn}
		</if>
		<if test="thirdPartyMerchCode != null and thirdPartyMerchCode.trim() != ''">
			and third_party_merch_code = #{thirdPartyMerchCode}
		</if>
	</select>
	 
	<insert id="save" parameterType="com.kmall.admin.entity.ThirdMerchantBizEntity" useGeneratedKeys="true" keyProperty="thirdMerchSn">
		insert into third_merchant_biz(
			`merch_sn`,
			`third_party_merch_code`,
			`third_party_merch_name`,
			`is_valid`,
			`creater_sn`,
			`create_time`,
			`moder_sn`,
			`mod_time`,
			`tstm`)
		values(
			#{merchSn},
			#{thirdPartyMerchCode},
			#{thirdPartyMerchName},
			#{isValid},
			#{createrSn},
			#{createTime},
			#{moderSn},
			#{modTime},
			#{tstm})
	</insert>
	 
	<update id="update" parameterType="com.kmall.admin.entity.ThirdMerchantBizEntity">
		update third_merchant_biz 
		<set>
			<if test="merchSn != null">`merch_sn` = #{merchSn},</if>
			<if test="thirdPartyMerchCode != null">`third_party_merch_code` = #{thirdPartyMerchCode}, </if>
			<if test="thirdPartyMerchName != null">`third_party_merch_name` = #{thirdPartyMerchName}, </if>
			<if test="isValid != null">`is_valid` = #{isValid}, </if>
			<if test="createrSn != null">`creater_sn` = #{createrSn}, </if>
			<if test="createTime != null">`create_time` = #{createTime}, </if>
			<if test="moderSn != null">`moder_sn` = #{moderSn}, </if>
			<if test="modTime != null">`mod_time` = #{modTime}, </if>
			<if test="tstm != null">`tstm` = #{tstm}</if>
		</set>
		where third_merch_sn = #{thirdMerchSn}
	</update>
	
	<delete id="delete">
		delete from third_merchant_biz where third_merch_sn = #{value}
	</delete>
	
	<delete id="deleteBatch">
		delete from third_merchant_biz where third_merch_sn in 
		<foreach item="thirdMerchSn" collection="array" open="(" separator="," close=")">
			#{thirdMerchSn}
		</foreach>
	</delete>

</mapper>