<?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.chushang.inspection.work.mapper.WrkInfoTerminalRecordMapper">

    <select id="minePageList" resultType="com.chushang.inspection.terminal.vo.StoreTerminalVO">
        SELECT pt.project_id          AS projectId,
               p.project_name         AS projectName,

               i.task_id              AS task_id,
               i.`task_name`          AS taskName,
               i.lower_task_id        AS lowerTaskId,
               lpt.`name`             AS lowerTaskName,
               i.dept_id              AS deptId,
               i.dept_name            AS deptName,
               i.work_no              AS workNo,
               i.wrk_id               AS wrkId,

               s.store_id             AS storeId,
               s.store_no             AS storeNo,
               s.store_name           AS storeName,
               s.store_contact        AS storeContact,
               s.store_phone          AS storePhone,
               s.shop_name            AS shopName,
               s.special_num          AS specialNum,
               s.store_address        AS storeAddress,
               s.store_type           AS storeType,
               s.products             AS products,
               s.tip_tool             AS tipTool,
               s.register_time        AS registerTime,
               s.register_address     AS registerAddress,
               s.legal_name           AS legalName,
               s.create_by            AS createBy,
               s.create_time          AS createTime,
               s.state                AS storeState,
               s.ins_fre              AS insFre,
               s.account_phone        AS accountPhone,
               s.account_manager      AS accountManager,
               t.terminal_id          AS terminalId,
               t.terminal_no          AS terminalNo,
               t.terminal_sn          AS terminalSn,
               t.terminal_type        AS terminalType,
               t.terminal_model       AS terminalModel,
               t.terminal_version     AS terminalVersion,
               t.terminal_address     AS terminalAddress,
               t.terminal_source      AS terminalSource,
               t.occupy               AS occupy,
               t.terminal_status      AS terminalStatus,
               ti.deviation           AS deviation,
               ti.operator_id         AS operatorId,
               ti.inspection_status   AS inspectionStatus,
               ti.inspection_time     AS inspectionTime,
               ti.times_pass          AS timesPass,
               ti.service_result      AS serviceResult,
               ti.geographic_address  AS geographicAddress,
               ti.geographic_location AS geographicLocation,
               ti.work_location       AS workLocation,
               ti.work_address        AS workAddress
        FROM wrk_info i
                 LEFT JOIN ta_polling_task pt ON i.task_id = pt.id
                 LEFT JOIN wrk_project p ON pt.project_id = p.project_id
                 INNER JOIN wrk_info_store_record s ON i.wrk_id = s.wrk_id
                 INNER JOIN wrk_info_terminal_record t ON i.wrk_id = t.wrk_id
                 LEFT JOIN wrk_info_terminal_ins_record ti ON i.wrk_id = ti.wrk_id
                 LEFT JOIN ta_polling_task lpt ON i.task_id = lpt.id
        WHERE i.del_state = 0
        <if test="1 == 1">
            ${query.sqlParam.get('sqlWhere')}
        </if>
        <if test="1 == 1">
            ${query.sqlParam.get('dataScope')}
        </if>
        ORDER BY i.${query.orderBy} ${query.isAsc}
    </select>
</mapper>
