<?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.ytpm.middle.dao.WorkorderMapper">
    <update id="updateById">
        update yt_work_order
        <set>
            <if test="title != null">
                title = #{title},
            </if>
            <if test="content != null">
                content = #{content},
            </if>
            <if test="workorderStatus != null">
                workorder_status = #{workorderStatus},
            </if>
            <if test="remark != null">
                remark = #{remark},
            </if>
            <if test="processor != null">
                processor = #{processor},
            </if>
            <if test="finishTime != null">
                finish_time = #{finishTime},
            </if>
            <if test="updateUserId != null">
                update_user_id = #{updateUserId},
            </if>
            <if test="updateTime != null">
                update_time = #{updateTime},
            </if>
            <if test="available != null">
                available = #{available}
            </if>
        </set>
        where workorder_id = #{workorderId}
    </update>

    <select id="queryList" resultType="com.ytpm.middle.view.WorkorderVO">
        select
            wo.workorder_id,
            wo.title,
            wo.content,
            wo.workorder_status,
            wo.remark,
            wo.processor,
            wo.finish_time,
            wo.create_user_id,
            wo.create_time,
            wo.update_user_id,
            wo.update_time,
            wo.available,
            pu.nick_name creatorName,
            pu1.nick_name processorName
        from yt_work_order wo
        left join yt_platform_user pu on wo.create_user_id = pu.user_id
        left join yt_platform_user pu1 on wo.processor = pu1.user_id
        where wo.available = 1
        <if test=" creatorName!=null and creatorName!= ''">
            and pu.nick_name like concat('%',#{creatorName},'%')
        </if>
        <if test=" processorName!=null and processorName!= ''">
            and pu1.nick_name like concat('%',#{processorName},'%')
        </if>
        <if test="title!=null and title!= ''">
            and wo.title like concat('%', #{title}, '%')
        </if>
    </select>
    <select id="selectByPrimary" resultType="com.ytpm.agent.model.YtWorkorder">
        select
            wo.workorder_id,
            wo.title,
            wo.content,
            wo.workorder_status,
            wo.remark,
            wo.processor,
            wo.finish_time,
            wo.create_user_id,
            wo.create_time,
            wo.update_user_id,
            wo.update_time,
            wo.available,
            pu.nick_name creatorName,
            pu1.nick_name processorName
        from yt_work_order wo
        left join yt_platform_user pu on wo.create_user_id = pu.user_id
        left join yt_platform_user pu1 on wo.processor = pu1.user_id
        where wo.workorder_id = #{workorderId}
    </select>
</mapper>