@ -1,21 +1,24 @@
 
			
		
	
		
			
				
					package  com.glxp.sale.admin.controller.sync ;  
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					import  cn.hutool.core.lang.Dict ;  
			
		
	
		
			
				
					import  cn.hutool.core.util.StrUtil ;  
			
		
	
		
			
				
					import  com.alibaba.fastjson.JSON ;  
			
		
	
		
			
				
					import  com.glxp.sale.admin.constant.BasicProcessStatus ;  
			
		
	
		
			
				
					import  com.glxp.sale.admin.constant.ConstantStatus ;  
			
		
	
		
			
				
					import  com.glxp.sale.admin.constant.FileConstant ;  
			
		
	
		
			
				
					import  com.baomidou.mybatisplus.core.toolkit.Wrappers ;  
			
		
	
		
			
				
					import  com.glxp.sale.admin.constant.* ;  
			
		
	
		
			
				
					import  com.glxp.sale.admin.entity.param.SystemParamConfigEntity ;  
			
		
	
		
			
				
					import  com.glxp.sale.admin.entity.sync. BasicUploadStatusEntity ;  
			
		
	
		
			
				
					import  com.glxp.sale.admin.entity.sync. * ;  
			
		
	
		
			
				
					import  com.glxp.sale.admin.http.SpGetHttp ;  
			
		
	
		
			
				
					import  com.glxp.sale.admin.http.SpPostHttp ;  
			
		
	
		
			
				
					import  com.glxp.sale.admin.req.sync.SpsSyncDataRequest ;  
			
		
	
		
			
				
					import  com.glxp.sale.admin.res.sync.* ;  
			
		
	
		
			
				
					import  com.glxp.sale.admin.service.param.SystemParamConfigService ;  
			
		
	
		
			
				
					import  com.glxp.sale.admin.service.sync.BasicExportService ;  
			
		
	
		
			
				
					import  com.glxp.sale.admin.service.sync.BasicUploadService ;  
			
		
	
		
			
				
					import  com.glxp.sale.admin.util.* ;  
			
		
	
		
			
				
					import  com.glxp.sale.common.enums.ResultEnum ;  
			
		
	
		
			
				
					import  com.glxp.sale.common.res.BaseResponse ;  
			
		
	
		
			
				
					import  com.glxp.sale.common.util.ResultVOUtils ;  
			
		
	
		
			
				
					import  lombok.RequiredArgsConstructor ;  
			
		
	
		
			
				
					import  org.slf4j.Logger ;  
			
		
	
		
			
				
					import  org.slf4j.LoggerFactory ;  
			
		
	
		
			
				
					import  org.springframework.beans.factory.annotation.Value ;  
			
		
	
	
		
			
				
					
						
						
						
							
								 
						
					 
				
				@ -26,9 +29,14 @@ import org.springframework.web.bind.annotation.RequestBody;
 
			
		
	
		
			
				
					import  org.springframework.web.bind.annotation.RestController ;  
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					import  javax.annotation.Resource ;  
			
		
	
		
			
				
					import  java.io.FileNotFoundException ;  
			
		
	
		
			
				
					import  java.io.FileReader ;  
			
		
	
		
			
				
					import  java.io.IOException ;  
			
		
	
		
			
				
					import  java.util.Date ;  
			
		
	
		
			
				
					import  java.util.List ;  
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					@RestController  
			
		
	
		
			
				
					@RequiredArgsConstructor  
			
		
	
		
			
				
					public  class  SpsSyncDataController  {  
			
		
	
		
			
				
					    @Resource 
 
			
		
	
		
			
				
					    RedisUtil  redisUtil ; 
 
			
		
	
	
		
			
				
					
						
							
								 
						
						
							
								 
						
						
					 
				
				@ -182,8 +190,6 @@ public class SpsSyncDataController {
 
			
		
	
		
			
				
					    } 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					    @PostMapping ( "sps/sync/schedule/upload" ) 
 
			
		
	
		
			
				
					    public  BaseResponse  postSchedule ( @RequestBody  SpsSyncScheduleResponse  spsSyncScheduleResponse )  { 
 
			
		
	
		
			
				
					        SystemParamConfigEntity  systemParamConfigEntity  =  systemParamConfigService . selectByParamKey ( "sync_upstream_enable" ) ; 
 
			
		
	
	
		
			
				
					
						
							
								 
						
						
							
								 
						
						
					 
				
				@ -220,5 +226,75 @@ public class SpsSyncDataController {
 
			
		
	
		
			
				
					        } 
 
			
		
	
		
			
				
					    } 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					    private  final  BasicExportService  basicExportService ; 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					    //    下发基础数据 , ,  
 
			
		
	
		
			
				
					    @GetMapping ( "sps/sync/data" ) 
 
			
		
	
		
			
				
					    public  BaseResponse  data ( BasicExportTypeEnum  exportType )  { 
 
			
		
	
		
			
				
					        BaseResponse < RelaySyncResponse >  baseResponse  =  new  BaseResponse < > ( ) ; 
 
			
		
	
		
			
				
					        RelaySyncResponse  relaySyncResponse  =  null ; 
 
			
		
	
		
			
				
					        BasicExportStatusEntity  one  =  basicExportService . findByType ( exportType . getRemark ( ) ) ; 
 
			
		
	
		
			
				
					        if  ( one  ! =  null )  { 
 
			
		
	
		
			
				
					            if  ( BasicExportStatusEnum . WAIT_TRIGGERED . getCode ( ) . equals ( one . getStatus ( ) ) )  { 
 
			
		
	
		
			
				
					                basicExportService . updateByIdAndStatus ( one . getId ( ) ,  BasicExportStatusEnum . WAIT_BUILT . getCode ( ) ,  BasicExportStatusEnum . WAIT_TRIGGERED . getCode ( ) ) ; 
 
			
		
	
		
			
				
					            }  else  if  ( BasicExportStatusEnum . WAIT_SYNC . getCode ( ) . equals ( one . getStatus ( ) ) )  { 
 
			
		
	
		
			
				
					                if  ( StrUtil . isBlank ( one . getCacheFilePath ( ) ) )  { 
 
			
		
	
		
			
				
					                    throw  new  RuntimeException ( "系统异常,文件名为空" ) ; 
 
			
		
	
		
			
				
					                } 
 
			
		
	
		
			
				
					                relaySyncResponse  =  RelaySyncResponse . builder ( ) 
 
			
		
	
		
			
				
					                        . taskId ( one . getId ( ) ) 
 
			
		
	
		
			
				
					                        . fileContent ( this . readDataFile ( one . getCacheFilePath ( ) ) ) 
 
			
		
	
		
			
				
					                        . build ( ) ; 
 
			
		
	
		
			
				
					            } 
 
			
		
	
		
			
				
					        } 
 
			
		
	
		
			
				
					        baseResponse . setCode ( ResultEnum . SUCCESS . getCode ( ) ) ; 
 
			
		
	
		
			
				
					        baseResponse . setData ( relaySyncResponse ) ; 
 
			
		
	
		
			
				
					        return  baseResponse ; 
 
			
		
	
		
			
				
					    } 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					    private  String  readDataFile ( String  cacheFilePath )  { 
 
			
		
	
		
			
				
					        // 读取文件数据
 
 
			
		
	
		
			
				
					        try  { 
 
			
		
	
		
			
				
					            FileReader  reader  =  new  FileReader ( cacheFilePath ) ; 
 
			
		
	
		
			
				
					            StringBuilder  str  =  new  StringBuilder ( ) ; 
 
			
		
	
		
			
				
					            int  data ; 
 
			
		
	
		
			
				
					            while  ( ( data  =  reader . read ( ) )  ! =  - 1 )  { 
 
			
		
	
		
			
				
					                str . append ( ( char )  data ) ; 
 
			
		
	
		
			
				
					            } 
 
			
		
	
		
			
				
					            reader . close ( ) ; 
 
			
		
	
		
			
				
					            return  str . toString ( ) ; 
 
			
		
	
		
			
				
					        }  catch  ( FileNotFoundException  e )  { 
 
			
		
	
		
			
				
					            throw  new  RuntimeException ( "系统异常,未找到对应数据文件" ) ; 
 
			
		
	
		
			
				
					        }  catch  ( IOException  e )  { 
 
			
		
	
		
			
				
					            throw  new  RuntimeException ( e ) ; 
 
			
		
	
		
			
				
					        } 
 
			
		
	
		
			
				
					    } 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					    @PostMapping ( "/spssync/basic/udiinfo/finishTask" ) 
 
			
		
	
		
			
				
					    public  BaseResponse  finishTask ( @RequestBody  BasicExportStatusEntity  basicExportStatusEntity )  { 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					        if  ( StrUtil . isBlank ( basicExportStatusEntity . getId ( ) ) )  { 
 
			
		
	
		
			
				
					            return  ResultVOUtils . error ( 500 ,  "缺少唯一标识!" ) ; 
 
			
		
	
		
			
				
					        } 
 
			
		
	
		
			
				
					        if  ( StrUtil . isEmpty ( basicExportStatusEntity . getReceiveStatus ( ) ) )  { 
 
			
		
	
		
			
				
					            basicExportStatusEntity . setEndTime ( DateUtil . getDateTime ( ) ) ; 
 
			
		
	
		
			
				
					        } 
 
			
		
	
		
			
				
					        basicExportStatusEntity . setUpdateTime ( new  Date ( ) ) ; 
 
			
		
	
		
			
				
					        basicExportStatusEntity . setStatus ( BasicExportStatusEnum . COMPLETED . getCode ( ) ) ; 
 
			
		
	
		
			
				
					        boolean  b  =  basicExportService . update ( Wrappers . lambdaUpdate ( BasicExportStatusEntity . class ) 
 
			
		
	
		
			
				
					                . set ( BasicExportStatusEntity : : getStatus ,  BasicExportStatusEnum . COMPLETED . getCode ( ) ) 
 
			
		
	
		
			
				
					                . set ( BasicExportStatusEntity : : getEndTime ,  new  Date ( ) ) 
 
			
		
	
		
			
				
					                . set ( BasicExportStatusEntity : : getUpdateTime ,  new  Date ( ) ) 
 
			
		
	
		
			
				
					                . set ( BasicExportStatusEntity : : getReceiveStatus ,  1 ) 
 
			
		
	
		
			
				
					                . eq ( BasicExportStatusEntity : : getId ,  basicExportStatusEntity . getId ( ) ) 
 
			
		
	
		
			
				
					                . eq ( BasicExportStatusEntity : : getStatus ,  BasicExportStatusEnum . WAIT_SYNC . getCode ( ) ) 
 
			
		
	
		
			
				
					        ) ; 
 
			
		
	
		
			
				
					        if  ( b ) 
 
			
		
	
		
			
				
					            return  ResultVOUtils . success ( "更新成功!" ) ; 
 
			
		
	
		
			
				
					        else 
 
			
		
	
		
			
				
					            return  ResultVOUtils . error ( 500 ,  "更新成功!" ) ; 
 
			
		
	
		
			
				
					    } 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					}