<?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.lutao.cloud.oil.mapper.DivisionInspectionDetailMapper">

    <select id="getDivisionInspectionDetailPage"
            resultType="com.lutao.cloud.oil.pojo.vo.DivisionInspectionDetailVO">
        SELECT
            ai.app_name AS appName,
            pi.platform_name AS platformName,
            pi.oil_gas_name AS oilGasName,
            pi.operating_company AS operationCompany,
            did.facility_name AS facilityName,
            did.hidden_problems AS hiddenProblems,
            did.treatment_measures AS treatmentMeasures,
            did.hidden_problems_state AS hiddenProblemsState,
            did.input_time AS inputTime,
            did.rectification_period AS rectificationPeriod
        FROM
            division_inspection_detail did
                LEFT JOIN app_info ai ON did.app_id = ai.id
                LEFT JOIN platform_info pi ON did.platform_code = pi.platform_code
        <where>
            pi.delete_flag = '0'
            <if test="param.platformId != null and param.platformId != ''">
                and did.platform_code = #{param.platformId}
            </if>
            <if test="param.appId != null and param.appId != ''">
                and did.app_id = #{param.appId}
            </if>
            <if test="param.operatingCompany != null and param.operatingCompany != ''">
                and pi.operating_company = #{param.operatingCompany}
            </if>
            <if test="param.oilGasName != null and param.oilGasName != ''">
                and pi.oil_gas_name = #{param.oilGasName}
            </if>
            <if test="param.year != null and param.year != ''">
                and YEAR(did.input_time) = #{param.year}
            </if>
            <if test="param.rectifyStartTime != null">
                and did.rectification_period &gt;= #{param.rectifyStartTime}
            </if>
            <if test="param.rectifyEndTime != null">
                and did.rectification_period &lt;= #{param.rectifyEndTime}
            </if>
            <choose>
                <when test="param.status == 1">
                    and did.hidden_problems_state = '001'
                </when>
                <when test="param.status == 2">
                    and did.hidden_problems_state = '002'
                </when>
            </choose>
        </where>
        ORDER BY hiddenProblemsState ASC, inputTime DESC,appName,platformName,oilGasName,operationCompany
    </select>
</mapper>