<?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.ruoyi.clMaterial.mapper.CYlMaterialMapper">

    <resultMap type="CYlMaterial" id="CYlMaterialResult">
        <result property="materialId"    column="material_id"    />
        <result property="materialNo"    column="material_no"    />
        <result property="materialName"    column="material_name"    />
        <result property="materialPrice"    column="material_price"    />
    </resultMap>

    <sql id="selectCYlMaterialVo">
        select material_id, material_no, material_name, material_price from c_yl_material
    </sql>

    <select id="selectCYlMaterialList" parameterType="CYlMaterial" resultMap="CYlMaterialResult">
        <include refid="selectCYlMaterialVo"/>
        <where>
            <if test="materialNo != null  and materialNo != ''"> and material_no = #{materialNo}</if>
            <if test="materialName != null  and materialName != ''"> and material_name like concat('%', #{materialName}, '%')</if>
        </where>
    </select>

    <select id="selectCYlMaterialByMaterialId" parameterType="Long" resultMap="CYlMaterialResult">
        <include refid="selectCYlMaterialVo"/>
        where material_id = #{materialId}
    </select>

    <insert id="insertCYlMaterial" parameterType="CYlMaterial" useGeneratedKeys="true" keyProperty="materialId">
        insert into c_yl_material
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="materialNo != null and materialNo != ''">material_no,</if>
            <if test="materialName != null and materialName != ''">material_name,</if>
            <if test="materialPrice != null">material_price,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="materialNo != null and materialNo != ''">#{materialNo},</if>
            <if test="materialName != null and materialName != ''">#{materialName},</if>
            <if test="materialPrice != null">#{materialPrice},</if>
         </trim>
    </insert>

    <update id="updateCYlMaterial" parameterType="CYlMaterial">
        update c_yl_material
        <trim prefix="SET" suffixOverrides=",">
            <if test="materialNo != null and materialNo != ''">material_no = #{materialNo},</if>
            <if test="materialName != null and materialName != ''">material_name = #{materialName},</if>
            <if test="materialPrice != null">material_price = #{materialPrice},</if>
        </trim>
        where material_id = #{materialId}
    </update>

    <delete id="deleteCYlMaterialByMaterialId" parameterType="Long">
        delete from c_yl_material where material_id = #{materialId}
    </delete>

    <delete id="deleteCYlMaterialByMaterialIds" parameterType="String">
        delete from c_yl_material where material_id in
        <foreach item="materialId" collection="array" open="(" separator="," close=")">
            #{materialId}
        </foreach>
    </delete>

    <select id="checkMaterialNoUnique" parameterType="String" resultMap="CYlMaterialResult">
        select top(1) material_id, material_no from c_yl_material where material_no = #{materialNo}
    </select>

</mapper>
