<?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.zhyc.module.work.mapper.WorkOrderMapper">
    
    <resultMap type="WorkOrder" id="WorkOrderResult">
        <result property="id"    column="id"    />
        <result property="orderNo"    column="order_no"    />
        <result property="planId"    column="plan_id"    />
        <result property="bizType"    column="biz_type"    />
        <result property="title"    column="title"    />
        <result property="content"    column="content"    />
        <result property="department"    column="department"    />
        <result property="executorIds"    column="executor_ids"    />
        <result property="executor"    column="executor"    />
        <result property="executeDate"    column="execute_date"    />
        <result property="executeTime"    column="execute_time"    />
        <result property="sheepScope"    column="sheep_scope"  typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler"  />
        <result property="location"    column="location" typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler"   />
        <result property="materialList"    column="material_list"    />
        <result property="toolList"    column="tool_list"    />
        <result property="status"    column="status"    />
        <result property="priority"    column="priority"    />
        <result property="issuerId"    column="issuer_id"    />
        <result property="issuer"    column="issuer"    />
        <result property="issueTime"    column="issue_time"    />
        <result property="receiverId"    column="receiver_id"    />
        <result property="receiver"    column="receiver"    />
        <result property="receiveTime"    column="receive_time"    />
        <result property="finishTime"    column="finish_time"    />
        <result property="result"    column="result"    />
        <result property="remark"    column="remark"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="deleted"    column="deleted"    />
    </resultMap>

    <sql id="selectWorkOrderVo">
        select id, order_no, plan_id, biz_type, title, content, department, executor_ids,executor, execute_date, execute_time, sheep_scope, location, material_list, tool_list, status, priority, issuer_id, issuer,issue_time, receiver_id, receiver,receive_time, finish_time, result, remark, create_time, update_time, deleted from work_order
    </sql>

    <select id="selectWorkOrderList" parameterType="WorkOrder" resultMap="WorkOrderResult">
        <include refid="selectWorkOrderVo"/>
        <where>
            <if test="orderNo != null  and orderNo != ''"> and order_no like concat('%', #{orderNo}, '%')</if>
            <if test="planId != null "> and plan_id = #{planId}</if>
            <if test="bizType != null "> and biz_type = #{bizType}</if>
            <if test="title != null  and title != ''"> and title like concat('%', #{title},'%')</if>
            <if test="content != null  and content != ''"> and content = #{content}</if>
            <if test="department != null  and department != ''"> and department = #{department}</if>
            <if test="executor != null  and executor != ''"> and executor like concat('%',#{executor},'%') </if>
            <if test="beginPlanDate != null  and endPlanDate != null ">
             and execute_date between #{beginPlanDate} and #{endPlanDate}
             </if>
            <if test="executeTime != null  and executeTime != ''"> and execute_time = #{executeTime}</if>
            <if test="sheepScope != null  and sheepScope != ''"> and sheep_scope = #{sheepScope}</if>
            <if test="location != null  and location != ''"> and location = #{location}</if>
            <if test="materialList != null  and materialList != ''"> and material_list = #{materialList}</if>
            <if test="toolList != null  and toolList != ''"> and tool_list = #{toolList}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="priority != null "> and priority = #{priority}</if>
            <if test="issuer != null "> and issuer like concat('%',#{issuer},'%') </if>
            <if test="issueTime != null "> and issue_time = #{issueTime}</if>
            <if test="receiverId != null "> and receiver_id = #{receiverId}</if>
            <if test="receiveTime != null "> and receive_time = #{receiveTime}</if>
            <if test="beginFinishDate != null and endFinishDate != null ">
                and finish_time between #{beginFinishDate} and #{endFinishDate}
            </if>

            <if test="result != null  and result != ''"> and result = #{result}</if>
        </where>
        order by execute_date desc
    </select>

    
    <select id="selectWorkOrderById" parameterType="Long" resultMap="WorkOrderResult">
        <include refid="selectWorkOrderVo"/>
        where id = #{id}
    </select>

    <insert id="insertWorkOrder" parameterType="WorkOrder" useGeneratedKeys="true" keyProperty="id">
        insert into work_order
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="orderNo != null and orderNo != ''">order_no,</if>
            <if test="planId != null">plan_id,</if>
            <if test="bizType != null">biz_type,</if>
            <if test="title != null and title != ''">title,</if>
            <if test="content != null">content,</if>
            <if test="department != null and department != ''">department,</if>
            <if test="executorIds != null and executorIds != ''">executor_ids,</if>
            <if test="executor != null and executor != ''">executor,</if>
            <if test="executeDate != null">execute_date,</if>
            <if test="executeTime != null">execute_time,</if>
            <if test="sheepScope != null and sheepScope != ''">sheep_scope,</if>
            <if test="location != null">location,</if>
            <if test="materialList != null">material_list,</if>
            <if test="toolList != null">tool_list,</if>
            <if test="status != null">status,</if>
            <if test="priority != null">priority,</if>
            <if test="issuerId != null">issuer_id,</if>
            <if test="issuer != null">issuer,</if>
            <if test="issueTime != null">issue_time,</if>
            <if test="receiverId != null">receiver_id,</if>
            <if test="receiver != null">receiver,</if>
            <if test="receiveTime != null">receive_time,</if>
            <if test="finishTime != null">finish_time,</if>
            <if test="result != null">`result`,</if>
            <if test="remark != null">remark,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="deleted != null">deleted,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="orderNo != null and orderNo != ''">#{orderNo},</if>
            <if test="planId != null">#{planId},</if>
            <if test="bizType != null">#{bizType},</if>
            <if test="title != null and title != ''">#{title},</if>
            <if test="content != null">#{content},</if>
            <if test="department != null and department != ''">#{department},</if>
            <if test="executorIds != null and executorIds != ''">#{executorIds},</if>
            <if test="executor != null and executor != ''">#{executor},</if>
            <if test="executeDate != null">#{executeDate},</if>
            <if test="executeTime != null">#{executeTime},</if>
            <if test="sheepScope != null and sheepScope != ''">#{sheepScope,typeHandler=com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler},</if>
            <if test="location != null">#{location,typeHandler=com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler},</if>
            <if test="materialList != null">#{materialList},</if>
            <if test="toolList != null">#{toolList},</if>
            <if test="status != null">#{status},</if>
            <if test="priority != null">#{priority},</if>
            <if test="issuerId != null">#{issuerId},</if>
            <if test="issuer != null">#{issuer},</if>
            <if test="issueTime != null">#{issueTime},</if>
            <if test="receiverId != null">#{receiverId},</if>
            <if test="receiver != null">#{receiver},</if>
            <if test="receiveTime != null">#{receiveTime},</if>
            <if test="finishTime != null">#{finishTime},</if>
            <if test="result != null">#{result},</if>
            <if test="remark != null">#{remark},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="deleted != null">#{deleted},</if>
         </trim>
    </insert>

    <update id="updateWorkOrder" parameterType="WorkOrder">
        update work_order
        <trim prefix="SET" suffixOverrides=",">
            <if test="orderNo != null and orderNo != ''">order_no = #{orderNo},</if>
            <if test="planId != null">plan_id = #{planId},</if>
            <if test="bizType != null">biz_type = #{bizType},</if>
            <if test="title != null and title != ''">title = #{title},</if>
            <if test="content != null">content = #{content},</if>
            <if test="department != null and department != ''">department = #{department},</if>
            <if test="executorIds != null and executorIds != ''">executor_ids = #{executorIds},</if>
            <if test="executor != null and executor != ''">executor = #{executor},</if>
            <if test="executeDate != null">execute_date = #{executeDate},</if>
            <if test="executeTime != null">execute_time = #{executeTime},</if>
            <if test="sheepScope != null and sheepScope != ''">sheep_scope = #{sheepScope,typeHandler=com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler},</if>
            <if test="location != null">location = #{location,typeHandler=com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler},</if>
            <if test="materialList != null">material_list = #{materialList},</if>
            <if test="toolList != null">tool_list = #{toolList},</if>
            <if test="status != null">status = #{status},</if>
            <if test="priority != null">priority = #{priority},</if>
            <if test="issuerId != null">issuer_id = #{issuerId},</if>
            <if test="issuer != null">issuer = #{issuer},</if>
            <if test="issueTime != null">issue_time = #{issueTime},</if>
            <if test="receiverId != null">receiver_id = #{receiverId},</if>
            <if test="receiver != null">receiver = #{receiver},</if>
            <if test="receiveTime != null">receive_time = #{receiveTime},</if>
            <if test="finishTime != null">finish_time = #{finishTime},</if>
            <if test="result != null">`result` = #{result},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="deleted != null">deleted = #{deleted},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteWorkOrderById" parameterType="Long">
        delete from work_order where id = #{id}
    </delete>

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