正在显示
19 个修改的文件
包含
261 行增加
和
60 行删除
@@ -11,6 +11,8 @@ import ( | @@ -11,6 +11,8 @@ import ( | ||
11 | type RefreshIMCommand struct { | 11 | type RefreshIMCommand struct { |
12 | // 手机号码 | 12 | // 手机号码 |
13 | Phone string `cname:"手机号码" json:"phone" valid:"Required"` | 13 | Phone string `cname:"手机号码" json:"phone" valid:"Required"` |
14 | + // 刷新标识 0:刷新IM信息,并返回 1:使用旧的im信息 | ||
15 | + RefreshFlag int `cname:"刷新标识" json:"refreshFlag"` | ||
14 | } | 16 | } |
15 | 17 | ||
16 | func (refreshIMCommand *RefreshIMCommand) Valid(validation *validation.Validation) { | 18 | func (refreshIMCommand *RefreshIMCommand) Valid(validation *validation.Validation) { |
@@ -9,6 +9,8 @@ import ( | @@ -9,6 +9,8 @@ import ( | ||
9 | ) | 9 | ) |
10 | 10 | ||
11 | type UserInfoQuery struct { | 11 | type UserInfoQuery struct { |
12 | + // 用户Id 用户唯一标识 | ||
13 | + UserId int64 `cname:"用户Id 用户唯一标识" json:"userId"` | ||
12 | } | 14 | } |
13 | 15 | ||
14 | func (userInfoQuery *UserInfoQuery) Valid(validation *validation.Validation) { | 16 | func (userInfoQuery *UserInfoQuery) Valid(validation *validation.Validation) { |
@@ -6,6 +6,7 @@ import ( | @@ -6,6 +6,7 @@ import ( | ||
6 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/auth/query" | 6 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/auth/query" |
7 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/factory" | 7 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/factory" |
8 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | 8 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" |
9 | + "strconv" | ||
9 | "time" | 10 | "time" |
10 | ) | 11 | ) |
11 | 12 | ||
@@ -286,10 +287,19 @@ func (authService *AuthService) RefreshIM(refreshIMCommand *command.RefreshIMCom | @@ -286,10 +287,19 @@ func (authService *AuthService) RefreshIM(refreshIMCommand *command.RefreshIMCom | ||
286 | defer func() { | 287 | defer func() { |
287 | transactionContext.RollbackTransaction() | 288 | transactionContext.RollbackTransaction() |
288 | }() | 289 | }() |
290 | + | ||
291 | + imService, _ := factory.CreatePgImService(map[string]interface{}{ | ||
292 | + "transactionContext": transactionContext, | ||
293 | + }) | ||
294 | + userId, _ := strconv.Atoi(refreshIMCommand.Phone) | ||
295 | + imInfo, err := imService.InitOrUpdateUserIMInfo(int64(userId), refreshIMCommand.RefreshFlag) | ||
296 | + if err != nil { | ||
297 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
298 | + } | ||
289 | if err := transactionContext.CommitTransaction(); err != nil { | 299 | if err := transactionContext.CommitTransaction(); err != nil { |
290 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 300 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
291 | } | 301 | } |
292 | - return nil, nil | 302 | + return imInfo, nil |
293 | } | 303 | } |
294 | 304 | ||
295 | // 用户信息 | 305 | // 用户信息 |
@@ -256,6 +256,19 @@ func (companyService *CompanyService) UpdateCompany(updateCompanyCommand *comman | @@ -256,6 +256,19 @@ func (companyService *CompanyService) UpdateCompany(updateCompanyCommand *comman | ||
256 | if err := company.Update(tool_funs.SimpleStructToMap(updateCompanyCommand)); err != nil { | 256 | if err := company.Update(tool_funs.SimpleStructToMap(updateCompanyCommand)); err != nil { |
257 | return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | 257 | return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) |
258 | } | 258 | } |
259 | + | ||
260 | + orgRepository, _, _ := factory.FastPgOrg(transactionContext, 0) | ||
261 | + if org, err := orgRepository.FindOne(map[string]interface{}{"companyId": updateCompanyCommand.CompanyId, "parentId": 0}); err != nil { | ||
262 | + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | ||
263 | + } else { | ||
264 | + if org.OrgName != company.CompanyInfo.CompanyName { | ||
265 | + org.Update(map[string]interface{}{"orgName": company.CompanyInfo.CompanyName}) | ||
266 | + } | ||
267 | + if _, err := orgRepository.Save(org); err != nil { | ||
268 | + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | ||
269 | + } | ||
270 | + } | ||
271 | + | ||
259 | if company, err := companyRepository.Save(company); err != nil { | 272 | if company, err := companyRepository.Save(company); err != nil { |
260 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 273 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
261 | } else { | 274 | } else { |
@@ -78,3 +78,11 @@ func CreatePgRoleAccessMenusService(options map[string]interface{}) (service.PgR | @@ -78,3 +78,11 @@ func CreatePgRoleAccessMenusService(options map[string]interface{}) (service.PgR | ||
78 | } | 78 | } |
79 | return domainService.NewPgRoleAccessMenusService(transactionContext) | 79 | return domainService.NewPgRoleAccessMenusService(transactionContext) |
80 | } | 80 | } |
81 | + | ||
82 | +func CreatePgImService(options map[string]interface{}) (service.PgImService, error) { | ||
83 | + var transactionContext *pgTransaction.TransactionContext | ||
84 | + if value, ok := options["transactionContext"]; ok { | ||
85 | + transactionContext = value.(*pgTransaction.TransactionContext) | ||
86 | + } | ||
87 | + return domainService.NewPgImService(transactionContext) | ||
88 | +} |
@@ -31,6 +31,7 @@ type UserDto struct { | @@ -31,6 +31,7 @@ type UserDto struct { | ||
31 | Organization *domain.Org `json:"org,omitempty"` | 31 | Organization *domain.Org `json:"org,omitempty"` |
32 | // 部门 | 32 | // 部门 |
33 | Department *domain.Department `json:"department,omitempty"` | 33 | Department *domain.Department `json:"department,omitempty"` |
34 | + Im *domain.Im `json:"im,omitempty"` | ||
34 | } | 35 | } |
35 | 36 | ||
36 | type Company struct { | 37 | type Company struct { |
@@ -39,6 +40,8 @@ type Company struct { | @@ -39,6 +40,8 @@ type Company struct { | ||
39 | // 企业基本信息 | 40 | // 企业基本信息 |
40 | domain.CompanyInfo | 41 | domain.CompanyInfo |
41 | Status int `json:"status"` | 42 | Status int `json:"status"` |
43 | + // 系统名称 | ||
44 | + SystemName string `json:"systemName,omitempty"` | ||
42 | } | 45 | } |
43 | 46 | ||
44 | func (dto *UserDto) LoadDto(user *domain.User, company *domain.Company) error { | 47 | func (dto *UserDto) LoadDto(user *domain.User, company *domain.Company) error { |
@@ -57,6 +60,7 @@ func (dto *UserDto) LoadDto(user *domain.User, company *domain.Company) error { | @@ -57,6 +60,7 @@ func (dto *UserDto) LoadDto(user *domain.User, company *domain.Company) error { | ||
57 | CompanyId: company.CompanyId, | 60 | CompanyId: company.CompanyId, |
58 | CompanyInfo: *company.CompanyInfo, | 61 | CompanyInfo: *company.CompanyInfo, |
59 | Status: company.Status, | 62 | Status: company.Status, |
63 | + SystemName: company.CompanyConfig.SystemName, | ||
60 | } | 64 | } |
61 | } | 65 | } |
62 | if user.UserInfo == nil { | 66 | if user.UserInfo == nil { |
@@ -22,7 +22,7 @@ type ListUserQuery struct { | @@ -22,7 +22,7 @@ type ListUserQuery struct { | ||
22 | // 部门编号 | 22 | // 部门编号 |
23 | DepartmentId int64 `cname:"部门编号" json:"departmentId,omitempty"` | 23 | DepartmentId int64 `cname:"部门编号" json:"departmentId,omitempty"` |
24 | // 用户基础ID | 24 | // 用户基础ID |
25 | - UserBaseId string `cname:"用户基础ID" json:"userBaseId,omitempty"` | 25 | + UserBaseId int64 `cname:"用户基础ID" json:"userBaseId,omitempty"` |
26 | // 用户姓名 | 26 | // 用户姓名 |
27 | UserName string `cname:"用户姓名" json:"userName,omitempty"` | 27 | UserName string `cname:"用户姓名" json:"userName,omitempty"` |
28 | // 共创公司 | 28 | // 共创公司 |
@@ -37,6 +37,8 @@ type ListUserQuery struct { | @@ -37,6 +37,8 @@ type ListUserQuery struct { | ||
37 | InOrgIds []int64 `cname:"在组织范围内" json:"inOrgIds,omitempty"` | 37 | InOrgIds []int64 `cname:"在组织范围内" json:"inOrgIds,omitempty"` |
38 | // 实时拉取数据 (获取最新的) | 38 | // 实时拉取数据 (获取最新的) |
39 | PullRealTime bool `cname:"拉取最新数据" json:"pullRealTime,omitempty"` | 39 | PullRealTime bool `cname:"拉取最新数据" json:"pullRealTime,omitempty"` |
40 | + // 状态(1:启用 2:禁用 3:注销) | ||
41 | + EnableStatus int `cname:"状态(1:启用 2:禁用 3:注销)" json:"enableStatus,omitempty"` | ||
40 | } | 42 | } |
41 | 43 | ||
42 | func (listUserQuery *ListUserQuery) Valid(validation *validation.Validation) { | 44 | func (listUserQuery *ListUserQuery) Valid(validation *validation.Validation) { |
@@ -328,7 +328,7 @@ func (userService *UserService) GetUser(getUserQuery *query.GetUserQuery) (inter | @@ -328,7 +328,7 @@ func (userService *UserService) GetUser(getUserQuery *query.GetUserQuery) (inter | ||
328 | user.Company = company.CloneSample() | 328 | user.Company = company.CloneSample() |
329 | user.UserInfo = userBase.UserInfo | 329 | user.UserInfo = userBase.UserInfo |
330 | } | 330 | } |
331 | - userDto := &dto.UserDto{} | 331 | + userDto := &dto.UserDto{Im: userBase.Im} |
332 | if err := userDto.LoadDto(user, company); err != nil { | 332 | if err := userDto.LoadDto(user, company); err != nil { |
333 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 333 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
334 | } | 334 | } |
@@ -448,7 +448,7 @@ func (userService *UserService) ListUser(listUserQuery *query.ListUserQuery) (in | @@ -448,7 +448,7 @@ func (userService *UserService) ListUser(listUserQuery *query.ListUserQuery) (in | ||
448 | } else { | 448 | } else { |
449 | userRepository = value | 449 | userRepository = value |
450 | } | 450 | } |
451 | - _, company, _ := factory.FastPgCompany(transactionContext, listUserQuery.CompanyId) | 451 | + _, company, _ := factory.FastPgCompany(transactionContext, listUserQuery.OperateInfo.GetCompanyId(listUserQuery.CompanyId)) |
452 | var dtoUsers []*dto.UserDto | 452 | var dtoUsers []*dto.UserDto |
453 | queryOptions := utils.ObjectToMap(listUserQuery) | 453 | queryOptions := utils.ObjectToMap(listUserQuery) |
454 | if len(listUserQuery.Phone) > 0 { | 454 | if len(listUserQuery.Phone) > 0 { |
@@ -465,6 +465,9 @@ func (userService *UserService) ListUser(listUserQuery *query.ListUserQuery) (in | @@ -465,6 +465,9 @@ func (userService *UserService) ListUser(listUserQuery *query.ListUserQuery) (in | ||
465 | for i := range users { | 465 | for i := range users { |
466 | user := users[i] | 466 | user := users[i] |
467 | userDto := &dto.UserDto{} | 467 | userDto := &dto.UserDto{} |
468 | + if company == nil && user.CompanyId != 0 { | ||
469 | + _, company, _ = factory.FastPgCompany(transactionContext, user.CompanyId) | ||
470 | + } | ||
468 | if listUserQuery.PullRealTime { | 471 | if listUserQuery.PullRealTime { |
469 | _, dep, _ := factory.FastPgOrg(transactionContext, user.DepartmentId) | 472 | _, dep, _ := factory.FastPgOrg(transactionContext, user.DepartmentId) |
470 | _, org, _ := factory.FastPgOrg(transactionContext, user.OrganizationId) | 473 | _, org, _ := factory.FastPgOrg(transactionContext, user.OrganizationId) |
@@ -3,6 +3,8 @@ package constant | @@ -3,6 +3,8 @@ package constant | ||
3 | import ( | 3 | import ( |
4 | "fmt" | 4 | "fmt" |
5 | "os" | 5 | "os" |
6 | + "strconv" | ||
7 | + "strings" | ||
6 | ) | 8 | ) |
7 | 9 | ||
8 | var SERVICE_NAME = "allied-creation-user" | 10 | var SERVICE_NAME = "allied-creation-user" |
@@ -10,6 +12,10 @@ var SERVICE_ENV = "dev" | @@ -10,6 +12,10 @@ var SERVICE_ENV = "dev" | ||
10 | var CACHE_PREFIX = "allied-creation-user-dev" | 12 | var CACHE_PREFIX = "allied-creation-user-dev" |
11 | var LOG_LEVEL = "debug" | 13 | var LOG_LEVEL = "debug" |
12 | 14 | ||
15 | +var CUSTOMER_ACCOUNT = []int64{3129687560814592, 3129687690100739, 3492238958608384} | ||
16 | + | ||
17 | +const CUSTOMER_ACCOUNT_DELIMITER = "," | ||
18 | + | ||
13 | /***** 1.数据传输 *****/ | 19 | /***** 1.数据传输 *****/ |
14 | const HeaderCompanyId = "companyId" | 20 | const HeaderCompanyId = "companyId" |
15 | const HeaderUserId = "userId" | 21 | const HeaderUserId = "userId" |
@@ -19,5 +25,20 @@ func init() { | @@ -19,5 +25,20 @@ func init() { | ||
19 | if os.Getenv("LOG_LEVEL") != "" { | 25 | if os.Getenv("LOG_LEVEL") != "" { |
20 | LOG_LEVEL = os.Getenv("LOG_LEVEL") | 26 | LOG_LEVEL = os.Getenv("LOG_LEVEL") |
21 | } | 27 | } |
28 | + if os.Getenv("CUSTOMER_ACCOUNT") != "" { | ||
29 | + account := os.Getenv("CUSTOMER_ACCOUNT") | ||
30 | + accounts := strings.Split(account, CUSTOMER_ACCOUNT_DELIMITER) | ||
31 | + var tmpAccounts []int64 | ||
32 | + for i := range accounts { | ||
33 | + v, err := strconv.ParseInt(accounts[i], 10, 64) | ||
34 | + if err != nil { | ||
35 | + panic(err) | ||
36 | + } | ||
37 | + tmpAccounts = append(tmpAccounts, v) | ||
38 | + } | ||
39 | + if len(tmpAccounts) > 0 { | ||
40 | + CUSTOMER_ACCOUNT = tmpAccounts | ||
41 | + } | ||
42 | + } | ||
22 | CACHE_PREFIX = fmt.Sprintf("%v-%v", SERVICE_NAME, SERVICE_ENV) | 43 | CACHE_PREFIX = fmt.Sprintf("%v-%v", SERVICE_NAME, SERVICE_ENV) |
23 | } | 44 | } |
pkg/constant/im.go
0 → 100644
1 | +package constant | ||
2 | + | ||
3 | +import "os" | ||
4 | + | ||
5 | +var ( | ||
6 | + IM_SERVICE_ADDRESS = "https://api.netease.im/nimserver" | ||
7 | + IM_APP_KEY = "be7c0639c10e6a69f86ce3b4fa8dc8ec" //"ebf3ae278ee1b346773b99be5080f6a9" | ||
8 | + IM_APP_SECRET = "9c5b60346613" //"67ea92e1ea45" | ||
9 | +) | ||
10 | + | ||
11 | +func init() { | ||
12 | + if os.Getenv("IM_APP_KEY") != "" { | ||
13 | + IM_APP_KEY = os.Getenv("IM_APP_KEY") | ||
14 | + } | ||
15 | + if os.Getenv("IM_APP_SECRET") != "" { | ||
16 | + IM_APP_SECRET = os.Getenv("IM_APP_SECRET") | ||
17 | + } | ||
18 | +} |
pkg/domain/service/pg_im_service.go
0 → 100644
1 | +package domainService | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
6 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/repository" | ||
7 | +) | ||
8 | + | ||
9 | +// PgCommonStatisticsService 通用统计服务 | ||
10 | +type PgCommonStatisticsService struct { | ||
11 | + transactionContext *pgTransaction.TransactionContext | ||
12 | +} | ||
13 | + | ||
14 | +const ( | ||
15 | + // 累计组织用户 | ||
16 | + TotalOrganizationUser = iota + 1 | ||
17 | +) | ||
18 | + | ||
19 | +var ( | ||
20 | + mapStatistics = map[int]string{ | ||
21 | + TotalOrganizationUser: "totalOrganizationUser", | ||
22 | + } | ||
23 | +) | ||
24 | + | ||
25 | +// Scan 扫描需要统计的项 | ||
26 | +// | ||
27 | +// keyFlags 统计项标识符号 | ||
28 | +// queryOption 查询参数 | ||
29 | +func (ptr *PgCommonStatisticsService) Scan(keyFlags []int, queryOption map[string]interface{}) (interface{}, error) { | ||
30 | + var res = make(map[string]interface{}) | ||
31 | + for i := range keyFlags { | ||
32 | + switch keyFlags[i] { | ||
33 | + case TotalOrganizationUser: | ||
34 | + queryTotalOrganizationUser, err := ptr.loadQueryOptions(queryOption, "companyId", "organizationId") | ||
35 | + if err != nil { | ||
36 | + return nil, err | ||
37 | + } | ||
38 | + if v, err := ptr.totalOrganizationUser(queryTotalOrganizationUser); err != nil { | ||
39 | + return nil, err | ||
40 | + } else { | ||
41 | + res[v.key] = v.val | ||
42 | + } | ||
43 | + } | ||
44 | + } | ||
45 | + return res, nil | ||
46 | +} | ||
47 | + | ||
48 | +// totalOrganizationUser 统计组织用户 | ||
49 | +func (ptr *PgCommonStatisticsService) totalOrganizationUser(queryOption map[string]interface{}) (item, error) { | ||
50 | + res := item{ | ||
51 | + key: mapStatistics[TotalOrganizationUser], | ||
52 | + } | ||
53 | + userRepository, _ := repository.NewUserRepository(ptr.transactionContext) | ||
54 | + if total, _, err := userRepository.Find(queryOption); err != nil { | ||
55 | + return res, err | ||
56 | + } else { | ||
57 | + res.val = map[string]interface{}{ | ||
58 | + "total": total, | ||
59 | + } | ||
60 | + } | ||
61 | + return res, nil | ||
62 | +} | ||
63 | + | ||
64 | +func (ptr *PgCommonStatisticsService) loadQueryOptions(queryOption map[string]interface{}, keys ...string) (map[string]interface{}, error) { | ||
65 | + var res = make(map[string]interface{}) | ||
66 | + for i := 0; i < len(keys); i++ { | ||
67 | + k := keys[i] | ||
68 | + if v, ok := queryOption[k]; ok { | ||
69 | + res[k] = v | ||
70 | + } else { | ||
71 | + return nil, fmt.Errorf("参数 %v 不存在", k) | ||
72 | + } | ||
73 | + } | ||
74 | + return res, nil | ||
75 | +} | ||
76 | + | ||
77 | +type item struct { | ||
78 | + key string | ||
79 | + val interface{} | ||
80 | +} |
@@ -3,8 +3,10 @@ package domainService | @@ -3,8 +3,10 @@ package domainService | ||
3 | import ( | 3 | import ( |
4 | "fmt" | 4 | "fmt" |
5 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | 5 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" |
6 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/constant" | ||
6 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" | 7 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain" |
7 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/im" | 8 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/im" |
9 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/repository" | ||
8 | ) | 10 | ) |
9 | 11 | ||
10 | // PgImService 网易云信IM服务 | 12 | // PgImService 网易云信IM服务 |
@@ -12,54 +14,49 @@ type PgImService struct { | @@ -12,54 +14,49 @@ type PgImService struct { | ||
12 | transactionContext *pgTransaction.TransactionContext | 14 | transactionContext *pgTransaction.TransactionContext |
13 | } | 15 | } |
14 | 16 | ||
15 | -func (s *PgImService) InitOrUpdateUserIMInfo(userId int64, name string) (imInfo *domain.Im, err error) { | 17 | +func (ptr *PgImService) InitOrUpdateUserIMInfo(userId int64, flag int) (*domain.Im, error) { |
16 | var ( | 18 | var ( |
17 | - //ImInfoRepository, _ = factory.CreateImInfoRepository(ctx) | ||
18 | checkImRequest *im.CheckImRequest = &im.CheckImRequest{} | 19 | checkImRequest *im.CheckImRequest = &im.CheckImRequest{} |
19 | IsCreated = false | 20 | IsCreated = false |
20 | checkImResponse *im.CheckImResponse | 21 | checkImResponse *im.CheckImResponse |
21 | ) | 22 | ) |
22 | - var errFind error | ||
23 | - //imInfo, errFind = ImInfoRepository.FindOne(map[string]interface{}{"user_id": userId}) | ||
24 | - // 异常 | ||
25 | - //if errFind != nil && errFind != domain.QueryNoRow { | ||
26 | - // err = errFind | ||
27 | - // return | ||
28 | - //} | ||
29 | - // 不存在 | ||
30 | - //if errFind == domain.QueryNoRow { | ||
31 | - // imInfo = &domain.Im{ | ||
32 | - // UserId: userId, | ||
33 | - // CreateTime: time.Now(), | ||
34 | - // } | ||
35 | - //} | ||
36 | - // 已存在 | ||
37 | - if errFind == nil && imInfo != nil { | ||
38 | - IsCreated = true | 23 | + userBaseRepository, _ := repository.NewUserBaseRepository(ptr.transactionContext) |
24 | + userBase, err := userBaseRepository.FindOne(map[string]interface{}{"account": fmt.Sprintf("%v", userId)}) | ||
25 | + if err != nil || userBase == nil || userBase.Status != int(domain.UserStatusEnable) { | ||
26 | + return nil, fmt.Errorf("账号不存在") | ||
39 | } | 27 | } |
40 | - | ||
41 | - if len(imInfo.Accid) == 0 { | ||
42 | - //id, _ := utils.NewSnowflakeId() | ||
43 | - //imInfo.ImId = fmt.Sprintf("%v", id) | 28 | + if userBase.Im != nil && len(userBase.Im.Accid) > 0 { |
29 | + IsCreated = true | ||
30 | + if flag == domain.RefreshWhenNotExists { | ||
31 | + return userBase.Im, nil | ||
32 | + } | ||
33 | + } else { | ||
34 | + id, err := repository.IdWorker.NextId() | ||
35 | + if err != nil { | ||
36 | + return nil, err | ||
37 | + } | ||
38 | + userBase.Im = &domain.Im{ | ||
39 | + Accid: fmt.Sprintf("%v", id), | ||
40 | + } | ||
44 | } | 41 | } |
45 | checkImRequest = &im.CheckImRequest{ | 42 | checkImRequest = &im.CheckImRequest{ |
46 | UserId: userId, | 43 | UserId: userId, |
47 | - ImId: imInfo.Accid, | ||
48 | - Uname: name, | ||
49 | - CustomerImId: fmt.Sprintf("%v", imInfo.CsAccountId), | 44 | + ImId: userBase.Im.Accid, |
45 | + Uname: userBase.UserInfo.UserName, | ||
46 | + CustomerImId: fmt.Sprintf("%v", userBase.Im.CsAccountId), | ||
50 | IsCreated: IsCreated, | 47 | IsCreated: IsCreated, |
51 | } | 48 | } |
52 | if checkImResponse, err = CheckIm(checkImRequest); err != nil { | 49 | if checkImResponse, err = CheckIm(checkImRequest); err != nil { |
53 | - return | 50 | + return nil, err |
54 | } | 51 | } |
55 | - if len(imInfo.CsAccountId) == 0 { | ||
56 | - imInfo.CsAccountId = getRandomCustomerAccount(userId) | 52 | + if len(userBase.Im.CsAccountId) == 0 { |
53 | + userBase.Im.CsAccountId = fmt.Sprintf("%v", getRandomCustomerAccount(userId)) | ||
57 | } | 54 | } |
58 | - imInfo.ImToken = checkImResponse.ImToken | ||
59 | - //if _, err = ImInfoRepository.Save(imInfo); err != nil { | ||
60 | - // return | ||
61 | - //} | ||
62 | - return | 55 | + userBase.Im.ImToken = checkImResponse.ImToken |
56 | + if userBase, err = userBaseRepository.Save(userBase); err != nil { | ||
57 | + | ||
58 | + } | ||
59 | + return userBase.Im, nil | ||
63 | } | 60 | } |
64 | 61 | ||
65 | // 检查ImToken | 62 | // 检查ImToken |
@@ -139,21 +136,24 @@ func imRefreshToken(request *im.CheckImRequest, rsp *im.CheckImResponse) (err er | @@ -139,21 +136,24 @@ func imRefreshToken(request *im.CheckImRequest, rsp *im.CheckImResponse) (err er | ||
139 | } | 136 | } |
140 | 137 | ||
141 | // 获取客服id | 138 | // 获取客服id |
142 | -func getRandomCustomerAccount(userId int64) (acid string) { | ||
143 | - //ImCustomerServiceRepository, _ := factory.CreateImCustomerServiceRepository(ctx) | ||
144 | - //total, customers, err := ImCustomerServiceRepository.Find(map[string]interface{}{"sortById": domain.ASC}) | ||
145 | - //if err != nil { | ||
146 | - // log.Error(err) | ||
147 | - // return 0 | ||
148 | - //} | ||
149 | - //if total == 0 { | ||
150 | - // return 0 | ||
151 | - //} | ||
152 | - //index := userId % total | ||
153 | - //if int(index) < len(customers) { | ||
154 | - // acid, _ = strconv.ParseInt(customers[index].ImId, 10, 64) | ||
155 | - // return | ||
156 | - //} | ||
157 | - //acid, _ = strconv.ParseInt(customers[0].ImId, 10, 64) | ||
158 | - return | 139 | +func getRandomCustomerAccount(userId int64) int64 { |
140 | + total, customers := len(constant.CUSTOMER_ACCOUNT), constant.CUSTOMER_ACCOUNT | ||
141 | + if total == 0 { | ||
142 | + return 0 | ||
143 | + } | ||
144 | + index := (int(userId) & 0xFF) % int(total) | ||
145 | + if int(index) < len(customers) { | ||
146 | + return customers[index] | ||
147 | + } | ||
148 | + return customers[0] | ||
149 | +} | ||
150 | + | ||
151 | +func NewPgImService(transactionContext *pgTransaction.TransactionContext) (*PgImService, error) { | ||
152 | + if transactionContext == nil { | ||
153 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
154 | + } else { | ||
155 | + return &PgImService{ | ||
156 | + transactionContext: transactionContext, | ||
157 | + }, nil | ||
158 | + } | ||
159 | } | 159 | } |
@@ -2,11 +2,12 @@ package im | @@ -2,11 +2,12 @@ package im | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "encoding/json" | 4 | "encoding/json" |
5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/constant" | ||
5 | ) | 6 | ) |
6 | 7 | ||
7 | -//func init() { | ||
8 | -// InitImClient(constant.IM_SERVICE_ADDRESS, constant.IM_APP_KEY, constant.IM_APP_SECRET) | ||
9 | -//} | 8 | +func init() { |
9 | + InitImClient(constant.IM_SERVICE_ADDRESS, constant.IM_APP_KEY, constant.IM_APP_SECRET) | ||
10 | +} | ||
10 | 11 | ||
11 | type RequestParam interface { | 12 | type RequestParam interface { |
12 | Format() map[string]string | 13 | Format() map[string]string |
pkg/infrastructure/repository/id_worker.go
0 → 100644
1 | +package repository | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/linmadan/egglib-go/utils/snowflake" | ||
5 | +) | ||
6 | + | ||
7 | +var IdWorker *snowflake.IdWorker | ||
8 | + | ||
9 | +func init() { | ||
10 | + worker, err := snowflake.NewIdWorker(2) | ||
11 | + if err != nil { | ||
12 | + //log.Logger.Panic("idWorker init err" + err.Error()) | ||
13 | + panic(err) | ||
14 | + } | ||
15 | + IdWorker = worker | ||
16 | +} |
@@ -210,7 +210,7 @@ func (repository *UserRepository) Find(queryOptions map[string]interface{}) (int | @@ -210,7 +210,7 @@ func (repository *UserRepository) Find(queryOptions map[string]interface{}) (int | ||
210 | if v, ok := queryOptions["cooperationCompany"]; ok && len(v.(string)) > 0 { | 210 | if v, ok := queryOptions["cooperationCompany"]; ok && len(v.(string)) > 0 { |
211 | query.Where(fmt.Sprintf(`cooperation_info->>'cooperationCompany' like '%%%v%%'`, v)) | 211 | query.Where(fmt.Sprintf(`cooperation_info->>'cooperationCompany' like '%%%v%%'`, v)) |
212 | } | 212 | } |
213 | - query.SetOffsetAndLimit(999) | 213 | + query.SetOffsetAndLimit(20) |
214 | query.SetOrderDirect("user_id", "DESC") | 214 | query.SetOrderDirect("user_id", "DESC") |
215 | if count, err := query.SelectAndCount(); err != nil { | 215 | if count, err := query.SelectAndCount(); err != nil { |
216 | return 0, users, err | 216 | return 0, users, err |
@@ -65,3 +65,11 @@ func (controller *AuthController) UserInfo() { | @@ -65,3 +65,11 @@ func (controller *AuthController) UserInfo() { | ||
65 | data, err := authService.UserInfo(userInfoQuery) | 65 | data, err := authService.UserInfo(userInfoQuery) |
66 | controller.Response(data, err) | 66 | controller.Response(data, err) |
67 | } | 67 | } |
68 | + | ||
69 | +func (controller *AuthController) RefreshIM() { | ||
70 | + authService := service.NewAuthService(nil) | ||
71 | + refreshIMCommand := &command.RefreshIMCommand{} | ||
72 | + controller.Unmarshal(refreshIMCommand) | ||
73 | + data, err := authService.RefreshIM(refreshIMCommand) | ||
74 | + controller.Response(data, err) | ||
75 | +} |
@@ -12,5 +12,5 @@ func init() { | @@ -12,5 +12,5 @@ func init() { | ||
12 | web.Router("/auth/change-password", &controllers.AuthController{}, "Post:PhoneAuthChangePassword") | 12 | web.Router("/auth/change-password", &controllers.AuthController{}, "Post:PhoneAuthChangePassword") |
13 | web.Router("/auth/reset-phone", &controllers.AuthController{}, "Post:PhoneAuthResetPhone") | 13 | web.Router("/auth/reset-phone", &controllers.AuthController{}, "Post:PhoneAuthResetPhone") |
14 | web.Router("/auth/destroy-account", &controllers.AuthController{}, "Post:DestroyAccount") | 14 | web.Router("/auth/destroy-account", &controllers.AuthController{}, "Post:DestroyAccount") |
15 | - web.Router("/auth/userInfo", &controllers.AuthController{}, "Post:UserInfo") | 15 | + web.Router("/auth/refresh-im", &controllers.AuthController{}, "Post:RefreshIM") |
16 | } | 16 | } |
-
请 注册 或 登录 后发表评论