<?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.microservices.pms.productLibrary.mapper.PmsProductlibJyrldLibMapper">

    <resultMap type="com.microservices.pms.productLibrary.domain.PmsProductlibJyrldLib" id="PmsProductlibJyrldLibMap">
        <result property="id" column="id" jdbcType="INTEGER"/>
        <result property="name" column="name" jdbcType="VARCHAR"/>
        <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
        <result property="updateBy" column="update_by" jdbcType="VARCHAR"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
        <result property="createBy" column="create_by" jdbcType="VARCHAR"/>
        <result property="delFlag" column="del_flag" jdbcType="VARCHAR"/>
    </resultMap>

    <!--查询单个-->
    <select id="queryById" resultMap="PmsProductlibJyrldLibMap">
        select id,
               name,
               update_time,
               update_by,
               create_time,
               create_by,
               del_flag
        from pms_productlib_jyrld_lib
        where id = #{id}
    </select>

    <!--查询单个-->
    <select id="queryByName" resultMap="PmsProductlibJyrldLibMap">
        select id,
               name,
               update_time,
               update_by,
               create_time,
               create_by,
               del_flag
        from pms_productlib_jyrld_lib
        where name = #{name}
        limit 1
    </select>

    <!--查询指定行数据-->
    <select id="queryAllByLimit" resultMap="PmsProductlibJyrldLibMap">
        select
        id, name, update_time, update_by, create_time, create_by, del_flag
        from pms_productlib_jyrld_lib
        <where>
            <if test="id != null">
                and id = #{id}
            </if>
            <if test="name != null and name != ''">
                and name = #{name}
            </if>
            <if test="updateTime != null">
                and update_time = #{updateTime}
            </if>
            <if test="updateBy != null and updateBy != ''">
                and update_by = #{updateBy}
            </if>
            <if test="createTime != null">
                and create_time = #{createTime}
            </if>
            <if test="createBy != null and createBy != ''">
                and create_by = #{createBy}
            </if>
            <if test="delFlag != null and delFlag != ''">
                and del_flag = #{delFlag}
            </if>
        </where>
        limit #{pageable.offset}, #{pageable.pageSize}
    </select>

    <!--统计总行数-->
    <select id="count" resultType="java.lang.Long">
        select count(1)
        from pms_productlib_jyrld_lib
        <where>
            <if test="id != null">
                and id = #{id}
            </if>
            <if test="name != null and name != ''">
                and name = #{name}
            </if>
            <if test="updateTime != null">
                and update_time = #{updateTime}
            </if>
            <if test="updateBy != null and updateBy != ''">
                and update_by = #{updateBy}
            </if>
            <if test="createTime != null">
                and create_time = #{createTime}
            </if>
            <if test="createBy != null and createBy != ''">
                and create_by = #{createBy}
            </if>
            <if test="delFlag != null and delFlag != ''">
                and del_flag = #{delFlag}
            </if>
        </where>
    </select>

    <!--新增所有列-->
    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
        insert into pms_productlib_jyrld_lib(name, update_time, update_by, create_time, create_by, del_flag)
        values (#{name}, #{updateTime}, #{updateBy}, #{createTime}, #{createBy}, #{delFlag})
    </insert>

    <insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
        insert into pms_productlib_jyrld_lib(name, update_time, update_by, create_time, create_by, del_flag)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.name}, #{entity.updateTime}, #{entity.updateBy}, #{entity.createTime}, #{entity.createBy},
            #{entity.delFlag})
        </foreach>
    </insert>

    <insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
        insert into pms_productlib_jyrld_lib(name, update_time, update_by, create_time, create_by, del_flag)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.name}, #{entity.updateTime}, #{entity.updateBy}, #{entity.createTime}, #{entity.createBy},
            #{entity.delFlag})
        </foreach>
        on duplicate key update
        name = values(name),
        update_time = values(update_time),
        update_by = values(update_by),
        create_time = values(create_time),
        create_by = values(create_by),
        del_flag = values(del_flag)
    </insert>

    <!--通过主键修改数据-->
    <update id="update">
        update pms_productlib_jyrld_lib
        <set>
            <if test="name != null and name != ''">
                name = #{name},
            </if>
            <if test="updateTime != null">
                update_time = #{updateTime},
            </if>
            <if test="updateBy != null and updateBy != ''">
                update_by = #{updateBy},
            </if>
            <if test="createTime != null">
                create_time = #{createTime},
            </if>
            <if test="createBy != null and createBy != ''">
                create_by = #{createBy},
            </if>
            <if test="delFlag != null and delFlag != ''">
                del_flag = #{delFlag},
            </if>
        </set>
        where id = #{id}
    </update>

    <!--通过主键删除-->
    <delete id="deleteById">
        delete
        from pms_productlib_jyrld_lib
        where id = #{id}
    </delete>

</mapper>

