<?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.api.manage.dao.butlerService.SysRepairEngineeringDao">

    <select id="list" parameterType="com.api.model.butlerService.SearchRepairEngineering" resultType="com.api.vo.butlerService.VoRepairEngineering">
        select srre.*,su1.actual_name as create_name,su1.tel as create_tel,so.name as organization_name,
        su2.actual_name as maintenance_staff_name,so2.name as subordinate_departments
        from sys_user as su1,sys_report_repair_engineering as srre
        LEFT JOIN sys_organization as so on srre.organization_id = so.id
        LEFT JOIN sys_user as su2 on srre.maintenance_staff = su2.id
        LEFT JOIN sys_organization as so2 on su2.organization_id = so2.id
        <where>
            srre.create_id = su1.id
            <if test="code != null and code != ''">
                and srre.code like concat('%',#{code},'%')
            </if>
            <if test="status != null">
                and srre.status = #{status}
            </if>
            <if test="repairArea != null and repairArea != ''">
                and srre.repair_area like concat('%',#{repairArea},'%')
            </if>
        </where>
    </select>
    <select id="findById" parameterType="java.lang.Integer" resultType="com.api.vo.butlerService.VoRepairEngineeringFBI">
        select srre.*,su1.actual_name as create_name,su1.tel as create_tel,so.name as organization_name,
        su2.actual_name as leading_name,su2.tel as leading_tel,su3.actual_name as maintenance_staff_name,
        su3.tel as maintenance_staff_tel,so2.name subordinate_departments_name
        from sys_user as su1,sys_report_repair_engineering as srre
        LEFT JOIN sys_organization as so on srre.organization_id = so.id
        LEFT JOIN sys_user as su2 on so.leading_id = su2.id
        LEFT JOIN sys_user as su3 on srre.maintenance_staff = su3.id
        LEFT JOIN sys_organization as so2 on su3.organization_id = so2.id
        where srre.create_id = su1.id and srre.id = #{repairEngineeringId}
    </select>
    <select id="findReportByRepairEngineeringId" parameterType="java.lang.Integer"
            resultType="com.api.vo.butlerService.VoRepairEngineeringReport">
        select * from sys_report_repair_engineering_report
        where repair_engineering_id = #{repairEngineeringId}
    </select>
    <select id="findRecordByRepairEngineeringId" parameterType="java.lang.Integer"
            resultType="com.api.vo.butlerService.VoRepairEngineeringProcessRecord">
        select * from sys_report_repair_engineering_process_record
        where repair_engineering_id = #{repairEngineeringId}
        order by operation_date desc
    </select>
    <select id="findResultsByRepairEngineeringId" parameterType="java.lang.Integer"
            resultType="com.api.vo.butlerService.VoRepairEngineeringMaintenanceResults">
        select * from sys_report_repair_engineering_maintenance_results
        where repair_engineering_id = #{repairEngineeringId}
    </select>
</mapper>