<?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.PowerStationMapper">
<select id="queryPage" resultType="com.yeejoin.amos.boot.module.hygf.api.dto.PowerStationDto">
    select * from (select
    hygf_power_station.*,
    b.initiate_status,
    b.contract_lock_id,
    hygf_peasant_household.regional_companies_code,
    hygf_peasant_household.regional_companies_name,
    hygf_peasant_household.developer_code,
    hygf_peasant_household.developer_user_id,
    hygf_peasant_household.project_address_detail,
    b.stamp_status,
    b.status
    from hygf_power_station LEFT JOIN ( select peasant_household_id,initiate_status, contract_lock_id,stamp_status,status from  hygf_household_contract where   hygf_household_contract.status !='已作废'
    ) b    on b.peasant_household_id=hygf_power_station.peasant_household_id
    LEFT JOIN hygf_peasant_household on hygf_peasant_household.sequence_nbr=hygf_power_station.peasant_household_id
    where hygf_power_station.is_delete=0

    <if test="powerStationCode!=null and powerStationCode!=''">
        and hygf_power_station.power_station_code like concat(concat("%",#{powerStationCode}),"%")
    </if>
    <if test="ownersName!=null and ownersName!=''">
        and hygf_power_station.owners_name like concat(concat("%",#{ownersName}),"%")
    </if>
    <if test="serviceAgent!=null and serviceAgent!=''">
        and hygf_power_station.service_agent like concat(concat("%",#{serviceAgent}),"%")
    </if>
    <if test="regionalCompaniesName!=null and regionalCompaniesName!=''">
        and hygf_peasant_household.regional_companies_name like concat(concat("%",#{regionalCompaniesName}),"%")
    </if>
    <if test="processStatus != null and processStatus != ''">
        and hygf_power_station.process_status = #{processStatus}
    </if>
    ORDER BY hygf_power_station.rec_date desc
    ) a
</select>
</mapper>
