@ -85,6 +85,7 @@ public class IdcServiceImpl implements IdcService {
 
			
		
	
		
			
				
					    @Resource 
 
			
		
	
		
			
				
					    private  ScheduledDao  scheduledDao ; 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					    /*获取拉取任务列表*/ 
 
			
		
	
		
			
				
					    @Override 
 
			
		
	
		
			
				
					    public  BaseResponse  taskList ( HttpServletRequest  request ,  Map < String ,  Object >  params )  { 
 
			
		
	
		
			
				
					        Map < String ,  Object >  map  =  new  HashMap < String ,  Object > ( ) ; 
 
			
		
	
	
		
			
				
					
						
						
						
							
								 
						
					 
				
				@ -93,6 +94,7 @@ public class IdcServiceImpl implements IdcService {
 
			
		
	
		
			
				
					        return  ResultVOUtils . success ( list ) ; 
 
			
		
	
		
			
				
					    } 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					    
 
			
		
	
		
			
				
					    /*下载任务*/ 
 
			
		
	
		
			
				
					    @Override 
 
			
		
	
		
			
				
					    public  BaseResponse  download ( HttpServletRequest  request ,  Map < String ,  Object >  params )  { 
 
			
		
	
	
		
			
				
					
						
						
						
							
								 
						
					 
				
				@ -114,7 +116,8 @@ public class IdcServiceImpl implements IdcService {
 
			
		
	
		
			
				
					             id  =  params . get ( "id" ) . toString ( ) ; 
 
			
		
	
		
			
				
					         } 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					    	 Map < String ,  Object >  map  =  map  =  dbDao . get ( "select * from "  +  tableName  +  " where id='"  +  id  +  "'" ) ; 
 
			
		
	
		
			
				
					         Map < String ,  Object >  map  =  map  =  dbDao . get ( "select * from "  +  tableName  +  " where id='"  +  id  +  "'" ) ; 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					         if  ( map  = =  null ) 
 
			
		
	
		
			
				
					         	return  ResultVOUtils . error ( 9000 ,  "下载任务不存在" ) ; 
 
			
		
	
		
			
				
					         if  ( ! ( map . get ( "cacheFilePath" )  ! =  null  & &  FileUtils . isFileExist ( map . get ( "cacheFilePath" ) . toString ( ) ) ) ) 
 
			
		
	
	
		
			
				
					
						
							
								 
						
						
							
								 
						
						
					 
				
				@ -147,13 +150,14 @@ public class IdcServiceImpl implements IdcService {
 
			
		
	
		
			
				
					        asyncDataTask ( false ) ; 
 
			
		
	
		
			
				
					    } 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					    /* 拉取前一级中继服务数据*/
 
			
		
	
		
			
				
					    /* UDI系统 拉取前一级中继服务或自助平台 数据*/
 
			
		
	
		
			
				
					    @Async 
 
			
		
	
		
			
				
					    @Override 
 
			
		
	
		
			
				
					    public  void  asyncFetchUdiTask ( )  { 
 
			
		
	
		
			
				
					        fetchTask ( false ) ; 
 
			
		
	
		
			
				
					    } 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					    /*中继服务拉取任务*/ 
 
			
		
	
		
			
				
					    @Async 
 
			
		
	
		
			
				
					    @Override 
 
			
		
	
		
			
				
					    public  void  asyncFetchTask ( )  { 
 
			
		
	
	
		
			
				
					
						
						
						
							
								 
						
					 
				
				@ -166,6 +170,7 @@ public class IdcServiceImpl implements IdcService {
 
			
		
	
		
			
				
					    } 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					    /*任务拉取,isIdc 是否中继服务*/ 
 
			
		
	
		
			
				
					    private  void  fetchTask ( boolean  isIdc )  { 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					        String  host  =  getNextHost ( ) ; 
 
			
		
	
	
		
			
				
					
						
						
						
							
								 
						
					 
				
				@ -174,10 +179,8 @@ public class IdcServiceImpl implements IdcService {
 
			
		
	
		
			
				
					            if  ( map  ! =  null  & &  map . get ( "syncIp" )  ! =  null ) 
 
			
		
	
		
			
				
					                host  =  map . get ( "syncIp" ) . toString ( ) ; 
 
			
		
	
		
			
				
					        } 
 
			
		
	
		
			
				
					        logger . info ( "fetch from ip:"  +  host ) ; 
 
			
		
	
		
			
				
					        if  ( ! StringUtils . isEmpty ( host ) )  { 
 
			
		
	
		
			
				
					            String  result  =  IDCUtils . post ( host  +  "/spssync/common/list" ,  null ) ; 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					            if  ( IDCUtils . isJson ( result ) )  { 
 
			
		
	
		
			
				
					                JSONObject  json  =  JSON . parseObject ( result ) ; 
 
			
		
	
		
			
				
					                if  ( json  ! =  null  & &  json . getInteger ( "code" )  = =  20000  & &  json . getString ( "data" )  ! =  null )  { 
 
			
		
	
	
		
			
				
					
						
							
								 
						
						
							
								 
						
						
					 
				
				@ -207,11 +210,11 @@ public class IdcServiceImpl implements IdcService {
 
			
		
	
		
			
				
					            } 
 
			
		
	
		
			
				
					            String [ ]  syncTables  =  TableUtils . syncTables ( ) ; 
 
			
		
	
		
			
				
					            for  ( int  i  =  0 ;  i  <  syncTables . length ;  i + + )  { 
 
			
		
	
		
			
				
					            	 String [ ]  tnames  =  syncTables [ i ] . split ( "/" ) ; 
 
			
		
	
		
			
				
					                 String [ ]  tnames  =  syncTables [ i ] . split ( "/" ) ; 
 
			
		
	
		
			
				
					                boolean  sync  =  ( ( tnames [ 0 ] = = null | | StringUtils . isEmpty ( tnames [ 0 ] ) | | ( tnames [ 0 ] ! = null & & tnames [ 0 ] . equals ( "null" ) ) ) & & 
 
			
		
	
		
			
				
					                		( tnames [ 1 ] = = null | | StringUtils . isEmpty ( tnames [ 1 ] ) | | ( tnames [ 1 ] ! = null & & tnames [ 1 ] . equals ( "null" ) ) ) ) | | 
 
			
		
	
		
			
				
					                        ( ! StringUtils . isEmpty ( tnames [ 0 ] )  & &  map  ! =  null  & &  map . get ( tnames [ 0 ] )  ! =  null  & &  map . get ( tnames [ 0 ] ) . toString ( ) . equals ( "1" ) ) ; 
 
			
		
	
		
			
				
					                saveIdcLog ( "---" +sync  , "" ,  map . get ( tnames [ 0 ] )  +  syncTables [ i ] ,  0 ,  0 ) ; 
 
			
		
	
		
			
				
					                saveIdcLog ( "---" "" ,  map . get ( tnames [ 0 ] )  +  syncTables [ i ] ,  0 ,  0 ) ; 
 
			
		
	
		
			
				
					                if  ( sync )  { 
 
			
		
	
		
			
				
					                    String  syncIp  =  map . get ( "syncIp" )  ! =  null  ?  map . get ( "syncIp" ) . toString ( )  :  "" ; 
 
			
		
	
		
			
				
					                    syncData ( syncTables [ i ] ,  isUpload ,  syncIp ) ; 
 
			
		
	
	
		
			
				
					
						
						
						
							
								 
						
					 
				
				@ -220,8 +223,33 @@ public class IdcServiceImpl implements IdcService {
 
			
		
	
		
			
				
					        } 
 
			
		
	
		
			
				
					    } 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					    private  void  syncData ( String  t ,  boolean  isUpload ,  String  syncIp )  { 
 
			
		
	
		
			
				
					    
 
			
		
	
		
			
				
					    /*单独表调用, ,  
 
			
		
	
		
			
				
					    @Override 
 
			
		
	
		
			
				
					    public  BaseResponse  onceSync ( String  tableName , boolean  isUpload )  { 
 
			
		
	
		
			
				
					    	String  tnames  =  tableName . contains ( "/" )  ?  tableName  :  "//" + tableName + "///////" ; 
 
			
		
	
		
			
				
					    	String [ ]  ts  =  tnames . split ( "/" ) ; 
 
			
		
	
		
			
				
					    	String  ip = "" ; 
 
			
		
	
		
			
				
					    	Map < String ,  Object >  map  =  dbDao . get ( "select * from sync_data_set limit 1" ) ; 
 
			
		
	
		
			
				
					    	if ( isUpload )  { 
 
			
		
	
		
			
				
					    		if  ( ! ( map . get ( "syncIp" )  ! =  null  & &  ! StringUtils . isEmpty ( map . get ( "syncIp" ) . toString ( ) ) ) )  { 
 
			
		
	
		
			
				
					                logger . error ( "中继服务地址未配置" ) ; 
 
			
		
	
		
			
				
					                return  ResultVOUtils . error ( 9999 ,  "中继服务地址未配置" ) ; 
 
			
		
	
		
			
				
					            } 
 
			
		
	
		
			
				
					    		ip  =  map . get ( "syncIp" ) . toString ( ) ; 
 
			
		
	
		
			
				
					    	} 
 
			
		
	
		
			
				
					    	if ( ! StringUtils . isEmpty ( ts [ 0 ] ) )  { 
 
			
		
	
		
			
				
					    		if ( ! ( map ! = null & & map . get ( ts [ 0 ] ) ! = null & & map . get ( ts [ 0 ] ) . equals ( "1" ) ) )  
 
			
		
	
		
			
				
					    			return  ResultVOUtils . error ( 9999 ,  "当前不允许生成" ) ; 
 
			
		
	
		
			
				
					    	} 
 
			
		
	
		
			
				
					    	if ( syncData ( tnames , isUpload , ip ) )  
 
			
		
	
		
			
				
					    		return  ResultVOUtils . success ( ) ; 
 
			
		
	
		
			
				
					    	return  ResultVOUtils . error ( 9999 ,  "系统错误" ) ; 
 
			
		
	
		
			
				
					    } 
 
			
		
	
		
			
				
					    
 
			
		
	
		
			
				
					    private  boolean  syncData ( String  t ,  boolean  isUpload ,  String  syncIp )  { 
 
			
		
	
		
			
				
					        boolean  sync  =  true ; 
 
			
		
	
		
			
				
					        boolean  result  =  false ; 
 
			
		
	
		
			
				
					        try  { 
 
			
		
	
		
			
				
					        String [ ]  tnames  =  t . split ( "/" ) ; 
 
			
		
	
		
			
				
					
 
			
		
	
	
		
			
				
					
						
						
						
							
								 
						
					 
				
				@ -233,14 +261,22 @@ public class IdcServiceImpl implements IdcService {
 
			
		
	
		
			
				
					            String  keyColumn  =  keyList  ! =  null  & &  keyList . size ( )  >  0  ?  keyList . get ( 0 ) . get ( "columnName" ) . toString ( )  :  "id" ; 
 
			
		
	
		
			
				
					            Map < String ,  Object >  map  =  new  HashMap < String ,  Object > ( ) ; 
 
			
		
	
		
			
				
					            String  sqlWhere  =  "" ; 
 
			
		
	
		
			
				
					            if  ( ! StringUtils . isEmpty ( tnames [ 6 ] ) )  { 
 
			
		
	
		
			
				
					                sqlWhere  + =  " "  +  tnames [ 6 ]  +  ">= cast('"  +  lastUpdateTime  +  "' as datetime)" ; // and date_add(cast('"+DateUtil.formatDate(nowUpdateTime, "yyyy-MM-dd HH:mm:ss")+"' as datetime),INTERVAL 1 day)";
 
 
			
		
	
		
			
				
					            String  updateTimeColumn  =  tnames [ 6 ] ; 
 
			
		
	
		
			
				
					            if ( StringUtils . isEmpty ( updateTimeColumn ) )  { 
 
			
		
	
		
			
				
					            	Map < String , Object >  tMap  =  dbDao . get ( "select column_name columnName from information_schema.columns where column_name='updateTime' and lower(table_name) = lower('" + tnames [ 0 ] + "') and table_schema = (select database()) limit 1" ) ; 
 
			
		
	
		
			
				
					            	updateTimeColumn  =  tMap  ! = null  ?  "updateTime"  :  "" ; 
 
			
		
	
		
			
				
					            } 
 
			
		
	
		
			
				
					            
 
			
		
	
		
			
				
					            
 
			
		
	
		
			
				
					            if  ( ! StringUtils . isEmpty ( updateTimeColumn ) )  { 
 
			
		
	
		
			
				
					                sqlWhere  + =  " "  +  updateTimeColumn  +  ">= cast('"  +  lastUpdateTime  +  "' as datetime)" ; // and date_add(cast('"+DateUtil.formatDate(nowUpdateTime, "yyyy-MM-dd HH:mm:ss")+"' as datetime),INTERVAL 1 day)";
 
 
			
		
	
		
			
				
					                sqlWhere  + =  " and not exists (select fkId from idc_record where type='"  +  tnames [ 2 ]  +  "' and fkId="  +  tnames [ 2 ]  +  "."  +  keyColumn  +  " and createTime>date_sub(now(),interval 15 MINUTE))" ; 
 
			
		
	
		
			
				
					            }  else  { 
 
			
		
	
		
			
				
					                sqlWhere  =  "not exists (select fkId from idc_record where type='"  +  tnames [ 2 ]  +  "' and fkId="  +  tnames [ 2 ]  +  "."  +  keyColumn  +  ")" ; 
 
			
		
	
		
			
				
					                map . put ( "isEnd" ,  "1" ) ; 
 
			
		
	
		
			
				
					            } 
 
			
		
	
		
			
				
					            map . put ( "sqlWhere" ,  sqlWhere ) ; 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					            map . put ( "tableKey" ,  tnames [ 0 ] ) ; 
 
			
		
	
		
			
				
					            map . put ( "tableName" ,  tnames [ 2 ] ) ; 
 
			
		
	
		
			
				
					            map . put ( "uniqueColumn" ,  tnames [ 3 ] ) ; 
 
			
		
	
	
		
			
				
					
						
						
						
							
								 
						
					 
				
				@ -261,7 +297,8 @@ public class IdcServiceImpl implements IdcService {
 
			
		
	
		
			
				
					                sync  =  nextTimePoint . before ( nowUpdateTime ) ; 
 
			
		
	
		
			
				
					            } 
 
			
		
	
		
			
				
					            if  ( sync )  { 
 
			
		
	
		
			
				
					                if  ( syncMasterData ( map ,  isUpload ,  syncIp ) )  { 
 
			
		
	
		
			
				
					            	result  =  syncMasterData ( map ,  isUpload ,  syncIp ) ; 
 
			
		
	
		
			
				
					                if  ( result )  { 
 
			
		
	
		
			
				
					                    setUpdateTime ( tnames [ 2 ]  +  "."  +  tnames [ 0 ] ,  DateUtil . formatDate ( nowUpdateTime ,  "yyyy-MM-dd HH:mm:ss" ) ) ; 
 
			
		
	
		
			
				
					                } 
 
			
		
	
		
			
				
					            } 
 
			
		
	
	
		
			
				
					
						
						
						
							
								 
						
					 
				
				@ -269,6 +306,7 @@ public class IdcServiceImpl implements IdcService {
 
			
		
	
		
			
				
					        }  catch  ( Exception  ex )  { 
 
			
		
	
		
			
				
					        	
 
			
		
	
		
			
				
					        } 
 
			
		
	
		
			
				
					        return  result ; 
 
			
		
	
		
			
				
					    }