<?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.baseinfo.mapper.BaseMaterialInfoMapper">

    <resultMap type="BaseMaterialInfo" id="BaseMaterialInfoResult">
        <result property="objid"    column="objid"    />
        <result property="materialId"    column="material_id"    />
        <result property="materialName"    column="material_name"    />
        <result property="materialCode"    column="material_code"    />
        <result property="materialTypeId"    column="material_type_id"    />
        <result property="status"    column="status"    />
        <result property="remark"    column="remark"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="materialTypeName"    column="material_type_name"    />
    </resultMap>

    <sql id="selectBaseMaterialInfoVo">
        select objid, material_id, material_name, material_code, material_type_id, status, remark, create_by, create_time, update_by, update_time, del_flag from base_material_info
    </sql>

    <select id="selectBaseMaterialInfoList" parameterType="BaseMaterialInfo" resultMap="BaseMaterialInfoResult">
        select t1.objid, t1.material_id, t1.material_name, t1.material_code, t1.material_type_id,t2.material_type_name, t1.status, t1.remark, t1.create_by, t1.create_time, t1.update_by, t1.update_time, t1.del_flag from base_material_info t1
        left join base_materialtype_info t2 on t1.material_type_id = t2.material_type_id
        <where>
            <if test="materialId != null  and materialId != ''"> and t1.material_id = #{materialId}</if>
            <if test="materialName != null  and materialName != ''"> and t1.material_name like ('%' + #{materialName} + '%')</if>
            <if test="materialCode != null  and materialCode != ''"> and t1.material_code = #{materialCode}</if>
            <if test="materialTypeId != null  and materialTypeId != ''"> and t1.material_type_id = #{materialTypeId}</if>
            <if test="status != null  and status != ''"> and t1.status = #{status}</if>
        </where>
    </select>

    <select id="selectBaseMaterialInfoById" parameterType="Long" resultMap="BaseMaterialInfoResult">
        <include refid="selectBaseMaterialInfoVo"/>
        where objid = #{objid}
    </select>

    <insert id="insertBaseMaterialInfo" parameterType="BaseMaterialInfo">
        insert into base_material_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="objid != null">objid,</if>
            <if test="materialId != null">material_id,</if>
            <if test="materialName != null">material_name,</if>
            <if test="materialCode != null">material_code,</if>
            <if test="materialTypeId != null">material_type_id,</if>
            <if test="status != null">status,</if>
            <if test="remark != null">remark,</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>
            <if test="delFlag != null">del_flag,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="objid != null">#{objid},</if>
            <if test="materialId != null">#{materialId},</if>
            <if test="materialName != null">#{materialName},</if>
            <if test="materialCode != null">#{materialCode},</if>
            <if test="materialTypeId != null">#{materialTypeId},</if>
            <if test="status != null">#{status},</if>
            <if test="remark != null">#{remark},</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>
            <if test="delFlag != null">#{delFlag},</if>
         </trim>
    </insert>

    <update id="updateBaseMaterialInfo" parameterType="BaseMaterialInfo">
        update base_material_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="materialId != null">material_id = #{materialId},</if>
            <if test="materialName != null">material_name = #{materialName},</if>
            <if test="materialCode != null">material_code = #{materialCode},</if>
            <if test="materialTypeId != null">material_type_id = #{materialTypeId},</if>
            <if test="status != null">status = #{status},</if>
            <if test="remark != null">remark = #{remark},</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>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
        </trim>
        where objid = #{objid}
    </update>

    <delete id="deleteBaseMaterialInfoById" parameterType="Long">
        delete from base_material_info where objid = #{objid}
    </delete>

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

</mapper>
