forked from cookieY/Yearning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyearning.go
77 lines (70 loc) · 2.07 KB
/
yearning.go
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
// Copyright 2019 HenryYee.
//
// Licensed under the AGPL, Version 3.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.gnu.org/licenses/agpl-3.0.en.html
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.
package service
import (
"Yearning-go/src/lib"
"Yearning-go/src/model"
_ "Yearning-go/src/model"
"Yearning-go/src/router"
"embed"
"encoding/json"
"fmt"
"github.com/cookieY/yee"
"github.com/cookieY/yee/logger"
"github.com/cookieY/yee/middleware"
"github.com/robfig/cron/v3"
"net/http"
)
//go:embed dist/*
var f embed.FS
//go:embed dist/index.html
var html string
func cronTabMaskQuery() {
crontab := cron.New()
if _, err := crontab.AddFunc("* * * * *", func() {
var queryOrder []model.CoreQueryOrder
model.DB().Model(model.CoreQueryOrder{}).Where("`status` =?", 2).Find(&queryOrder)
for _, i := range queryOrder {
if lib.TimeDifference(i.ApprovalTime) {
model.DB().Model(model.CoreQueryOrder{}).Where("work_id =?", i.WorkId).Updates(&model.CoreQueryOrder{Status: 3})
}
}
}); err != nil {
logger.DefaultLogger.Error(err)
}
crontab.Start()
}
func StartYearning(port string, host string) {
go cronTabMaskQuery()
model.DB().First(&model.GloPer)
model.Host = host
_ = json.Unmarshal(model.GloPer.Message, &model.GloMessage)
_ = json.Unmarshal(model.GloPer.Ldap, &model.GloLdap)
_ = json.Unmarshal(model.GloPer.Other, &model.GloOther)
_ = json.Unmarshal(model.GloPer.AuditRole, &model.GloRole)
e := yee.New()
e.Pack("/front", f, "dist")
e.Use(middleware.Cors())
e.Use(middleware.Logger())
e.Use(middleware.Secure())
e.Use(middleware.Recovery())
e.Use(middleware.GzipWithConfig(middleware.GzipConfig{
Level: 9,
}))
e.SetLogLevel(2)
e.GET("/", func(c yee.Context) error {
return c.HTML(http.StatusOK, html)
})
router.AddRouter(e)
e.Run(fmt.Sprintf("%s", port))
}