iedc-go/example/main.go
2022-03-26 16:53:40 +08:00

268 lines
8.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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"
)
func main() {
date, _ := time.Parse("2006-01-02 15:04", time.Now().Format("2006-01-02")+" 14:00")
fmt.Println(date, date.Unix())
//fmt.Println("0123456"[1:7])
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" &&that.Req.Method == "GET"{
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",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)
}
}
}
}
}
}
return isFinished
})
//appIns.Db.Action(func(db db.HoTimeDB) (isSuccess bool) {
// return isSuccess
//})
appIns.Run(Router{
"app": app.Project,
})
}