/*
初始化customer_staff_agency,customer_staff_department,customer_staff_grid
*/


INSERT INTO epmet_gov_org.customer_staff_grid ( ID, CUSTOMER_ID, USER_ID, GRID_ID, DEL_FLAG, CREATED_BY, CREATED_TIME, UPDATED_BY, UPDATED_TIME ) SELECT
t1.id,
'bb19419e365cf97567dc0520cdcfba9e',
t1.id AS USER_ID,
t1.dept_id AS GRID_ID,
t1.del_flag,
t1.creator AS CREATED_BY,
t1.create_date AS CREATED_TIME,
t1.updater AS UPDATED_BY,
t1.update_date AS UPDATED_TIME 
FROM
	esua_epdc_admin.sys_user t1
	LEFT JOIN esua_epdc_admin.sys_dept t2 ON t1.dept_id = t2.id 
WHERE
	t2.type_key = 'grid_party';


INSERT INTO epmet_gov_org.customer_staff_department (
	ID,
	CUSTOMER_ID,
	USER_ID,
	DEPARTMENT_ID,
	DEL_FLAG,
	CREATED_BY,
	CREATED_TIME,
	UPDATED_BY,
	UPDATED_TIME 
) SELECT
t1.id ,
'bb19419e365cf97567dc0520cdcfba9e',
t1.id as USER_ID,
t1.dept_id as DEPARTMENT_ID,
t1.del_flag,
t1.creator as CREATED_BY,
t1.create_date as CREATED_TIME,
t1.updater as UPDATED_BY,
t1.update_date as UPDATED_TIME
from esua_epdc_admin.sys_user t1
left join esua_epdc_admin.sys_dept t2 on t1.dept_id = t2.id
WHERE
	t2.type_key = 'district_dept' 
	OR t2.type_key = 'street_dept';



INSERT INTO epmet_gov_org.customer_staff_agency (
	ID,
	CUSTOMER_ID,
	USER_ID,
	AGENCY_ID,
	DEL_FLAG,
	CREATED_BY,
	CREATED_TIME,
	UPDATED_BY,
	UPDATED_TIME 
) SELECT
t1.id ,
'bb19419e365cf97567dc0520cdcfba9e',
t1.id as USER_ID,
t1.dept_id as AGENCY_ID,
t1.del_flag,
t1.creator as CREATED_BY,
t1.create_date as CREATED_TIME,
t1.updater as UPDATED_BY,
t1.update_date as UPDATED_TIME
from esua_epdc_admin.sys_user t1
left join esua_epdc_admin.sys_dept t2 on t1.dept_id = t2.id
WHERE
	t2.type_key = 'district_party' 
	OR t2.type_key = 'street_party' 
	OR t2.type_key = 'community_party';