正在显示
14 个修改的文件
包含
426 行增加
和
37 行删除
@@ -39,10 +39,7 @@ func (adminPermissionSrv AdminPermissionService) ListAdminPermission(queryOption | @@ -39,10 +39,7 @@ func (adminPermissionSrv AdminPermissionService) ListAdminPermission(queryOption | ||
39 | } else { | 39 | } else { |
40 | permissionRepository = value | 40 | permissionRepository = value |
41 | } | 41 | } |
42 | - permissions, err = permissionRepository.Find(domain.AdminPermissionFindQuery{ | ||
43 | - NotCode: queryOption.NotCode, | ||
44 | - ParentId: queryOption.ParentId, | ||
45 | - }) | 42 | + permissions, err = permissionRepository.Find(map[string]interface{}{}) |
46 | if err != nil { | 43 | if err != nil { |
47 | return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | 44 | return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) |
48 | } | 45 | } |
@@ -87,8 +87,8 @@ func (adminUserSrv AdminUserService) SaveAdminUser(saveUserCmd *command.SaveAdmi | @@ -87,8 +87,8 @@ func (adminUserSrv AdminUserService) SaveAdminUser(saveUserCmd *command.SaveAdmi | ||
87 | } else { | 87 | } else { |
88 | permissionRepository = value | 88 | permissionRepository = value |
89 | } | 89 | } |
90 | - permissions, err = permissionRepository.Find(domain.AdminPermissionFindQuery{ | ||
91 | - IdsIn: saveUserCmd.PermissionId, | 90 | + permissions, err = permissionRepository.Find(map[string]interface{}{ |
91 | + "IdsIn": saveUserCmd.PermissionId, | ||
92 | }) | 92 | }) |
93 | if err != nil { | 93 | if err != nil { |
94 | return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | 94 | return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) |
pkg/application/company/service/service.go
0 → 100644
1 | +package service | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/factory" | ||
7 | + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain" | ||
8 | + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib" | ||
9 | +) | ||
10 | + | ||
11 | +type CompanyService struct{} | ||
12 | + | ||
13 | +func NewCompanyService(options map[string]interface{}) *CompanyService { | ||
14 | + newCompanyService := &CompanyService{} | ||
15 | + return newCompanyService | ||
16 | +} | ||
17 | + | ||
18 | +//AllowCompany 公司启用合伙人功能 | ||
19 | +func (service CompanyService) AllowCompany(companyId int64) error { | ||
20 | + var ( | ||
21 | + transactionContext, _ = factory.CreateTransactionContext(nil) | ||
22 | + err error | ||
23 | + ) | ||
24 | + if err = transactionContext.StartTransaction(); err != nil { | ||
25 | + return err | ||
26 | + } | ||
27 | + defer func() { | ||
28 | + transactionContext.RollbackTransaction() | ||
29 | + }() | ||
30 | + var ( | ||
31 | + companyRespository domain.CompanyRepository | ||
32 | + oldCompanyData domain.Company | ||
33 | + ) | ||
34 | + if companyRespository, err = factory.CreateCompanyRepository(map[string]interface{}{ | ||
35 | + "transactionContext": transactionContext, | ||
36 | + }); err != nil { | ||
37 | + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
38 | + } | ||
39 | + oldCompanyData, err = companyRespository.FindOne(map[string]interface{}{ | ||
40 | + "Id": companyId, | ||
41 | + }) | ||
42 | + if err != nil { | ||
43 | + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("获取公司(id=%d)的数据失败:%s", companyId, err.Error())) | ||
44 | + } | ||
45 | + err = oldCompanyData.Update(map[string]interface{}{ | ||
46 | + "Enable": domain.CompanyEnableYes, | ||
47 | + }) | ||
48 | + if err != nil { | ||
49 | + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
50 | + } | ||
51 | + //更新公司数据 | ||
52 | + err = companyRespository.Edit(&oldCompanyData) | ||
53 | + if err != nil { | ||
54 | + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("更新公司(id=%d)的数据失败:%s", companyId, err.Error())) | ||
55 | + } | ||
56 | + err = transactionContext.CommitTransaction() | ||
57 | + return nil | ||
58 | +} | ||
59 | + | ||
60 | +//ForbidCompany 公司禁用合伙人功能 | ||
61 | +func (service CompanyService) ForbidCompany(companyId int64) error { | ||
62 | + var ( | ||
63 | + transactionContext, _ = factory.CreateTransactionContext(nil) | ||
64 | + err error | ||
65 | + ) | ||
66 | + if err = transactionContext.StartTransaction(); err != nil { | ||
67 | + return err | ||
68 | + } | ||
69 | + defer func() { | ||
70 | + transactionContext.RollbackTransaction() | ||
71 | + }() | ||
72 | + var ( | ||
73 | + companyRespository domain.CompanyRepository | ||
74 | + oldCompanyData domain.Company | ||
75 | + ) | ||
76 | + if companyRespository, err = factory.CreateCompanyRepository(map[string]interface{}{ | ||
77 | + "transactionContext": transactionContext, | ||
78 | + }); err != nil { | ||
79 | + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
80 | + } | ||
81 | + oldCompanyData, err = companyRespository.FindOne(map[string]interface{}{ | ||
82 | + "Id": companyId, | ||
83 | + }) | ||
84 | + if err != nil { | ||
85 | + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("获取公司(id=%d)的数据失败:%s", companyId, err.Error())) | ||
86 | + } | ||
87 | + err = oldCompanyData.Update(map[string]interface{}{ | ||
88 | + "Enable": domain.CompanyEnableNo, | ||
89 | + }) | ||
90 | + if err != nil { | ||
91 | + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
92 | + } | ||
93 | + //更新公司数据 | ||
94 | + err = companyRespository.Edit(&oldCompanyData) | ||
95 | + if err != nil { | ||
96 | + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("更新公司(id=%d)的数据失败:%s", companyId, err.Error())) | ||
97 | + } | ||
98 | + err = transactionContext.CommitTransaction() | ||
99 | + return nil | ||
100 | +} | ||
101 | + | ||
102 | +//GetCompanyData 获取公司数据 | ||
103 | +func (service CompanyService) GetCompanyData(companyId int64) (*domain.Company, error) { | ||
104 | + var ( | ||
105 | + transactionContext, _ = factory.CreateTransactionContext(nil) | ||
106 | + err error | ||
107 | + ) | ||
108 | + if err = transactionContext.StartTransaction(); err != nil { | ||
109 | + return nil, err | ||
110 | + } | ||
111 | + defer func() { | ||
112 | + transactionContext.RollbackTransaction() | ||
113 | + }() | ||
114 | + var ( | ||
115 | + companyRespository domain.CompanyRepository | ||
116 | + companyData domain.Company | ||
117 | + ) | ||
118 | + if companyRespository, err = factory.CreateCompanyRepository(map[string]interface{}{ | ||
119 | + "transactionContext": transactionContext, | ||
120 | + }); err != nil { | ||
121 | + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
122 | + } | ||
123 | + companyData, err = companyRespository.FindOne(map[string]interface{}{ | ||
124 | + "Id": companyId, | ||
125 | + }) | ||
126 | + if err != nil { | ||
127 | + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("获取公司(id=%d)的数据失败:%s", companyId, err.Error())) | ||
128 | + } | ||
129 | + err = transactionContext.CommitTransaction() | ||
130 | + return &companyData, nil | ||
131 | +} |
@@ -13,6 +13,8 @@ import ( | @@ -13,6 +13,8 @@ import ( | ||
13 | 13 | ||
14 | type SyncCompanyService struct{} | 14 | type SyncCompanyService struct{} |
15 | 15 | ||
16 | +var _ SyncAction = (*SyncCompanyService)(nil) | ||
17 | + | ||
16 | //企业平台的公司基础数据 | 18 | //企业平台的公司基础数据 |
17 | type CompanyBase struct { | 19 | type CompanyBase struct { |
18 | Id int64 `json:"id"` //id | 20 | Id int64 `json:"id"` //id |
@@ -73,7 +75,6 @@ func (service SyncCompanyService) DoAction(action string, byteData []byte) error | @@ -73,7 +75,6 @@ func (service SyncCompanyService) DoAction(action string, byteData []byte) error | ||
73 | default: | 75 | default: |
74 | return errors.New("action not found") | 76 | return errors.New("action not found") |
75 | } | 77 | } |
76 | - return nil | ||
77 | } | 78 | } |
78 | 79 | ||
79 | func (service SyncCompanyService) addCompany(data CompanytData) error { | 80 | func (service SyncCompanyService) addCompany(data CompanytData) error { |
@@ -252,14 +253,14 @@ func (service SyncCompanyService) updateCompanyCharge(data CompanyCharge) error | @@ -252,14 +253,14 @@ func (service SyncCompanyService) updateCompanyCharge(data CompanyCharge) error | ||
252 | "Id": v, | 253 | "Id": v, |
253 | }) | 254 | }) |
254 | if err != nil { | 255 | if err != nil { |
255 | - return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("获取用户id=%d的失败:%s", v, err.Error())) | 256 | + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("获取用户(id=%d)的数据失败:%s", v, err.Error())) |
256 | } | 257 | } |
257 | _ = userToUpdate.Update(map[string]interface{}{ | 258 | _ = userToUpdate.Update(map[string]interface{}{ |
258 | "charge_status": domain.UserIsCompanyCharge, | 259 | "charge_status": domain.UserIsCompanyCharge, |
259 | }) | 260 | }) |
260 | err = userRespository.Edit(&userToUpdate) | 261 | err = userRespository.Edit(&userToUpdate) |
261 | if err != nil { | 262 | if err != nil { |
262 | - return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("更新用户id=%d的失败:%s", v, err.Error())) | 263 | + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, fmt.Sprintf("更新用户(id=%d)的数据失败:%s", v, err.Error())) |
263 | } | 264 | } |
264 | } | 265 | } |
265 | err = transactionContext.CommitTransaction() | 266 | err = transactionContext.CommitTransaction() |
@@ -7,6 +7,7 @@ import ( | @@ -7,6 +7,7 @@ import ( | ||
7 | "time" | 7 | "time" |
8 | 8 | ||
9 | "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/factory" | 9 | "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/factory" |
10 | + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/unifiedUserCenter/command" | ||
10 | "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain" | 11 | "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/infrastructure/dao" |
12 | "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib" | 13 | "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib" |
@@ -75,6 +76,13 @@ type ImportEmployeeData struct { | @@ -75,6 +76,13 @@ type ImportEmployeeData struct { | ||
75 | //SyncEmployeeService 同步用户数据 | 76 | //SyncEmployeeService 同步用户数据 |
76 | type SyncEmployeeService struct{} | 77 | type SyncEmployeeService struct{} |
77 | 78 | ||
79 | +func NewSyncEmployeeService(option map[string]interface{}) *SyncEmployeeService { | ||
80 | + syncEmployee := new(SyncEmployeeService) | ||
81 | + return syncEmployee | ||
82 | +} | ||
83 | + | ||
84 | +var _ SyncAction = (*SyncEmployeeService)(nil) | ||
85 | + | ||
78 | func (service SyncEmployeeService) DoAction(action string, byteData []byte) error { | 86 | func (service SyncEmployeeService) DoAction(action string, byteData []byte) error { |
79 | switch action { | 87 | switch action { |
80 | case "add": | 88 | case "add": |
@@ -297,6 +305,82 @@ func (service SyncEmployeeService) updateUsersStatus(data ForbidAllowUserData) e | @@ -297,6 +305,82 @@ func (service SyncEmployeeService) updateUsersStatus(data ForbidAllowUserData) e | ||
297 | } | 305 | } |
298 | 306 | ||
299 | //ChangeAdmin 变更公司负责人,超级管理员 | 307 | //ChangeAdmin 变更公司负责人,超级管理员 |
300 | -func (service SyncEmployeeService) ChangeAdmin() error { | 308 | +func (service SyncEmployeeService) ChangeSuperAdmin(cmd command.ChanceSuperAdminCommand) error { |
309 | + var ( | ||
310 | + transactionContext, _ = factory.CreateTransactionContext(nil) | ||
311 | + err error | ||
312 | + ) | ||
313 | + if err = transactionContext.StartTransaction(); err != nil { | ||
314 | + return err | ||
315 | + } | ||
316 | + defer func() { | ||
317 | + transactionContext.RollbackTransaction() | ||
318 | + }() | ||
319 | + var usersRepository domain.UsersRepository | ||
320 | + if usersRepository, err = factory.CreateUsersRepository(map[string]interface{}{ | ||
321 | + "transactionContext": transactionContext, | ||
322 | + }); err != nil { | ||
323 | + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
324 | + } | ||
325 | + var ( | ||
326 | + oldSuperUser domain.Users | ||
327 | + newSuperUser domain.Users | ||
328 | + userList []domain.Users | ||
329 | + ) | ||
330 | + _, userList, err = usersRepository.Find(map[string]interface{}{ | ||
331 | + "CompanyId": cmd.CompanyId, | ||
332 | + "AdminType": domain.UserIsAdmin, | ||
333 | + }) | ||
334 | + if err != nil { | ||
335 | + e := fmt.Sprintf("获取用户(admin_type=%d;company_id=%d)数据失败:%s", | ||
336 | + domain.UserIsAdmin, cmd.CompanyId, err.Error()) | ||
337 | + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e) | ||
338 | + } | ||
339 | + if len(userList) == 0 { | ||
340 | + e := fmt.Sprintf("没有获得公司主管数据(admin_type=%d;company_id=%d)", | ||
341 | + domain.UserIsAdmin, cmd.CompanyId) | ||
342 | + return lib.ThrowError(lib.BUSINESS_ERROR, e) | ||
343 | + } | ||
344 | + if len(userList) > 1 { | ||
345 | + e := fmt.Sprintf("存在复数公司主管数据(admin_type=%d;company_id=%d)", | ||
346 | + domain.UserIsAdmin, cmd.CompanyId) | ||
347 | + return lib.ThrowError(lib.BUSINESS_ERROR, e) | ||
348 | + } | ||
349 | + oldSuperUser = userList[0] | ||
350 | + newSuperUser, err = usersRepository.FindOne(map[string]interface{}{ | ||
351 | + "CompanyId": cmd.CompanyId, | ||
352 | + "Phone": cmd.Phone, | ||
353 | + }) | ||
354 | + if err != nil { | ||
355 | + e := fmt.Sprintf("获取公司用户数据(phone=%s;company_id=%d)", | ||
356 | + cmd.Phone, cmd.CompanyId) | ||
357 | + return lib.ThrowError(lib.BUSINESS_ERROR, e) | ||
358 | + } | ||
359 | + err = oldSuperUser.Update(map[string]interface{}{ | ||
360 | + "AdminType": domain.UserIsNotAdmin, | ||
361 | + }) | ||
362 | + if err != nil { | ||
363 | + return lib.ThrowError(lib.BUSINESS_ERROR, err.Error()) | ||
364 | + } | ||
365 | + //提取到domain??? | ||
366 | + err = newSuperUser.Update(map[string]interface{}{ | ||
367 | + "AdminType": domain.UserIsAdmin, | ||
368 | + }) | ||
369 | + if err != nil { | ||
370 | + return lib.ThrowError(lib.BUSINESS_ERROR, err.Error()) | ||
371 | + } | ||
372 | + err = usersRepository.Edit(&oldSuperUser) | ||
373 | + if err != nil { | ||
374 | + e := fmt.Sprintf("更新公司主管user数据(id=%d)", | ||
375 | + oldSuperUser.Id) | ||
376 | + return lib.ThrowError(lib.BUSINESS_ERROR, e) | ||
377 | + } | ||
378 | + err = usersRepository.Edit(&newSuperUser) | ||
379 | + if err != nil { | ||
380 | + e := fmt.Sprintf("更新公司主管user数据(id=%d)", | ||
381 | + newSuperUser.Id) | ||
382 | + return lib.ThrowError(lib.BUSINESS_ERROR, e) | ||
383 | + } | ||
384 | + err = transactionContext.CommitTransaction() | ||
301 | return nil | 385 | return nil |
302 | } | 386 | } |
1 | package service | 1 | package service |
2 | 2 | ||
3 | -import "errors" | 3 | +import ( |
4 | + "errors" | ||
4 | 5 | ||
5 | -//PlatformAction 企业平台数据同步服务 接口设定 | ||
6 | -type PlatformAction interface { | 6 | + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/unifiedUserCenter/command" |
7 | +) | ||
8 | + | ||
9 | +//PlatformAction 企业平台数据同步服务 动作接口设定 | ||
10 | +type SyncAction interface { | ||
7 | DoAction(string, []byte) error | 11 | DoAction(string, []byte) error |
8 | } | 12 | } |
9 | 13 | ||
10 | -var actionmap = map[string]PlatformAction{ | 14 | +//actionMap 数据同步需要的动作集合,静态不要在运行时变更这里的数据 |
15 | +var actionMap = map[string]SyncAction{ | ||
11 | // "department": | 16 | // "department": |
12 | // "position": | 17 | // "position": |
13 | "employee": SyncEmployeeService{}, | 18 | "employee": SyncEmployeeService{}, |
14 | "company": SyncCompanyService{}, | 19 | "company": SyncCompanyService{}, |
15 | } | 20 | } |
16 | 21 | ||
17 | -func NewPlatformAction(module string) (PlatformAction, error) { | ||
18 | - if v, ok := actionmap[module]; ok { | ||
19 | - return v, nil | 22 | +func NewSyncAction(cmd command.SyncCallbackCommand) error { |
23 | + err := cmd.ValidateCommand() | ||
24 | + if err != nil { | ||
25 | + return err | ||
26 | + } | ||
27 | + var ( | ||
28 | + action SyncAction | ||
29 | + ok bool | ||
30 | + ) | ||
31 | + if action, ok = actionMap[cmd.Module]; !ok { | ||
32 | + return errors.New("module cannot found") | ||
20 | } | 33 | } |
21 | - return nil, errors.New("module cannot found") | 34 | + return action.DoAction(cmd.Action, cmd.Data) |
22 | } | 35 | } |
@@ -26,12 +26,6 @@ type AdminPermission struct { | @@ -26,12 +26,6 @@ type AdminPermission struct { | ||
26 | Icon string `json:"icon"` | 26 | Icon string `json:"icon"` |
27 | } | 27 | } |
28 | 28 | ||
29 | -type AdminPermissionFindQuery struct { | ||
30 | - IdsIn []int | ||
31 | - NotCode []string | ||
32 | - ParentId interface{} | ||
33 | -} | ||
34 | - | ||
35 | type AdminPermissionRepository interface { | 29 | type AdminPermissionRepository interface { |
36 | - Find(queryOptions AdminPermissionFindQuery) ([]AdminPermission, error) | 30 | + Find(map[string]interface{}) ([]AdminPermission, error) |
37 | } | 31 | } |
@@ -14,6 +14,12 @@ const ( | @@ -14,6 +14,12 @@ const ( | ||
14 | UserIsNotCompanyCharge int8 = 2 | 14 | UserIsNotCompanyCharge int8 = 2 |
15 | ) | 15 | ) |
16 | 16 | ||
17 | +//用户类型 1普通用户 2主管理员 | ||
18 | +const ( | ||
19 | + UserIsNotAdmin int8 = 1 | ||
20 | + UserIsAdmin int8 = 2 | ||
21 | +) | ||
22 | + | ||
17 | //Users 企业平台的用户 | 23 | //Users 企业平台的用户 |
18 | type Users struct { | 24 | type Users struct { |
19 | Id int64 //用户id | 25 | Id int64 //用户id |
@@ -36,7 +42,7 @@ type Users struct { | @@ -36,7 +42,7 @@ type Users struct { | ||
36 | UpdateAt time.Time | 42 | UpdateAt time.Time |
37 | Permission []AdminPermissionBase //权限 | 43 | Permission []AdminPermissionBase //权限 |
38 | AccessPartners []Partner | 44 | AccessPartners []Partner |
39 | - AdminType int8 //是否是公司负责人,即超级管理员 | 45 | + AdminType int8 //是否是公司负责人,即超级管理员 1普通用户 2主管理员 |
40 | } | 46 | } |
41 | 47 | ||
42 | //IsUsable 用户是否可用 | 48 | //IsUsable 用户是否可用 |
@@ -33,18 +33,13 @@ func (reponsitory AdminPermissionRepository) transformPgModelToDomainModel(permi | @@ -33,18 +33,13 @@ func (reponsitory AdminPermissionRepository) transformPgModelToDomainModel(permi | ||
33 | return result, nil | 33 | return result, nil |
34 | } | 34 | } |
35 | 35 | ||
36 | -func (reponsitory AdminPermissionRepository) Find(queryOptions domain.AdminPermissionFindQuery) ([]domain.AdminPermission, error) { | 36 | +func (reponsitory AdminPermissionRepository) Find(queryOptions map[string]interface{}) ([]domain.AdminPermission, error) { |
37 | db := reponsitory.transactionContext.PgDd | 37 | db := reponsitory.transactionContext.PgDd |
38 | permissionModels := make([]models.AdminPermission, 0) | 38 | permissionModels := make([]models.AdminPermission, 0) |
39 | query := db.Model(&permissionModels) | 39 | query := db.Model(&permissionModels) |
40 | - if queryOptions.ParentId != nil { | ||
41 | - query = query.Where("parent_id=?", queryOptions.ParentId) | ||
42 | - } | ||
43 | - if len(queryOptions.NotCode) > 0 { | ||
44 | - query = query.WhereIn("code not in (?) ", queryOptions.NotCode) | ||
45 | - } | ||
46 | - if len(queryOptions.IdsIn) > 0 { | ||
47 | - query = query.WhereIn(" id in (?) ", queryOptions.IdsIn) | 40 | + if v, ok := queryOptions["IdsIn"]; ok { |
41 | + in := v.([]int) | ||
42 | + query = query.WhereIn("id in (?) ", in) | ||
48 | } | 43 | } |
49 | if err := query.Select(); err != nil { | 44 | if err := query.Select(); err != nil { |
50 | return nil, err | 45 | return nil, err |
@@ -113,18 +113,21 @@ func (reponsitory UsersRepository) Edit(u *domain.Users) error { | @@ -113,18 +113,21 @@ func (reponsitory UsersRepository) Edit(u *domain.Users) error { | ||
113 | 113 | ||
114 | func (reponsitory UsersRepository) FindOne(queryOptions map[string]interface{}) (domain.Users, error) { | 114 | func (reponsitory UsersRepository) FindOne(queryOptions map[string]interface{}) (domain.Users, error) { |
115 | if len(queryOptions) == 0 { | 115 | if len(queryOptions) == 0 { |
116 | - return domain.Users{}, errors.New("queryOptions empty") | 116 | + return domain.Users{}, errors.New("queryOptions is empty") |
117 | } | 117 | } |
118 | var ( | 118 | var ( |
119 | err error | 119 | err error |
120 | tx = reponsitory.transactionContext.PgTx | 120 | tx = reponsitory.transactionContext.PgTx |
121 | m models.Users | 121 | m models.Users |
122 | ) | 122 | ) |
123 | - | ||
124 | query := tx.Model(&m) | 123 | query := tx.Model(&m) |
124 | + query.Where("deleted_at ISNULL") | ||
125 | if v, ok := queryOptions["Id"]; ok { | 125 | if v, ok := queryOptions["Id"]; ok { |
126 | query = query.Where("id=?", v) | 126 | query = query.Where("id=?", v) |
127 | } | 127 | } |
128 | + if v, ok := queryOptions["phone"]; ok { | ||
129 | + query = query.Where("phone=?", v) | ||
130 | + } | ||
128 | err = query.First() | 131 | err = query.First() |
129 | if err != nil { | 132 | if err != nil { |
130 | return domain.Users{}, err | 133 | return domain.Users{}, err |
@@ -136,12 +139,16 @@ func (reponsitory UsersRepository) Find(queryOption map[string]interface{}) (int | @@ -136,12 +139,16 @@ func (reponsitory UsersRepository) Find(queryOption map[string]interface{}) (int | ||
136 | db := reponsitory.transactionContext.PgTx | 139 | db := reponsitory.transactionContext.PgTx |
137 | usersModels := []models.Users{} | 140 | usersModels := []models.Users{} |
138 | query := db.Model(&usersModels) | 141 | query := db.Model(&usersModels) |
142 | + query.Where("deleted_at ISNULL") | ||
139 | if v, ok := queryOption["CompanyId"]; ok { | 143 | if v, ok := queryOption["CompanyId"]; ok { |
140 | query = query.Where("company_id=?", v) | 144 | query = query.Where("company_id=?", v) |
141 | } | 145 | } |
142 | if v, ok := queryOption["ChargeStatus"]; ok { | 146 | if v, ok := queryOption["ChargeStatus"]; ok { |
143 | query = query.Where("charge_status=?", v) | 147 | query = query.Where("charge_status=?", v) |
144 | } | 148 | } |
149 | + if v, ok := queryOption["AdminType"]; ok { | ||
150 | + query = query.Where("admin_type=?", v) | ||
151 | + } | ||
145 | if v, ok := queryOption["Offset"]; ok { | 152 | if v, ok := queryOption["Offset"]; ok { |
146 | offset := v.(int) | 153 | offset := v.(int) |
147 | query = query.Offset(offset) | 154 | query = query.Offset(offset) |
@@ -230,6 +230,9 @@ func (c *AdminUserController) BeforeEditAdminUser() { | @@ -230,6 +230,9 @@ func (c *AdminUserController) BeforeEditAdminUser() { | ||
230 | } | 230 | } |
231 | var rspData []map[string]interface{} | 231 | var rspData []map[string]interface{} |
232 | for i := range allPermission { | 232 | for i := range allPermission { |
233 | + if allPermission[i].Code == domain.PERMINSSION_ADMIN_USER { | ||
234 | + continue | ||
235 | + } | ||
233 | m := map[string]interface{}{ | 236 | m := map[string]interface{}{ |
234 | "id": allPermission[i].Id, | 237 | "id": allPermission[i].Id, |
235 | "permissionName": allPermission[i].Name, | 238 | "permissionName": allPermission[i].Name, |
1 | +package controllers | ||
2 | + | ||
3 | +//用于和企业平台和总后台进行数据通讯 | ||
4 | +import ( | ||
5 | + "encoding/json" | ||
6 | + "errors" | ||
7 | + | ||
8 | + "github.com/astaxie/beego/logs" | ||
9 | + companyService "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/company/service" | ||
10 | + syncCmd "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/unifiedUserCenter/command" | ||
11 | + syncService "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/unifiedUserCenter/service" | ||
12 | + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain" | ||
13 | +) | ||
14 | + | ||
15 | +type SyncDataController struct { | ||
16 | + BaseController | ||
17 | +} | ||
18 | + | ||
19 | +////Prepare 重写 BaseController 的Prepare方法 | ||
20 | +func (c *SyncDataController) Prepare() { | ||
21 | + c.BaseController.Prepare() | ||
22 | +} | ||
23 | + | ||
24 | +//SyncData 和企业后台同步数据 | ||
25 | +func (c *SyncDataController) SyncData() { | ||
26 | + var ( | ||
27 | + cmd syncCmd.SyncCallbackCommand | ||
28 | + err error | ||
29 | + ) | ||
30 | + if err = c.BindJsonData(&cmd); err != nil { | ||
31 | + logs.Error(err) | ||
32 | + c.ResponseError(errors.New("json数据解析失败")) | ||
33 | + return | ||
34 | + } | ||
35 | + err = syncService.NewSyncAction(cmd) | ||
36 | + if err != nil { | ||
37 | + logs.Error("同步数据异常;%s", err) | ||
38 | + } | ||
39 | + //不论子系统如何处理以及处理结果成功失败 必须返回 0 | ||
40 | + c.ResponseData(nil) | ||
41 | + return | ||
42 | +} | ||
43 | + | ||
44 | +//CompanyAdminChance 变更公司主管(超级管理) | ||
45 | +func (c *SyncDataController) CompanyAdminChance() { | ||
46 | + | ||
47 | + var ( | ||
48 | + param syncCmd.ChanceSuperAdminCommand | ||
49 | + err error | ||
50 | + ) | ||
51 | + if err = c.BindJsonData(¶m); err != nil { | ||
52 | + logs.Error(err) | ||
53 | + c.ResponseError(errors.New("json数据解析失败")) | ||
54 | + return | ||
55 | + } | ||
56 | + syncEmployeeSrv := syncService.NewSyncEmployeeService(nil) | ||
57 | + syncEmployeeSrv.ChangeSuperAdmin(param) | ||
58 | + if err != nil { | ||
59 | + logs.Error("变更公司的主管失败;%s", err) | ||
60 | + } | ||
61 | + c.ResponseData(nil) | ||
62 | + return | ||
63 | +} | ||
64 | + | ||
65 | +//AllowForidCompany 总后台调用 | ||
66 | +func (c *SyncDataController) AllowForidCompany() { | ||
67 | + type Paremeter struct { | ||
68 | + Companyid int64 `json:"company_id"` | ||
69 | + Status int `json:"status"` | ||
70 | + } | ||
71 | + var param Paremeter | ||
72 | + if err := json.Unmarshal(c.Ctx.Input.RequestBody, ¶m); err != nil { | ||
73 | + logs.Error("json 解析失败 err:%s", err) | ||
74 | + c.ResponseError(errors.New("json数据解析失败")) | ||
75 | + return | ||
76 | + } | ||
77 | + var ( | ||
78 | + err error | ||
79 | + ) | ||
80 | + comanySrv := companyService.NewCompanyService(nil) | ||
81 | + switch param.Status { | ||
82 | + case 1: | ||
83 | + err = comanySrv.AllowCompany(param.Companyid) | ||
84 | + case 2: | ||
85 | + err = comanySrv.ForbidCompany(param.Companyid) | ||
86 | + default: | ||
87 | + c.ResponseError(errors.New("参数错误")) | ||
88 | + return | ||
89 | + } | ||
90 | + if err != nil { | ||
91 | + c.ResponseError(err) | ||
92 | + } | ||
93 | + c.ResponseData(nil) | ||
94 | + return | ||
95 | +} | ||
96 | + | ||
97 | +//GetCompanyInfo 总后台调用 | ||
98 | +func (c *SyncDataController) GetCompanyInfo() { | ||
99 | + type Paremeter struct { | ||
100 | + Companyid int64 `json:"company_id"` | ||
101 | + } | ||
102 | + var param Paremeter | ||
103 | + if err := json.Unmarshal(c.Ctx.Input.RequestBody, ¶m); err != nil { | ||
104 | + logs.Error("json 解析失败 err:%s", err) | ||
105 | + c.ResponseError(errors.New("json数据解析失败")) | ||
106 | + return | ||
107 | + } | ||
108 | + var ( | ||
109 | + err error | ||
110 | + companyData *domain.Company | ||
111 | + ) | ||
112 | + comanySrv := companyService.NewCompanyService(nil) | ||
113 | + companyData, err = comanySrv.GetCompanyData(param.Companyid) | ||
114 | + rspData := map[string]interface{}{ | ||
115 | + "comopany_id": 0, | ||
116 | + "exist": -1, //公司【1:存在;【-1:不存在】 | ||
117 | + "status": -1, //公司的启用状态【1:启用,-1:禁用】 | ||
118 | + } | ||
119 | + if err != nil { | ||
120 | + logs.Error(err) | ||
121 | + c.ResponseData(rspData) | ||
122 | + return | ||
123 | + } | ||
124 | + if companyData.EnableIsOk() { | ||
125 | + rspData["status"] = 1 | ||
126 | + } | ||
127 | + rspData["exist"] = 1 | ||
128 | + c.ResponseData(rspData) | ||
129 | + return | ||
130 | +} |
pkg/port/beego/routers/router2.go
0 → 100644
1 | +package routers | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/astaxie/beego" | ||
5 | + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/port/beego/controllers" | ||
6 | +) | ||
7 | + | ||
8 | +//外部调用,企业平台,总后台调用 | ||
9 | + | ||
10 | +func init() { | ||
11 | + nsPlatform := beego.NewNamespace("/platform", | ||
12 | + beego.NSRouter("/action", &controllers.SyncDataController{}, "post:SyncData"), | ||
13 | + beego.NSRouter("/admins_change", &controllers.SyncDataController{}, "post:CompanyAdminChance"), | ||
14 | + ) | ||
15 | + nsUcenter := beego.NewNamespace("/ucenter", | ||
16 | + beego.NSRouter("/company/allow_forbid", &controllers.SyncDataController{}, "post:AllowForidCompany"), | ||
17 | + beego.NSRouter("/company/info", &controllers.SyncDataController{}, "post:GetCompanyInfo"), | ||
18 | + ) | ||
19 | + | ||
20 | + beego.AddNamespace(nsPlatform) //企业平台调用 | ||
21 | + beego.AddNamespace(nsUcenter) //统一用户中心调用 | ||
22 | +} |
-
请 注册 或 登录 后发表评论