<?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="org.springblade.modules.business.check.order.mapper.RtuCheckOrderMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="checkOrderInfoResultMap" type="org.springblade.modules.business.check.order.entity.CheckOrderInfoEntity">
        <result column="id" property="id"/>
        <result column="create_user" property="createUser"/>
        <result column="create_time" property="createTime"/>
        <result column="update_user" property="updateUser"/>
        <result column="update_time" property="updateTime"/>
        <result column="status" property="status"/>
        <result column="is_deleted" property="isDeleted"/>
        <result column="rtu_code" property="rtuCode"/>
        <result column="order_desc" property="orderDesc"/>
        <result column="order_from_key" property="orderFromKey"/>
        <result column="order_status_key" property="orderStatusKey"/>
        <result column="order_confirm_user" property="orderConfirmUser"/>
        <result column="warn_id" property="warnId"/>
        <result column="order_close" property="orderClose"/>
        <result column="order_confirm" property="orderConfirm"/>

    </resultMap>

    <!-- 通用查询映射结果 -->
    <resultMap id="checkOrderInfoVOResultMap" type="org.springblade.modules.business.check.order.vo.CheckOrderInfoVO">
        <result column="id" property="id"/>
        <result column="create_user" property="createUser"/>
        <result column="create_time" property="createTime"/>
        <result column="update_user" property="updateUser"/>
        <result column="update_time" property="updateTime"/>
        <result column="status" property="status"/>
        <result column="is_deleted" property="isDeleted"/>
        <result column="rtu_code" property="rtuCode"/>
        <result column="order_desc" property="orderDesc"/>
        <result column="order_from_key" property="orderFromKey"/>
        <result column="order_status_key" property="orderStatusKey"/>
        <result column="order_confirm_user" property="orderConfirmUser"/>
        <result column="rtu_name" property="rtuName"/>
        <result column="real_name" property="processorName"/>
        <result column="project_name" property="projectName"/>
        <result column="org_name" property="orgName"/>
        <result column="warn_id" property="warnId"/>
        <result column="order_close" property="orderClose"/>
        <result column="order_confirm" property="orderConfirm"/>
        <result column="lng" property="lng"/>
        <result column="lat" property="lat"/>
        <result column="location_desc" property="locationDesc"/>
    </resultMap>


    <select id="selectPage" resultMap="checkOrderInfoVOResultMap">
        SELECT
         o.*,u.real_name,i.rtu_name,p.project_name,d2.dept_name AS org_name,i.lng,i.lat,i.location_desc
        FROM
        rtu_failure_check_order o
        LEFT JOIN rtu_info i ON i.rtu_code = o.rtu_code
        LEFT JOIN blade_user u ON u.id = o.update_user
        LEFT JOIN project_info p ON i.project_id = p.id
        LEFT JOIN blade_user_dept ud ON ud.user_id=u.id
        LEFT JOIN blade_dept d2 ON ud.dept_id = d2.id
        WHERE
        o.is_deleted = 0
        <if test="checkOrderInfoDTO.rtuCode!=null">
            and o.rtu_code like concat(concat('%', #{checkOrderInfoDTO.rtuCode}), '%')
        </if>
        <if test="checkOrderInfoDTO.rtuName!=null">
            and i.rtu_name like concat(concat('%', #{checkOrderInfoDTO.rtuName}), '%')
        </if>
        <if test="checkOrderInfoDTO.orgId!=null">
            and i.org_id = #{checkOrderInfoDTO.orgId}
        </if>
        <if test="checkOrderInfoDTO.projectId !=null">
            and i.project_id = #{checkOrderInfoDTO.projectId}
        </if>
        <if test="checkOrderInfoDTO.orderConfirmUser!=null">
            and o.order_confirm_user = #{checkOrderInfoDTO.orderConfirmUser}
        </if>

        <if test="checkOrderInfoDTO.createTime!=null">
            and o.create_time >= #{checkOrderInfoDTO.createTime}
        </if>


        <if test="checkOrderInfoDTO.orderClose!=null">
            and o.order_close >= #{checkOrderInfoDTO.orderClose}
        </if>


        <if test="checkOrderInfoDTO.orderConfirm!=null">
            and o.order_confirm >= #{checkOrderInfoDTO.orderConfirm}
        </if>

         order by o.update_time desc

    </select>

    <select id="unconfirmOrderList" resultMap="checkOrderInfoVOResultMap">
        SELECT
        o.*,u.real_name,i.rtu_name,p.project_name,d2.dept_name AS org_name,i.lng,i.lat,i.location_desc
        FROM
        rtu_failure_check_order o
        LEFT JOIN rtu_info i ON i.rtu_code = o.rtu_code
        LEFT JOIN blade_user u ON u.id = o.update_user
        LEFT JOIN project_info p ON i.project_id = p.id
        LEFT JOIN blade_user_dept ud ON ud.user_id=u.id
        LEFT JOIN blade_dept d2 ON ud.dept_id = d2.id
        WHERE
        o.is_deleted = 0

        <if test="checkOrderInfoDTO.orgId!=null">
            and i.org_id = #{checkOrderInfoDTO.orgId}
        </if>


        <if test="checkOrderInfoDTO.orderConfirm!=null">
            and o.order_confirm = #{checkOrderInfoDTO.orderConfirm}
        </if>

        order by o.create_time desc

    </select>

    <select id="selectPage" resultMap="checkOrderInfoVOResultMap">
        SELECT
        o.*,u.real_name,i.rtu_name,p.project_name,d2.dept_name AS org_name,i.lng,i.lat,i.location_desc
        FROM
        rtu_failure_check_order o
        LEFT JOIN rtu_info i ON i.rtu_code = o.rtu_code
        LEFT JOIN blade_user u ON u.id = o.update_user
        LEFT JOIN project_info p ON i.project_id = p.id
        LEFT JOIN blade_user_dept ud ON ud.user_id=u.id
        LEFT JOIN blade_dept d2 ON ud.dept_id = d2.id
        WHERE
        o.is_deleted = 0
        <if test="checkOrderInfoDTO.rtuCode!=null">
            and o.rtu_code like concat(concat('%', #{checkOrderInfoDTO.rtuCode}), '%')
        </if>
        <if test="checkOrderInfoDTO.rtuName!=null">
            and i.rtu_name like concat(concat('%', #{checkOrderInfoDTO.rtuName}), '%')
        </if>
        <if test="checkOrderInfoDTO.orgId!=null">
            and i.org_id = #{checkOrderInfoDTO.orgId}
        </if>
        <if test="checkOrderInfoDTO.projectId !=null">
            and i.project_id = #{checkOrderInfoDTO.projectId}
        </if>
        <if test="checkOrderInfoDTO.orderConfirmUser!=null">
            and o.order_confirm_user = #{checkOrderInfoDTO.orderConfirmUser}
        </if>

        <if test="checkOrderInfoDTO.createTime!=null">
            and o.create_time >= #{checkOrderInfoDTO.createTime}
        </if>


        <if test="checkOrderInfoDTO.orderClose!=null">
            and o.order_close >= #{checkOrderInfoDTO.orderClose}
        </if>


        <if test="checkOrderInfoDTO.orderConfirm!=null">
            and o.order_confirm >= #{checkOrderInfoDTO.orderConfirm}
        </if>

        order by o.update_time desc

    </select>
</mapper>
