REPLACE INTO dispatch.rd_employee_summary (
			id,
			supervise_region_code,
			security_station_id,
			security_station_name,
			supervise_depart_id,
			supervise_domain_id,
	        supervise_depart_name,
			`name`,
			head_photo,
			contact,
			company_name,
			`status`,
			checked_status,
			authenticated_status,
			military_status,
			security_certificate_no,
			occupation_type,
			hired_date,
			leave_time,
			insure,
			organization_id,
			tenant_user_id,
			tenant_employee_id,
			last_sync_time,
			last_updated_time,
			device_number,
			tenant_im_user_id,
			idCard_no,
			cid
	)
SELECT
    ee.id,
    '#fk-jdbce',
    ifnull( (SELECT
                 t1.ID
             FROM baibaodunflow.tlk_attendance_site_base_info t1
                      JOIN baibaodunflow.tlk_attendance_site_person_info t2 ON t1.ID = t2.ITEM_attendanceSiteId
             WHERE t1.ITEM_attendanceSiteState IN ( '已完善', '生效') and t2.ITEM_securityId=ee.id and t1.ITEM_attendanceStartDate <=CURRENT_TIMESTAMP and t1.ITEM_attendanceEndDate>=CURRENT_DATE order by ITEM_attendanceStartDate desc limit 1), '#1' ),
    ifnull( (SELECT
                 t1.ITEM_attendanceSiteName
             FROM baibaodunflow.tlk_attendance_site_base_info t1
                      JOIN baibaodunflow.tlk_attendance_site_person_info t2 ON t1.ID = t2.ITEM_attendanceSiteId
             WHERE t1.ITEM_attendanceSiteState IN ( '已完善', '生效' ) and t2.ITEM_securityId=ee.id and t1.ITEM_attendanceStartDate <=CURRENT_TIMESTAMP and t1.ITEM_attendanceEndDate>=CURRENT_DATE order by ITEM_attendanceStartDate desc limit 1), '#1' ),
    ifnull( (SELECT
                 t1.ITEM_officePoliceAddressID
             FROM baibaodunflow.tlk_attendance_site_base_info t1
                      JOIN baibaodunflow.tlk_attendance_site_person_info t2 ON t1.ID = t2.ITEM_attendanceSiteId
             WHERE t1.ITEM_attendanceSiteState IN ( '已完善', '生效' ) and t2.ITEM_securityId=ee.id and t1.ITEM_attendanceStartDate <=CURRENT_TIMESTAMP and t1.ITEM_attendanceEndDate>=CURRENT_DATE order by ITEM_attendanceStartDate desc limit 1), '#1' ),
    '#fk-t190',
    ifnull( (SELECT
                 t1.ITEM_officePoliceAddress
             FROM baibaodunflow.tlk_attendance_site_base_info t1
                      JOIN baibaodunflow.tlk_attendance_site_person_info t2 ON t1.ID = t2.ITEM_attendanceSiteId
             WHERE t1.ITEM_attendanceSiteState IN ( '已完善', '生效' ) and t2.ITEM_securityId=ee.id and t1.ITEM_attendanceStartDate <=CURRENT_TIMESTAMP and t1.ITEM_attendanceEndDate>=CURRENT_DATE order by ITEM_attendanceStartDate desc limit 1), '#1' ),
    u.`name`,
    c.head_photo,
    u.telephone,
    o.`name` AS orgName,
    ee.`status`,
    u.checked_status,
    u.authenticated_status,
    u.military_status,(
        SELECT
            c2.number
        FROM
            obpm2.tenant_user_credentials c2
        WHERE
                c2.tenant_user_id = u.id
          AND c2.credential_type = 7 order by valid_date_from desc
                LIMIT 1
    ) AS securityCredentialNo,
		ee.occupation_type,
(case when IFNULL( ee.hired_date, CURRENT_TIMESTAMP )<'1990-01-01' then '1990-01-01' else IFNULL( ee.hired_date, CURRENT_TIMESTAMP ) end) AS hired_date,
		ee.leave_time AS leave_time,
		ifnull( ee.insure, 0 ),
		ee.organization_id,
		ee.tenant_user_id,
		ee.id,
		ee.last_sync_time AS last_sync_time,
		ee.last_updated_time AS last_updated_time,
		'',
		ifnull( u.im_identity, '#' ),
		c.number,
		u.cid
FROM 	obpm2.tenant_users u
    LEFT JOIN obpm2.tenant_user_credentials c ON u.selected_credential_id = c.id
    JOIN obpm2.tenant_employees ee ON ee.tenant_user_id = u.id
    JOIN obpm2.tenant_organizations o ON o.id = ee.organization_id
where ee.last_sync_time>'2023-04-27 12:00:00';


SELECT
    concat("""",ee.id,""",")
FROM 	obpm2.tenant_users u
    LEFT JOIN obpm2.tenant_user_credentials c ON u.selected_credential_id = c.id
    JOIN obpm2.tenant_employees ee ON ee.tenant_user_id = u.id
    JOIN obpm2.tenant_organizations o ON o.id = ee.organization_id
where ee.last_sync_time>'2023-04-27 12:00:00';