<?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.zg.project.information.mapper.StockOutTypeMapper">

    <resultMap type="StockOutType" id="StockOutTypeResult">
        <result property="id"           column="id"/>
        <result property="typeName"     column="type_name"/>
        <result property="typeCode"     column="type_code"/>
        <result property="createdBy"    column="created_by"/>
        <result property="createdAt"    column="created_at"/>
        <result property="updatedBy"    column="updated_by"/>
        <result property="updatedAt"    column="updated_at"/>
        <result property="isDelete"     column="is_delete"/>
    </resultMap>

    <sql id="selectStockOutTypeVo">
        select id, type_name, type_code, created_by, created_at, updated_by, updated_at, is_delete
        from stock_out_type
    </sql>

    <select id="selectStockOutTypeList" parameterType="StockOutType" resultMap="StockOutTypeResult">
        <include refid="selectStockOutTypeVo"/>
        <where>
            <if test="typeName != null and typeName != ''">
                and type_name like concat('%', #{typeName}, '%')
            </if>
            <if test="typeCode != null and typeCode != ''">
                and type_code = #{typeCode}
            </if>
            <if test="createdBy != null and createdBy != ''">
                and created_by = #{createdBy}
            </if>
            <if test="createdAt != null">
                and created_at = #{createdAt}
            </if>
            <if test="updatedBy != null and updatedBy != ''">
                and updated_by = #{updatedBy}
            </if>
            <if test="updatedAt != null">
                and updated_at = #{updatedAt}
            </if>
            <if test="isDelete != null and isDelete != ''">
                and is_delete = #{isDelete}
            </if>
        </where>
    </select>

    <select id="selectStockOutTypeById" parameterType="Long" resultMap="StockOutTypeResult">
        <include refid="selectStockOutTypeVo"/>
        where id = #{id}
    </select>

    <insert id="insertStockOutType" parameterType="StockOutType" useGeneratedKeys="true" keyProperty="id">
        insert into stock_out_type
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="typeName != null and typeName != ''">type_name,</if>
            <if test="typeCode != null and typeCode != ''">type_code,</if>
            <if test="createdBy != null">created_by,</if>
            <if test="createdAt != null">created_at,</if>
            <if test="updatedBy != null">updated_by,</if>
            <if test="updatedAt != null">updated_at,</if>
            <if test="isDelete != null">is_delete,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="typeName != null and typeName != ''">#{typeName},</if>
            <if test="typeCode != null and typeCode != ''">#{typeCode},</if>
            <if test="createdBy != null">#{createdBy},</if>
            <if test="createdAt != null">#{createdAt},</if>
            <if test="updatedBy != null">#{updatedBy},</if>
            <if test="updatedAt != null">#{updatedAt},</if>
            <if test="isDelete != null">#{isDelete},</if>
        </trim>
    </insert>

    <update id="updateStockOutType" parameterType="StockOutType">
        update stock_out_type
        <trim prefix="SET" suffixOverrides=",">
            <if test="typeName != null and typeName != ''">type_name = #{typeName},</if>
            <if test="typeCode != null and typeCode != ''">type_code = #{typeCode},</if>
            <if test="createdBy != null">created_by = #{createdBy},</if>
            <if test="createdAt != null">created_at = #{createdAt},</if>
            <if test="updatedBy != null">updated_by = #{updatedBy},</if>
            <if test="updatedAt != null">updated_at = #{updatedAt},</if>
            <if test="isDelete != null">is_delete = #{isDelete},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteStockOutTypeById" parameterType="Long">
        delete from stock_out_type where id = #{id}
    </delete>

    <delete id="deleteStockOutTypeByIds" parameterType="String">
        delete from stock_out_type where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>
