2017-08-17 02:37:00 +00:00
|
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
2022-03-13 09:02:19 +00:00
|
|
|
|
. "code.hoteas.com/golang/hotime"
|
2022-03-26 08:53:40 +00:00
|
|
|
|
. "code.hoteas.com/golang/hotime/common"
|
2022-03-14 08:48:19 +00:00
|
|
|
|
"code.hoteas.com/golang/hotime/example/app"
|
2022-03-26 08:53:40 +00:00
|
|
|
|
"strings"
|
2022-03-14 08:48:19 +00:00
|
|
|
|
|
2022-03-12 21:06:28 +00:00
|
|
|
|
//. "code.hoteas.com/golang/hotime/common"
|
2017-09-05 03:09:13 +00:00
|
|
|
|
"fmt"
|
2018-04-08 16:02:13 +00:00
|
|
|
|
"time"
|
2017-08-17 02:37:00 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func main() {
|
2021-09-15 20:33:10 +00:00
|
|
|
|
date, _ := time.Parse("2006-01-02 15:04", time.Now().Format("2006-01-02")+" 14:00")
|
|
|
|
|
fmt.Println(date, date.Unix())
|
2021-10-26 16:27:24 +00:00
|
|
|
|
//fmt.Println("0123456"[1:7])
|
2022-03-13 09:02:19 +00:00
|
|
|
|
appIns := Init("config/config.json")
|
2022-03-12 21:06:28 +00:00
|
|
|
|
//a:=Map{}
|
|
|
|
|
//a.GetBool()
|
2022-03-13 09:02:19 +00:00
|
|
|
|
appIns.SetConnectListener(func(that *Context) (isFinished bool) {
|
2022-03-16 01:58:24 +00:00
|
|
|
|
//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
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2022-03-26 08:53:40 +00:00
|
|
|
|
|
2022-03-27 17:14:09 +00:00
|
|
|
|
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
|
2022-03-26 08:53:40 +00:00
|
|
|
|
|
|
|
|
|
}
|
2022-03-27 17:14:09 +00:00
|
|
|
|
if zoneId != 0 {
|
|
|
|
|
cdata["zone_id"] = zoneId
|
2022-03-26 08:53:40 +00:00
|
|
|
|
}
|
2022-03-27 17:14:09 +00:00
|
|
|
|
if channelId != 0 {
|
|
|
|
|
cdata["channel_id"] = channelId
|
2022-03-26 08:53:40 +00:00
|
|
|
|
}
|
2022-03-27 17:14:09 +00:00
|
|
|
|
that.Db.Update("company", cdata, Map{"id": companyId})
|
2022-03-26 08:53:40 +00:00
|
|
|
|
}
|
2022-03-27 17:14:09 +00:00
|
|
|
|
projD := Map{}
|
|
|
|
|
if categoryId != 0 {
|
|
|
|
|
category := that.Db.Get("category", "*", Map{"id": categoryId})
|
|
|
|
|
projD["name"] = category.GetString("name")
|
2022-03-26 08:53:40 +00:00
|
|
|
|
|
|
|
|
|
}
|
2022-03-27 17:14:09 +00:00
|
|
|
|
if companyId != 0 {
|
|
|
|
|
company := that.Db.Get("company", "*", Map{"id": companyId})
|
|
|
|
|
projD["level"] = company.GetString("level")
|
2022-03-26 08:53:40 +00:00
|
|
|
|
|
|
|
|
|
}
|
2022-03-27 17:14:09 +00:00
|
|
|
|
if len(projD) != 0 {
|
2022-03-26 08:53:40 +00:00
|
|
|
|
|
2022-03-27 17:14:09 +00:00
|
|
|
|
that.Db.Update("proj", projD, Map{"id": projId})
|
2022-03-26 08:53:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2022-03-27 20:52:10 +00:00
|
|
|
|
//查询详情插入
|
|
|
|
|
if that.HandlerStr == "/app/task_admin/time" && that.Req.Method == "GET" {
|
|
|
|
|
adminId := that.Session("admin_id").ToCeilInt()
|
2022-03-28 21:31:02 +00:00
|
|
|
|
loc, _ := time.LoadLocation("Asia/Shanghai")
|
|
|
|
|
todayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", time.Now().Format("2006-01-02")+" 00:00:00", loc)
|
2022-03-27 20:52:10 +00:00
|
|
|
|
|
2022-03-28 21:31:02 +00:00
|
|
|
|
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"))
|
2022-03-27 20:52:10 +00:00
|
|
|
|
//如果当天还未签到
|
2022-03-26 08:53:40 +00:00
|
|
|
|
|
2022-03-27 20:52:10 +00:00
|
|
|
|
that.Display(0, taskAdmin)
|
|
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
}
|
2022-03-26 08:53:40 +00:00
|
|
|
|
//查询列表插入
|
2022-03-27 17:14:09 +00:00
|
|
|
|
if that.HandlerStr == "/app/task_admin" && that.Req.Method == "GET" {
|
2022-03-28 21:31:02 +00:00
|
|
|
|
if that.Req.FormValue("admin_id") == "" {
|
|
|
|
|
|
|
|
|
|
that.Req.Form.Set("admin_id", that.Session("admin_id").ToStr())
|
|
|
|
|
}
|
2022-03-27 17:14:09 +00:00
|
|
|
|
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)
|
2022-03-26 08:53:40 +00:00
|
|
|
|
v["task"] = that.Db.Get("task", "*", Map{"id": v.GetCeilInt("task_id")})
|
|
|
|
|
}
|
2022-03-27 17:14:09 +00:00
|
|
|
|
that.RespData["result"] = Map{"count": that.RespData.GetMap("result").GetCeilInt("count"), "data": taskAdmin}
|
2022-03-26 08:53:40 +00:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//查询详情插入
|
2022-03-27 17:14:09 +00:00
|
|
|
|
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")
|
2022-03-26 08:53:40 +00:00
|
|
|
|
|
|
|
|
|
taskAdmin["task"] = that.Db.Get("task", "*", Map{"id": taskAdmin.GetCeilInt("task_id")})
|
|
|
|
|
|
2022-03-27 17:14:09 +00:00
|
|
|
|
taskAdmin["admins"] = that.Db.Select("task", Map{"[><]admin": "admin.id=task.admin_id"}, "*", Map{"task_id": taskAdmin.GetCeilInt("task_id"), "ORDER": "modify_time DESC"})
|
2022-03-26 08:53:40 +00:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//编辑详情插入
|
2022-03-27 17:14:09 +00:00
|
|
|
|
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})
|
2022-03-26 08:53:40 +00:00
|
|
|
|
|
2022-03-27 17:14:09 +00:00
|
|
|
|
taskAdminStatus := taskAdmin.GetCeilInt64("status")
|
2022-03-26 08:53:40 +00:00
|
|
|
|
|
2022-03-27 17:14:09 +00:00
|
|
|
|
that.Log["task_id"] = taskAdmin.GetCeilInt("task_id")
|
|
|
|
|
that.Log["type"] = 4
|
2022-03-26 08:53:40 +00:00
|
|
|
|
|
|
|
|
|
//执行者,状态为1,部分执行,不能审批状态
|
2022-03-27 17:14:09 +00:00
|
|
|
|
if taskAdminStatus == 1 {
|
2022-03-26 08:53:40 +00:00
|
|
|
|
|
2022-03-27 17:14:09 +00:00
|
|
|
|
that.Log["name"] = "执行"
|
2022-03-26 08:53:40 +00:00
|
|
|
|
|
2022-03-27 17:14:09 +00:00
|
|
|
|
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
|
2022-03-26 08:53:40 +00:00
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//全部执行完成,则变更任务为待审批,同时将所有审批者权限设置为待审批,没有执行完成则全部变部分执行完成,审批者不操作
|
2022-03-27 17:14:09 +00:00
|
|
|
|
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")})
|
2022-03-26 08:53:40 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//审批者,状态为2,已完成执行,部分审批,或全部审批状态
|
2022-03-27 17:14:09 +00:00
|
|
|
|
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
|
2022-03-26 08:53:40 +00:00
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//全部审批完成,则变更任务为已审批,同时将所有审批者权限设置为待审批,没有执行完成则全部变部分执行完成,审批者不操作
|
2022-03-27 17:14:09 +00:00
|
|
|
|
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")})
|
2022-03-26 08:53:40 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//审批者,状态为3,驳回状态,则将所有人状态都设置为驳回状态
|
2022-03-27 17:14:09 +00:00
|
|
|
|
if taskAdminStatus == 3 {
|
2022-03-26 08:53:40 +00:00
|
|
|
|
|
2022-03-27 17:14:09 +00:00
|
|
|
|
that.Log["name"] = "驳回"
|
2022-03-26 08:53:40 +00:00
|
|
|
|
|
2022-03-27 17:14:09 +00:00
|
|
|
|
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")})
|
2022-03-26 08:53:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-27 17:14:09 +00:00
|
|
|
|
if that.HandlerStr == "/app/task" && that.Req.Method == "POST" {
|
|
|
|
|
that.RespFunc = func() {
|
|
|
|
|
if that.RespData["status"] != nil && that.RespData.GetCeilInt64("status") == 0 {
|
2022-03-26 08:53:40 +00:00
|
|
|
|
executorData := ObjToMap(that.Req.FormValue("executor_data"))
|
|
|
|
|
approverData := ObjToMap(that.Req.FormValue("approver_data"))
|
|
|
|
|
readerData := ObjToMap(that.Req.FormValue("reader_data"))
|
2022-03-27 17:14:09 +00:00
|
|
|
|
taskId := that.RespData.GetCeilInt("result")
|
2022-03-27 20:52:10 +00:00
|
|
|
|
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})
|
2022-03-27 17:14:09 +00:00
|
|
|
|
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 {
|
2022-03-26 08:53:40 +00:00
|
|
|
|
continue
|
|
|
|
|
}
|
2022-03-27 17:14:09 +00:00
|
|
|
|
task["admin_id"] = admin.GetCeilInt64("id")
|
|
|
|
|
adminMap[task.GetString("admin_id")] = task["admin_id"]
|
2022-03-26 08:53:40 +00:00
|
|
|
|
|
2022-03-27 17:14:09 +00:00
|
|
|
|
task["role"] = 1
|
|
|
|
|
that.Db.Insert("task_admin", task)
|
2022-03-26 08:53:40 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-27 17:14:09 +00:00
|
|
|
|
if executorData != nil {
|
|
|
|
|
admins := executorData.GetMap("admin")
|
|
|
|
|
for k, _ := range admins {
|
|
|
|
|
admin := admins.GetMap(k)
|
|
|
|
|
if admin == nil {
|
2022-03-26 08:53:40 +00:00
|
|
|
|
continue
|
|
|
|
|
}
|
2022-03-27 17:14:09 +00:00
|
|
|
|
task["admin_id"] = admin.GetCeilInt64("id")
|
2022-03-26 08:53:40 +00:00
|
|
|
|
//转换为执行&审批者
|
2022-03-27 17:14:09 +00:00
|
|
|
|
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}})
|
2022-03-26 08:53:40 +00:00
|
|
|
|
|
2022-03-27 17:14:09 +00:00
|
|
|
|
} else {
|
2022-03-26 08:53:40 +00:00
|
|
|
|
|
2022-03-27 17:14:09 +00:00
|
|
|
|
adminMap[task.GetString("admin_id")] = task["admin_id"]
|
|
|
|
|
task["role"] = 0
|
|
|
|
|
that.Db.Insert("task_admin", task)
|
2022-03-26 08:53:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-27 17:14:09 +00:00
|
|
|
|
if readerData != nil {
|
2022-03-26 08:53:40 +00:00
|
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-27 17:14:09 +00:00
|
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-26 08:53:40 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-13 09:02:19 +00:00
|
|
|
|
return isFinished
|
|
|
|
|
})
|
|
|
|
|
//appIns.Db.Action(func(db db.HoTimeDB) (isSuccess bool) {
|
|
|
|
|
// return isSuccess
|
|
|
|
|
//})
|
2022-03-14 08:48:19 +00:00
|
|
|
|
appIns.Run(Router{
|
|
|
|
|
"app": app.Project,
|
|
|
|
|
})
|
2017-08-17 02:37:00 +00:00
|
|
|
|
}
|