<?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.huaxu.order.dao.WorkOrderManageMapper" >
  <resultMap id="BaseResultMap" type="com.huaxu.order.dto.WorkOrderManageDto" >
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="task_no" property="taskNo" jdbcType="VARCHAR" />
    <result column="task_desc" property="taskDesc" jdbcType="VARCHAR" />
    <result column="order_user_id" property="orderUserId" jdbcType="VARCHAR" />
    <result column="send_time" property="sendTime" jdbcType="TIMESTAMP" />
    <result column="send_by" property="sendBy" jdbcType="VARCHAR" />
    <result column="plan_finish_date" property="planFinishDate" jdbcType="TIMESTAMP" />
    <result column="finish_date" property="finishDate" jdbcType="TIMESTAMP" />
    <result column="date_limit" property="dateLimit" jdbcType="VARCHAR" />
    <result column="urgency" property="urgency" jdbcType="VARCHAR" />
    <result column="address" property="address" jdbcType="VARCHAR" />
    <result column="contact_user" property="contactUser" jdbcType="VARCHAR" />
    <result column="contact_phone" property="contactPhone" jdbcType="VARCHAR" />
    <result column="order_time" property="orderTime" jdbcType="VARCHAR" />
    <result column="company_org_id" property="companyOrgId" jdbcType="VARCHAR" />
    <result column="department_org_id" property="departmentOrgId" jdbcType="VARCHAR" />
    <result column="order_status" property="orderStatus" jdbcType="INTEGER" />
    <result column="event_type" property="eventType" jdbcType="INTEGER" />
    <result column="order_type_id" property="orderTypeId" jdbcType="INTEGER" />
    <result column="order_pid" property="orderPid" jdbcType="VARCHAR" />
    <result column="tenant_id" property="tenantId" jdbcType="VARCHAR" />
    <result column="process_instance_id" property="processInstanceId" jdbcType="VARCHAR" />
    <result column="process_def_id" property="processDefId" jdbcType="VARCHAR" />
    <result column="current_task_id" property="currentTaskId" jdbcType="VARCHAR" />
    <result column="current_users" property="currentUsers" jdbcType="VARCHAR" />
    <result column="current_task_name" property="currentTaskName" jdbcType="VARCHAR" />
    <result column="create_by" property="createBy" jdbcType="VARCHAR" />
    <result column="date_create" property="dateCreate" jdbcType="TIMESTAMP" />
    <result column="update_by" property="updateBy" jdbcType="VARCHAR" />
    <result column="date_update" property="dateUpdate" jdbcType="TIMESTAMP" />
    <result column="geo" property="geo" jdbcType="VARCHAR" />
    <result column="videos" property="videos" jdbcType="VARCHAR" />
    <result column="pictures" property="pictures" jdbcType="VARCHAR" />
    <result column="flow_detail" property="flowDetail" jdbcType="VARCHAR" />
  </resultMap>

  <resultMap id="workFlowLogResultMap" type="com.huaxu.order.entity.WorkFlowLog">
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="flow_id" property="flowId" jdbcType="INTEGER" />
    <result column="log_process_instance_id" property="processInstanceId" jdbcType="VARCHAR" />
    <result column="task_id" property="taskId" jdbcType="VARCHAR" />
    <result column="handle_user_id" property="handleUserId" jdbcType="VARCHAR" />
    <result column="handle_user_name" property="handleUserName" jdbcType="VARCHAR" />
    <result column="flow_type" property="flowType" jdbcType="INTEGER" />
    <result column="flow_result" property="flowResult" jdbcType="VARCHAR" />
    <result column="log_create_by" property="createBy" jdbcType="VARCHAR" />
    <result column="log_date_create" property="dateCreate" jdbcType="TIMESTAMP" />
    <result column="log_update_by" property="updateBy" jdbcType="VARCHAR" />
    <result column="log_date_update" property="dateUpdate" jdbcType="TIMESTAMP" />
  </resultMap>

  <resultMap id="OrderResultMap" type="com.huaxu.order.dto.WorkOrderManageDto" extends="BaseResultMap">
    <association property="workFlowDetail" javaType="com.huaxu.order.entity.WorkFlowDetail">
      <id column="id" property="id" jdbcType="INTEGER" />
      <result column="flow_id" property="flowId" jdbcType="INTEGER" />
      <result column="flow_type" property="flowType" jdbcType="INTEGER" />
      <result column="flow_detail" property="flowDetail" jdbcType="VARCHAR" />
      <result column="detail_create_by" property="createBy" jdbcType="VARCHAR" />
      <result column="detail_date_create" property="dateCreate" jdbcType="TIMESTAMP" />
      <result column="detail_update_by" property="updateBy" jdbcType="VARCHAR" />
      <result column="detail_date_update" property="dateUpdate" jdbcType="TIMESTAMP" />
    </association>
    <collection property="workFlowLogList" ofType="com.huaxu.order.entity.WorkFlowLog" javaType="java.util.List" select="getWorkFlowLog" column="{flowId=id}">
      <id column="id" property="id" jdbcType="INTEGER" />
      <result column="flow_id" property="flowId" jdbcType="INTEGER" />
      <result column="log_process_instance_id" property="processInstanceId" jdbcType="VARCHAR" />
      <result column="task_id" property="taskId" jdbcType="VARCHAR" />
      <result column="handle_user_id" property="handleUserId" jdbcType="VARCHAR" />
      <result column="handle_user_name" property="handleUserName" jdbcType="VARCHAR" />
      <result column="flow_type" property="flowType" jdbcType="INTEGER" />
      <result column="flow_result" property="flowResult" jdbcType="VARCHAR" />
      <result column="log_create_by" property="createBy" jdbcType="VARCHAR" />
      <result column="log_date_create" property="dateCreate" jdbcType="TIMESTAMP" />
      <result column="log_update_by" property="updateBy" jdbcType="VARCHAR" />
      <result column="log_date_update" property="dateUpdate" jdbcType="TIMESTAMP" />
    </collection>
  </resultMap>

  <sql id="Base_Column_List" >
    id, task_no, task_desc, order_user_id, send_time, send_by, plan_finish_date, finish_date, 
    date_limit, urgency, address, contact_user, contact_phone, order_time, company_org_id, 
    department_org_id, order_status, event_type, order_type_id, order_pid, tenant_id, 
    process_instance_id, process_def_id, current_task_id, current_users, current_task_name, 
    create_by, date_create, update_by, date_update, geo,videos,pictures
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
    select 
    <include refid="Base_Column_List" />
    from sc_work_order_manage
    where id = #{id,jdbcType=INTEGER}
  </select>

  <select id="getWorkFlowLog" resultMap="workFlowLogResultMap" parameterType="map">
        select t3.process_instance_id log_process_instance_id,t3.task_id,t3.handle_user_id,t3.handle_user_name,t3.flow_result,t3.create_by log_create_by,
        t3.date_create log_date_create,t3.update_by log_update_by,t3.date_update log_date_update
        from sc_work_flow_log t3
        where t3.flow_id= #{flowId,jdbcType=INTEGER} and t3.flow_type=2
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
    delete from sc_work_order_manage
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.huaxu.order.entity.WorkOrderManage" >
    insert into sc_work_order_manage (id, task_no, task_desc, 
      order_user_id, send_time, send_by, 
      plan_finish_date, finish_date, date_limit, 
      urgency, address, contact_user, 
      contact_phone, order_time, company_org_id, 
      department_org_id, order_status, event_type, 
      order_type_id, order_pid, tenant_id, 
      process_instance_id, process_def_id, current_task_id, 
      current_users, current_task_name, create_by, 
      date_create, update_by, date_update, 
      geo,videos,pictures)
    values (#{id,jdbcType=INTEGER}, #{taskNo,jdbcType=VARCHAR}, #{taskDesc,jdbcType=VARCHAR}, 
      #{orderUserId,jdbcType=VARCHAR}, #{sendTime,jdbcType=TIMESTAMP}, #{sendBy,jdbcType=VARCHAR}, 
      #{planFinishDate,jdbcType=TIMESTAMP}, #{finishDate,jdbcType=TIMESTAMP}, #{dateLimit,jdbcType=VARCHAR}, 
      #{urgency,jdbcType=VARCHAR}, #{address,jdbcType=VARCHAR}, #{contactUser,jdbcType=VARCHAR}, 
      #{contactPhone,jdbcType=VARCHAR}, #{orderTime,jdbcType=VARCHAR}, #{companyOrgId,jdbcType=VARCHAR}, 
      #{departmentOrgId,jdbcType=VARCHAR}, #{orderStatus,jdbcType=INTEGER}, #{eventType,jdbcType=INTEGER}, 
      #{orderTypeId,jdbcType=INTEGER}, #{orderPid,jdbcType=VARCHAR}, #{tenantId,jdbcType=VARCHAR}, 
      #{processInstanceId,jdbcType=VARCHAR}, #{processDefId,jdbcType=VARCHAR}, #{currentTaskId,jdbcType=VARCHAR}, 
      #{currentUsers,jdbcType=VARCHAR}, #{currentTaskName,jdbcType=VARCHAR}, #{createBy,jdbcType=VARCHAR}, 
      #{dateCreate,jdbcType=TIMESTAMP}, #{updateBy,jdbcType=VARCHAR}, #{dateUpdate,jdbcType=TIMESTAMP}, 
      #{geo,jdbcType=VARCHAR},#{videos,jdbcType=VARCHAR},#{pictures,jdbcType=VARCHAR})
  </insert>
  <insert id="insertSelective" parameterType="com.huaxu.order.entity.WorkOrderManage" keyProperty="id" useGeneratedKeys="true">
    insert into sc_work_order_manage
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="taskNo != null" >
        task_no,
      </if>
      <if test="taskDesc != null" >
        task_desc,
      </if>
      <if test="orderUserId != null" >
        order_user_id,
      </if>
      <if test="sendTime != null" >
        send_time,
      </if>
      <if test="sendBy != null" >
        send_by,
      </if>
      <if test="planFinishDate != null" >
        plan_finish_date,
      </if>
      <if test="finishDate != null" >
        finish_date,
      </if>
      <if test="dateLimit != null" >
        date_limit,
      </if>
      <if test="urgency != null" >
        urgency,
      </if>
      <if test="address != null" >
        address,
      </if>
      <if test="contactUser != null" >
        contact_user,
      </if>
      <if test="contactPhone != null" >
        contact_phone,
      </if>
      <if test="orderTime != null" >
        order_time,
      </if>
      <if test="companyOrgId != null" >
        company_org_id,
      </if>
      <if test="departmentOrgId != null" >
        department_org_id,
      </if>
      <if test="orderStatus != null" >
        order_status,
      </if>
      <if test="eventType != null" >
        event_type,
      </if>
      <if test="orderTypeId != null" >
        order_type_id,
      </if>
      <if test="orderPid != null" >
        order_pid,
      </if>
      <if test="tenantId != null" >
        tenant_id,
      </if>
      <if test="processInstanceId != null" >
        process_instance_id,
      </if>
      <if test="processDefId != null" >
        process_def_id,
      </if>
      <if test="currentTaskId != null" >
        current_task_id,
      </if>
      <if test="currentUsers != null" >
        current_users,
      </if>
      <if test="currentTaskName != null" >
        current_task_name,
      </if>
      <if test="createBy != null" >
        create_by,
      </if>
      <if test="dateCreate != null" >
        date_create,
      </if>
      <if test="updateBy != null" >
        update_by,
      </if>
      <if test="dateUpdate != null" >
        date_update,
      </if>
      <if test="geo != null" >
        geo,
      </if>
      <if test="videos != null" >
        videos,
      </if>
      <if test="pictures != null" >
        pictures,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        #{id,jdbcType=INTEGER},
      </if>
      <if test="taskNo != null" >
        #{taskNo,jdbcType=VARCHAR},
      </if>
      <if test="taskDesc != null" >
        #{taskDesc,jdbcType=VARCHAR},
      </if>
      <if test="orderUserId != null" >
        #{orderUserId,jdbcType=VARCHAR},
      </if>
      <if test="sendTime != null" >
        #{sendTime,jdbcType=TIMESTAMP},
      </if>
      <if test="sendBy != null" >
        #{sendBy,jdbcType=VARCHAR},
      </if>
      <if test="planFinishDate != null" >
        #{planFinishDate,jdbcType=TIMESTAMP},
      </if>
      <if test="finishDate != null" >
        #{finishDate,jdbcType=TIMESTAMP},
      </if>
      <if test="dateLimit != null" >
        #{dateLimit,jdbcType=VARCHAR},
      </if>
      <if test="urgency != null" >
        #{urgency,jdbcType=VARCHAR},
      </if>
      <if test="address != null" >
        #{address,jdbcType=VARCHAR},
      </if>
      <if test="contactUser != null" >
        #{contactUser,jdbcType=VARCHAR},
      </if>
      <if test="contactPhone != null" >
        #{contactPhone,jdbcType=VARCHAR},
      </if>
      <if test="orderTime != null" >
        #{orderTime,jdbcType=VARCHAR},
      </if>
      <if test="companyOrgId != null" >
        #{companyOrgId,jdbcType=VARCHAR},
      </if>
      <if test="departmentOrgId != null" >
        #{departmentOrgId,jdbcType=VARCHAR},
      </if>
      <if test="orderStatus != null" >
        #{orderStatus,jdbcType=INTEGER},
      </if>
      <if test="eventType != null" >
        #{eventType,jdbcType=INTEGER},
      </if>
      <if test="orderTypeId != null" >
        #{orderTypeId,jdbcType=INTEGER},
      </if>
      <if test="orderPid != null" >
        #{orderPid,jdbcType=VARCHAR},
      </if>
      <if test="tenantId != null" >
        #{tenantId,jdbcType=VARCHAR},
      </if>
      <if test="processInstanceId != null" >
        #{processInstanceId,jdbcType=VARCHAR},
      </if>
      <if test="processDefId != null" >
        #{processDefId,jdbcType=VARCHAR},
      </if>
      <if test="currentTaskId != null" >
        #{currentTaskId,jdbcType=VARCHAR},
      </if>
      <if test="currentUsers != null" >
        #{currentUsers,jdbcType=VARCHAR},
      </if>
      <if test="currentTaskName != null" >
        #{currentTaskName,jdbcType=VARCHAR},
      </if>
      <if test="createBy != null" >
        #{createBy,jdbcType=VARCHAR},
      </if>
      <if test="dateCreate != null" >
        #{dateCreate,jdbcType=TIMESTAMP},
      </if>
      <if test="updateBy != null" >
        #{updateBy,jdbcType=VARCHAR},
      </if>
      <if test="dateUpdate != null" >
        #{dateUpdate,jdbcType=TIMESTAMP},
      </if>
      <if test="geo != null" >
        #{geo,jdbcType=VARCHAR},
      </if>
      <if test="videos != null" >
        #{videos,jdbcType=VARCHAR},
      </if>
      <if test="pictures != null" >
        #{pictures,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.huaxu.order.entity.WorkOrderManage" >
    update sc_work_order_manage
    <set >
      <if test="taskNo != null" >
        task_no = #{taskNo,jdbcType=VARCHAR},
      </if>
      <if test="taskDesc != null" >
        task_desc = #{taskDesc,jdbcType=VARCHAR},
      </if>
      <if test="orderUserId != null" >
        order_user_id = #{orderUserId,jdbcType=VARCHAR},
      </if>
      <if test="sendTime != null" >
        send_time = #{sendTime,jdbcType=TIMESTAMP},
      </if>
      <if test="sendBy != null" >
        send_by = #{sendBy,jdbcType=VARCHAR},
      </if>
      <if test="planFinishDate != null" >
        plan_finish_date = #{planFinishDate,jdbcType=TIMESTAMP},
      </if>
      <if test="finishDate != null" >
        finish_date = #{finishDate,jdbcType=TIMESTAMP},
      </if>
      <if test="dateLimit != null" >
        date_limit = #{dateLimit,jdbcType=VARCHAR},
      </if>
      <if test="urgency != null" >
        urgency = #{urgency,jdbcType=VARCHAR},
      </if>
      <if test="address != null" >
        address = #{address,jdbcType=VARCHAR},
      </if>
      <if test="contactUser != null" >
        contact_user = #{contactUser,jdbcType=VARCHAR},
      </if>
      <if test="contactPhone != null" >
        contact_phone = #{contactPhone,jdbcType=VARCHAR},
      </if>
      <if test="orderTime != null" >
        order_time = #{orderTime,jdbcType=VARCHAR},
      </if>
      <if test="companyOrgId != null" >
        company_org_id = #{companyOrgId,jdbcType=VARCHAR},
      </if>
      <if test="departmentOrgId != null" >
        department_org_id = #{departmentOrgId,jdbcType=VARCHAR},
      </if>
      <if test="orderStatus != null" >
        order_status = #{orderStatus,jdbcType=INTEGER},
      </if>
      <if test="eventType != null" >
        event_type = #{eventType,jdbcType=INTEGER},
      </if>
      <if test="orderTypeId != null" >
        order_type_id = #{orderTypeId,jdbcType=INTEGER},
      </if>
      <if test="orderPid != null" >
        order_pid = #{orderPid,jdbcType=VARCHAR},
      </if>
      <if test="tenantId != null" >
        tenant_id = #{tenantId,jdbcType=VARCHAR},
      </if>
      <if test="processInstanceId != null" >
        process_instance_id = #{processInstanceId,jdbcType=VARCHAR},
      </if>
      <if test="processDefId != null" >
        process_def_id = #{processDefId,jdbcType=VARCHAR},
      </if>
      <if test="currentTaskId != null" >
        current_task_id = #{currentTaskId,jdbcType=VARCHAR},
      </if>
      <if test="currentUsers != null" >
        current_users = #{currentUsers,jdbcType=VARCHAR},
      </if>
      <if test="currentTaskName != null" >
        current_task_name = #{currentTaskName,jdbcType=VARCHAR},
      </if>
      <if test="createBy != null" >
        create_by = #{createBy,jdbcType=VARCHAR},
      </if>
      <if test="dateCreate != null" >
        date_create = #{dateCreate,jdbcType=TIMESTAMP},
      </if>
      <if test="updateBy != null" >
        update_by = #{updateBy,jdbcType=VARCHAR},
      </if>
      <if test="dateUpdate != null" >
        date_update = #{dateUpdate,jdbcType=TIMESTAMP},
      </if>
      <if test="geo != null" >
        geo = #{geo,jdbcType=VARCHAR},
      </if>
      <if test="videos != null" >
        videos=#{videos,jdbcType=VARCHAR},
      </if>
      <if test="pictures != null" >
        pictures=#{pictures,jdbcType=VARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.huaxu.order.entity.WorkOrderManage" >
    update sc_work_order_manage
    set task_no = #{taskNo,jdbcType=VARCHAR},
      task_desc = #{taskDesc,jdbcType=VARCHAR},
      order_user_id = #{orderUserId,jdbcType=VARCHAR},
      send_time = #{sendTime,jdbcType=TIMESTAMP},
      send_by = #{sendBy,jdbcType=VARCHAR},
      plan_finish_date = #{planFinishDate,jdbcType=TIMESTAMP},
      finish_date = #{finishDate,jdbcType=TIMESTAMP},
      date_limit = #{dateLimit,jdbcType=VARCHAR},
      urgency = #{urgency,jdbcType=VARCHAR},
      address = #{address,jdbcType=VARCHAR},
      contact_user = #{contactUser,jdbcType=VARCHAR},
      contact_phone = #{contactPhone,jdbcType=VARCHAR},
      order_time = #{orderTime,jdbcType=VARCHAR},
      company_org_id = #{companyOrgId,jdbcType=VARCHAR},
      department_org_id = #{departmentOrgId,jdbcType=VARCHAR},
      order_status = #{orderStatus,jdbcType=INTEGER},
      event_type = #{eventType,jdbcType=INTEGER},
      order_type_id = #{orderTypeId,jdbcType=INTEGER},
      order_pid = #{orderPid,jdbcType=VARCHAR},
      tenant_id = #{tenantId,jdbcType=VARCHAR},
      process_instance_id = #{processInstanceId,jdbcType=VARCHAR},
      process_def_id = #{processDefId,jdbcType=VARCHAR},
      current_task_id = #{currentTaskId,jdbcType=VARCHAR},
      current_users = #{currentUsers,jdbcType=VARCHAR},
      current_task_name = #{currentTaskName,jdbcType=VARCHAR},
      create_by = #{createBy,jdbcType=VARCHAR},
      date_create = #{dateCreate,jdbcType=TIMESTAMP},
      update_by = #{updateBy,jdbcType=VARCHAR},
      date_update = #{dateUpdate,jdbcType=TIMESTAMP},
      geo = #{geo,jdbcType=VARCHAR},
      videos = #{videos,jdbcType=VARCHAR},
      pictures = #{pictures,jdbcType=VARCHAR}
    where id = #{id,jdbcType=INTEGER}
  </update>

  <select id="selectAppTodo" resultMap="BaseResultMap">
    select id,task_no,send_time,address,order_type_id,create_by,update_by
    from sc_work_order_manage
    where find_in_set(#{userId},current_users) and tenant_id = #{tenantId}
    union
    select id,plan_id,plan_start_date,task_area_name,task_type,create_by,update_by
    from sc_plan_manage
    where find_in_set(#{userId},current_users) and tenant_id = #{tenantId}
    order by send_time
  </select>
  <select id="selectAppAll" resultMap="BaseResultMap">
    select id,task_no,send_time,address,order_type_id,current_task_name,create_by,update_by
    from sc_work_order_manage
    where (find_in_set(#{userId},current_users)
     or id in(select flow_id from sc_work_flow_log where flow_type=2 and find_in_set(#{userId},handle_user_id)))
     and tenant_id = #{tenantId}
    union
    select id,plan_id,plan_start_date,task_area_name,task_type,current_task_name,create_by,update_by
    from sc_plan_manage
    where (find_in_set(#{userId},current_users)
     or id in(select flow_id from sc_work_flow_log where flow_type=1 and find_in_set(#{userId},handle_user_id)))
     and tenant_id = #{tenantId}
    order by send_time
  </select>
  <select id="selectOrderDetail" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
    select t1.*,t2.flow_detail
    from sc_work_order_manage t1
    left join sc_work_flow_detail t2 on t1.id=t2.flow_id and t2.flow_type=2
    where t1.id = #{id,jdbcType=INTEGER} or t1.order_pid = #{orderPid,jdbcType=INTEGER}
    order by t1.order_pid
  </select>

  <insert id="batchInsertByAlarms" parameterType="com.huaxu.order.dto.WorkOrderManageByAlarmDto" keyProperty="id" useGeneratedKeys="true">
  insert into sc_work_order_manage( task_no, task_desc, address, order_time, company_org_id, department_org_id, order_status, event_type, order_pid, tenant_id, current_task_name,  date_create, date_update, geo)
 values
  <foreach collection="workOrderManages" item="item" index="index" separator=",">
    (#{item.taskNo} , #{item.taskDesc}, #{item.address}, #{item.orderTime}, #{item.companyOrgId}, #{item.departmentOrgId}, 0, 3, 0, #{item.tenantId}, '设备报警工单',  now(),  now(), #{item.geo})
  </foreach>
  </insert>



  <!--分页查询-->
  <select id="findPage" resultMap="OrderResultMap">
    select
    t1.id, t1.task_no, t1.task_desc, t1.order_user_id, t1.send_time, t1.send_by, t1.plan_finish_date, t1.finish_date,
    t1.date_limit, t1.urgency, t1.address, t1.contact_user, t1.contact_phone, t1.order_time, t1.company_org_id,
    t1.department_org_id, t1.order_status, t1.event_type, t1.order_type_id, t1.order_pid, t1.tenant_id,
    t1.process_instance_id, t1.process_def_id, t1.current_task_id, t1.current_users, t1.current_task_name,
    t1.create_by, t1.date_create, t1.update_by, t1.date_update, t1.geo,t1.videos,t1.pictures,
    t2.flow_detail,t2.create_by detail_create_by,t2.date_create detail_date_create,t2.update_by detail_update_by,t2.date_update detail_date_update
    from sc_work_order_manage t1 left  join sc_work_flow_detail t2
    on t1.id = t2.flow_id and t2.flow_type=2
    <where>
      <if test="order.tenantId != null and order.tenantId != ''">
        and t1.tenant_id = #{order.tenantId}
      </if>
      <if test="order.taskNo != null and order.taskNo != ''">
        and t1.task_no like CONCAT('%',#{order.taskNo},'%')
      </if>
      <if test="order.userType!=null and order.userType!=-999 and order.userType!=-9999 and  order.programItems != null and order.programItems.size() > 0">
        <if test="order.permissonType == 5 or order.permissonType == 2">
          and ( t1.DEPT_ORG_ID in
          <foreach collection="order.programItems" item="item" open="(" close=")" separator=",">
            #{item.orgId}
          </foreach>
          or
          t1.COMPANY_ORG_ID in
          <foreach collection="order.programItems" item="item" open="(" close=")" separator=",">
            #{item.orgId}
          </foreach>
          )
        </if>
        <if test="order.permissonType == 4 or order.permissonType == 3">
          and t1.DEPT_ORG_ID in
          <foreach collection="order.programItems" item="item" open="(" close=")" separator=",">
            #{item.orgId}
          </foreach>
        </if>
        <if test="plan.permissonType == 1">
          and t1.COMPANY_ORG_ID in
          <foreach collection="plan.programItems" item="item" open="(" close=")" separator=",">
            #{item.orgId}
          </foreach>
          and (t1.DEPT_ORG_ID is null or t1.DEPT_ORG_ID =0)
        </if>
      </if>
      <if test="order.orderStatus != null">
        and t1.order_status =  #{order.orderStatus,jdbcType=INTEGER}
      </if>
      <if test="order.orderStatus == null">
        and t1.order_status != 0
      </if>
      <if test="order.orderTypeId != null">
        and t1.order_type_id = #{plan.orderTypeId,jdbcType=INTEGER}
      </if>
      <if test="order.eventType != null">
        and t1.event_type = #{order.eventType,jdbcType=INTEGER}
      </if>
      <if test="order.currentUsers != null">
        and  INSTR(t1.current_users,#{plan.currentUsers})
      </if>
      <if test="order.startDate != null and order.endDate != null">
        and t1.date_create &gt;= date_format(#{order.startDate,jdbcType=VARCHAR},'%Y-%c-%d')
        and t1.date_create &lt;= DATE_ADD(date_format(#{order.endDate,jdbcType=VARCHAR},'%Y-%c-%d'),INTERVAL 1 DAY)
      </if>
    </where>
    order by t1.date_create
  </select>
  <!--删除-->
  <delete id="batchDelete">
    delete from  sc_work_order_manage
    where order_status = 0
    and id in
    <foreach collection="ids" item="item" open="(" close=")" separator=",">
      #{item}
    </foreach>
  </delete>
  <!--根据orderPid 查询工单-->
  <select id="selectByPId" parameterType="map" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List"></include>
    from sc_work_order_manage
    where order_pid =  #{orderPid,jdbcType=VARCHAR}
  </select>
</mapper>