<?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.zbf.system.mapper.TCallNoticeMapper">

    <resultMap type="TCallNotice" id="TCallNoticeResult">
            <result property="id"    column="id"    />
            <result property="storageId"    column="storage_id"    />
            <result property="ctl"    column="ctl"    />
            <result property="plcid"    column="plcid"    />
            <result property="ctl"    column="ctl"    />
            <result property="rLocationId"    column="r_location_id"    />
            <result property="cLocationId"    column="c_location_id"    />
            <result property="rukuId"    column="ruku_id"    />
            <result property="taskType"    column="task_type"    />
            <result property="chukuId"    column="chuku_id"    />
            <result property="status"    column="status"    />
            <result property="createBy"    column="create_by"    />
            <result property="updateBy"    column="update_by"    />
            <result property="createTime"    column="create_time"    />
            <result property="updateTime"    column="update_time"    />
            <result property="goodsId"    column="goods_id"    />
            <result property="goodsName"    column="goods_name"    />
            <result property="shelfCtl"    column="shelf_ctl"    />
            <result property="shelfPlcId"    column="shelf_plc"    />
            <result property="pickCtl"    column="pick_ctl"    />
            <result property="pickPlcId"    column="pick_plc"    />
            <result property="fictitious"    column="fictitious"    />
    </resultMap>

    <sql id="selectTCallNoticeVo">
        select distinct t.id, t.storage_id, t.ctl, t.plcid , t.ruku_id, t.task_type, t.chuku_id, t.status, t.create_by, t.update_by, t.create_time, t.update_time, t.goods_id, t.goods_name,
                t1.ctl as shelf_ctl,t1.location_id as r_location_id, t1.plc_id as shelf_plc, t2.ctl as pick_ctl, t2.location_id as c_location_id,t2.plc_id as pick_plc,t.fictitious
        from t_call_notice t
            left join t_ongoodsshelf t1 on t1.acce_id = t.task_id
            left join t_ck_pickingwavegoods t2 on t2.picking_id = t.task_id
    </sql>

    <select id="selectTCallNoticeList" parameterType="TCallNotice" resultMap="TCallNoticeResult">
        <include refid="selectTCallNoticeVo"/>
        <where>
            <if test="storageList != null  and storageList != ''">
                t.storage_id in
                <foreach item="storageId" collection="storageList" open="(" separator="," close=")">
                    #{storageId}
                </foreach>
            </if>
            <if test="ctl != null  and ctl != ''"> and t.ctl = #{ctl}</if>
            <if test="plcid != null "> and t.plcid = #{plcid}</if>
            <if test="rukuId != null  and rukuId != ''"> and t.ruku_id = #{rukuId}</if>
            <if test="taskType != null  and taskType != ''"> and t.task_type = #{taskType}</if>
            <if test="chukuId != null  and chukuId != ''"> and t.chuku_id = #{chukuId}</if>
            <if test="status != null  and status != ''"> and t.status = #{status}</if>
            <if test="goodsId != null  and goodsId != ''"> and t.goods_id = #{goodsId}</if>
            <if test="goodsName != null  and goodsName != ''"> and t.goods_name like concat('%', #{goodsName}, '%')</if>
        </where>
         order by t.create_time desc
    </select>

    <select id="selectTCallNoticeById" parameterType="String" resultMap="TCallNoticeResult">
            <include refid="selectTCallNoticeVo"/>
            where t.id = #{id}
    </select>

    <insert id="insertTCallNotice" parameterType="TCallNotice">
        insert into t_call_notice
        <trim prefix="(" suffix=")" suffixOverrides=",">
                    <if test="id != null">id,</if>
                    <if test="storageId != null">storage_id,</if>
                    <if test="ctl != null">ctl,</if>
                    <if test="plcid != null">plcid,</if>
                    <if test="rukuId != null">ruku_id,</if>
                    <if test="taskType != null">task_type,</if>
                    <if test="chukuId != null">chuku_id,</if>
                    <if test="status != null">status,</if>
                    <if test="createBy != null">create_by,</if>
                    <if test="updateBy != null">update_by,</if>
                    <if test="createTime != null">create_time,</if>
                    <if test="updateTime != null">update_time,</if>
                    <if test="goodsId != null">goods_id,</if>
                    <if test="goodsName != null">goods_name,</if>
                    <if test="fictitious != null">fictitious,</if>
                    <if test="taskId != null">task_id,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
                    <if test="id != null">#{id},</if>
                    <if test="storageId != null">#{storageId},</if>
                    <if test="ctl != null">#{ctl},</if>
                    <if test="plcid != null">#{plcid},</if>
                    <if test="rukuId != null">#{rukuId},</if>
                    <if test="taskType != null">#{taskType},</if>
                    <if test="chukuId != null">#{chukuId},</if>
                    <if test="status != null">#{status},</if>
                    <if test="createBy != null">#{createBy},</if>
                    <if test="updateBy != null">#{updateBy},</if>
                    <if test="createTime != null">#{createTime},</if>
                    <if test="updateTime != null">#{updateTime},</if>
                    <if test="goodsId != null">#{goodsId},</if>
                    <if test="goodsName != null">#{goodsName},</if>
                    <if test="fictitious != null">#{fictitious},</if>
                    <if test="taskId != null">#{taskId},</if>
        </trim>
    </insert>

    <update id="updateTCallNotice" parameterType="TCallNotice">
        update t_call_notice
        <trim prefix="SET" suffixOverrides=",">
                    <if test="storageId != null">storage_id = #{storageId},</if>
                    <if test="ctl != null">ctl = #{ctl},</if>
                    <if test="plcid != null">plcid = #{plcid},</if>
                    <if test="rukuId != null">ruku_id = #{rukuId},</if>
                    <if test="taskType != null">task_type = #{taskType},</if>
                    <if test="chukuId != null">chuku_id = #{chukuId},</if>
                    <if test="status != null">status = #{status},</if>
                    <if test="createBy != null">create_by = #{createBy},</if>
                    <if test="updateBy != null">update_by = #{updateBy},</if>
                    <if test="createTime != null">create_time = #{createTime},</if>
                    <if test="updateTime != null">update_time = #{updateTime},</if>
                    <if test="goodsId != null">goods_id = #{goodsId},</if>
        </trim>
        where id = #{id}
    </update>

    <update id="enableTCallNoticeByIds" parameterType="String">
        update t_call_notice set status=0 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
    <update id="disabledTCallNoticeByIds" parameterType="String">
        update t_call_notice set status=1 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>

    <delete id="deleteTCallNoticeById" parameterType="String">
        delete from t_call_notice  where id = #{id}
    </delete>

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

    <update id="updateTaskStatus" parameterType="TCallNotice">
        update t_call_notice
            set status= '1'
                , update_by = #{updateBy}
                , update_time = #{updateTime}
        <where>
            <if test="rukuId != null">and ruku_id = #{rukuId}</if>
            <if test="taskType != null">and task_type = #{taskType}</if>
            <if test="chukuId != null">and chuku_id = #{chukuId}</if>
            <if test="id != null">and id = #{id}</if>
        </where>
    </update>
</mapper>
