<?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.shzg.project.worn.mapper.WornMaterialUnitMapper">

    <resultMap id="WornMaterialUnitResult" type="com.shzg.project.worn.domain.WornMaterialUnit">
        <id property="id" column="id"/>

        <result property="unitName" column="unit_name"/>
        <result property="description" column="description"/>
        <result property="orderNum" column="order_num"/>
        <result property="status" column="status"/>
        <result property="isDelete" column="is_delete"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>


    <sql id="selectWornMaterialUnitVo">
        SELECT
            id,
            unit_name,
            description,
            order_num,
            status,
            is_delete,
            create_by,
            create_time,
            update_by,
            update_time
        FROM worn_material_unit
    </sql>


    <select id="selectWornMaterialUnitList"
            parameterType="com.shzg.project.worn.domain.WornMaterialUnit"
            resultMap="WornMaterialUnitResult">

        <include refid="selectWornMaterialUnitVo"/>

        <where>

            <if test="unitName != null and unitName != ''">
                AND unit_name LIKE CONCAT('%',#{unitName},'%')
            </if>

            <if test="description != null and description != ''">
                AND description = #{description}
            </if>

            <if test="orderNum != null">
                AND order_num = #{orderNum}
            </if>

            <if test="status != null and status != ''">
                AND status = #{status}
            </if>

            <if test="isDelete != null and isDelete != ''">
                AND is_delete = #{isDelete}
            </if>

        </where>

    </select>


    <select id="selectWornMaterialUnitById"
            parameterType="Long"
            resultMap="WornMaterialUnitResult">

        <include refid="selectWornMaterialUnitVo"/>

        WHERE id = #{id}

    </select>


    <insert id="insertWornMaterialUnit"
            parameterType="com.shzg.project.worn.domain.WornMaterialUnit"
            useGeneratedKeys="true"
            keyProperty="id">

        INSERT INTO worn_material_unit

        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="unitName != null and unitName != ''">unit_name,</if>
            <if test="description != null">description,</if>
            <if test="orderNum != null">order_num,</if>
            <if test="status != null">status,</if>
            <if test="isDelete != null">is_delete,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
        </trim>

        <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
            <if test="unitName != null and unitName != ''">#{unitName},</if>
            <if test="description != null">#{description},</if>
            <if test="orderNum != null">#{orderNum},</if>
            <if test="status != null">#{status},</if>
            <if test="isDelete != null">#{isDelete},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
        </trim>

    </insert>


    <update id="updateWornMaterialUnit"
            parameterType="com.shzg.project.worn.domain.WornMaterialUnit">

        UPDATE worn_material_unit

        <trim prefix="SET" suffixOverrides=",">
            <if test="unitName != null and unitName != ''">unit_name = #{unitName},</if>
            <if test="description != null">description = #{description},</if>
            <if test="orderNum != null">order_num = #{orderNum},</if>
            <if test="status != null">status = #{status},</if>
            <if test="isDelete != null">is_delete = #{isDelete},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>

        WHERE id = #{id}

    </update>


    <delete id="deleteWornMaterialUnitById" parameterType="Long">
        DELETE FROM worn_material_unit
        WHERE id = #{id}
    </delete>


    <delete id="deleteWornMaterialUnitByIds" parameterType="String">
        DELETE FROM worn_material_unit
        WHERE id IN
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

</mapper>