diff --git a/dsBaseRpc/DataExchange/DataExchange.go b/dsBaseRpc/DataExchange/DataExchange.go index 42757763..ea8aab00 100644 --- a/dsBaseRpc/DataExchange/DataExchange.go +++ b/dsBaseRpc/DataExchange/DataExchange.go @@ -18,8 +18,9 @@ var db = DbUtil.Engine //每次获取的条数 var limit = 100 + //默认开始时间 -var defaultStartTs="1970-01-01 00:00:00" +var defaultStartTs = "1970-01-01 00:00:00" // 日志文件路径 var progressFilePath = "/usr/local/SyncDataLogs/" @@ -66,15 +67,13 @@ func init() { os.MkdirAll(progressFilePath, os.ModePerm) } } - /** -功能:数据上报 +功能:组织机构上报 作者:黄海 -时间:2020-07-16 -*/ -func DataExchange() { - //是不是进行过首次上报,如果没有话,需要执行一次组织机构上报 - //日志文件位置 +时间:2020-07-17 + */ +func InitOrg() { + //(1)是不是进行过首次上报,如果没有话,需要执行一次组织机构上报 logName := progressFilePath + "t_base_organization.log" //判断文件是不是存在 if !FileUtil.PathExists(logName) { @@ -86,8 +85,8 @@ func DataExchange() { list, _ := db.SQL(orgSql).Query().List() var l logStruct l.IdInt = 0 - l.StartUpdateTs = defaultStartTs - if len(list)>0{ + l.StartUpdateTs = defaultStartTs + if len(list) > 0 { l.StartUpdateTs = list[len(list)-1]["last_updated_time"].(string) l.IdInt = list[len(list)-1]["id_int"].(int64) } @@ -106,15 +105,15 @@ func DataExchange() { } //利用切片分批次上报 if len(list) > limit { - success:=PostToServer(t, list[0:limit]) //0-99不包含100 - if !success{ + success := PostToServer(t, list[0:limit]) //0-99不包含100 + if !success { continue } count = count + limit list = list[limit:] } else if len(list) > 0 { - success:=PostToServer(t, list) - if !success{ + success := PostToServer(t, list) + if !success { continue } count = count + len(list) @@ -131,9 +130,19 @@ func DataExchange() { } FileUtil.WriteContent(logName, string(jsonBytes)) } +} +/** +功能:数据上报 +作者:黄海 +时间:2020-07-16 +*/ +func DataExchange() { + //死循环上报中 for { - //本轮上报的数量,如果是0,休息5秒后再继续上传 + //(1)组织机构上报 + InitOrg() + //(2)本轮上报的数量,如果是0,休息5秒后再继续上传 postCount := UploadData() if postCount == 0 { fmt.Println(CommonUtil.GetCurrentTime() + " 同步:本轮没有可以上报的数据,将休息5秒!") @@ -306,8 +315,8 @@ func getRecordGt(gtSql string, lastUpdatedTime string, idInt int64, limit int) ( } type ResultStruct struct { - Message string `json:"message"` - Success bool `json:"success"` + Message string `json:"message"` + Success bool `json:"success"` } // 基础方法,这里多用于访问webapi,配合上json转换。此方法可以运行但是不算完善。