mirror of
https://github.com/ZSCNetSupportDept/scheduler.git
synced 2025-10-28 04:25:03 +08:00
1
This commit is contained in:
17
Makefile
17
Makefile
@@ -1,8 +1,21 @@
|
||||
# 配置项
|
||||
PWD = $(shell pwd)
|
||||
|
||||
SOURCE_PATH = $(PWD)/src
|
||||
|
||||
# **构建配置项**
|
||||
|
||||
# 如果构建,将构建目标放到哪个目录下
|
||||
TARGET_PATH = $(PWD)/build/target
|
||||
# 如果安装,将程序安装到哪里
|
||||
INSTALL_PATH = /opt/scheduler
|
||||
|
||||
# 是否将前端嵌入到最终二进制文件里?
|
||||
EMBED_FRONTEND = 1
|
||||
|
||||
# **运行配置项**
|
||||
|
||||
# 如果运行,使用的配置文件在哪里?
|
||||
CONFIG_FILE_PATH = $(PWD)/ignore/secret.yaml
|
||||
# 如果运行,使用的成员信息文件在哪里?
|
||||
CSV_PATH = $(PWD)/ignore/aa.csv
|
||||
|
||||
include build/Makefile
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
.PHONY: clean help
|
||||
.PHONY: clean help run build
|
||||
|
||||
help:
|
||||
./build/Help
|
||||
@@ -6,7 +6,14 @@ help:
|
||||
clean:
|
||||
rm -rf $(TARGET_PATH)/*
|
||||
|
||||
scheduler:
|
||||
FrontEnd:
|
||||
|
||||
BackEnd: FrontEnd
|
||||
cd $(SOURCE_PATH) && go build -o $(TARGET_PATH)/scheduler
|
||||
|
||||
all: scheduler
|
||||
build: BackEnd
|
||||
|
||||
|
||||
run:
|
||||
$(TARGET_PATH)/scheduler --config $(CONFIG_FILE_PATH) --csv-path $(CSV_PATH)
|
||||
|
||||
|
||||
0
scheduler.db
Normal file
0
scheduler.db
Normal file
@@ -13,6 +13,7 @@ func Load() {
|
||||
|
||||
parseArgs()
|
||||
readconfig()
|
||||
overrides()
|
||||
fmt.Printf("%+v\n", Default)
|
||||
|
||||
carbon.SetDefault(carbon.Default{
|
||||
@@ -37,9 +38,17 @@ func readconfig() {
|
||||
|
||||
func parseArgs() {
|
||||
pflag.String("config", "./config.yaml", "the path to config file.")
|
||||
pflag.Bool("init-db", false, "whether to initialize the database,useful when migrating to a new one.")
|
||||
pflag.Bool("init-db", false, "whether to initialize the database on starting,useful when migrating to a new one.")
|
||||
pflag.String("csv-path", "./member.csv", "the CSV file containing member information")
|
||||
viper.BindPFlags(pflag.CommandLine)
|
||||
pflag.Parse()
|
||||
pathToConfigure = viper.GetString("config")
|
||||
InitDB = viper.GetBool("init-db")
|
||||
CSVPath = viper.GetString("csv-path")
|
||||
}
|
||||
|
||||
func overrides() {
|
||||
if CSVPath != "" {
|
||||
Default.App.File = CSVPath
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
package config
|
||||
|
||||
//
|
||||
// import (
|
||||
// "github.com/labstack/echo/v4"
|
||||
// "github.com/labstack/echo/v4/middleware"
|
||||
// )
|
||||
//
|
||||
// func Middleware(app *echo.Echo) {
|
||||
// //here are middlewares we use
|
||||
// app.Use(middleware.Logger())
|
||||
// app.Use(middleware.Recover())
|
||||
// }
|
||||
@@ -1,3 +1,4 @@
|
||||
// 系统配置
|
||||
package config
|
||||
|
||||
type Config struct {
|
||||
@@ -22,6 +23,7 @@ type Config struct {
|
||||
} `mapstructure:"business"`
|
||||
}
|
||||
|
||||
var pathToConfigure string
|
||||
var Default Config
|
||||
var pathToConfigure string //配置文件的路径
|
||||
var Default Config //系统的默认配置
|
||||
var InitDB bool
|
||||
var CSVPath string
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
package config
|
||||
|
||||
func sqliteNewSemester() {
|
||||
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package config
|
||||
|
||||
//
|
||||
// import (
|
||||
// "github.com/labstack/echo/v4"
|
||||
// "github.com/labstack/echo/v4/middleware"
|
||||
// "zsxyww.com/scheduler/handler"
|
||||
// )
|
||||
//
|
||||
// func Route(app *echo.Echo) {
|
||||
// // here is the route for our site
|
||||
// staticFiles := app.Group("/")
|
||||
// staticFiles.Use(middleware.Static("./FrontEnd"))
|
||||
//
|
||||
// api := app.Group("/api/")
|
||||
// api.GET("/getAssignment", handler.GetAssignment)
|
||||
// }
|
||||
1
src/embed_frontend.go
Normal file
1
src/embed_frontend.go
Normal file
@@ -0,0 +1 @@
|
||||
package main
|
||||
@@ -2,7 +2,6 @@ package handler
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/golang-module/carbon/v2"
|
||||
"github.com/labstack/echo/v4"
|
||||
@@ -10,6 +9,22 @@ import (
|
||||
"zsxyww.com/scheduler/model"
|
||||
)
|
||||
|
||||
// 一个值班表有7行,每行一个片区,第一个人是片区负责人
|
||||
// 片区数暂时是硬编码的
|
||||
type table_t [7][]*model.Member
|
||||
|
||||
// 为每个行添加标题
|
||||
func addZoneName(table *table_t) {
|
||||
//添加标题
|
||||
table[0] = append(table[0], &model.Member{Name: "凤翔", Access: 7})
|
||||
table[1] = append(table[1], &model.Member{Name: "朝晖", Access: 7})
|
||||
table[2] = append(table[2], &model.Member{Name: "香晖AB", Access: 7})
|
||||
table[3] = append(table[3], &model.Member{Name: "香晖CD", Access: 7})
|
||||
table[4] = append(table[4], &model.Member{Name: "东门", Access: 7})
|
||||
table[5] = append(table[5], &model.Member{Name: "北门", Access: 7})
|
||||
table[6] = append(table[6], &model.Member{Name: "歧头", Access: 7})
|
||||
}
|
||||
|
||||
// /api/getAssignment GET 获取当日值班表
|
||||
// 接受参数date,是需要生成值班表的日期
|
||||
func GetAssignment(i echo.Context) error {
|
||||
@@ -24,8 +39,8 @@ func GetAssignment(i echo.Context) error {
|
||||
data, err := generateTable(arg)
|
||||
|
||||
if err != nil {
|
||||
i.String(http.StatusInternalServerError, err.Error())
|
||||
return echo.ErrInternalServerError
|
||||
i.String(500, err.Error())
|
||||
return err
|
||||
}
|
||||
|
||||
i.JSON(200, data)
|
||||
@@ -33,13 +48,13 @@ func GetAssignment(i echo.Context) error {
|
||||
}
|
||||
|
||||
// 根据指定的时间来生成对应的值班表
|
||||
func generateTable(time carbon.Carbon) (*[7][]*model.Member, error) {
|
||||
func generateTable(time carbon.Carbon) (*table_t, error) {
|
||||
|
||||
table := [7][]*model.Member{} //结果放入这里
|
||||
members := []*model.Member{} //包含所有成员信息的切片
|
||||
today := []*model.Member{} //今天值班的人
|
||||
female := []*model.Member{} //今天的女生
|
||||
male := []*model.Member{} //今天的男生
|
||||
table := table_t{} //结果放入这里
|
||||
members := []*model.Member{} //包含所有成员信息的切片
|
||||
today := []*model.Member{} //今天值班的人
|
||||
female := []*model.Member{} //今天的女生
|
||||
male := []*model.Member{} //今天的男生
|
||||
week, dayOfWeek := getWorkDay(time)
|
||||
|
||||
//检查传入时间有没有问题
|
||||
@@ -56,13 +71,7 @@ func generateTable(time carbon.Carbon) (*[7][]*model.Member, error) {
|
||||
members = model.MemberList
|
||||
|
||||
//添加标题
|
||||
table[0] = append(table[0], &model.Member{Name: "凤翔", Access: 7})
|
||||
table[1] = append(table[1], &model.Member{Name: "朝晖", Access: 7})
|
||||
table[2] = append(table[2], &model.Member{Name: "香晖AB", Access: 7})
|
||||
table[3] = append(table[3], &model.Member{Name: "香晖CD", Access: 7})
|
||||
table[4] = append(table[4], &model.Member{Name: "东门", Access: 7})
|
||||
table[5] = append(table[5], &model.Member{Name: "北门", Access: 7})
|
||||
table[6] = append(table[6], &model.Member{Name: "歧头", Access: 7})
|
||||
addZoneName(&table)
|
||||
|
||||
//初始化数据
|
||||
for _, i := range members {
|
||||
@@ -115,7 +124,7 @@ func generateTable(time carbon.Carbon) (*[7][]*model.Member, error) {
|
||||
}
|
||||
|
||||
// 找出人数最少的片区
|
||||
func fewest(a [7][]*model.Member) int {
|
||||
func fewest(a table_t) int {
|
||||
b := min(len(a[0]), len(a[1]), len(a[2]), len(a[3]), len(a[4]), len(a[5]), len(a[6]))
|
||||
for i := range len(a) {
|
||||
if b == len(a[i]) {
|
||||
@@ -126,7 +135,7 @@ func fewest(a [7][]*model.Member) int {
|
||||
}
|
||||
|
||||
// 找出人数最少的女生片区
|
||||
func fewestF(a [7][]*model.Member) int {
|
||||
func fewestF(a table_t) int {
|
||||
b := min(len(a[0]), len(a[1]), len(a[2]), len(a[3]))
|
||||
for i := range len(a) - 3 {
|
||||
if b == len(a[i]) {
|
||||
|
||||
14
src/main.go
14
src/main.go
@@ -26,10 +26,9 @@ func main() {
|
||||
|
||||
route.Route(app) //注册路由表
|
||||
route.Middleware(app) //注册中间件
|
||||
renderer := tl.Tlw{
|
||||
Tl: template.Must(template.ParseGlob("templates/*.html")),
|
||||
}
|
||||
app.Renderer = renderer //注册模板
|
||||
|
||||
// 暂时在初始化时不注册模板,因为用不上
|
||||
//registerTemplate(app) //注册模板
|
||||
|
||||
listenAddress := fmt.Sprintf(":%d", config.Default.App.ListenPort)
|
||||
|
||||
@@ -49,3 +48,10 @@ func csv() {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func registerTemplate(app *echo.Echo) {
|
||||
renderer := tl.Tlw{
|
||||
Tl: template.Must(template.ParseGlob("templates/*.html")),
|
||||
}
|
||||
app.Renderer = renderer
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user