domain.go
3.0 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package domain
import (
"fmt"
"strings"
)
const MaxQueryRow = 10000
// 班次
const (
WorkOnFullDay = 1 //全天
WorkOnDay = 2 //白班
WorkOnMidDay = 4 //中班
WorkOnNight = 8 //夜班
)
const WorkOn = WorkOnFullDay | WorkOnDay | WorkOnMidDay | WorkOnNight
var (
ErrorNotFound = fmt.Errorf("没有此资源")
)
// excel 编码
var (
ExcelImportProduct = "MANUFACTURE_EXCEL_IMPORT_PRODUCT"
ExcelExportProduct = "MANUFACTURE_EXCEL_EXPORT_PRODUCT"
)
/***** 1.数据权限 *****/
// DataAuthor 数据验证器
type DataAuthor interface {
DataAuth(options OperateInfo, data AuthedData) error
}
// AuthedData 需要认证的数据
type AuthedData interface {
// 数据所属组织
BelongOrg() int64
}
// 验证参数
type OperateInfo struct {
// 当前操作人
UserId int
// 当前公司
CompanyId int
// 当前登录的组织
OrgId int
// 菜单模块
MenuCode string
// 匹配多个组织
OrgIds []int
}
func NewCheckOptions(optUser, org int) OperateInfo {
return OperateInfo{
UserId: optUser,
OrgId: org,
}
}
func (info OperateInfo) Valid() bool {
if info.UserId == 0 || info.CompanyId == 0 || info.OrgId == 0 {
return false
}
return true
}
func (info OperateInfo) GetCompanyId(companyId int) int {
if companyId != 0 {
return companyId
}
return info.CompanyId
}
func (info OperateInfo) GetOrgId(orgId int) int {
if orgId != 0 {
return orgId
}
return info.OrgId
}
func (info OperateInfo) GetUserId(userId int) int {
if userId != 0 {
return userId
}
return info.UserId
}
func (info OperateInfo) String() string {
return fmt.Sprintf("UserId: %v OrgId:%v CompanyId:%v", info.UserId, info.OrgId, info.CompanyId)
}
func Pagination(pageNumber, pageSize int) (offset int, limit int) {
if pageSize != 0 {
offset = (pageNumber - 1) * pageSize
limit = pageSize
}
return
}
func ValidWorkOn(workOn int) error {
if (workOn & WorkOn) == 0 {
return fmt.Errorf("班次有误")
}
return nil
}
func WorkOnDescription(workOn int) []string {
result := make([]string, 0)
if workOn&WorkOnFullDay > 0 {
result = append(result, "全天")
}
if workOn&WorkOnDay > 0 {
result = append(result, "白班")
}
if workOn&WorkOnMidDay > 0 {
result = append(result, "中班")
}
if workOn&WorkOnNight > 0 {
result = append(result, "夜班")
}
return result
}
func WorkOnDescriptions(workOn int) string {
r := WorkOnDescription(workOn)
return strings.Join(r, ",")
}
func EmployeeTypeDescription(employeeType int) string {
if employeeType == 1 {
return "固定"
}
if employeeType == 2 {
return "派遣"
}
if employeeType == 3 {
return "临时"
}
return "固定"
}
func ParticipateTypeDescription(participateType int) string {
if participateType == 1 {
return "正常"
}
if participateType == 2 {
return "支援"
}
return "正常"
}
func AttendanceStatusDescription(status int) string {
if status == 1 {
return "未审核"
}
if status == 2 {
return "已审核"
}
if status == 4 {
return "自动审核"
}
return "已审核"
}