hsi.*,hph.id_card,hph.peasant_household_no,hph.owners_name,hph.telephone,hph.project_address_name,hph.project_address_detail,hph.permanent_address_name,hph.permanent_address_detail,hph.sequence_nbr AS stationId
FROM
hygf_survey_information hsi
LEFT JOIN hygf_peasant_household hph ON hph.survey_information_id=hsi.sequence_nbr
hpsei.*,hwops.peasant_household_id AS stationId,hpsc.construction_component_info,hpsc.construction_inverter_info,hpsc.construction_collector_box_info,hpsc.construction_grid_box_info
FROM
hygf_power_station_engineering_info hpsei
LEFT JOIN hygf_work_order_power_station hwops ON hwops.sequence_nbr=hpsei.work_order_power_station_id
LEFT JOIN hygf_power_station_construction_data hpsc on hpsc.work_order_power_station_id=hpsei.work_order_power_station_id
from hygf_work_order_power_station LEFT join hygf_work_order
on hygf_work_order.sequence_nbr=hygf_work_order_power_station.work_order_id
LEFT JOIN hygf_peasant_household on hygf_peasant_household.sequence_nbr=hygf_work_order_power_station.peasant_household_id
LEFT JOIN hygf_power_station_engineering_info on hygf_power_station_engineering_info.work_order_power_station_id=hygf_work_order_power_station.sequence_nbr
<where>
<iftest="dto.workOrderId!=null and dto.workOrderId!=''">
and hygf_work_order.sequence_nbr = #{dto.workOrderId}
</if>
<iftest=' dto.type!=null and dto.type == "1"'>
and hygf_work_order_power_station.power_station_construction_status in ('待登记','未通过','已完工','待审核')
</if>
<iftest=' dto.type !=null and dto.type == "2"'>
and hygf_work_order_power_station.power_station_construction_status IN ( '未通过', '已完工', '待审核', '待整改', '整改中','整改待审核' )
</if>
<iftest=' dto.type !=null and dto.type == "3" and dto.workOrderPowerStationNodes !=null'>
and ( hygf_work_order_power_station.work_order_power_station_node is not null
or hygf_work_order_power_station.work_order_power_station_node = 'all'
or hygf_work_order_power_station.power_station_area_status is not null
or hygf_work_order_power_station.power_station_design_status is not null
or hygf_work_order_power_station.power_station_engineering_status is not null
)
</if>
<iftest="dto.projectAddressName!=null and dto.projectAddressName!=''">
and hygf_peasant_household.project_address_name like concat(concat('%',#{dto.projectAddressName}),'%')
</if>
<iftest="dto.peasantHouseholdNo!=null and dto.peasantHouseholdNo!=''">
and hygf_peasant_household.peasant_household_no like concat(concat('%',#{dto.peasantHouseholdNo}),'%')
</if>
<iftest="dto.ownersName!=null and dto.ownersName!=''">
and hygf_peasant_household.owners_name like concat(concat('%',#{dto.ownersName}),'%')
</if>
<iftest="dto.workOrderNum!=null and dto.workOrderNum!=''">
and hygf_work_order.work_order_num like concat(concat('%',#{dto.workOrderNum}),'%')
</if>
<iftest="dto.projectRegionManager!=null and dto.projectRegionManager!=''">
and hygf_work_order.project_region_manager like concat(concat('%',#{dto.projectRegionManager}),'%')
</if>
<iftest="dto.powerStationConstructionStatus!=null and dto.powerStationConstructionStatus!=''">
and hygf_work_order_power_station.power_station_construction_status=#{dto.powerStationConstructionStatus}
</if>
<iftest="dto.amosDealerId!=null and dto.amosDealerId!=''">
and hygf_work_order.amos_dealer_id = #{dto.amosDealerId}
</if>
<iftest="dto.regionCompanyId!=null and dto.regionCompanyId!=''">
and hygf_work_order.region_company_id =#{dto.regionCompanyId}
</if>
<iftest="dto.province != null and dto.province != ''">
and hygf_peasant_household.project_address like concat(concat('%',#{dto.province}),'%')
hygf_document_station.preparation_money_id as preparationMoneyId,
hygf_preparation_money.delivery_time as deliveryTime,
hygf_preparation_money.arrival_time as arrivalTime,
(select instance_id from hygf_preparation_money_auditing where hygf_document_station.preparation_money_id = hygf_preparation_money_auditing.preparation_money_id limit 1) as instanceId from
hygf_peasant_household
LEFT JOIN hygf_document_station on hygf_peasant_household.sequence_nbr = hygf_document_station.station_id
LEFT JOIN hygf_power_station on hygf_peasant_household.sequence_nbr = hygf_power_station.peasant_household_id
LEFT JOIN hygf_preparation_money on hygf_preparation_money.sequence_nbr = hygf_document_station.preparation_money_id
<where>
<iftest=" map.preparationMoneyState == 0 ">
and hygf_peasant_household.preparation_money_state in ('待发货','待补货','暂存发货')
</if>
<iftest="map.regionalCompaniesSeq!=null and map.regionalCompaniesSeq !='' ">
and hygf_peasant_household.regional_companies_code like concat('%',#{map.regionalCompaniesSeq},'%')
</if>
<iftest="map.developerId!=null and map.developerId !=''">
and hygf_peasant_household.developer_code like concat('%',#{map.developerId},'%')
</if>
<iftest="map.state!=null and map.state !=''">
and hygf_peasant_household.preparation_money_state = #{map.state}
</if>
<iftest="map.ownersName!=null and map.ownersName !=''">
and hygf_peasant_household.owners_name like concat ('%',#{map.ownersName},'%')
</if>
<iftest=" map.preparationMoneyState == 1 ">
and hygf_peasant_household.preparation_money_state not in ('待发货','待补货','暂存发货') and preparation_money_state is not null and preparation_money_state != ''
</if>
<iftest="map.province != null and map.province != ''">
and hygf_peasant_household.project_address like concat(concat('%',#{map.province}),'%')
</if>
</where>
<iftest=" map.preparationMoneyState == 1 ">
order by hygf_preparation_money.delivery_time DESC
substring_index ( hygf_peasant_household.project_address_name, '/', 1 ) AS province,
b.stamp_status,
b.status
from hygf_power_station LEFT JOIN ( SELECT bb.peasant_household_id, initiate_status, contract_lock_id, stamp_status, status FROM (SELECT peasant_household_id,MAX(sequence_nbr) AS sequence_nbr from hygf_household_contract GROUP BY peasant_household_id ) aa LEFT JOIN hygf_household_contract bb ON aa.sequence_nbr=bb.sequence_nbr) 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
<iftest="powerStationCode!=null and powerStationCode!=''">
and hygf_power_station.power_station_code like concat(concat('%',#{powerStationCode}),'%')
SELECT DISTINCT
ps.sequence_nbr,
ps.power_station_code,
ps.owners_name,
ps.project_address,
ps.service_agent,
ps.power_station_type,
ps.process_status,
ps.design_status,
ps.business_status,
ps.technology_status,
ps.process_instance_id,
ps.peasant_household_id,
ps.task_id,
ps.node_routing,
ps.process_definition_id,
ps.node_role,
ps.next_process_node,
ps.flow_task_id,
ps.plan_instance_id,
ps.drawing_review,
ps.next_node_name,
ps.next_execute_user_ids,
lc.initiate_status,
lc.contract_lock_id,
ph.regional_companies_code,
ph.regional_companies_name,
ph.developer_code,
ph.developer_user_id,
ph.project_address_detail,
SUBSTRING_INDEX(ph.project_address_name, '/', 1) AS province,
lc.stamp_status,
lc.status
FROM
hygf_power_station ps
LEFT JOIN (
SELECT
peasant_household_id,
initiate_status,
contract_lock_id,
stamp_status,
status
FROM (
SELECT
hhc.*,
ROW_NUMBER() OVER (PARTITION BY peasant_household_id ORDER BY sequence_nbr DESC) AS rn
FROM
hygf_household_contract hhc
) subq
WHERE subq.rn = 1
) lc
ON lc.peasant_household_id = ps.peasant_household_id
LEFT JOIN hygf_peasant_household ph
ON ph.sequence_nbr = ps.peasant_household_id
WHERE
ps.is_delete = 0
<iftest="powerStationCode != null and powerStationCode != ''">
AND ps.power_station_code LIKE CONCAT('%', #{powerStationCode}, '%')
</if>
<iftest="ownersName!=null and ownersName!=''">
and hygf_power_station.owners_name like concat(concat('%',#{ownersName}),'%')
<iftest="ownersName != null and ownersName != ''">
AND ps.owners_name LIKE CONCAT('%', #{ownersName}, '%')
</if>
<iftest="serviceAgent!=null and serviceAgent!=''">
and hygf_power_station.service_agent like concat(concat('%',#{serviceAgent}),'%')
<iftest="serviceAgent != null and serviceAgent != ''">
AND ps.service_agent LIKE CONCAT('%', #{serviceAgent}, '%')
</if>
<iftest="regionalCompaniesName!=null and regionalCompaniesName!=''">
and hygf_peasant_household.regional_companies_name like concat(concat('%',#{regionalCompaniesName}),'%')
<iftest="regionalCompaniesName != null and regionalCompaniesName != ''">
AND ph.regional_companies_name LIKE CONCAT('%', #{regionalCompaniesName}, '%')
</if>
<iftest="processStatus != null and processStatus != ''">
and hygf_power_station.process_status = #{processStatus}
AND ps.process_status = #{processStatus}
</if>
<iftest="province != null and province != ''">
and hygf_peasant_household.project_address like concat(concat('%',#{province}),'%')
AND ph.project_address_name LIKE CONCAT('%', #{province}, '%')
</if>
<!-- GROUP BY hygf_peasant_household.sequence_nbr-->
SUM(CASE WHEN ps.process_status = '不通过' THEN 1 ELSE 0 END)AS '未通过',
SUM(CASE WHEN ps.process_status = '进行中' AND ps.business_status = '通过' AND next_node_name = '设计上传典型图库' THEN 1 ELSE 0 END) AS '已完成(法务审核)',
SUM(CASE WHEN ps.process_status = '完成' THEN 1 ELSE 0 END) AS completeTotal,
SUM(CASE WHEN ps.process_status = '进行中' AND (ps.business_status IS NULL OR ps.design_status IS NULL OR ps.technology_status IS NULL or ps.business_status = '' OR ps.design_status = '' OR ps.technology_status = '') THEN 1 ELSE 0 END) AS '进行中(审核)'
FROM
hygf_power_station ps
LEFT JOIN
hygf_peasant_household ph ON ps.peasant_household_id = ph.sequence_nbr
WHERE
ps.is_delete = 0
<iftest="developerCode != null and developerCode != ''">
AND ph.developer_code = #{developerCode}
</if>
<iftest="regionalCompaniesCode != null and regionalCompaniesCode != ''">
AND ph.regional_companies_code = #{regionalCompaniesCode}
</if>
<iftest="province != null and province != ''">
AND ph.project_address LIKE CONCAT ('%',#{province},'%')
</if>
<iftest="city != null and city != ''">
AND ph.project_address LIKE CONCAT ('%',#{city},'%')
</if>
<iftest="district != null and district != ''">
AND ph.project_address LIKE CONCAT ('%',#{district},'%')
</if>
</select>
<selectid="selectWKC"resultType="int">
SELECT count(*) FROM hygf_peasant_household WHERE construction_state = '待勘察' and is_delete = 0
<iftest="developerCode != null and developerCode != ''">
AND hygf_peasant_household.developer_code = #{developerCode}
</if>
<iftest="regionalCompaniesCode != null and regionalCompaniesCode != ''">
AND hygf_peasant_household.regional_companies_code = #{regionalCompaniesCode}
</if>
<iftest="province != null and province != ''">
AND hygf_peasant_household.project_address LIKE CONCAT ('%',#{province},'%')
</if>
<iftest="city != null and city != ''">
AND hygf_peasant_household.project_address LIKE CONCAT ('%',#{city},'%')
</if>
<iftest="district != null and district != ''">
AND hygf_peasant_household.project_address LIKE CONCAT ('%',#{district},'%')
</if>
</select>
<selectid="contractStatusTotal"resultType="map">
SELECT
SUM(CASE WHEN status = '未签署' THEN 1 ELSE 0 END) AS '未签署',
SUM(CASE WHEN status = '双方已签署' THEN 1 ELSE 0 END) AS '双方已签署',
SUM(CASE WHEN status = '农户已签署' THEN 1 ELSE 0 END) AS '农户已签署',
SUM(CASE WHEN status = '已作废' THEN 1 ELSE 0 END) AS '已作废'
FROM
( SELECT hhc.*, ROW_NUMBER() OVER ( PARTITION BY peasant_household_id ORDER BY sequence_nbr DESC ) AS rn FROM hygf_household_contract hhc ) subq
LEFT JOIN hygf_peasant_household ph ON ph.SEQUENCE_NBR = subq.peasant_household_id
WHERE
subq.rn = 1
<iftest="developerCode != null and developerCode != ''">
AND ph.developer_code = #{developerCode}
</if>
<iftest="regionalCompaniesCode != null and regionalCompaniesCode != ''">
AND ph.regional_companies_code = #{regionalCompaniesCode}
</if>
<iftest="province != null and province != ''">
AND ph.project_address LIKE CONCAT ('%',#{province},'%')
</if>
<iftest="city != null and city != ''">
AND ph.project_address LIKE CONCAT ('%',#{city},'%')
</if>
<iftest="district != null and district != ''">
AND ph.project_address LIKE CONCAT ('%',#{district},'%')
</if>
</select>
<selectid="desionTotal"resultType="map">
SELECT
SUM( CASE WHEN next_node_name = '经销商设计人员上传设计图' and process_status = '进行中'THEN 1 ELSE 0 END ) AS '典设图已上传',
SUM( CASE WHEN next_node_name = '设计图纸审核' and process_status = '进行中'THEN 1 ELSE 0 END ) AS '施工图已上传'
FROM
`hygf_power_station`
LEFT JOIN
hygf_peasant_household ON hygf_power_station.peasant_household_id = hygf_peasant_household.sequence_nbr
<where>
<iftest="developerCode != null and developerCode != ''">
AND hygf_peasant_household.developer_code = #{developerCode}
</if>
<iftest="regionalCompaniesCode != null and regionalCompaniesCode != ''">
AND hygf_peasant_household.regional_companies_code = #{regionalCompaniesCode}
</if>
<iftest="province != null and province != ''">
AND hygf_peasant_household.project_address LIKE CONCAT ('%',#{province},'%')
</if>
<iftest="city != null and city != ''">
AND hygf_peasant_household.project_address LIKE CONCAT ('%',#{city},'%')
</if>
<iftest="district != null and district != ''">
AND hygf_peasant_household.project_address LIKE CONCAT ('%',#{district},'%')
SELECT count(*) as total FROM hygf_peasant_household WHERE is_delete = 0
<iftest="developerCode != null and developerCode != ''">
AND hygf_peasant_household.developer_code = #{developerCode}
</if>
<iftest="regionalCompaniesCode != null and regionalCompaniesCode != ''">
AND hygf_peasant_household.regional_companies_code = #{regionalCompaniesCode}
</if>
<iftest="province != null and province != ''">
AND hygf_peasant_household.project_address LIKE CONCAT ('%',#{province},'%')
</if>
<iftest="city != null and city != ''">
AND hygf_peasant_household.project_address LIKE CONCAT ('%',#{city},'%')
</if>
<iftest="district != null and district != ''">
AND hygf_peasant_household.project_address LIKE CONCAT ('%',#{district},'%')
</if>
</select>
<selectid="homePageExport"resultType="map">
SELECT
ph.regional_companies_name AS regionalCompaniesName,
ph.developer_name AS developerName,
ROUND(COALESCE(SUM(IFNULL(ei.real_scale, 0))/1000, 0), 2) AS realScale,
SUM(CASE WHEN ph.construction_state = '待勘察' THEN 1 ELSE 0 END) AS wkc,
SUM(CASE WHEN ps.process_status = '不通过' THEN 1 ELSE 0 END) AS kcwtg,
'' AS kcwtgrl,
SUM(CASE WHEN ps.process_status = '进行中' THEN 1 ELSE 0 END) AS kcjxz,
'' AS kcjxzrl,
SUM(CASE WHEN ps.process_status = '完成' THEN 1 ELSE 0 END) AS kcywc,
ROUND(COALESCE(SUM(CASE WHEN ps.process_status = '完成' THEN ei.real_scale ELSE 0 END)/1000, 0), 2) AS kcywcrl,
SUM(CASE WHEN ph.preparation_money_state = '备货完成' THEN 1 ELSE 0 END) AS bhywc,
ROUND(COALESCE(SUM(CASE WHEN ph.preparation_money_state = '备货完成' THEN ei.real_scale ELSE 0 END)/1000, 0), 2) AS bhywcrl,
SUM(CASE WHEN ph.preparation_money_state = '待发货' or ph.preparation_money_state = '暂存发货'or ph.preparation_money_state = '待补货' THEN 1 ELSE 0 END ) AS bhwtg,
'' AS bhjxzrl,
SUM(CASE WHEN ph.preparation_money_state = '待收货' THEN 1 ELSE 0 END) AS bhjxz,
'' AS bhwtgrl,
SUM(CASE WHEN wops.power_station_construction_status = '未通过' THEN 1 ELSE 0 END) AS sgwtg,
SUM(CASE WHEN wops.power_station_construction_status = '未通过' THEN ROUND(COALESCE(ei.real_scale/1000, 0), 2) ELSE 0 END) AS sgwtgrl,
SUM(CASE WHEN wops.power_station_construction_status NOT IN ('未通过', '已完工', '待施工') THEN 1 ELSE 0 END) AS sgjxz,
ROUND(COALESCE( SUM(CASE WHEN wops.power_station_construction_status NOT IN ('未通过', '已完工', '待施工') THEN ei.real_scale/1000 ELSE 0 END), 0), 2) AS sgjxzrl,
SUM(CASE WHEN wops.power_station_construction_status = '已完工' THEN 1 ELSE 0 END) AS sgywc,
ROUND(COALESCE(SUM(CASE WHEN wops.power_station_construction_status = '已完工' THEN ei.real_scale/1000 ELSE 0 END) , 0), 2)AS sgywcrl,
SUM(CASE WHEN br.grid_status = '4' THEN 1 ELSE 0 END) AS bwwtg,
SUM(CASE WHEN br.grid_status = '4' THEN ROUND(COALESCE(ei.real_scale/1000, 0), 2) ELSE 0 END) AS bwwtgrl,
SUM(CASE WHEN br.grid_status NOT IN ('4', '3', '1') THEN 1 ELSE 0 END) AS bwjxz,
ROUND(COALESCE(SUM(CASE WHEN br.grid_status NOT IN ('4', '3', '1') THEN ei.real_scale/1000 ELSE 0 END), 0), 2) AS bwjxzrl,
SUM(CASE WHEN br.grid_status = '3' THEN 1 ELSE 0 END) AS bwywc,
ROUND(COALESCE(SUM(CASE WHEN br.grid_status = '3' THEN ei.real_scale/1000 ELSE 0 END), 0), 2) AS bwywcrl,
SUM(CASE WHEN ac.acceptance_check_status = '3' THEN 1 ELSE 0 END) AS ysywc,
ROUND(COALESCE(SUM(CASE WHEN ac.acceptance_check_status = '3' THEN ei.real_scale/1000 ELSE 0 END), 0), 2) AS ysywcrl,
SUM(CASE WHEN ac.acceptance_check_status = '4' THEN 1 ELSE 0 END) AS yswtg,
ROUND(COALESCE(SUM(CASE WHEN ac.acceptance_check_status = '4' THEN ei.real_scale/1000 ELSE 0 END), 0), 2) AS yswtgrl,
SUM(CASE WHEN ac.acceptance_check_status NOT IN ('3', '4', '15') THEN 1 ELSE 0 END) AS ysjxz,
ROUND(COALESCE(SUM(CASE WHEN ac.acceptance_check_status NOT IN ('3', '4', '15') THEN ei.real_scale/1000 ELSE 0 END), 0), 2) AS ysjxzrl,
SUM(CASE WHEN fi.status = '放款完成' THEN 1 ELSE 0 END) AS rzhs,
MAX(CASE WHEN fi.status = '放款完成' THEN fi.unit_price ELSE 0 END) AS rzdj,
MAX(CASE WHEN fi.status = '放款完成' THEN fi.financing_companies_name ELSE '' END) AS rzgs,
ROUND(COALESCE(SUM(CASE WHEN fi.status = '放款完成' THEN fi.disbursement_money ELSE 0 END), 0), 2) AS fkje,
ROUND(COALESCE(SUM(CASE WHEN fi.status = '放款完成' THEN ei.real_scale/1000 ELSE 0 END), 0), 2)AS rzrl
FROM
hygf_peasant_household ph
LEFT JOIN hygf_power_station ps ON ps.peasant_household_id = ph.sequence_nbr
LEFT JOIN hygf_work_order_power_station wops ON wops.peasant_household_id = ph.sequence_nbr
LEFT JOIN hygf_power_station_engineering_info ei ON ei.work_order_power_station_id = wops.sequence_nbr
LEFT JOIN hygf_acceptance_check ac ON ac.peasant_household_id = ph.sequence_nbr
LEFT JOIN hygf_basic_grid_record br ON br.peasant_household_id = ph.sequence_nbr
LEFT JOIN hygf_financing_info fi ON fi.peasant_household_id = ph.sequence_nbr
WHERE
ph.is_delete = 0
<iftest="developerCode != null and developerCode != ''">
AND ph.developer_code = #{developerCode}
</if>
<iftest="regionalCompaniesCode != null and regionalCompaniesCode != ''">
AND ph.regional_companies_code = #{regionalCompaniesCode}
</if>
<iftest="province != null and province != ''">
AND ph.project_address LIKE CONCAT ('%',#{province},'%')
</if>
<iftest="city != null and city != ''">
AND ph.project_address LIKE CONCAT ('%',#{city},'%')
</if>
<iftest="district != null and district != ''">
AND ph.project_address LIKE CONCAT ('%',#{district},'%')
IFNULL(SUM( CASE WHEN preparation_money_state = '待发货' or preparation_money_state = '暂存发货' or preparation_money_state = '待补货' THEN 1 ELSE 0 END ), 0 ) AS dfh,
IFNULL(SUM( CASE WHEN preparation_money_state = '备货完成' THEN 1 ELSE 0 END ), 0 ) AS ysh,
IFNULL(SUM( CASE WHEN preparation_money_state = '备货完成' THEN ei.real_scale ELSE 0 END ), 0 ) AS yshrl,
IFNULL(SUM( CASE WHEN preparation_money_state = '待收货' THEN 1 ELSE 0 END ), 0 ) AS yfh
FROM
hygf_peasant_household
LEFT JOIN hygf_work_order_power_station wops ON wops.peasant_household_id = hygf_peasant_household.sequence_nbr
LEFT JOIN hygf_power_station_engineering_info ei ON ei.work_order_power_station_id = wops.sequence_nbr
WHERE
preparation_money_state IS NOT NULL
<iftest="developerCode != null and developerCode != ''">
AND hygf_peasant_household.developer_code = #{developerCode}
</if>
<iftest="regionalCompaniesCode != null and regionalCompaniesCode != ''">
AND hygf_peasant_household.regional_companies_code = #{regionalCompaniesCode}
</if>
<iftest="province != null and province != ''">
AND hygf_peasant_household.project_address LIKE CONCAT ('%',#{province},'%')
</if>
<iftest="city != null and city != ''">
AND hygf_peasant_household.project_address LIKE CONCAT ('%',#{city},'%')
</if>
<iftest="district != null and district != ''">
AND hygf_peasant_household.project_address LIKE CONCAT ('%',#{district},'%')