作者 陈志颖

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

package subscriber
import (
"fmt"
"github.com/linmadan/egglib-go/core/domain"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/factory"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain/event"
)
type WorthServiceSubscriber struct {
}
func (subscriber *WorthServiceSubscriber) HandleEvent(domainEvent domain.DomainEvent) error {
worthServiceGateway, err := factory.CreateWorthServiceGateway(nil)
if err != nil {
fmt.Println(err.Error())
return nil
}
switch domainEvent.EventType() {
case event.USER_CHANGE_PHONE:
phoneChangedEvent := domainEvent.(*event.PhoneChanged)
data, err := worthServiceGateway.ChangePhoneCallback(phoneChangedEvent.OldPhone, phoneChangedEvent.NewPhone)
if err != nil {
fmt.Println(err.Error())
return nil
}
fmt.Println(data)
break
}
return nil
}
func (subscriber *WorthServiceSubscriber) SubscribedToEventTypes() []string {
return []string{
event.USER_CHANGE_PHONE,
}
}
... ...
... ... @@ -110,5 +110,10 @@ func CreateExchangeSuMoneyService(options map[string]interface{}) (service.Excha
return domainService.NewExchangeSuMoneyService(transactionContext)
}
func CreateChangePhoneService(options map[string]interface{}) (service.ChangePhoneService, error) {
var transactionContext *pgTransaction.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pgTransaction.TransactionContext)
}
return domainService.NewChangePhoneService(transactionContext)
}
... ...
... ... @@ -9,3 +9,7 @@ func CreateAbilityServiceGateway(options map[string]interface{}) (serviceGateway
func CreateMmmOpenApiServiceGateway(options map[string]interface{}) (serviceGateway.MmmOpenApiServiceGateway, error) {
return serviceGateway.NewHttplibMmmOpenApiServiceGateway(), nil
}
func CreateWorthServiceGateway(options map[string]interface{}) (serviceGateway.WorthServiceGateway, error) {
return serviceGateway.NewHttplibWorthServiceGateway(), nil
}
... ...
... ... @@ -3,9 +3,11 @@ package service
import (
"encoding/json"
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/event/subscriber"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/factory"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/unifiedUserCenter/command"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain/service"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/dao"
"time"
)
... ... @@ -27,8 +29,9 @@ func (unifiedUserCenterService *UnifiedUserCenterService) SyncEmployeeCallback(s
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
_ = transactionContext.RollbackTransaction()
}()
var employeeRepository domain.EmployeeRepository
if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -37,6 +40,7 @@ func (unifiedUserCenterService *UnifiedUserCenterService) SyncEmployeeCallback(s
} else {
employeeRepository = value
}
var employeeDao *dao.EmployeeDao
if value, err := factory.CreateEmployeeDao(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -45,6 +49,7 @@ func (unifiedUserCenterService *UnifiedUserCenterService) SyncEmployeeCallback(s
} else {
employeeDao = value
}
var cashPoolDao *dao.CashPoolDao
if value, err := factory.CreateCashPoolDao(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -53,6 +58,21 @@ func (unifiedUserCenterService *UnifiedUserCenterService) SyncEmployeeCallback(s
} else {
cashPoolDao = value
}
// 修改手机号事件订阅初始化
var changePhoneService service.ChangePhoneService
if value, err := factory.CreateChangePhoneService(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
changePhoneService = value
err := changePhoneService.Subscribe(&subscriber.WorthServiceSubscriber{})
if err != nil {
return nil, err
}
}
var companyId int64
var uid int64
var employeeName string
... ... @@ -84,10 +104,10 @@ func (unifiedUserCenterService *UnifiedUserCenterService) SyncEmployeeCallback(s
if value, ok := data["avatar"]; ok {
employeeAvatarUrl = value.(string)
}
if value, ok := data["oldPhone"]; ok {
if value, ok := data["old_phone"]; ok {
oldPhone = value.(string)
}
if value, ok := data["newPhone"]; ok {
if value, ok := data["new_phone"]; ok {
newPhone = value.(string)
}
if value, ok := data["admin_type"]; ok {
... ... @@ -115,6 +135,7 @@ func (unifiedUserCenterService *UnifiedUserCenterService) SyncEmployeeCallback(s
editEmployees = append(editEmployees, editEmployee.(map[string]interface{}))
}
}
if syncEmployeeCallbackCommand.Module == "employee" {
switch syncEmployeeCallbackCommand.Action {
case "import":
... ... @@ -263,7 +284,7 @@ func (unifiedUserCenterService *UnifiedUserCenterService) SyncEmployeeCallback(s
return false, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
break
case "changePhone": // TODO 修改手机号
case "changePhoneAllCompany": // 修改手机号
// 修改用户数据
err := employeeDao.ChangePhone(oldPhone, newPhone)
if err != nil {
... ... @@ -274,6 +295,10 @@ func (unifiedUserCenterService *UnifiedUserCenterService) SyncEmployeeCallback(s
if errUpdateExchangeCashPersonList != nil {
return false, application.ThrowError(application.TRANSACTION_ERROR, errUpdateExchangeCashPersonList.Error())
}
// 发布修改手机号事件
if err := changePhoneService.ChangePhone(oldPhone, newPhone); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
break
default:
return false, nil
... ...
... ... @@ -6,6 +6,7 @@ const SERVICE_NAME = "mmm-worth"
var ABILITY_SERVICE_HOST = "https://suplus-worth-app-gateway-dev.fjmaimaimai.com"
var MMM_OPEN_API_SERVICE_HOST = "https://mmm-open-api-dev.fjmaimaimai.com"
var WORTH_SERVICE_GATEWAY_HOST = "https://suplus-worth-app-gateway-dev.fjmaimaimai.com"
var LOG_LEVEL = "debug"
var LOG_File = "logs/app.log"
... ...
package event
import coreDomain "github.com/linmadan/egglib-go/core/domain"
const USER_CHANGE_PHONE = "user-change-phone"
type PhoneChanged struct {
coreDomain.BaseEvent
OldPhone string `json:"oldPhone"` // 旧手机号
NewPhone string `json:"newPhone"` // 新手机号
}
func (event *PhoneChanged) EventType() string {
return USER_CHANGE_PHONE
}
... ...
package service
import coreDomain "github.com/linmadan/egglib-go/core/domain"
type ChangePhoneService interface {
coreDomain.DomainEventPublisher
ChangePhone(oldPhone string, newPhone string) error
}
... ...
... ... @@ -35,7 +35,7 @@ func (dao *CashPoolDao) CalculateActivityExchangedSuMoney(activityId int64) (map
}, nil
}
// UpdateExchangeCashPersonListUserInfo TODO 更新素币兑换清单用户信息
// UpdateExchangeCashPersonListUserInfo 更新素币兑换清单用户信息
func (dao *CashPoolDao) UpdateExchangeCashPersonListUserInfo(oldPhone string, newPhone string) error {
tx := dao.transactionContext.PgTx
if _, err := tx.QueryOne(
... ...
... ... @@ -57,7 +57,7 @@ func (dao *EmployeeDao) ChangePrincipal(companyId int64, employeeAccount string)
return nil
}
// ChangePhone TODO 修改用户手机号
// ChangePhone 修改用户手机号
func (dao *EmployeeDao) ChangePhone(oldPhone string, newPhone string) error {
tx := dao.transactionContext.PgTx
if _, err := tx.QueryOne(
... ...
... ... @@ -9,7 +9,7 @@ type SentNotificationDao struct {
transactionContext *pgTransaction.TransactionContext
}
// ChangeSentNotificationReceiverAccount TODO
// ChangeSentNotificationReceiverAccount TODO 修改已发送通知用户信息
func (dao *SentNotificationDao) ChangeSentNotificationReceiverAccount() {
}
... ...
... ... @@ -9,12 +9,12 @@ type SuMoneyTransactionRecordsDao struct {
transactionContext *pgTransaction.TransactionContext
}
//TODO ChangeSuMoneyTransactionRecordsEmployeeAccount
// ChangeSuMoneyTransactionRecordsEmployeeAccount TODO 修改素币流水记录用户信息
func (dao *SuMoneyTransactionRecordsDao) ChangeSuMoneyTransactionRecordsEmployeeAccount() {
}
//TODO ChangeSuMoneyTransactionRecordsOperatorAccount
// ChangeSuMoneyTransactionRecordsOperatorAccount TODO 素币流水记操作人信息
func (dao *SuMoneyTransactionRecordsDao) ChangeSuMoneyTransactionRecordsOperatorAccount() {
}
... ...
package domain_service
import (
"fmt"
coreDomain "github.com/linmadan/egglib-go/core/domain"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain/event"
)
type ChangePhoneService struct {
coreDomain.BaseEventPublisher
transactionContext *pgTransaction.TransactionContext
}
func (service *ChangePhoneService) ChangePhone(oldPhone string, newPhone string) error {
changePhoneEvent := new(event.PhoneChanged)
changePhoneEvent.OldPhone = oldPhone
changePhoneEvent.NewPhone = newPhone
if err := service.Publish(changePhoneEvent); err != nil {
return err
}
return nil
}
func NewChangePhoneService(transactionContext *pgTransaction.TransactionContext) (*ChangePhoneService, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &ChangePhoneService{
transactionContext: transactionContext,
}, nil
}
}
... ...
package service_gateway
import (
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/constant"
"strings"
"time"
)
type HttplibWorthServiceGateway struct {
httplibBaseServiceGateway
}
// ChangePhoneCallback 修改手机号码回调,通知价值APP端中台
func (serviceGateway *HttplibWorthServiceGateway) ChangePhoneCallback(oldPhone string, newPhone string) (map[string]interface{}, error) {
url := strings.Join([]string{serviceGateway.baseURL, "/v1/auth/forceRevoke"}, "/")
request := serviceGateway.createRequest(url, "post")
options := make(map[string]interface{})
options["phone"] = oldPhone
options["newPhone"] = newPhone
request.JSONBody(options)
response := make(map[string]interface{})
request.ToJSON(&response)
data, err := serviceGateway.responseHandle(response)
return data, err
}
func NewHttplibWorthServiceGateway() *HttplibWorthServiceGateway {
return &HttplibWorthServiceGateway{
httplibBaseServiceGateway: httplibBaseServiceGateway{
baseURL: constant.ABILITY_SERVICE_HOST,
connectTimeout: 100 * time.Second,
readWriteTimeout: 30 * time.Second,
},
}
}
... ...
... ... @@ -14,3 +14,7 @@ type AbilityServiceGateway interface {
type MmmOpenApiServiceGateway interface {
PushInfo(msgType int, uids []int64, title string, content string, ext map[string]interface{}) (map[string]interface{}, error)
}
type WorthServiceGateway interface {
ChangePhoneCallback(oldPhone string, newPhone string) (map[string]interface{}, error)
}
... ...