StockMapper.xml 3.13 KB
<?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.huaheng.pc.config.stock.mapper.StockMapper">
    
    <resultMap type="com.huaheng.pc.config.stock.domain.Stock" id="stockResult">
        <result property="stockId"    column="stockId"    />
        <result property="name"    column="name"    />
        <result property="number"    column="number"    />
        <result property="isOpenLocation"    column="isOpenLocation"    />
        <result property="useOrgId"    column="useOrgId"    />
        <result property="deleted"    column="deleted"    />
    </resultMap>
	<sql id="selectStockVo">
        select stockId, name, number, isOpenLocation,useOrgId,deleted from stock
    </sql>

    <select id="selectByNumber" resultType="com.huaheng.pc.config.stock.domain.Stock">
        <include refid="selectStockVo"></include>
        <where>
            `number`=#{code}
        </where>
    </select>

    <insert id="insertBatch" parameterType="java.util.List">
        INSERT INTO stock
        (stockId,name,number,isOpenLocation,useOrgId) VALUES
        <foreach collection="list" item="item" separator=",">
            (
            #{item.stockId},#{item.name},#{item.number},#{item.isOpenLocation},#{item.useOrgId}
            )
        </foreach>
    </insert>

    <update id="modifyBatch" parameterType="java.util.List">
        update stock
        <trim prefix="set" suffixOverrides=",">
            <trim prefix="name =case" suffix="end,">
                <foreach collection="list" item="item" index="index">
                    <if test="item.name!=null">
                        when stockId=#{item.stockId}
                        then #{item.name}
                    </if>
                </foreach>
            </trim>
            <trim prefix="number =case" suffix="end,">
                <foreach collection="list" item="item" index="index">
                    <if test="item.number!=null">
                        when stockId=#{item.stockId}
                        then #{item.number}
                    </if>
                </foreach>
            </trim>
            <trim prefix="isOpenLocation =case" suffix="end,">
                <foreach collection="list" item="item" index="index">
                    <if test="item.isOpenLocation!=null">
                        when stockId=#{item.stockId}
                        then #{item.isOpenLocation}
                    </if>
                </foreach>
            </trim>
            <trim prefix="useOrgId =case" suffix="end,">
                <foreach collection="list" item="item" index="index">
                    <if test="item.useOrgId!=null">
                        when stockId=#{item.stockId}
                        then #{item.useOrgId}
                    </if>
                </foreach>
            </trim>
        </trim>
        where stockId in
        <foreach collection="list" item="item" index="index" separator="," open="(" close=")">
            #{item.stockId}
        </foreach>
    </update>

    <update id="truncateTable">
        truncate table stock
    </update>
</mapper>