-
Notifications
You must be signed in to change notification settings - Fork 0
/
fields_config.go
132 lines (118 loc) · 3.41 KB
/
fields_config.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
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
package OrgTime
import (
"database/sql/driver"
"encoding/json"
"errors"
"github.com/lib/pq"
"time"
)
//FieldsWorkTime 上下班处理,提供给用户
type FieldsWorkTime struct {
//ID
ID int64 `db:"id" json:"id"`
//创建时间
CreateAt time.Time `db:"create_at" json:"createAt"`
//更新时间
UpdateAt time.Time `db:"update_at" json:"updateAt"`
//过期时间
// 过期后自动失效,用于排临时班
ExpireAt time.Time `db:"expire_at" json:"expireAt"`
//掌管该数据的组织ID
OrgID int64 `db:"org_id" json:"orgID"`
//分组ID列
Groups pq.Int64Array `db:"groups" json:"groups"`
//绑定人列
Binds pq.Int64Array `db:"binds" json:"binds"`
//名称
Name string `db:"name" json:"name"`
//当前上下班状态
// 根据配置时间自动调整,外部读取即可使用
IsWork bool `db:"is_work" json:"isWork"`
//时间配置组
Configs FieldsConfigs `db:"configs" json:"configs"`
//轮动任务
RotConfig FieldsConfigRot `db:"rot_config" json:"rotConfig"`
}
//FieldsConfigs 配置组
type FieldsConfigs struct {
//每年月时间
// 1-12月
Month []int `db:"month" json:"month"`
//每月时间
// 检查1-31的天
MonthDay []int `db:"month_day" json:"monthDay"`
//每月第几个周
// 1-6周
MonthWeek []int `db:"month_week" json:"monthWeek"`
//每周7天时间
// 检查1\2\3\4\5\6\0
Week []int `db:"week" json:"week"`
//具体的分配时间组合
WorkTime FieldsWorkTimeTimes `db:"work_time" json:"workTime"`
//自动跳过节假日
AllowHoliday bool `db:"allow_holiday" json:"allowHoliday"`
}
//Value sql底层处理器
func (t FieldsConfigs) Value() (driver.Value, error) {
return json.Marshal(t)
}
func (t *FieldsConfigs) Scan(value interface{}) error {
b, ok := value.([]byte)
if !ok {
return errors.New("type assertion to []byte failed")
}
return json.Unmarshal(b, &t)
}
//FieldsWorkTimeTimes 上下班时间 24小时制
type FieldsWorkTimeTimes []FieldsWorkTimeTime
//Value sql底层处理器
func (t FieldsWorkTimeTimes) Value() (driver.Value, error) {
return json.Marshal(t)
}
func (t *FieldsWorkTimeTimes) Scan(value interface{}) error {
b, ok := value.([]byte)
if !ok {
return errors.New("type assertion to []byte failed")
}
return json.Unmarshal(b, &t)
}
type FieldsWorkTimeTime struct {
//上班时间
StartHour int `db:"start_hour" json:"startHour"`
StartMinute int `db:"start_minute" json:"startMinute"`
//下班时间
EndHour int `db:"end_hour" json:"endHour"`
EndMinute int `db:"end_minute" json:"endMinute"`
}
//Value sql底层处理器
func (t FieldsWorkTimeTime) Value() (driver.Value, error) {
return json.Marshal(t)
}
func (t *FieldsWorkTimeTime) Scan(value interface{}) error {
b, ok := value.([]byte)
if !ok {
return errors.New("type assertion to []byte failed")
}
return json.Unmarshal(b, &t)
}
//FieldsConfigRot 轮动任务
type FieldsConfigRot struct {
//当前轮动到的位置
NowKey int `db:"now_key" json:"nowKey"`
//切换间隔日
// 如果给1,则每个轮动间隔1天;必须大于0,否则自动修正为1
DiffDay int `db:"diff_day" json:"diffDay"`
//具体的分配时间组合
WorkTime FieldsWorkTimeTimes `db:"work_time" json:"workTime"`
}
//Value sql底层处理器
func (t FieldsConfigRot) Value() (driver.Value, error) {
return json.Marshal(t)
}
func (t *FieldsConfigRot) Scan(value interface{}) error {
b, ok := value.([]byte)
if !ok {
return errors.New("type assertion to []byte failed")
}
return json.Unmarshal(b, &t)
}