master
huanghai 5 years ago
parent a15a5ef731
commit d96e2fd9dd

@ -71,6 +71,10 @@ type logStruct struct {
IdInt int64 `json:"id_int"` IdInt int64 `json:"id_int"`
} }
//系统token
var SystemToken=""
//是否成功
var success =false
/** /**
*/ */
@ -93,7 +97,7 @@ func InitFull() {
if !FileUtil.PathExists(logName) { if !FileUtil.PathExists(logName) {
//SQL内容 //SQL内容
isql := FileUtil.ReadFileContent("./Sql/" + FullSqlDict[i].TableName + ".sql") isql := FileUtil.ReadFileContent("./Sql/" + FullSqlDict[i].TableName + ".sql")
sql:=isql sql := isql
var list []map[string]interface{} var list []map[string]interface{}
//如果是组织机构表,那么需要变更一下查询的排序条件 //如果是组织机构表,那么需要变更一下查询的排序条件
if FullSqlDict[i].TableName == "t_base_organization" { if FullSqlDict[i].TableName == "t_base_organization" {
@ -159,11 +163,15 @@ func InitFull() {
2020-07-16 2020-07-16
*/ */
func DataExchange() { func DataExchange() {
//获取系统token
success,SystemToken=getSystemToken()
if !success{
return
}
//死循环上报中 //死循环上报中
for { for {
//(1)组织机构上报 //(1)组织机构上报
InitFull() InitFull()
//(2)本轮上报的数量如果是0休息5秒后再继续上传 //(2)本轮上报的数量如果是0休息5秒后再继续上传
postCount := UploadData() postCount := UploadData()
if postCount == 0 { if postCount == 0 {
@ -238,49 +246,54 @@ func UploadData() int {
// 获取签名用的结构体 // 获取签名用的结构体
type authStruct struct { type authStruct struct {
AuthTime string `json:"auth_time"` AuthTime string `json:"auth_time"`
SystemId string `json:"system_id"` SystemId string `json:"system_id"`
SystemToken string `json:"system_token"` SystemToken string `json:"system_token"`
} }
/** /**
token
2020-07-17 2020-07-22
*/ */
func PostToServer(t tableStruct, list []map[string]interface{}) bool { func getSystemToken() (bool, string) {
//(1)计算出system_token=MD5.hash(MD5.hash(system_id+auth_time)+system_key) //(1)计算出system_token=MD5.hash(MD5.hash(system_id+auth_time)+system_key)
var as authStruct var as authStruct
as.AuthTime=CommonUtil.GetCurrentTime() as.AuthTime = CommonUtil.GetCurrentTime()
as.SystemId=ConfigUtil.DataExchangeSystemId as.SystemId = ConfigUtil.DataExchangeSystemId
//计算 md5 //计算 md5
w := md5.New() w := md5.New()
io.WriteString(w, as.SystemId+as.AuthTime) io.WriteString(w, as.SystemId+as.AuthTime)
//将str写入到w中 //将str写入到w中
md5str := fmt.Sprintf("%x", w.Sum(nil)) md5str := fmt.Sprintf("%x", w.Sum(nil))
w = md5.New() w = md5.New()
io.WriteString(w, md5str+ConfigUtil.DataExchangeSystemKey) io.WriteString(w, md5str+ConfigUtil.DataExchangeSystemKey)
//将str写入到w中 //将str写入到w中
md5str= fmt.Sprintf("%x", w.Sum(nil)) md5str = fmt.Sprintf("%x", w.Sum(nil))
//系统token //系统token
as.SystemToken=md5str as.SystemToken = md5str
//(2)根据system_token换取authToken //(2)根据system_token换取authToken
jsonBytes, err := json.Marshal(as) jsonBytes, _ := json.Marshal(as)
if err != nil {
fmt.Println(CommonUtil.GetCurrentTime() +err.Error())
return false
}
p := httpDo("POST", ConfigUtil.DataExchangeSystemAuthUrl, string(jsonBytes)) p := httpDo("POST", ConfigUtil.DataExchangeSystemAuthUrl, string(jsonBytes))
if !p.Success { if !p.Success {
fmt.Println(CommonUtil.GetCurrentTime() +"获取认证签名失败!") fmt.Println(CommonUtil.GetCurrentTime() + "获取认证签名失败!")
return false return false,"获取认证签名失败!"
} }
return true,p.Message
}
/**
2020-07-17
*/
func PostToServer(t tableStruct, list []map[string]interface{}) bool {
//上报到Http Api--->Body--->Post //上报到Http Api--->Body--->Post
var ps postStruct var ps postStruct
ps.DataSource = t.DataSource ps.DataSource = t.DataSource
ps.AuthToken =p.Message //p.Message中记录了authToken ps.AuthToken = SystemToken //p.Message中记录了authToken
ps.SystemId = ConfigUtil.DataExchangeSystemId ps.SystemId = ConfigUtil.DataExchangeSystemId
var dsMap = make([]dataStruct, 0) var dsMap = make([]dataStruct, 0)
for k := range list { for k := range list {
@ -300,10 +313,10 @@ func PostToServer(t tableStruct, list []map[string]interface{}) bool {
} }
ps.Datas = dsMap ps.Datas = dsMap
//将Struct转为json //将Struct转为json
jsonBytes, _ = json.Marshal(ps) jsonBytes, _ := json.Marshal(ps)
msg := string(jsonBytes) msg := string(jsonBytes)
//提交到汇集中心 //提交到汇集中心
p = httpDo("POST", ConfigUtil.DataExchangeUrl, msg) p := httpDo("POST", ConfigUtil.DataExchangeUrl, msg)
if !p.Success { if !p.Success {
fmt.Println(CommonUtil.GetCurrentTime() + " 同步上报到数据汇集中心失败将休息5秒后重试错误原因" + p.Message) fmt.Println(CommonUtil.GetCurrentTime() + " 同步上报到数据汇集中心失败将休息5秒后重试错误原因" + p.Message)
time.Sleep(5 * 1e9) time.Sleep(5 * 1e9)

Loading…
Cancel
Save