<?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="ckTypeName"    column="ck_type_name"    />
        <result property="ckTypeCode"    column="ck_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, ck_type_name, ck_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="ckTypeName != null  and ckTypeName != ''"> and ck_type_name like concat('%', #{ckTypeName}, '%')</if>
            <if test="ckTypeCode != null  and ckTypeCode != ''"> and ck_type_code = #{ckTypeCode}</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="ckTypeName != null and ckTypeName != ''">ck_type_name,</if>
            <if test="ckTypeCode != null and ckTypeCode != ''">ck_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="ckTypeName != null and ckTypeName != ''">#{ckTypeName},</if>
            <if test="ckTypeCode != null and ckTypeCode != ''">#{ckTypeCode},</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="ckTypeName != null and ckTypeName != ''">ck_type_name = #{ckTypeName},</if>
            <if test="ckTypeCode != null and ckTypeCode != ''">ck_type_code = #{ckTypeCode},</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>