作者 陈志颖

feat:增加修改手机号调用中台

  1 +package subscriber
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/linmadan/egglib-go/core/domain"
  6 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/factory"
  7 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain/event"
  8 +)
  9 +
  10 +type WorthServiceSubscriber struct {
  11 +}
  12 +
  13 +func (subscriber *WorthServiceSubscriber) HandleEvent(domainEvent domain.DomainEvent) error {
  14 + worthServiceGateway, err := factory.CreateWorthServiceGateway(nil)
  15 + if err != nil {
  16 + fmt.Println(err.Error())
  17 + return nil
  18 + }
  19 + switch domainEvent.EventType() {
  20 + case event.USER_CHANGE_PHONE:
  21 + phoneChangedEvent := domainEvent.(*event.PhoneChanged)
  22 + data, err := worthServiceGateway.ChangePhoneCallback(phoneChangedEvent.OldPhone, phoneChangedEvent.NewPhone)
  23 + if err != nil {
  24 + fmt.Println(err.Error())
  25 + return nil
  26 + }
  27 + fmt.Println(data)
  28 + break
  29 + }
  30 + return nil
  31 +}
  32 +
  33 +func (subscriber *WorthServiceSubscriber) SubscribedToEventTypes() []string {
  34 + return []string{
  35 + event.USER_CHANGE_PHONE,
  36 + }
  37 +}
@@ -110,5 +110,10 @@ func CreateExchangeSuMoneyService(options map[string]interface{}) (service.Excha @@ -110,5 +110,10 @@ func CreateExchangeSuMoneyService(options map[string]interface{}) (service.Excha
110 return domainService.NewExchangeSuMoneyService(transactionContext) 110 return domainService.NewExchangeSuMoneyService(transactionContext)
111 } 111 }
112 112
113 -  
114 - 113 +func CreateChangePhoneService(options map[string]interface{}) (service.ChangePhoneService, error) {
  114 + var transactionContext *pgTransaction.TransactionContext
  115 + if value, ok := options["transactionContext"]; ok {
  116 + transactionContext = value.(*pgTransaction.TransactionContext)
  117 + }
  118 + return domainService.NewChangePhoneService(transactionContext)
  119 +}
@@ -9,3 +9,7 @@ func CreateAbilityServiceGateway(options map[string]interface{}) (serviceGateway @@ -9,3 +9,7 @@ func CreateAbilityServiceGateway(options map[string]interface{}) (serviceGateway
9 func CreateMmmOpenApiServiceGateway(options map[string]interface{}) (serviceGateway.MmmOpenApiServiceGateway, error) { 9 func CreateMmmOpenApiServiceGateway(options map[string]interface{}) (serviceGateway.MmmOpenApiServiceGateway, error) {
10 return serviceGateway.NewHttplibMmmOpenApiServiceGateway(), nil 10 return serviceGateway.NewHttplibMmmOpenApiServiceGateway(), nil
11 } 11 }
  12 +
  13 +func CreateWorthServiceGateway(options map[string]interface{}) (serviceGateway.WorthServiceGateway, error) {
  14 + return serviceGateway.NewHttplibWorthServiceGateway(), nil
  15 +}
@@ -3,9 +3,11 @@ package service @@ -3,9 +3,11 @@ package service
3 import ( 3 import (
4 "encoding/json" 4 "encoding/json"
5 "github.com/linmadan/egglib-go/core/application" 5 "github.com/linmadan/egglib-go/core/application"
  6 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/event/subscriber"
6 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/factory" 7 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/factory"
7 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/unifiedUserCenter/command" 8 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/unifiedUserCenter/command"
8 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain" 9 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
  10 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain/service"
9 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/dao" 11 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/dao"
10 "time" 12 "time"
11 ) 13 )
@@ -27,8 +29,9 @@ func (unifiedUserCenterService *UnifiedUserCenterService) SyncEmployeeCallback(s @@ -27,8 +29,9 @@ func (unifiedUserCenterService *UnifiedUserCenterService) SyncEmployeeCallback(s
27 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 29 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
28 } 30 }
29 defer func() { 31 defer func() {
30 - transactionContext.RollbackTransaction() 32 + _ = transactionContext.RollbackTransaction()
31 }() 33 }()
  34 +
32 var employeeRepository domain.EmployeeRepository 35 var employeeRepository domain.EmployeeRepository
33 if value, err := factory.CreateEmployeeRepository(map[string]interface{}{ 36 if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
34 "transactionContext": transactionContext, 37 "transactionContext": transactionContext,
@@ -37,6 +40,7 @@ func (unifiedUserCenterService *UnifiedUserCenterService) SyncEmployeeCallback(s @@ -37,6 +40,7 @@ func (unifiedUserCenterService *UnifiedUserCenterService) SyncEmployeeCallback(s
37 } else { 40 } else {
38 employeeRepository = value 41 employeeRepository = value
39 } 42 }
  43 +
40 var employeeDao *dao.EmployeeDao 44 var employeeDao *dao.EmployeeDao
41 if value, err := factory.CreateEmployeeDao(map[string]interface{}{ 45 if value, err := factory.CreateEmployeeDao(map[string]interface{}{
42 "transactionContext": transactionContext, 46 "transactionContext": transactionContext,
@@ -45,6 +49,7 @@ func (unifiedUserCenterService *UnifiedUserCenterService) SyncEmployeeCallback(s @@ -45,6 +49,7 @@ func (unifiedUserCenterService *UnifiedUserCenterService) SyncEmployeeCallback(s
45 } else { 49 } else {
46 employeeDao = value 50 employeeDao = value
47 } 51 }
  52 +
48 var cashPoolDao *dao.CashPoolDao 53 var cashPoolDao *dao.CashPoolDao
49 if value, err := factory.CreateCashPoolDao(map[string]interface{}{ 54 if value, err := factory.CreateCashPoolDao(map[string]interface{}{
50 "transactionContext": transactionContext, 55 "transactionContext": transactionContext,
@@ -53,6 +58,21 @@ func (unifiedUserCenterService *UnifiedUserCenterService) SyncEmployeeCallback(s @@ -53,6 +58,21 @@ func (unifiedUserCenterService *UnifiedUserCenterService) SyncEmployeeCallback(s
53 } else { 58 } else {
54 cashPoolDao = value 59 cashPoolDao = value
55 } 60 }
  61 +
  62 + // 修改手机号事件订阅初始化
  63 + var changePhoneService service.ChangePhoneService
  64 + if value, err := factory.CreateChangePhoneService(map[string]interface{}{
  65 + "transactionContext": transactionContext,
  66 + }); err != nil {
  67 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  68 + } else {
  69 + changePhoneService = value
  70 + err := changePhoneService.Subscribe(&subscriber.WorthServiceSubscriber{})
  71 + if err != nil {
  72 + return nil, err
  73 + }
  74 + }
  75 +
56 var companyId int64 76 var companyId int64
57 var uid int64 77 var uid int64
58 var employeeName string 78 var employeeName string
@@ -84,10 +104,10 @@ func (unifiedUserCenterService *UnifiedUserCenterService) SyncEmployeeCallback(s @@ -84,10 +104,10 @@ func (unifiedUserCenterService *UnifiedUserCenterService) SyncEmployeeCallback(s
84 if value, ok := data["avatar"]; ok { 104 if value, ok := data["avatar"]; ok {
85 employeeAvatarUrl = value.(string) 105 employeeAvatarUrl = value.(string)
86 } 106 }
87 - if value, ok := data["oldPhone"]; ok { 107 + if value, ok := data["old_phone"]; ok {
88 oldPhone = value.(string) 108 oldPhone = value.(string)
89 } 109 }
90 - if value, ok := data["newPhone"]; ok { 110 + if value, ok := data["new_phone"]; ok {
91 newPhone = value.(string) 111 newPhone = value.(string)
92 } 112 }
93 if value, ok := data["admin_type"]; ok { 113 if value, ok := data["admin_type"]; ok {
@@ -115,6 +135,7 @@ func (unifiedUserCenterService *UnifiedUserCenterService) SyncEmployeeCallback(s @@ -115,6 +135,7 @@ func (unifiedUserCenterService *UnifiedUserCenterService) SyncEmployeeCallback(s
115 editEmployees = append(editEmployees, editEmployee.(map[string]interface{})) 135 editEmployees = append(editEmployees, editEmployee.(map[string]interface{}))
116 } 136 }
117 } 137 }
  138 +
118 if syncEmployeeCallbackCommand.Module == "employee" { 139 if syncEmployeeCallbackCommand.Module == "employee" {
119 switch syncEmployeeCallbackCommand.Action { 140 switch syncEmployeeCallbackCommand.Action {
120 case "import": 141 case "import":
@@ -263,7 +284,7 @@ func (unifiedUserCenterService *UnifiedUserCenterService) SyncEmployeeCallback(s @@ -263,7 +284,7 @@ func (unifiedUserCenterService *UnifiedUserCenterService) SyncEmployeeCallback(s
263 return false, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 284 return false, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
264 } 285 }
265 break 286 break
266 - case "changePhone": // TODO 修改手机号 287 + case "changePhoneAllCompany": // 修改手机号
267 // 修改用户数据 288 // 修改用户数据
268 err := employeeDao.ChangePhone(oldPhone, newPhone) 289 err := employeeDao.ChangePhone(oldPhone, newPhone)
269 if err != nil { 290 if err != nil {
@@ -274,6 +295,10 @@ func (unifiedUserCenterService *UnifiedUserCenterService) SyncEmployeeCallback(s @@ -274,6 +295,10 @@ func (unifiedUserCenterService *UnifiedUserCenterService) SyncEmployeeCallback(s
274 if errUpdateExchangeCashPersonList != nil { 295 if errUpdateExchangeCashPersonList != nil {
275 return false, application.ThrowError(application.TRANSACTION_ERROR, errUpdateExchangeCashPersonList.Error()) 296 return false, application.ThrowError(application.TRANSACTION_ERROR, errUpdateExchangeCashPersonList.Error())
276 } 297 }
  298 + // 发布修改手机号事件
  299 + if err := changePhoneService.ChangePhone(oldPhone, newPhone); err != nil {
  300 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  301 + }
277 break 302 break
278 default: 303 default:
279 return false, nil 304 return false, nil
@@ -6,6 +6,7 @@ const SERVICE_NAME = "mmm-worth" @@ -6,6 +6,7 @@ const SERVICE_NAME = "mmm-worth"
6 6
7 var ABILITY_SERVICE_HOST = "https://suplus-worth-app-gateway-dev.fjmaimaimai.com" 7 var ABILITY_SERVICE_HOST = "https://suplus-worth-app-gateway-dev.fjmaimaimai.com"
8 var MMM_OPEN_API_SERVICE_HOST = "https://mmm-open-api-dev.fjmaimaimai.com" 8 var MMM_OPEN_API_SERVICE_HOST = "https://mmm-open-api-dev.fjmaimaimai.com"
  9 +var WORTH_SERVICE_GATEWAY_HOST = "https://suplus-worth-app-gateway-dev.fjmaimaimai.com"
9 10
10 var LOG_LEVEL = "debug" 11 var LOG_LEVEL = "debug"
11 var LOG_File = "logs/app.log" 12 var LOG_File = "logs/app.log"
  1 +package event
  2 +
  3 +import coreDomain "github.com/linmadan/egglib-go/core/domain"
  4 +
  5 +const USER_CHANGE_PHONE = "user-change-phone"
  6 +
  7 +type PhoneChanged struct {
  8 + coreDomain.BaseEvent
  9 + OldPhone string `json:"oldPhone"` // 旧手机号
  10 + NewPhone string `json:"newPhone"` // 新手机号
  11 +}
  12 +
  13 +func (event *PhoneChanged) EventType() string {
  14 + return USER_CHANGE_PHONE
  15 +}
  1 +package service
  2 +
  3 +import coreDomain "github.com/linmadan/egglib-go/core/domain"
  4 +
  5 +type ChangePhoneService interface {
  6 + coreDomain.DomainEventPublisher
  7 + ChangePhone(oldPhone string, newPhone string) error
  8 +}
@@ -35,7 +35,7 @@ func (dao *CashPoolDao) CalculateActivityExchangedSuMoney(activityId int64) (map @@ -35,7 +35,7 @@ func (dao *CashPoolDao) CalculateActivityExchangedSuMoney(activityId int64) (map
35 }, nil 35 }, nil
36 } 36 }
37 37
38 -// UpdateExchangeCashPersonListUserInfo TODO 更新素币兑换清单用户信息 38 +// UpdateExchangeCashPersonListUserInfo 更新素币兑换清单用户信息
39 func (dao *CashPoolDao) UpdateExchangeCashPersonListUserInfo(oldPhone string, newPhone string) error { 39 func (dao *CashPoolDao) UpdateExchangeCashPersonListUserInfo(oldPhone string, newPhone string) error {
40 tx := dao.transactionContext.PgTx 40 tx := dao.transactionContext.PgTx
41 if _, err := tx.QueryOne( 41 if _, err := tx.QueryOne(
@@ -57,7 +57,7 @@ func (dao *EmployeeDao) ChangePrincipal(companyId int64, employeeAccount string) @@ -57,7 +57,7 @@ func (dao *EmployeeDao) ChangePrincipal(companyId int64, employeeAccount string)
57 return nil 57 return nil
58 } 58 }
59 59
60 -// ChangePhone TODO 修改用户手机号 60 +// ChangePhone 修改用户手机号
61 func (dao *EmployeeDao) ChangePhone(oldPhone string, newPhone string) error { 61 func (dao *EmployeeDao) ChangePhone(oldPhone string, newPhone string) error {
62 tx := dao.transactionContext.PgTx 62 tx := dao.transactionContext.PgTx
63 if _, err := tx.QueryOne( 63 if _, err := tx.QueryOne(
@@ -9,7 +9,7 @@ type SentNotificationDao struct { @@ -9,7 +9,7 @@ type SentNotificationDao struct {
9 transactionContext *pgTransaction.TransactionContext 9 transactionContext *pgTransaction.TransactionContext
10 } 10 }
11 11
12 -// ChangeSentNotificationReceiverAccount TODO 12 +// ChangeSentNotificationReceiverAccount TODO 修改已发送通知用户信息
13 func (dao *SentNotificationDao) ChangeSentNotificationReceiverAccount() { 13 func (dao *SentNotificationDao) ChangeSentNotificationReceiverAccount() {
14 14
15 } 15 }
@@ -9,12 +9,12 @@ type SuMoneyTransactionRecordsDao struct { @@ -9,12 +9,12 @@ type SuMoneyTransactionRecordsDao struct {
9 transactionContext *pgTransaction.TransactionContext 9 transactionContext *pgTransaction.TransactionContext
10 } 10 }
11 11
12 -//TODO ChangeSuMoneyTransactionRecordsEmployeeAccount 12 +// ChangeSuMoneyTransactionRecordsEmployeeAccount TODO 修改素币流水记录用户信息
13 func (dao *SuMoneyTransactionRecordsDao) ChangeSuMoneyTransactionRecordsEmployeeAccount() { 13 func (dao *SuMoneyTransactionRecordsDao) ChangeSuMoneyTransactionRecordsEmployeeAccount() {
14 14
15 } 15 }
16 16
17 -//TODO ChangeSuMoneyTransactionRecordsOperatorAccount 17 +// ChangeSuMoneyTransactionRecordsOperatorAccount TODO 素币流水记操作人信息
18 func (dao *SuMoneyTransactionRecordsDao) ChangeSuMoneyTransactionRecordsOperatorAccount() { 18 func (dao *SuMoneyTransactionRecordsDao) ChangeSuMoneyTransactionRecordsOperatorAccount() {
19 19
20 } 20 }
  1 +package domain_service
  2 +
  3 +import (
  4 + "fmt"
  5 + coreDomain "github.com/linmadan/egglib-go/core/domain"
  6 + pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
  7 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain/event"
  8 +)
  9 +
  10 +type ChangePhoneService struct {
  11 + coreDomain.BaseEventPublisher
  12 + transactionContext *pgTransaction.TransactionContext
  13 +}
  14 +
  15 +func (service *ChangePhoneService) ChangePhone(oldPhone string, newPhone string) error {
  16 + changePhoneEvent := new(event.PhoneChanged)
  17 + changePhoneEvent.OldPhone = oldPhone
  18 + changePhoneEvent.NewPhone = newPhone
  19 + if err := service.Publish(changePhoneEvent); err != nil {
  20 + return err
  21 + }
  22 + return nil
  23 +}
  24 +
  25 +func NewChangePhoneService(transactionContext *pgTransaction.TransactionContext) (*ChangePhoneService, error) {
  26 + if transactionContext == nil {
  27 + return nil, fmt.Errorf("transactionContext参数不能为nil")
  28 + } else {
  29 + return &ChangePhoneService{
  30 + transactionContext: transactionContext,
  31 + }, nil
  32 + }
  33 +}
  1 +package service_gateway
  2 +
  3 +import (
  4 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/constant"
  5 + "strings"
  6 + "time"
  7 +)
  8 +
  9 +type HttplibWorthServiceGateway struct {
  10 + httplibBaseServiceGateway
  11 +}
  12 +
  13 +// ChangePhoneCallback 修改手机号码回调,通知价值APP端中台
  14 +func (serviceGateway *HttplibWorthServiceGateway) ChangePhoneCallback(oldPhone string, newPhone string) (map[string]interface{}, error) {
  15 + url := strings.Join([]string{serviceGateway.baseURL, "/v1/auth/forceRevoke"}, "/")
  16 + request := serviceGateway.createRequest(url, "post")
  17 + options := make(map[string]interface{})
  18 + options["phone"] = oldPhone
  19 + options["newPhone"] = newPhone
  20 + request.JSONBody(options)
  21 + response := make(map[string]interface{})
  22 + request.ToJSON(&response)
  23 + data, err := serviceGateway.responseHandle(response)
  24 + return data, err
  25 +}
  26 +
  27 +func NewHttplibWorthServiceGateway() *HttplibWorthServiceGateway {
  28 + return &HttplibWorthServiceGateway{
  29 + httplibBaseServiceGateway: httplibBaseServiceGateway{
  30 + baseURL: constant.ABILITY_SERVICE_HOST,
  31 + connectTimeout: 100 * time.Second,
  32 + readWriteTimeout: 30 * time.Second,
  33 + },
  34 + }
  35 +}
@@ -14,3 +14,7 @@ type AbilityServiceGateway interface { @@ -14,3 +14,7 @@ type AbilityServiceGateway interface {
14 type MmmOpenApiServiceGateway interface { 14 type MmmOpenApiServiceGateway interface {
15 PushInfo(msgType int, uids []int64, title string, content string, ext map[string]interface{}) (map[string]interface{}, error) 15 PushInfo(msgType int, uids []int64, title string, content string, ext map[string]interface{}) (map[string]interface{}, error)
16 } 16 }
  17 +
  18 +type WorthServiceGateway interface {
  19 + ChangePhoneCallback(oldPhone string, newPhone string) (map[string]interface{}, error)
  20 +}