|
@@ -4,6 +4,12 @@ import ( |
|
@@ -4,6 +4,12 @@ import ( |
4
|
"encoding/json"
|
4
|
"encoding/json"
|
5
|
"errors"
|
5
|
"errors"
|
6
|
"fmt"
|
6
|
"fmt"
|
|
|
7
|
+ "time"
|
|
|
8
|
+
|
|
|
9
|
+ "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/factory"
|
|
|
10
|
+ "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
|
|
|
11
|
+ "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/dao"
|
|
|
12
|
+ "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
|
7
|
)
|
13
|
)
|
8
|
|
14
|
|
9
|
// UserDepartData 用户的部门数据
|
15
|
// UserDepartData 用户的部门数据
|
|
@@ -47,12 +53,32 @@ type EmployeeData struct { |
|
@@ -47,12 +53,32 @@ type EmployeeData struct { |
47
|
UserPositions []UserPositionData `json:"user_positions"`
|
53
|
UserPositions []UserPositionData `json:"user_positions"`
|
48
|
}
|
54
|
}
|
49
|
|
55
|
|
|
|
56
|
+//DeleteUserData 批量删除用户
|
|
|
57
|
+type DeleteUserData struct {
|
|
|
58
|
+ CompanyId int64 `json:"companyId"`
|
|
|
59
|
+ Ids []int64 `json:"ids"`
|
|
|
60
|
+}
|
|
|
61
|
+
|
|
|
62
|
+//ForbidAllowUserData 禁用启用用户
|
|
|
63
|
+type ForbidAllowUserData struct {
|
|
|
64
|
+ CompanyId int64 `json:"companyId"`
|
|
|
65
|
+ Ids []int64 `json:"ids"`
|
|
|
66
|
+ Status int8 `json:"status"`
|
|
|
67
|
+}
|
|
|
68
|
+
|
|
|
69
|
+//ImportEmployeeData 批量导入用户
|
|
|
70
|
+type ImportEmployeeData struct {
|
|
|
71
|
+ Add []EmployeeData `json:"add"`
|
|
|
72
|
+ Edit []EmployeeData `json:"edit"`
|
|
|
73
|
+}
|
|
|
74
|
+
|
50
|
//SyncEmployeeService 同步用户数据
|
75
|
//SyncEmployeeService 同步用户数据
|
51
|
type SyncEmployeeService struct{}
|
76
|
type SyncEmployeeService struct{}
|
52
|
|
77
|
|
53
|
func (service SyncEmployeeService) DoAction(action string, byteData []byte) error {
|
78
|
func (service SyncEmployeeService) DoAction(action string, byteData []byte) error {
|
54
|
switch action {
|
79
|
switch action {
|
55
|
case "add":
|
80
|
case "add":
|
|
|
81
|
+ //添加
|
56
|
var (
|
82
|
var (
|
57
|
data EmployeeData
|
83
|
data EmployeeData
|
58
|
err error
|
84
|
err error
|
|
@@ -61,9 +87,10 @@ func (service SyncEmployeeService) DoAction(action string, byteData []byte) erro |
|
@@ -61,9 +87,10 @@ func (service SyncEmployeeService) DoAction(action string, byteData []byte) erro |
61
|
if err != nil {
|
87
|
if err != nil {
|
62
|
return fmt.Errorf("数据解析失败:%s", err)
|
88
|
return fmt.Errorf("数据解析失败:%s", err)
|
63
|
}
|
89
|
}
|
64
|
- err = service.AddEmployeeData(data)
|
90
|
+ err = service.addEmployeeData(data)
|
65
|
return err
|
91
|
return err
|
66
|
case "edit":
|
92
|
case "edit":
|
|
|
93
|
+ //编辑更新
|
67
|
var (
|
94
|
var (
|
68
|
data EmployeeData
|
95
|
data EmployeeData
|
69
|
err error
|
96
|
err error
|
|
@@ -72,23 +99,195 @@ func (service SyncEmployeeService) DoAction(action string, byteData []byte) erro |
|
@@ -72,23 +99,195 @@ func (service SyncEmployeeService) DoAction(action string, byteData []byte) erro |
72
|
if err != nil {
|
99
|
if err != nil {
|
73
|
return fmt.Errorf("数据解析失败:%s", err)
|
100
|
return fmt.Errorf("数据解析失败:%s", err)
|
74
|
}
|
101
|
}
|
75
|
- err = service.UpdateEmployeeData(data)
|
102
|
+ err = service.updateEmployeeData(data)
|
76
|
return err
|
103
|
return err
|
77
|
case "batchDelete":
|
104
|
case "batchDelete":
|
|
|
105
|
+ //批量删除
|
|
|
106
|
+ var (
|
|
|
107
|
+ err error
|
|
|
108
|
+ data DeleteUserData
|
|
|
109
|
+ )
|
|
|
110
|
+ err = json.Unmarshal(byteData, &data)
|
|
|
111
|
+ if err != nil {
|
|
|
112
|
+ return fmt.Errorf("数据解析失败:%s", err)
|
|
|
113
|
+ }
|
|
|
114
|
+ return service.deleteEmployeeData(data)
|
78
|
case "batchForbid":
|
115
|
case "batchForbid":
|
|
|
116
|
+ //启用禁用
|
|
|
117
|
+ var (
|
|
|
118
|
+ err error
|
|
|
119
|
+ data ForbidAllowUserData
|
|
|
120
|
+ )
|
|
|
121
|
+ err = json.Unmarshal(byteData, &data)
|
|
|
122
|
+ if err != nil {
|
|
|
123
|
+ return fmt.Errorf("数据解析失败:%s", err)
|
|
|
124
|
+ }
|
|
|
125
|
+ return service.updateUsersStatus(data)
|
|
|
126
|
+
|
79
|
case "batchRemove":
|
127
|
case "batchRemove":
|
|
|
128
|
+ //移动通讯录用户部门 暂时不需要
|
|
|
129
|
+ return nil
|
80
|
case "import":
|
130
|
case "import":
|
|
|
131
|
+ //批量导入
|
|
|
132
|
+ var (
|
|
|
133
|
+ data ImportEmployeeData
|
|
|
134
|
+ err error
|
|
|
135
|
+ )
|
|
|
136
|
+ err = json.Unmarshal(byteData, &data)
|
|
|
137
|
+ if err != nil {
|
|
|
138
|
+ return fmt.Errorf("数据解析失败:%s", err)
|
|
|
139
|
+ }
|
|
|
140
|
+ // service.addEmployeeData(data.Add)
|
|
|
141
|
+ // for i := range data.Edit {
|
|
|
142
|
+ // UpdateEmployeeData(data.Edit[i])
|
|
|
143
|
+ // }
|
|
|
144
|
+ return nil
|
|
|
145
|
+
|
81
|
default:
|
146
|
default:
|
82
|
- return errors.New("action not found")
|
147
|
+ return errors.New("nothing todo")
|
83
|
}
|
148
|
}
|
84
|
return nil
|
149
|
return nil
|
85
|
}
|
150
|
}
|
86
|
|
151
|
|
87
|
-func (service SyncEmployeeService) AddEmployeeData(data EmployeeData) error {
|
152
|
+func (service SyncEmployeeService) addEmployeeData(data EmployeeData) error {
|
|
|
153
|
+ var (
|
|
|
154
|
+ transactionContext, _ = factory.CreateTransactionContext(nil)
|
|
|
155
|
+ err error
|
|
|
156
|
+ )
|
|
|
157
|
+ if err = transactionContext.StartTransaction(); err != nil {
|
|
|
158
|
+ return err
|
|
|
159
|
+ }
|
|
|
160
|
+ defer func() {
|
|
|
161
|
+ transactionContext.RollbackTransaction()
|
|
|
162
|
+ }()
|
|
|
163
|
+ var usersRepository domain.UsersRepository
|
|
|
164
|
+ if usersRepository, err = factory.CreateUsersRepository(map[string]interface{}{
|
|
|
165
|
+ "transactionContext": transactionContext,
|
|
|
166
|
+ }); err != nil {
|
|
|
167
|
+ return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
168
|
+ }
|
|
|
169
|
+ newUser := domain.Users{
|
|
|
170
|
+ Id: data.Id,
|
|
|
171
|
+ CompanyId: data.CompanyId,
|
|
|
172
|
+ OpenId: data.OpenId,
|
|
|
173
|
+ Name: data.Name,
|
|
|
174
|
+ Sex: data.Sex,
|
|
|
175
|
+ JobNum: data.JobNum,
|
|
|
176
|
+ Phone: data.Phone,
|
|
|
177
|
+ PrivatePhone: data.PrivatePhone,
|
|
|
178
|
+ Email: data.Email,
|
|
|
179
|
+ ExtensionNum: data.ExtensionNum,
|
|
|
180
|
+ Workspace: data.WorkSpace,
|
|
|
181
|
+ Status: data.Status,
|
|
|
182
|
+ Avatar: data.Avatar,
|
|
|
183
|
+ Remarks: data.Remarks,
|
|
|
184
|
+ ChargeStatus: data.ChargeStatus,
|
|
|
185
|
+ Permission: []domain.AdminPermissionBase{}, //权限
|
|
|
186
|
+ AccessPartners: []domain.Partner{},
|
|
|
187
|
+ }
|
|
|
188
|
+ newUser.EntryTime, _ = time.Parse("2006-01-02", data.EntryTime)
|
|
|
189
|
+ if err = usersRepository.Add(&newUser); err != nil {
|
|
|
190
|
+ return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
191
|
+ }
|
|
|
192
|
+ err = transactionContext.CommitTransaction()
|
|
|
193
|
+ return err
|
|
|
194
|
+}
|
88
|
|
195
|
|
89
|
- return nil
|
196
|
+func (service SyncEmployeeService) updateEmployeeData(data EmployeeData) error {
|
|
|
197
|
+ var (
|
|
|
198
|
+ transactionContext, _ = factory.CreateTransactionContext(nil)
|
|
|
199
|
+ err error
|
|
|
200
|
+ )
|
|
|
201
|
+ if err = transactionContext.StartTransaction(); err != nil {
|
|
|
202
|
+ return err
|
|
|
203
|
+ }
|
|
|
204
|
+ defer func() {
|
|
|
205
|
+ transactionContext.RollbackTransaction()
|
|
|
206
|
+ }()
|
|
|
207
|
+ var usersRepository domain.UsersRepository
|
|
|
208
|
+ if usersRepository, err = factory.CreateUsersRepository(map[string]interface{}{
|
|
|
209
|
+ "transactionContext": transactionContext,
|
|
|
210
|
+ }); err != nil {
|
|
|
211
|
+ return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
212
|
+ }
|
|
|
213
|
+ var oldUser domain.Users
|
|
|
214
|
+ oldUser, err = usersRepository.FindOne(domain.UsersFindOneQuery{
|
|
|
215
|
+ Id: data.Id,
|
|
|
216
|
+ })
|
|
|
217
|
+ if err != nil {
|
|
|
218
|
+ return lib.ThrowError(lib.BUSINESS_ERROR, err.Error())
|
|
|
219
|
+ }
|
|
|
220
|
+ entryTime, _ := time.Parse("2006-01-02", data.EntryTime)
|
|
|
221
|
+ _ = oldUser.Update(map[string]interface{}{
|
|
|
222
|
+ "Id": data.Id,
|
|
|
223
|
+ "CompanyId": data.CompanyId,
|
|
|
224
|
+ "OpenId": data.OpenId,
|
|
|
225
|
+ "Name": data.Name,
|
|
|
226
|
+ "Sex": data.Sex,
|
|
|
227
|
+ "JobNum": data.JobNum,
|
|
|
228
|
+ "Phone": data.Phone,
|
|
|
229
|
+ "PrivatePhone": data.PrivatePhone,
|
|
|
230
|
+ "Email": data.Email,
|
|
|
231
|
+ "ExtensionNum": data.ExtensionNum,
|
|
|
232
|
+ "Workspace": data.WorkSpace,
|
|
|
233
|
+ "Status": data.Status,
|
|
|
234
|
+ "Avatar": data.Avatar,
|
|
|
235
|
+ "Remarks": data.Remarks,
|
|
|
236
|
+ "ChargeStatus": data.ChargeStatus,
|
|
|
237
|
+ "EntryTime": entryTime,
|
|
|
238
|
+ })
|
|
|
239
|
+ if err = usersRepository.Edit(&oldUser); err != nil {
|
|
|
240
|
+ return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
241
|
+ }
|
|
|
242
|
+ err = transactionContext.CommitTransaction()
|
|
|
243
|
+ return err
|
90
|
}
|
244
|
}
|
91
|
|
245
|
|
92
|
-func (service SyncEmployeeService) UpdateEmployeeData(data EmployeeData) error {
|
|
|
93
|
- return nil
|
246
|
+func (service SyncEmployeeService) deleteEmployeeData(data DeleteUserData) error {
|
|
|
247
|
+ var (
|
|
|
248
|
+ transactionContext, _ = factory.CreateTransactionContext(nil)
|
|
|
249
|
+ err error
|
|
|
250
|
+ )
|
|
|
251
|
+ if err = transactionContext.StartTransaction(); err != nil {
|
|
|
252
|
+ return err
|
|
|
253
|
+ }
|
|
|
254
|
+ defer func() {
|
|
|
255
|
+ transactionContext.RollbackTransaction()
|
|
|
256
|
+ }()
|
|
|
257
|
+ var usersRepository domain.UsersRepository
|
|
|
258
|
+ if usersRepository, err = factory.CreateUsersRepository(map[string]interface{}{
|
|
|
259
|
+ "transactionContext": transactionContext,
|
|
|
260
|
+ }); err != nil {
|
|
|
261
|
+ return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
262
|
+ }
|
|
|
263
|
+ if err = usersRepository.Remove(data.Ids); err != nil {
|
|
|
264
|
+ return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
265
|
+ }
|
|
|
266
|
+ err = transactionContext.CommitTransaction()
|
|
|
267
|
+ return err
|
|
|
268
|
+}
|
|
|
269
|
+
|
|
|
270
|
+//UpdateUsersStatus 批量更新用户的状态
|
|
|
271
|
+func (service SyncEmployeeService) updateUsersStatus(data ForbidAllowUserData) error {
|
|
|
272
|
+ var (
|
|
|
273
|
+ transactionContext, _ = factory.CreateTransactionContext(nil)
|
|
|
274
|
+ err error
|
|
|
275
|
+ )
|
|
|
276
|
+ if err = transactionContext.StartTransaction(); err != nil {
|
|
|
277
|
+ return err
|
|
|
278
|
+ }
|
|
|
279
|
+ defer func() {
|
|
|
280
|
+ transactionContext.RollbackTransaction()
|
|
|
281
|
+ }()
|
|
|
282
|
+ var uDao *dao.UsersDao
|
|
|
283
|
+ if uDao, err = factory.CreateUsersDao(map[string]interface{}{
|
|
|
284
|
+ "transactionContext": transactionContext,
|
|
|
285
|
+ }); err != nil {
|
|
|
286
|
+ return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
287
|
+ }
|
|
|
288
|
+ if err = uDao.UpdateUserStatus(data.Ids, data.Status); err != nil {
|
|
|
289
|
+ return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
290
|
+ }
|
|
|
291
|
+ err = transactionContext.CommitTransaction()
|
|
|
292
|
+ return err
|
94
|
} |
293
|
} |