<?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.yijia.integral.mapper.IntegralWaresMapper">

    <resultMap type="IntegralWares" id="IntegralWaresResult">
        <result property="id"    column="id"    />
        <result property="waresName"    column="wares_name"    />
        <result property="saleIntegral"    column="sale_integral"    />
        <result property="waresPic"    column="wares_pic"    />
        <result property="waresDetail"    column="wares_detail"    />
        <result property="waresCount"    column="wares_count"    />
        <result property="waresOutCount"    column="wares_out_count"    />
        <result property="waresStatus"    column="wares_status"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateName"    column="update_name"    />
        <result property="stationId"    column="station_id"    />
        <result property="stationName"    column="station_name"    />
    </resultMap>

    <sql id="selectIntegralWaresVo">
        select w.id, wares_name, w.sale_integral, wares_pic, wares_detail,
        wares_count, wares_out_count, wares_status, w.create_time, w.create_by,
        w.update_time, w.update_by, w.station_id,d.dept_name as station_name
        from integral_wares w join sys_dept d on w.station_id = d.dept_id
    </sql>

    <select id="selectIntegralWaresList" parameterType="IntegralWares" resultMap="IntegralWaresResult">
        <include refid="selectIntegralWaresVo"/>
        <where>
            <if test="waresName != null  and waresName != ''"> and wares_name like concat('%', #{waresName}, '%')</if>
            <if test="saleIntegral != null "> and w.sale_integral = #{saleIntegral}</if>
            <if test="waresPic != null  and waresPic != ''"> and w.wares_pic = #{waresPic}</if>
            <if test="waresDetail != null  and waresDetail != ''"> and wares_detail = #{waresDetail}</if>
            <if test="waresCount != null "> and wares_count = #{waresCount}</if>
            <if test="waresOutCount != null "> and wares_out_count = #{waresOutCount}</if>
            <if test="waresStatusList != null ">
                and wares_status in
                <foreach item="item" index="index" collection="waresStatusList" open="(" separator="," close=")">
                    #{item}
                </foreach>
             </if>
            <if test="stationId != null "> and w.station_id = #{stationId}</if>
            <if test="stationIdList != null ">
                and station_id in
                <foreach item="item" index="index" collection="stationIdList"
                         open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
        </where>
        order by  wares_status
    </select>

    <select id="selectIntegralWaresById" parameterType="Long" resultMap="IntegralWaresResult">
        <include refid="selectIntegralWaresVo"/>
        where id = #{id}
    </select>

    <insert id="insertIntegralWares" parameterType="IntegralWares" useGeneratedKeys="true" keyProperty="id">
        insert into integral_wares
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="waresName != null">wares_name,</if>
            <if test="saleIntegral != null">sale_integral,</if>
            <if test="waresPic != null">wares_pic,</if>
            <if test="waresDetail != null">wares_detail,</if>
            <if test="waresCount != null">wares_count,</if>
            <if test="waresOutCount != null">wares_out_count,</if>
            <if test="waresStatus != null">wares_status,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createName != null">create_name,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateName != null">update_name,</if>
            <if test="stationId != null">station_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="waresName != null">#{waresName},</if>
            <if test="saleIntegral != null">#{saleIntegral},</if>
            <if test="waresPic != null">#{waresPic},</if>
            <if test="waresDetail != null">#{waresDetail},</if>
            <if test="waresCount != null">#{waresCount},</if>
            <if test="waresOutCount != null">#{waresOutCount},</if>
            <if test="waresStatus != null">#{waresStatus},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createName != null">#{createName},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateName != null">#{updateName},</if>
            <if test="stationId != null">#{stationId},</if>
         </trim>
    </insert>

    <update id="updateIntegralWares" parameterType="IntegralWares">
        update integral_wares
        <trim prefix="SET" suffixOverrides=",">
            <if test="waresName != null">wares_name = #{waresName},</if>
            <if test="saleIntegral != null">sale_integral = #{saleIntegral},</if>
            <if test="waresPic != null">wares_pic = #{waresPic},</if>
            <if test="waresDetail != null">wares_detail = #{waresDetail},</if>
            <if test="waresCount != null">wares_count = #{waresCount},</if>
            <if test="waresOutCount != null">wares_out_count = #{waresOutCount},</if>
            <if test="waresStatus != null">wares_status = #{waresStatus},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="stationId != null">station_id = #{stationId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteIntegralWaresById" parameterType="Long">
        delete from integral_wares where id = #{id}
    </delete>

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

</mapper>
