<?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.yeejoin.amos.boot.module.hygf.api.mapper.AcceptanceRectificationOrderMapper">
    <select id="page" resultType="com.yeejoin.amos.boot.module.hygf.api.dto.AcceptanceRectificationOrderDto">
        SELECT
            aro.sequence_nbr AS sequenceNbr,
            bga.work_order_power_station_id AS workOrderPowerStationId,
            ph.peasant_household_no as powerStationCode,
            ph.owners_name AS ownersName,
            ph.project_address_name AS powerStationAddress,
            aro.rectification_status AS rectificationStatus,
            ph.regional_companies_seq regionCompanyId,
            CASE aro.rectification_status
                WHEN 1 THEN '待整改'
                WHEN 2 THEN '整改未完成'
                WHEN 3 THEN '整改已完成'
                ELSE ''
            END AS rectificationStatusDesc
        FROM
            hygf_acceptance_rectification_order aro
                 LEFT JOIN hygf_basic_grid_acceptance bga ON bga.peasant_household_id = aro.peasant_household_id
                 LEFT JOIN hygf_peasant_household ph ON ph.sequence_nbr = bga.peasant_household_id
        <where>
            aro.is_delete = 0
            <if test="acceptanceSeqNbr != null and acceptanceSeqNbr != ''">
                AND bga.sequence_nbr = #{acceptanceSeqNbr}
            </if>
        </where>
        ORDER BY
            aro.rectification_status DESC,
            aro.rec_date DESC
    </select>

    <select id="queryBySequenceNbr"
            resultType="com.yeejoin.amos.boot.module.hygf.api.dto.AcceptanceRectificationOrderDto">
        SELECT
            aro.*,
            aro.rectification_photo AS rectificationPhotoStr,
            ph.peasant_household_no as powerStationCode,
            ph.owners_name AS ownersName,
            ph.project_address_name AS powerStationAddress,
            aro.rectification_status AS rectificationStatus,
            CASE aro.rectification_status
                WHEN 1 THEN '待整改'
                WHEN 2 THEN '整改未完成'
                WHEN 3 THEN '整改已完成'
                ELSE ''
            END AS rectificationStatusDesc
        FROM
            hygf_acceptance_rectification_order aro
                LEFT JOIN hygf_basic_grid_acceptance bga ON bga.peasant_household_id = aro.peasant_household_id
                LEFT JOIN hygf_peasant_household ph ON ph.sequence_nbr = bga.peasant_household_id
        <where>
            aro.is_delete = 0
            <if test="sequenceNbr != null and sequenceNbr != ''">
                AND aro.sequence_nbr = #{sequenceNbr}
            </if>
        </where>
    </select>
</mapper>
