正在显示
12 个修改的文件
包含
276 行增加
和
64 行删除
1 | +package command | ||
2 | + | ||
3 | +type EditDepartmentCommand struct { | ||
4 | + Id int64 `json:"id" ` // 组织id | ||
5 | + CompanyId int64 `json:"company_id"` // 公司编号 | ||
6 | + Level int `json:"level"` // 组织名称 | ||
7 | + Name string `json:"name"` // 组织名称 | ||
8 | + ParentId int64 `json:"parent_id"` // 组织父级id | ||
9 | + ChargeUserIds []int64 `json:"charge"` // 主管uids | ||
10 | + Path string `json:"path"` // 组织路径 | ||
11 | + ChangeDepartmentLists []struct { | ||
12 | + Id int64 `json:"id"` // 组织id | ||
13 | + Level int `json:"level"` // 组织名称 | ||
14 | + Path string `json:"path"` // 组织路径 | ||
15 | + } `json:"change_department_list"` | ||
16 | +} |
1 | +package command | ||
2 | + | ||
3 | +//导入部门数据 | ||
4 | +type ImportDepartmentCommand struct { | ||
5 | + Id int64 `json:"id"` // 组织id | ||
6 | + CompanyId int64 `json:"company_id"` // 公司编号 | ||
7 | + Level int `json:"level"` // 组织级别 | ||
8 | + Name string `json:"name"` // 组织名称 | ||
9 | + ParentId int64 `json:"parent_id"` // 组织父级id | ||
10 | + Path string `json:"path"` // 组织路径 | ||
11 | +} |
1 | package department | 1 | package department |
2 | 2 | ||
3 | +import ( | ||
4 | + "time" | ||
5 | + | ||
6 | + "github.com/linmadan/egglib-go/core/application" | ||
7 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/department/command" | ||
8 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory" | ||
9 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" | ||
10 | +) | ||
11 | + | ||
3 | type SyncDataDepartmentService struct{} | 12 | type SyncDataDepartmentService struct{} |
4 | 13 | ||
5 | //AddDepartment | 14 | //AddDepartment |
6 | //从BusinessAdmins 接收消息 添加部门 | 15 | //从BusinessAdmins 接收消息 添加部门 |
7 | //module="department" action="add" | 16 | //module="department" action="add" |
8 | -func (srv SyncDataDepartmentService) AddDepartment() error { | 17 | +func (srv SyncDataDepartmentService) addDepartment(param command.AddDepartmentCommand) error { |
18 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
19 | + if err != nil { | ||
20 | + return application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
21 | + } | ||
22 | + if err := transactionContext.StartTransaction(); err != nil { | ||
23 | + return application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
24 | + } | ||
25 | + defer func() { | ||
26 | + _ = transactionContext.RollbackTransaction() | ||
27 | + }() | ||
28 | + | ||
29 | + nowTime := time.Now() | ||
30 | + newDepartment := domain.Department{ | ||
31 | + Id: param.Id, | ||
32 | + CompanyId: param.CompanyId, | ||
33 | + Level: param.Level, | ||
34 | + Name: param.Name, | ||
35 | + ParentId: param.ParentId, | ||
36 | + ChargeUserIds: param.ChargeUserIds, | ||
37 | + Path: param.Path, | ||
38 | + CreateAt: nowTime, | ||
39 | + UpdateAt: nowTime, | ||
40 | + DeleteAt: nil, | ||
41 | + } | ||
42 | + | ||
43 | + departmentRepo := factory.CreateDepartmentRepository(map[string]interface{}{ | ||
44 | + "transactionContext": transactionContext, | ||
45 | + }) | ||
46 | + _, err = departmentRepo.Insert(&newDepartment) | ||
47 | + if err != nil { | ||
48 | + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
49 | + } | ||
50 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
51 | + return application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
52 | + } | ||
9 | return nil | 53 | return nil |
10 | } | 54 | } |
11 | 55 | ||
12 | //EditDepartment | 56 | //EditDepartment |
13 | //从BusinessAdmins 接收消息 编辑部门 | 57 | //从BusinessAdmins 接收消息 编辑部门 |
14 | //module="department" action="edit" | 58 | //module="department" action="edit" |
15 | -func (srv SyncDataDepartmentService) EditDepartment() error { | 59 | +func (srv SyncDataDepartmentService) editDepartment(param command.EditDepartmentCommand) error { |
60 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
61 | + if err != nil { | ||
62 | + return application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
63 | + } | ||
64 | + if err := transactionContext.StartTransaction(); err != nil { | ||
65 | + return application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
66 | + } | ||
67 | + defer func() { | ||
68 | + _ = transactionContext.RollbackTransaction() | ||
69 | + }() | ||
70 | + | ||
71 | + departmentIds := []int64{param.Id} | ||
72 | + for _, v := range param.ChangeDepartmentLists { | ||
73 | + departmentIds = append(departmentIds, v.Id) | ||
74 | + } | ||
75 | + departmentRepo := factory.CreateDepartmentRepository(map[string]interface{}{ | ||
76 | + "transactionContext": transactionContext, | ||
77 | + }) | ||
78 | + _, departmentList, err := departmentRepo.Find(map[string]interface{}{ | ||
79 | + "ids": departmentIds, | ||
80 | + }) | ||
81 | + if err != nil { | ||
82 | + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
83 | + } | ||
84 | + for i := range departmentList { | ||
85 | + if departmentList[i].Id == param.Id { | ||
86 | + departmentList[i].CompanyId = param.CompanyId | ||
87 | + departmentList[i].Name = param.Name | ||
88 | + departmentList[i].Name = param.Path | ||
89 | + departmentList[i].ChargeUserIds = param.ChargeUserIds | ||
90 | + departmentList[i].Level = param.Level | ||
91 | + departmentList[i].ParentId = param.ParentId | ||
92 | + continue | ||
93 | + } | ||
94 | + | ||
95 | + for _, vv := range param.ChangeDepartmentLists { | ||
96 | + if vv.Id == departmentList[i].Id { | ||
97 | + departmentList[i].Path = vv.Path | ||
98 | + departmentList[i].Level = vv.Level | ||
99 | + break | ||
100 | + } | ||
101 | + } | ||
102 | + } | ||
103 | + for i := range departmentList { | ||
104 | + _, err := departmentRepo.Update(departmentList[i]) | ||
105 | + if err != nil { | ||
106 | + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
107 | + } | ||
108 | + } | ||
109 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
110 | + return application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
111 | + } | ||
16 | return nil | 112 | return nil |
17 | } | 113 | } |
18 | 114 | ||
19 | //batchDelete | 115 | //batchDelete |
20 | //从BusinessAdmins 接收消息 删除部门 | 116 | //从BusinessAdmins 接收消息 删除部门 |
21 | //module="department" action="batchDelete" | 117 | //module="department" action="batchDelete" |
22 | -func (srv SyncDataDepartmentService) batchDelete() error { | 118 | +func (srv SyncDataDepartmentService) batchDeleteDepartment(param command.BatchDeleteCommand) error { |
119 | + if len(param.Ids) == 0 { | ||
120 | + return nil | ||
121 | + } | ||
122 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
123 | + if err != nil { | ||
124 | + return application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
125 | + } | ||
126 | + if err := transactionContext.StartTransaction(); err != nil { | ||
127 | + return application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
128 | + } | ||
129 | + defer func() { | ||
130 | + _ = transactionContext.RollbackTransaction() | ||
131 | + }() | ||
132 | + departmentRepo := factory.CreateDepartmentRepository(map[string]interface{}{ | ||
133 | + "transactionContext": transactionContext, | ||
134 | + }) | ||
135 | + err = departmentRepo.Remove(param.Ids) | ||
136 | + if err != nil { | ||
137 | + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
138 | + } | ||
139 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
140 | + return application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
141 | + } | ||
23 | return nil | 142 | return nil |
24 | } | 143 | } |
25 | 144 | ||
26 | //importDepartment | 145 | //importDepartment |
27 | //从BusinessAdmins 接收消息 导入部门数据 | 146 | //从BusinessAdmins 接收消息 导入部门数据 |
28 | //module="department" action="import" | 147 | //module="department" action="import" |
29 | -func (srv SyncDataDepartmentService) importDepartment() error { | 148 | +func (srv SyncDataDepartmentService) importDepartment(param []command.ImportDepartmentCommand) error { |
149 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
150 | + if err != nil { | ||
151 | + return application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
152 | + } | ||
153 | + if err := transactionContext.StartTransaction(); err != nil { | ||
154 | + return application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
155 | + } | ||
156 | + defer func() { | ||
157 | + _ = transactionContext.RollbackTransaction() | ||
158 | + }() | ||
159 | + departmentRepo := factory.CreateDepartmentRepository(map[string]interface{}{ | ||
160 | + "transactionContext": transactionContext, | ||
161 | + }) | ||
162 | + nowTime := time.Now() | ||
163 | + for i := range param { | ||
164 | + newDepartment := domain.Department{ | ||
165 | + Id: param[i].Id, | ||
166 | + CompanyId: param[i].CompanyId, | ||
167 | + Level: param[i].Level, | ||
168 | + Name: param[i].Name, | ||
169 | + ParentId: param[i].ParentId, | ||
170 | + ChargeUserIds: []int64{}, | ||
171 | + Path: param[i].Path, | ||
172 | + CreateAt: nowTime, | ||
173 | + UpdateAt: nowTime, | ||
174 | + DeleteAt: nil, | ||
175 | + } | ||
176 | + _, err = departmentRepo.Insert(&newDepartment) | ||
177 | + if err != nil { | ||
178 | + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
179 | + } | ||
180 | + } | ||
181 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
182 | + return application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
183 | + } | ||
30 | return nil | 184 | return nil |
31 | } | 185 | } |
@@ -27,3 +27,11 @@ func CreateUserRepository(options map[string]interface{}) domain.UserRepository | @@ -27,3 +27,11 @@ func CreateUserRepository(options map[string]interface{}) domain.UserRepository | ||
27 | } | 27 | } |
28 | return repository.NewUserRepository(transactionContext) | 28 | return repository.NewUserRepository(transactionContext) |
29 | } | 29 | } |
30 | + | ||
31 | +func CreateDepartmentRepository(options map[string]interface{}) domain.DepartmentRepository { | ||
32 | + var transactionContext *pg.TransactionContext | ||
33 | + if value, ok := options["transactionContext"]; ok { | ||
34 | + transactionContext = value.(*pg.TransactionContext) | ||
35 | + } | ||
36 | + return repository.NewDepartmentRepository(transactionContext) | ||
37 | +} |
1 | package command | 1 | package command |
2 | 2 | ||
3 | type SaveUserCommand struct { | 3 | type SaveUserCommand struct { |
4 | - Id int64 ` json:"id"` // 用户Id | ||
5 | - Phone string `json:"phone"` // 用户账号 | ||
6 | - Avatar string `json:"avatar"` // 用户头像URL | ||
7 | - CompanyId int64 `json:"company_id"` // 公司编号 | ||
8 | - AdminType int `json:"admin_type"` // 1普通员工 2 主管理员 | ||
9 | - Name string `json:"name"` // 用户姓名 | ||
10 | - Status int `json:"status"` // 用户状态(1正常 2禁用) | 4 | + Id int64 `json:"id"` // 用户Id |
5 | + Phone string `json:"phone"` // 用户账号 | ||
6 | + Avatar string `json:"avatar"` // 用户头像URL | ||
7 | + CompanyId int64 `json:"company_id"` // 公司编号 | ||
8 | + AdminType int `json:"admin_type"` // 1普通员工 2 主管理员 | ||
9 | + Name string `json:"name"` // 用户姓名 | ||
10 | + Status int `json:"status"` // 用户状态(1正常 2禁用) | ||
11 | + UserDepartments []struct { | ||
12 | + DepartmentId int `json:"department_id" ` | ||
13 | + } `json:"user_departments"` //用户的组织ids | ||
11 | } | 14 | } |
@@ -25,28 +25,33 @@ func (srv SyncDataUserService) AddUser(param command.SaveUserCommand) error { | @@ -25,28 +25,33 @@ func (srv SyncDataUserService) AddUser(param command.SaveUserCommand) error { | ||
25 | defer func() { | 25 | defer func() { |
26 | _ = transactionContext.RollbackTransaction() | 26 | _ = transactionContext.RollbackTransaction() |
27 | }() | 27 | }() |
28 | + var departmentIds []int | ||
29 | + for _, v := range param.UserDepartments { | ||
30 | + departmentIds = append(departmentIds, v.DepartmentId) | ||
31 | + } | ||
28 | nowTime := time.Now() | 32 | nowTime := time.Now() |
29 | newUser := domain.User{ | 33 | newUser := domain.User{ |
30 | - Id: param.Id, | ||
31 | - Account: param.Phone, | ||
32 | - AvatarUrl: param.Avatar, | ||
33 | - CompanyId: param.CompanyId, | ||
34 | - AdminType: param.AdminType, | ||
35 | - Name: param.Name, | ||
36 | - Status: param.Status, | ||
37 | - UpdateAt: nowTime, | ||
38 | - DeleteAt: nil, | ||
39 | - CreateAt: nowTime, | 34 | + Id: param.Id, |
35 | + Account: param.Phone, | ||
36 | + AvatarUrl: param.Avatar, | ||
37 | + CompanyId: param.CompanyId, | ||
38 | + AdminType: param.AdminType, | ||
39 | + DepartmentId: departmentIds, | ||
40 | + Name: param.Name, | ||
41 | + Status: param.Status, | ||
42 | + UpdateAt: nowTime, | ||
43 | + DeleteAt: nil, | ||
44 | + CreateAt: nowTime, | ||
40 | } | 45 | } |
41 | userRepo := factory.CreateUserRepository(map[string]interface{}{ | 46 | userRepo := factory.CreateUserRepository(map[string]interface{}{ |
42 | "transactionContext": transactionContext, | 47 | "transactionContext": transactionContext, |
43 | }) | 48 | }) |
44 | _, err = userRepo.Insert(&newUser) | 49 | _, err = userRepo.Insert(&newUser) |
45 | if err != nil { | 50 | if err != nil { |
46 | - return err | 51 | + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
47 | } | 52 | } |
48 | if err := transactionContext.CommitTransaction(); err != nil { | 53 | if err := transactionContext.CommitTransaction(); err != nil { |
49 | - return err | 54 | + return application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
50 | } | 55 | } |
51 | return nil | 56 | return nil |
52 | } | 57 | } |
@@ -73,7 +78,7 @@ func (srv SyncDataUserService) UpdateUser(param command.SaveUserCommand) error { | @@ -73,7 +78,7 @@ func (srv SyncDataUserService) UpdateUser(param command.SaveUserCommand) error { | ||
73 | "id": param.Id, | 78 | "id": param.Id, |
74 | }) | 79 | }) |
75 | if err != nil { | 80 | if err != nil { |
76 | - return err | 81 | + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
77 | } | 82 | } |
78 | var ( | 83 | var ( |
79 | newUser *domain.User | 84 | newUser *domain.User |
@@ -97,16 +102,16 @@ func (srv SyncDataUserService) UpdateUser(param command.SaveUserCommand) error { | @@ -97,16 +102,16 @@ func (srv SyncDataUserService) UpdateUser(param command.SaveUserCommand) error { | ||
97 | if len(userList) > 0 { | 102 | if len(userList) > 0 { |
98 | _, err = userRepo.Update(newUser) | 103 | _, err = userRepo.Update(newUser) |
99 | if err != nil { | 104 | if err != nil { |
100 | - return err | 105 | + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
101 | } | 106 | } |
102 | } else { | 107 | } else { |
103 | _, err = userRepo.Insert(newUser) | 108 | _, err = userRepo.Insert(newUser) |
104 | if err != nil { | 109 | if err != nil { |
105 | - return err | 110 | + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
106 | } | 111 | } |
107 | } | 112 | } |
108 | if err := transactionContext.CommitTransaction(); err != nil { | 113 | if err := transactionContext.CommitTransaction(); err != nil { |
109 | - return err | 114 | + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
110 | } | 115 | } |
111 | return nil | 116 | return nil |
112 | } | 117 | } |
@@ -134,10 +139,10 @@ func (srv SyncDataUserService) batchDelete(param command.BatchDeleteCommand) err | @@ -134,10 +139,10 @@ func (srv SyncDataUserService) batchDelete(param command.BatchDeleteCommand) err | ||
134 | 139 | ||
135 | err = userRepo.Remove(param.Uids) | 140 | err = userRepo.Remove(param.Uids) |
136 | if err != nil { | 141 | if err != nil { |
137 | - return err | 142 | + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
138 | } | 143 | } |
139 | if err := transactionContext.CommitTransaction(); err != nil { | 144 | if err := transactionContext.CommitTransaction(); err != nil { |
140 | - return err | 145 | + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
141 | } | 146 | } |
142 | return nil | 147 | return nil |
143 | } | 148 | } |
@@ -167,17 +172,17 @@ func (srv SyncDataUserService) batchForbid(param command.BatchForbidCommand) err | @@ -167,17 +172,17 @@ func (srv SyncDataUserService) batchForbid(param command.BatchForbidCommand) err | ||
167 | "limit": len(param.Uids), | 172 | "limit": len(param.Uids), |
168 | }) | 173 | }) |
169 | if err != nil { | 174 | if err != nil { |
170 | - return err | 175 | + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
171 | } | 176 | } |
172 | for i := range userList { | 177 | for i := range userList { |
173 | userList[i].Status = param.Status | 178 | userList[i].Status = param.Status |
174 | _, err = userRepo.Update(userList[i]) | 179 | _, err = userRepo.Update(userList[i]) |
175 | if err != nil { | 180 | if err != nil { |
176 | - return err | 181 | + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
177 | } | 182 | } |
178 | } | 183 | } |
179 | if err := transactionContext.CommitTransaction(); err != nil { | 184 | if err := transactionContext.CommitTransaction(); err != nil { |
180 | - return err | 185 | + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
181 | } | 186 | } |
182 | return nil | 187 | return nil |
183 | } | 188 | } |
@@ -210,7 +215,7 @@ func (srv SyncDataUserService) importUser(param command.ImportUserCommand) error | @@ -210,7 +215,7 @@ func (srv SyncDataUserService) importUser(param command.ImportUserCommand) error | ||
210 | "ids": editUserIds, | 215 | "ids": editUserIds, |
211 | }) | 216 | }) |
212 | if err != nil { | 217 | if err != nil { |
213 | - return err | 218 | + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
214 | } | 219 | } |
215 | nowTime := time.Now() | 220 | nowTime := time.Now() |
216 | for i := range editUserList { | 221 | for i := range editUserList { |
@@ -248,11 +253,11 @@ func (srv SyncDataUserService) importUser(param command.ImportUserCommand) error | @@ -248,11 +253,11 @@ func (srv SyncDataUserService) importUser(param command.ImportUserCommand) error | ||
248 | } | 253 | } |
249 | _, err := userRepo.Insert(&tempUser) | 254 | _, err := userRepo.Insert(&tempUser) |
250 | if err != nil { | 255 | if err != nil { |
251 | - return err | 256 | + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
252 | } | 257 | } |
253 | } | 258 | } |
254 | if err := transactionContext.CommitTransaction(); err != nil { | 259 | if err := transactionContext.CommitTransaction(); err != nil { |
255 | - return err | 260 | + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
256 | } | 261 | } |
257 | 262 | ||
258 | return nil | 263 | return nil |
@@ -17,7 +17,7 @@ type Department struct { | @@ -17,7 +17,7 @@ type Department struct { | ||
17 | type DepartmentRepository interface { | 17 | type DepartmentRepository interface { |
18 | Insert(param *Department) (*Department, error) | 18 | Insert(param *Department) (*Department, error) |
19 | Update(param *Department) (*Department, error) | 19 | Update(param *Department) (*Department, error) |
20 | - Remove(param *Department) (*Department, error) | 20 | + Remove(ids []int64) error |
21 | FindOne(queryOptions map[string]interface{}) (*Department, error) | 21 | FindOne(queryOptions map[string]interface{}) (*Department, error) |
22 | Find(queryOptions map[string]interface{}) (int, []*Department, error) | 22 | Find(queryOptions map[string]interface{}) (int, []*Department, error) |
23 | } | 23 | } |
@@ -3,16 +3,17 @@ package domain | @@ -3,16 +3,17 @@ package domain | ||
3 | import "time" | 3 | import "time" |
4 | 4 | ||
5 | type User struct { | 5 | type User struct { |
6 | - Id int64 // 用户Id | ||
7 | - Account string // 用户账号 | ||
8 | - AvatarUrl string // 用户头像URL | ||
9 | - CompanyId int64 // 公司编号 | ||
10 | - AdminType int // 1普通员工 2 主管理员 | ||
11 | - Name string // 用户姓名 | ||
12 | - Status int // 用户状态(1正常 2禁用) | ||
13 | - UpdateAt time.Time // 更新时间 | ||
14 | - DeleteAt *time.Time | ||
15 | - CreateAt time.Time | 6 | + Id int64 // 用户Id |
7 | + Account string // 用户账号 | ||
8 | + AvatarUrl string // 用户头像URL | ||
9 | + CompanyId int64 // 公司编号 | ||
10 | + AdminType int // 1普通员工 2 主管理员 | ||
11 | + Name string // 用户姓名 | ||
12 | + Status int // 用户状态(1正常 2禁用) | ||
13 | + DepartmentId []int // 用户归属的部门 | ||
14 | + UpdateAt time.Time // 更新时间 | ||
15 | + DeleteAt *time.Time | ||
16 | + CreateAt time.Time | ||
16 | } | 17 | } |
17 | 18 | ||
18 | //1普通员工 2 主管理员 | 19 | //1普通员工 2 主管理员 |
@@ -3,15 +3,16 @@ package models | @@ -3,15 +3,16 @@ package models | ||
3 | import "time" | 3 | import "time" |
4 | 4 | ||
5 | type User struct { | 5 | type User struct { |
6 | - tableName struct{} `pg:"user"` | ||
7 | - Id int64 `pg:"pk:id"` // 用户Id | ||
8 | - Account string // 用户账号 | ||
9 | - AvatarUrl string // 用户头像URL | ||
10 | - CompanyId int64 // 公司编号 | ||
11 | - AdminType int // 1普通员工 2 主管理员 | ||
12 | - Name string // 用户姓名 | ||
13 | - Status int // 用户状态(1正常 2禁用) | ||
14 | - UpdateAt time.Time // 更新时间 | ||
15 | - CreateAt time.Time // 创建时间 | ||
16 | - DeleteAt *time.Time // 删除时间 | 6 | + tableName struct{} `pg:"user"` |
7 | + Id int64 `pg:"pk:id"` // 用户Id | ||
8 | + Account string // 用户账号 | ||
9 | + AvatarUrl string // 用户头像URL | ||
10 | + CompanyId int64 // 公司编号 | ||
11 | + AdminType int // 1普通员工 2 主管理员 | ||
12 | + Name string // 用户姓名 | ||
13 | + Status int // 用户状态(1正常 2禁用) | ||
14 | + DepartmentId []int // 用户归属的部门 | ||
15 | + UpdateAt time.Time // 更新时间 | ||
16 | + CreateAt time.Time // 创建时间 | ||
17 | + DeleteAt *time.Time // 删除时间 | ||
17 | } | 18 | } |
@@ -15,8 +15,8 @@ type DepartmentRepository struct { | @@ -15,8 +15,8 @@ type DepartmentRepository struct { | ||
15 | 15 | ||
16 | var _ domain.DepartmentRepository = (*DepartmentRepository)(nil) | 16 | var _ domain.DepartmentRepository = (*DepartmentRepository)(nil) |
17 | 17 | ||
18 | -func NewDepartmentRepository(tx *pgTransaction.TransactionContext) *CompanyRepository { | ||
19 | - return &CompanyRepository{ | 18 | +func NewDepartmentRepository(tx *pgTransaction.TransactionContext) *DepartmentRepository { |
19 | + return &DepartmentRepository{ | ||
20 | transactionContext: tx, | 20 | transactionContext: tx, |
21 | } | 21 | } |
22 | } | 22 | } |
@@ -54,7 +54,7 @@ func (repo *DepartmentRepository) Update(u *domain.Department) (*domain.Departme | @@ -54,7 +54,7 @@ func (repo *DepartmentRepository) Update(u *domain.Department) (*domain.Departme | ||
54 | Path: u.Path, | 54 | Path: u.Path, |
55 | CreateAt: u.CreateAt, | 55 | CreateAt: u.CreateAt, |
56 | UpdateAt: u.UpdateAt, | 56 | UpdateAt: u.UpdateAt, |
57 | - DeleteAt: nil, | 57 | + DeleteAt: u.DeleteAt, |
58 | } | 58 | } |
59 | tx := repo.transactionContext.PgTx | 59 | tx := repo.transactionContext.PgTx |
60 | _, err := tx.Model(&departmentModel).WherePK().Update() | 60 | _, err := tx.Model(&departmentModel).WherePK().Update() |
@@ -64,11 +64,15 @@ func (repo *DepartmentRepository) Update(u *domain.Department) (*domain.Departme | @@ -64,11 +64,15 @@ func (repo *DepartmentRepository) Update(u *domain.Department) (*domain.Departme | ||
64 | return u, nil | 64 | return u, nil |
65 | } | 65 | } |
66 | 66 | ||
67 | -func (repo *DepartmentRepository) Remove(u *domain.Department) (*domain.Department, error) { | 67 | +func (repo *DepartmentRepository) Remove(ids []int64) error { |
68 | nowTime := time.Now() | 68 | nowTime := time.Now() |
69 | - u.DeleteAt = &nowTime | ||
70 | - _, err := repo.Update(u) | ||
71 | - return u, err | 69 | + tx := repo.transactionContext.PgTx |
70 | + uModel := models.Department{} | ||
71 | + _, err := tx.Model(&uModel). | ||
72 | + Set("delete_at", nowTime). | ||
73 | + Where("id in (?)", pg.In(ids)). | ||
74 | + Update() | ||
75 | + return err | ||
72 | } | 76 | } |
73 | 77 | ||
74 | func (repo *DepartmentRepository) FindOne(queryOptions map[string]interface{}) (*domain.Department, error) { | 78 | func (repo *DepartmentRepository) FindOne(queryOptions map[string]interface{}) (*domain.Department, error) { |
@@ -97,6 +101,9 @@ func (repo *DepartmentRepository) Find(queryOptions map[string]interface{}) (int | @@ -97,6 +101,9 @@ func (repo *DepartmentRepository) Find(queryOptions map[string]interface{}) (int | ||
97 | if v, ok := queryOptions["id"]; ok { | 101 | if v, ok := queryOptions["id"]; ok { |
98 | query.Where("id=?", v) | 102 | query.Where("id=?", v) |
99 | } | 103 | } |
104 | + if v, ok := queryOptions["ids"]; ok { | ||
105 | + query.Where("id in(?)", pg.In(v)) | ||
106 | + } | ||
100 | if v, ok := queryOptions["limit"]; ok { | 107 | if v, ok := queryOptions["limit"]; ok { |
101 | query.Limit(v.(int)) | 108 | query.Limit(v.(int)) |
102 | } | 109 | } |
-
请 注册 或 登录 后发表评论