|
@@ -4,34 +4,51 @@ import (
|
|
"app.yhyue.com/moapp/jybase/common"
|
|
"app.yhyue.com/moapp/jybase/common"
|
|
"app.yhyue.com/moapp/jybase/encrypt"
|
|
"app.yhyue.com/moapp/jybase/encrypt"
|
|
elastic "app.yhyue.com/moapp/jybase/es"
|
|
elastic "app.yhyue.com/moapp/jybase/es"
|
|
|
|
+ "app.yhyue.com/moapp/jybase/redis"
|
|
MC "bp.jydev.jianyu360.cn/BaseService/biCenter/api/common"
|
|
MC "bp.jydev.jianyu360.cn/BaseService/biCenter/api/common"
|
|
"bp.jydev.jianyu360.cn/BaseService/biCenter/api/internal/types"
|
|
"bp.jydev.jianyu360.cn/BaseService/biCenter/api/internal/types"
|
|
"fmt"
|
|
"fmt"
|
|
|
|
+ "github.com/gogf/gf/v2/util/gconv"
|
|
)
|
|
)
|
|
|
|
|
|
type SqlService struct {
|
|
type SqlService struct {
|
|
}
|
|
}
|
|
|
|
|
|
-func (l SqlService) SqlManage(in *types.SqlManageReq) (*[]map[string]interface{}, int64) {
|
|
|
|
|
|
+func (l SqlService) SqlManage(in *types.SqlManageReq) map[string]interface{} {
|
|
sqlData := MC.BaseMysql.FindOne("sql_manage", map[string]interface{}{
|
|
sqlData := MC.BaseMysql.FindOne("sql_manage", map[string]interface{}{
|
|
"id": common.Int64All(in.Id),
|
|
"id": common.Int64All(in.Id),
|
|
}, "", "")
|
|
}, "", "")
|
|
if sqlData == nil || len(*sqlData) == 0 {
|
|
if sqlData == nil || len(*sqlData) == 0 {
|
|
- return &[]map[string]interface{}{}, 0
|
|
|
|
|
|
+ return map[string]interface{}{}
|
|
}
|
|
}
|
|
dbType := (*sqlData)["db_type"]
|
|
dbType := (*sqlData)["db_type"]
|
|
|
|
+ cache_time := common.IntAll((*sqlData)["cache_time"])
|
|
|
|
+ key := common.GetMd5String(gconv.String(in))
|
|
|
|
+ if cache_time != 0 {
|
|
|
|
+ dataStr := redis.Get("other", key)
|
|
|
|
+ if dataStr != nil {
|
|
|
|
+ data, _ := dataStr.(map[string]interface{})
|
|
|
|
+ return data
|
|
|
|
+ }
|
|
|
|
+ }
|
|
rs := &[]map[string]interface{}{}
|
|
rs := &[]map[string]interface{}{}
|
|
count := int64(0)
|
|
count := int64(0)
|
|
switch dbType {
|
|
switch dbType {
|
|
case "es":
|
|
case "es":
|
|
count, rs = elastic.GetWithCount(common.InterfaceToStr((*sqlData)["db_name"]), common.InterfaceToStr((*sqlData)["db_name"]), "", Sqlformat(common.InterfaceToStr((*sqlData)["content"]), *in))
|
|
count, rs = elastic.GetWithCount(common.InterfaceToStr((*sqlData)["db_name"]), common.InterfaceToStr((*sqlData)["db_name"]), "", Sqlformat(common.InterfaceToStr((*sqlData)["content"]), *in))
|
|
}
|
|
}
|
|
-
|
|
|
|
for k, v := range *rs {
|
|
for k, v := range *rs {
|
|
(*rs)[k]["id"] = encrypt.EncodeArticleId2ByCheck(common.InterfaceToStr(v["id"]))
|
|
(*rs)[k]["id"] = encrypt.EncodeArticleId2ByCheck(common.InterfaceToStr(v["id"]))
|
|
delete((*rs)[k], "_id")
|
|
delete((*rs)[k], "_id")
|
|
}
|
|
}
|
|
- return rs, count
|
|
|
|
|
|
+ result := map[string]interface{}{
|
|
|
|
+ "data": rs,
|
|
|
|
+ "count": count,
|
|
|
|
+ }
|
|
|
|
+ if count > 0 && cache_time != 0 {
|
|
|
|
+ redis.Put("other", key, result, cache_time)
|
|
|
|
+ }
|
|
|
|
+ return result
|
|
}
|
|
}
|
|
func Sqlformat(sqlStr string, sqlData types.SqlManageReq) string {
|
|
func Sqlformat(sqlStr string, sqlData types.SqlManageReq) string {
|
|
data := []interface{}{}
|
|
data := []interface{}{}
|