Compare commits
25 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2ee0838d8a | |||
| 72c23499f2 | |||
| 96d8868694 | |||
| 1533a57cb8 | |||
| 615f52d2e4 | |||
| f7dfd4ec77 | |||
| 2276aa12ef | |||
| 6505594fd0 | |||
| c55e26021b | |||
| 78420a692f | |||
| 6d9af149ad | |||
| 253cad35ef | |||
| 47c8736f34 | |||
| dcce8ace9e | |||
| 125ccc5c3b | |||
| 432d59d483 | |||
| 60f222b011 | |||
| 7a8b86ed12 | |||
| b940afa6b0 | |||
| 8afd00ff86 | |||
| 8992fd6d3a | |||
| 524a892480 | |||
| c420e23edb | |||
| 7419e03d67 | |||
| 9425544d1c |
+11
-17
@@ -23,7 +23,6 @@ type Application struct {
|
||||
MakeCodeRouter map[string]*code.MakeCode
|
||||
MethodRouter
|
||||
Router
|
||||
ContextBase
|
||||
Error
|
||||
Log *logrus.Logger
|
||||
WebConnectLog *logrus.Logger
|
||||
@@ -375,15 +374,17 @@ func (that *Application) handler(w http.ResponseWriter, req *http.Request) {
|
||||
}()
|
||||
|
||||
//访问拦截true继续false暂停
|
||||
connectListenerLen := len(that.connectListener)
|
||||
|
||||
for i := connectListenerLen - 1; i >= 0; i-- {
|
||||
|
||||
if that.connectListener[i](&context) {
|
||||
connectListenerLen := len(that.connectListener) - 1
|
||||
|
||||
for true {
|
||||
if connectListenerLen < 0 {
|
||||
break
|
||||
}
|
||||
if that.connectListener[connectListenerLen](&context) {
|
||||
context.View()
|
||||
return
|
||||
}
|
||||
connectListenerLen--
|
||||
}
|
||||
|
||||
//接口服务
|
||||
@@ -567,14 +568,9 @@ func Init(config string) *Application {
|
||||
codeMake["name"] = codeMake.GetString("table")
|
||||
}
|
||||
|
||||
if appIns.Config.GetInt("mode") > 0 {
|
||||
appIns.MakeCodeRouter[codeMake.GetString("name")] = &code.MakeCode{Error: appIns.Error}
|
||||
appIns.MakeCodeRouter[codeMake.GetString("name")] = &code.MakeCode{Error: appIns.Error}
|
||||
appIns.MakeCodeRouter[codeMake.GetString("name")].Db2JSON(&appIns.Db, codeMake)
|
||||
|
||||
appIns.MakeCodeRouter[codeMake.GetString("name")].Db2JSON(&appIns.Db, codeMake)
|
||||
} else {
|
||||
appIns.MakeCodeRouter[codeMake.GetString("name")] = &code.MakeCode{Error: appIns.Error}
|
||||
appIns.MakeCodeRouter[codeMake.GetString("name")].Db2JSON(nil, codeMake)
|
||||
}
|
||||
//接入动态代码层
|
||||
if appIns.Router == nil {
|
||||
appIns.Router = Router{}
|
||||
@@ -593,9 +589,7 @@ func Init(config string) *Application {
|
||||
appIns.Router[codeMake.GetString("name")][k1] = appIns.Router[codeMake.GetString("name")]["hotimeCommon"]
|
||||
}
|
||||
|
||||
go func() {
|
||||
setMakeCodeLintener(codeMake.GetString("name"), &appIns)
|
||||
}()
|
||||
setMakeCodeListener(codeMake.GetString("name"), &appIns)
|
||||
|
||||
}
|
||||
|
||||
@@ -665,7 +659,7 @@ func SetSqliteDB(appIns *Application, config Map) {
|
||||
})
|
||||
}
|
||||
|
||||
func setMakeCodeLintener(name string, appIns *Application) {
|
||||
func setMakeCodeListener(name string, appIns *Application) {
|
||||
appIns.SetConnectListener(func(context *Context) (isFinished bool) {
|
||||
|
||||
codeIns := appIns.MakeCodeRouter[name]
|
||||
|
||||
@@ -57,45 +57,6 @@ var TptProject = Proj{
|
||||
}
|
||||
re[link] = that.Db.Get(column.GetString("link"), seStr, Map{"id": v})
|
||||
}
|
||||
|
||||
//权限设置
|
||||
if column["type"] == "auth" {
|
||||
|
||||
btes, err := ioutil.ReadFile(fileConfig.GetString("config"))
|
||||
|
||||
if err != nil {
|
||||
that.Display(4, "找不到权限配置文件")
|
||||
return
|
||||
}
|
||||
|
||||
conf := ObjToMap(string(btes))
|
||||
menus := conf.GetSlice("menus")
|
||||
|
||||
userAuth := re.GetMap("auth")
|
||||
|
||||
for k1, _ := range menus {
|
||||
v1 := menus.GetMap(k1)
|
||||
if userAuth[v1.GetString("name")] != nil {
|
||||
v1["auth"] = userAuth[v1.GetString("name")]
|
||||
}
|
||||
if userAuth[v1.GetString("table")] != nil {
|
||||
v1["auth"] = userAuth[v1.GetString("table")]
|
||||
}
|
||||
v1menus := v1.GetSlice("menus")
|
||||
for k2, _ := range v1menus {
|
||||
v2 := v1menus.GetMap(k2)
|
||||
if userAuth[v2.GetString("name")] != nil {
|
||||
v2["auth"] = userAuth[v2.GetString("name")]
|
||||
}
|
||||
if userAuth[v2.GetString("table")] != nil {
|
||||
v2["auth"] = userAuth[v2.GetString("table")]
|
||||
}
|
||||
}
|
||||
}
|
||||
re["auth"] = menus.ToJsonString()
|
||||
//that.Display(0,menus)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//如果有table字段则代为link
|
||||
@@ -135,230 +96,109 @@ var TptProject = Proj{
|
||||
|
||||
for _, v := range that.MakeCodeRouter[hotimeName].TableColumns[fileConfig.GetString("table")] {
|
||||
if v.GetString("link") != "" {
|
||||
|
||||
//与用户信息有关联的parent_id自填充
|
||||
if v.GetString("link") == tableName && that.MakeCodeRouter[hotimeName].TableColumns[v.GetString("link")]["parent_id"] != nil {
|
||||
if inData["parent_id"] == nil {
|
||||
if inData["parent_id"] == nil && data[v.GetString("name")] != nil {
|
||||
inData["parent_id"] = data.GetCeilInt64(v.GetString("name"))
|
||||
pre := that.Db.Get(v.GetString("link"), "parent_ids", Map{"id": data.GetCeilInt64(v.GetString("name"))})
|
||||
inData["parent_ids"] = pre.GetString("parent_ids")
|
||||
//pre := that.Db.Get(v.GetString("link"), "parent_ids", Map{"id": data.GetCeilInt64(v.GetString("name"))})
|
||||
//inData["parent_ids"] = pre.GetString("parent_ids")+ObjToStr(data.GetCeilInt64(v.GetString("name")))+","
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if inData["auth"] != nil {
|
||||
if v.GetString("link") == tableName && that.MakeCodeRouter[hotimeName].TableColumns[v.GetString("link")]["auth"] != nil {
|
||||
linkAuthMap := that.Db.Get(v.GetString("link"), "auth", Map{"id": data.GetCeilInt(v.GetString("name"))})
|
||||
linkAuth := linkAuthMap.GetMap("auth")
|
||||
|
||||
btes, err := ioutil.ReadFile(fileConfig.GetString("config"))
|
||||
if linkAuth == nil {
|
||||
btes, err := ioutil.ReadFile(fileConfig.GetString("config"))
|
||||
if err != nil {
|
||||
that.Display(4, "找不到配置文件")
|
||||
return
|
||||
}
|
||||
linkAuth = Map{}
|
||||
conf := ObjToMap(string(btes))
|
||||
menus := conf.GetSlice("menus")
|
||||
|
||||
if err != nil {
|
||||
that.Display(4, "找不到配置文件")
|
||||
return
|
||||
}
|
||||
|
||||
conf := ObjToMap(string(btes))
|
||||
menus := conf.GetSlice("menus")
|
||||
|
||||
for _, v := range that.MakeCodeRouter[hotimeName].TableColumns[fileConfig.GetString("table")] {
|
||||
if v.GetString("link") != "" && that.MakeCodeRouter[hotimeName].TableColumns[v.GetString("link")]["auth"] != nil {
|
||||
//linkHasAuth := that.MakeCodeRouter[hotimeName].TableColumns[v.GetString("link")]["auth"]
|
||||
//if linkHasAuth != nil {
|
||||
|
||||
linkAuthMap := that.Db.Get(v.GetString("link"), "auth", Map{"id": data.GetCeilInt(v.GetString("name"))})
|
||||
linkAuth := linkAuthMap.GetMap("auth")
|
||||
myAuth := Map{}
|
||||
if linkAuth != nil {
|
||||
|
||||
for k1, _ := range menus {
|
||||
|
||||
v1 := menus.GetMap(k1)
|
||||
|
||||
if linkAuth[v1.GetString("table")] != nil {
|
||||
v1["auth"] = linkAuth[v1.GetString("table")]
|
||||
|
||||
}
|
||||
if linkAuth[v1.GetString("name")] != nil {
|
||||
v1["auth"] = linkAuth[v1.GetString("name")]
|
||||
|
||||
}
|
||||
|
||||
if v1.GetString("name") != "" && v1["auth"] == nil {
|
||||
v1["auth"] = Slice{"show"}
|
||||
|
||||
}
|
||||
|
||||
if v1.GetString("table") != "" && v1["auth"] == nil {
|
||||
v1["auth"] = that.MakeCodeRouter[hotimeName].TableConfig.GetMap(v1.GetString("table"))["auth"]
|
||||
}
|
||||
|
||||
if v1.GetString("table") != "" {
|
||||
myAuth[v1.GetString("table")] = v1
|
||||
}
|
||||
if v1.GetString("name") != "" {
|
||||
myAuth[v1.GetString("name")] = v1
|
||||
}
|
||||
|
||||
v1menus := v1.GetSlice("menus")
|
||||
for k2, _ := range v1menus {
|
||||
v2 := v1menus.GetMap(k2)
|
||||
if linkAuth[v2.GetString("table")] != nil {
|
||||
v2["auth"] = linkAuth[v2.GetString("table")]
|
||||
for k1, _ := range menus {
|
||||
v1 := menus.GetMap(k1)
|
||||
name := v1.GetString("name")
|
||||
if name == "" {
|
||||
name = v1.GetString("table")
|
||||
}
|
||||
if v1["auth"] != nil {
|
||||
|
||||
if linkAuth[name] == nil {
|
||||
linkAuth[name] = v1["auth"]
|
||||
} else {
|
||||
newAuth := Slice{}
|
||||
for k2, _ := range linkAuth.GetSlice(name) {
|
||||
v2 := linkAuth.GetSlice(name).GetString(k2)
|
||||
if strings.Contains(v1.GetString("auth"), v2) {
|
||||
newAuth = append(newAuth, v2)
|
||||
}
|
||||
}
|
||||
linkAuth[name] = newAuth
|
||||
}
|
||||
}
|
||||
|
||||
if linkAuth[v2.GetString("name")] != nil {
|
||||
v2["auth"] = linkAuth[v2.GetString("name")]
|
||||
}
|
||||
menusChild := v1.GetSlice("menus")
|
||||
for k2, _ := range menusChild {
|
||||
v2 := menusChild.GetMap(k2)
|
||||
name := v2.GetString("name")
|
||||
if name == "" {
|
||||
name = v2.GetString("table")
|
||||
}
|
||||
if v2["auth"] != nil {
|
||||
|
||||
if v2.GetString("name") != "" && v2["auth"] == nil {
|
||||
v2["auth"] = Slice{"show"}
|
||||
if linkAuth[name] == nil {
|
||||
linkAuth[name] = v2["auth"]
|
||||
|
||||
}
|
||||
} else {
|
||||
|
||||
if v2.GetString("table") != "" && v2["auth"] == nil {
|
||||
v2["auth"] = that.MakeCodeRouter[hotimeName].TableConfig.GetMap(v2.GetString("table"))["auth"]
|
||||
}
|
||||
newAuth := Slice{}
|
||||
for k3, _ := range linkAuth.GetSlice(name) {
|
||||
v3 := linkAuth.GetSlice(name).GetString(k3)
|
||||
if strings.Contains(v2.GetString("auth"), v3) {
|
||||
newAuth = append(newAuth, v3)
|
||||
}
|
||||
}
|
||||
linkAuth[name] = newAuth
|
||||
continue
|
||||
|
||||
if v2.GetString("table") != "" {
|
||||
myAuth[v2.GetString("table")] = v2
|
||||
}
|
||||
|
||||
if v2.GetString("name") != "" {
|
||||
myAuth[v2.GetString("name")] = v2
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
newAuth := inData.GetSlice("auth")
|
||||
toDB := Map{}
|
||||
for k1, _ := range newAuth {
|
||||
v1 := newAuth.GetMap(k1)
|
||||
toDB := Map{}
|
||||
newAuth := inData.GetMap("auth")
|
||||
if newAuth == nil {
|
||||
inData["auth"] = linkAuth.ToJsonString()
|
||||
continue
|
||||
}
|
||||
|
||||
if myAuth.GetMap(v1.GetString("name")) == nil && myAuth.GetMap(v1.GetString("table")) == nil {
|
||||
for k1, _ := range newAuth {
|
||||
v1 := newAuth.GetSlice(k1)
|
||||
if linkAuth.GetString(k1) == "" {
|
||||
continue
|
||||
}
|
||||
toDbli := Slice{}
|
||||
for k2, _ := range v1 {
|
||||
v2 := v1.GetString(k2)
|
||||
|
||||
if !strings.Contains(linkAuth.GetString(k1), `"`+v2+`"`) {
|
||||
continue
|
||||
}
|
||||
|
||||
auth := Slice{}
|
||||
|
||||
str := v1.GetString("name")
|
||||
|
||||
if v1.GetString("table") != "" {
|
||||
|
||||
str = v1.GetString("table")
|
||||
}
|
||||
|
||||
if v1.GetString("auth") == "" {
|
||||
if myAuth.GetMap(str).GetString("table") != "" {
|
||||
auth = that.MakeCodeRouter[hotimeName].TableConfig.GetMap(str).GetSlice("auth")
|
||||
} else {
|
||||
auth = Slice{"show"}
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
if strings.Contains(myAuth.GetMap(str).GetString("auth"), `"show"`) &&
|
||||
strings.Contains(v1.GetString("auth"), `"show"`) {
|
||||
auth = append(auth, "show")
|
||||
|
||||
}
|
||||
|
||||
if strings.Contains(myAuth.GetMap(str).GetString("auth"), `"download"`) &&
|
||||
strings.Contains(v1.GetString("auth"), `"download"`) {
|
||||
auth = append(auth, "download")
|
||||
|
||||
}
|
||||
|
||||
if strings.Contains(myAuth.GetMap(str).GetString("auth"), `"add"`) &&
|
||||
strings.Contains(v1.GetString("auth"), `"add"`) {
|
||||
auth = append(auth, "add")
|
||||
//continue
|
||||
}
|
||||
if strings.Contains(myAuth.GetMap(str).GetString("auth"), `"edit"`) &&
|
||||
strings.Contains(v1.GetString("auth"), `"edit"`) {
|
||||
auth = append(auth, "edit")
|
||||
|
||||
}
|
||||
if strings.Contains(myAuth.GetMap(str).GetString("auth"), `"delete"`) &&
|
||||
strings.Contains(v1.GetString("auth"), `"delete"`) {
|
||||
auth = append(auth, "delete")
|
||||
|
||||
}
|
||||
if strings.Contains(myAuth.GetMap(str).GetString("auth"), `"info"`) &&
|
||||
strings.Contains(v1.GetString("auth"), `"info"`) {
|
||||
auth = append(auth, "info")
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
toDB[str] = auth
|
||||
v1Menus := v1.GetSlice("menus")
|
||||
for k2, _ := range v1Menus {
|
||||
v2 := v1Menus.GetMap(k2)
|
||||
|
||||
if myAuth.GetMap(v2.GetString("name")) == nil && myAuth.GetMap(v2.GetString("table")) == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
auth := Slice{}
|
||||
|
||||
str := v2.GetString("name")
|
||||
|
||||
if v2.GetString("table") != "" {
|
||||
|
||||
str = v2.GetString("table")
|
||||
}
|
||||
|
||||
if v2.GetString("auth") == "" {
|
||||
if myAuth.GetMap(str).GetString("table") != "" {
|
||||
auth = that.MakeCodeRouter[hotimeName].TableConfig.GetMap(str).GetSlice("auth")
|
||||
} else {
|
||||
auth = Slice{"show"}
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
if strings.Contains(myAuth.GetMap(str).GetString("auth"), `"show"`) &&
|
||||
strings.Contains(v2.GetString("auth"), `"show"`) {
|
||||
auth = append(auth, "show")
|
||||
|
||||
}
|
||||
if strings.Contains(myAuth.GetMap(str).GetString("auth"), `"download"`) &&
|
||||
strings.Contains(v1.GetString("auth"), `"download"`) {
|
||||
auth = append(auth, "download")
|
||||
|
||||
}
|
||||
if strings.Contains(myAuth.GetMap(str).GetString("auth"), `"add"`) &&
|
||||
strings.Contains(v2.GetString("auth"), `"add"`) {
|
||||
auth = append(auth, "add")
|
||||
//continue
|
||||
}
|
||||
if strings.Contains(myAuth.GetMap(str).GetString("auth"), `"edit"`) &&
|
||||
strings.Contains(v2.GetString("auth"), `"edit"`) {
|
||||
auth = append(auth, "edit")
|
||||
|
||||
}
|
||||
if strings.Contains(myAuth.GetMap(str).GetString("auth"), `"delete"`) &&
|
||||
strings.Contains(v2.GetString("auth"), `"delete"`) {
|
||||
auth = append(auth, "delete")
|
||||
|
||||
}
|
||||
if strings.Contains(myAuth.GetMap(str).GetString("auth"), `"info"`) &&
|
||||
strings.Contains(v2.GetString("auth"), `"info"`) {
|
||||
auth = append(auth, "info")
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
toDB[str] = auth
|
||||
|
||||
}
|
||||
|
||||
toDbli = append(toDbli, v2)
|
||||
}
|
||||
inData["auth"] = toDB.ToJsonString()
|
||||
break
|
||||
toDB[k1] = toDbli
|
||||
}
|
||||
//}
|
||||
|
||||
inData["auth"] = toDB.ToJsonString()
|
||||
//break
|
||||
}
|
||||
}
|
||||
|
||||
@@ -369,14 +209,16 @@ var TptProject = Proj{
|
||||
return
|
||||
}
|
||||
//索引管理,便于检索以及权限
|
||||
if inData.Get("parent_id") != nil && inData.GetString("parent_ids") != "" {
|
||||
if inData.Get("parent_id") != nil {
|
||||
index := that.Db.Get(tableName, "`parent_ids`", Map{"id": inData.Get("parent_id")})
|
||||
inData["parent_ids"] = index.GetString("parent_ids") + ObjToStr(re) + ","
|
||||
that.Db.Update(tableName, Map{"parent_ids": inData["parent_ids"]}, Map{"id": re})
|
||||
} else if inData.GetString("parent_ids") != "" {
|
||||
inData["parent_ids"] = "," + ObjToStr(re) + ","
|
||||
parent_ids := index.GetString("parent_ids")
|
||||
if parent_ids == "" {
|
||||
parent_ids = ","
|
||||
}
|
||||
inData["parent_ids"] = parent_ids + ObjToStr(re) + ","
|
||||
that.Db.Update(tableName, Map{"parent_ids": inData["parent_ids"]}, Map{"id": re})
|
||||
}
|
||||
|
||||
that.Log["table_id"] = re
|
||||
that.Display(0, re)
|
||||
},
|
||||
@@ -393,254 +235,144 @@ var TptProject = Proj{
|
||||
that.Display(3, "没有找到要更新的数据")
|
||||
return
|
||||
}
|
||||
|
||||
data := that.Db.Get(fileConfig.GetString("table"), "*", Map{"id": that.Session(fileConfig.GetString("table") + "_id").ToCeilInt()})
|
||||
|
||||
//树状结构不允许修改自身的属性,修改别人的可以
|
||||
if fileConfig.GetString("table") == tableName && that.RouterString[2] == that.Session(fileConfig.GetString("table")+"_id").ToStr() {
|
||||
btes, err := ioutil.ReadFile(fileConfig.GetString("config"))
|
||||
if err != nil {
|
||||
that.Display(4, "找不到权限配置文件")
|
||||
return
|
||||
}
|
||||
|
||||
for _, v := range that.MakeCodeRouter[hotimeName].TableColumns[fileConfig.GetString("table")] {
|
||||
|
||||
if v.GetString("link") == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
if that.MakeCodeRouter[hotimeName].TableColumns[v.GetString("link")]["parent_id"] != nil {
|
||||
|
||||
delete(inData, v.GetString("name"))
|
||||
}
|
||||
conf := ObjToMap(string(btes))
|
||||
|
||||
stop := conf.GetSlice("stop")
|
||||
for k, _ := range stop {
|
||||
v := stop.GetString(k)
|
||||
//不能改对应行数据
|
||||
if tableName == v && data.GetCeilInt64(v+"_id") == ObjToCeilInt64(that.RouterString[2]) {
|
||||
that.Display(4, "你没有权限修改当前数据")
|
||||
return
|
||||
}
|
||||
//不能改自身对应的数据
|
||||
if tableName == fileConfig.GetString("table") && inData[v+"_id"] != nil {
|
||||
delete(inData, v+"_id")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if inData["auth"] != nil {
|
||||
|
||||
btes, err := ioutil.ReadFile(fileConfig.GetString("config"))
|
||||
|
||||
if err != nil {
|
||||
that.Display(4, "找不到配置文件")
|
||||
return
|
||||
}
|
||||
|
||||
conf := ObjToMap(string(btes))
|
||||
menus := conf.GetSlice("menus")
|
||||
|
||||
for _, v := range that.MakeCodeRouter[hotimeName].TableColumns[fileConfig.GetString("table")] {
|
||||
if v.GetString("link") != "" && that.MakeCodeRouter[hotimeName].TableColumns[v.GetString("link")]["auth"] != nil {
|
||||
//linkHasAuth := that.MakeCodeRouter[hotimeName].TableColumns[v.GetString("link")]["auth"]
|
||||
//if linkHasAuth != nil {
|
||||
|
||||
if v.GetString("link") != "" && that.MakeCodeRouter[hotimeName].TableColumns[v.GetString("link")]["auth"] != nil {
|
||||
linkAuthMap := that.Db.Get(v.GetString("link"), "auth", Map{"id": data.GetCeilInt(v.GetString("name"))})
|
||||
linkAuth := linkAuthMap.GetMap("auth")
|
||||
myAuth := Map{}
|
||||
if linkAuth != nil {
|
||||
//conf := ObjToMap(string(btes))
|
||||
//menus := conf.GetSlice("menus")
|
||||
if linkAuth == nil {
|
||||
linkAuth = Map{}
|
||||
}
|
||||
|
||||
for k1, _ := range menus {
|
||||
|
||||
v1 := menus.GetMap(k1)
|
||||
|
||||
if linkAuth[v1.GetString("table")] != nil {
|
||||
v1["auth"] = linkAuth[v1.GetString("table")]
|
||||
|
||||
}
|
||||
if linkAuth[v1.GetString("name")] != nil {
|
||||
v1["auth"] = linkAuth[v1.GetString("name")]
|
||||
|
||||
}
|
||||
|
||||
if v1.GetString("name") != "" && v1["auth"] == nil {
|
||||
v1["auth"] = Slice{"show"}
|
||||
|
||||
}
|
||||
|
||||
if v1.GetString("table") != "" && v1["auth"] == nil {
|
||||
v1["auth"] = that.MakeCodeRouter[hotimeName].TableConfig.GetMap(v1.GetString("table"))["auth"]
|
||||
}
|
||||
|
||||
if v1.GetString("table") != "" {
|
||||
myAuth[v1.GetString("table")] = v1
|
||||
}
|
||||
if v1.GetString("name") != "" {
|
||||
myAuth[v1.GetString("name")] = v1
|
||||
}
|
||||
|
||||
v1menus := v1.GetSlice("menus")
|
||||
for k2, _ := range v1menus {
|
||||
v2 := v1menus.GetMap(k2)
|
||||
if linkAuth[v2.GetString("table")] != nil {
|
||||
v2["auth"] = linkAuth[v2.GetString("table")]
|
||||
for k1, _ := range menus {
|
||||
v1 := menus.GetMap(k1)
|
||||
name := v1.GetString("name")
|
||||
if name == "" {
|
||||
name = v1.GetString("table")
|
||||
}
|
||||
if v1["auth"] != nil {
|
||||
|
||||
if linkAuth[name] == nil {
|
||||
linkAuth[name] = v1["auth"]
|
||||
} else {
|
||||
newAuth := Slice{}
|
||||
for k2, _ := range linkAuth.GetSlice(name) {
|
||||
v2 := linkAuth.GetSlice(name).GetString(k2)
|
||||
if strings.Contains(v1.GetString("auth"), v2) {
|
||||
newAuth = append(newAuth, v2)
|
||||
}
|
||||
}
|
||||
linkAuth[name] = newAuth
|
||||
}
|
||||
}
|
||||
|
||||
if linkAuth[v2.GetString("name")] != nil {
|
||||
v2["auth"] = linkAuth[v2.GetString("name")]
|
||||
}
|
||||
menusChild := v1.GetSlice("menus")
|
||||
for k2, _ := range menusChild {
|
||||
v2 := menusChild.GetMap(k2)
|
||||
name := v2.GetString("name")
|
||||
if name == "" {
|
||||
name = v2.GetString("table")
|
||||
}
|
||||
if v2["auth"] != nil {
|
||||
|
||||
if v2.GetString("name") != "" && v2["auth"] == nil {
|
||||
v2["auth"] = Slice{"show"}
|
||||
if linkAuth[name] == nil {
|
||||
linkAuth[name] = v2["auth"]
|
||||
|
||||
}
|
||||
} else {
|
||||
|
||||
if v2.GetString("table") != "" && v2["auth"] == nil {
|
||||
v2["auth"] = that.MakeCodeRouter[hotimeName].TableConfig.GetMap(v2.GetString("table"))["auth"]
|
||||
}
|
||||
newAuth := Slice{}
|
||||
for k3, _ := range linkAuth.GetSlice(name) {
|
||||
v3 := linkAuth.GetSlice(name).GetString(k3)
|
||||
if strings.Contains(v2.GetString("auth"), v3) {
|
||||
newAuth = append(newAuth, v3)
|
||||
}
|
||||
}
|
||||
linkAuth[name] = newAuth
|
||||
continue
|
||||
|
||||
if v2.GetString("table") != "" {
|
||||
myAuth[v2.GetString("table")] = v2
|
||||
}
|
||||
|
||||
if v2.GetString("name") != "" {
|
||||
myAuth[v2.GetString("name")] = v2
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
newAuth := inData.GetSlice("auth")
|
||||
toDB := Map{}
|
||||
newAuth := inData.GetMap("auth")
|
||||
if newAuth == nil || len(newAuth) == 0 {
|
||||
inData["auth"] = linkAuth.ToJsonString()
|
||||
break
|
||||
}
|
||||
//不可超出用户权限
|
||||
for k1, _ := range newAuth {
|
||||
v1 := newAuth.GetMap(k1)
|
||||
|
||||
if myAuth.GetMap(v1.GetString("name")) == nil && myAuth.GetMap(v1.GetString("table")) == nil {
|
||||
v1 := newAuth.GetSlice(k1)
|
||||
if linkAuth.GetString(k1) == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
auth := Slice{}
|
||||
|
||||
str := v1.GetString("name")
|
||||
|
||||
if v1.GetString("table") != "" {
|
||||
|
||||
str = v1.GetString("table")
|
||||
}
|
||||
|
||||
if v1.GetString("auth") == "" {
|
||||
if myAuth.GetMap(str).GetString("table") != "" {
|
||||
auth = that.MakeCodeRouter[hotimeName].TableConfig.GetMap(str).GetSlice("auth")
|
||||
} else {
|
||||
auth = Slice{"show"}
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
if strings.Contains(myAuth.GetMap(str).GetString("auth"), `"show"`) &&
|
||||
strings.Contains(v1.GetString("auth"), `"show"`) {
|
||||
auth = append(auth, "show")
|
||||
|
||||
}
|
||||
if strings.Contains(myAuth.GetMap(str).GetString("auth"), `"download"`) &&
|
||||
strings.Contains(v1.GetString("auth"), `"download"`) {
|
||||
auth = append(auth, "download")
|
||||
|
||||
}
|
||||
if strings.Contains(myAuth.GetMap(str).GetString("auth"), `"add"`) &&
|
||||
strings.Contains(v1.GetString("auth"), `"add"`) {
|
||||
auth = append(auth, "add")
|
||||
//continue
|
||||
}
|
||||
if strings.Contains(myAuth.GetMap(str).GetString("auth"), `"edit"`) &&
|
||||
strings.Contains(v1.GetString("auth"), `"edit"`) {
|
||||
auth = append(auth, "edit")
|
||||
|
||||
}
|
||||
if strings.Contains(myAuth.GetMap(str).GetString("auth"), `"delete"`) &&
|
||||
strings.Contains(v1.GetString("auth"), `"delete"`) {
|
||||
auth = append(auth, "delete")
|
||||
|
||||
}
|
||||
if strings.Contains(myAuth.GetMap(str).GetString("auth"), `"info"`) &&
|
||||
strings.Contains(v1.GetString("auth"), `"info"`) {
|
||||
auth = append(auth, "info")
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
toDB[str] = auth
|
||||
v1Menus := v1.GetSlice("menus")
|
||||
for k2, _ := range v1Menus {
|
||||
v2 := v1Menus.GetMap(k2)
|
||||
|
||||
if myAuth.GetMap(v2.GetString("name")) == nil && myAuth.GetMap(v2.GetString("table")) == nil {
|
||||
toDbli := Slice{}
|
||||
for k2, _ := range v1 {
|
||||
v2 := v1.GetString(k2)
|
||||
if !strings.Contains(linkAuth.GetString(k1), `"`+v2+`"`) {
|
||||
continue
|
||||
}
|
||||
|
||||
auth := Slice{}
|
||||
|
||||
str := v2.GetString("name")
|
||||
|
||||
if v2.GetString("table") != "" {
|
||||
|
||||
str = v2.GetString("table")
|
||||
}
|
||||
|
||||
if v2.GetString("auth") == "" {
|
||||
if myAuth.GetMap(str).GetString("table") != "" {
|
||||
auth = that.MakeCodeRouter[hotimeName].TableConfig.GetMap(str).GetSlice("auth")
|
||||
} else {
|
||||
auth = Slice{"show"}
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
if strings.Contains(myAuth.GetMap(str).GetString("auth"), `"show"`) &&
|
||||
strings.Contains(v2.GetString("auth"), `"show"`) {
|
||||
auth = append(auth, "show")
|
||||
|
||||
}
|
||||
if strings.Contains(myAuth.GetMap(str).GetString("auth"), `"download"`) &&
|
||||
strings.Contains(v1.GetString("auth"), `"download"`) {
|
||||
auth = append(auth, "download")
|
||||
|
||||
}
|
||||
if strings.Contains(myAuth.GetMap(str).GetString("auth"), `"add"`) &&
|
||||
strings.Contains(v2.GetString("auth"), `"add"`) {
|
||||
auth = append(auth, "add")
|
||||
//continue
|
||||
}
|
||||
if strings.Contains(myAuth.GetMap(str).GetString("auth"), `"edit"`) &&
|
||||
strings.Contains(v2.GetString("auth"), `"edit"`) {
|
||||
auth = append(auth, "edit")
|
||||
|
||||
}
|
||||
if strings.Contains(myAuth.GetMap(str).GetString("auth"), `"delete"`) &&
|
||||
strings.Contains(v2.GetString("auth"), `"delete"`) {
|
||||
auth = append(auth, "delete")
|
||||
|
||||
}
|
||||
if strings.Contains(myAuth.GetMap(str).GetString("auth"), `"info"`) &&
|
||||
strings.Contains(v2.GetString("auth"), `"info"`) {
|
||||
auth = append(auth, "info")
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
toDB[str] = auth
|
||||
|
||||
toDbli = append(toDbli, v2)
|
||||
}
|
||||
|
||||
toDB[k1] = toDbli
|
||||
}
|
||||
|
||||
inData["auth"] = toDB.ToJsonString()
|
||||
break
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//索引管理,便于检索以及权限
|
||||
if inData.GetString("parent_ids") != "" {
|
||||
if inData.Get("parent_id") != nil {
|
||||
Index := that.Db.Get(tableName, "`index`", Map{"id": that.RouterString[2]})
|
||||
parentIndex := that.Db.Get(tableName, "`index`", Map{"id": inData.Get("parent_id")})
|
||||
inData["parent_ids"] = parentIndex.GetString("parent_ids") + that.RouterString[2] + ","
|
||||
|
||||
childNodes := that.Db.Select(tableName, "id,`index``", Map{"index[~]": "," + that.RouterString[2] + ","})
|
||||
|
||||
if inData.Get("parent_id") != nil {
|
||||
//1
|
||||
//12 62
|
||||
//123 623
|
||||
Index := that.Db.Get(tableName, "parent_id,`parent_ids`", Map{"id": that.RouterString[2]})
|
||||
if inData.GetCeilInt64("parent_id") != Index.GetCeilInt64("parent_id") {
|
||||
parentIndex := that.Db.Get(tableName, "`parent_ids`", Map{"id": inData.Get("parent_id")})
|
||||
if strings.Contains(parentIndex.GetString("parent_ids"), ","+that.RouterString[2]+",") {
|
||||
that.Display(4, "不能将子级设置为父级")
|
||||
return
|
||||
}
|
||||
parent_ids := parentIndex.GetString("parent_ids") + that.RouterString[2] + ","
|
||||
childNodes := that.Db.Select(tableName, "id,`parent_ids`", Map{"parent_ids[~]": "," + that.RouterString[2] + ","})
|
||||
for _, v := range childNodes {
|
||||
v["parent_ids"] = strings.Replace(v.GetString("parent_ids"), Index.GetString("parent_ids"), inData.GetString("parent_ids"), -1)
|
||||
v["parent_ids"] = strings.Replace(v.GetString("parent_ids"), Index.GetString("parent_ids"), parent_ids, -1)
|
||||
that.Db.Update(tableName, Map{"parent_ids": v["parent_ids"]}, Map{"id": v.GetCeilInt("id")})
|
||||
}
|
||||
} else {
|
||||
delete(inData, "parent_ids")
|
||||
}
|
||||
|
||||
}
|
||||
@@ -652,21 +384,18 @@ var TptProject = Proj{
|
||||
return
|
||||
}
|
||||
|
||||
//索引管理,便于检索以及权限
|
||||
that.Display(0, re)
|
||||
},
|
||||
"remove": func(that *Context) {
|
||||
tableName := that.RouterString[1]
|
||||
that.Log = Map{"table": tableName, "type": 3, "table_id": that.RouterString[2]}
|
||||
hotimeName := that.RouterString[0]
|
||||
inData := that.MakeCodeRouter[hotimeName].Delete(tableName, that.Req)
|
||||
if inData == nil {
|
||||
that.Display(3, "请求参数不足")
|
||||
return
|
||||
}
|
||||
|
||||
re := int64(0)
|
||||
//索引管理,便于检索以及权限
|
||||
if inData.Get("parent_id") != nil && inData.GetSlice("parent_ids") != nil {
|
||||
re = that.Db.Delete(tableName, Map{"index[~]": "," + that.RouterString[2] + ","})
|
||||
//有索引则删除对应的参数
|
||||
if that.MakeCodeRouter[hotimeName].TableColumns[tableName]["parent_id"] != nil {
|
||||
re = that.Db.Delete(tableName, Map{"parent_ids[~]": "," + that.RouterString[2] + ","})
|
||||
} else {
|
||||
re = that.Db.Delete(tableName, Map{"id": that.RouterString[2]})
|
||||
}
|
||||
@@ -931,47 +660,7 @@ var TptProject = Proj{
|
||||
}
|
||||
re[link] = that.Db.Get(column.GetString("link"), seStr, Map{"id": v})
|
||||
}
|
||||
|
||||
//权限设置
|
||||
if column["type"] == "auth" {
|
||||
|
||||
btes, err := ioutil.ReadFile(fileConfig.GetString("config"))
|
||||
|
||||
if err != nil {
|
||||
that.Display(4, "找不到权限配置文件")
|
||||
return
|
||||
}
|
||||
|
||||
conf := ObjToMap(string(btes))
|
||||
menus := conf.GetSlice("menus")
|
||||
|
||||
userAuth := re.GetMap("auth")
|
||||
|
||||
for k1, _ := range menus {
|
||||
v1 := menus.GetMap(k1)
|
||||
if userAuth[v1.GetString("name")] != nil {
|
||||
v1["auth"] = userAuth[v1.GetString("name")]
|
||||
}
|
||||
if userAuth[v1.GetString("table")] != nil {
|
||||
v1["auth"] = userAuth[v1.GetString("table")]
|
||||
}
|
||||
v1menus := v1.GetSlice("menus")
|
||||
for k2, _ := range v1menus {
|
||||
v2 := v1menus.GetMap(k2)
|
||||
if userAuth[v2.GetString("name")] != nil {
|
||||
v2["auth"] = userAuth[v2.GetString("name")]
|
||||
}
|
||||
if userAuth[v2.GetString("table")] != nil {
|
||||
v2["auth"] = userAuth[v2.GetString("table")]
|
||||
}
|
||||
}
|
||||
}
|
||||
re["auth"] = menus.ToJsonString()
|
||||
//that.Display(0,menus)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//如果有table字段则代为link
|
||||
if re["table"] != nil && re["table_id"] != nil {
|
||||
|
||||
@@ -1008,11 +697,15 @@ var TptProject = Proj{
|
||||
where := Map{"name": name}
|
||||
if that.MakeCodeRouter[hotimeName].TableColumns[fileConfig.GetString("table")]["phone"] != nil {
|
||||
where["phone"] = name
|
||||
where = Map{"AND": Map{"OR": where, "password": Md5(password)}}
|
||||
where = Map{"OR": where, "password": Md5(password)}
|
||||
} else {
|
||||
where["password"] = Md5(password)
|
||||
}
|
||||
|
||||
if len(where) > 1 {
|
||||
where = Map{"AND": where}
|
||||
}
|
||||
|
||||
user := that.Db.Get(fileConfig.GetString("table"), "*", where)
|
||||
|
||||
if user == nil {
|
||||
@@ -1073,58 +766,118 @@ var TptProject = Proj{
|
||||
|
||||
linkAuthMap := that.Db.Get(v.GetString("link"), "auth", Map{"id": user.GetCeilInt(v.GetString("name"))})
|
||||
linkAuth := linkAuthMap.GetMap("auth")
|
||||
//conf := ObjToMap(string(btes))
|
||||
//menus := conf.GetSlice("menus")
|
||||
if linkAuth == nil {
|
||||
linkAuth = Map{}
|
||||
}
|
||||
|
||||
for k1, _ := range menus {
|
||||
v1 := menus.GetMap(k1)
|
||||
if linkAuth[v1.GetString("name")] != nil {
|
||||
v1["auth"] = linkAuth[v1.GetString("name")]
|
||||
name := v1.GetString("name")
|
||||
if name == "" {
|
||||
name = v1.GetString("table")
|
||||
}
|
||||
if linkAuth[v1.GetString("table")] != nil {
|
||||
v1["auth"] = linkAuth[v1.GetString("table")]
|
||||
if v1["auth"] != nil {
|
||||
|
||||
if linkAuth[name] == nil {
|
||||
linkAuth[name] = v1["auth"]
|
||||
} else {
|
||||
newAuth := Slice{}
|
||||
for k2, _ := range linkAuth.GetSlice(name) {
|
||||
v2 := linkAuth.GetSlice(name).GetString(k2)
|
||||
if strings.Contains(v1.GetString("auth"), v2) {
|
||||
newAuth = append(newAuth, v2)
|
||||
}
|
||||
}
|
||||
linkAuth[name] = newAuth
|
||||
}
|
||||
}
|
||||
|
||||
menusChild := v1.GetSlice("menus")
|
||||
for k2, _ := range menusChild {
|
||||
v2 := menusChild.GetMap(k2)
|
||||
name := v2.GetString("name")
|
||||
if name == "" {
|
||||
name = v2.GetString("table")
|
||||
}
|
||||
if v2["auth"] != nil {
|
||||
|
||||
if linkAuth[name] == nil {
|
||||
linkAuth[name] = v2["auth"]
|
||||
|
||||
} else {
|
||||
|
||||
newAuth := Slice{}
|
||||
for k3, _ := range linkAuth.GetSlice(name) {
|
||||
v3 := linkAuth.GetSlice(name).GetString(k3)
|
||||
if strings.Contains(v2.GetString("auth"), v3) {
|
||||
newAuth = append(newAuth, v3)
|
||||
}
|
||||
}
|
||||
linkAuth[name] = newAuth
|
||||
continue
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for k1, _ := range menus {
|
||||
v1 := menus.GetMap(k1)
|
||||
//保证个人权限可用
|
||||
if fileConfig.GetString("table") == v1.GetString("table") {
|
||||
v1["auth"] = Slice{"info", "edit"}
|
||||
}
|
||||
name := v1.GetString("name")
|
||||
if name == "" {
|
||||
name = v1.GetString("table")
|
||||
}
|
||||
|
||||
if linkAuth[name] != nil {
|
||||
v1["auth"] = linkAuth[name]
|
||||
}
|
||||
|
||||
v1menus := v1.GetSlice("menus")
|
||||
for k2, _ := range v1menus {
|
||||
v2 := v1menus.GetMap(k2)
|
||||
if linkAuth[v2.GetString("name")] != nil {
|
||||
v2["auth"] = linkAuth[v2.GetString("name")]
|
||||
//保证个人权限可用
|
||||
if fileConfig.GetString("table") == v2.GetString("table") {
|
||||
v2["auth"] = Slice{"info", "edit"}
|
||||
|
||||
}
|
||||
if linkAuth[v2.GetString("table")] != nil {
|
||||
v2["auth"] = linkAuth[v2.GetString("table")]
|
||||
name := v2.GetString("name")
|
||||
if name == "" {
|
||||
name = v2.GetString("table")
|
||||
}
|
||||
if linkAuth[name] != nil {
|
||||
v2["auth"] = linkAuth[name]
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
userAuth := user.GetMap("auth")
|
||||
for k1, _ := range menus {
|
||||
v1 := menus.GetMap(k1)
|
||||
if userAuth[v1.GetString("table")] != nil {
|
||||
v1["auth"] = userAuth[v1.GetString("table")]
|
||||
}
|
||||
v1menus := v1.GetSlice("menus")
|
||||
for k2, _ := range v1menus {
|
||||
v2 := v1menus.GetMap(k2)
|
||||
if userAuth[v2.GetString("table")] != nil {
|
||||
v2["auth"] = userAuth[v2.GetString("table")]
|
||||
}
|
||||
}
|
||||
}
|
||||
//不可读写数据
|
||||
config := DeepCopyMap(that.MakeCodeRouter[hotimeName].Config).(Map)
|
||||
|
||||
config["menus"] = menus
|
||||
newTables := Map{}
|
||||
newTables[fileConfig.GetString("table")] = config.GetMap("tables").GetMap(fileConfig.GetString("table"))
|
||||
for k1, _ := range menus {
|
||||
v1 := menus.GetMap(k1)
|
||||
if config.GetMap("tables").GetMap(v1.GetString("table")) != nil {
|
||||
if config.GetMap("tables").GetMap(v1.GetString("table")) != nil && len(v1.GetSlice("auth")) != 0 {
|
||||
config.GetMap("tables").GetMap(v1.GetString("table"))["auth"] = Slice{}
|
||||
newTables[v1.GetString("name")] = config.GetMap("tables").GetMap(v1.GetString("table"))
|
||||
}
|
||||
v1menus := v1.GetSlice("menus")
|
||||
for k2, _ := range v1.GetSlice("menus") {
|
||||
v2 := v1menus.GetMap(k2)
|
||||
if config.GetMap("tables").GetMap(v2.GetString("table")) != nil {
|
||||
if config.GetMap("tables").GetMap(v2.GetString("table")) != nil && len(v2.GetSlice("auth")) != 0 {
|
||||
|
||||
//有自定义配置文件
|
||||
if conf.GetMap("tables") != nil && conf.GetMap("tables").GetMap(v2.GetString("table")) != nil {
|
||||
|
||||
@@ -1143,7 +896,7 @@ var TptProject = Proj{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
config.GetMap("tables").GetMap(v2.GetString("table"))["auth"] = Slice{}
|
||||
newTables[v2.GetString("table")] = config.GetMap("tables").GetMap(v2.GetString("table"))
|
||||
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ var Config = Map{
|
||||
"name": "HoTimeDashBoard",
|
||||
//"id": "2f92h3herh23rh2y8",
|
||||
"label": "HoTime管理平台",
|
||||
"stop": Slice{"role", "org"}, //不更新的,同时不允许修改用户自身对应的表数据
|
||||
"labelConfig": Map{
|
||||
"show": "开启",
|
||||
"add": "添加",
|
||||
|
||||
+305
-260
@@ -43,20 +43,6 @@ func (that *MakeCode) Db2JSON(db *db.HoTimeDB, config Map) {
|
||||
that.Config = DeepCopyMap(Config).(Map)
|
||||
|
||||
that.Config["name"] = config.GetString("table")
|
||||
//if err == nil {
|
||||
// cmap := Map{}
|
||||
// //文件是否损坏
|
||||
// cmap.JsonToMap(string(btes), &that.Error)
|
||||
// for k, v := range cmap {
|
||||
// that.Config[k] = v //程序配置
|
||||
// //Config[k] = v //系统配置
|
||||
// }
|
||||
// hasConfigFile = true
|
||||
//} else {
|
||||
//
|
||||
// that.Error.SetError(errors.New("config配置文件不存在,或者配置出错,使用缺省默认配置"))
|
||||
//
|
||||
//}
|
||||
//加载规则文件
|
||||
btesRule, errRule := ioutil.ReadFile(config.GetString("rule"))
|
||||
that.RuleConfig = []Map{}
|
||||
@@ -84,38 +70,6 @@ func (that *MakeCode) Db2JSON(db *db.HoTimeDB, config Map) {
|
||||
}
|
||||
|
||||
that.IndexMenus = Map{}
|
||||
//menusConfig := that.Config.GetSlice("menus")
|
||||
////将配置写入到内存中仅作为判断用
|
||||
//if menusConfig != nil {
|
||||
// for kmenu, _ := range menusConfig {
|
||||
// menu := menusConfig.GetMap(kmenu)
|
||||
// if menu != nil {
|
||||
// mname := menu.GetString("table")
|
||||
// if mname == "" { //如果为空则不是表格
|
||||
// mname = menu.GetString("name")
|
||||
// }
|
||||
// that.IndexMenus[mname] = menu
|
||||
// childMenus := menu.GetSlice("menus")
|
||||
// if childMenus != nil {
|
||||
// for ckmenu, _ := range childMenus {
|
||||
// cmenu := childMenus.GetMap(ckmenu)
|
||||
// if cmenu != nil {
|
||||
// cname := cmenu.GetString("table")
|
||||
// if cmenu.GetString("table") == "" {
|
||||
// continue
|
||||
// }
|
||||
// that.IndexMenus[mname+"/"+cname] = cmenu
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//}
|
||||
|
||||
that.TableConfig = that.Config.GetMap("tables")
|
||||
if that.TableConfig == nil {
|
||||
that.TableConfig = Map{}
|
||||
@@ -179,7 +133,8 @@ func (that *MakeCode) Db2JSON(db *db.HoTimeDB, config Map) {
|
||||
"auth": []string{"show", "add", "delete", "edit", "info", "download"},
|
||||
"columns": []Map{},
|
||||
"search": []Map{
|
||||
|
||||
{"type": "search", "name": "keywordtable", "label": "筛选", "options": Slice{Map{"name": "无", "value": nil}}, "value": nil},
|
||||
{"type": "search", "name": "daterangetable", "label": "筛选", "options": Slice{Map{"name": "无", "value": nil}}, "value": nil},
|
||||
{"type": "search", "name": "keyword", "label": "请输入关键词", "value": nil},
|
||||
{"type": "search", "name": "daterange", "label": "时间段", "value": nil},
|
||||
{"type": "search", "name": "sort", "label": "排序", "value": nil},
|
||||
@@ -321,13 +276,6 @@ func (that *MakeCode) Db2JSON(db *db.HoTimeDB, config Map) {
|
||||
//}
|
||||
|
||||
}
|
||||
//else {
|
||||
//
|
||||
// //if !(coloum.GetString("label") != "备注" && info.GetString("label") == "备注") {
|
||||
// // coloum["label"] = info.GetString("label")
|
||||
// //}
|
||||
// //coloum["type"] = info.GetString("type")
|
||||
//}
|
||||
|
||||
//暂时不关闭参数,保证表数据完全读取到
|
||||
that.TableColumns[v.GetString("name")][info.GetString("name")] = coloum
|
||||
@@ -371,21 +319,6 @@ func (that *MakeCode) Db2JSON(db *db.HoTimeDB, config Map) {
|
||||
//数据生成完后进一步解析
|
||||
for fk, fv := range that.TableColumns {
|
||||
|
||||
//判断是否将表写入menu中
|
||||
//isMenusGet := false //判断是否被目录收录
|
||||
//for indexKey, _ := range that.IndexMenus {
|
||||
// indexCode := strings.Index(indexKey, fk)
|
||||
// if indexCode == 0 || indexCode == 4 {
|
||||
// isMenusGet = false
|
||||
// continue
|
||||
// }
|
||||
// //如果相等或者表名在目录中已经设置(主要前一位是/并且他是最后一个字符串)
|
||||
// if indexKey == fk || (indexCode != -1 && indexKey[indexCode-1] == '/' && indexKey[indexCode:] == fk) {
|
||||
// isMenusGet = true
|
||||
// break
|
||||
// }
|
||||
//}
|
||||
|
||||
//目录没有收录
|
||||
//if !isMenusGet {
|
||||
//if !hasConfigFile {
|
||||
@@ -410,14 +343,14 @@ func (that *MakeCode) Db2JSON(db *db.HoTimeDB, config Map) {
|
||||
|
||||
prefixName = DefaultMenuParentName + ":" + prefixName
|
||||
|
||||
menuIns := Map{"label": that.TableConfig.GetMap(fk).GetString("label"), "table": fk}
|
||||
menuIns := Map{"label": that.TableConfig.GetMap(fk).GetString("label"), "table": fk, "auth": that.TableConfig.GetMap(fk).GetSlice("auth")}
|
||||
//多耗费一点内存
|
||||
mMenu := Map{"menus": Slice{menuIns}, "label": that.TableConfig.GetMap(fk).GetString("label"), "name": prefixName, "icon": "el-icon-setting"}
|
||||
mMenu := Map{"menus": Slice{menuIns}, "auth": Slice{"show"}, "label": that.TableConfig.GetMap(fk).GetString("label"), "name": prefixName, "icon": "Setting"}
|
||||
//表名有前缀
|
||||
if !isNewPrefix {
|
||||
//是否已有对应前缀,已经有对应的menu只需要push进去即可
|
||||
prefixName = DefaultMenuParentName
|
||||
mMenu = Map{"menus": Slice{menuIns}, "label": "系统管理", "name": prefixName, "icon": "el-icon-setting"}
|
||||
mMenu = Map{"menus": Slice{menuIns}, "auth": Slice{"show"}, "label": "系统管理", "name": prefixName, "icon": "Setting"}
|
||||
}
|
||||
//没有新前缀
|
||||
if that.IndexMenus[prefixName] != nil {
|
||||
@@ -438,103 +371,129 @@ func (that *MakeCode) Db2JSON(db *db.HoTimeDB, config Map) {
|
||||
that.IndexMenus[prefixName+"/"+fk] = menuIns
|
||||
}
|
||||
//}
|
||||
|
||||
search := that.TableConfig.GetMap(fk).GetSlice("search")
|
||||
for k, v := range fv {
|
||||
|
||||
//虚招后缀是_id结尾的表字段 假设org_id
|
||||
if !(len(k) <= 3 || strings.LastIndex(k, "_id") != len(k)-3) {
|
||||
//普通表匹配 org_id匹配为org
|
||||
oldTableName := k[:len(k)-3]
|
||||
//上级ID匹配
|
||||
if oldTableName == "parent" {
|
||||
oldTableName = fk
|
||||
}
|
||||
//如果本身匹配则不再继续精简匹配
|
||||
if that.TableConfig[oldTableName] == nil {
|
||||
|
||||
//如果依然找不到则查询system_org是否存在
|
||||
if that.TableConfig[DefaultMenuParentName+"_"+oldTableName] != nil {
|
||||
oldTableName = DefaultMenuParentName + "_" + oldTableName
|
||||
}
|
||||
|
||||
//字段有动词前缀,自动进行解析
|
||||
prefixColumn := strings.Index(oldTableName, "_")
|
||||
|
||||
//sys_org_id oldTableName即为sys此处判断为org表存在
|
||||
|
||||
if prefixColumn > -1 && that.TableConfig[oldTableName[prefixColumn+1:]] != nil {
|
||||
oldTableName = oldTableName[prefixColumn+1:]
|
||||
}
|
||||
if prefixColumn >= len(oldTableName) {
|
||||
prefixColumn = -1
|
||||
}
|
||||
//如果依然找不到则查询system_org是否存在
|
||||
if prefixColumn > -1 && that.TableConfig[DefaultMenuParentName+"_"+oldTableName[prefixColumn+1:]] != nil {
|
||||
oldTableName = DefaultMenuParentName + "_" + oldTableName[prefixColumn+1:]
|
||||
}
|
||||
}
|
||||
|
||||
//普通方式查询不到,则转换为大型项目模块划分,暂时只支持一级模块划分,
|
||||
//比如表sys_user 字段org_id,查询不到sys_org表则查询org表,org表查询不到则查询默认前缀system_org表
|
||||
//都查询不到则找不到,
|
||||
prefix := strings.Index(fk, "_")
|
||||
tableName := oldTableName
|
||||
if prefix > 0 {
|
||||
//表模块前缀sys_user sys即为前缀 sys_org
|
||||
tableName = fk[:prefix+1] + oldTableName
|
||||
if that.TableConfig[tableName] == nil || that.TableConfig[oldTableName] != nil {
|
||||
//不存在则改为org
|
||||
tableName = oldTableName
|
||||
}
|
||||
//表前缀+去除字段前缀
|
||||
prefixColumn := strings.Index(oldTableName, "_")
|
||||
if prefixColumn > -1 {
|
||||
tableName = fk[:prefix+1] + oldTableName[prefixColumn+1:]
|
||||
if that.TableConfig[tableName] == nil {
|
||||
tableName = oldTableName
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//如果数据匹配则写入到配置中
|
||||
if that.TableConfig[tableName] != nil {
|
||||
v["link"] = tableName
|
||||
//一般查询name字段或者label字段,如果没有name字段则默认第二个地段
|
||||
if that.TableColumns[tableName]["name"] != nil {
|
||||
v["value"] = "name"
|
||||
continue
|
||||
}
|
||||
if that.TableColumns[tableName]["label"] != nil {
|
||||
v["value"] = "label"
|
||||
continue
|
||||
}
|
||||
tempC := that.TableConfig.GetMap(tableName).GetSlice("columns")
|
||||
isGet := true
|
||||
for k2, _ := range tempC {
|
||||
if strings.Contains(tempC.GetMap(k2).GetString("name"), "name") || strings.Contains(tempC.GetMap(k2).GetString("name"), "title") {
|
||||
v["value"] = tempC.GetMap(k2).GetString("name")
|
||||
isGet = false
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if isGet && len(that.TableConfig.GetMap(tableName).GetSlice("columns")) > 2 {
|
||||
v["value"] = that.TableConfig.GetMap(tableName).GetSlice("columns").GetMap(1).GetString("name")
|
||||
continue
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//搜索服务
|
||||
if that.SearchColumns[fk][v.GetString("name")] == nil &&
|
||||
v.GetString("type") == "select" {
|
||||
search := that.TableConfig.GetMap(fk).GetSlice("search")
|
||||
//search := that.TableConfig.GetMap(fk).GetSlice("search")
|
||||
sv := DeepCopyMap(v).(Map)
|
||||
sv["value"] = nil
|
||||
sv["options"] = append(sv.GetSlice("options"), Map{"name": "全部", "value": nil})
|
||||
that.TableConfig.GetMap(fk)["search"] = append(search, sv)
|
||||
search = append(search, sv)
|
||||
that.TableConfig.GetMap(fk)["search"] = search
|
||||
that.SearchColumns[fk][k] = sv
|
||||
}
|
||||
|
||||
//虚招后缀是_id结尾的表字段 假设org_id
|
||||
if len(k) <= 3 || strings.LastIndex(k, "_id") != len(k)-3 {
|
||||
continue
|
||||
//搜索关键字
|
||||
if strings.Contains(v.GetString("type"), "text") || v.GetString("name") == "id" {
|
||||
keyWordSearchData := search.GetMap(0)
|
||||
|
||||
keyWordSearchData["options"] = append(keyWordSearchData.GetSlice("options"), Map{"name": v.GetString("label"), "value": v.GetString("name")})
|
||||
search[0] = keyWordSearchData
|
||||
}
|
||||
//普通表匹配 org_id匹配为org
|
||||
oldTableName := k[:len(k)-3]
|
||||
//上级ID匹配
|
||||
if oldTableName == "parent" {
|
||||
oldTableName = fk
|
||||
}
|
||||
//如果本身匹配则不再继续精简匹配
|
||||
if that.TableConfig[oldTableName] == nil {
|
||||
if v.GetString("link") != "" &&
|
||||
v.GetString("name") != "parent_id" {
|
||||
|
||||
//如果依然找不到则查询system_org是否存在
|
||||
if that.TableConfig[DefaultMenuParentName+"_"+oldTableName] != nil {
|
||||
oldTableName = DefaultMenuParentName + "_" + oldTableName
|
||||
}
|
||||
|
||||
//字段有动词前缀,自动进行解析
|
||||
prefixColumn := strings.Index(oldTableName, "_")
|
||||
|
||||
//sys_org_id oldTableName即为sys此处判断为org表存在
|
||||
|
||||
if prefixColumn > -1 && that.TableConfig[oldTableName[prefixColumn+1:]] != nil {
|
||||
oldTableName = oldTableName[prefixColumn+1:]
|
||||
}
|
||||
if prefixColumn >= len(oldTableName) {
|
||||
prefixColumn = -1
|
||||
}
|
||||
//如果依然找不到则查询system_org是否存在
|
||||
if prefixColumn > -1 && that.TableConfig[DefaultMenuParentName+"_"+oldTableName[prefixColumn+1:]] != nil {
|
||||
oldTableName = DefaultMenuParentName + "_" + oldTableName[prefixColumn+1:]
|
||||
}
|
||||
keyWordSearchData := search.GetMap(0)
|
||||
name := strings.Replace(that.TableConfig.GetMap(v.GetString("link")).GetString("label"), "管理", "", -1)
|
||||
keyWordSearchData["options"] = append(keyWordSearchData.GetSlice("options"), Map{"name": name, "value": v.GetString("name")})
|
||||
search[0] = keyWordSearchData
|
||||
}
|
||||
|
||||
//普通方式查询不到,则转换为大型项目模块划分,暂时只支持一级模块划分,
|
||||
//比如表sys_user 字段org_id,查询不到sys_org表则查询org表,org表查询不到则查询默认前缀system_org表
|
||||
//都查询不到则找不到,
|
||||
prefix := strings.Index(fk, "_")
|
||||
tableName := oldTableName
|
||||
if prefix > 0 {
|
||||
//表模块前缀sys_user sys即为前缀 sys_org
|
||||
tableName = fk[:prefix+1] + oldTableName
|
||||
if that.TableConfig[tableName] == nil || that.TableConfig[oldTableName] != nil {
|
||||
//不存在则改为org
|
||||
tableName = oldTableName
|
||||
}
|
||||
//表前缀+去除字段前缀
|
||||
prefixColumn := strings.Index(oldTableName, "_")
|
||||
if prefixColumn > -1 {
|
||||
tableName = fk[:prefix+1] + oldTableName[prefixColumn+1:]
|
||||
if that.TableConfig[tableName] == nil {
|
||||
tableName = oldTableName
|
||||
}
|
||||
}
|
||||
}
|
||||
//搜索时间
|
||||
if strings.Contains(v.GetString("type"), "time") {
|
||||
daterangeData := search.GetMap(1)
|
||||
|
||||
//如果数据匹配则写入到配置中
|
||||
if that.TableConfig[tableName] != nil {
|
||||
v["link"] = tableName
|
||||
//一般查询name字段或者label字段,如果没有name字段则默认第二个地段
|
||||
if that.TableColumns[tableName]["name"] != nil {
|
||||
v["value"] = "name"
|
||||
continue
|
||||
}
|
||||
if that.TableColumns[tableName]["label"] != nil {
|
||||
v["value"] = "label"
|
||||
continue
|
||||
}
|
||||
tempC := that.TableConfig.GetMap(tableName).GetSlice("columns")
|
||||
isGet := true
|
||||
for k2, _ := range tempC {
|
||||
if strings.Contains(tempC.GetMap(k2).GetString("name"), "name") || strings.Contains(tempC.GetMap(k2).GetString("name"), "title") {
|
||||
v["value"] = tempC.GetMap(k2).GetString("name")
|
||||
isGet = false
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if isGet && len(that.TableConfig.GetMap(tableName).GetSlice("columns")) > 2 {
|
||||
v["value"] = that.TableConfig.GetMap(tableName).GetSlice("columns").GetMap(1).GetString("name")
|
||||
continue
|
||||
}
|
||||
daterangeData["options"] = append(daterangeData.GetSlice("options"), Map{"name": v.GetString("label"), "value": v.GetString("name")})
|
||||
search[1] = daterangeData
|
||||
|
||||
}
|
||||
|
||||
@@ -550,9 +509,12 @@ func (that *MakeCode) Db2JSON(db *db.HoTimeDB, config Map) {
|
||||
search := that.TableConfig.GetMap(fk).GetSlice("search")
|
||||
sv := Map{"type": "tree", "label": v["label"], "name": v["name"], "value": v["value"], "link": v["link"]}
|
||||
that.TableConfig.GetMap(fk)["search"] = append(search, sv)
|
||||
|
||||
that.SearchColumns[fk][k] = sv
|
||||
}
|
||||
|
||||
if fk == that.FileConfig.GetString("table") && v["link"] != nil && that.TableColumns[v.GetString("link")]["parent_id"] != nil {
|
||||
that.Config["stop"] = append(that.Config.GetSlice("stop"), v.GetString("link"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -763,15 +725,18 @@ func (that *MakeCode) Edit(table string, req *http.Request) Map {
|
||||
for _, v := range that.TableColumns[table] {
|
||||
//不可使用,未在前端展示,但在内存中保持有
|
||||
if v.GetBool("notUse") {
|
||||
if v.GetString("type") == "index" && that.TableColumns[table]["parent_id"] != nil {
|
||||
data[v.GetString("name")] = ","
|
||||
}
|
||||
//if v.GetString("type") == "index" && that.TableColumns[table]["parent_id"] != nil {
|
||||
// data[v.GetString("name")] = ","
|
||||
//}
|
||||
continue
|
||||
}
|
||||
|
||||
if v.Get("edit") == nil || v.GetBool("edit") {
|
||||
if len(req.Form[v.GetString("name")]) == 0 {
|
||||
continue
|
||||
}
|
||||
reqValue := req.FormValue(v.GetString("name"))
|
||||
if reqValue == "" || reqValue == "null" {
|
||||
if reqValue == "null" {
|
||||
continue
|
||||
}
|
||||
if v.GetString("type") == "password" {
|
||||
@@ -799,16 +764,16 @@ func (that *MakeCode) Edit(table string, req *http.Request) Map {
|
||||
}
|
||||
func (that *MakeCode) Delete(table string, req *http.Request) Map {
|
||||
data := Map{}
|
||||
for _, v := range that.TableColumns[table] {
|
||||
//不可使用,未在前端展示,但在内存中保持有
|
||||
if v.GetBool("notUse") {
|
||||
if v.GetString("type") == "index" && that.TableColumns[table]["parent_id"] != nil {
|
||||
data[v.GetString("name")] = ","
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
}
|
||||
//for _, v := range that.TableColumns[table] {
|
||||
// //不可使用,未在前端展示,但在内存中保持有
|
||||
// if v.GetBool("notUse") {
|
||||
// //if v.GetString("type") == "index" && that.TableColumns[table]["parent_id"] != nil {
|
||||
// // data[v.GetString("name")] = ","
|
||||
// //}
|
||||
// continue
|
||||
// }
|
||||
//
|
||||
//}
|
||||
return data
|
||||
}
|
||||
|
||||
@@ -823,6 +788,8 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
|
||||
hasUser := false
|
||||
|
||||
keywordStr := req.FormValue("keyword")
|
||||
keywordTableStr := req.FormValue("keywordtable")
|
||||
daterangeTableStr := req.FormValue("daterangetable")
|
||||
|
||||
testQu := []string{}
|
||||
testQuData := that.TableColumns[table]
|
||||
@@ -831,7 +798,6 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
|
||||
testQu = append(testQu, key)
|
||||
}
|
||||
sort.Strings(testQu)
|
||||
|
||||
for _, k := range testQu {
|
||||
v := testQuData[k]
|
||||
//不可使用,未在前端展示,但在内存中保持有
|
||||
@@ -839,6 +805,7 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
if v["list"] != false {
|
||||
|
||||
if v.GetString("link") != "" &&
|
||||
@@ -871,9 +838,17 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
reStr += table + "." + v.GetString("name") + ","
|
||||
}
|
||||
|
||||
if v["name"] == "parent_id" && v.GetString("link") != "" {
|
||||
leftJoin["[>]"+v.GetString("link")+" selfParent"] =
|
||||
"selfParent.id=" +
|
||||
v.GetString("link") + "." + v.GetString("name")
|
||||
reStr += "selfParent." + v.GetString("value") + " AS " + v.GetString("link") + "_" + v.GetString("name") + "_" + v.GetString("value") + ","
|
||||
}
|
||||
|
||||
//准备加入索引权限
|
||||
if v.GetString("link") != "" &&
|
||||
userData != nil &&
|
||||
@@ -917,29 +892,44 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
|
||||
|
||||
}
|
||||
|
||||
if keywordStr != "" {
|
||||
if v.GetString("type") == "text" {
|
||||
keyword[table+"."+v.GetString("name")+"[~]"] = keywordStr
|
||||
}
|
||||
|
||||
}
|
||||
if v.GetString("name") == "id" {
|
||||
keyword[table+"."+v.GetString("name")] = keywordStr
|
||||
}
|
||||
if v.GetString("link") != "" &&
|
||||
v.GetString("name") != "parent_id" {
|
||||
childs := db.Select(v.GetString("link"), "id", Map{v.GetString("value") + "[~]": keywordStr})
|
||||
childIds := Slice{}
|
||||
for _, cv := range childs {
|
||||
childIds = append(childIds, cv.GetString("id"))
|
||||
}
|
||||
if len(childIds) != 0 {
|
||||
keyword[v.GetString("link")+".id"] = childIds
|
||||
}
|
||||
|
||||
}
|
||||
if strings.Contains(v.GetString("type"), "text") {
|
||||
reqValue := req.FormValue(v.GetString("name"))
|
||||
if reqValue != "" {
|
||||
data[table+"."+v.GetString("name")+"[~]"] = reqValue
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if v.GetString("type") == "unixtime" {
|
||||
|
||||
if len(req.Form[v.GetString("name")]) == 1 {
|
||||
daterange[table+"."+v.GetString("name")+"[>]"] = req.FormValue("daterange")
|
||||
} else if len(req.Form[v.GetString("name")]) == 2 {
|
||||
daterange[table+"."+v.GetString("name")+"[<>]"] = ObjToSlice(req.Form["daterange"])
|
||||
}
|
||||
|
||||
//fmt.Println(req.Form["daterange"])
|
||||
|
||||
}
|
||||
|
||||
if v.GetString("type") == "time" {
|
||||
//fmt.Println(req.Form["daterange"])
|
||||
|
||||
if len(req.Form[v.GetString("name")]) == 1 {
|
||||
t := time.Unix(ObjToCeilInt64(req.FormValue(v.GetString("name"))), 0).Format("2006-01-02 15:04:05")
|
||||
|
||||
daterange[table+"."+v.GetString("name")+"[>]"] = t
|
||||
|
||||
} else if len(req.Form[v.GetString("name")]) == 2 {
|
||||
t1 := time.Unix(ObjToCeilInt64(req.Form[v.GetString("name")][0]), 0).Format("2006-01-02 15:04:05")
|
||||
t2 := time.Unix(ObjToCeilInt64(req.Form[v.GetString("name")][1]), 0).Format("2006-01-02 15:04:05")
|
||||
daterange[table+"."+v.GetString("name")+"[<>]"] = Slice{t1, t2}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
if len(reStr) != 0 {
|
||||
reStr = reStr[:len(reStr)-1]
|
||||
@@ -949,48 +939,57 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
|
||||
for k, _ := range search {
|
||||
searchItem := search.GetMap(k)
|
||||
searchItemName := searchItem.GetString("name")
|
||||
if data[table+"."+searchItemName] != nil {
|
||||
delete(data, table+"."+searchItemName)
|
||||
}
|
||||
reqValue := req.Form[searchItemName]
|
||||
parent_idsStr := ""
|
||||
parent_ids := that.TableColumns[searchItem.GetString("link")]["parent_ids"]
|
||||
if parent_ids != nil {
|
||||
parent_idsStr = "parent_ids[~]"
|
||||
}
|
||||
index := that.TableColumns[searchItem.GetString("link")]["index"]
|
||||
if index != nil {
|
||||
parent_idsStr = "index[~]"
|
||||
}
|
||||
|
||||
reqValue := req.Form[search.GetMap(k).GetString("name")]
|
||||
|
||||
//reqValue := req.FormValue(search.GetMap(k).GetString("name"))
|
||||
if len(reqValue) == 0 || reqValue[0] == "" {
|
||||
|
||||
if parent_idsStr != "" && userData[searchItem.GetString("name")] != nil {
|
||||
where := Map{parent_idsStr: "," + ObjToStr(userData.GetCeilInt64(searchItem.GetString("name"))) + ","}
|
||||
r := db.Select(searchItem.GetString("link"), "id", where)
|
||||
reqValue = []string{}
|
||||
for _, v := range r {
|
||||
reqValue = append(reqValue, v.GetString("id"))
|
||||
}
|
||||
|
||||
data[table+"."+searchItemName] = reqValue
|
||||
if searchItem.GetString("link") != "" {
|
||||
|
||||
parent_ids := that.TableColumns[searchItem.GetString("link")]["parent_ids"]
|
||||
if parent_ids != nil {
|
||||
parent_idsStr = "parent_ids[~]"
|
||||
}
|
||||
index := that.TableColumns[searchItem.GetString("link")]["index"]
|
||||
if index != nil {
|
||||
parent_idsStr = "index[~]"
|
||||
}
|
||||
|
||||
continue
|
||||
}
|
||||
//reqValue := req.FormValue(search.GetMap(k).GetString("name"))
|
||||
if len(reqValue) == 0 || reqValue[0] == "" {
|
||||
|
||||
if parent_idsStr != "" && userData[searchItem.GetString("name")] != nil {
|
||||
where := Map{parent_idsStr: "," + ObjToStr(userData.GetCeilInt64(searchItem.GetString("name"))) + ","}
|
||||
r := db.Select(searchItem.GetString("link"), "id", where)
|
||||
reqValue = []string{}
|
||||
for _, v := range r {
|
||||
reqValue = append(reqValue, v.GetString("id"))
|
||||
}
|
||||
|
||||
data[table+"."+searchItemName] = reqValue
|
||||
|
||||
}
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
}
|
||||
//columns := that.TableConfig.GetMap(table).GetSlice("columns")
|
||||
if searchItem.GetString("type") == "search" {
|
||||
for _, v := range that.TableColumns[table] {
|
||||
if v["list"] == false {
|
||||
continue
|
||||
}
|
||||
//if v["list"] == false {
|
||||
// continue
|
||||
//}
|
||||
//日期类型
|
||||
if searchItemName == "daterange" {
|
||||
|
||||
if daterangeTableStr != "" && daterangeTableStr != v.GetString("name") {
|
||||
continue
|
||||
}
|
||||
if v.GetString("type") == "unixtime" {
|
||||
//fmt.Println(req.Form["daterange"])
|
||||
if len(req.Form["daterange"]) == 1 {
|
||||
daterange[table+"."+v.GetString("name")+"[<]"] = req.FormValue("daterange")
|
||||
if len(req.Form["daterange"]) == 1 && req.Form["daterange"][0] != "" {
|
||||
daterange[table+"."+v.GetString("name")+"[>]"] = req.FormValue("daterange")
|
||||
} else if len(req.Form["daterange"]) == 2 {
|
||||
|
||||
daterange[table+"."+v.GetString("name")+"[<>]"] = ObjToSlice(req.Form["daterange"])
|
||||
@@ -999,10 +998,10 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
|
||||
if v.GetString("type") == "time" {
|
||||
//fmt.Println(req.Form["daterange"])
|
||||
|
||||
if len(req.Form["daterange"]) == 1 {
|
||||
if len(req.Form["daterange"]) == 1 && req.Form["daterange"][0] != "" {
|
||||
t := time.Unix(ObjToCeilInt64(req.FormValue("daterange")), 0).Format("2006-01-02 15:04:05")
|
||||
|
||||
daterange[table+"."+v.GetString("name")+"[<]"] = t
|
||||
daterange[table+"."+v.GetString("name")+"[>]"] = t
|
||||
|
||||
} else if len(req.Form["daterange"]) == 2 {
|
||||
t1 := time.Unix(ObjToCeilInt64(req.Form["daterange"][0]), 0).Format("2006-01-02 15:04:05")
|
||||
@@ -1012,44 +1011,79 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if searchItemName == "keyword" && keywordStr != "" {
|
||||
|
||||
if keywordTableStr != "" {
|
||||
if keywordTableStr == v.GetString("name") {
|
||||
keyword[table+"."+keywordTableStr+"[~]"] = keywordStr
|
||||
}
|
||||
|
||||
if keywordTableStr == v.GetString("value") {
|
||||
childs := db.Select(v.GetString("link"), "id", Map{v.GetString("value") + "[~]": keywordStr})
|
||||
childIds := Slice{}
|
||||
for _, cv := range childs {
|
||||
childIds = append(childIds, cv.GetString("id"))
|
||||
}
|
||||
if len(childIds) != 0 {
|
||||
keyword[v.GetString("link")+".id"] = childIds
|
||||
}
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
if strings.Contains(v.GetString("type"), "text") {
|
||||
keyword[table+"."+v.GetString("name")+"[~]"] = keywordStr
|
||||
|
||||
}
|
||||
if v.GetString("name") == "id" {
|
||||
keyword[table+"."+v.GetString("name")] = keywordStr
|
||||
}
|
||||
if v.GetString("link") != "" &&
|
||||
v.GetString("name") != "parent_id" {
|
||||
childs := db.Select(v.GetString("link"), "id", Map{v.GetString("value") + "[~]": keywordStr})
|
||||
childIds := Slice{}
|
||||
for _, cv := range childs {
|
||||
childIds = append(childIds, cv.GetString("id"))
|
||||
}
|
||||
if len(childIds) != 0 {
|
||||
keyword[v.GetString("link")+".id"] = childIds
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if searchItem.GetString("name") == "sort" {
|
||||
if len(reqValue) != 0 && searchItem.GetString("name") == "sort" && reqValue[0] != "" {
|
||||
sortMap["ORDER"] = table + "." + reqValue[0]
|
||||
}
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
//树节点模式搜索
|
||||
if searchItemName == "parent_id" {
|
||||
//if parent_idsStr != "" {
|
||||
//
|
||||
// where := Map{}
|
||||
//
|
||||
// for _, v := range reqValue {
|
||||
// if len(where) == 0 {
|
||||
// where[parent_idsStr] = "," + v + ","
|
||||
// continue
|
||||
// }
|
||||
// where = Map{"OR": where, parent_idsStr: "," + v + ","}
|
||||
// }
|
||||
// //用户
|
||||
// if userData[searchItem.GetString("name")] != nil {
|
||||
// where = Map{"AND": Map{parent_idsStr: "," + ObjToStr(userData.GetCeilInt64(searchItem.GetString("name"))) + ",", "OR": where}}
|
||||
// }
|
||||
// r := db.Select(searchItem.GetString("link"), "id", where)
|
||||
// for _, v := range r {
|
||||
// reqValue = append(reqValue, v.GetString("id"))
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
||||
parentID := ObjToInt(req.FormValue("parent_id"))
|
||||
if parentID == 0 {
|
||||
parentID = userData.GetCeilInt(table + "_id")
|
||||
data["OR"] = Map{table + ".id": parentID, table + ".parent_id": nil}
|
||||
} else {
|
||||
data[table+".parent_id"] = reqValue
|
||||
|
||||
if req.FormValue("showself") != "" {
|
||||
where := Map{}
|
||||
for _, v := range reqValue {
|
||||
if len(where) == 0 {
|
||||
where[table+"."+parent_idsStr] = "," + v + ","
|
||||
continue
|
||||
}
|
||||
where = Map{"OR": where, table + "." + parent_idsStr: "," + v + ","}
|
||||
}
|
||||
data["OR"] = Map{"OR": where, table + ".id": reqValue}
|
||||
} else {
|
||||
data[table+".parent_id"] = reqValue
|
||||
}
|
||||
|
||||
}
|
||||
continue
|
||||
}
|
||||
@@ -1059,28 +1093,43 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
|
||||
if parent_idsStr != "" {
|
||||
|
||||
where := Map{}
|
||||
|
||||
for _, v := range reqValue {
|
||||
if len(reqValue) == 1 {
|
||||
if len(where) == 0 {
|
||||
where[parent_idsStr] = "," + v + ","
|
||||
continue
|
||||
where[table+"."+searchItem.GetString("name")] = reqValue[0]
|
||||
|
||||
} else {
|
||||
where = Map{"OR": where, table + "." + searchItem.GetString("name"): reqValue[0]}
|
||||
}
|
||||
|
||||
} else {
|
||||
for _, v := range reqValue {
|
||||
if len(where) == 0 {
|
||||
where[searchItem.GetString("link")+"."+parent_idsStr] = "," + v + ","
|
||||
continue
|
||||
}
|
||||
where = Map{"OR": where, searchItem.GetString("link") + "." + parent_idsStr: "," + v + ","}
|
||||
}
|
||||
where = Map{"OR": where, parent_idsStr: "," + v + ","}
|
||||
}
|
||||
//用户
|
||||
if userData[searchItem.GetString("name")] != nil {
|
||||
where = Map{"AND": Map{parent_idsStr: "," + ObjToStr(userData.GetCeilInt64(searchItem.GetString("name"))) + ",", "OR": where}}
|
||||
}
|
||||
r := db.Select(searchItem.GetString("link"), "id", where)
|
||||
for _, v := range r {
|
||||
reqValue = append(reqValue, v.GetString("id"))
|
||||
|
||||
where = Map{"AND": Map{searchItem.GetString("link") + "." + parent_idsStr: "," + ObjToStr(userData.GetCeilInt64(searchItem.GetString("name"))) + ",", "OR": where}}
|
||||
}
|
||||
data["OR"] = where
|
||||
|
||||
continue
|
||||
//r := db.Select(searchItem.GetString("link"), "id", where)
|
||||
//for _, v := range r {
|
||||
// reqValue = append(reqValue, v.GetString("id"))
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
data[table+"."+searchItemName] = reqValue
|
||||
if len(reqValue) != 0 && reqValue[0] != "" {
|
||||
data[table+"."+searchItemName] = reqValue
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if sortMap["ORDER"] == nil {
|
||||
@@ -1139,7 +1188,3 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
|
||||
|
||||
return reStr, leftJoin, where
|
||||
}
|
||||
|
||||
func setListener() {
|
||||
|
||||
}
|
||||
|
||||
+12
-2
@@ -1,11 +1,11 @@
|
||||
package hotime
|
||||
|
||||
import (
|
||||
. "code.hoteas.com/golang/hotime/cache"
|
||||
. "code.hoteas.com/golang/hotime/common"
|
||||
. "code.hoteas.com/golang/hotime/db"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -19,7 +19,7 @@ type Context struct {
|
||||
Db *HoTimeDB
|
||||
RespData Map
|
||||
RespFunc func()
|
||||
CacheIns
|
||||
//CacheIns
|
||||
SessionIns
|
||||
DataSize int
|
||||
HandlerStr string //复写请求url
|
||||
@@ -75,6 +75,16 @@ func (that *Context) View() {
|
||||
if that.Session("user_id").Data != nil {
|
||||
that.Log["user_id"] = that.Session("user_id").ToCeilInt()
|
||||
}
|
||||
ipStr := Substr(that.Req.RemoteAddr, 0, strings.Index(that.Req.RemoteAddr, ":"))
|
||||
//负载均衡优化
|
||||
if ipStr == "127.0.0.1" {
|
||||
if that.Req.Header.Get("X-Forwarded-For") != "" {
|
||||
ipStr = that.Req.Header.Get("X-Forwarded-For")
|
||||
} else if that.Req.Header.Get("X-Real-IP") != "" {
|
||||
ipStr = that.Req.Header.Get("X-Real-IP")
|
||||
}
|
||||
}
|
||||
that.Log["ip"] = ipStr
|
||||
that.Db.Insert("logs", that.Log)
|
||||
}
|
||||
|
||||
|
||||
+145
-33
@@ -34,7 +34,7 @@ type HoTimeDB struct {
|
||||
}
|
||||
|
||||
type HotimeDBBuilder struct {
|
||||
*HoTimeDB
|
||||
HoTimeDB *HoTimeDB
|
||||
table string
|
||||
selects []interface{}
|
||||
join Slice
|
||||
@@ -70,7 +70,21 @@ func (that *HotimeDBBuilder) Select(qu ...interface{}) []Map {
|
||||
return that.HoTimeDB.Select(that.table, that.join, qu, that.where)
|
||||
}
|
||||
|
||||
func (that *HotimeDBBuilder) Update(data Map) int64 {
|
||||
func (that *HotimeDBBuilder) Update(qu ...interface{}) int64 {
|
||||
lth := len(qu)
|
||||
if lth == 0 {
|
||||
return 0
|
||||
}
|
||||
data := Map{}
|
||||
if lth == 1 {
|
||||
data = ObjToMap(qu[0])
|
||||
}
|
||||
if lth > 1 {
|
||||
for k := 1; k < lth; k++ {
|
||||
data[ObjToStr(qu[k-1])] = qu[k]
|
||||
k++
|
||||
}
|
||||
}
|
||||
|
||||
return that.HoTimeDB.Update(that.table, data, that.where)
|
||||
}
|
||||
@@ -101,19 +115,51 @@ func (that *HotimeDBBuilder) FullJoin(table, joinStr string) *HotimeDBBuilder {
|
||||
return that
|
||||
}
|
||||
|
||||
func (that *HotimeDBBuilder) Join(join Map) *HotimeDBBuilder {
|
||||
func (that *HotimeDBBuilder) Join(qu ...interface{}) *HotimeDBBuilder {
|
||||
lth := len(qu)
|
||||
if lth == 0 {
|
||||
return that
|
||||
}
|
||||
data := Map{}
|
||||
if lth == 1 {
|
||||
data = ObjToMap(qu[0])
|
||||
}
|
||||
if lth > 1 {
|
||||
for k := 1; k < lth; k++ {
|
||||
data[ObjToStr(qu[k-1])] = qu[k]
|
||||
k++
|
||||
}
|
||||
}
|
||||
|
||||
if that.join == nil {
|
||||
that.join = Slice{}
|
||||
}
|
||||
if join == nil {
|
||||
if data == nil {
|
||||
return that
|
||||
}
|
||||
|
||||
that.join = append(that.join, join)
|
||||
that.join = append(that.join, data)
|
||||
return that
|
||||
}
|
||||
|
||||
func (that *HotimeDBBuilder) And(where Map) *HotimeDBBuilder {
|
||||
func (that *HotimeDBBuilder) And(qu ...interface{}) *HotimeDBBuilder {
|
||||
|
||||
lth := len(qu)
|
||||
if lth == 0 {
|
||||
return that
|
||||
}
|
||||
var where Map
|
||||
if lth == 1 {
|
||||
where = ObjToMap(qu[0])
|
||||
}
|
||||
if lth > 1 {
|
||||
where = Map{}
|
||||
for k := 1; k < lth; k++ {
|
||||
where[ObjToStr(qu[k-1])] = qu[k]
|
||||
k++
|
||||
}
|
||||
}
|
||||
|
||||
if where == nil {
|
||||
return that
|
||||
}
|
||||
@@ -129,7 +175,22 @@ func (that *HotimeDBBuilder) And(where Map) *HotimeDBBuilder {
|
||||
return that
|
||||
}
|
||||
|
||||
func (that *HotimeDBBuilder) Or(where Map) *HotimeDBBuilder {
|
||||
func (that *HotimeDBBuilder) Or(qu ...interface{}) *HotimeDBBuilder {
|
||||
lth := len(qu)
|
||||
if lth == 0 {
|
||||
return that
|
||||
}
|
||||
var where Map
|
||||
if lth == 1 {
|
||||
where = ObjToMap(qu[0])
|
||||
}
|
||||
if lth > 1 {
|
||||
where = Map{}
|
||||
for k := 1; k < lth; k++ {
|
||||
where[ObjToStr(qu[k-1])] = qu[k]
|
||||
k++
|
||||
}
|
||||
}
|
||||
if where == nil {
|
||||
return that
|
||||
}
|
||||
@@ -144,7 +205,24 @@ func (that *HotimeDBBuilder) Or(where Map) *HotimeDBBuilder {
|
||||
|
||||
return that
|
||||
}
|
||||
func (that *HotimeDBBuilder) Where(where Map) *HotimeDBBuilder {
|
||||
func (that *HotimeDBBuilder) Where(qu ...interface{}) *HotimeDBBuilder {
|
||||
|
||||
lth := len(qu)
|
||||
if lth == 0 {
|
||||
return that
|
||||
}
|
||||
var where Map
|
||||
if lth == 1 {
|
||||
where = ObjToMap(qu[0])
|
||||
}
|
||||
if lth > 1 {
|
||||
where = Map{}
|
||||
for k := 1; k < lth; k++ {
|
||||
where[ObjToStr(qu[k-1])] = qu[k]
|
||||
k++
|
||||
}
|
||||
}
|
||||
|
||||
if where == nil {
|
||||
return that
|
||||
}
|
||||
@@ -193,7 +271,11 @@ func (that *HoTimeDB) GetType() string {
|
||||
|
||||
// Action 事务,如果action返回true则执行成功;false则回滚
|
||||
func (that *HoTimeDB) Action(action func(db HoTimeDB) (isSuccess bool)) (isSuccess bool) {
|
||||
db := HoTimeDB{DB: that.DB, HoTimeCache: that.HoTimeCache, Prefix: that.Prefix}
|
||||
db := HoTimeDB{that.DB, that.ContextBase, that.DBName,
|
||||
that.HoTimeCache, that.Log, that.Type,
|
||||
that.Prefix, that.LastQuery, that.LastData,
|
||||
that.ConnectFunc, that.LastErr, that.limit, that.Tx,
|
||||
that.SlaveDB, that.Mode}
|
||||
tx, err := db.Begin()
|
||||
if err != nil {
|
||||
that.LastErr.SetError(err)
|
||||
@@ -236,7 +318,7 @@ func (that *HoTimeDB) InitDb(err ...*Error) *Error {
|
||||
e := that.SlaveDB.Ping()
|
||||
that.LastErr.SetError(e)
|
||||
}
|
||||
|
||||
//that.DB.SetConnMaxLifetime(time.Second)
|
||||
return that.LastErr
|
||||
}
|
||||
|
||||
@@ -456,7 +538,7 @@ func (that *HoTimeDB) md5(query string, args ...interface{}) string {
|
||||
|
||||
func (that *HoTimeDB) Query(query string, args ...interface{}) []Map {
|
||||
defer func() {
|
||||
if that.Mode == 2 {
|
||||
if that.Mode != 0 {
|
||||
that.Log.Info("SQL:"+that.LastQuery, " DATA:", that.LastData, " ERROR:", that.LastErr.GetError())
|
||||
}
|
||||
}()
|
||||
@@ -484,16 +566,18 @@ func (that *HoTimeDB) Query(query string, args ...interface{}) []Map {
|
||||
resl, err = db.Query(query, args...)
|
||||
}
|
||||
|
||||
if err != nil && that.LastErr.GetError() != nil &&
|
||||
that.LastErr.GetError().Error() == err.Error() {
|
||||
return nil
|
||||
}
|
||||
|
||||
that.LastErr.SetError(err)
|
||||
if err != nil {
|
||||
if err = db.Ping(); err != nil {
|
||||
that.LastErr.SetError(err)
|
||||
_ = that.InitDb()
|
||||
if that.LastErr.GetError() != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if err = db.Ping(); err == nil {
|
||||
return that.Query(query, args...)
|
||||
}
|
||||
that.LastErr.SetError(err)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -502,7 +586,7 @@ func (that *HoTimeDB) Query(query string, args ...interface{}) []Map {
|
||||
|
||||
func (that *HoTimeDB) Exec(query string, args ...interface{}) (sql.Result, *Error) {
|
||||
defer func() {
|
||||
if that.Mode == 2 {
|
||||
if that.Mode != 0 {
|
||||
that.Log.Info("SQL: "+that.LastQuery, " DATA: ", that.LastData, " ERROR: ", that.LastErr.GetError())
|
||||
}
|
||||
}()
|
||||
@@ -523,19 +607,18 @@ func (that *HoTimeDB) Exec(query string, args ...interface{}) (sql.Result, *Erro
|
||||
resl, e = that.DB.Exec(query, args...)
|
||||
}
|
||||
|
||||
if e != nil && that.LastErr.GetError() != nil &&
|
||||
that.LastErr.GetError().Error() == e.Error() {
|
||||
return resl, that.LastErr
|
||||
}
|
||||
that.LastErr.SetError(e)
|
||||
|
||||
//判断是否连接断开了
|
||||
if e != nil {
|
||||
|
||||
if e = that.DB.Ping(); e != nil {
|
||||
that.LastErr.SetError(e)
|
||||
_ = that.InitDb()
|
||||
if that.LastErr.GetError() != nil {
|
||||
return resl, that.LastErr
|
||||
}
|
||||
if e = that.DB.Ping(); e == nil {
|
||||
return that.Exec(query, args...)
|
||||
}
|
||||
that.LastErr.SetError(e)
|
||||
return resl, that.LastErr
|
||||
}
|
||||
|
||||
@@ -582,11 +665,13 @@ func (that *HoTimeDB) Select(table string, qu ...interface{}) []Map {
|
||||
data := ObjToSlice(qu[intQs])
|
||||
for i := 0; i < len(data); i++ {
|
||||
k := data.GetString(i)
|
||||
if strings.Contains(k, " AS ") {
|
||||
if strings.Contains(k, " AS ") ||
|
||||
strings.Contains(k, ".") {
|
||||
|
||||
query += " " + k + " "
|
||||
|
||||
} else {
|
||||
|
||||
query += " `" + k + "` "
|
||||
}
|
||||
|
||||
@@ -618,9 +703,9 @@ func (that *HoTimeDB) Select(table string, qu ...interface{}) []Map {
|
||||
}
|
||||
|
||||
if reflect.ValueOf(qu[0]).Type().String() == "common.Slice" {
|
||||
|
||||
for key, _ := range testQuData {
|
||||
v := testQuData.GetMap(key)
|
||||
qu0 := ObjToSlice(qu[0])
|
||||
for key, _ := range qu0 {
|
||||
v := qu0.GetMap(key)
|
||||
for k1, v1 := range v {
|
||||
testQu = append(testQu, k1)
|
||||
testQuData[k1] = v1
|
||||
@@ -634,15 +719,42 @@ func (that *HoTimeDB) Select(table string, qu ...interface{}) []Map {
|
||||
v := testQuData[k]
|
||||
switch Substr(k, 0, 3) {
|
||||
case "[>]":
|
||||
query += " LEFT JOIN `" + Substr(k, 3, len(k)-3) + "` ON " + v.(string) + " "
|
||||
func() {
|
||||
table := Substr(k, 3, len(k)-3)
|
||||
if !strings.Contains(table, " ") {
|
||||
table = "`" + table + "`"
|
||||
}
|
||||
query += " LEFT JOIN " + table + " ON " + v.(string) + " "
|
||||
}()
|
||||
case "[<]":
|
||||
query += " RIGHT JOIN `" + Substr(k, 3, len(k)-3) + "` ON " + v.(string) + " "
|
||||
func() {
|
||||
table := Substr(k, 3, len(k)-3)
|
||||
if !strings.Contains(table, " ") {
|
||||
table = "`" + table + "`"
|
||||
}
|
||||
query += " RIGHT JOIN " + table + " ON " + v.(string) + " "
|
||||
}()
|
||||
|
||||
}
|
||||
switch Substr(k, 0, 4) {
|
||||
case "[<>]":
|
||||
query += " FULL JOIN `" + Substr(k, 4, len(k)-4) + "` ON " + v.(string) + " "
|
||||
func() {
|
||||
table := Substr(k, 4, len(k)-4)
|
||||
if !strings.Contains(table, " ") {
|
||||
table = "`" + table + "`"
|
||||
}
|
||||
query += " FULL JOIN " + table + " ON " + v.(string) + " "
|
||||
}()
|
||||
|
||||
case "[><]":
|
||||
query += " INNER JOIN `" + Substr(k, 4, len(k)-4) + "` ON " + v.(string) + " "
|
||||
func() {
|
||||
table := Substr(k, 4, len(k)-4)
|
||||
if !strings.Contains(table, " ") {
|
||||
table = "`" + table + "`"
|
||||
}
|
||||
query += " INNER JOIN " + table + " ON " + v.(string) + " "
|
||||
}()
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,104 +0,0 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
. "code.hoteas.com/golang/hotime"
|
||||
. "code.hoteas.com/golang/hotime/common"
|
||||
"time"
|
||||
)
|
||||
|
||||
var ArticleCtr = Ctr{
|
||||
"info": func(that *Context) {
|
||||
sn := that.Req.FormValue("sn")
|
||||
article := that.Db.Get("article", Map{"[><]ctg_article": "article.id=ctg_article.article_id"}, "article.*,ctg_article.ctg_id AS sctg_id", Map{"ctg_article.sn": sn})
|
||||
if article == nil {
|
||||
that.Display(4, "找不到对应数据")
|
||||
return
|
||||
}
|
||||
ctgId := article.GetCeilInt64("sctg_id")
|
||||
ctg := that.Db.Get("ctg", "*", Map{"id": ctgId})
|
||||
parents := []Map{}
|
||||
parentId := ctg.GetCeilInt64("parent_id")
|
||||
article["tongji"] = that.Db.Select("ctg", "sn,name,img,parent_id", Map{"parent_id": parentId})
|
||||
for true {
|
||||
|
||||
if parentId == 0 {
|
||||
break
|
||||
}
|
||||
|
||||
parent := that.Db.Get("ctg", "sn,name,img,parent_id", Map{"id": parentId})
|
||||
if parent == nil {
|
||||
break
|
||||
}
|
||||
|
||||
parents = append(parents, parent)
|
||||
parentId = parent.GetCeilInt64("parent_id")
|
||||
|
||||
}
|
||||
|
||||
ctg["parents"] = parents
|
||||
|
||||
article["ctg"] = ctg
|
||||
that.Display(0, article)
|
||||
},
|
||||
"list": func(that *Context) {
|
||||
sn := that.Req.FormValue("ctg_sn") //ctgsn
|
||||
page := ObjToInt(that.Req.FormValue("page"))
|
||||
pageSize := ObjToInt(that.Req.FormValue("pageSize"))
|
||||
|
||||
if page == 0 {
|
||||
page = 1
|
||||
}
|
||||
if pageSize == 0 {
|
||||
pageSize = 10
|
||||
}
|
||||
|
||||
keywords := that.Req.FormValue("keywords")
|
||||
|
||||
lunbo := ObjToInt(that.Req.FormValue("lunbo"))
|
||||
|
||||
sort := that.Req.FormValue("sort")
|
||||
|
||||
where := Map{"article.push_time[<]": time.Now().Format("2006-01-02 15:04"), "article.state": 0}
|
||||
if sn != "" {
|
||||
ctg := that.Db.Get("ctg", "id", Map{"sn": sn})
|
||||
if ctg != nil {
|
||||
where["ctg_article.ctg_id"] = ctg.GetCeilInt("id")
|
||||
}
|
||||
}
|
||||
|
||||
startTime := that.Req.FormValue("start_time") //ctgsn
|
||||
finishTime := that.Req.FormValue("finish_time") //ctgsn
|
||||
|
||||
if lunbo != 0 {
|
||||
where["article.lunbo"] = lunbo
|
||||
}
|
||||
|
||||
if len(startTime) > 5 {
|
||||
where["article.push_time[>=]"] = startTime
|
||||
}
|
||||
if len(finishTime) > 5 {
|
||||
where["article.push_time[<=]"] = finishTime
|
||||
}
|
||||
|
||||
if keywords != "" {
|
||||
where["OR"] = Map{"article.title[~]": keywords, "article.description[~]": keywords, "article.author[~]": keywords, "article.sn[~]": keywords, "article.origin[~]": keywords, "article.url[~]": keywords}
|
||||
}
|
||||
|
||||
if len(where) > 1 {
|
||||
where = Map{"AND": where}
|
||||
}
|
||||
|
||||
if sort == "" {
|
||||
where["ORDER"] = Slice{"article.sort DESC", "article.push_time DESC"}
|
||||
}
|
||||
|
||||
if sort == "time" {
|
||||
where["ORDER"] = "article.push_time DESC"
|
||||
}
|
||||
count := that.Db.Count("article", Map{"[><]ctg_article": "article.id=ctg_article.article_id"}, where)
|
||||
article := that.Db.Page(page, pageSize).PageSelect("article", Map{"[><]ctg_article": "article.id=ctg_article.article_id"}, "ctg_article.sn,article.img,article.title,article.description,article.push_time,article.lunbo,article.author,article.origin,article.url", where)
|
||||
|
||||
that.Display(0, Map{"count": count, "data": article})
|
||||
|
||||
},
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
. "code.hoteas.com/golang/hotime"
|
||||
. "code.hoteas.com/golang/hotime/common"
|
||||
)
|
||||
|
||||
var CtgCtr = Ctr{
|
||||
"info": func(that *Context) {
|
||||
sn := that.Req.FormValue("sn")
|
||||
ctg := that.Db.Get("ctg", "*", Map{"sn": sn})
|
||||
parents := []Map{}
|
||||
parentId := ctg.GetCeilInt64("parent_id")
|
||||
ctg["tongji"] = that.Db.Select("ctg", "sn,name,img,parent_id", Map{"parent_id": parentId})
|
||||
for true {
|
||||
|
||||
if parentId == 0 {
|
||||
break
|
||||
}
|
||||
|
||||
parent := that.Db.Get("ctg", "sn,name,img,parent_id", Map{"id": parentId})
|
||||
if parent == nil {
|
||||
break
|
||||
}
|
||||
|
||||
parents = append(parents, parent)
|
||||
parentId = parent.GetCeilInt64("parent_id")
|
||||
|
||||
}
|
||||
|
||||
if ctg.GetCeilInt64("article_id") != 0 {
|
||||
ctg["article"] = that.Db.Get("article", "*", Map{"id": ctg.GetCeilInt64("article_id")})
|
||||
}
|
||||
|
||||
ctg["parents"] = parents
|
||||
that.Display(0, ctg)
|
||||
},
|
||||
"list": func(that *Context) {
|
||||
sn := that.Req.FormValue("sn") //ctgsn
|
||||
page := ObjToInt(that.Req.FormValue("page"))
|
||||
pageSize := ObjToInt(that.Req.FormValue("pageSize"))
|
||||
|
||||
if page == 0 {
|
||||
page = 1
|
||||
}
|
||||
if pageSize == 0 {
|
||||
pageSize = 50
|
||||
}
|
||||
|
||||
keywords := that.Req.FormValue("keywords")
|
||||
|
||||
//sort:=that.Req.FormValue("sort")
|
||||
|
||||
where := Map{"state": 0}
|
||||
if sn != "" {
|
||||
ctg := that.Db.Get("ctg", "id", Map{"sn": sn})
|
||||
if ctg != nil {
|
||||
where["parent_id"] = ctg.GetCeilInt("id")
|
||||
}
|
||||
}
|
||||
|
||||
if keywords != "" {
|
||||
where["OR"] = Map{"name[~]": keywords, "url[~]": keywords, "sn[~]": keywords}
|
||||
}
|
||||
|
||||
if len(where) > 1 {
|
||||
where = Map{"AND": where}
|
||||
}
|
||||
|
||||
where["ORDER"] = Slice{"sort DESC", "id DESC"}
|
||||
|
||||
article := that.Db.Page(page, pageSize).PageSelect("ctg", "name,sn,sort,url,img", where)
|
||||
|
||||
that.Display(0, article)
|
||||
|
||||
},
|
||||
}
|
||||
@@ -1,127 +0,0 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
. "code.hoteas.com/golang/hotime"
|
||||
. "code.hoteas.com/golang/hotime/common"
|
||||
"time"
|
||||
)
|
||||
|
||||
var AppProj = Proj{
|
||||
"article": ArticleCtr,
|
||||
"org": OrgCtr,
|
||||
"ctg": CtgCtr,
|
||||
"mail": MailCtr,
|
||||
"test": {
|
||||
"test": func(that *Context) {
|
||||
//data:=that.Db.Table("admin").Order("id DESC").Select("*")
|
||||
//data1:=that.Db.Table("admin").Where(Map{"name[~]":"m"}).Order("id DESC").Select("*")
|
||||
//
|
||||
//data3:=that.Db.Select("admin","*",Map{"name[~]":"m"})
|
||||
data2 := that.Db.Table("article").Where(Map{"title[~]": "m"}).Order("id DESC").Page(1, 10).Select("*")
|
||||
c := that.Db.Table("article").Where(Map{"title[~]": "m"}).Order("id DESC").Group("title").Select("*")
|
||||
//that.Display(0,Slice{data1,data,data3,data2})
|
||||
that.Display(0, Slice{data2, c})
|
||||
},
|
||||
"res": func(that *Context) {
|
||||
ebw_res := that.Db.Select("ebw_res", "*")
|
||||
|
||||
for _, v := range ebw_res {
|
||||
data := Map{"id": v.GetCeilInt("id"), "name": v.GetString("name"),
|
||||
"parent_id": v.GetCeilInt64("pid"),
|
||||
"sn": v.GetString("url"), "create_time": time.Now().Format("2006-01-02 15:04"),
|
||||
"modify_time": time.Now().Format("2006-01-02 15:04"), "admin_id": 1}
|
||||
if data.GetCeilInt("parent_id") == 0 {
|
||||
data["parent_id"] = nil
|
||||
}
|
||||
that.Db.Insert("ctg", data)
|
||||
}
|
||||
|
||||
that.Db.Exec("UPDATE ctg SET parent_id =NULL WHERE parent_id=id")
|
||||
|
||||
ss(0, that)
|
||||
|
||||
that.Display(0, len(ebw_res))
|
||||
|
||||
},
|
||||
"news": func(that *Context) {
|
||||
ebw_news := that.Db.Select("ebw_news", "*")
|
||||
|
||||
for _, v := range ebw_news {
|
||||
ctg := that.Db.Get("ctg", "*", Map{"sn": v.GetString("type")})
|
||||
data := Map{"sn": v.GetString("id"), "title": v.GetString("title"),
|
||||
"content": v.GetString("content"), "push_time": v.GetString("timedate"),
|
||||
"author": v.GetString("owner"), "origin": v.GetString("source"), "click_num": v.GetString("readtime"),
|
||||
"sort": v.GetCeilInt("zhiding"), "create_time": time.Now().Format("2006-01-02 15:04"),
|
||||
"modify_time": time.Now().Format("2006-01-02 15:04"), "admin_id": 1}
|
||||
if ctg != nil {
|
||||
data["ctg_id"] = ctg.GetCeilInt("id")
|
||||
}
|
||||
that.Db.Insert("article", data)
|
||||
}
|
||||
|
||||
that.Display(0, len(ebw_news))
|
||||
|
||||
},
|
||||
"res2news": func(that *Context) {
|
||||
ebw_news_addition_res := that.Db.Select("ebw_news_addition_res", "*")
|
||||
|
||||
for _, v := range ebw_news_addition_res {
|
||||
ctg := that.Db.Get("ctg", "*", Map{"sn": v.GetString("fk_res")})
|
||||
article := that.Db.Get("article", "*", Map{"sn": v.GetString("fk_newsid")})
|
||||
data := Map{"sn": Md5(ObjToStr(time.Now().UnixNano()) + ObjToStr(RandX(10000, 100000))),
|
||||
"create_time": time.Now().Format("2006-01-02 15:04"),
|
||||
"modify_time": time.Now().Format("2006-01-02 15:04"), "admin_id": 1}
|
||||
if ctg != nil {
|
||||
data["ctg_id"] = ctg.GetCeilInt("id")
|
||||
}
|
||||
if article != nil {
|
||||
data["article_id"] = article.GetCeilInt("id")
|
||||
}
|
||||
that.Db.Insert("ctg_article", data)
|
||||
}
|
||||
|
||||
that.Display(0, len(ebw_news_addition_res))
|
||||
},
|
||||
//将文章没有关联的ctg_article进行关联
|
||||
"article": func(that *Context) {
|
||||
articles := that.Db.Select("article", "id,ctg_id")
|
||||
for _, v := range articles {
|
||||
ctg_article := that.Db.Get("ctg_article", "id", Map{"article_id": v.GetCeilInt("id")})
|
||||
if ctg_article == nil {
|
||||
|
||||
data := Map{"sn": Md5(ObjToStr(time.Now().UnixNano()) + ObjToStr(RandX(10000, 100000))),
|
||||
"create_time": time.Now().Format("2006-01-02 15:04"),
|
||||
"modify_time": time.Now().Format("2006-01-02 15:04"), "admin_id": 1}
|
||||
if v.GetCeilInt("ctg_id") == 0 || v.GetCeilInt("id") == 0 {
|
||||
continue
|
||||
}
|
||||
data["ctg_id"] = v.GetCeilInt("ctg_id")
|
||||
data["article_id"] = v.GetCeilInt("id")
|
||||
that.Db.Insert("ctg_article", data)
|
||||
}
|
||||
|
||||
}
|
||||
that.Display(0, len(articles))
|
||||
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func ss(parent_id int, that *Context) {
|
||||
var ctgs []Map
|
||||
ctg := that.Db.Get("ctg", "*", Map{"id": parent_id})
|
||||
if parent_id == 0 {
|
||||
ctgs = that.Db.Select("ctg", "*", Map{"parent_id": nil})
|
||||
} else {
|
||||
ctgs = that.Db.Select("ctg", "*", Map{"parent_id": parent_id})
|
||||
}
|
||||
|
||||
for _, v := range ctgs {
|
||||
if ctg == nil {
|
||||
ctg = Map{"parent_ids": ","}
|
||||
}
|
||||
ids := ctg.GetString("parent_ids") + ObjToStr(v.GetCeilInt("id")) + ","
|
||||
that.Db.Update("ctg", Map{"parent_ids": ids}, Map{"id": v.GetCeilInt("id")})
|
||||
ss(v.GetCeilInt("id"), that)
|
||||
}
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
. "code.hoteas.com/golang/hotime"
|
||||
. "code.hoteas.com/golang/hotime/common"
|
||||
"time"
|
||||
)
|
||||
|
||||
var MailCtr = Ctr{
|
||||
"add": func(that *Context) {
|
||||
title := that.Req.FormValue("title")
|
||||
name := that.Req.FormValue("name")
|
||||
phone := that.Req.FormValue("phone")
|
||||
content := that.Req.FormValue("content")
|
||||
|
||||
tp := ObjToInt(that.Req.FormValue("type"))
|
||||
show := ObjToInt(that.Req.FormValue("show"))
|
||||
|
||||
if len(title) < 5 {
|
||||
that.Display(3, "标题过短")
|
||||
return
|
||||
}
|
||||
if len(name) < 2 {
|
||||
that.Display(3, "姓名错误")
|
||||
return
|
||||
}
|
||||
if len(phone) < 8 {
|
||||
that.Display(3, "联系方式错误")
|
||||
return
|
||||
}
|
||||
if len(content) < 10 {
|
||||
that.Display(3, "内容过短")
|
||||
return
|
||||
}
|
||||
|
||||
data := Map{
|
||||
"sn": Md5(ObjToStr(time.Now().UnixNano()) + ObjToStr(RandX(10000, 100000))),
|
||||
"name": name, "title": title, "phone": phone, "content": content, "type": tp, "show": show,
|
||||
"modify_time[#]": "NOW()", "create_time[#]": "NOW()",
|
||||
}
|
||||
id := that.Db.Insert("mail", data)
|
||||
if id == 0 {
|
||||
that.Display(4, "创建失败")
|
||||
return
|
||||
}
|
||||
|
||||
that.Display(0, "成功")
|
||||
return
|
||||
|
||||
},
|
||||
"info": func(that *Context) {
|
||||
sn := that.Req.FormValue("sn")
|
||||
|
||||
mail := that.Db.Get("mail", "*", Map{"sn": sn})
|
||||
|
||||
that.Display(0, mail)
|
||||
},
|
||||
"list": func(that *Context) {
|
||||
page := ObjToInt(that.Req.FormValue("page"))
|
||||
pageSize := ObjToInt(that.Req.FormValue("pageSize"))
|
||||
|
||||
if page == 0 {
|
||||
page = 1
|
||||
}
|
||||
if pageSize == 0 {
|
||||
pageSize = 10
|
||||
}
|
||||
|
||||
//keywords:=that.Req.FormValue("keywords")
|
||||
|
||||
//sort:=that.Req.FormValue("sort")
|
||||
|
||||
where := Map{"state": 0, "show": 1}
|
||||
|
||||
//if keywords!=""{
|
||||
// where["OR"]=Map{"title[~]":keywords,"description[~]":keywords,"author[~]":keywords,"sn[~]":keywords,"origin[~]":keywords,"url[~]":keywords}
|
||||
//}
|
||||
|
||||
if len(where) > 1 {
|
||||
where = Map{"AND": where}
|
||||
}
|
||||
|
||||
//if sort==""{
|
||||
// where["ORDER"]=Slice{"sort DESC","push_time DESC"}
|
||||
//}
|
||||
//
|
||||
//if sort=="time"{
|
||||
where["ORDER"] = "create_time DESC"
|
||||
//}
|
||||
count := that.Db.Count("mail", where)
|
||||
mail := that.Db.Page(page, pageSize).PageSelect("mail", "*", where)
|
||||
|
||||
that.Display(0, Map{"count": count, "data": mail})
|
||||
|
||||
},
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
. "code.hoteas.com/golang/hotime"
|
||||
. "code.hoteas.com/golang/hotime/common"
|
||||
"time"
|
||||
)
|
||||
|
||||
var OrgCtr = Ctr{
|
||||
"info": func(that *Context) {
|
||||
sn := that.Req.FormValue("sn")
|
||||
article := that.Db.Get("article", "*", Map{"sn": sn})
|
||||
that.Display(0, article)
|
||||
},
|
||||
"list": func(that *Context) {
|
||||
sn := that.Req.FormValue("sn") //orgsn
|
||||
page := ObjToInt(that.Req.FormValue("page"))
|
||||
pageSize := ObjToInt(that.Req.FormValue("pageSize"))
|
||||
|
||||
if page == 0 {
|
||||
page = 1
|
||||
}
|
||||
if pageSize == 0 {
|
||||
pageSize = 50
|
||||
}
|
||||
|
||||
keywords := that.Req.FormValue("keywords")
|
||||
|
||||
sort := that.Req.FormValue("sort")
|
||||
|
||||
where := Map{"push_time[<=]": time.Now().Format("2006-01-02 15:04"), "state": 0}
|
||||
if sn != "" {
|
||||
org := that.Db.Get("org", "id", Map{"sn": sn})
|
||||
if org != nil {
|
||||
where["org_id"] = org.GetCeilInt("id")
|
||||
}
|
||||
}
|
||||
|
||||
if keywords != "" {
|
||||
where["OR"] = Map{"title[~]": keywords, "description[~]": keywords, "author[~]": keywords, "sn[~]": keywords, "origin[~]": keywords, "url[~]": keywords}
|
||||
}
|
||||
|
||||
if len(where) > 1 {
|
||||
where = Map{"AND": where}
|
||||
}
|
||||
|
||||
if sort == "" {
|
||||
where["ORDER"] = Slice{"sort DESC", "id DESC"}
|
||||
}
|
||||
|
||||
if sort == "time" {
|
||||
where["ORDER"] = "push_time DESC"
|
||||
}
|
||||
|
||||
article := that.Db.Page(page, pageSize).PageSelect("article", "sn,title,description,push_time,lunbo,author,origin,url", where)
|
||||
|
||||
that.Display(0, article)
|
||||
|
||||
},
|
||||
}
|
||||
@@ -23,13 +23,12 @@
|
||||
],
|
||||
"db": {
|
||||
"mysql": {
|
||||
"host": "192.168.2.20",
|
||||
"name": "gov_crawler",
|
||||
"password": "fh22y8b882d",
|
||||
"host": "192.168.6.253",
|
||||
"name": "dgs-cms",
|
||||
"password": "dasda8454456",
|
||||
"port": "3306",
|
||||
"prefix": "",
|
||||
"user": "root"
|
||||
|
||||
}
|
||||
},
|
||||
"defFile": [
|
||||
"index.html",
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
{
|
||||
"cache": {
|
||||
"db": {
|
||||
"db": false,
|
||||
"session": true,
|
||||
"timeout": 7200
|
||||
},
|
||||
"memory": {
|
||||
"db": true,
|
||||
"session": true,
|
||||
"timeout": 7200
|
||||
}
|
||||
},
|
||||
"codeConfig": [
|
||||
{
|
||||
"config": "config/admin.json",
|
||||
"configDB": "config/adminDB.json",
|
||||
"mode": 0,
|
||||
"name": "",
|
||||
"rule": "config/rule.json",
|
||||
"table": "admin"
|
||||
}
|
||||
],
|
||||
"db": {
|
||||
"mysql": {
|
||||
"host": "192.168.2.20",
|
||||
"name": "gov_crawler",
|
||||
"password": "fh22y8b882d",
|
||||
"port": "3306",
|
||||
"prefix": "",
|
||||
"user": "root"
|
||||
}
|
||||
},
|
||||
"defFile": [
|
||||
"index.html",
|
||||
"index.htm"
|
||||
],
|
||||
"error": {
|
||||
"1": "内部系统异常",
|
||||
"2": "访问权限异常",
|
||||
"3": "请求参数异常",
|
||||
"4": "数据处理异常",
|
||||
"5": "数据结果异常"
|
||||
},
|
||||
"mode": 2,
|
||||
"port": "8081",
|
||||
"sessionName": "HOTIME",
|
||||
"tpt": "tpt"
|
||||
}
|
||||
+1
-2
@@ -2,7 +2,6 @@ package main
|
||||
|
||||
import (
|
||||
. "code.hoteas.com/golang/hotime"
|
||||
"code.hoteas.com/golang/hotime/example/app"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -13,6 +12,6 @@ func main() {
|
||||
return isFinished
|
||||
})
|
||||
|
||||
appIns.Run(Router{"app": app.AppProj})
|
||||
appIns.Run(Router{})
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user