diff --git a/application.go b/application.go index c87b3f6..eb78c4e 100644 --- a/application.go +++ b/application.go @@ -530,7 +530,7 @@ func (that *Application) crossDomain(context *Context, sessionId string) { } //Init 初始化application -func Init(config string) Application { +func Init(config string) *Application { appIns := Application{} //手动模式, appIns.SetConfig(config) @@ -580,7 +580,7 @@ func Init(config string) Application { } - return appIns + return &appIns } // SetDB 智能数据库设置 diff --git a/example/config/appRule.json b/example/config/appRule.json deleted file mode 100644 index 8ccf500..0000000 --- a/example/config/appRule.json +++ /dev/null @@ -1,344 +0,0 @@ -[ - { - "edit": true, - "info": true, - "list": false, - "must": false, - "name": "idcard", - "strict": false, - "type": "" - }, - { - "edit": false, - "info": true, - "list": true, - "must": false, - "name": "id", - "strict": true, - "type": "" - }, - { - "edit": true, - "info": true, - "list": true, - "must": false, - "name": "parent_id", - "strict": true, - "type": "" - }, - { - "edit": true, - "info": true, - "list": true, - "must": false, - "name": "status", - "strict": false, - "type": "select" - }, - { - "edit": true, - "info": true, - "list": true, - "must": false, - "name": "state", - "strict": false, - "type": "select" - }, - { - "edit": true, - "info": true, - "list": true, - "must": false, - "name": "sex", - "strict": false, - "type": "select" - }, - { - "edit": false, - "info": false, - "list": false, - "must": false, - "name": "delete", - "strict": false, - "type": "" - }, - { - "edit": true, - "info": true, - "list": false, - "must": false, - "name": "lat", - "strict": false, - "type": "" - }, - { - "edit": true, - "info": true, - "list": false, - "must": false, - "name": "lng", - "strict": false, - "type": "" - }, - { - "edit": true, - "info": true, - "list": false, - "must": false, - "name": "latitude", - "strict": false, - "type": "" - }, - { - "edit": true, - "info": true, - "list": false, - "must": false, - "name": "longitude", - "strict": false, - "type": "" - }, - { - "edit": false, - "info": false, - "list": false, - "must": false, - "name": "index", - "strict": false, - "type": "index" - }, - { - "edit": true, - "info": false, - "list": false, - "must": false, - "name": "password", - "strict": false, - "type": "password" - }, - { - "edit": true, - "info": false, - "list": false, - "must": false, - "name": "pwd", - "strict": false, - "type": "password" - }, - { - "edit": true, - "info": true, - "list": false, - "must": false, - "name": "info", - "strict": false, - "type": "" - }, - { - "edit": false, - "info": false, - "list": false, - "must": false, - "name": "version", - "strict": false, - "type": "" - }, - { - "edit": true, - "info": true, - "list": false, - "must": false, - "name": "seq", - "strict": false, - "type": "" - }, - { - "edit": true, - "info": true, - "list": false, - "must": false, - "name": "sort", - "strict": false, - "type": "" - }, - { - "edit": true, - "info": true, - "list": false, - "must": false, - "name": "note", - "strict": false, - "type": "" - }, - { - "edit": true, - "info": true, - "list": false, - "must": false, - "name": "description", - "strict": false, - "type": "" - }, - { - "edit": true, - "info": true, - "list": false, - "must": false, - "name": "abstract", - "strict": false, - "type": "" - }, - { - "edit": true, - "info": true, - "list": false, - "must": false, - "name": "content", - "strict": false, - "type": "" - }, - { - "edit": true, - "info": true, - "list": true, - "must": false, - "name": "address", - "strict": false, - "type": "" - }, - { - "edit": true, - "info": true, - "list": false, - "must": false, - "name": "full_name", - "strict": false, - "type": "" - }, - { - "edit": false, - "info": true, - "list": false, - "must": false, - "name": "create_time", - "strict": true, - "type": "time" - }, - { - "edit": false, - "info": true, - "list": true, - "must": false, - "name": "modify_time", - "strict": true, - "type": "time" - }, - { - "edit": true, - "info": true, - "list": false, - "must": false, - "name": "image", - "strict": false, - "type": "image" - }, - { - "edit": true, - "info": true, - "list": false, - "must": false, - "name": "img", - "strict": false, - "type": "image" - }, - { - "edit": true, - "info": true, - "list": false, - "must": false, - "name": "icon", - "strict": false, - "type": "image" - }, - { - "edit": true, - "info": true, - "list": false, - "must": false, - "name": "avatar", - "strict": false, - "type": "image" - }, - { - "edit": true, - "info": true, - "list": false, - "must": false, - "name": "file", - "strict": false, - "type": "file" - }, - { - "edit": true, - "info": true, - "list": false, - "must": false, - "name": "age", - "strict": false, - "type": "" - }, - { - "edit": true, - "info": true, - "list": false, - "must": false, - "name": "email", - "strict": false, - "type": "" - }, - { - "edit": true, - "info": true, - "list": true, - "must": false, - "name": "time", - "strict": false, - "type": "time" - }, - { - "edit": false, - "info": true, - "list": false, - "must": false, - "name": "level", - "strict": false, - "type": "" - }, - { - "edit": true, - "info": true, - "list": true, - "must": false, - "name": "rule", - "strict": false, - "type": "form" - }, - { - "edit": false, - "info": true, - "list": true, - "must": false, - "name": "table", - "strict": false, - "type": "table" - }, - { - "edit": false, - "info": true, - "list": true, - "must": false, - "name": "table_id", - "strict": false, - "type": "table_id" - } -] \ No newline at end of file diff --git a/example/config/config.json b/example/config/config.json index 0dbeca9..c533655 100644 --- a/example/config/config.json +++ b/example/config/config.json @@ -15,24 +15,16 @@ { "config": "config/admin.json", "mode": 0, - "name": "", "rule": "config/adminRule.json", "table": "admin" - }, - { - "config": "config/app.json", - "mode": 0, - "name": "app", - "rule": "config/appRule.json", - "table": "admin" } ], "crossDomain": "", "db": { "mysql": { - "host": "192.168.6.253", - "name": "rfcb", - "password": "dasda8454456", + "host": "192.168.2.50", + "name": "zct_v2", + "password": "kct@2021", "port": "3306", "prefix": "", "user": "root" diff --git a/example/config/data.zip b/example/config/data.zip deleted file mode 100644 index 474ed17..0000000 Binary files a/example/config/data.zip and /dev/null differ diff --git a/example/main.go b/example/main.go index 08b9fe3..7b32d83 100644 --- a/example/main.go +++ b/example/main.go @@ -2,11 +2,6 @@ package main import ( . "code.hoteas.com/golang/hotime" - . "code.hoteas.com/golang/hotime/common" - "code.hoteas.com/golang/hotime/example/app" - "strings" - - //. "code.hoteas.com/golang/hotime/common" "fmt" "time" ) @@ -18,300 +13,14 @@ func main() { appIns := Init("config/config.json") //a:=Map{} //a.GetBool() - appIns.SetConnectListener(func(that *Context) (isFinished bool) { - //that.Session("admin_id", 1) - if len(that.RouterString) == 3 { - if that.HandlerStr == "/app/hotime/test" { - that.Session("admin_id", 1) - that.Display(0, that.SessionId) - return true - } - - if that.RouterString[1] == "wechat" || that.RouterString[1] == "websocket" { - if appIns.MethodRouter[that.HandlerStr] != nil { - appIns.MethodRouter[that.HandlerStr](that) - return true - } - } - - } - - if len(that.RouterString) == 2 { - if that.HandlerStr == "/app/proj" && that.Req.Method == "POST" { - that.RespFunc = func() { - if that.RespData["status"] != nil && that.RespData.GetCeilInt64("status") == 0 { - companyId := ObjToInt(that.Req.FormValue("company_id")) - userId := ObjToInt(that.Req.FormValue("user_id")) - zoneId := ObjToInt(that.Req.FormValue("zone_id")) - channelId := ObjToInt(that.Req.FormValue("channel_id")) - categoryId := ObjToInt(that.Req.FormValue("category_id")) - projId := that.RespData.GetCeilInt("result") - if companyId != 0 { - - cdata := Map{"proj_id": projId} - if userId != 0 { - cdata["user_id"] = userId - - } - if zoneId != 0 { - cdata["zone_id"] = zoneId - } - if channelId != 0 { - cdata["channel_id"] = channelId - } - that.Db.Update("company", cdata, Map{"id": companyId}) - } - projD := Map{} - if categoryId != 0 { - category := that.Db.Get("category", "*", Map{"id": categoryId}) - projD["name"] = category.GetString("name") - - } - if companyId != 0 { - company := that.Db.Get("company", "*", Map{"id": companyId}) - projD["level"] = company.GetString("level") - - } - if len(projD) != 0 { - - that.Db.Update("proj", projD, Map{"id": projId}) - } - - } - } - } - - } - //查询详情插入 - if that.HandlerStr == "/app/task_admin/time" && that.Req.Method == "GET" { - adminId := that.Session("admin_id").ToCeilInt() - loc, _ := time.LoadLocation("Asia/Shanghai") - todayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", time.Now().Format("2006-01-02")+" 00:00:00", loc) - - taskAdmin := that.Db.Get("task_admin", "*", Map{"AND": Map{"admin_id": adminId, "create_time[>]": todayTime.Unix(), "type": Slice{13, 15, 2}}, "ORDER": "create_time DESC"}) - fmt.Println(todayTime.Format("2006-01-02 15:04:05")) - //如果当天还未签到 - - that.Display(0, taskAdmin) - - return true - } - //查询列表插入 - if that.HandlerStr == "/app/task_admin" && that.Req.Method == "GET" { - if that.Req.FormValue("admin_id") == "" { - - that.Req.Form.Set("admin_id", that.Session("admin_id").ToStr()) - } - that.RespFunc = func() { - if that.RespData["status"] != nil && that.RespData.GetCeilInt64("status") == 0 { - taskAdmin := that.RespData.GetMap("result").GetSlice("data") - for k, _ := range taskAdmin { - v := taskAdmin.GetMap(k) - v["task"] = that.Db.Get("task", "*", Map{"id": v.GetCeilInt("task_id")}) - } - that.RespData["result"] = Map{"count": that.RespData.GetMap("result").GetCeilInt("count"), "data": taskAdmin} - - } - } - } - //查询详情插入 - if len(that.RouterString) == 3 && strings.Contains(that.HandlerStr, "/app/task_admin") && that.Req.Method == "GET" { - that.RespFunc = func() { - if that.RespData["status"] != nil && that.RespData.GetCeilInt64("status") == 0 { - taskAdmin := that.RespData.GetMap("result") - - taskAdmin["task"] = that.Db.Get("task", "*", Map{"id": taskAdmin.GetCeilInt("task_id")}) - - taskAdmin["admins"] = that.Db.Select("task", Map{"[><]admin": "admin.id=task.admin_id"}, "*", Map{"task_id": taskAdmin.GetCeilInt("task_id"), "ORDER": "modify_time DESC"}) - - } - } - } - - //编辑详情插入 - if len(that.RouterString) == 3 && strings.Contains(that.HandlerStr, "/app/task_admin") && that.Req.Method == "PUT" { - that.RespFunc = func() { - if that.RespData["status"] != nil && that.RespData.GetCeilInt64("status") == 0 { - taskAdminID := that.RouterString[2] - taskAdmin := that.Db.Get("task_admin", "*", Map{"id": taskAdminID}) - - taskAdminStatus := taskAdmin.GetCeilInt64("status") - - that.Log["task_id"] = taskAdmin.GetCeilInt("task_id") - that.Log["type"] = 4 - - //执行者,状态为1,部分执行,不能审批状态 - if taskAdminStatus == 1 { - - that.Log["name"] = "执行" - - taskData := Map{} - taskAdmins := that.Db.Select("task_admin", "*", Map{"AND": Map{"task_id": taskAdmin.GetCeilInt("task_id"), "role": 0}}) - for _, v := range taskAdmins { - if v.GetCeilInt("status") != 1 { - taskData["status"] = 4 - break - } - } - //全部执行完成,则变更任务为待审批,同时将所有审批者权限设置为待审批,没有执行完成则全部变部分执行完成,审批者不操作 - if taskData.GetCeilInt("status") != 4 { - taskData["status"] = 1 - that.Db.Update("task_admin", Map{"status": 1}, Map{"AND": Map{"task_id": taskAdmin.GetCeilInt("task_id"), "role": Slice{1, 3}}}) - that.Db.Update("task", Map{"status": 1}, Map{"id": taskAdmin.GetCeilInt("task_id")}) - } else { - that.Db.Update("task", taskData, Map{"id": taskAdmin.GetCeilInt("task_id")}) - } - } - - //审批者,状态为2,已完成执行,部分审批,或全部审批状态 - if taskAdminStatus == 2 { - that.Log["name"] = "审批" - taskData := Map{} - taskAdmins := that.Db.Select("task_admin", "*", Map{"AND": Map{"task_id": taskAdmin.GetCeilInt("task_id"), "role": Slice{1, 3}}}) - for _, v := range taskAdmins { - if v.GetCeilInt("status") != 2 { - taskData["status"] = 5 - break - } - } - //全部审批完成,则变更任务为已审批,同时将所有审批者权限设置为待审批,没有执行完成则全部变部分执行完成,审批者不操作 - if taskData.GetCeilInt("status") != 5 { - taskData["status"] = 2 - that.Db.Update("task_admin", Map{"status": 2}, Map{"AND": Map{"task_id": taskAdmin.GetCeilInt("task_id")}}) - that.Db.Update("task", Map{"status": 2}, Map{"id": taskAdmin.GetCeilInt("task_id")}) - } else { - that.Db.Update("task", taskData, Map{"id": taskAdmin.GetCeilInt("task_id")}) - } - } - - //审批者,状态为3,驳回状态,则将所有人状态都设置为驳回状态 - if taskAdminStatus == 3 { - - that.Log["name"] = "驳回" - - that.Db.Update("task_admin", Map{"status": 3}, Map{"AND": Map{"task_id": taskAdmin.GetCeilInt("task_id")}}) - that.Db.Update("task", Map{"status": 3}, Map{"id": taskAdmin.GetCeilInt("task_id")}) - } - - } - } - } - - if that.HandlerStr == "/app/task" && that.Req.Method == "POST" { - that.RespFunc = func() { - if that.RespData["status"] != nil && that.RespData.GetCeilInt64("status") == 0 { - executorData := ObjToMap(that.Req.FormValue("executor_data")) - approverData := ObjToMap(that.Req.FormValue("approver_data")) - readerData := ObjToMap(that.Req.FormValue("reader_data")) - taskId := that.RespData.GetCeilInt("result") - task := that.Db.Get("task", "admin_id,name,create_time,modify_time,state,company_id,proj_id,reward,reward_money,reward_description,type,zone_id,extend_data,city_id,status,user_id,zone_id,out_tag_id,visit_tag_id,car_id,seal_tag_id,time_tag_id", Map{"id": taskId}) - task["task_id"] = taskId - - that.Log["task_id"] = taskId - - adminId := task.GetCeilInt64("admin_id") - adminMap := Map{} - if approverData != nil { - admins := approverData.GetMap("admin") - for k, _ := range admins { - admin := admins.GetMap(k) - if admin == nil { - continue - } - task["admin_id"] = admin.GetCeilInt64("id") - adminMap[task.GetString("admin_id")] = task["admin_id"] - - task["role"] = 1 - that.Db.Insert("task_admin", task) - } - } - - if executorData != nil { - admins := executorData.GetMap("admin") - for k, _ := range admins { - admin := admins.GetMap(k) - if admin == nil { - continue - } - task["admin_id"] = admin.GetCeilInt64("id") - //转换为执行&审批者 - if adminMap[task.GetString("admin_id")] != nil { - that.Db.Update("task_admin", Map{"role": 3}, Map{"AND": Map{"admin_id": task["admin_id"], "task_id": taskId}}) - - } else { - - adminMap[task.GetString("admin_id")] = task["admin_id"] - task["role"] = 0 - that.Db.Insert("task_admin", task) - } - - } - } - - if readerData != nil { - admins := readerData.GetMap("admin") - for k, _ := range admins { - admin := admins.GetMap(k) - if admin == nil { - continue - } - task["admin_id"] = admin.GetCeilInt64("id") - //已经为执行和审批者不再创建监督者 - if adminMap[task.GetString("admin_id")] == nil { - task["admin_id"] = adminId - task["role"] = 2 - that.Db.Insert("task_admin", task) - } - - } - } - - if task.GetCeilInt("type") != 0 { - - //that.Db.Update("task",Map{"status":2},Map{"id":taskId}) - - if executorData == nil { - task["admin_id"] = adminId - task["role"] = 3 - //task["status"]=2 - - that.Db.Insert("task_admin", task) - } else { - //that.Db.Update("task_admin",Map{"status":2},Map{"task_id":taskId}) - } - - admin := that.Db.Get("admin", "org_id", Map{"id": adminId}) - org := that.Db.Get("org", "index", Map{"id": admin.GetCeilInt64("org_id")}) - orgstr := strings.Split(org.GetString("index"), ",") - orgs := Slice{} - for _, v := range orgstr { - if v != "" && v != ObjToStr(admin.GetCeilInt64("org_id")) { - orgs = append(orgs, v) - } - } - if len(orgs) != 0 { - admins := that.Db.Select("admin", "id", Map{"org_id": orgs}) - - for _, v := range admins { - task["admin_id"] = v.GetCeilInt("id") - task["role"] = 2 - //task["status"]=2 - that.Db.Insert("task_admin", task) - } - } - - } - - } - } - } - - return isFinished - }) + //appIns.SetConnectListener(func(that *Context) (isFinished bool) { + // + // return isFinished + //}) //appIns.Db.Action(func(db db.HoTimeDB) (isSuccess bool) { // return isSuccess //}) appIns.Run(Router{ - "app": app.Project, + //"app": app.Project, }) } diff --git a/example/zct_manage.exe b/example/zct_manage.exe new file mode 100644 index 0000000..1306eb9 Binary files /dev/null and b/example/zct_manage.exe differ