<?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.yinlihupo.enlish.service.domain.mapper.UnitDOMapper">
    <resultMap id="BaseResultMap" type="com.yinlihupo.enlish.service.domain.dataobject.UnitDO">
        <id column="id" jdbcType="INTEGER" property="id" />
        <result column="title" jdbcType="VARCHAR" property="title" />
        <result column="version" jdbcType="VARCHAR" property="version" />
        <result column="create_at" jdbcType="TIMESTAMP" property="createAt" />
    </resultMap>

    <sql id="Base_Column_List">
        id, title, version, create_at
    </sql>

    <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from unit
        where id = #{id,jdbcType=INTEGER}
    </select>

    <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
        delete from unit
        where id = #{id,jdbcType=INTEGER}
    </delete>

    <insert id="insert" parameterType="com.yinlihupo.enlish.service.domain.dataobject.UnitDO" useGeneratedKeys="true" keyProperty="id">
        insert into unit (title, version, create_at)
        values (#{title,jdbcType=VARCHAR}, #{version,jdbcType=VARCHAR}, #{createAt,jdbcType=TIMESTAMP})
    </insert>

    <insert id="insertSelective" parameterType="com.yinlihupo.enlish.service.domain.dataobject.UnitDO" useGeneratedKeys="true" keyProperty="id">
        insert into unit
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">
                id,
            </if>
            <if test="title != null">
                title,
            </if>
            <if test="version != null">
                version,
            </if>
            <if test="createAt != null">
                create_at,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">
                #{id,jdbcType=INTEGER},
            </if>
            <if test="title != null">
                #{title,jdbcType=VARCHAR},
            </if>
            <if test="version != null">
                #{version,jdbcType=VARCHAR},
            </if>
            <if test="createAt != null">
                #{createAt,jdbcType=TIMESTAMP},
            </if>
        </trim>
    </insert>

    <update id="updateByPrimaryKeySelective" parameterType="com.yinlihupo.enlish.service.domain.dataobject.UnitDO">
        update unit
        <set>
            <if test="title != null">
                title = #{title,jdbcType=VARCHAR},
            </if>
            <if test="version != null">
                version = #{version,jdbcType=VARCHAR},
            </if>
            <if test="createAt != null">
                create_at = #{createAt,jdbcType=TIMESTAMP},
            </if>
        </set>
        where id = #{id,jdbcType=INTEGER}
    </update>

    <update id="updateByPrimaryKey" parameterType="com.yinlihupo.enlish.service.domain.dataobject.UnitDO">
        update unit
        set title = #{title,jdbcType=VARCHAR},
            version = #{version,jdbcType=VARCHAR},
            create_at = #{createAt,jdbcType=TIMESTAMP}
        where id = #{id,jdbcType=INTEGER}
    </update>

    <select id="selectByTitle" resultMap="BaseResultMap">
        select *
        from unit
        where title = #{title}
    </select>

    <select id="selectUnitDOList" resultMap="BaseResultMap">
        select *
        from unit
        limit #{startIndex}, #{pageSize}
    </select>

    <select id="selectUnitDOListCount" resultType="java.lang.Integer">
        select count(*)
        from unit
    </select>
    <select id="selectByUnitName" resultType="com.yinlihupo.enlish.service.domain.dataobject.UnitDO">
        select *
        from unit
        where title like concat(#{unitName}, '%')
    </select>

</mapper>