<iftest="serialNumber !=null and serialNumber !=''">
(select count(charging_station_id) from xhpc_mechanism where community_id=mechanism_id and source=0 and charging_station_id in (select charging_station_id from xhpc_terminal where 1=1 and del_flag=0 and serial_number=#{serialNumber})) as number,
<iftest="serialNumber !=null and serialNumber !=''">
(select count(charging_station_id) from xhpc_mechanism where customers_id=mechanism_id and source=1 and charging_station_id in (select charging_station_id from xhpc_terminal where 1=1 and del_flag=0 and serial_number=#{serialNumber})) as number,
join xhpc_community xc on xc.community_id = xcp.community_id and xc.del_flag =0
left join xhpc_history_order xho on xho.source =2 and xho.user_id =xcp.community_personnel_id
where xcp.tenant_id=#{tenantId} and xcp.del_flag=0
<iftest="number==1 or number==2">
and xcp.create_type=2 and xcp.create_id=#{userId}
</if>
<iftest="type==1">
and xcp.create_type=2 and xcp.create_id=#{userId}
</if>
<iftest="chargingStationId !=null">
and xcp.create_id=(select operator_id from xhpc_charging_station where charging_station_id=#{chargingStationId})
</if>
<iftest="operatorId !=null">
and xcp.create_id=#{operatorId}
</if>
<iftest="chargingPileId !=null">
and xcp.create_id=(select operator_id from xhpc_charging_station where charging_station_id=(select terminal_id from xhpc_charging_pile where charging_pile_id=#{chargingPileId}))
join xhpc_customers xuc on xuc.customers_id = xcup.customers_personnel_id and xuc.del_flag =0
left join xhpc_history_order xho on xho.source =3 and xho.user_id =xcup.customers_personnel_id
where xcup.tenant_id=#{tenantId} and xcup.del_flag=0
<iftest="number==1 or number==2">
and xcup.create_type=2 and xcup.create_id=#{userId}
</if>
<iftest="type==1">
and xcup.create_type=2 and xcup.create_id=#{userId}
</if>
<iftest="chargingStationId !=null">
and xcup.create_id=(select operator_id from xhpc_charging_station where charging_station_id=#{chargingStationId})
</if>
<iftest="operatorId !=null">
and xcup.create_id=#{operatorId}
</if>
<iftest="chargingPileId !=null">
and xcup.create_id=(select operator_id from xhpc_charging_station where charging_station_id=(select terminal_id from xhpc_charging_pile where charging_pile_id=#{chargingPileId}))
join xhpc_community xc on xc.community_id = xcp.community_id and xc.del_flag =0
left join xhpc_history_order xho on xho.source =2 and xho.user_id =xcp.community_personnel_id
where xcp.tenant_id=#{tenantId} and xcp.del_flag=0
<iftest="number==1 or number==2">
and xcp.create_type=2 and xcp.create_id=#{userId}
</if>
<iftest="type==1">
and xcp.create_type=2 and xcp.create_id=#{userId}
</if>
<iftest="chargingStationId !=null">
and xcp.create_id=(select operator_id from xhpc_charging_station where charging_station_id=#{chargingStationId})
</if>
<iftest="operatorId !=null">
and xcp.create_id=#{operatorId}
</if>
<iftest="chargingPileId !=null">
and xcp.create_id=(select operator_id from xhpc_charging_station where charging_station_id=(select terminal_id from xhpc_charging_pile where charging_pile_id=#{chargingPileId}))
join xhpc_customers xuc on xuc.customers_id = xcup.customers_personnel_id and xuc.del_flag =0
left join xhpc_history_order xho on xho.source =3 and xho.user_id =xcup.customers_personnel_id
where xcup.tenant_id=#{tenantId} and xcup.del_flag=0
<iftest="number==1 or number==2">
and xcup.create_type=2 and xcup.create_id=#{userId}
</if>
<iftest="type==1">
and xcup.create_type=2 and xcup.create_id=#{userId}
</if>
<iftest="chargingStationId !=null">
and xcup.create_id=(select operator_id from xhpc_charging_station where charging_station_id=#{chargingStationId})
</if>
<iftest="operatorId !=null">
and xcup.create_id=#{operatorId}
</if>
<iftest="chargingPileId !=null">
and xcup.create_id=(select operator_id from xhpc_charging_station where charging_station_id=(select terminal_id from xhpc_charging_pile where charging_pile_id=#{chargingPileId}))