main.go
3.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package main
import (
"encoding/json"
"github.com/aarongao/tools"
"github.com/gin-gonic/gin"
"gopkg.in/mgo.v2"
"gopkg.in/mgo.v2/bson"
"letu/Api"
"letu/Config"
"letu/DB"
"letu/Lib/Cache"
"letu/Lib/DelayMessage"
"os"
"time"
)
// @APIVersion 1.0.0
// @APITitle 乐游图后端接口文档
// @BasePath https://letu.api.imagchina.com
func main() {
// 读取配置文件
dir, _ := os.Getwd()
//println(dir)
file, _ := os.Open(dir + "/Config/config.json")
defer file.Close()
decoder := json.NewDecoder(file)
conf := Config.Config{}
err := decoder.Decode(&conf)
tools.CheckError(err)
// 连接数据库
DB.DBSession, err = mgo.Dial(conf.DbPath)
defer DB.DBSession.Close()
// 连接redis
DB.Redis = Cache.NewRedis(&Cache.RedisOpts{
conf.RedisPath,
"",
0,
20,
20,
0,
})
//设置模式
DB.DBSession.SetMode(mgo.Monotonic, true)
//获取文档集
DB.DB = DB.DBSession.DB(conf.DbName)
DB.DB.Login(conf.DbUser, conf.DbPassword)
DB.CItem = DB.DB.C("Item")
DB.CComplaint = DB.DB.C("Complaint")
DB.CInvestigation = DB.DB.C("Investigation")
DB.CMember = DB.DB.C("Member")
DB.CCommodity = DB.DB.C("Commodity")
DB.CTags = DB.DB.C("Tags")
DB.CScenic = DB.DB.C("Scenic")
DB.CLine = DB.DB.C("Line")
DB.CUserLog = DB.DB.C("UserLog")
DB.CSystemLog = DB.DB.C("SystemLog")
DB.CInvestigation = DB.DB.C("Investigation")
DB.CTrajectory = DB.DB.C("Trajectory")
DB.CIcons = DB.DB.C("Icons")
DelayMessage.CDelayMessage = DB.DB.C("DelayMessage")
DelayMessage.CDelayErrorLog = DB.DB.C("DelayErrorLog")
// 设置接口地址
//controllers := LeYouTu.Controllers{}
//controllers.SetLayout(Api.Layout)
r := gin.Default()
//r.Static("/.well-known", "./.well-known/")
r.GET("/AllItems", Api.AllItems)
r.GET("/AllItemTime", Api.AllItemTime)
r.GET("/AllCommodity", Api.AllCommodity)
r.GET("/AllLine", Api.AllLine)
r.GET("/ItemInfo", Api.ItemInfo)
r.GET("/CommodityInfo", Api.CommodityInfo)
r.POST("/CreateComplaint", Api.CreateComplaint)
r.GET("/AllComplaint", Api.AllComplaint)
//r.POST("/CreateUser", Api.CreateUser)
r.POST("/LoginUser", Api.LoginUser)
r.POST("/UpdateUser", Api.UpdateUser)
r.GET("/UserInfo", Api.UserInfo)
r.GET("/ScenicInfo", Api.ScenicInfo)
r.GET("/LineInfo", Api.LineInfo)
r.GET("/AllTag", Api.AllTag)
r.GET("/AllTagGroup", Api.AllTagGroup)
r.POST("/Tag/Create", Api.CreateTag)
r.POST("/Tag/Remove", Api.RemoveTag)
r.POST("/Upload", Api.Upload)
r.POST("/UpdateItem", Api.UpdateItem)
r.POST("/UpdateCommodity", Api.UpdateCommodity)
r.POST("/UpdateLine", Api.UpdateLine)
r.POST("/UpdateScenic", Api.UpdateScenic)
r.POST("/UpdateItemTime", Api.UpdateItemTime)
r.GET("/AllScenic", Api.AllScenic)
r.POST("/UserLog", Api.UserLog)
r.POST("/Sms/Send", Api.Send)
r.POST("/Investigation/Save", Api.SaveInvestigation)
r.GET("/Investigation/List", Api.AllInvestigation)
r.POST("/Trajectory/Save", Api.SaveTrajectory)
r.POST("/DealyMessage/Create", Api.CreateDealyMessage)
r.GET("/DealyMessage/Info", Api.DealyMessageInfo)
r.POST("/DealyMessage/Remove", Api.RemoveDealyMessage)
r.POST("/Icon/Update", Api.UpdateIcon)
r.GET("/Icon/All", Api.AllIcons)
r.GET("/Icon/Info", Api.IconInfo)
r.POST("/CheckToken", Api.CheckToken)
r.GET("/Tiles", Api.Tiles)
//r.GET("/ws", Api.WsPage)
r.Static("/Upload", "./Upload")
r.Static("/Console", "./Console")
r.Static("/Policy", dir+"/Policy")
r.Static("/tiles2", dir+"/tiles")
// go Ws.Manager.Start()
// 创建延迟消息
DelayMessage.GlobalDM = DelayMessage.NewDelayMessage()
go func() {
DelayMessage.GlobalDM.Start()
}()
// -初始化数据
var aMessage []DelayMessage.Message
DelayMessage.CDelayMessage.Find(bson.M{}).All(&aMessage)
nowTimeU := time.Now().Unix()
for i := 0; i < len(aMessage); i++ {
iDelayTIme := aMessage[i].DelayTime - nowTimeU
if iDelayTIme < 0 {
iDelayTIme = 1
}
DelayMessage.GlobalDM.AddTask(time.Now().Add(time.Second*time.Duration(iDelayTIme)), DelayMessage.Callback, &aMessage[i])
}
println("增加", len(aMessage), "条提醒任务")
r.Run(":8080")
}