Merge branch 'dev' of http://gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway into dev
正在显示
5 个修改的文件
包含
153 行增加
和
0 行删除
1 | +package dto | ||
2 | + | ||
3 | +import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user" | ||
4 | + | ||
5 | +type DepartmentUsersDto struct { | ||
6 | + Departments []*Department `json:"departments"` | ||
7 | +} | ||
8 | + | ||
9 | +type Department struct { | ||
10 | + DepartmentID int64 `json:"departmentId"` | ||
11 | + DepartmentName string `json:"departmentName"` | ||
12 | + Users []User `json:"users"` | ||
13 | +} | ||
14 | +type User struct { | ||
15 | + UserID int `json:"userId"` | ||
16 | + UserName string `json:"userName"` | ||
17 | +} | ||
18 | + | ||
19 | +func (dto *DepartmentUsersDto) LoadDto(subDepartment *allied_creation_user.DataOrgGetSubDepartment, userSearch *allied_creation_user.DataUserSearch) error { | ||
20 | + var mapDepartment = make(map[int64]*Department) | ||
21 | + | ||
22 | + for i := range subDepartment.Orgs { | ||
23 | + org := subDepartment.Orgs[i] | ||
24 | + dep := &Department{ | ||
25 | + DepartmentID: int64(org.OrgID), | ||
26 | + DepartmentName: org.OrgName, | ||
27 | + Users: make([]User, 0), | ||
28 | + } | ||
29 | + dto.Departments = append(dto.Departments, dep) | ||
30 | + mapDepartment[dep.DepartmentID] = dep | ||
31 | + } | ||
32 | + | ||
33 | + for i := range userSearch.Users { | ||
34 | + user := userSearch.Users[i] | ||
35 | + if user.Department == nil { | ||
36 | + continue | ||
37 | + } | ||
38 | + if v, ok := mapDepartment[int64(user.Department.DepartmentId)]; ok { | ||
39 | + v.Users = append(v.Users, User{ | ||
40 | + UserID: user.UserId, | ||
41 | + UserName: user.UserInfo.UserName, | ||
42 | + }) | ||
43 | + } | ||
44 | + } | ||
45 | + return nil | ||
46 | +} |
1 | +package query | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "github.com/beego/beego/v2/core/validation" | ||
6 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain" | ||
7 | +) | ||
8 | + | ||
9 | +//获取自定义菜单列表 | ||
10 | +type DepartmentsUsersQuery struct { | ||
11 | + //操作人 | ||
12 | + Operator domain.Operator `json:"-"` | ||
13 | +} | ||
14 | + | ||
15 | +func (departmentsUsersQuery *DepartmentsUsersQuery) Valid(validation *validation.Validation) { | ||
16 | + | ||
17 | +} | ||
18 | + | ||
19 | +func (departmentsUsersQuery *DepartmentsUsersQuery) ValidateQuery() error { | ||
20 | + valid := validation.Validation{} | ||
21 | + b, err := valid.Valid(departmentsUsersQuery) | ||
22 | + if err != nil { | ||
23 | + return err | ||
24 | + } | ||
25 | + if !b { | ||
26 | + for _, validErr := range valid.Errors { | ||
27 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
28 | + } | ||
29 | + } | ||
30 | + return nil | ||
31 | +} |
1 | +package service | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/linmadan/egglib-go/core/application" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/mobile/org/dto" | ||
6 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/mobile/org/query" | ||
7 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user" | ||
8 | +) | ||
9 | + | ||
10 | +type OrgService struct { | ||
11 | +} | ||
12 | + | ||
13 | +//DepartmentsUsers 部门用户列表 | ||
14 | +func (srv OrgService) DepartmentsUsers(departmentsUsersQuery *query.DepartmentsUsersQuery) (interface{}, error) { | ||
15 | + creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser( | ||
16 | + departmentsUsersQuery.Operator) | ||
17 | + orgs, err := creationUserGateway.OrgGetSubDepartment(allied_creation_user.ReqOrgGetSubDepartment{ | ||
18 | + OrgId: departmentsUsersQuery.Operator.OrgId, | ||
19 | + }) | ||
20 | + if err != nil { | ||
21 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
22 | + } | ||
23 | + | ||
24 | + users, err := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{ | ||
25 | + //Offset: 0, | ||
26 | + //Limit: 999, | ||
27 | + CompanyId: departmentsUsersQuery.Operator.CompanyId, | ||
28 | + OrganizationId: departmentsUsersQuery.Operator.OrgId, | ||
29 | + }) | ||
30 | + if err != nil { | ||
31 | + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | ||
32 | + } | ||
33 | + departmentUsersDto := &dto.DepartmentUsersDto{} | ||
34 | + if err := departmentUsersDto.LoadDto(orgs, users); err != nil { | ||
35 | + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | ||
36 | + } | ||
37 | + return departmentUsersDto, nil | ||
38 | +} | ||
39 | + | ||
40 | +func NewOrgService(options map[string]interface{}) *OrgService { | ||
41 | + newOrgService := &OrgService{} | ||
42 | + return newOrgService | ||
43 | +} |
1 | +package mobile_client | ||
2 | + | ||
3 | +import ( | ||
4 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/mobile/org/query" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/mobile/org/service" | ||
6 | +) | ||
7 | + | ||
8 | +type OrgController struct { | ||
9 | + baseController | ||
10 | +} | ||
11 | + | ||
12 | +func (controller *OrgController) DepartmentUsers() { | ||
13 | + orgService := service.OrgService{} | ||
14 | + departmentsUsersQuery := &query.DepartmentsUsersQuery{} | ||
15 | + err := controller.Unmarshal(departmentsUsersQuery) | ||
16 | + if err != nil { | ||
17 | + controller.Response(nil, err) | ||
18 | + return | ||
19 | + } | ||
20 | + departmentsUsersQuery.Operator = controller.GetOperator() | ||
21 | + data, err := orgService.DepartmentsUsers(departmentsUsersQuery) | ||
22 | + controller.Response(data, err) | ||
23 | +} |
pkg/port/beego/routers/mobile_org_router.go
0 → 100644
1 | +package routers | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/beego/beego/v2/server/web" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/port/beego/controllers/mobile_client" | ||
6 | +) | ||
7 | + | ||
8 | +func init() { | ||
9 | + web.Router("/v1/app/orgs/department-users", &mobile_client.OrgController{}, "Post:DepartmentUsers") | ||
10 | +} |
-
请 注册 或 登录 后发表评论