@ -1,13 +1,16 @@
package com.glxp.sale.admin.controller.sync ;
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.glxp.sale.admin.entity.param.SystemParamConfigEntity ;
import com.glxp.sale.admin.entity.sync.Basic Export StatusEntity;
import com.glxp.sale.admin.entity.sync.Basic Upload StatusEntity;
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.BasicUploadService ;
import com.glxp.sale.admin.util.CustomUtil ;
import com.glxp.sale.admin.util.DateUtil ;
import com.glxp.sale.admin.util.FileUtils ;
@ -34,6 +37,9 @@ public class SpsSyncDataController {
SystemParamConfigService systemParamConfigService ;
@Resource
SpPostHttp spPostHttp ;
@Resource
private BasicUploadService basicUploadService ;
private static final Logger logger = LoggerFactory . getLogger ( SpsSyncDataController . class ) ;
public String getPath ( ) {
@ -83,16 +89,41 @@ public class SpsSyncDataController {
if ( bindingResult . hasErrors ( ) ) {
return ResultVOUtils . error ( ResultEnum . PARAM_VERIFY_FALL , bindingResult . getFieldError ( ) . getDefaultMessage ( ) ) ;
}
SystemParamConfigEntity systemParamConfigEntity = systemParamConfigService . selectByParamKey ( "sync_upstream_enable" ) ;
BasicUploadStatusEntity basicUploadStatusEntity = new BasicUploadStatusEntity ( ) ;
basicUploadStatusEntity . setId ( CustomUtil . getId ( ) ) ;
basicUploadStatusEntity . setTaskId ( syncDataResponse . getTaskId ( ) ) ;
basicUploadStatusEntity . setStartTime ( DateUtil . getDateTime ( ) ) ;
basicUploadStatusEntity . setIdDatas ( ConstantStatus . SYNC_BASIC_DATA ) ;
basicUploadStatusEntity . setType ( BasicProcessStatus . NEW_ALL_DATA ) ;
basicUploadStatusEntity . setRemark ( syncDataResponse . toString ( ) ) ;
if ( systemParamConfigEntity . getParamValue ( ) . equals ( "0" ) ) { //上游不通
String path = getPath ( ) ;
String fileName = path + FileConstant . lowerWaitCopy_products + "BaseData_" + DateUtil . formatDate ( new Date ( ) , "yyyyMMddHHmmss" ) + ".UpperIn" ;
String datas = JSON . toJSONString ( syncDataResponse ) ;
FileUtils . SaveFileAs ( datas , fileName ) ;
basicUploadStatusEntity . setTransportType ( BasicProcessStatus . FILE_TYPE ) ;
basicUploadStatusEntity . setUpdateTime ( new Date ( ) ) ;
basicUploadStatusEntity . setEndTime ( DateUtil . getDateTime ( ) ) ;
basicUploadStatusEntity . setStatus ( 1 ) ;
basicUploadService . insertDownloadStatus ( basicUploadStatusEntity ) ;
return ResultVOUtils . success ( "文件上传成功,已保存,等待拷贝!" ) ;
} else {
//上游通
return spPostHttp . postAllDatas ( syncDataResponse ) ;
BaseResponse < String > response = spPostHttp . postAllDatas ( syncDataResponse ) ;
basicUploadStatusEntity . setTransportType ( BasicProcessStatus . INTERFACE_TYPE ) ;
basicUploadStatusEntity . setEndTime ( DateUtil . getDateTime ( ) ) ;
basicUploadStatusEntity . setUpdateTime ( new Date ( ) ) ;
if ( response . getCode ( ) = = 20000 ) {
basicUploadStatusEntity . setStatus ( 1 ) ;
} else {
basicUploadStatusEntity . setStatus ( 0 ) ;
}
basicUploadService . insertDownloadStatus ( basicUploadStatusEntity ) ;
return response ;
}
}
@ -104,15 +135,40 @@ public class SpsSyncDataController {
return ResultVOUtils . error ( ResultEnum . PARAM_VERIFY_FALL , bindingResult . getFieldError ( ) . getDefaultMessage ( ) ) ;
}
SystemParamConfigEntity systemParamConfigEntity = systemParamConfigService . selectByParamKey ( "sync_upstream_enable" ) ;
BasicUploadStatusEntity basicUploadStatusEntity = new BasicUploadStatusEntity ( ) ;
basicUploadStatusEntity . setId ( CustomUtil . getId ( ) ) ;
basicUploadStatusEntity . setTaskId ( spsSyncOrderResponse . getTaskId ( ) ) ;
basicUploadStatusEntity . setStartTime ( DateUtil . getDateTime ( ) ) ;
basicUploadStatusEntity . setIdDatas ( ConstantStatus . SYNC_SCAN_ORDER ) ;
basicUploadStatusEntity . setType ( BasicProcessStatus . NEW_ALL_ORDER ) ;
basicUploadStatusEntity . setRemark ( spsSyncOrderResponse . toString ( ) ) ;
if ( systemParamConfigEntity . getParamValue ( ) . equals ( "0" ) ) { //上游不通
String path = getPath ( ) ;
String fileName = path + FileConstant . lowerWaitCopy_products + "order_" + DateUtil . formatDate ( new Date ( ) , "yyyyMMddHHmmss" ) + ".UpperIn" ;
String datas = JSON . toJSONString ( spsSyncOrderResponse ) ;
FileUtils . SaveFileAs ( datas , fileName ) ;
basicUploadStatusEntity . setUpdateTime ( new Date ( ) ) ;
basicUploadStatusEntity . setEndTime ( DateUtil . getDateTime ( ) ) ;
basicUploadStatusEntity . setTransportType ( BasicProcessStatus . FILE_TYPE ) ;
basicUploadStatusEntity . setStatus ( 1 ) ;
return ResultVOUtils . success ( "文件上传成功,已保存,等待拷贝!" ) ;
} else {
//上游通
return spPostHttp . postAllOrders ( spsSyncOrderResponse ) ;
BaseResponse < String > response = spPostHttp . postAllOrders ( spsSyncOrderResponse ) ;
basicUploadStatusEntity . setUpdateTime ( new Date ( ) ) ;
basicUploadStatusEntity . setEndTime ( DateUtil . getDateTime ( ) ) ;
basicUploadStatusEntity . setTransportType ( BasicProcessStatus . INTERFACE_TYPE ) ;
if ( response . getCode ( ) = = 20000 ) {
basicUploadStatusEntity . setStatus ( 1 ) ;
} else {
basicUploadStatusEntity . setStatus ( 0 ) ;
}
basicUploadService . insertDownloadStatus ( basicUploadStatusEntity ) ;
return response ;
}
}
@ -125,33 +181,81 @@ public class SpsSyncDataController {
return ResultVOUtils . error ( ResultEnum . PARAM_VERIFY_FALL , bindingResult . getFieldError ( ) . getDefaultMessage ( ) ) ;
}
SystemParamConfigEntity systemParamConfigEntity = systemParamConfigService . selectByParamKey ( "sync_upstream_enable" ) ;
BasicUploadStatusEntity basicUploadStatusEntity = new BasicUploadStatusEntity ( ) ;
basicUploadStatusEntity . setId ( CustomUtil . getId ( ) ) ;
basicUploadStatusEntity . setTaskId ( spsSyncBusResponse . getTaskId ( ) ) ;
basicUploadStatusEntity . setStartTime ( DateUtil . getDateTime ( ) ) ;
basicUploadStatusEntity . setIdDatas ( ConstantStatus . SYNC_BUS_TYPE ) ;
basicUploadStatusEntity . setType ( BasicProcessStatus . NEW_ALL_BUS ) ;
basicUploadStatusEntity . setRemark ( spsSyncBusResponse . toString ( ) ) ;
if ( systemParamConfigEntity . getParamValue ( ) . equals ( "0" ) ) { //上游不通
String path = getPath ( ) ;
String fileName = path + FileConstant . lowerWaitCopy_products + "BusType_" + DateUtil . formatDate ( new Date ( ) , "yyyyMMddHHmmss" ) + ".UpperIn" ;
String datas = JSON . toJSONString ( spsSyncBusResponse ) ;
FileUtils . SaveFileAs ( datas , fileName ) ;
basicUploadStatusEntity . setUpdateTime ( new Date ( ) ) ;
basicUploadStatusEntity . setEndTime ( DateUtil . getDateTime ( ) ) ;
basicUploadStatusEntity . setTransportType ( BasicProcessStatus . FILE_TYPE ) ;
basicUploadStatusEntity . setStatus ( 1 ) ;
basicUploadService . insertDownloadStatus ( basicUploadStatusEntity ) ;
return ResultVOUtils . success ( "文件上传成功,已保存,等待拷贝!" ) ;
} else {
//上游通
return spPostHttp . postAllBus ( spsSyncBusResponse ) ;
BaseResponse < String > response = spPostHttp . postAllBus ( spsSyncBusResponse ) ;
basicUploadStatusEntity . setUpdateTime ( new Date ( ) ) ;
basicUploadStatusEntity . setEndTime ( DateUtil . getDateTime ( ) ) ;
basicUploadStatusEntity . setTransportType ( BasicProcessStatus . INTERFACE_TYPE ) ;
if ( response . getCode ( ) = = 20000 ) {
basicUploadStatusEntity . setStatus ( 0 ) ;
} else {
basicUploadStatusEntity . setStatus ( 1 ) ;
}
basicUploadService . insertDownloadStatus ( basicUploadStatusEntity ) ;
return response ;
}
}
@PostMapping ( "sps/sync/schedule/upload" )
public BaseResponse postSchedule ( @RequestBody SpsSyncScheduleResponse spsSyncScheduleResponse ) {
SystemParamConfigEntity systemParamConfigEntity = systemParamConfigService . selectByParamKey ( "sync_upstream_enable" ) ;
BasicUploadStatusEntity basicUploadStatusEntity = new BasicUploadStatusEntity ( ) ;
basicUploadStatusEntity . setId ( CustomUtil . getId ( ) ) ;
basicUploadStatusEntity . setStartTime ( DateUtil . getDateTime ( ) ) ;
basicUploadStatusEntity . setRemark ( spsSyncScheduleResponse . toString ( ) ) ;
SystemParamConfigEntity systemParamConfigEntity = systemParamConfigService . selectByParamKey ( "sync_upstream_enable" ) ;
if ( systemParamConfigEntity . getParamValue ( ) . equals ( "0" ) ) { //上游不通
String path = getPath ( ) ;
String fileName = path + FileConstant . lowerWaitCopy_products + "ScheduleList_" + DateUtil . formatDate ( new Date ( ) , "yyyyMMddHHmmss" ) + ".UpperIn" ;
String datas = JSON . toJSONString ( spsSyncScheduleResponse ) ;
FileUtils . SaveFileAs ( datas , fileName ) ;
basicUploadStatusEntity . setUpdateTime ( new Date ( ) ) ;
basicUploadStatusEntity . setEndTime ( DateUtil . getDateTime ( ) ) ;
basicUploadStatusEntity . setStatus ( 1 ) ;
basicUploadStatusEntity . setTransportType ( BasicProcessStatus . FILE_TYPE ) ;
basicUploadService . insertDownloadStatus ( basicUploadStatusEntity ) ;
return ResultVOUtils . success ( "文件上传成功,已保存,等待拷贝!" ) ;
} else {
//上游通
return spPostHttp . postAllSchedule ( spsSyncScheduleResponse ) ;
BaseResponse < String > response = spPostHttp . postAllSchedule ( spsSyncScheduleResponse ) ;
basicUploadStatusEntity . setUpdateTime ( new Date ( ) ) ;
basicUploadStatusEntity . setEndTime ( DateUtil . getDateTime ( ) ) ;
basicUploadStatusEntity . setTransportType ( BasicProcessStatus . INTERFACE_TYPE ) ;
if ( response . getCode ( ) = = 20000 ) {
basicUploadStatusEntity . setStatus ( 1 ) ;
} else {
basicUploadStatusEntity . setStatus ( 0 ) ;
}
basicUploadService . insertDownloadStatus ( basicUploadStatusEntity ) ;
return response ;
}
}