正在显示
38 个修改的文件
包含
685 行增加
和
78 行删除
@@ -110,6 +110,10 @@ spec: | @@ -110,6 +110,10 @@ spec: | ||
110 | key: kafkaperformance.id | 110 | key: kafkaperformance.id |
111 | - name: KAFKA_BUSINESS_TOPIC | 111 | - name: KAFKA_BUSINESS_TOPIC |
112 | value: "mmm_business_test" | 112 | value: "mmm_business_test" |
113 | + - name: UCENTER_SERVICE_HOST | ||
114 | + value: "https://suplus-ucenter-test.fjmaimaimai.com" | ||
115 | + - name: BUSINESS_ADMIN_SERVICE_HOST | ||
116 | + value: "https://suplus-business-admin-test.fjmaimaimai.com" | ||
113 | volumes: | 117 | volumes: |
114 | - name: accesslogs | 118 | - name: accesslogs |
115 | emptyDir: {} | 119 | emptyDir: {} |
@@ -6,6 +6,7 @@ require ( | @@ -6,6 +6,7 @@ require ( | ||
6 | github.com/Shopify/sarama v1.25.0 | 6 | github.com/Shopify/sarama v1.25.0 |
7 | github.com/beego/beego/v2 v2.0.5 | 7 | github.com/beego/beego/v2 v2.0.5 |
8 | github.com/bwmarrin/snowflake v0.3.0 | 8 | github.com/bwmarrin/snowflake v0.3.0 |
9 | + github.com/dgrijalva/jwt-go v3.2.0+incompatible | ||
9 | github.com/go-pg/pg/v10 v10.10.7 | 10 | github.com/go-pg/pg/v10 v10.10.7 |
10 | github.com/linmadan/egglib-go v0.0.0-20210827085852-177fa745932d | 11 | github.com/linmadan/egglib-go v0.0.0-20210827085852-177fa745932d |
11 | ) | 12 | ) |
@@ -111,6 +111,7 @@ github.com/cupcake/rdb v0.0.0-20161107195141-43ba34106c76/go.mod h1:vYwsqCOLxGii | @@ -111,6 +111,7 @@ github.com/cupcake/rdb v0.0.0-20161107195141-43ba34106c76/go.mod h1:vYwsqCOLxGii | ||
111 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | 111 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= |
112 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= | 112 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= |
113 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | 113 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= |
114 | +github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= | ||
114 | github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= | 115 | github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= |
115 | github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= | 116 | github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= |
116 | github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= | 117 | github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= |
不能预览此文件类型
pkg/application/auth/command/login.go
0 → 100644
1 | package service | 1 | package service |
2 | 2 | ||
3 | +import ( | ||
4 | + "github.com/linmadan/egglib-go/core/application" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/auth/command" | ||
6 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory" | ||
7 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" | ||
8 | +) | ||
9 | + | ||
3 | type AuthService struct { | 10 | type AuthService struct { |
4 | } | 11 | } |
12 | + | ||
13 | +// Login PC端登录 | ||
14 | +func (service *AuthService) Login(loginCommand *command.LoginCommand) (interface{}, error) { | ||
15 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
16 | + if err != nil { | ||
17 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
18 | + } | ||
19 | + if errStart := transactionContext.StartTransaction(); errStart != nil { | ||
20 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, errStart.Error()) | ||
21 | + } | ||
22 | + defer func() { | ||
23 | + _ = transactionContext.RollbackTransaction() | ||
24 | + }() | ||
25 | + //统一用户中心登录 | ||
26 | + authCodeReply, err := factory.UCenterApi().AuthCode(loginCommand.Code) | ||
27 | + if err != nil || !authCodeReply.IsOk() { | ||
28 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "统一用户中心认证失败") | ||
29 | + } | ||
30 | + //用户权限校验 | ||
31 | + userAuthReply, err := factory.BusinessAdminApi().GetUserAuth(authCodeReply.Data.MUid, loginCommand.PlatformId) | ||
32 | + if err != nil { | ||
33 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "用户鉴权失败") | ||
34 | + } | ||
35 | + if !userAuthReply.IsOk() { | ||
36 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, userAuthReply.Message()) | ||
37 | + } | ||
38 | + //获取公司数据 | ||
39 | + companyRepository := factory.CreateCompanyRepository(map[string]interface{}{ | ||
40 | + "transactionContext": transactionContext, | ||
41 | + }) | ||
42 | + company, err := companyRepository.FindOne(map[string]interface{}{ | ||
43 | + "id": authCodeReply.Data.CompanyId, | ||
44 | + }) | ||
45 | + if err != nil { | ||
46 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取公司数据失败") | ||
47 | + } | ||
48 | + userRepository := factory.CreateUserRepository(map[string]interface{}{ | ||
49 | + "transactionContext": transactionContext, | ||
50 | + }) | ||
51 | + user, err := userRepository.FindOne(map[string]interface{}{ | ||
52 | + "id": authCodeReply.Data.MUid, | ||
53 | + "companyId": company.Id, | ||
54 | + }) | ||
55 | + if err != nil { | ||
56 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取公司数据失败") | ||
57 | + } | ||
58 | + if user.Status != domain.UserStatusEnable { | ||
59 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "用户被禁用") | ||
60 | + } | ||
61 | + userAuth := &domain.UserAuth{ | ||
62 | + UserId: user.Id, | ||
63 | + CompanyId: user.CompanyId, | ||
64 | + Phone: user.Account, | ||
65 | + PlatformId: loginCommand.PlatformId, | ||
66 | + Name: user.Name, | ||
67 | + AdminType: user.AdminType, | ||
68 | + } | ||
69 | + accessToken, err := userAuth.CreateAccessToken() | ||
70 | + if err != nil { | ||
71 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
72 | + } | ||
73 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
74 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
75 | + } | ||
76 | + return map[string]interface{}{ | ||
77 | + "access": map[string]interface{}{ | ||
78 | + "accessToken": accessToken, | ||
79 | + "expiresIn": domain.JWTExpiresSecond, | ||
80 | + }, | ||
81 | + }, nil | ||
82 | +} |
1 | package command | 1 | package command |
2 | 2 | ||
3 | -//AddCompanyCommand 数据来源 企业平台 推送的消息 | ||
4 | -//新建公司 | 3 | +// AddCompanyCommand 数据来源 企业平台 推送的消息 |
4 | +// 新建公司 | ||
5 | type SaveCompanyCommand struct { | 5 | type SaveCompanyCommand struct { |
6 | //新添加的公司 | 6 | //新添加的公司 |
7 | - Comapany struct { | 7 | + Company struct { |
8 | Id int64 `json:"id" ` | 8 | Id int64 `json:"id" ` |
9 | Logo string `json:"logo"` // 公司logo | 9 | Logo string `json:"logo"` // 公司logo |
10 | Name string `json:"name"` // 公司名称 | 10 | Name string `json:"name"` // 公司名称 |
@@ -79,14 +79,14 @@ func (c SyncDataCompanyService) addCompany(param *command.SaveCompanyCommand) er | @@ -79,14 +79,14 @@ func (c SyncDataCompanyService) addCompany(param *command.SaveCompanyCommand) er | ||
79 | }() | 79 | }() |
80 | nowTime := time.Now() | 80 | nowTime := time.Now() |
81 | newCompany := domain.Company{ | 81 | newCompany := domain.Company{ |
82 | - Id: param.Comapany.Id, | ||
83 | - Logo: param.Comapany.Logo, | ||
84 | - Name: param.Comapany.Name, | ||
85 | - Status: param.Comapany.Status, | ||
86 | - UpdateAt: nowTime, | ||
87 | - CreateAt: nowTime, | 82 | + Id: param.Company.Id, |
83 | + Logo: param.Company.Logo, | ||
84 | + Name: param.Company.Name, | ||
85 | + Status: param.Company.Status, | ||
86 | + UpdatedAt: nowTime, | ||
87 | + CreatedAt: nowTime, | ||
88 | ChargeUserIds: []int64{}, | 88 | ChargeUserIds: []int64{}, |
89 | - DeleteAt: nil, | 89 | + DeletedAt: nil, |
90 | } | 90 | } |
91 | 91 | ||
92 | newUser := domain.User{ | 92 | newUser := domain.User{ |
@@ -144,7 +144,7 @@ func (c SyncDataCompanyService) editCompany(param *command.SaveCompanyCommand) e | @@ -144,7 +144,7 @@ func (c SyncDataCompanyService) editCompany(param *command.SaveCompanyCommand) e | ||
144 | 144 | ||
145 | _, companyList, err := companyRepo.Find(map[string]interface{}{ | 145 | _, companyList, err := companyRepo.Find(map[string]interface{}{ |
146 | "limit": 1, | 146 | "limit": 1, |
147 | - "id": param.Comapany.Id, | 147 | + "id": param.Company.Id, |
148 | }) | 148 | }) |
149 | if err != nil { | 149 | if err != nil { |
150 | return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 150 | return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
@@ -165,7 +165,7 @@ func (c SyncDataCompanyService) editCompany(param *command.SaveCompanyCommand) e | @@ -165,7 +165,7 @@ func (c SyncDataCompanyService) editCompany(param *command.SaveCompanyCommand) e | ||
165 | newCompany = companyList[0] | 165 | newCompany = companyList[0] |
166 | } else { | 166 | } else { |
167 | newCompany = &domain.Company{ | 167 | newCompany = &domain.Company{ |
168 | - CreateAt: nowTime, | 168 | + CreatedAt: nowTime, |
169 | } | 169 | } |
170 | } | 170 | } |
171 | if len(userList) > 0 { | 171 | if len(userList) > 0 { |
@@ -176,11 +176,11 @@ func (c SyncDataCompanyService) editCompany(param *command.SaveCompanyCommand) e | @@ -176,11 +176,11 @@ func (c SyncDataCompanyService) editCompany(param *command.SaveCompanyCommand) e | ||
176 | } | 176 | } |
177 | } | 177 | } |
178 | 178 | ||
179 | - newCompany.Id = param.Comapany.Id | ||
180 | - newCompany.Logo = param.Comapany.Logo | ||
181 | - newCompany.Name = param.Comapany.Name | ||
182 | - newCompany.Status = param.Comapany.Status | ||
183 | - newCompany.UpdateAt = nowTime | 179 | + newCompany.Id = param.Company.Id |
180 | + newCompany.Logo = param.Company.Logo | ||
181 | + newCompany.Name = param.Company.Name | ||
182 | + newCompany.Status = param.Company.Status | ||
183 | + newCompany.UpdatedAt = nowTime | ||
184 | 184 | ||
185 | newUser.Id = param.User.Id | 185 | newUser.Id = param.User.Id |
186 | newUser.Account = param.User.Phone | 186 | newUser.Account = param.User.Phone |
@@ -245,7 +245,7 @@ func (srv SyncDataCompanyService) setCompanyCharge(param *command.SetCompanyChar | @@ -245,7 +245,7 @@ func (srv SyncDataCompanyService) setCompanyCharge(param *command.SetCompanyChar | ||
245 | } | 245 | } |
246 | for i := range companyList { | 246 | for i := range companyList { |
247 | companyList[i].ChargeUserIds = param.ChargeUserIds | 247 | companyList[i].ChargeUserIds = param.ChargeUserIds |
248 | - companyList[i].UpdateAt = time.Now() | 248 | + companyList[i].UpdatedAt = time.Now() |
249 | _, err = companyRepo.Update(companyList[i]) | 249 | _, err = companyRepo.Update(companyList[i]) |
250 | if err != nil { | 250 | if err != nil { |
251 | return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 251 | return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
@@ -81,9 +81,9 @@ func (srv SyncDataDepartmentService) addDepartment(param *command.AddDepartmentC | @@ -81,9 +81,9 @@ func (srv SyncDataDepartmentService) addDepartment(param *command.AddDepartmentC | ||
81 | ParentId: param.ParentId, | 81 | ParentId: param.ParentId, |
82 | ChargeUserIds: param.ChargeUserIds, | 82 | ChargeUserIds: param.ChargeUserIds, |
83 | Path: param.Path, | 83 | Path: param.Path, |
84 | - CreateAt: nowTime, | ||
85 | - UpdateAt: nowTime, | ||
86 | - DeleteAt: nil, | 84 | + CreatedAt: nowTime, |
85 | + UpdatedAt: nowTime, | ||
86 | + DeletedAt: nil, | ||
87 | } | 87 | } |
88 | 88 | ||
89 | departmentRepo := factory.CreateDepartmentRepository(map[string]interface{}{ | 89 | departmentRepo := factory.CreateDepartmentRepository(map[string]interface{}{ |
@@ -130,11 +130,16 @@ func (srv SyncDataDepartmentService) editDepartment(param *command.EditDepartmen | @@ -130,11 +130,16 @@ func (srv SyncDataDepartmentService) editDepartment(param *command.EditDepartmen | ||
130 | for i := range departmentList { | 130 | for i := range departmentList { |
131 | if departmentList[i].Id == param.Id { | 131 | if departmentList[i].Id == param.Id { |
132 | departmentList[i].CompanyId = param.CompanyId | 132 | departmentList[i].CompanyId = param.CompanyId |
133 | + departmentList[i].ParentId = param.ParentId | ||
134 | + if param.Name != "" { | ||
133 | departmentList[i].Name = param.Name | 135 | departmentList[i].Name = param.Name |
136 | + } | ||
137 | + if param.Path != "" { | ||
134 | departmentList[i].Path = param.Path | 138 | departmentList[i].Path = param.Path |
135 | - departmentList[i].ChargeUserIds = make([]int64, 0) | 139 | + } |
140 | + if param.Level > 0 { | ||
136 | departmentList[i].Level = param.Level | 141 | departmentList[i].Level = param.Level |
137 | - departmentList[i].ParentId = param.ParentId | 142 | + } |
138 | if len(param.ChargeUserIds) > 0 { | 143 | if len(param.ChargeUserIds) > 0 { |
139 | departmentList[i].ChargeUserIds = param.ChargeUserIds | 144 | departmentList[i].ChargeUserIds = param.ChargeUserIds |
140 | } | 145 | } |
@@ -218,9 +223,9 @@ func (srv SyncDataDepartmentService) importDepartment(param []command.ImportDepa | @@ -218,9 +223,9 @@ func (srv SyncDataDepartmentService) importDepartment(param []command.ImportDepa | ||
218 | ParentId: param[i].ParentId, | 223 | ParentId: param[i].ParentId, |
219 | ChargeUserIds: []int64{}, | 224 | ChargeUserIds: []int64{}, |
220 | Path: param[i].Path, | 225 | Path: param[i].Path, |
221 | - CreateAt: nowTime, | ||
222 | - UpdateAt: nowTime, | ||
223 | - DeleteAt: nil, | 226 | + CreatedAt: nowTime, |
227 | + UpdatedAt: nowTime, | ||
228 | + DeletedAt: nil, | ||
224 | } | 229 | } |
225 | _, err = departmentRepo.Insert(&newDepartment) | 230 | _, err = departmentRepo.Insert(&newDepartment) |
226 | if err != nil { | 231 | if err != nil { |
pkg/application/factory/api.go
0 → 100644
1 | +package factory | ||
2 | + | ||
3 | +import ( | ||
4 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/serviceGateway" | ||
6 | +) | ||
7 | + | ||
8 | +func UCenterApi() domain.UCenterApi { | ||
9 | + return serviceGateway.NewHttpLibUCenterApiServiceGateway() | ||
10 | +} | ||
11 | + | ||
12 | +func BusinessAdminApi() domain.BusinessAdminApi { | ||
13 | + return serviceGateway.NewHttpLibBusinessAdminServiceGateway() | ||
14 | +} |
pkg/constant/business_admin.go
0 → 100644
1 | +package constant | ||
2 | + | ||
3 | +import "os" | ||
4 | + | ||
5 | +// 用户中心地址 | ||
6 | +var UCENTER_SERVICE_HOST = "http://suplus-ucenter-test.fjmaimaimai.com" | ||
7 | + | ||
8 | +// var UCENTER_HOST = "https://suplus-ucenter-dev.fjmaimaimai.com" //统一用户中心地址 | ||
9 | +var UCENTER_SECRET = "cykbjnfqgctn" | ||
10 | +var UCENTER_APP_KEY = "39aefef9e22744a3b2d2d3791824ae7b" | ||
11 | +var UCENTER_CHECK_ALT = "rsF0pL!6DwjBO735" | ||
12 | + | ||
13 | +// 企业平台地址 | ||
14 | +var BUSINESS_ADMIN_SERVICE_HOST = "http://suplus-business-admin-test.fjmaimaimai.com" | ||
15 | + | ||
16 | +// 绩效管理平台ID | ||
17 | +var PLATFORM_ADMIN_ID = 28 | ||
18 | + | ||
19 | +// 员工绩效平台ID | ||
20 | +var PLATFORM_FONT_ID = 29 | ||
21 | + | ||
22 | +func init() { | ||
23 | + if os.Getenv("UCENTER_SERVICE_HOST") != "" { | ||
24 | + UCENTER_SERVICE_HOST = os.Getenv("UCENTER_SERVICE_HOST") | ||
25 | + } | ||
26 | + if os.Getenv("BUSINESS_ADMIN_SERVICE_HOST") != "" { | ||
27 | + BUSINESS_ADMIN_SERVICE_HOST = os.Getenv("BUSINESS_ADMIN_SERVICE_HOST") | ||
28 | + } | ||
29 | +} |
@@ -2,7 +2,7 @@ package constant | @@ -2,7 +2,7 @@ package constant | ||
2 | 2 | ||
3 | import "os" | 3 | import "os" |
4 | 4 | ||
5 | -var POSTGRESQL_DB_NAME = "performance_dev" | 5 | +var POSTGRESQL_DB_NAME = "performance_test" |
6 | var POSTGRESQL_USER = "postgres" | 6 | var POSTGRESQL_USER = "postgres" |
7 | var POSTGRESQL_PASSWORD = "eagle1010" | 7 | var POSTGRESQL_PASSWORD = "eagle1010" |
8 | var POSTGRESQL_HOST = "114.55.200.59" | 8 | var POSTGRESQL_HOST = "114.55.200.59" |
pkg/domain/business_admin.go
0 → 100644
1 | +package domain | ||
2 | + | ||
3 | +import "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/serviceGateway/reply" | ||
4 | + | ||
5 | +// UCenterApi 统一用户中心 | ||
6 | +type UCenterApi interface { | ||
7 | + AuthCode(code string) (*reply.UCenterAuthCode, error) | ||
8 | +} | ||
9 | + | ||
10 | +// BusinessAdminApi 企业平台 | ||
11 | +type BusinessAdminApi interface { | ||
12 | + GetUserAuth(userId int64, platformId int) (*reply.BusinessAdminUserAuth, error) | ||
13 | +} |
@@ -8,9 +8,9 @@ type Company struct { | @@ -8,9 +8,9 @@ type Company struct { | ||
8 | Name string //公司名称 | 8 | Name string //公司名称 |
9 | ChargeUserIds []int64 //公司级别的部门主管uids | 9 | ChargeUserIds []int64 //公司级别的部门主管uids |
10 | Status int //公司状态,1正常 2禁用 | 10 | Status int //公司状态,1正常 2禁用 |
11 | - UpdateAt time.Time //更新时间 | ||
12 | - CreateAt time.Time //创建时间 | ||
13 | - DeleteAt *time.Time | 11 | + UpdatedAt time.Time //更新时间 |
12 | + CreatedAt time.Time //创建时间 | ||
13 | + DeletedAt *time.Time //删除时间 | ||
14 | } | 14 | } |
15 | 15 | ||
16 | type CompanyRepository interface { | 16 | type CompanyRepository interface { |
@@ -10,10 +10,11 @@ type Department struct { | @@ -10,10 +10,11 @@ type Department struct { | ||
10 | ParentId int64 // 组织父级id | 10 | ParentId int64 // 组织父级id |
11 | ChargeUserIds []int64 // 主管uids | 11 | ChargeUserIds []int64 // 主管uids |
12 | Path string // 组织路径 | 12 | Path string // 组织路径 |
13 | - CreateAt time.Time // 创建时间 | ||
14 | - UpdateAt time.Time // 更新时间 | ||
15 | - DeleteAt *time.Time // 删除时间 | 13 | + CreatedAt time.Time // 创建时间 |
14 | + UpdatedAt time.Time // 更新时间 | ||
15 | + DeletedAt *time.Time // 删除时间 | ||
16 | } | 16 | } |
17 | + | ||
17 | type DepartmentRepository interface { | 18 | type DepartmentRepository interface { |
18 | Insert(param *Department) (*Department, error) | 19 | Insert(param *Department) (*Department, error) |
19 | Update(param *Department) (*Department, error) | 20 | Update(param *Department) (*Department, error) |
@@ -10,7 +10,7 @@ type ReceivedMessage struct { | @@ -10,7 +10,7 @@ type ReceivedMessage struct { | ||
10 | MessageType string `json:"MessageType"` | 10 | MessageType string `json:"MessageType"` |
11 | MessageBody string `json:"MessageBody"` | 11 | MessageBody string `json:"MessageBody"` |
12 | OccurredOn time.Time `json:"OccurredOn"` | 12 | OccurredOn time.Time `json:"OccurredOn"` |
13 | - CreateAt time.Time `json:"-"` | 13 | + CreatedAt time.Time `json:"-"` |
14 | } | 14 | } |
15 | 15 | ||
16 | type MessageBody struct { | 16 | type MessageBody struct { |
@@ -22,6 +22,8 @@ type User struct { | @@ -22,6 +22,8 @@ type User struct { | ||
22 | const ( | 22 | const ( |
23 | UserTypeCommon int = 1 | 23 | UserTypeCommon int = 1 |
24 | UserTypeManager int = 2 | 24 | UserTypeManager int = 2 |
25 | + | ||
26 | + UserStatusEnable int = 1 | ||
25 | ) | 27 | ) |
26 | 28 | ||
27 | type UserRepository interface { | 29 | type UserRepository interface { |
pkg/domain/user_auth.go
0 → 100644
1 | +package domain | ||
2 | + | ||
3 | +import ( | ||
4 | + "errors" | ||
5 | + "github.com/dgrijalva/jwt-go" | ||
6 | + "time" | ||
7 | +) | ||
8 | + | ||
9 | +type UserAuth struct { | ||
10 | + jwt.StandardClaims `json:"-"` | ||
11 | + UserId int64 `json:"userId"` | ||
12 | + CompanyId int64 `json:"companyId"` | ||
13 | + Phone string `json:"phone"` | ||
14 | + PlatformId int `json:"platformId"` | ||
15 | + Name string `json:"name"` | ||
16 | + AdminType int `json:"adminType"` | ||
17 | +} | ||
18 | + | ||
19 | +var issuer = "performance" | ||
20 | + | ||
21 | +var secretKey = "Ma9HXITeliSYS43Z" | ||
22 | + | ||
23 | +var JWTExpiresSecond = 3600 * 24 | ||
24 | + | ||
25 | +// CreateAccessToken 生成token | ||
26 | +func (userAuth *UserAuth) CreateAccessToken() (string, error) { | ||
27 | + userAuth.StandardClaims = jwt.StandardClaims{ | ||
28 | + ExpiresAt: time.Now().Add(time.Duration(JWTExpiresSecond) * time.Second).Unix(), | ||
29 | + Issuer: issuer, | ||
30 | + } | ||
31 | + token := jwt.NewWithClaims(jwt.SigningMethodHS256, userAuth) | ||
32 | + return token.SignedString([]byte(secretKey)) | ||
33 | +} | ||
34 | + | ||
35 | +// ParseAccessToken 解析token | ||
36 | +func (userAuth *UserAuth) ParseAccessToken(token string) (*UserAuth, error) { | ||
37 | + user := &UserAuth{} | ||
38 | + tokenClaims, err := jwt.ParseWithClaims(token, user, func(token *jwt.Token) (interface{}, error) { | ||
39 | + return []byte(secretKey), nil | ||
40 | + }) | ||
41 | + if err != nil || tokenClaims == nil { | ||
42 | + return nil, errors.New("解析token失败") | ||
43 | + } | ||
44 | + if claim, ok := tokenClaims.Claims.(*UserAuth); ok && tokenClaims.Valid { | ||
45 | + user.UserId = claim.UserId | ||
46 | + user.CompanyId = claim.CompanyId | ||
47 | + user.Phone = claim.Phone | ||
48 | + user.PlatformId = claim.PlatformId | ||
49 | + user.Name = claim.Name | ||
50 | + user.AdminType = claim.AdminType | ||
51 | + return user, nil | ||
52 | + } | ||
53 | + return user, errors.New("解析token失败") | ||
54 | +} |
@@ -9,7 +9,7 @@ type Company struct { | @@ -9,7 +9,7 @@ type Company struct { | ||
9 | Name string //公司名称 | 9 | Name string //公司名称 |
10 | ChargeUserIds []int64 //公司级别的部门主管uids | 10 | ChargeUserIds []int64 //公司级别的部门主管uids |
11 | Status int //公司状态,1正常 2禁用 | 11 | Status int //公司状态,1正常 2禁用 |
12 | - UpdateAt time.Time //更新时间 | ||
13 | - CreateAt time.Time //创建时间 | ||
14 | - DeleteAt *time.Time `pg:",soft_delete"` //删除时间 | 12 | + CreatedAt time.Time //创建时间 |
13 | + UpdatedAt time.Time //更新时间 | ||
14 | + DeletedAt *time.Time `pg:",soft_delete"` //删除时间 | ||
15 | } | 15 | } |
@@ -13,7 +13,7 @@ type Department struct { | @@ -13,7 +13,7 @@ type Department struct { | ||
13 | ParentId int64 `pg:",use_zero"` // 组织父级id | 13 | ParentId int64 `pg:",use_zero"` // 组织父级id |
14 | ChargeUserIds []int64 // 主管uids | 14 | ChargeUserIds []int64 // 主管uids |
15 | Path string // 组织路径 | 15 | Path string // 组织路径 |
16 | - CreateAt time.Time // 创建时间 | ||
17 | - UpdateAt time.Time // 更新时间 | ||
18 | - DeleteAt *time.Time `pg:",soft_delete"` // 删除时间 | 16 | + CreatedAt time.Time // 创建时间 |
17 | + UpdatedAt time.Time // 更新时间 | ||
18 | + DeletedAt *time.Time `pg:",soft_delete"` // 删除时间 | ||
19 | } | 19 | } |
@@ -8,5 +8,7 @@ type ReceivedMessage struct { | @@ -8,5 +8,7 @@ type ReceivedMessage struct { | ||
8 | MessageType string | 8 | MessageType string |
9 | MessageBody string | 9 | MessageBody string |
10 | OccurredOn time.Time | 10 | OccurredOn time.Time |
11 | - CreateAt time.Time | 11 | + CreatedAt time.Time `pg:"default:now()"` |
12 | + UpdatedAt time.Time `pg:"default:now()"` | ||
13 | + DeletedAt *time.Time `pg:",soft_delete"` | ||
12 | } | 14 | } |
@@ -11,5 +11,5 @@ type Role struct { | @@ -11,5 +11,5 @@ type Role struct { | ||
11 | CompanyId int64 `comment:"公司ID"` | 11 | CompanyId int64 `comment:"公司ID"` |
12 | CreatedAt time.Time `comment:"创建时间"` | 12 | CreatedAt time.Time `comment:"创建时间"` |
13 | UpdatedAt time.Time `comment:"更新时间"` | 13 | UpdatedAt time.Time `comment:"更新时间"` |
14 | - DeletedAt *time.Time `comment:"删除时间"` | 14 | + DeletedAt *time.Time `comment:"删除时间" pg:",soft_delete"` |
15 | } | 15 | } |
@@ -10,5 +10,5 @@ type RoleUser struct { | @@ -10,5 +10,5 @@ type RoleUser struct { | ||
10 | CompanyId int64 `comment:"公司ID"` | 10 | CompanyId int64 `comment:"公司ID"` |
11 | CreatedAt time.Time `comment:"创建时间"` | 11 | CreatedAt time.Time `comment:"创建时间"` |
12 | UpdatedAt time.Time `comment:"更新时间"` | 12 | UpdatedAt time.Time `comment:"更新时间"` |
13 | - DeletedAt *time.Time `comment:"删除时间"` | 13 | + DeletedAt *time.Time `comment:"删除时间" pg:",soft_delete"` |
14 | } | 14 | } |
@@ -14,7 +14,7 @@ type User struct { | @@ -14,7 +14,7 @@ type User struct { | ||
14 | Status int // 用户状态(1正常 2禁用) | 14 | Status int // 用户状态(1正常 2禁用) |
15 | DepartmentId []int // 用户归属的部门 | 15 | DepartmentId []int // 用户归属的部门 |
16 | PositionId []int // 用户职位 | 16 | PositionId []int // 用户职位 |
17 | - UpdateAt time.Time // 更新时间 | ||
18 | - CreateAt time.Time // 创建时间 | ||
19 | - DeleteAt *time.Time `pg:",soft_delete"` // 删除时间 | 17 | + CreatedAt time.Time // 创建时间 |
18 | + UpdatedAt time.Time // 更新时间 | ||
19 | + DeletedAt *time.Time `pg:",soft_delete"` // 删除时间 | ||
20 | } | 20 | } |
@@ -28,9 +28,9 @@ func (repo *CompanyRepository) Insert(u *domain.Company) (*domain.Company, error | @@ -28,9 +28,9 @@ func (repo *CompanyRepository) Insert(u *domain.Company) (*domain.Company, error | ||
28 | Name: u.Name, | 28 | Name: u.Name, |
29 | Status: u.Status, | 29 | Status: u.Status, |
30 | ChargeUserIds: u.ChargeUserIds, | 30 | ChargeUserIds: u.ChargeUserIds, |
31 | - UpdateAt: u.UpdateAt, | ||
32 | - CreateAt: u.CreateAt, | ||
33 | - DeleteAt: u.DeleteAt, | 31 | + UpdatedAt: u.UpdatedAt, |
32 | + CreatedAt: u.CreatedAt, | ||
33 | + DeletedAt: u.DeletedAt, | ||
34 | } | 34 | } |
35 | tx := repo.transactionContext.PgTx | 35 | tx := repo.transactionContext.PgTx |
36 | _, err := tx.Model(&companyModel).Insert() | 36 | _, err := tx.Model(&companyModel).Insert() |
@@ -48,9 +48,9 @@ func (repo *CompanyRepository) Update(u *domain.Company) (*domain.Company, error | @@ -48,9 +48,9 @@ func (repo *CompanyRepository) Update(u *domain.Company) (*domain.Company, error | ||
48 | Name: u.Name, | 48 | Name: u.Name, |
49 | Status: u.Status, | 49 | Status: u.Status, |
50 | ChargeUserIds: u.ChargeUserIds, | 50 | ChargeUserIds: u.ChargeUserIds, |
51 | - UpdateAt: u.UpdateAt, | ||
52 | - CreateAt: u.CreateAt, | ||
53 | - DeleteAt: u.DeleteAt, | 51 | + UpdatedAt: u.UpdatedAt, |
52 | + CreatedAt: u.CreatedAt, | ||
53 | + DeletedAt: u.DeletedAt, | ||
54 | } | 54 | } |
55 | tx := repo.transactionContext.PgTx | 55 | tx := repo.transactionContext.PgTx |
56 | _, err := tx.Model(&companyModel).WherePK().Update() | 56 | _, err := tx.Model(&companyModel).WherePK().Update() |
@@ -62,7 +62,7 @@ func (repo *CompanyRepository) Update(u *domain.Company) (*domain.Company, error | @@ -62,7 +62,7 @@ func (repo *CompanyRepository) Update(u *domain.Company) (*domain.Company, error | ||
62 | 62 | ||
63 | func (repo *CompanyRepository) Remove(u *domain.Company) (*domain.Company, error) { | 63 | func (repo *CompanyRepository) Remove(u *domain.Company) (*domain.Company, error) { |
64 | nowTime := time.Now() | 64 | nowTime := time.Now() |
65 | - u.DeleteAt = &nowTime | 65 | + u.DeletedAt = &nowTime |
66 | _, err := repo.Update(u) | 66 | _, err := repo.Update(u) |
67 | return u, err | 67 | return u, err |
68 | } | 68 | } |
@@ -117,8 +117,8 @@ func (repo *CompanyRepository) TransformToCompanyDomain(m *models.Company) *doma | @@ -117,8 +117,8 @@ func (repo *CompanyRepository) TransformToCompanyDomain(m *models.Company) *doma | ||
117 | Logo: m.Logo, | 117 | Logo: m.Logo, |
118 | Name: m.Name, | 118 | Name: m.Name, |
119 | Status: m.Status, | 119 | Status: m.Status, |
120 | - UpdateAt: m.UpdateAt, | ||
121 | - CreateAt: m.CreateAt, | ||
122 | - DeleteAt: m.DeleteAt, | 120 | + UpdatedAt: m.UpdatedAt, |
121 | + CreatedAt: m.CreatedAt, | ||
122 | + DeletedAt: m.DeletedAt, | ||
123 | } | 123 | } |
124 | } | 124 | } |
@@ -30,9 +30,9 @@ func (repo *DepartmentRepository) Insert(u *domain.Department) (*domain.Departme | @@ -30,9 +30,9 @@ func (repo *DepartmentRepository) Insert(u *domain.Department) (*domain.Departme | ||
30 | ParentId: u.ParentId, | 30 | ParentId: u.ParentId, |
31 | ChargeUserIds: u.ChargeUserIds, | 31 | ChargeUserIds: u.ChargeUserIds, |
32 | Path: u.Path, | 32 | Path: u.Path, |
33 | - CreateAt: u.CreateAt, | ||
34 | - UpdateAt: u.UpdateAt, | ||
35 | - DeleteAt: nil, | 33 | + CreatedAt: u.CreatedAt, |
34 | + UpdatedAt: u.UpdatedAt, | ||
35 | + DeletedAt: nil, | ||
36 | } | 36 | } |
37 | tx := repo.transactionContext.PgTx | 37 | tx := repo.transactionContext.PgTx |
38 | _, err := tx.Model(&departmentModel).Insert() | 38 | _, err := tx.Model(&departmentModel).Insert() |
@@ -52,9 +52,9 @@ func (repo *DepartmentRepository) Update(u *domain.Department) (*domain.Departme | @@ -52,9 +52,9 @@ func (repo *DepartmentRepository) Update(u *domain.Department) (*domain.Departme | ||
52 | ParentId: u.ParentId, | 52 | ParentId: u.ParentId, |
53 | ChargeUserIds: u.ChargeUserIds, | 53 | ChargeUserIds: u.ChargeUserIds, |
54 | Path: u.Path, | 54 | Path: u.Path, |
55 | - CreateAt: u.CreateAt, | ||
56 | - UpdateAt: u.UpdateAt, | ||
57 | - DeleteAt: u.DeleteAt, | 55 | + CreatedAt: u.CreatedAt, |
56 | + UpdatedAt: u.UpdatedAt, | ||
57 | + DeletedAt: u.DeletedAt, | ||
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() |
@@ -95,14 +95,14 @@ func (repo *DepartmentRepository) FindOne(queryOptions map[string]interface{}) ( | @@ -95,14 +95,14 @@ func (repo *DepartmentRepository) FindOne(queryOptions map[string]interface{}) ( | ||
95 | 95 | ||
96 | func (repo *DepartmentRepository) Find(queryOptions map[string]interface{}) (int, []*domain.Department, error) { | 96 | func (repo *DepartmentRepository) Find(queryOptions map[string]interface{}) (int, []*domain.Department, error) { |
97 | tx := repo.transactionContext.PgTx | 97 | tx := repo.transactionContext.PgTx |
98 | - dparmentModel := []models.Department{} | 98 | + var dparmentModel []models.Department |
99 | query := tx.Model(&dparmentModel). | 99 | query := tx.Model(&dparmentModel). |
100 | Limit(20) | 100 | Limit(20) |
101 | if v, ok := queryOptions["id"]; ok { | 101 | if v, ok := queryOptions["id"]; ok { |
102 | query.Where("id=?", v) | 102 | query.Where("id=?", v) |
103 | } | 103 | } |
104 | if v, ok := queryOptions["ids"]; ok { | 104 | if v, ok := queryOptions["ids"]; ok { |
105 | - query.Where("id in(?)", pg.In(v)) | 105 | + query.Where("id in (?)", pg.In(v)) |
106 | } | 106 | } |
107 | if v, ok := queryOptions["limit"]; ok { | 107 | if v, ok := queryOptions["limit"]; ok { |
108 | query.Limit(v.(int)) | 108 | query.Limit(v.(int)) |
@@ -131,8 +131,8 @@ func (repo *DepartmentRepository) TransformToCompanyDomain(u *models.Department) | @@ -131,8 +131,8 @@ func (repo *DepartmentRepository) TransformToCompanyDomain(u *models.Department) | ||
131 | ParentId: u.ParentId, | 131 | ParentId: u.ParentId, |
132 | ChargeUserIds: u.ChargeUserIds, | 132 | ChargeUserIds: u.ChargeUserIds, |
133 | Path: u.Path, | 133 | Path: u.Path, |
134 | - CreateAt: u.CreateAt, | ||
135 | - UpdateAt: u.UpdateAt, | ||
136 | - DeleteAt: u.DeleteAt, | 134 | + CreatedAt: u.CreatedAt, |
135 | + UpdatedAt: u.UpdatedAt, | ||
136 | + DeletedAt: u.DeletedAt, | ||
137 | } | 137 | } |
138 | } | 138 | } |
@@ -27,7 +27,7 @@ func (repo *ReceivedMessageRepository) SaveMessage(param *domain.ReceivedMessage | @@ -27,7 +27,7 @@ func (repo *ReceivedMessageRepository) SaveMessage(param *domain.ReceivedMessage | ||
27 | MessageType: param.MessageType, | 27 | MessageType: param.MessageType, |
28 | MessageBody: param.MessageBody, | 28 | MessageBody: param.MessageBody, |
29 | OccurredOn: param.OccurredOn, | 29 | OccurredOn: param.OccurredOn, |
30 | - CreateAt: time.Now(), | 30 | + CreatedAt: time.Now(), |
31 | } | 31 | } |
32 | tx := repo.transactionContext.PgTx | 32 | tx := repo.transactionContext.PgTx |
33 | _, err := tx.Model(message). | 33 | _, err := tx.Model(message). |
@@ -50,7 +50,7 @@ func (repo *ReceivedMessageRepository) FindMessage(messageId int64) (*domain.Rec | @@ -50,7 +50,7 @@ func (repo *ReceivedMessageRepository) FindMessage(messageId int64) (*domain.Rec | ||
50 | MessageType: receivedMessageModel.MessageType, | 50 | MessageType: receivedMessageModel.MessageType, |
51 | MessageBody: receivedMessageModel.MessageBody, | 51 | MessageBody: receivedMessageModel.MessageBody, |
52 | OccurredOn: receivedMessageModel.OccurredOn, | 52 | OccurredOn: receivedMessageModel.OccurredOn, |
53 | - CreateAt: receivedMessageModel.CreateAt, | 53 | + CreatedAt: receivedMessageModel.CreatedAt, |
54 | } | 54 | } |
55 | return message, nil | 55 | return message, nil |
56 | 56 |
@@ -30,9 +30,9 @@ func (repo *UserRepository) Insert(user *domain.User) (*domain.User, error) { | @@ -30,9 +30,9 @@ func (repo *UserRepository) Insert(user *domain.User) (*domain.User, error) { | ||
30 | AdminType: user.AdminType, | 30 | AdminType: user.AdminType, |
31 | Name: user.Name, | 31 | Name: user.Name, |
32 | Status: user.Status, | 32 | Status: user.Status, |
33 | - UpdateAt: user.UpdateAt, | ||
34 | - CreateAt: user.CreateAt, | ||
35 | - DeleteAt: user.DeleteAt, | 33 | + UpdatedAt: user.UpdateAt, |
34 | + CreatedAt: user.CreateAt, | ||
35 | + DeletedAt: user.DeleteAt, | ||
36 | } | 36 | } |
37 | tx := repo.transactionContext.PgTx | 37 | tx := repo.transactionContext.PgTx |
38 | _, err := tx.Model(&userModel).Insert() | 38 | _, err := tx.Model(&userModel).Insert() |
@@ -53,9 +53,9 @@ func (repo *UserRepository) Update(user *domain.User) (*domain.User, error) { | @@ -53,9 +53,9 @@ func (repo *UserRepository) Update(user *domain.User) (*domain.User, error) { | ||
53 | Name: user.Name, | 53 | Name: user.Name, |
54 | Email: user.Email, | 54 | Email: user.Email, |
55 | Status: user.Status, | 55 | Status: user.Status, |
56 | - UpdateAt: user.UpdateAt, | ||
57 | - CreateAt: user.CreateAt, | ||
58 | - DeleteAt: user.DeleteAt, | 56 | + UpdatedAt: user.UpdateAt, |
57 | + CreatedAt: user.CreateAt, | ||
58 | + DeletedAt: user.DeleteAt, | ||
59 | } | 59 | } |
60 | tx := repo.transactionContext.PgTx | 60 | tx := repo.transactionContext.PgTx |
61 | _, err := tx.Model(&userModel).WherePK().Update() | 61 | _, err := tx.Model(&userModel).WherePK().Update() |
@@ -83,6 +83,9 @@ func (repo *UserRepository) FindOne(queryOptions map[string]interface{}) (*domai | @@ -83,6 +83,9 @@ func (repo *UserRepository) FindOne(queryOptions map[string]interface{}) (*domai | ||
83 | if v, ok := queryOptions["id"]; ok { | 83 | if v, ok := queryOptions["id"]; ok { |
84 | query.Where("id=?", v) | 84 | query.Where("id=?", v) |
85 | } | 85 | } |
86 | + if v, ok := queryOptions["companyId"]; ok { | ||
87 | + query.Where("company_id = ?", v) | ||
88 | + } | ||
86 | err := query.First() | 89 | err := query.First() |
87 | if err == pg.ErrNoRows { | 90 | if err == pg.ErrNoRows { |
88 | return nil, ErrNoRows | 91 | return nil, ErrNoRows |
@@ -142,8 +145,8 @@ func (repo *UserRepository) TransformToUserDomain(user *models.User) *domain.Use | @@ -142,8 +145,8 @@ func (repo *UserRepository) TransformToUserDomain(user *models.User) *domain.Use | ||
142 | Name: user.Name, | 145 | Name: user.Name, |
143 | Email: user.Email, | 146 | Email: user.Email, |
144 | Status: user.Status, | 147 | Status: user.Status, |
145 | - UpdateAt: user.UpdateAt, | ||
146 | - CreateAt: user.CreateAt, | ||
147 | - DeleteAt: user.DeleteAt, | 148 | + UpdateAt: user.UpdatedAt, |
149 | + CreateAt: user.CreatedAt, | ||
150 | + DeleteAt: user.DeletedAt, | ||
148 | } | 151 | } |
149 | } | 152 | } |
1 | +package serviceGateway | ||
2 | + | ||
3 | +import ( | ||
4 | + "crypto/tls" | ||
5 | + "encoding/json" | ||
6 | + "github.com/beego/beego/v2/client/httplib" | ||
7 | + "github.com/linmadan/egglib-go/utils/tool_funs" | ||
8 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log" | ||
9 | + "io/ioutil" | ||
10 | + "net/http" | ||
11 | + "reflect" | ||
12 | + "strings" | ||
13 | + "time" | ||
14 | +) | ||
15 | + | ||
16 | +type httpLibBaseServiceGateway struct { | ||
17 | + baseURL string | ||
18 | + connectTimeout time.Duration | ||
19 | + readWriteTimeout time.Duration | ||
20 | + request *httplib.BeegoHTTPRequest | ||
21 | + params map[string]interface{} | ||
22 | + body string | ||
23 | +} | ||
24 | + | ||
25 | +func (client *httpLibBaseServiceGateway) CreateRequest(method, url string) { | ||
26 | + client.request = httplib.NewBeegoRequest(client.baseURL+url, strings.ToUpper(method)) | ||
27 | + client.request.SetTLSClientConfig(&tls.Config{InsecureSkipVerify: true}) | ||
28 | +} | ||
29 | + | ||
30 | +// 设置请求参数 | ||
31 | +func (client *httpLibBaseServiceGateway) SetParams(params map[string]string) { | ||
32 | + if len(params) > 0 { | ||
33 | + for key, value := range params { | ||
34 | + client.request.Param(key, value) | ||
35 | + client.params[key] = value | ||
36 | + } | ||
37 | + } | ||
38 | +} | ||
39 | + | ||
40 | +// 设置请求参数 | ||
41 | +func (client *httpLibBaseServiceGateway) SetParam(key, value string) { | ||
42 | + client.request.Param(key, value) | ||
43 | + client.params[key] = value | ||
44 | +} | ||
45 | + | ||
46 | +// 设置body | ||
47 | +func (client *httpLibBaseServiceGateway) SetBody(body interface{}) { | ||
48 | + //判断是否为string | ||
49 | + ty := reflect.TypeOf(body) | ||
50 | + if ty.Name() == "string" { | ||
51 | + client.request.Body(body) | ||
52 | + client.body = body.(string) | ||
53 | + } else { | ||
54 | + mBytes, _ := json.Marshal(body) | ||
55 | + client.request.Body(mBytes) | ||
56 | + client.body = string(mBytes) | ||
57 | + } | ||
58 | + client.request.Header("Content-Type", "application/json") | ||
59 | + client.request.Header("Accept", "application/json") | ||
60 | +} | ||
61 | + | ||
62 | +// 设置头信息 | ||
63 | +func (client *httpLibBaseServiceGateway) SetHeader(key, value string) { | ||
64 | + client.request.Header(key, value) | ||
65 | +} | ||
66 | + | ||
67 | +// 设置多个头部信息 | ||
68 | +func (client *httpLibBaseServiceGateway) SetHeaders(headers map[string]string) { | ||
69 | + if len(headers) > 0 { | ||
70 | + for key, value := range headers { | ||
71 | + client.request.Header(key, value) | ||
72 | + } | ||
73 | + } | ||
74 | +} | ||
75 | + | ||
76 | +// 设置超时时间 | ||
77 | +func (client *httpLibBaseServiceGateway) SetTimeout(connectTimeout, readWriteTimeout time.Duration) { | ||
78 | + client.request.SetTimeout(connectTimeout, readWriteTimeout) | ||
79 | +} | ||
80 | + | ||
81 | +// 设置cookie | ||
82 | +func (client *httpLibBaseServiceGateway) SetCookie(cookie *http.Cookie) { | ||
83 | + client.request.SetCookie(cookie) | ||
84 | +} | ||
85 | + | ||
86 | +// 设置UserAgent | ||
87 | +func (client *httpLibBaseServiceGateway) SetUserAgent(userAgent string) { | ||
88 | + client.request.SetUserAgent(userAgent) | ||
89 | +} | ||
90 | + | ||
91 | +// 请求结果返回结构体 | ||
92 | +func (client *httpLibBaseServiceGateway) ToJson(result interface{}) error { | ||
93 | + response, err := client.request.Response() | ||
94 | + if err != nil { | ||
95 | + return err | ||
96 | + } | ||
97 | + client.addOptionLog(response) | ||
98 | + mBytes, err := ioutil.ReadAll(response.Body) | ||
99 | + if err != nil { | ||
100 | + return err | ||
101 | + } | ||
102 | + err = json.Unmarshal(mBytes, result) | ||
103 | + //增加返回数据日志 | ||
104 | + log.Logger.Debug(response.Request.Method+" "+response.Request.URL.String()+"----response----", tool_funs.SimpleStructToMap(result)) | ||
105 | + return err | ||
106 | +} | ||
107 | + | ||
108 | +// 请求结果返回string | ||
109 | +func (client *httpLibBaseServiceGateway) ToString() (string, error) { | ||
110 | + response, err := client.request.Response() | ||
111 | + if err != nil { | ||
112 | + return "", err | ||
113 | + } | ||
114 | + client.addOptionLog(response) | ||
115 | + mBytes, err := ioutil.ReadAll(response.Body) | ||
116 | + //增加返回数据日志 | ||
117 | + log.Logger.Debug(response.Request.Method + " " + response.Request.URL.String() + "----response----" + string(mBytes)) | ||
118 | + return string(mBytes), err | ||
119 | +} | ||
120 | + | ||
121 | +// 请求结果返回bytes | ||
122 | +func (client *httpLibBaseServiceGateway) ToBytes() ([]byte, error) { | ||
123 | + response, err := client.request.Response() | ||
124 | + if err != nil { | ||
125 | + return nil, err | ||
126 | + } | ||
127 | + client.addOptionLog(response) | ||
128 | + mBytes, _ := ioutil.ReadAll(response.Body) | ||
129 | + //增加返回数据日志 | ||
130 | + log.Logger.Debug(response.Request.Method + " " + response.Request.URL.String() + "----response----" + string(mBytes)) | ||
131 | + return mBytes, nil | ||
132 | +} | ||
133 | + | ||
134 | +// 添加options日志 | ||
135 | +func (client *httpLibBaseServiceGateway) addOptionLog(response *http.Response) { | ||
136 | + logTxt := response.Request.Method + " " + response.Request.URL.String() | ||
137 | + if response.Request.Method != http.MethodGet { | ||
138 | + contentType := client.request.GetRequest().Header.Get("Content-Type") | ||
139 | + if strings.Contains(strings.ToLower(contentType), "json") { | ||
140 | + log.Logger.Debug(logTxt+" ----options----", map[string]interface{}{"body": client.body}) | ||
141 | + } else { | ||
142 | + log.Logger.Debug(logTxt+" ----options----", map[string]interface{}{"params": client.params}) | ||
143 | + } | ||
144 | + } | ||
145 | +} |
1 | +package serviceGateway | ||
2 | + | ||
3 | +import ( | ||
4 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/constant" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/serviceGateway/reply" | ||
6 | + "net/http" | ||
7 | +) | ||
8 | + | ||
9 | +type HttpLibBusinessAdminServiceGateway struct { | ||
10 | + httpLibBaseServiceGateway | ||
11 | +} | ||
12 | + | ||
13 | +// GetUserAuth 请求企业平台确认用户是否可以使用 | ||
14 | +func (serviceGateway *HttpLibBusinessAdminServiceGateway) GetUserAuth(userId int64, platformId int) (*reply.BusinessAdminUserAuth, error) { | ||
15 | + businessAdminUserAuth := &reply.BusinessAdminUserAuth{} | ||
16 | + serviceGateway.CreateRequest(http.MethodPost, "/auth/get-user-auth") | ||
17 | + serviceGateway.SetBody(map[string]interface{}{ | ||
18 | + "userId": userId, | ||
19 | + "platformId": platformId, | ||
20 | + }) | ||
21 | + err := serviceGateway.ToJson(businessAdminUserAuth) | ||
22 | + return businessAdminUserAuth, err | ||
23 | +} | ||
24 | + | ||
25 | +func NewHttpLibBusinessAdminServiceGateway() *HttpLibBusinessAdminServiceGateway { | ||
26 | + return &HttpLibBusinessAdminServiceGateway{ | ||
27 | + httpLibBaseServiceGateway{ | ||
28 | + baseURL: constant.BUSINESS_ADMIN_SERVICE_HOST, | ||
29 | + }, | ||
30 | + } | ||
31 | +} |
1 | +package serviceGateway | ||
2 | + | ||
3 | +import ( | ||
4 | + "crypto/sha1" | ||
5 | + "fmt" | ||
6 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/constant" | ||
7 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/serviceGateway/reply" | ||
8 | + "net/http" | ||
9 | + "net/url" | ||
10 | + "time" | ||
11 | +) | ||
12 | + | ||
13 | +type HttpLibUCenterApiServiceGateway struct { | ||
14 | + httpLibBaseServiceGateway | ||
15 | +} | ||
16 | + | ||
17 | +func (serviceGateway *HttpLibUCenterApiServiceGateway) buildHeaders() map[string]string { | ||
18 | + nowTime := fmt.Sprint(time.Now().Unix()) | ||
19 | + str := fmt.Sprintf("%s%s%s", nowTime, constant.UCENTER_SECRET, constant.UCENTER_CHECK_ALT) | ||
20 | + bt := sha1.Sum([]byte(str)) | ||
21 | + checksum := fmt.Sprintf("%x", bt) | ||
22 | + return map[string]string{ | ||
23 | + "appKey": constant.UCENTER_APP_KEY, | ||
24 | + "nonce": "", | ||
25 | + "curTime": nowTime, | ||
26 | + "checkSum": checksum, | ||
27 | + } | ||
28 | +} | ||
29 | + | ||
30 | +// AuthCode PC端登录 | ||
31 | +func (serviceGateway *HttpLibUCenterApiServiceGateway) AuthCode(code string) (*reply.UCenterAuthCode, error) { | ||
32 | + authCodeReply := &reply.UCenterAuthCode{} | ||
33 | + serviceGateway.CreateRequest(http.MethodPost, "/auth/serverLogin") | ||
34 | + serviceGateway.SetBody(map[string]interface{}{ | ||
35 | + "type": 3, | ||
36 | + "secret": url.QueryEscape(code), | ||
37 | + }) | ||
38 | + serviceGateway.SetHeaders(serviceGateway.buildHeaders()) | ||
39 | + err := serviceGateway.ToJson(authCodeReply) | ||
40 | + return authCodeReply, err | ||
41 | +} | ||
42 | + | ||
43 | +func NewHttpLibUCenterApiServiceGateway() *HttpLibUCenterApiServiceGateway { | ||
44 | + return &HttpLibUCenterApiServiceGateway{ | ||
45 | + httpLibBaseServiceGateway{baseURL: constant.UCENTER_SERVICE_HOST}, | ||
46 | + } | ||
47 | +} |
1 | +package reply | ||
2 | + | ||
3 | +type BusinessAdminUserAuth struct { | ||
4 | + BaseReply | ||
5 | + Data struct { | ||
6 | + UserAuth bool `json:"userAuth"` | ||
7 | + } `json:"data"` | ||
8 | +} | ||
9 | + | ||
10 | +func (businessAdminUserAuth *BusinessAdminUserAuth) Message() string { | ||
11 | + if businessAdminUserAuth.Code == 10001 { | ||
12 | + return "用户不存在" | ||
13 | + } | ||
14 | + if businessAdminUserAuth.Code == 10002 { | ||
15 | + return "登录凭证已过期,请重新登陆" | ||
16 | + } | ||
17 | + if businessAdminUserAuth.Code == 10003 { | ||
18 | + return "验证码不能为空" | ||
19 | + } | ||
20 | + if businessAdminUserAuth.Code == 10004 { | ||
21 | + return "登录凭证不能为空" | ||
22 | + } | ||
23 | + if businessAdminUserAuth.Code == 10005 { | ||
24 | + return "密码不能为空" | ||
25 | + } | ||
26 | + if businessAdminUserAuth.Code == 10006 { | ||
27 | + return "当前账号已被禁用" | ||
28 | + } | ||
29 | + if businessAdminUserAuth.Code == 10007 { | ||
30 | + return "该企业已被禁用,无法正常访问!重新选择其他企业进入,或退出登录。" | ||
31 | + } | ||
32 | + if businessAdminUserAuth.Code == 10008 { | ||
33 | + return "抱歉,企业管理员未帮您开通权限。如需访问,请联系企业管理员" | ||
34 | + } | ||
35 | + if businessAdminUserAuth.Code == 10009 { | ||
36 | + return "密码错误" | ||
37 | + } | ||
38 | + if businessAdminUserAuth.Code == 10010 { | ||
39 | + return "验证码错误" | ||
40 | + } | ||
41 | + return "你没有权限进入系统,请联系管理员" | ||
42 | +} |
1 | +package reply | ||
2 | + | ||
3 | +type UCenterAuthCode struct { | ||
4 | + BaseReply | ||
5 | + Data struct { | ||
6 | + Id int64 `json:"id"` //统一用户中心的id,对应本系统中users表的open_id | ||
7 | + Phone string `json:"phone"` //手机号 ,账号 | ||
8 | + NickName string `json:"nickname"` //昵称 | ||
9 | + Avatar string `json:"avatar"` //头像 | ||
10 | + ImToken string `json:"imtoken"` //网易云imtoken | ||
11 | + AccId int64 `json:"accid"` //网易云id | ||
12 | + CustomerAccount int64 `json:"customerAccount"` //客服id | ||
13 | + CompanyId int64 `json:"companyId"` //总后台的公司id ,对应company表中的admin_company_id | ||
14 | + MUid int64 `json:"muid"` //企业平台的用户id,对应本系统中users表的id | ||
15 | + } `json:"data"` | ||
16 | +} |
1 | +package controllers | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/linmadan/egglib-go/web/beego" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/auth/command" | ||
6 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/auth/service" | ||
7 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" | ||
8 | +) | ||
9 | + | ||
10 | +type AuthController struct { | ||
11 | + beego.BaseController | ||
12 | +} | ||
13 | + | ||
14 | +// Login PC端登录 | ||
15 | +func (controller *AuthController) Login() { | ||
16 | + authService := &service.AuthService{} | ||
17 | + loginCommand := &command.LoginCommand{} | ||
18 | + _ = controller.Unmarshal(loginCommand) | ||
19 | + resp, err := authService.Login(loginCommand) | ||
20 | + controller.Response(resp, err) | ||
21 | +} | ||
22 | + | ||
23 | +func (controller *AuthController) User() { | ||
24 | + | ||
25 | + userAuth := controller.Ctx.Input.GetData(domain.UserAuth{}).(*domain.UserAuth) | ||
26 | + controller.Response(map[string]interface{}{ | ||
27 | + "user": userAuth, | ||
28 | + }, nil) | ||
29 | +} |
1 | +package middlewares | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/beego/beego/v2/server/web/context" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/constant" | ||
6 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" | ||
7 | +) | ||
8 | + | ||
9 | +func CheckAdminToken() func(ctx *context.Context) { | ||
10 | + return func(ctx *context.Context) { | ||
11 | + adminToken := ctx.Input.Header("x-admin-token") | ||
12 | + userAuth, err := (&domain.UserAuth{}).ParseAccessToken(adminToken) | ||
13 | + if err != nil || userAuth.UserId <= 0 { | ||
14 | + forbidden(ctx) | ||
15 | + return | ||
16 | + } | ||
17 | + if userAuth.PlatformId != constant.PLATFORM_ADMIN_ID { | ||
18 | + forbidden(ctx) | ||
19 | + return | ||
20 | + } | ||
21 | + ctx.Input.SetData(domain.UserAuth{}, userAuth) | ||
22 | + } | ||
23 | +} | ||
24 | + | ||
25 | +func forbidden(ctx *context.Context) { | ||
26 | + resp := map[string]interface{}{ | ||
27 | + "code": 902, | ||
28 | + "msg": "Authorization过期或无效,需要进行重新获取令牌", | ||
29 | + } | ||
30 | + _ = ctx.Output.JSON(resp, false, false) | ||
31 | +} |
1 | +package middlewares | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/beego/beego/v2/server/web/context" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/constant" | ||
6 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" | ||
7 | +) | ||
8 | + | ||
9 | +func CheckFontToken() func(ctx *context.Context) { | ||
10 | + return func(ctx *context.Context) { | ||
11 | + adminToken := ctx.Input.Header("x-font-token") | ||
12 | + userAuth, err := (&domain.UserAuth{}).ParseAccessToken(adminToken) | ||
13 | + if err != nil || userAuth.UserId <= 0 { | ||
14 | + forbidden(ctx) | ||
15 | + return | ||
16 | + } | ||
17 | + if userAuth.PlatformId != constant.PLATFORM_FONT_ID { | ||
18 | + forbidden(ctx) | ||
19 | + return | ||
20 | + } | ||
21 | + ctx.Input.SetData(domain.UserAuth{}, userAuth) | ||
22 | + } | ||
23 | +} |
pkg/port/beego/routers/auth.go
0 → 100644
1 | +package routers | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/beego/beego/v2/server/web" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/controllers" | ||
6 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego/middlewares" | ||
7 | +) | ||
8 | + | ||
9 | +func init() { | ||
10 | + web.Router("/login", &controllers.AuthController{}, "Post:Login") | ||
11 | + | ||
12 | + web.InsertFilter("/auth/admin/*", web.BeforeExec, middlewares.CheckAdminToken()) | ||
13 | + web.Router("/auth/admin/user", &controllers.AuthController{}, "Get:User") | ||
14 | + | ||
15 | + web.InsertFilter("/auth/font/*", web.BeforeExec, middlewares.CheckFontToken()) | ||
16 | + web.Router("/auth/font/user", &controllers.AuthController{}, "Get:User") | ||
17 | +} |
-
请 注册 或 登录 后发表评论