DELETE FROM dispatch.rd_project_summary WHERE id in #{item} INSERT INTO `dispatch`.`rd_project_summary` (`id`, `name`, `type`, `state`, `lon_lat`, `organization_id`, `company_name`,`begin_date`, `end_date`, `principal_id`, `address`, `supervise_region_code`, `supervise_domain_id`, `supervise_depart_id`, `last_sync_time`, `last_updated_time`,`supervise_depart_name`, count_of_stations,count_of_teams,count_of_members) SELECT p1.ID,p1.ITEM_PROJECT_NAME,p1.ITEM_PROJECT_TYPE,p1.ITEM_PREJECT_STATE,p1.lonlat, p1.DOMAINID,p1.company_name,p1.ITEM_PROJECT_START_TIME,p1.ITEM_PROJECT_END_TIME,p1.ITEM_PRINCIPAL,p1.ITEM_ATTENDANCESITEFULLADDRESS, p1.supervise_region_code, p1.supervise_domain_id,p1.supervise_depart_id,last_sync_time, p1.LASTMODIFIED,p1.supervise_depart_name, count_of_stations,count_of_teams,count_of_members FROM ( select a.id,a.ITEM_PROJECT_NAME,a.ITEM_PROJECT_TYPE,'启用' as ITEM_PREJECT_STATE, CONCAT("{""lat"":",ITEM_ATTENDANCESITELATITUDE,",""lon"":",ITEM_ATTENDANCESITELONGITUDE,"}") AS lonlat, a.DOMAINID,o.`NAME` as company_name,a.ITEM_PROJECT_START_TIME,a.ITEM_PROJECT_END_TIME, IFNULL((select GROUP_CONCAT((case when (LEFT(m1.ITEM_PERSON_ID,2)='1-') then REPLACE(m1.ITEM_PERSON_ID, '1-', '') else m1.ITEM_PERSON_ID end)) from baibaodunflow.tlk_event_manager m1 where m1.ITEM_PROJECT_ID=a.ID),'') as ITEM_PRINCIPAL,a.ITEM_ATTENDANCESITEFULLADDRESS, IFNULL(o.supervise_region_code,'#1') as supervise_region_code,IFNULL(a.ITEM_OFFICE_POLICE_ID,'#1') as supervise_domain_id, IFNULL(a.ITEM_OFFICE_POLICE_ID,'#1') as supervise_depart_id, CURRENT_TIMESTAMP as last_sync_time,a.LASTMODIFIED,'' as supervise_depart_name, -1 as count_of_stations,-1 as count_of_teams,-1 as count_of_members from baibaodunflow.tlk_event_project a join obpm2.tenant_organizations o on a.DOMAINID=o.ID =CURRENT_DATE ]]> AND a.id in #{item} ) as p1 where p1.id is not null ON DUPLICATE KEY UPDATE `name`=p1.ITEM_PROJECT_NAME,`type`=p1.ITEM_PROJECT_TYPE,`state`=p1.ITEM_PREJECT_STATE, `lon_lat`=p1.lonlat,`organization_id`=p1.DOMAINID,`begin_date`=p1.ITEM_PROJECT_START_TIME,`end_date`=p1.ITEM_PROJECT_END_TIME, `principal_id`=p1.ITEM_PRINCIPAL, `address`=p1.ITEM_ATTENDANCESITEFULLADDRESS,`supervise_region_code`=p1.supervise_region_code, `supervise_domain_id`=p1.supervise_region_code,`supervise_depart_id`=p1.supervise_domain_id,`supervise_depart_id`=p1.supervise_depart_id, `last_updated_time`=p1.LASTMODIFIED, `supervise_depart_name`=p1.supervise_depart_name, count_of_stations=p1.count_of_stations,count_of_teams=p1.count_of_teams,count_of_members=p1.count_of_members, company_name = p1.company_name delete from dispatch.rd_dispatch_data_scopes WHERE scope_type in (4) and id in concat('4_',#{item}) insert into dispatch.rd_dispatch_data_scopes (id,scope,scope_type,note,last_updated_time) select concat('4_',ITEM_PERSON_ID),item_scopes,4, '大型活动承办商的管理人员的权限--管理多个岗点-2',CURRENT_TIMESTAMP from ( =CURRENT_DATE union SELECT t1.ITEM_PERSON_ID,t2.ITEM_ATT_ID as resource_Id FROM baibaodunFlow.tlk_event_post_manager t1 join baibaodunflow.tlk_event_post t2 on t1.ITEM_POST_ID=t2.ID where t2.ITEM_PROJECT_START_TIME <= DATE_ADD(CURRENT_TIMESTAMP,INTERVAL 30 DAY) and t2.ITEM_PROJECT_END_TIME>=CURRENT_DATE union select (case when (LEFT(m1.ITEM_PERSON_ID,2)='1-') then REPLACE(m1.ITEM_PERSON_ID, '1-', '') else m1.ITEM_PERSON_ID end) as ITEM_PERSON_ID, m1.ITEM_PROJECT_ID as resource_Id from baibaodunflow.tlk_event_manager m1 join baibaodunflow.tlk_event_project m2 on m1.ITEM_PROJECT_ID=m2.ID where m2.ITEM_PROJECT_START_TIME <= DATE_ADD(CURRENT_TIMESTAMP,INTERVAL 30 DAY) and m2.ITEM_PROJECT_END_TIME>=CURRENT_DATE ]]> ) as x2 where x2.ITEM_PERSON_ID in #{item} GROUP BY ITEM_PERSON_ID ) as p1 ON DUPLICATE KEY UPDATE scope=item_scopes delete from dispatch.rd_dispatch_data_scopes WHERE scope_type in (3) and id in concat('3_',#{item}) insert into dispatch.rd_dispatch_data_scopes (id,scope,scope_type,note,last_updated_time) select concat('3_',DOMAINID),item_scopes,3, '大型活动承办商的关联的项目Id',CURRENT_TIMESTAMP from ( select x.DOMAINID,GROUP_CONCAT( DISTINCT resourceId) AS item_scopes from ( =CURRENT_DATE UNION select t1.ITEM_TEAM_ID as DOMAINID,t2.ID as resourceId from baibaodunFlow.tlk_event_team t1 join baibaodunFlow.tlk_event_project t2 on t1.ITEM_PROJECT_ID=t2.ID and t2.ITEM_PROJECT_START_TIME<=DATE_ADD(CURRENT_TIMESTAMP,INTERVAL 30 DAY) and t2.ITEM_PROJECT_END_TIME>=CURRENT_DATE join obpm2.tenant_organizations o on o.id=t1.ITEM_TEAM_ID and SUBSTR(ifnull( o.institutional_code, '' ),1,4) in ('0201','0212','0214','0215','0216','0217','0218','0219','0221') UNION select 'hbTS3taB' as DOMAINID, k.item_project_id as resourceId from baibaodunFlow.tlk_add_work_demand k where item_approval_status='审批通过' ]]> ) as x where x.DOMAINID in #{item} GROUP BY DOMAINID ) as p1 ON DUPLICATE KEY UPDATE scope=item_scopes delete from dispatch.rd_dispatch_data_scopes WHERE scope_type in (5) and id in concat('5_',#{item}) insert into dispatch.rd_dispatch_data_scopes (id,scope,scope_type,note,last_updated_time) select concat('5_',ITEM_TEAM_ID),item_scopes,5, '大型活动承办商的管理单位的岗点权限-限制',CURRENT_TIMESTAMP from ( =CURRENT_DATE ) as x2 where x2.ITEM_TEAM_ID in #{item} GROUP BY x2.ITEM_TEAM_ID ]]> ) as p1 ON DUPLICATE KEY UPDATE scope=item_scopes delete from dispatch.rd_dispatch_data_scopes WHERE scope_type in (4) and id in concat('4_',#{item}) insert into dispatch.rd_dispatch_data_scopes (id,scope,scope_type,note,last_updated_time) select concat('4_',ITEM_PERSON_ID),item_scopes,4, '大型活动承办商的管理人员的权限--管理多个岗点-1',CURRENT_TIMESTAMP from ( =CURRENT_DATE union SELECT t1.ITEM_PERSON_ID,t2.ITEM_ATT_ID as resource_Id FROM baibaodunFlow.tlk_event_post_manager t1 join baibaodunflow.tlk_event_post t2 on t1.ITEM_POST_ID=t2.ID where t2.ITEM_PROJECT_START_TIME <= DATE_ADD(CURRENT_TIMESTAMP,INTERVAL 30 DAY) and t2.ITEM_PROJECT_END_TIME>=CURRENT_DATE union select (case when (LEFT(m1.ITEM_PERSON_ID,2)='1-') then REPLACE(m1.ITEM_PERSON_ID, '1-', '') else m1.ITEM_PERSON_ID end) as ITEM_PERSON_ID, m1.ITEM_PROJECT_ID as resource_Id from baibaodunflow.tlk_event_manager m1 join baibaodunflow.tlk_event_project m2 on m1.ITEM_PROJECT_ID=m2.ID where m2.ITEM_PROJECT_START_TIME <= DATE_ADD(CURRENT_TIMESTAMP,INTERVAL 30 DAY) and m2.ITEM_PROJECT_END_TIME>=CURRENT_DATE ]]> ) as x2 where x2.resource_Id in #{item} GROUP BY ITEM_PERSON_ID ) as p1 ON DUPLICATE KEY UPDATE scope=item_scopes delete from dispatch.rd_dispatch_data_scopes WHERE scope_type in (3) and id in concat('3_',#{item}) insert into dispatch.rd_dispatch_data_scopes (id,scope,scope_type,note,last_updated_time) select concat('3_',DOMAINID),item_scopes,3, '大型活动承办商的关联的项目Id',CURRENT_TIMESTAMP from ( select x.DOMAINID,GROUP_CONCAT( DISTINCT resourceId) AS item_scopes from ( =CURRENT_DATE UNION select t1.ITEM_TEAM_ID as DOMAINID,t2.ID as resourceId,t2.ID as ITEM_PROJECT_ID from baibaodunFlow.tlk_event_team t1 join baibaodunFlow.tlk_event_project t2 on t1.ITEM_PROJECT_ID=t2.ID and t2.ITEM_PROJECT_START_TIME<=DATE_ADD(CURRENT_TIMESTAMP,INTERVAL 30 DAY) and t2.ITEM_PROJECT_END_TIME>=CURRENT_DATE join obpm2.tenant_organizations o on o.id=t1.ITEM_TEAM_ID and SUBSTR(ifnull( o.institutional_code, '' ),1,4) in ('0201','0212','0214','0215','0216','0217','0218','0219','0221') UNION select 'hbTS3taB' as DOMAINID, k.item_project_id as resourceId, k.item_project_id as ITEM_PROJECT_ID from baibaodunFlow.tlk_add_work_demand k where item_approval_status='审批通过' ]]> ) as x where x.ITEM_PROJECT_ID in #{item} GROUP BY DOMAINID ) as p1 ON DUPLICATE KEY UPDATE scope=item_scopes delete from dispatch.rd_dispatch_data_scopes WHERE scope_type in (5) and id in concat('5_',#{item}) insert into dispatch.rd_dispatch_data_scopes (id,scope,scope_type,note,last_updated_time) select concat('5_',ITEM_TEAM_ID),item_scopes,5, '大型活动承办商的管理单位的岗点权限-限制',CURRENT_TIMESTAMP from ( select x2.ITEM_TEAM_ID,GROUP_CONCAT(DISTINCT x2.ITEM_ATTENDANCE_ID ) AS item_scopes from ( SELECT t1.ITEM_TEAM_ID,bi.ITEM_ATT_ID as ITEM_ATTENDANCE_ID,bi.ITEM_PROJECT_ID FROM baibaodunFlow.tlk_event_team_power t1 join baibaodunflow.tlk_event_post bi on t1.ITEM_POST_ID=bi.ID =CURRENT_DATE ]]> ) as x2 where x2.ITEM_PROJECT_ID in #{item} GROUP BY x2.ITEM_TEAM_ID ) as p1 ON DUPLICATE KEY UPDATE scope=item_scopes