From 3933669a0fe85c9e142b6192f7345a6ea0595eb0 Mon Sep 17 00:00:00 2001 From: wangshuai Date: Tue, 24 Nov 2020 16:39:18 +0800 Subject: [PATCH] 'commit' --- Logs/dsBaseRpc.log | 4 + dsDataexV1.1/Config/Config.ini | 29 ++++--- dsDataexV1.1/GenXorm/models/t_app_base.go | 16 ++++ .../MyService/Auth/AuthDAO/AuthDAO.go | 21 +++--- .../MyService/Auth/AuthService/AuthService.go | 16 ++-- dsSupport/Config/Config.ini | 2 +- .../MyModel/Account/AccountDAO/AccountDAO.go | 3 +- .../DatasourceOpenAPI/DatasourceOpenAPI.go | 4 +- .../DatasourceService/DatasourceService.go | 75 +++++++++++++++---- dsSupport/MyModel/MySwagger/Result2.go | 11 +++ dsSupport/Utils/ES7Util/DataEX/ESData2.go | 35 +++++++++ 11 files changed, 166 insertions(+), 50 deletions(-) create mode 100644 dsDataexV1.1/GenXorm/models/t_app_base.go create mode 100644 dsSupport/MyModel/MySwagger/Result2.go create mode 100644 dsSupport/Utils/ES7Util/DataEX/ESData2.go diff --git a/Logs/dsBaseRpc.log b/Logs/dsBaseRpc.log index 34d9288c..cdc359e1 100644 --- a/Logs/dsBaseRpc.log +++ b/Logs/dsBaseRpc.log @@ -52427,3 +52427,7 @@ [Error]2020/10/15 15:25:42 SqlQueryError bad connection [Error]2020/10/15 15:25:42 SqlQueryError bad connection [Error]2020/10/15 15:25:42 SqlQueryError bad connection +[Error]2020/11/23 14:24:28 SqlQueryError Error 1146: Table 'base_db_zhangjun.t_app_base' doesn't exist +[Error]2020/11/23 14:27:23 SqlQueryError Error 1146: Table 'base_db_zhangjun.t_app_base' doesn't exist +[Error]2020/11/23 14:27:37 SqlQueryError Error 1146: Table 'base_db_zhangjun.t_app_base' doesn't exist +[Error]2020/11/23 14:29:21 SqlQueryError Error 1146: Table 'base_db_zhangjun.t_app_base' doesn't exist diff --git a/dsDataexV1.1/Config/Config.ini b/dsDataexV1.1/Config/Config.ini index 0f2573ce..b5ee4a48 100644 --- a/dsDataexV1.1/Config/Config.ini +++ b/dsDataexV1.1/Config/Config.ini @@ -1,20 +1,25 @@ [mysql] -ip = 10.10.6.200 -port = 22066 -database = base_db_zhangjun -user = root -pwd = DsideaL147258369 - -;ip = 10.10.14.187 +;ip = 10.10.6.200 ;port = 22066 ;database = base_db_zhangjun ;user = root ;pwd = DsideaL147258369 +ip = 10.10.14.187 +port = 22066 +database = base_db_dev +user = root +pwd = DsideaL147258369 + [redis] -ip = 127.0.0.1 -port = 6379 -db = 1 +;ip = 127.0.0.1 +;port = 6379 +;db = 1 +;expireTime = 86400 + +ip = 10.10.14.187 +port = 18890 +db = 0 expireTime = 86400 ;ip =server.dsmin.com @@ -33,8 +38,8 @@ process_no = 1 [elasticsearch] ;nodes = http://10.10.14.188:9200, nodes = http://10.10.14.61:9200,http://10.10.14.62:9200,http://10.10.14.63:9200 -user = -pwd = +user = root +pwd = dsideal [project] project_name = dsDataex diff --git a/dsDataexV1.1/GenXorm/models/t_app_base.go b/dsDataexV1.1/GenXorm/models/t_app_base.go new file mode 100644 index 00000000..ade820e0 --- /dev/null +++ b/dsDataexV1.1/GenXorm/models/t_app_base.go @@ -0,0 +1,16 @@ +package models + +type TAppBase struct { + AppId string `json:"app_id" xorm:"not null pk comment('系统ID') CHAR(36)"` + AppCode string `json:"app_code" xorm:"not null comment('系统编码') VARCHAR(50)"` + AppName string `json:"app_name" xorm:"not null comment('系统名称') VARCHAR(100)"` + AccessKey string `json:"access_key" xorm:"not null comment('AK') CHAR(20)"` + SecretKey string `json:"secret_key" xorm:"not null comment('SK') CHAR(26)"` + AppToken string `json:"app_token" xorm:"not null comment('系统鉴权票据') CHAR(26)"` + AppUrl string `json:"app_url" xorm:"default 'NULL' comment('系统集成页面调用地址') VARCHAR(1024)"` + AppIcon string `json:"app_icon" xorm:"default 'NULL' comment('系统图标的路径') VARCHAR(1024)"` + RedirectUri string `json:"redirect_uri" xorm:"default 'NULL' comment('统一认证回调地址') VARCHAR(1024)"` + LogoutUri string `json:"logout_uri" xorm:"default 'NULL' comment('统一认证登出地址') VARCHAR(1024)"` + BUse int32 `json:"b_use" xorm:"not null comment('是否可用 -2:不可用 1:可用') TINYINT(1)"` + SortId int32 `json:"sort_id" xorm:"not null default 1 comment('排序号') INT(11)"` +} diff --git a/dsDataexV1.1/MyService/Auth/AuthDAO/AuthDAO.go b/dsDataexV1.1/MyService/Auth/AuthDAO/AuthDAO.go index fce10c1d..59718d6a 100644 --- a/dsDataexV1.1/MyService/Auth/AuthDAO/AuthDAO.go +++ b/dsDataexV1.1/MyService/Auth/AuthDAO/AuthDAO.go @@ -7,7 +7,6 @@ import ( "dsDataex/Utils/ErrorConst" "dsDataex/Utils/LogUtil" "html" - "time" ) //数据库 @@ -27,7 +26,7 @@ func GetbyID(id string) (bool, string, map[string]interface{}, error){ ids:=[]string{id} - result := CacheUtil.GetListByIds( ids ,CacheUtil.GetBean("t_dataex_linksystem")) + result := CacheUtil.GetListByIds( ids ,CacheUtil.GetBean("t_app_base")) if len(result)==1 { return true, "数据获取成功", result[0],nil @@ -48,7 +47,7 @@ func GetbyID(id string) (bool, string, map[string]interface{}, error){ **/ func GetbyCode(code string) (bool, string, map[string]interface{}, error){ - sql := "SELECT id from t_dataex_linksystem where delete_flag = -1 and enable_flag = 1 and system_code = '" + html.EscapeString(code) + "'" + sql := "SELECT app_id from t_app_base where b_use = 1 and app_code = '" + html.EscapeString(code) + "'" //通过SQL获取带缓存的数据 list, count, _ := CacheUtil.Page(sql, 10,0) @@ -72,21 +71,19 @@ func GetbyCode(code string) (bool, string, map[string]interface{}, error){ * @return string 结果说明 * @return error 异常 **/ -func Update(id string, authToken string ,authTime time.Time) (bool, string, error){ - business := new(models.TDataexLinksystem) +func Update(appId string, authToken string) (bool, string, error){ + business := new(models.TAppBase) //清除Redis缓存 - var ids = []string{id} - var selector = CacheUtil.GetBean("t_dataex_linksystem") + var ids = []string{appId} + var selector = CacheUtil.GetBean("t_app_base") CacheUtil.DeleteCacheByIds(ids, selector) - business.Id = html.EscapeString(id) - business.AuthToken = html.EscapeString(authToken) - business.AuthTime = authTime - business.ChangeTime = time.Now() + business.AppId = html.EscapeString(appId) + business.AppToken = html.EscapeString(authToken) //通过添加Cols函数指定需要更新结构体中的哪些值,未指定的将不更新,指定了的即使为0也会更新。 - _, err := db.Where(" id = ?", id ).Cols("auth_time", "auth_token", "change_time").Update(business) + _, err := db.Where(" app_id = ?", appId ).Cols("app_token").Update(business) if err != nil { LogUtil.Error(ErrorConst.SqlUpdateError, "接入系统authToken Update,数据库操作发生严重错误:"+err.Error()) diff --git a/dsDataexV1.1/MyService/Auth/AuthService/AuthService.go b/dsDataexV1.1/MyService/Auth/AuthService/AuthService.go index fe6722a0..a5a4c457 100644 --- a/dsDataexV1.1/MyService/Auth/AuthService/AuthService.go +++ b/dsDataexV1.1/MyService/Auth/AuthService/AuthService.go @@ -26,15 +26,15 @@ func CreateToken(systemID string,systemToken string,authTime string) (bool, stri return false,result,"" }else { - systemKey:= data["system_key"].(string) - id:= data["id"].(string) + systemKey:= data["secret_key"].(string) + appId:= data["app_id"].(string) if systemToken==MD5Util.MD5V1(MD5Util.MD5V1(systemID + authTime) + systemKey){ nowTime := time.Now() - authToken := "DSDataex_Token_"+MD5Util.MD5V1(systemID + nowTime.Format("2004-01-02 15:04:05") + systemKey) + authToken := "DSDataex_Token_"+MD5Util.MD5V1(systemID + nowTime.Format("2006-01-02 15:04:05") + systemKey) - AuthDAO.Update(id,authToken,nowTime) + AuthDAO.Update(appId,authToken) return true,"接入系统Token验证成功",authToken }else { @@ -63,7 +63,7 @@ func CheckToken(systemID string,authToken string) (bool, string,string){ return false,result,"" }else { - myToken:= data["auth_token"].(string) + myToken:= data["app_token"].(string) if myToken==authToken{ @@ -83,14 +83,14 @@ func CheckAccessToken(systemID string,accessTime string,accessToken string) (boo return false,result,"" }else { - if data["auth_token"] != nil { - myToken:= data["auth_token"].(string) + if data["app_token"] != nil { + myToken:= data["app_token"].(string) var testToken=MD5Util.MD5V1(systemID + accessTime + myToken) if testToken==accessToken{ - return true,"接入系统票据验证成功",data["id"].(string) + return true,"接入系统票据验证成功",data["app_id"].(string) }else { return false,"接入系统票据验证失败","" diff --git a/dsSupport/Config/Config.ini b/dsSupport/Config/Config.ini index de8d9cee..1f2f0719 100644 --- a/dsSupport/Config/Config.ini +++ b/dsSupport/Config/Config.ini @@ -25,7 +25,7 @@ pwd = DsideaL147258369 ;expireTime = 86400 ip = 10.10.14.187 port = 18890 -db = 0 +db = 1 expireTime = 86400 #gin服务器的端口 diff --git a/dsSupport/MyModel/Account/AccountDAO/AccountDAO.go b/dsSupport/MyModel/Account/AccountDAO/AccountDAO.go index 5ef7f424..4f316725 100644 --- a/dsSupport/MyModel/Account/AccountDAO/AccountDAO.go +++ b/dsSupport/MyModel/Account/AccountDAO/AccountDAO.go @@ -96,7 +96,8 @@ func CurrentUser(username string) (bool, string) { * @return error 异常 **/ func GetbyCode(code string) (bool, string, map[string]interface{}, error){ - sql := "SELECT * from t_dataex_linksystem where delete_flag = -1 and enable_flag = 1 and system_code = '" + html.EscapeString(code) + "'" + //sql := "SELECT * from t_dataex_linksystem where delete_flag = -1 and enable_flag = 1 and system_code = '" + html.EscapeString(code) + "'" + sql := "SELECT * from t_app_base where b_use = 1 and app_code = '" + html.EscapeString(code) + "'" var limit = 100 var offset = 0 diff --git a/dsSupport/MyModel/DataSource/DatasourceOpenAPI/DatasourceOpenAPI.go b/dsSupport/MyModel/DataSource/DatasourceOpenAPI/DatasourceOpenAPI.go index 0ace301e..8ce8b3ec 100644 --- a/dsSupport/MyModel/DataSource/DatasourceOpenAPI/DatasourceOpenAPI.go +++ b/dsSupport/MyModel/DataSource/DatasourceOpenAPI/DatasourceOpenAPI.go @@ -256,7 +256,7 @@ func ReadESDoc(c *gin.Context) { success, message, count, esdata := DatasourceService.ReadESDoc(datasourceCode, orgIDs, page, begin, conditions, sort) if success { - c.JSON(http.StatusOK, MySwagger.Result{ + c.JSON(http.StatusOK, MySwagger.Result2{ Success: true, Fail: false, Message: message, @@ -266,7 +266,7 @@ func ReadESDoc(c *gin.Context) { return } else { - c.JSON(http.StatusOK, MySwagger.Result{ + c.JSON(http.StatusOK, MySwagger.Result2{ Success: false, Fail: true, Message: message, diff --git a/dsSupport/MyModel/DataSource/DatasourceService/DatasourceService.go b/dsSupport/MyModel/DataSource/DatasourceService/DatasourceService.go index 2beac5a6..bccad560 100644 --- a/dsSupport/MyModel/DataSource/DatasourceService/DatasourceService.go +++ b/dsSupport/MyModel/DataSource/DatasourceService/DatasourceService.go @@ -8,6 +8,7 @@ import ( "dsSupport/Utils/CacheUtil" "dsSupport/Utils/CommonUtil" "dsSupport/Utils/ES7Util" + "dsSupport/Utils/ES7Util/DataEX" "dsSupport/models" "encoding/json" "fmt" @@ -216,31 +217,74 @@ func GetESDoc(datasourceCode string, dataId string) (bool, string, map[string]in return result, message, m } -func ReadESDoc(datasourceCode string, orgIDs []string, page int, begin string, conditions map[string]interface{}, sort map[string]interface{}) (bool, string, int, []map[string]interface{}) { +func ReadESDoc(datasourceCode string, orgIDs []string, page int, begin string, conditions map[string]interface{}, sort map[string]interface{}) (bool, string, int, []DataEX.ESData2) { + t1 := time.Now() count, _ := ES7Util.GetDocCount(datasourceCode, begin, conditions) + t2 := time.Now() + fmt.Println("t2与t1相差:", t2.Sub(t1)) result, message, esdata := ES7Util.SearchDocPage(datasourceCode, orgIDs, page, begin, conditions, sort) + t3 := time.Now() + fmt.Println("t3与t2相差:", t3.Sub(t2)) + var ESData2 []DataEX.ESData2 + var esData2 DataEX.ESData2 + + for _, value := range esdata { + var query = "AND datasource_code='" + datasourceCode + "'" + res, _, data, _ := DatasourceDAO.GetDatasourceRow(query) + var datasourceName interface{} + if res == true { + datasourceName = data["datasource_name"] + esData2.DatasourceName = datasourceName.(string) + } + + esData2.SystemId = value.SystemId + esData2.DatasourceId = value.DatasourceId + // + esData2.ProvinceId = value.ProvinceId + esData2.ProvinceName = value.ProvinceName + esData2.CityId = value.CityId + esData2.CityName = value.CityName + esData2.AreaId = value.AreaId + esData2.AreaName = value.AreaName + esData2.BureauId = value.BureauId + esData2.RegionId = value.RegionId + esData2.MainId = value.MainId + esData2.OrgId = value.OrgId + esData2.OrgName = value.OrgName + esData2.OrgType = value.OrgType + esData2.SchoolType = value.SchoolType + esData2.SchoolTypeName = value.SchoolTypeName + esData2.DeptId = value.DeptId + esData2.StageId = value.StageId + esData2.GradeId = value.GradeId + esData2.ClassId = value.ClassId + esData2.DataId = value.DataId + esData2.FileUri = value.FileUri + esData2.BeginTime = value.BeginTime + esData2.EndTime = value.EndTime + esData2.DelFlag = value.DelFlag + esData2.EnableFlag = value.EnableFlag + esData2.DataContent = value.DataContent + ESData2 = append(ESData2, esData2) + } + + /* var esDatas []map[string]interface{} var datas []map[string]interface{} - // 写法2 - //esDatas := make([]interface{}, count) - fmt.Println(esDatas) for _, value := range esdata { esData := make(map[string]interface{}) j, _ := json.Marshal(value) json.Unmarshal(j, &esData) - - //esData["datasource_name"] = datasourceName - //fmt.Println("esData:", esData) - esDatas = append(esDatas, esData) - // 写法2 - //esDatas[k] = make(map[string]interface{}, 1) - //esDatas[k] = esData } + */ + t4 := time.Now() + fmt.Println("t4与t3相差:", t4.Sub(t3)) + /* var query = "" res, _, _, datasources, _ := DatasourceDAO.GetAllDatasourceResults(query) fmt.Println(datasources) @@ -251,9 +295,12 @@ func ReadESDoc(datasourceCode string, orgIDs []string, page int, begin string, c json.Unmarshal([]byte(mergedesDatas), &datas) } - fmt.Println("datas:", datas) - - return result, message, count, datas + */ + //t4 := time.Now() + //fmt.Println("t4与t3相差:", t4.Sub(t3)) + fmt.Println("ESData2:", ESData2) + //var datas []map[string]interface{} + return result, message, count, ESData2 } //func IsDatasourceExistsByCode(code string) bool { diff --git a/dsSupport/MyModel/MySwagger/Result2.go b/dsSupport/MyModel/MySwagger/Result2.go new file mode 100644 index 00000000..1d9198a4 --- /dev/null +++ b/dsSupport/MyModel/MySwagger/Result2.go @@ -0,0 +1,11 @@ +package MySwagger + +import "dsSupport/Utils/ES7Util/DataEX" + +type Result2 struct { + Success bool `json:"success" example:"true"` + Fail bool `json:"fail" example:"false"` + Message string `json:"message" example:"操作成功"` + Total int `json:"total" example:"120"` + Data []DataEX.ESData2 `json:"data" ` +} diff --git a/dsSupport/Utils/ES7Util/DataEX/ESData2.go b/dsSupport/Utils/ES7Util/DataEX/ESData2.go new file mode 100644 index 00000000..973b8a71 --- /dev/null +++ b/dsSupport/Utils/ES7Util/DataEX/ESData2.go @@ -0,0 +1,35 @@ +package DataEX + +type ESData2 struct { + + SystemId string `json:"system_id"` + DatasourceId string `json:"datasource_id"` + DatasourceName string `json:"datasource_name"` + ProvinceId string `json:"province_code"` + ProvinceName string `json:"province_name"` + CityId string `json:"city_code"` + CityName string `json:"city_name"` + AreaId string `json:"district_code"` + AreaName string `json:"district_name"` + BureauId string `json:"bureau_id"` + RegionId string `json:"region_id"` + MainId string `json:"main_id"` + OrgId string `json:"org_id"` + OrgName string `json:"org_name" ` + OrgType int `json:"org_type"` + SchoolType string `json:"school_type"` + SchoolTypeName string `json:"school_typename"` + DeptId string `json:"dept_id"` + StageId string `json:"stage_id"` + GradeId string `json:"grade_id"` + ClassId string `json:"class_id"` + DataId string `json:"data_id"` + FileUri string `json:"file_uri"` + BeginTime JsonDate `json:"begin_time"` + EndTime JsonDate `json:"end_time"` + DelFlag int `json:"del_flag"` + EnableFlag int `json:"enable_flag"` + + DataContent map[string]interface{} `json:"data_content"` +} +