<?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.storageLocation.mapper.StorageLocationMapper">

    <resultMap type="StorageLocation" id="StorageLocationResult">
        <result property="userName"    column="userName"    />
        <result property="materialBh"    column="materialBh"    />
        <result property="materialZlh"    column="materialZlh"    />
        <result property="materialXingh"    column="materialXingh"    />
        <result property="materialGuig"    column="materialGuig"    />
        <result property="materialDiany"    column="materialDiany"    />
        <result property="materialMs"    column="materialMs"    />
        <result property="materialState"    column="materialState"    />
    </resultMap>

    <select id="selectStorageLocationAList" parameterType="StorageLocation" resultMap="StorageLocationResult">
        select materialBh, materialZlh, materialXingh, materialGuig, materialDiany, materialMs, materialState
        from storageLocation where materialBh like 'A%'
    </select>
    <select id="selectStorageLocationBList" parameterType="StorageLocation" resultMap="StorageLocationResult">
        select materialBh, materialZlh, materialXingh, materialGuig, materialDiany, materialMs, materialState
        from storageLocation where materialBh like 'B%'
    </select>
    <select id="selectStorageLocationCList" parameterType="StorageLocation" resultMap="StorageLocationResult">
        select materialBh, materialZlh, materialXingh, materialGuig, materialDiany, materialMs, materialState
        from storageLocation where materialBh like 'C%'
    </select>

    <update id="addStorageLocation" parameterType="StorageLocation">
        update storageLocation
        <trim prefix="SET" suffixOverrides=",">
            <if test="materialZlh != null and materialZlh != ''">materialZlh = #{materialZlh},</if>
            <if test="materialXingh != null and materialXingh != ''">materialXingh = #{materialXingh},</if>
            <if test="materialGuig != null and materialGuig != ''">materialGuig = #{materialGuig},</if>
            <if test="materialDiany != null and materialDiany != ''">materialDiany = #{materialDiany},</if>
            <if test="materialMs != null and materialMs != ''">materialMs = #{materialMs},</if>
            materialState = '1'
        </trim>
        where materialBh = #{materialBh}
    </update>

    <update id="confirmStorageLocation" parameterType="java.util.List">
        update storageLocation set materialState = '0',materialZlh = null,materialXingh = null,materialGuig = null,
        materialDiany = null, materialMs = null
        <where>
            materialBh
            <foreach collection="list" item="item" index="index" open="in (" close=")" separator=",">
                #{item}
            </foreach>
        </where>
    </update>

    <select id="hasStorageLocation" parameterType="java.lang.String" resultType="StorageSelected">
        select user_name, material_bh
        from storageSelected where material_bh = #{materialBh}
    </select>

    <insert id="saveStorageLocation" parameterType="java.lang.String">
        insert into storageSelected (user_name,material_bh) values (#{userName},#{materialBh})
    </insert>

    <delete id="deleteStorageLocation">
        delete from storageSelected where user_name = #{userName} and material_bh = #{materialBh}
    </delete>

    <select id="selectStorageSelectedLocationAList" parameterType="java.lang.String" resultMap="StorageLocationResult">
        select a.user_name userName,b.materialBh,b.materialXingh,
               b.materialGuig,b.materialDiany,
               b.materialMs,b.materialZlh
        from storageSelected a
        left join storageLocation b
        on a.material_Bh = b.materialBh
        where a.user_name = #{userName} and a.material_bh like 'A%'
    </select>
    <select id="selectStorageSelectedLocationBList" parameterType="java.lang.String" resultMap="StorageLocationResult">
        select a.user_name userName,b.materialBh,b.materialXingh,
               b.materialGuig,b.materialDiany,
               b.materialMs,b.materialZlh
        from storageSelected a
        left join storageLocation b
        on a.material_Bh = b.materialBh
        where a.user_name = #{userName} and a.material_bh like 'B%'
    </select>
    <select id="selectStorageSelectedLocationCList" parameterType="java.lang.String" resultMap="StorageLocationResult">
        select a.user_name userName,b.materialBh,b.materialXingh,
               b.materialGuig,b.materialDiany,
               b.materialMs,b.materialZlh
        from storageSelected a
        left join storageLocation b
        on a.material_Bh = b.materialBh
        where a.user_name = #{userName} and a.material_bh like 'C%'
    </select>

    <select id="selectStorageSelectedLocationList" resultType="StorageSelected">
        select user_name,material_bh
        from storageSelected
    </select>

    <delete id="deleteBatchStorageLocation">
        delete from storageSelected where user_name = #{userName}
        and material_bh
        <foreach collection="list" item="item" index="index" open="in (" close=")" separator=",">
            #{item}
        </foreach>
    </delete>

    <insert id="addOperlog" parameterType="Operlog">
        insert into operlog (operlog_kw,operlog_date,operlog_user_name,operlog_event,operlog_zlh,operlog_xingh,operlog_guig,operlog_diany,operlog_ms)
        values (#{operlog_kw},#{operlog_date},#{operlog_user_name},#{operlog_event},#{operlog_zlh},#{operlog_xingh},#{operlog_guig},#{operlog_diany},#{operlog_ms})
    </insert>

    <select id="selectStorageLocation" resultType="StorageLocation">
        select a.material_bh materialBh,b.materialXingh,b.materialGuig,b.materialDiany,b.materialMs,b.materialZlh
        from storageSelected a
        left join storageLocation b on a.material_bh = b.materialBh
        where a.user_name = #{userName}
        and a.material_bh
        <foreach collection="list" item="item" index="index" open="in (" close=")" separator=",">
            #{item}
        </foreach>
    </select>

    <insert id="addBatchOperlog">
        insert into operlog (operlog_kw,operlog_date,operlog_user_name,operlog_event,operlog_zlh,operlog_xingh,operlog_guig,operlog_diany,operlog_ms)
        values
        <foreach collection="list" index="" item="item" separator=",">
            (#{item.operlog_kw,jdbcType=VARCHAR},
            #{item.operlog_date,jdbcType=VARCHAR},
            #{item.operlog_user_name,jdbcType=VARCHAR},
            #{item.operlog_event,jdbcType=VARCHAR},
            #{item.operlog_zlh,jdbcType=VARCHAR},
            #{item.operlog_xingh,jdbcType=VARCHAR},
            #{item.operlog_guig,jdbcType=VARCHAR},
            #{item.operlog_diany,jdbcType=VARCHAR},
            #{item.operlog_ms,jdbcType=VARCHAR})
        </foreach>
    </insert>

    <select id="selectOperlogs" parameterType="Operlog"  resultType="Operlog">
        select operlog_date,operlog_user_name,operlog_event,operlog_zlh,operlog_xingh
             ,operlog_guig,operlog_diany,operlog_ms
        from operlog
        where operlog_kw = #{operlog_kw} order by operlog_date desc
    </select>
</mapper>
