作者 tangxvhui

更新

1 package company 1 package company
2 2
3 import ( 3 import (
  4 + "encoding/json"
4 "time" 5 "time"
5 6
6 "github.com/linmadan/egglib-go/core/application" 7 "github.com/linmadan/egglib-go/core/application"
7 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/company/command" 8 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/company/command"
8 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory" 9 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
9 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" 10 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
  11 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log"
10 ) 12 )
11 13
12 -type CompanyServices struct { 14 +type SyncDataCompanyService struct {
  15 +}
  16 +
  17 +type BusinessAdminCommand struct {
  18 + //company:公司
  19 + Module string `json:"module"`
  20 + // add:添加,edit:编辑,setCompanyCharge:更改公司主管,changeAdmin换管理员
  21 + Action string `json:"action"`
  22 + // 具体的对象JSON数据
  23 + Datas json.RawMessage `json:"data"`
13 } 24 }
14 25
15 //从BusinessAdmins 接收消息,变更公司数据 26 //从BusinessAdmins 接收消息,变更公司数据
16 -//  
17 -func (c CompanyServices) BusinessAdminCompany() error {  
18 - return nil 27 +func (c SyncDataCompanyService) FromBusinessAdminCompany(param *BusinessAdminCommand) error {
  28 + action := param.Module + "/" + param.Action
  29 + var err error
  30 + switch action {
  31 + case "company/add":
  32 + var param1 command.SaveCompanyCommand
  33 + err = json.Unmarshal(param.Datas, &param1)
  34 + if err != nil {
  35 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  36 + }
  37 + err = c.addCompany(&param1)
  38 + case "company/edit":
  39 + var param2 command.SaveCompanyCommand
  40 + err = json.Unmarshal(param.Datas, &param2)
  41 + if err != nil {
  42 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  43 + }
  44 + err = c.editCompany(&param2)
  45 + case "company/setCompanyCharge":
  46 + var param3 command.SetCompanyCharge
  47 + err = json.Unmarshal(param.Datas, &param3)
  48 + if err != nil {
  49 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  50 + }
  51 + err = c.setCompanyCharge(&param3)
  52 + case "company/changeAdmin":
  53 + var param3 command.ChangeAdminCommand
  54 + err = json.Unmarshal(param.Datas, &param3)
  55 + if err != nil {
  56 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  57 + }
  58 + err = c.changeAdmin(&param3)
  59 + default:
  60 + log.Logger.Error("action err:" + action)
  61 + }
  62 +
  63 + return err
19 } 64 }
20 65
21 //addCompany 66 //addCompany
22 //从BusinessAdmins 接收消息 添加公司 67 //从BusinessAdmins 接收消息 添加公司
23 -func (c CompanyServices) addCompany(param *command.SaveCompanyCommand) error { 68 +//module="company" action="add"
  69 +func (c SyncDataCompanyService) addCompany(param *command.SaveCompanyCommand) error {
24 transactionContext, err := factory.CreateTransactionContext(nil) 70 transactionContext, err := factory.CreateTransactionContext(nil)
25 if err != nil { 71 if err != nil {
26 return application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 72 return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -63,11 +109,11 @@ func (c CompanyServices) addCompany(param *command.SaveCompanyCommand) error { @@ -63,11 +109,11 @@ func (c CompanyServices) addCompany(param *command.SaveCompanyCommand) error {
63 }) 109 })
64 _, err = companyRepo.Insert(&newCompany) 110 _, err = companyRepo.Insert(&newCompany)
65 if err != nil { 111 if err != nil {
66 - return err 112 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
67 } 113 }
68 _, err = userRepo.Insert(&newUser) 114 _, err = userRepo.Insert(&newUser)
69 if err != nil { 115 if err != nil {
70 - return err 116 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
71 } 117 }
72 if err := transactionContext.CommitTransaction(); err != nil { 118 if err := transactionContext.CommitTransaction(); err != nil {
73 return application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 119 return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -77,7 +123,8 @@ func (c CompanyServices) addCompany(param *command.SaveCompanyCommand) error { @@ -77,7 +123,8 @@ func (c CompanyServices) addCompany(param *command.SaveCompanyCommand) error {
77 123
78 //editCompany 124 //editCompany
79 //从BusinessAdmins 接收消息 更新公司 125 //从BusinessAdmins 接收消息 更新公司
80 -func (c CompanyServices) editCompany(param *command.SaveCompanyCommand) error { 126 +//module="company" action="edit"
  127 +func (c SyncDataCompanyService) editCompany(param *command.SaveCompanyCommand) error {
81 transactionContext, err := factory.CreateTransactionContext(nil) 128 transactionContext, err := factory.CreateTransactionContext(nil)
82 if err != nil { 129 if err != nil {
83 return application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 130 return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -100,14 +147,14 @@ func (c CompanyServices) editCompany(param *command.SaveCompanyCommand) error { @@ -100,14 +147,14 @@ func (c CompanyServices) editCompany(param *command.SaveCompanyCommand) error {
100 "id": param.Comapany.Id, 147 "id": param.Comapany.Id,
101 }) 148 })
102 if err != nil { 149 if err != nil {
103 - return err 150 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
104 } 151 }
105 _, userList, err := userRepo.Find(map[string]interface{}{ 152 _, userList, err := userRepo.Find(map[string]interface{}{
106 "limit": 1, 153 "limit": 1,
107 "id": param.User.Id, 154 "id": param.User.Id,
108 }) 155 })
109 if err != nil { 156 if err != nil {
110 - return err 157 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
111 } 158 }
112 var ( 159 var (
113 newCompany *domain.Company 160 newCompany *domain.Company
@@ -146,32 +193,33 @@ func (c CompanyServices) editCompany(param *command.SaveCompanyCommand) error { @@ -146,32 +193,33 @@ func (c CompanyServices) editCompany(param *command.SaveCompanyCommand) error {
146 if len(companyList) > 0 { 193 if len(companyList) > 0 {
147 _, err = companyRepo.Update(newCompany) 194 _, err = companyRepo.Update(newCompany)
148 if err != nil { 195 if err != nil {
149 - return err 196 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
150 } 197 }
151 } else { 198 } else {
152 _, err = companyRepo.Insert(newCompany) 199 _, err = companyRepo.Insert(newCompany)
153 if err != nil { 200 if err != nil {
154 - return err 201 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
155 } 202 }
156 } 203 }
157 if len(userList) > 0 { 204 if len(userList) > 0 {
158 _, err = userRepo.Update(newUser) 205 _, err = userRepo.Update(newUser)
159 if err != nil { 206 if err != nil {
160 - return err 207 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
161 } 208 }
162 } else { 209 } else {
163 _, err = userRepo.Insert(newUser) 210 _, err = userRepo.Insert(newUser)
164 if err != nil { 211 if err != nil {
165 - return err 212 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
166 } 213 }
167 } 214 }
168 if err := transactionContext.CommitTransaction(); err != nil { 215 if err := transactionContext.CommitTransaction(); err != nil {
169 - return err 216 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
170 } 217 }
171 return nil 218 return nil
172 } 219 }
173 220
174 -func (srv CompanyServices) setCompanyCharge(param *command.SetCompanyCharge) error { 221 +//module="company" action="setCompanyCharge"
  222 +func (srv SyncDataCompanyService) setCompanyCharge(param *command.SetCompanyCharge) error {
175 transactionContext, err := factory.CreateTransactionContext(nil) 223 transactionContext, err := factory.CreateTransactionContext(nil)
176 if err != nil { 224 if err != nil {
177 return application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 225 return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -193,14 +241,14 @@ func (srv CompanyServices) setCompanyCharge(param *command.SetCompanyCharge) err @@ -193,14 +241,14 @@ func (srv CompanyServices) setCompanyCharge(param *command.SetCompanyCharge) err
193 }) 241 })
194 242
195 if err != nil { 243 if err != nil {
196 - return err 244 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
197 } 245 }
198 for i := range companyList { 246 for i := range companyList {
199 companyList[i].ChargeUserIds = param.ChargeUserIds 247 companyList[i].ChargeUserIds = param.ChargeUserIds
200 companyList[i].UpdateAt = time.Now() 248 companyList[i].UpdateAt = time.Now()
201 _, err = companyRepo.Update(companyList[i]) 249 _, err = companyRepo.Update(companyList[i])
202 if err != nil { 250 if err != nil {
203 - return err 251 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
204 } 252 }
205 } 253 }
206 if err := transactionContext.CommitTransaction(); err != nil { 254 if err := transactionContext.CommitTransaction(); err != nil {
@@ -211,7 +259,8 @@ func (srv CompanyServices) setCompanyCharge(param *command.SetCompanyCharge) err @@ -211,7 +259,8 @@ func (srv CompanyServices) setCompanyCharge(param *command.SetCompanyCharge) err
211 259
212 //changeAdmin 260 //changeAdmin
213 //从BusinessAdmins 接收消息 变更主管 261 //从BusinessAdmins 接收消息 变更主管
214 -func (srv CompanyServices) changeAdmin(param *command.ChangeAdminCommand) error { 262 +//module="company" action="changeAdmin"
  263 +func (srv SyncDataCompanyService) changeAdmin(param *command.ChangeAdminCommand) error {
215 transactionContext, err := factory.CreateTransactionContext(nil) 264 transactionContext, err := factory.CreateTransactionContext(nil)
216 if err != nil { 265 if err != nil {
217 return application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 266 return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -233,7 +282,7 @@ func (srv CompanyServices) changeAdmin(param *command.ChangeAdminCommand) error @@ -233,7 +282,7 @@ func (srv CompanyServices) changeAdmin(param *command.ChangeAdminCommand) error
233 "adminType": domain.UserTypeManager, 282 "adminType": domain.UserTypeManager,
234 }) 283 })
235 if err != nil { 284 if err != nil {
236 - return err 285 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
237 } 286 }
238 //修改旧管理员 为普通用户 287 //修改旧管理员 为普通用户
239 for i := range userList { 288 for i := range userList {
@@ -241,7 +290,7 @@ func (srv CompanyServices) changeAdmin(param *command.ChangeAdminCommand) error @@ -241,7 +290,7 @@ func (srv CompanyServices) changeAdmin(param *command.ChangeAdminCommand) error
241 userList[i].UpdateAt = time.Now() 290 userList[i].UpdateAt = time.Now()
242 _, err := userRepo.Update(userList[i]) 291 _, err := userRepo.Update(userList[i])
243 if err != nil { 292 if err != nil {
244 - return err 293 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
245 } 294 }
246 } 295 }
247 //获取新管理员 296 //获取新管理员
@@ -251,7 +300,7 @@ func (srv CompanyServices) changeAdmin(param *command.ChangeAdminCommand) error @@ -251,7 +300,7 @@ func (srv CompanyServices) changeAdmin(param *command.ChangeAdminCommand) error
251 "account": param.UserAccount, 300 "account": param.UserAccount,
252 }) 301 })
253 if err != nil { 302 if err != nil {
254 - return err 303 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
255 } 304 }
256 //修改为管理员用户 305 //修改为管理员用户
257 for i := range userList2 { 306 for i := range userList2 {
@@ -259,7 +308,7 @@ func (srv CompanyServices) changeAdmin(param *command.ChangeAdminCommand) error @@ -259,7 +308,7 @@ func (srv CompanyServices) changeAdmin(param *command.ChangeAdminCommand) error
259 userList[i].UpdateAt = time.Now() 308 userList[i].UpdateAt = time.Now()
260 _, err := userRepo.Update(userList[i]) 309 _, err := userRepo.Update(userList[i])
261 if err != nil { 310 if err != nil {
262 - return err 311 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
263 } 312 }
264 } 313 }
265 if err := transactionContext.CommitTransaction(); err != nil { 314 if err := transactionContext.CommitTransaction(); err != nil {
1 package department 1 package department
2 2
3 import ( 3 import (
  4 + "encoding/json"
4 "time" 5 "time"
5 6
6 "github.com/linmadan/egglib-go/core/application" 7 "github.com/linmadan/egglib-go/core/application"
@@ -11,10 +12,55 @@ import ( @@ -11,10 +12,55 @@ import (
11 12
12 type SyncDataDepartmentService struct{} 13 type SyncDataDepartmentService struct{}
13 14
  15 +type BusinessAdminCommand struct {
  16 + // department:部门
  17 + Module string `json:"module"`
  18 + // add:添加,edit:编辑,batchDelete:批量删除,import:导入部门
  19 + Action string `json:"action"`
  20 + // 具体的对象JSON数据
  21 + Datas json.RawMessage `json:"data"`
  22 +}
  23 +
  24 +func (srv SyncDataDepartmentService) FromBusinessAdminCompany(param BusinessAdminCommand) error {
  25 + action := param.Module + "/" + param.Action
  26 + var err error
  27 + switch action {
  28 + case "department/add":
  29 + var param1 command.AddDepartmentCommand
  30 + err = json.Unmarshal(param.Datas, &param1)
  31 + if err != nil {
  32 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  33 + }
  34 + err = srv.addDepartment(&param1)
  35 + case "department/edit":
  36 + var param1 command.EditDepartmentCommand
  37 + err = json.Unmarshal(param.Datas, &param1)
  38 + if err != nil {
  39 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  40 + }
  41 + err = srv.editDepartment(&param1)
  42 + case "department/batchDelete":
  43 + var param1 command.BatchDeleteCommand
  44 + err = json.Unmarshal(param.Datas, &param1)
  45 + if err != nil {
  46 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  47 + }
  48 + err = srv.batchDeleteDepartment(&param1)
  49 + case "department/import":
  50 + var param1 []command.ImportDepartmentCommand
  51 + err = json.Unmarshal(param.Datas, &param1)
  52 + if err != nil {
  53 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  54 + }
  55 + err = srv.importDepartment(param1)
  56 + }
  57 + return err
  58 +}
  59 +
14 //AddDepartment 60 //AddDepartment
15 //从BusinessAdmins 接收消息 添加部门 61 //从BusinessAdmins 接收消息 添加部门
16 //module="department" action="add" 62 //module="department" action="add"
17 -func (srv SyncDataDepartmentService) addDepartment(param command.AddDepartmentCommand) error { 63 +func (srv SyncDataDepartmentService) addDepartment(param *command.AddDepartmentCommand) error {
18 transactionContext, err := factory.CreateTransactionContext(nil) 64 transactionContext, err := factory.CreateTransactionContext(nil)
19 if err != nil { 65 if err != nil {
20 return application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 66 return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -56,7 +102,7 @@ func (srv SyncDataDepartmentService) addDepartment(param command.AddDepartmentCo @@ -56,7 +102,7 @@ func (srv SyncDataDepartmentService) addDepartment(param command.AddDepartmentCo
56 //EditDepartment 102 //EditDepartment
57 //从BusinessAdmins 接收消息 编辑部门 103 //从BusinessAdmins 接收消息 编辑部门
58 //module="department" action="edit" 104 //module="department" action="edit"
59 -func (srv SyncDataDepartmentService) editDepartment(param command.EditDepartmentCommand) error { 105 +func (srv SyncDataDepartmentService) editDepartment(param *command.EditDepartmentCommand) error {
60 transactionContext, err := factory.CreateTransactionContext(nil) 106 transactionContext, err := factory.CreateTransactionContext(nil)
61 if err != nil { 107 if err != nil {
62 return application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 108 return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -115,7 +161,7 @@ func (srv SyncDataDepartmentService) editDepartment(param command.EditDepartment @@ -115,7 +161,7 @@ func (srv SyncDataDepartmentService) editDepartment(param command.EditDepartment
115 //batchDelete 161 //batchDelete
116 //从BusinessAdmins 接收消息 删除部门 162 //从BusinessAdmins 接收消息 删除部门
117 //module="department" action="batchDelete" 163 //module="department" action="batchDelete"
118 -func (srv SyncDataDepartmentService) batchDeleteDepartment(param command.BatchDeleteCommand) error { 164 +func (srv SyncDataDepartmentService) batchDeleteDepartment(param *command.BatchDeleteCommand) error {
119 if len(param.Ids) == 0 { 165 if len(param.Ids) == 0 {
120 return nil 166 return nil
121 } 167 }
1 package user 1 package user
2 2
3 import ( 3 import (
  4 + "encoding/json"
4 "time" 5 "time"
5 6
  7 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log"
  8 +
6 "github.com/linmadan/egglib-go/core/application" 9 "github.com/linmadan/egglib-go/core/application"
7 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory" 10 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
8 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/user/command" 11 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/user/command"
@@ -11,10 +14,65 @@ import ( @@ -11,10 +14,65 @@ import (
11 14
12 type SyncDataUserService struct{} 15 type SyncDataUserService struct{}
13 16
  17 +type BusinessAdminCommand struct {
  18 + // employee:员工
  19 + Module string `json:"module"`
  20 + // add:添加,edit:编辑,batchDelete:批量删除,batchForbid:批量禁用用户,batchRemove:批量更改用户部门,import:导入用户
  21 + Action string `json:"action"`
  22 + // 具体的对象JSON数据
  23 + Datas json.RawMessage `json:"data"`
  24 +}
  25 +
  26 +func (srv SyncDataUserService) FromBusinessAdminCompany(param *BusinessAdminCommand) error {
  27 + action := param.Module + "/" + param.Action
  28 + var err error
  29 + switch action {
  30 + case "employee/add":
  31 + var param1 command.SaveUserCommand
  32 + err = json.Unmarshal(param.Datas, &param1)
  33 + if err != nil {
  34 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  35 + }
  36 + err = srv.AddUser(&param1)
  37 + case "employee/edit":
  38 + var param2 command.SaveUserCommand
  39 + err = json.Unmarshal(param.Datas, &param2)
  40 + if err != nil {
  41 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  42 + }
  43 + err = srv.UpdateUser(&param2)
  44 + case "employee/batchDelete":
  45 + var param3 command.BatchDeleteCommand
  46 + err = json.Unmarshal(param.Datas, &param3)
  47 + if err != nil {
  48 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  49 + }
  50 + err = srv.batchDelete(&param3)
  51 + case "company/batchForbid":
  52 + var param4 command.BatchForbidCommand
  53 + err = json.Unmarshal(param.Datas, &param4)
  54 + if err != nil {
  55 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  56 + }
  57 + err = srv.batchForbid(&param4)
  58 + case "company/import":
  59 + var param4 command.ImportUserCommand
  60 + err = json.Unmarshal(param.Datas, &param4)
  61 + if err != nil {
  62 + return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  63 + }
  64 + err = srv.importUser(&param4)
  65 + default:
  66 + log.Logger.Error("action err:" + action)
  67 + }
  68 +
  69 + return err
  70 +}
  71 +
14 //AddUser 72 //AddUser
15 //从BusinessAdmins 接收消息 添加用户 73 //从BusinessAdmins 接收消息 添加用户
16 //module="employee" action="add" 74 //module="employee" action="add"
17 -func (srv SyncDataUserService) AddUser(param command.SaveUserCommand) error { 75 +func (srv SyncDataUserService) AddUser(param *command.SaveUserCommand) error {
18 transactionContext, err := factory.CreateTransactionContext(nil) 76 transactionContext, err := factory.CreateTransactionContext(nil)
19 if err != nil { 77 if err != nil {
20 return application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 78 return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -59,7 +117,7 @@ func (srv SyncDataUserService) AddUser(param command.SaveUserCommand) error { @@ -59,7 +117,7 @@ func (srv SyncDataUserService) AddUser(param command.SaveUserCommand) error {
59 //UpdateUser 117 //UpdateUser
60 //从BusinessAdmins 接收消息 更新用户 118 //从BusinessAdmins 接收消息 更新用户
61 //module="employee" action="edit" 119 //module="employee" action="edit"
62 -func (srv SyncDataUserService) UpdateUser(param command.SaveUserCommand) error { 120 +func (srv SyncDataUserService) UpdateUser(param *command.SaveUserCommand) error {
63 transactionContext, err := factory.CreateTransactionContext(nil) 121 transactionContext, err := factory.CreateTransactionContext(nil)
64 if err != nil { 122 if err != nil {
65 return application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 123 return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -119,7 +177,7 @@ func (srv SyncDataUserService) UpdateUser(param command.SaveUserCommand) error { @@ -119,7 +177,7 @@ func (srv SyncDataUserService) UpdateUser(param command.SaveUserCommand) error {
119 //batchDelete 177 //batchDelete
120 //从BusinessAdmins 接收消息 删除用户 178 //从BusinessAdmins 接收消息 删除用户
121 //module="employee" action="batchDelete" 179 //module="employee" action="batchDelete"
122 -func (srv SyncDataUserService) batchDelete(param command.BatchDeleteCommand) error { 180 +func (srv SyncDataUserService) batchDelete(param *command.BatchDeleteCommand) error {
123 if len(param.Uids) == 0 { 181 if len(param.Uids) == 0 {
124 return nil 182 return nil
125 } 183 }
@@ -150,7 +208,7 @@ func (srv SyncDataUserService) batchDelete(param command.BatchDeleteCommand) err @@ -150,7 +208,7 @@ func (srv SyncDataUserService) batchDelete(param command.BatchDeleteCommand) err
150 //batchForbid 208 //batchForbid
151 //从BusinessAdmins 接收消息 禁用,启用用户 209 //从BusinessAdmins 接收消息 禁用,启用用户
152 //module="employee" action="batchForbid" 210 //module="employee" action="batchForbid"
153 -func (srv SyncDataUserService) batchForbid(param command.BatchForbidCommand) error { 211 +func (srv SyncDataUserService) batchForbid(param *command.BatchForbidCommand) error {
154 if len(param.Uids) == 0 { 212 if len(param.Uids) == 0 {
155 return nil 213 return nil
156 } 214 }
@@ -190,7 +248,7 @@ func (srv SyncDataUserService) batchForbid(param command.BatchForbidCommand) err @@ -190,7 +248,7 @@ func (srv SyncDataUserService) batchForbid(param command.BatchForbidCommand) err
190 //importUser 248 //importUser
191 //从BusinessAdmins 接收消息 导入用户数据 249 //从BusinessAdmins 接收消息 导入用户数据
192 //module="employee" action="import" 250 //module="employee" action="import"
193 -func (srv SyncDataUserService) importUser(param command.ImportUserCommand) error { 251 +func (srv SyncDataUserService) importUser(param *command.ImportUserCommand) error {
194 transactionContext, err := factory.CreateTransactionContext(nil) 252 transactionContext, err := factory.CreateTransactionContext(nil)
195 if err != nil { 253 if err != nil {
196 return application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 254 return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  1 +package domain
  2 +
  3 +import "time"
  4 +
  5 +type ReceivedMessage struct {
  6 + MessageId int64
  7 + MessageType string
  8 + MessageBody string
  9 + OccurredOn time.Time
  10 + CreateAt time.Time
  11 +}
  12 +
  13 +type ReceivedMessageRepository interface {
  14 + SaveMessage(param *ReceivedMessage) error
  15 + FindMessage(id int64) (*ReceivedMessage, error)
  16 +}
@@ -3,11 +3,12 @@ package pg @@ -3,11 +3,12 @@ package pg
3 import ( 3 import (
4 "fmt" 4 "fmt"
5 5
6 - "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log"  
7 -  
8 "github.com/go-pg/pg/v10" 6 "github.com/go-pg/pg/v10"
  7 + "github.com/go-pg/pg/v10/orm"
9 "github.com/linmadan/egglib-go/persistent/pg/hooks" 8 "github.com/linmadan/egglib-go/persistent/pg/hooks"
10 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/constant" 9 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/constant"
  10 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/pg/models"
  11 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log"
11 ) 12 )
12 13
13 var DB *pg.DB 14 var DB *pg.DB
@@ -24,5 +25,22 @@ func init() { @@ -24,5 +25,22 @@ func init() {
24 Logger: log.Logger, 25 Logger: log.Logger,
25 }) 26 })
26 } 27 }
  28 + if !constant.DISABLE_CREATE_TABLE {
  29 + tables := []interface{}{
  30 + &models.Company{},
  31 + &models.Department{},
  32 + &models.User{},
  33 + }
  34 + for _, model := range tables {
  35 + err := DB.Model(model).CreateTable(&orm.CreateTableOptions{
  36 + Temp: false,
  37 + IfNotExists: true,
  38 + FKConstraints: true,
  39 + })
  40 + if err != nil {
  41 + panic(err)
  42 + }
  43 + }
  44 + }
27 45
28 } 46 }
  1 +package models
  2 +
  3 +import "time"
  4 +
  5 +type ReceivedMessage struct {
  6 + tableName struct{} `pg:"received_message"`
  7 + MessageId int64 `pg:"pk:message_id"`
  8 + MessageType string
  9 + MessageBody string
  10 + OccurredOn time.Time
  11 + CreateAt time.Time
  12 +}
  1 +package repository
  2 +
  3 +import (
  4 + "time"
  5 +
  6 + pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
  7 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
  8 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/pg/models"
  9 +)
  10 +
  11 +type ReceivedMessageRepository struct {
  12 + transactionContext *pgTransaction.TransactionContext
  13 +}
  14 +
  15 +var _ domain.ReceivedMessageRepository = (*ReceivedMessageRepository)(nil)
  16 +
  17 +func (repo *ReceivedMessageRepository) SaveMessage(param *domain.ReceivedMessage) error {
  18 + message := &models.ReceivedMessage{
  19 + MessageId: param.MessageId,
  20 + MessageType: param.MessageType,
  21 + MessageBody: param.MessageBody,
  22 + OccurredOn: param.OccurredOn,
  23 + CreateAt: time.Now(),
  24 + }
  25 + tx := repo.transactionContext.PgTx
  26 + _, err := tx.Model(message).
  27 + Insert()
  28 + return err
  29 +}
  30 +
  31 +func (repo *ReceivedMessageRepository) FindMessage(messageId int64) (*domain.ReceivedMessage, error) {
  32 + tx := repo.transactionContext.PgTx
  33 + receivedMessageModel := new(models.ReceivedMessage)
  34 + query := tx.Model(receivedMessageModel).Where("message.id = ?", messageId)
  35 + if err := query.First(); err != nil {
  36 + if err.Error() != "pg: no rows in result set" {
  37 + return nil, err
  38 + }
  39 + }
  40 + message := &domain.ReceivedMessage{
  41 + MessageId: receivedMessageModel.MessageId,
  42 + MessageType: receivedMessageModel.MessageType,
  43 + MessageBody: receivedMessageModel.MessageBody,
  44 + OccurredOn: receivedMessageModel.OccurredOn,
  45 + CreateAt: receivedMessageModel.CreateAt,
  46 + }
  47 + return message, nil
  48 +
  49 +}