mirror of
https://github.com/ZSCNetSupportDept/scheduler.git
synced 2025-10-28 12:35:03 +08:00
改善
This commit is contained in:
13
config.yaml
13
config.yaml
@@ -1,9 +1,16 @@
|
|||||||
# This is a example file for the system
|
# This is a example file for the system
|
||||||
ListenPort: 25005
|
ListenPort: 25005
|
||||||
File: "member.csv"
|
|
||||||
DB:
|
DB:
|
||||||
Path: "scheduler.db"
|
Type: "SQLite"
|
||||||
|
Path: "" # not need if use SQLite
|
||||||
Port: "" # not need if use SQLite
|
Port: "" # not need if use SQLite
|
||||||
User: "" # not need if use SQLite
|
User: "" # not need if use SQLite
|
||||||
Password: "" # not need if use SQLite
|
Password: "" # not need if use SQLite
|
||||||
Type: "SQLite"
|
Name: "" # not need if use SQLite
|
||||||
|
|
||||||
|
[business]
|
||||||
|
Session: "2024-2025" #学年
|
||||||
|
Semester: 1 #学期,1 或 2
|
||||||
|
StartTime: "2024-9-14" #开始值班的日期
|
||||||
|
Week: 15 #准备值班多少周
|
||||||
|
File: "member.csv" #成员信息文件的路径,看文档
|
||||||
|
|||||||
@@ -7,42 +7,79 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func Load() {
|
func Load() {
|
||||||
|
// where to read config
|
||||||
viper.SetConfigName("config")
|
viper.SetConfigName("config")
|
||||||
viper.SetConfigType("yaml")
|
viper.SetConfigType("yaml")
|
||||||
viper.AddConfigPath(".")
|
viper.AddConfigPath(".")
|
||||||
|
|
||||||
if err := viper.ReadInConfig(); err != nil {
|
readconfig()
|
||||||
fmt.Printf("Error reading config file: %v\n", err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
ListenPort = viper.GetInt("ListenPort")
|
check()
|
||||||
File = viper.GetString("File")
|
|
||||||
DB.Path = viper.GetString("DB.Path")
|
|
||||||
//DB.Port = viper.GetString("DB.Port")
|
|
||||||
DB.Type = viper.GetString("DB.Type")
|
|
||||||
|
|
||||||
err := check()
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("check your config!")
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
debugprint()
|
debugprint()
|
||||||
|
|
||||||
|
if len(os.Args) != 1 {
|
||||||
|
handleArguments()
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func check() error {
|
func check() {
|
||||||
|
// 暂时只支持SQLite
|
||||||
return nil
|
if DB.Type != "SQLite" {
|
||||||
|
fmt.Println("sorry,we support SQLite only so far(At config/config.go : check())")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
func debugprint() {
|
func debugprint() {
|
||||||
|
|
||||||
fmt.Printf("ListenPort=%v\n", ListenPort)
|
fmt.Printf("ListenPort=%v\n", ListenPort)
|
||||||
fmt.Printf("File=%v\n", File)
|
|
||||||
fmt.Printf("database path : %s\n", DB.Path)
|
|
||||||
fmt.Printf("database type:%s\n", DB.Type)
|
fmt.Printf("database type:%s\n", DB.Type)
|
||||||
|
fmt.Printf("database path : %s\n", DB.Path)
|
||||||
|
fmt.Printf("database port:%d\n", DB.Port)
|
||||||
|
fmt.Printf("database user:%s\n", DB.User)
|
||||||
|
fmt.Printf("database passowrd:%s\n", DB.Password)
|
||||||
|
fmt.Printf("database name:%s\n", DB.Name)
|
||||||
|
fmt.Printf("session:%s\n", Session)
|
||||||
|
fmt.Printf("semester:%d\n", Semester)
|
||||||
|
fmt.Printf("start time:%s\n", StartTime)
|
||||||
|
fmt.Printf("week:%d\n", Week)
|
||||||
|
fmt.Printf("File=%v\n", File)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func handleArguments() {
|
||||||
|
if len(os.Args) > 2 {
|
||||||
|
fmt.Println("Please enter only 1 argument")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
switch os.Args[1] {
|
||||||
|
case "newsemester":
|
||||||
|
if DB.Type == "SQLite" {
|
||||||
|
sqliteNewSemester()
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
panic("invalid argument")
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func readconfig() {
|
||||||
|
if err := viper.ReadInConfig(); err != nil {
|
||||||
|
fmt.Printf("Error reading config file: %v\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
ListenPort = viper.GetInt("ListenPort")
|
||||||
|
DB.Type = viper.GetString("DB.Type")
|
||||||
|
DB.Path = viper.GetString("DB.Path")
|
||||||
|
DB.Port = viper.GetInt("DB.Port")
|
||||||
|
DB.User = viper.GetString("DB.User")
|
||||||
|
DB.Password = viper.GetString("DB.Password")
|
||||||
|
DB.Name = viper.GetString("DB.Name")
|
||||||
|
Session = viper.GetString("Session")
|
||||||
|
Semester = viper.GetInt("Semester")
|
||||||
|
StartTime = viper.GetString("StartTime")
|
||||||
|
Week = viper.GetInt("Week")
|
||||||
|
File = viper.GetString("File")
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,16 +2,19 @@ package config
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
ListenPort int
|
ListenPort int
|
||||||
File string
|
|
||||||
DB database
|
DB database
|
||||||
|
Session string
|
||||||
|
Semester int
|
||||||
|
StartTime string
|
||||||
|
Week int
|
||||||
|
File string
|
||||||
)
|
)
|
||||||
|
|
||||||
type database struct {
|
type database struct {
|
||||||
Path string
|
Type string
|
||||||
//Port string
|
Path string
|
||||||
//User string
|
Port int
|
||||||
//Password string
|
User string
|
||||||
|
Password string
|
||||||
// enable if you want use an instance other than SQLite
|
Name string
|
||||||
Type string
|
|
||||||
}
|
}
|
||||||
|
|||||||
5
config/newsemester.go
Normal file
5
config/newsemester.go
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
func sqliteNewSemester() {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -2,9 +2,11 @@ package config
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
|
"github.com/labstack/echo/v4/middleware"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Route(app *echo.Echo) {
|
func Route(app *echo.Echo) {
|
||||||
// here is the route for our site
|
// here is the route for our site
|
||||||
app.File("/", "FrontEnd/index.html")
|
staticFiles := app.Group("/")
|
||||||
|
staticFiles.Use(middleware.Static("./FrontEnd"))
|
||||||
}
|
}
|
||||||
|
|||||||
4
doc/member.csv
Normal file
4
doc/member.csv
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
姓名,工号,性别,权限,有空
|
||||||
|
管理层,2200,0,1,0
|
||||||
|
正式老登,2300,1,4,6
|
||||||
|
实习萌新,2400,0,5,5
|
||||||
|
15
doc/member_csv文件说明.md
Normal file
15
doc/member_csv文件说明.md
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
# 说明
|
||||||
|
姓名:填写成员的姓名(string)
|
||||||
|
工号:填写成员的工号(string)
|
||||||
|
性别:填写成员的性别(bool),1是男生
|
||||||
|
权限:成员的权限(int),参考报修系统的权限枚举:
|
||||||
|
- 0:开发组
|
||||||
|
- 1:科长
|
||||||
|
- 2:api
|
||||||
|
- 3:组长
|
||||||
|
- 4.正式成员
|
||||||
|
- 5:实习成员
|
||||||
|
- 6:退休成员(或其他不应授权的成员
|
||||||
|
有空:填写成员在那哪一天值班(int),0表示成员不值班,1-7是星期几
|
||||||
|
## 用处
|
||||||
|
系统需要依据这个文件生成值班表
|
||||||
Reference in New Issue
Block a user