<?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.sv.mapper.PayConfigMapper">

    <resultMap id="PayConfigMap" type="com.sv.entity.PayConfig">
		<id column="id" property="id" jdbcType="INTEGER"/>
		<result column="appId" property="appId"  jdbcType="VARCHAR" />
		<result column="key" property="key"  jdbcType="VARCHAR" />
		<result column="mchId" property="mchId"  jdbcType="VARCHAR" />
		<result column="notifyUrl" property="notifyUrl"  jdbcType="VARCHAR" />
		<result column="cancel" property="cancel"  jdbcType="VARCHAR" />
		<result column="platform_id" property="platformId"  jdbcType="INTEGER" />
		<result column="deleted" property="deleted"  jdbcType="TINYINT" />
		<result column="created_time" property="createdTime"  jdbcType="TIMESTAMP" />
		<result column="cert" property="cert"  jdbcType="VARCHAR" />
		<result column="name" property="name"  jdbcType="VARCHAR" />
    </resultMap>

    <resultMap id="PayConfigDtoMap" type="com.sv.dto.api.PayConfigDTO">
		<id column="id" property="id" jdbcType="INTEGER"/>
		<result column="appId" property="appId" jdbcType="VARCHAR" />
		<result column="key" property="key" jdbcType="VARCHAR" />
		<result column="mchId" property="mchId" jdbcType="VARCHAR" />
		<result column="notifyUrl" property="notifyUrl" jdbcType="VARCHAR" />
		<result column="cancel" property="cancel"  jdbcType="VARCHAR" />
		<result column="platform_id" property="platformId" jdbcType="INTEGER" />
		<result column="deleted" property="deleted" jdbcType="TINYINT" />
		<result column="created_time" property="createdTime" jdbcType="TIMESTAMP" />
		<result column="cert" property="cert" jdbcType="VARCHAR" />
		<result column="name" property="name" jdbcType="VARCHAR" />
    </resultMap>
	
	<!--表名 -->
	<sql id="tableName">
		sv_pay_config
	</sql>
	
	<!-- 字段 -->
	<sql id="Field">
		id,
		appId,
		`key`,
		mchId,
		notifyUrl,
		cancel,
		platform_id,
		deleted,
		created_time,
		cert,
		name
	</sql>
	
	<!-- 字段值 -->
	<sql id="FieldValue">
		#{id, jdbcType=INTEGER},
		#{appId, jdbcType=VARCHAR},
		#{key, jdbcType=VARCHAR},
		#{mchId, jdbcType=VARCHAR},
		#{notifyUrl, jdbcType=VARCHAR},
		#{cancel, jdbcType=VARCHAR},
		#{platformId, jdbcType=INTEGER},
		#{deleted, jdbcType=TINYINT},
		#{createdTime, jdbcType=TIMESTAMP},
		#{cert, jdbcType=VARCHAR},
		#{name, jdbcType=VARCHAR}
	</sql>

	<!-- 查询全部记录 -->
    <select id="findAll" resultMap="PayConfigMap">
        SELECT
        	<include refid="Field"></include>
        FROM
        	<include refid="tableName"></include>
		WHERE
			deleted = 0
    </select>
	
	<!-- 新增-->
	<insert id="insert" parameterType="com.sv.entity.PayConfig" useGeneratedKeys="true" keyProperty="id">
        INSERT INTO
			<include refid="tableName"></include>
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">
				id,
            </if>
            <if test="appId != null">
				appId,
            </if>
            <if test="key != null">
				key,
            </if>
            <if test="mchId != null">
				mchId,
            </if>
            <if test="notifyUrl != null">
				notifyUrl,
            </if>
            <if test="cancel != null">
				cancel,
            </if>
            <if test="platformId != null">
				platform_id,
            </if>
            <if test="deleted != null">
				deleted,
            </if>
            <if test="createdTime != null">
				created_time,
            </if>
            <if test="cert != null">
				cert,
            </if>
            <if test="name != null">
				name,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">
				#{id},
            </if>
            <if test="appId != null">
				#{appId},
            </if>
            <if test="key != null">
				#{key},
            </if>
            <if test="mchId != null">
				#{mchId},
            </if>
            <if test="notifyUrl != null">
				#{notifyUrl},
            </if>
            <if test="cancel != null">
				#{cancel},
            </if>
            <if test="platformId != null">
				#{platformId},
            </if>
            <if test="deleted != null">
				#{deleted},
            </if>
            <if test="createdTime != null">
				#{createdTime},
            </if>
            <if test="cert != null">
				#{cert},
            </if>
            <if test="name != null">
				#{name},
            </if>
        </trim>
	</insert>
	
	<!-- 删除-->
	<delete id="delete" parameterType="java.lang.Integer">
		UPDATE
			<include refid="tableName"></include>
		SET
			deleted = 1
		WHERE
			id = #{id}
	</delete>

    <!-- 批量删除 -->
    <delete id="deleteByIds">
        UPDATE
        	<include refid="tableName"></include>
		SET
			deleted = 1
        WHERE
			id IN
			<foreach item="item" index="index" collection="array" open="(" separator="," close=")">
				#{item}
			</foreach>
    </delete>
	
	<!-- 更新记录 -->
	<update id="update" parameterType="com.sv.entity.PayConfig">
		UPDATE
			<include refid="tableName"></include>
        <set>
			<if test="appId != null">
				appId = #{appId},
			</if>
			<if test="key != null">
				key = #{key},
			</if>
			<if test="mchId != null">
				mchId = #{mchId},
			</if>
			<if test="notifyUrl != null">
				notifyUrl = #{notifyUrl},
			</if>
			<if test="cancel != null">
				cancel = #{cancel},
			</if>
			<if test="platformId != null">
				platform_id = #{platformId},
			</if>
			<if test="deleted != null">
				deleted = #{deleted},
			</if>
			<if test="createdTime != null">
				created_time = #{createdTime},
			</if>
			<if test="cert != null">
				cert = #{cert},
			</if>
			<if test="name != null">
				name = #{name},
			</if>
        </set>
        WHERE id = #{id}
	</update>
	
	<!-- 通过编号查询 -->
	<select id="findById" parameterType="java.lang.Integer" resultMap="PayConfigMap">
		SELECT
			<include refid="Field"></include>
		FROM
			<include refid="tableName"></include>
		WHERE id = #{id}
	</select>

	<!-- api -->
	<select id="findKey" parameterType="java.lang.String" resultMap="PayConfigMap">
		SELECT
		<include refid="Field"></include>
		FROM
		<include refid="tableName"></include>
		WHERE name = #{name}
		and deleted = 0
	</select>
</mapper>