|
@@ -15,16 +15,60 @@ import ( |
|
@@ -15,16 +15,60 @@ import ( |
15
|
|
15
|
|
16
|
//同步 人员数据
|
16
|
//同步 人员数据
|
17
|
|
17
|
|
18
|
-//--------------------
|
18
|
+type UserDepartData struct {
|
|
|
19
|
+ Id int64 `json:"id"`
|
|
|
20
|
+ CompanyId int64 `json:"company_id"`
|
|
|
21
|
+ DepartmentId int64 `json:"department_id"`
|
|
|
22
|
+ UserId int64 `json:"user_id"`
|
|
|
23
|
+}
|
|
|
24
|
+
|
|
|
25
|
+type UserPositionData struct {
|
|
|
26
|
+ Id int64 `json:"id"`
|
|
|
27
|
+ CompanyId int64 `json:"company_id"`
|
|
|
28
|
+ PositionId int64 `json:"position_id"`
|
|
|
29
|
+ UserId int64 `json:"user_id"`
|
|
|
30
|
+}
|
19
|
|
31
|
|
|
|
32
|
+//--------------------
|
20
|
type ModuleEmployee struct {
|
33
|
type ModuleEmployee struct {
|
21
|
- Userid int64 `json:"user_id"`
|
|
|
22
|
- UCenterId int64 `json:"ucenter_id"` //同一用户中心的用户id
|
|
|
23
|
- Phone string `json:"phone"`
|
|
|
24
|
- Nickname string `json:"nick_name"`
|
|
|
25
|
- Companyid int64 `json:"company_id"` //同意用户中心的company_id
|
|
|
26
|
- DepartmentId []int64 `json:"department_id"`
|
|
|
27
|
- Position []int64 `json:"position"`
|
34
|
+ Id int64 `json:"id"` //用户的id,对应本地的user_company_id
|
|
|
35
|
+ OpenId int64 `json:"open_id"` //同一用户中心的用户id
|
|
|
36
|
+ Phone string `json:"phone"`
|
|
|
37
|
+ Name string `json:"name"`
|
|
|
38
|
+ Sex int8 `json:"sex"`
|
|
|
39
|
+ JobNum string `json:"job_num"`
|
|
|
40
|
+ PrivatePhone string `json:"private_phone"` //私人手机
|
|
|
41
|
+ CompanyId int64 `json:"company_id"` //总后台的company_id
|
|
|
42
|
+ Email string `json:"email"`
|
|
|
43
|
+ ExtensionNum string `json:"extension_num"` //分机号
|
|
|
44
|
+ EntryTime string `json:"entry_time"` //入职时间
|
|
|
45
|
+ WorkSpace string `json:"work_space"`
|
|
|
46
|
+ IsBusiness int8 `json:"is_business"`
|
|
|
47
|
+ Status int8 `json:"status"`
|
|
|
48
|
+ Avatar string `json:"avatar"`
|
|
|
49
|
+ ExtraText string `json:"extra_text"`
|
|
|
50
|
+ Remarks string `json:"remarks"`
|
|
|
51
|
+ AdminType int8 `json:"admin_type"`
|
|
|
52
|
+ ChargeStatus int8 `json:"charge_status"`
|
|
|
53
|
+ UserDepartments []UserDepartData `json:"user_departments"`
|
|
|
54
|
+ UserPositions []UserPositionData `json:"user_positions"`
|
|
|
55
|
+}
|
|
|
56
|
+
|
|
|
57
|
+type DeleteUserData struct {
|
|
|
58
|
+ CompanyId int64 `json:"company_id"`
|
|
|
59
|
+ Ids []int64 `json:"ids"`
|
|
|
60
|
+}
|
|
|
61
|
+
|
|
|
62
|
+type ForbidAllowUserData struct {
|
|
|
63
|
+ CompanyId int64 `json:"company_id"`
|
|
|
64
|
+ Ids []int64 `json:"ids"`
|
|
|
65
|
+ Status int8 `json:"status"`
|
|
|
66
|
+}
|
|
|
67
|
+
|
|
|
68
|
+type RemoveUserDepartmentData struct {
|
|
|
69
|
+ CompanyId int64 `json:"company_id"`
|
|
|
70
|
+ UserIds []int64 `json:"user_ids"`
|
|
|
71
|
+ DepartmentIds []int64 `json:"department_ids"`
|
28
|
}
|
72
|
}
|
29
|
|
73
|
|
30
|
var _ PlatformAction = ModuleEmployee{}
|
74
|
var _ PlatformAction = ModuleEmployee{}
|
|
@@ -33,34 +77,73 @@ var _ PlatformAction = ModuleEmployee{} |
|
@@ -33,34 +77,73 @@ var _ PlatformAction = ModuleEmployee{} |
33
|
func (m ModuleEmployee) DoAction(code string, jsondata []byte) error {
|
77
|
func (m ModuleEmployee) DoAction(code string, jsondata []byte) error {
|
34
|
switch code {
|
78
|
switch code {
|
35
|
case "edit":
|
79
|
case "edit":
|
36
|
- // return UpdateDepartmentData(m)
|
80
|
+ var (
|
|
|
81
|
+ data ModuleEmployee
|
|
|
82
|
+ err error
|
|
|
83
|
+ )
|
|
|
84
|
+ err = json.Unmarshal(jsondata, &data)
|
|
|
85
|
+ if err != nil {
|
|
|
86
|
+ return fmt.Errorf("数据解析失败:%s", err)
|
|
|
87
|
+ }
|
|
|
88
|
+ return UpdateEmployeeData(data)
|
37
|
case "add":
|
89
|
case "add":
|
38
|
var (
|
90
|
var (
|
39
|
- data []ModuleEmployee
|
91
|
+ data ModuleEmployee
|
40
|
err error
|
92
|
err error
|
41
|
)
|
93
|
)
|
42
|
err = json.Unmarshal(jsondata, &data)
|
94
|
err = json.Unmarshal(jsondata, &data)
|
43
|
if err != nil {
|
95
|
if err != nil {
|
44
|
return fmt.Errorf("数据解析失败:%s", err)
|
96
|
return fmt.Errorf("数据解析失败:%s", err)
|
45
|
}
|
97
|
}
|
46
|
- return AddEmployeeData(data)
|
|
|
47
|
- case "delete":
|
98
|
+ datas := []ModuleEmployee{data}
|
|
|
99
|
+ return AddEmployeeData(datas)
|
|
|
100
|
+ case "batchDelete":
|
48
|
var (
|
101
|
var (
|
49
|
- err error
|
|
|
50
|
- ids []int64
|
102
|
+ err error
|
|
|
103
|
+ data DeleteUserData
|
51
|
)
|
104
|
)
|
52
|
- err = json.Unmarshal(jsondata, &ids)
|
105
|
+ err = json.Unmarshal(jsondata, &data)
|
53
|
if err != nil {
|
106
|
if err != nil {
|
54
|
return fmt.Errorf("数据解析失败:%s", err)
|
107
|
return fmt.Errorf("数据解析失败:%s", err)
|
55
|
}
|
108
|
}
|
56
|
- if len(ids) == 0 {
|
|
|
57
|
- return fmt.Errorf("参数错误")
|
109
|
+ return DeleteEmployeeData(data)
|
|
|
110
|
+ case "batchForbid":
|
|
|
111
|
+ //批量禁用、启用
|
|
|
112
|
+ var (
|
|
|
113
|
+ err error
|
|
|
114
|
+ data ForbidAllowUserData
|
|
|
115
|
+ )
|
|
|
116
|
+ err = json.Unmarshal(jsondata, &data)
|
|
|
117
|
+ if err != nil {
|
|
|
118
|
+ return fmt.Errorf("数据解析失败:%s", err)
|
|
|
119
|
+ }
|
|
|
120
|
+ return ForbidAllowEmployeeData(data)
|
|
|
121
|
+ case "batchRemove":
|
|
|
122
|
+ //移动通讯录用户部门
|
|
|
123
|
+ var (
|
|
|
124
|
+ err error
|
|
|
125
|
+ data RemoveUserDepartmentData
|
|
|
126
|
+ )
|
|
|
127
|
+ err = json.Unmarshal(jsondata, &data)
|
|
|
128
|
+ if err != nil {
|
|
|
129
|
+ return fmt.Errorf("数据解析失败:%s", err)
|
58
|
}
|
130
|
}
|
59
|
- return DeleteEmployeeData(ids)
|
131
|
+ return RemoveUserDepartment(data)
|
|
|
132
|
+ case "import":
|
|
|
133
|
+ //导入用户
|
|
|
134
|
+ var (
|
|
|
135
|
+ data []ModuleEmployee
|
|
|
136
|
+ err error
|
|
|
137
|
+ )
|
|
|
138
|
+ err = json.Unmarshal(jsondata, &data)
|
|
|
139
|
+ if err != nil {
|
|
|
140
|
+ return fmt.Errorf("数据解析失败:%s", err)
|
|
|
141
|
+ }
|
|
|
142
|
+ return AddEmployeeData(data)
|
60
|
default:
|
143
|
default:
|
61
|
return errors.New("action not found")
|
144
|
return errors.New("action not found")
|
62
|
}
|
145
|
}
|
63
|
- return nil
|
146
|
+ // return nil
|
64
|
}
|
147
|
}
|
65
|
|
148
|
|
66
|
// AddEmployeeData ...
|
149
|
// AddEmployeeData ...
|
|
@@ -76,9 +159,10 @@ func AddEmployeeData(data []ModuleEmployee) error { |
|
@@ -76,9 +159,10 @@ func AddEmployeeData(data []ModuleEmployee) error { |
76
|
userpositionData []*models.UserPosition
|
159
|
userpositionData []*models.UserPosition
|
77
|
nowTime = time.Now()
|
160
|
nowTime = time.Now()
|
78
|
)
|
161
|
)
|
79
|
- companydata, err = models.GetCompanyByUCenter(data[0].Companyid)
|
162
|
+
|
|
|
163
|
+ companydata, err = models.GetCompanyByUCenter(data[0].CompanyId)
|
80
|
if err != nil {
|
164
|
if err != nil {
|
81
|
- log.Error("GetCompanyByUCenter获取公司数据失败,ucenterId=%d,err:%s", data[0].Companyid, err)
|
165
|
+ log.Error("GetCompanyByUCenter获取公司数据失败,ucenterId=%d,err:%s", data[0].CompanyId, err)
|
82
|
return errors.New("获取公司数据失败")
|
166
|
return errors.New("获取公司数据失败")
|
83
|
}
|
167
|
}
|
84
|
|
168
|
|
|
@@ -86,7 +170,7 @@ func AddEmployeeData(data []ModuleEmployee) error { |
|
@@ -86,7 +170,7 @@ func AddEmployeeData(data []ModuleEmployee) error { |
86
|
var (
|
170
|
var (
|
87
|
userdata *models.User
|
171
|
userdata *models.User
|
88
|
)
|
172
|
)
|
89
|
- userdata, err = models.GetUserByUCenter(v.UCenterId)
|
173
|
+ userdata, err = models.GetUserByUCenter(v.OpenId)
|
90
|
if err != nil && err != orm.ErrNoRows {
|
174
|
if err != nil && err != orm.ErrNoRows {
|
91
|
log.Error("获取用户数据失败,err:%s", err)
|
175
|
log.Error("获取用户数据失败,err:%s", err)
|
92
|
return errors.New("获取用户数据失败")
|
176
|
return errors.New("获取用户数据失败")
|
|
@@ -94,8 +178,8 @@ func AddEmployeeData(data []ModuleEmployee) error { |
|
@@ -94,8 +178,8 @@ func AddEmployeeData(data []ModuleEmployee) error { |
94
|
if err == orm.ErrNoRows {
|
178
|
if err == orm.ErrNoRows {
|
95
|
//添加用户
|
179
|
//添加用户
|
96
|
userdata = &models.User{
|
180
|
userdata = &models.User{
|
97
|
- UserCenterId: v.UCenterId,
|
|
|
98
|
- NickName: v.Nickname,
|
181
|
+ UserCenterId: v.OpenId,
|
|
|
182
|
+ NickName: v.Name,
|
99
|
Phone: v.Phone,
|
183
|
Phone: v.Phone,
|
100
|
}
|
184
|
}
|
101
|
_, err = models.AddUser(userdata)
|
185
|
_, err = models.AddUser(userdata)
|
|
@@ -104,31 +188,47 @@ func AddEmployeeData(data []ModuleEmployee) error { |
|
@@ -104,31 +188,47 @@ func AddEmployeeData(data []ModuleEmployee) error { |
104
|
return err
|
188
|
return err
|
105
|
}
|
189
|
}
|
106
|
} else {
|
190
|
} else {
|
107
|
- userdata.NickName = v.Nickname
|
191
|
+ userdata.NickName = v.Name
|
108
|
userdata.Phone = v.Phone
|
192
|
userdata.Phone = v.Phone
|
109
|
models.UpdateUserById(userdata, []string{"NickName", "Phone"})
|
193
|
models.UpdateUserById(userdata, []string{"NickName", "Phone"})
|
110
|
}
|
194
|
}
|
111
|
uc := &models.UserCompany{
|
195
|
uc := &models.UserCompany{
|
112
|
- Id: v.Userid,
|
|
|
113
|
- CompanyId: companydata.Id,
|
|
|
114
|
- UserId: userdata.Id,
|
|
|
115
|
- NickName: v.Nickname,
|
196
|
+ Id: v.Id,
|
|
|
197
|
+ CompanyId: companydata.Id,
|
|
|
198
|
+ UserId: userdata.Id,
|
|
|
199
|
+ NickName: v.Name,
|
|
|
200
|
+ OpenId: v.OpenId,
|
|
|
201
|
+ Sex: v.Sex,
|
|
|
202
|
+ JobNum: v.JobNum,
|
|
|
203
|
+ Phone: v.Phone,
|
|
|
204
|
+ PrivatePhone: v.PrivatePhone,
|
|
|
205
|
+ Email: v.Email,
|
|
|
206
|
+ ExtensionNum: v.ExtensionNum,
|
|
|
207
|
+ Workspace: v.WorkSpace,
|
|
|
208
|
+ IsBusiness: v.IsBusiness,
|
|
|
209
|
+ Enable: v.Status,
|
|
|
210
|
+ Avatar: v.Avatar,
|
|
|
211
|
+ Remarks: v.Remarks,
|
|
|
212
|
+ AdminType: v.AdminType,
|
|
|
213
|
+ ChargeStatus: v.ChargeStatus,
|
|
|
214
|
+ ExtraText: v.ExtraText,
|
116
|
}
|
215
|
}
|
|
|
216
|
+ uc.EntryTime, _ = time.ParseInLocation("2006-01-02", v.EntryTime, time.Local)
|
117
|
usercompanydata = append(usercompanydata, uc)
|
217
|
usercompanydata = append(usercompanydata, uc)
|
118
|
- for i := range v.DepartmentId {
|
218
|
+ for i := range v.UserDepartments {
|
119
|
d := &models.UserDepartment{
|
219
|
d := &models.UserDepartment{
|
120
|
CompanyId: companydata.Id,
|
220
|
CompanyId: companydata.Id,
|
121
|
- UserCompanyId: v.Userid,
|
|
|
122
|
- DepartmentId: v.DepartmentId[i],
|
221
|
+ UserCompanyId: v.UserDepartments[i].UserId,
|
|
|
222
|
+ DepartmentId: v.UserDepartments[i].DepartmentId,
|
123
|
CreateTime: nowTime,
|
223
|
CreateTime: nowTime,
|
124
|
}
|
224
|
}
|
125
|
userdepartmentData = append(userdepartmentData, d)
|
225
|
userdepartmentData = append(userdepartmentData, d)
|
126
|
}
|
226
|
}
|
127
|
- for i := range v.Position {
|
227
|
+ for i := range v.UserPositions {
|
128
|
p := &models.UserPosition{
|
228
|
p := &models.UserPosition{
|
129
|
CompanyId: companydata.Id,
|
229
|
CompanyId: companydata.Id,
|
130
|
- UserCompanyId: v.Userid,
|
|
|
131
|
- PositionId: v.Position[i],
|
230
|
+ UserCompanyId: v.UserPositions[i].UserId,
|
|
|
231
|
+ PositionId: v.UserPositions[i].PositionId,
|
132
|
CreateAt: nowTime,
|
232
|
CreateAt: nowTime,
|
133
|
}
|
233
|
}
|
134
|
userpositionData = append(userpositionData, p)
|
234
|
userpositionData = append(userpositionData, p)
|
|
@@ -143,7 +243,7 @@ func AddEmployeeData(data []ModuleEmployee) error { |
|
@@ -143,7 +243,7 @@ func AddEmployeeData(data []ModuleEmployee) error { |
143
|
o.Rollback()
|
243
|
o.Rollback()
|
144
|
return e
|
244
|
return e
|
145
|
}
|
245
|
}
|
146
|
- //添加部门职位
|
246
|
+ //添加用户的职位
|
147
|
_, err = o.InsertMulti(20, &userpositionData)
|
247
|
_, err = o.InsertMulti(20, &userpositionData)
|
148
|
if err != nil {
|
248
|
if err != nil {
|
149
|
e := fmt.Errorf("插入user_position数据失败,err:%s", err)
|
249
|
e := fmt.Errorf("插入user_position数据失败,err:%s", err)
|
|
@@ -151,6 +251,7 @@ func AddEmployeeData(data []ModuleEmployee) error { |
|
@@ -151,6 +251,7 @@ func AddEmployeeData(data []ModuleEmployee) error { |
151
|
o.Rollback()
|
251
|
o.Rollback()
|
152
|
return e
|
252
|
return e
|
153
|
}
|
253
|
}
|
|
|
254
|
+ //添加用户的部门
|
154
|
_, err = o.InsertMulti(20, &userdepartmentData)
|
255
|
_, err = o.InsertMulti(20, &userdepartmentData)
|
155
|
if err != nil {
|
256
|
if err != nil {
|
156
|
e := fmt.Errorf("批量插入user_department数据失败,err:%s", err)
|
257
|
e := fmt.Errorf("批量插入user_department数据失败,err:%s", err)
|
|
@@ -170,19 +271,19 @@ func UpdateEmployeeData(data ModuleEmployee) error { |
|
@@ -170,19 +271,19 @@ func UpdateEmployeeData(data ModuleEmployee) error { |
170
|
companyInfo *models.Company
|
271
|
companyInfo *models.Company
|
171
|
userdata *models.User
|
272
|
userdata *models.User
|
172
|
)
|
273
|
)
|
173
|
- userdata, err = models.GetUserByUCenter(data.UCenterId)
|
274
|
+ userdata, err = models.GetUserByUCenter(data.OpenId)
|
174
|
if err != nil {
|
275
|
if err != nil {
|
175
|
e := fmt.Errorf("获取用户数据失败:%s", err)
|
276
|
e := fmt.Errorf("获取用户数据失败:%s", err)
|
176
|
log.Error(e.Error())
|
277
|
log.Error(e.Error())
|
177
|
return e
|
278
|
return e
|
178
|
}
|
279
|
}
|
179
|
- companyInfo, err = models.GetCompanyByUCenter(data.Companyid)
|
280
|
+ companyInfo, err = models.GetCompanyByUCenter(data.CompanyId)
|
180
|
if err != nil {
|
281
|
if err != nil {
|
181
|
e := fmt.Errorf("获取公司数据失败:%s", err)
|
282
|
e := fmt.Errorf("获取公司数据失败:%s", err)
|
182
|
log.Error(e.Error())
|
283
|
log.Error(e.Error())
|
183
|
return e
|
284
|
return e
|
184
|
}
|
285
|
}
|
185
|
- ucompany, err = models.GetUserCompanyById(data.Userid)
|
286
|
+ ucompany, err = models.GetUserCompanyById(data.Id)
|
186
|
if err != nil {
|
287
|
if err != nil {
|
187
|
e := fmt.Errorf("获取用户和公司的关联数据失败:%s", err)
|
288
|
e := fmt.Errorf("获取用户和公司的关联数据失败:%s", err)
|
188
|
log.Error(e.Error())
|
289
|
log.Error(e.Error())
|
|
@@ -191,30 +292,52 @@ func UpdateEmployeeData(data ModuleEmployee) error { |
|
@@ -191,30 +292,52 @@ func UpdateEmployeeData(data ModuleEmployee) error { |
191
|
o := orm.NewOrm()
|
292
|
o := orm.NewOrm()
|
192
|
o.Begin()
|
293
|
o.Begin()
|
193
|
//更新用户数据
|
294
|
//更新用户数据
|
194
|
- userdata.NickName = data.Nickname
|
295
|
+ userdata.NickName = data.Name
|
195
|
userdata.Phone = data.Phone
|
296
|
userdata.Phone = data.Phone
|
|
|
297
|
+
|
196
|
err = models.UpdateUserById(userdata, []string{"NickName", "Phone"}, o)
|
298
|
err = models.UpdateUserById(userdata, []string{"NickName", "Phone"}, o)
|
197
|
if err != nil {
|
299
|
if err != nil {
|
198
|
o.Rollback()
|
300
|
o.Rollback()
|
199
|
log.Error("UpdateUserById err:%s", err)
|
301
|
log.Error("UpdateUserById err:%s", err)
|
200
|
return errors.New("更新用户数据失败")
|
302
|
return errors.New("更新用户数据失败")
|
201
|
}
|
303
|
}
|
202
|
- ucompany.NickName = data.Nickname
|
|
|
203
|
- models.UpdateUserCompanyById(ucompany, []string{"NickName"}, o)
|
304
|
+ ucompany.NickName = data.Name
|
|
|
305
|
+ ucompany.NickName = data.Name
|
|
|
306
|
+ ucompany.OpenId = data.OpenId
|
|
|
307
|
+ ucompany.Sex = data.Sex
|
|
|
308
|
+ ucompany.JobNum = data.JobNum
|
|
|
309
|
+ ucompany.Phone = data.Phone
|
|
|
310
|
+ ucompany.PrivatePhone = data.PrivatePhone
|
|
|
311
|
+ ucompany.Email = data.Email
|
|
|
312
|
+ ucompany.ExtensionNum = data.ExtensionNum
|
|
|
313
|
+ ucompany.Workspace = data.WorkSpace
|
|
|
314
|
+ ucompany.IsBusiness = data.IsBusiness
|
|
|
315
|
+ ucompany.Enable = data.Status
|
|
|
316
|
+ ucompany.Avatar = data.Avatar
|
|
|
317
|
+ ucompany.Remarks = data.Remarks
|
|
|
318
|
+ ucompany.AdminType = data.AdminType
|
|
|
319
|
+ ucompany.ChargeStatus = data.ChargeStatus
|
|
|
320
|
+ ucompany.ExtraText = data.ExtraText
|
|
|
321
|
+ cols := []string{"NickName", "OpenId", "Sex", "JobNum",
|
|
|
322
|
+ "Phone", "PrivatePhone", "Email", "ExtensionNum", "Workspace",
|
|
|
323
|
+ "IsBusiness", "Status", "Avatar", "Remarks", "AdminType", "ChargeStatus",
|
|
|
324
|
+ "ExtraText",
|
|
|
325
|
+ }
|
|
|
326
|
+ err = models.UpdateUserCompanyById(ucompany, cols, o)
|
204
|
if err != nil {
|
327
|
if err != nil {
|
205
|
o.Rollback()
|
328
|
o.Rollback()
|
206
|
log.Error("UpdateUserCompanyById err:%s", err)
|
329
|
log.Error("UpdateUserCompanyById err:%s", err)
|
207
|
return errors.New("更新用户数据失败")
|
330
|
return errors.New("更新用户数据失败")
|
208
|
}
|
331
|
}
|
209
|
//添加部门
|
332
|
//添加部门
|
210
|
- err = editUserDepart(data.Userid, companyInfo.Id, data.DepartmentId, o)
|
333
|
+ err = editUserDepart(data.Id, companyInfo.Id, data.UserDepartments, o)
|
211
|
if err != nil {
|
334
|
if err != nil {
|
212
|
o.Rollback()
|
335
|
o.Rollback()
|
213
|
log.Error("editUserDepart err:%s", err)
|
336
|
log.Error("editUserDepart err:%s", err)
|
214
|
return protocol.NewErrWithMessage("1")
|
337
|
return protocol.NewErrWithMessage("1")
|
215
|
}
|
338
|
}
|
216
|
//添加职位
|
339
|
//添加职位
|
217
|
- err = editUserPosition(data.Userid, companyInfo.Id, data.Position, o)
|
340
|
+ err = editUserPosition(data.Id, companyInfo.Id, data.UserPositions, o)
|
218
|
if err != nil {
|
341
|
if err != nil {
|
219
|
o.Rollback()
|
342
|
o.Rollback()
|
220
|
log.Error("editUserDepart err:%s", err)
|
343
|
log.Error("editUserDepart err:%s", err)
|
|
@@ -224,89 +347,126 @@ func UpdateEmployeeData(data ModuleEmployee) error { |
|
@@ -224,89 +347,126 @@ func UpdateEmployeeData(data ModuleEmployee) error { |
224
|
return nil
|
347
|
return nil
|
225
|
}
|
348
|
}
|
226
|
|
349
|
|
227
|
-func editUserDepart(usercompanyid int64, companyid int64, departids []int64, o orm.Ormer) error {
|
350
|
+func editUserDepart(usercompanyid int64, companyid int64, userDepart []UserDepartData, o orm.Ormer) error {
|
228
|
var (
|
351
|
var (
|
229
|
oldDepartIds []int64
|
352
|
oldDepartIds []int64
|
|
|
353
|
+ newDepartIds []int64
|
230
|
err error
|
354
|
err error
|
231
|
delDepartIds []int64
|
355
|
delDepartIds []int64
|
232
|
addDepartIds []int64
|
356
|
addDepartIds []int64
|
|
|
357
|
+ addDepart []models.UserDepartment
|
233
|
)
|
358
|
)
|
234
|
- dataSql := `SELECT department_id FROM user_department WHERE enable_status=1 AND user_company_id=?`
|
|
|
235
|
- dataSql2 := `UPDATE user_department SET enable_status = 2 WHERE user_company_id=? AND department_id=?`
|
|
|
236
|
- datasql3 := `INSERT INTO user_department (user_company_id,department_id,company_id,enable_status,create_time) VALUES (?,?,?,?,?)`
|
359
|
+ for i := range userDepart {
|
|
|
360
|
+ newDepartIds = append(newDepartIds, userDepart[i].DepartmentId)
|
|
|
361
|
+ }
|
|
|
362
|
+ dataSql := `SELECT department_id FROM user_department WHERE enable_status=1 AND user_company_id=? `
|
237
|
err = utils.ExecuteQueryAllWithOrmer(o, &oldDepartIds, dataSql, usercompanyid)
|
363
|
err = utils.ExecuteQueryAllWithOrmer(o, &oldDepartIds, dataSql, usercompanyid)
|
238
|
if err != nil {
|
364
|
if err != nil {
|
239
|
e := fmt.Errorf("Execute SQL err:%s", err)
|
365
|
e := fmt.Errorf("Execute SQL err:%s", err)
|
240
|
log.Error(e.Error())
|
366
|
log.Error(e.Error())
|
241
|
return e
|
367
|
return e
|
242
|
}
|
368
|
}
|
243
|
- delDepartIds = utils.ArrayInt64Diff(oldDepartIds, departids)
|
|
|
244
|
- addDepartIds = utils.ArrayInt64Diff(departids, oldDepartIds)
|
|
|
245
|
- for _, v := range delDepartIds {
|
|
|
246
|
- err = utils.ExecuteSQLWithOrmer(o, dataSql2, usercompanyid, v)
|
369
|
+ delDepartIds = utils.ArrayInt64Diff(oldDepartIds, newDepartIds)
|
|
|
370
|
+ addDepartIds = utils.ArrayInt64Diff(newDepartIds, oldDepartIds)
|
|
|
371
|
+ nowTime := time.Now()
|
|
|
372
|
+ for _, v := range addDepartIds {
|
|
|
373
|
+ m := models.UserDepartment{
|
|
|
374
|
+ UserCompanyId: usercompanyid,
|
|
|
375
|
+ DepartmentId: v,
|
|
|
376
|
+ EnableStatus: models.USER_DEPARTMENT_ENABLE_YES,
|
|
|
377
|
+ CompanyId: companyid,
|
|
|
378
|
+ CreateTime: nowTime,
|
|
|
379
|
+ }
|
|
|
380
|
+ addDepart = append(addDepart, m)
|
|
|
381
|
+ }
|
|
|
382
|
+ if len(delDepartIds) > 0 {
|
|
|
383
|
+ _, err = o.QueryTable(&models.UserDepartment{}).
|
|
|
384
|
+ Filter("id__in", delDepartIds).
|
|
|
385
|
+ Update(orm.Params{
|
|
|
386
|
+ "enable_status": models.USER_DEPARTMENT_ENABLE_NO,
|
|
|
387
|
+ })
|
247
|
if err != nil {
|
388
|
if err != nil {
|
248
|
- e := fmt.Errorf("Execute SQL err:%s", err)
|
|
|
249
|
- log.Error(e.Error())
|
|
|
250
|
- return e
|
389
|
+ log.Error("删除用户部门失败: 用户id=%d,err:%s", usercompanyid, err)
|
|
|
390
|
+ return errors.New("删除用户部门失败")
|
251
|
}
|
391
|
}
|
252
|
}
|
392
|
}
|
253
|
- nowTime := time.Now().String()
|
|
|
254
|
- for _, v := range addDepartIds {
|
|
|
255
|
- err = utils.ExecuteSQLWithOrmer(o, datasql3, usercompanyid, v, companyid, models.USER_POSITION_ENABLE_YES, nowTime)
|
393
|
+ if len(addDepart) > 0 {
|
|
|
394
|
+ _, err = o.InsertMulti(10, addDepart)
|
256
|
if err != nil {
|
395
|
if err != nil {
|
257
|
- e := fmt.Errorf("Execute SQL err:%s", err)
|
|
|
258
|
- log.Error(e.Error())
|
|
|
259
|
- return e
|
396
|
+ log.Error("添加用户的部门失败 用户id=%d,err:%s", usercompanyid, err)
|
|
|
397
|
+ return errors.New("添加用户的部门失败")
|
260
|
}
|
398
|
}
|
261
|
}
|
399
|
}
|
262
|
return nil
|
400
|
return nil
|
263
|
}
|
401
|
}
|
264
|
|
402
|
|
265
|
-func editUserPosition(usercompanyid int64, companyid int64, positionids []int64, o orm.Ormer) error {
|
403
|
+func editUserPosition(usercompanyid int64, companyid int64, userPosition []UserPositionData, o orm.Ormer) error {
|
266
|
var (
|
404
|
var (
|
267
|
oldPositionIds []int64
|
405
|
oldPositionIds []int64
|
|
|
406
|
+ newPositionIds []int64
|
268
|
err error
|
407
|
err error
|
269
|
delPositionIds []int64
|
408
|
delPositionIds []int64
|
270
|
addPositionIds []int64
|
409
|
addPositionIds []int64
|
|
|
410
|
+ addPosition []models.UserPosition
|
271
|
)
|
411
|
)
|
|
|
412
|
+ for _, v := range userPosition {
|
|
|
413
|
+ newPositionIds = append(newPositionIds, v.PositionId)
|
|
|
414
|
+ }
|
272
|
dataSql := `SELECT position_id FROM user_position WHERE enable_status=1 AND user_company_id=?`
|
415
|
dataSql := `SELECT position_id FROM user_position WHERE enable_status=1 AND user_company_id=?`
|
273
|
- dataSql2 := `UPDATE user_position SET enable_status = 2 WHERE user_company_id=? AND position_id=?`
|
|
|
274
|
- datasql3 := `INSERT INTO user_position (user_company_id,position_id,company_id,enable_status,create_at) VALUES (?,?,?,?,?)`
|
|
|
275
|
err = utils.ExecuteQueryAllWithOrmer(o, &oldPositionIds, dataSql, usercompanyid)
|
416
|
err = utils.ExecuteQueryAllWithOrmer(o, &oldPositionIds, dataSql, usercompanyid)
|
276
|
if err != nil {
|
417
|
if err != nil {
|
277
|
e := fmt.Errorf("Execute SQL err:%s", err)
|
418
|
e := fmt.Errorf("Execute SQL err:%s", err)
|
278
|
log.Error(e.Error())
|
419
|
log.Error(e.Error())
|
279
|
return e
|
420
|
return e
|
280
|
}
|
421
|
}
|
281
|
- delPositionIds = utils.ArrayInt64Diff(oldPositionIds, positionids)
|
|
|
282
|
- addPositionIds = utils.ArrayInt64Diff(positionids, oldPositionIds)
|
|
|
283
|
- for _, v := range delPositionIds {
|
|
|
284
|
- err = utils.ExecuteSQLWithOrmer(o, dataSql2, usercompanyid, v)
|
422
|
+ delPositionIds = utils.ArrayInt64Diff(oldPositionIds, newPositionIds)
|
|
|
423
|
+ addPositionIds = utils.ArrayInt64Diff(newPositionIds, oldPositionIds)
|
|
|
424
|
+ nowTime := time.Now()
|
|
|
425
|
+ for _, v := range addPositionIds {
|
|
|
426
|
+ m := models.UserPosition{
|
|
|
427
|
+ UserCompanyId: usercompanyid,
|
|
|
428
|
+ PositionId: v,
|
|
|
429
|
+ EnableStatus: models.USER_DEPARTMENT_ENABLE_YES,
|
|
|
430
|
+ CompanyId: companyid,
|
|
|
431
|
+ CreateAt: nowTime,
|
|
|
432
|
+ }
|
|
|
433
|
+ addPosition = append(addPosition, m)
|
|
|
434
|
+ }
|
|
|
435
|
+ if len(delPositionIds) > 0 {
|
|
|
436
|
+ _, err = o.QueryTable(&models.UserPosition{}).
|
|
|
437
|
+ Filter("id__in", delPositionIds).
|
|
|
438
|
+ Update(orm.Params{
|
|
|
439
|
+ "enable_status": models.USER_POSITION_ENABLE_NO,
|
|
|
440
|
+ })
|
285
|
if err != nil {
|
441
|
if err != nil {
|
286
|
- e := fmt.Errorf("Execute SQL err:%s", err)
|
|
|
287
|
- log.Error(e.Error())
|
|
|
288
|
- return e
|
442
|
+ log.Error("删除用户职位失败: 用户id=%d,err:%s", usercompanyid, err)
|
|
|
443
|
+ return errors.New("删除用户部门失败")
|
289
|
}
|
444
|
}
|
290
|
}
|
445
|
}
|
291
|
- nowTime := time.Now().String()
|
|
|
292
|
- for _, v := range addPositionIds {
|
|
|
293
|
- err = utils.ExecuteSQLWithOrmer(o, datasql3, usercompanyid, v, companyid, models.USER_POSITION_ENABLE_YES, nowTime)
|
446
|
+ if len(addPosition) > 0 {
|
|
|
447
|
+ _, err = o.InsertMulti(10, addPosition)
|
294
|
if err != nil {
|
448
|
if err != nil {
|
295
|
- e := fmt.Errorf("Execute SQL err:%s", err)
|
|
|
296
|
- log.Error(e.Error())
|
|
|
297
|
- return e
|
449
|
+ log.Error("添加用户的职位失败 用户id=%d,err:%s", usercompanyid, err)
|
|
|
450
|
+ return errors.New("添加用户的部门失败")
|
298
|
}
|
451
|
}
|
299
|
}
|
452
|
}
|
300
|
return nil
|
453
|
return nil
|
301
|
}
|
454
|
}
|
302
|
|
455
|
|
303
|
// DeleteEmployeeData ...
|
456
|
// DeleteEmployeeData ...
|
304
|
-func DeleteEmployeeData(ids []int64) error {
|
457
|
+func DeleteEmployeeData(data DeleteUserData) error {
|
|
|
458
|
+ companyData, err := models.GetCompanyByUCenter(data.CompanyId)
|
|
|
459
|
+ if err != nil {
|
|
|
460
|
+ log.Error("h获取公司数据失败,user_center_id=%d,err:%s", data.CompanyId, err)
|
|
|
461
|
+ return errors.New("获取公司数据失败")
|
|
|
462
|
+ }
|
305
|
o := orm.NewOrm()
|
463
|
o := orm.NewOrm()
|
306
|
- _, err := o.QueryTable(&models.UserCompany{}).
|
|
|
307
|
- Filter("id__in", ids).
|
464
|
+ _, err = o.QueryTable(&models.UserCompany{}).
|
|
|
465
|
+ Filter("id__in", data.Ids).
|
|
|
466
|
+ Filter("company_id", companyData.Id).
|
308
|
Update(orm.Params{
|
467
|
Update(orm.Params{
|
309
|
- "delete_at": time.Now().String(),
|
468
|
+ "delete_at": time.Now().Format("2006-01-02 15:04:05"),
|
|
|
469
|
+ "enable": models.USERCOMPANY_ENABLE_NO,
|
310
|
})
|
470
|
})
|
311
|
if err != nil {
|
471
|
if err != nil {
|
312
|
log.Error("更新user_company数据失败:%s", err)
|
472
|
log.Error("更新user_company数据失败:%s", err)
|
|
@@ -314,3 +474,69 @@ func DeleteEmployeeData(ids []int64) error { |
|
@@ -314,3 +474,69 @@ func DeleteEmployeeData(ids []int64) error { |
314
|
}
|
474
|
}
|
315
|
return nil
|
475
|
return nil
|
316
|
}
|
476
|
}
|
|
|
477
|
+
|
|
|
478
|
+func ForbidAllowEmployeeData(data ForbidAllowUserData) error {
|
|
|
479
|
+ companyData, err := models.GetCompanyByUCenter(data.CompanyId)
|
|
|
480
|
+ if err != nil {
|
|
|
481
|
+ log.Error("h获取公司数据失败,user_center_id=%d,err:%s", data.CompanyId, err)
|
|
|
482
|
+ return errors.New("获取公司数据失败")
|
|
|
483
|
+ }
|
|
|
484
|
+ var status int8
|
|
|
485
|
+ switch data.Status {
|
|
|
486
|
+ case 1:
|
|
|
487
|
+ status = models.USERCOMPANY_ENABLE_YES
|
|
|
488
|
+ case 2:
|
|
|
489
|
+ status = models.USERCOMPANY_ENABLE_NO
|
|
|
490
|
+ }
|
|
|
491
|
+ o := orm.NewOrm()
|
|
|
492
|
+ _, err = o.QueryTable(&models.UserCompany{}).
|
|
|
493
|
+ Filter("id__in", data.Ids).
|
|
|
494
|
+ Filter("company_id", companyData.Id).
|
|
|
495
|
+ Update(orm.Params{
|
|
|
496
|
+ "enable": status,
|
|
|
497
|
+ "update_at": time.Now().Format("2006-01-02 15:04:05"),
|
|
|
498
|
+ })
|
|
|
499
|
+ if err != nil {
|
|
|
500
|
+ log.Error("更新user_company数据失败:%s", err)
|
|
|
501
|
+ return errors.New("删除user_company数据失败")
|
|
|
502
|
+ }
|
|
|
503
|
+ return nil
|
|
|
504
|
+}
|
|
|
505
|
+
|
|
|
506
|
+func RemoveUserDepartment(data RemoveUserDepartmentData) error {
|
|
|
507
|
+ var (
|
|
|
508
|
+ err error
|
|
|
509
|
+ companyData *models.Company
|
|
|
510
|
+ )
|
|
|
511
|
+ userDepartmentDatas := make(map[int64][]UserDepartData)
|
|
|
512
|
+ companyData, err = models.GetCompanyByUCenter(data.CompanyId)
|
|
|
513
|
+ if err != nil {
|
|
|
514
|
+ log.Error("h获取公司数据失败,user_center_id=%d,err:%s", data.CompanyId, err)
|
|
|
515
|
+ return errors.New("获取公司数据失败")
|
|
|
516
|
+ }
|
|
|
517
|
+ for _, v := range data.UserIds {
|
|
|
518
|
+ var userDapart []UserDepartData
|
|
|
519
|
+ for _, vv := range data.DepartmentIds {
|
|
|
520
|
+ m := UserDepartData{
|
|
|
521
|
+ CompanyId: companyData.Id,
|
|
|
522
|
+ UserId: v,
|
|
|
523
|
+ DepartmentId: vv,
|
|
|
524
|
+ }
|
|
|
525
|
+ userDapart = append(userDapart, m)
|
|
|
526
|
+ }
|
|
|
527
|
+ userDepartmentDatas[v] = userDapart
|
|
|
528
|
+ }
|
|
|
529
|
+
|
|
|
530
|
+ o := orm.NewOrm()
|
|
|
531
|
+ o.Begin()
|
|
|
532
|
+ for k, v := range userDepartmentDatas {
|
|
|
533
|
+ err = editUserDepart(k, companyData.Id, v, o)
|
|
|
534
|
+ if err != nil {
|
|
|
535
|
+ o.Rollback()
|
|
|
536
|
+ log.Error("更新用户部门失败;user_company_id=%d,err:%s", k, err)
|
|
|
537
|
+ return errors.New("更新用户部门失败")
|
|
|
538
|
+ }
|
|
|
539
|
+ }
|
|
|
540
|
+ o.Commit()
|
|
|
541
|
+ return nil
|
|
|
542
|
+} |