作者 linmadan

接入推送功能

... ... @@ -69,7 +69,9 @@ spec:
- name: ERROR_BASE_CODE_MULTIPLE
value: "1000"
- name: ABILITY_SERVICE_HOST
value: "https://ability-dev.fjmaimaimai.com"
value: "https://suplus-worth-app-gateway-dev.fjmaimaimai.com"
- name: MMM_OPEN_API_SERVICE_HOST
value: "http://mmm-open-api-dev.fjmaimaimai.com"
volumes:
- name: accesslogs
emptyDir: {}
\ No newline at end of file
... ...
... ... @@ -70,6 +70,8 @@ spec:
value: "1000"
- name: ABILITY_SERVICE_HOST
value: "https://ability.fjmaimaimai.com"
- name: MMM_OPEN_API_SERVICE_HOST
value: "https://public-interface.fjmaimaimai.com/openapi"
volumes:
- name: accesslogs
emptyDir: {}
\ No newline at end of file
... ...
... ... @@ -69,7 +69,9 @@ spec:
- name: ERROR_BASE_CODE_MULTIPLE
value: "1000"
- name: ABILITY_SERVICE_HOST
value: "https://ability-test.fjmaimaimai.com"
value: "https://suplus-worth-app-gateway-test.fjmaimaimai.com"
- name: MMM_OPEN_API_SERVICE_HOST
value: "http://mmm-open-api-test.fjmaimaimai.com"
volumes:
- name: accesslogs
emptyDir: {}
\ No newline at end of file
... ...
package subscriber
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/application/factory"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain/event"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/repository"
)
type MmmOpenApiServiceServiceSubscriber struct {
TransactionContext *pgTransaction.TransactionContext
}
func (subscriber *MmmOpenApiServiceServiceSubscriber) HandleEvent(domainEvent coreDomain.DomainEvent) error {
mmmOpenApiServiceGateway, err := factory.CreateMmmOpenApiServiceGateway(nil)
if err != nil {
fmt.Println(err.Error())
return nil
}
switch domainEvent.EventType() {
case event.TASK_RELEASED_EVENT:
taskReleasedEvent := domainEvent.(*event.TaskReleased)
var employeeRepository domain.EmployeeRepository
if repository, err := repository.NewEmployeeRepository(subscriber.TransactionContext); err != nil {
fmt.Println(err.Error())
return nil
} else {
employeeRepository = repository
}
uids := make([]int64, 0)
if _, employees, err := employeeRepository.Find(map[string]interface{}{"companyId": taskReleasedEvent.CompanyId}); err != nil {
fmt.Println(err.Error())
return nil
} else {
for _, employee := range employees {
uids = append(uids, employee.EmployeeInfo.Uid)
}
}
title := fmt.Sprintf("%s发布了一个任务", taskReleasedEvent.Sponsor.EmployeeName)
content := fmt.Sprintf("%s发布了一个任务", taskReleasedEvent.Sponsor.EmployeeName)
transData := make(map[string]interface{})
transData["mmmType"] = "101"
transData["mmmTitle"] = title
transData["mmmContent"] = content
transData["resourceId"] = taskReleasedEvent.TaskId
ext := make(map[string]interface{})
ext["transData"] = transData
data, err := mmmOpenApiServiceGateway.PushInfo(0, uids, title, content, ext)
if err != nil {
fmt.Println(err.Error())
return nil
}
fmt.Println(data)
break
}
return nil
}
func (subscriber *MmmOpenApiServiceServiceSubscriber) SubscribedToEventTypes() []string {
return [] string{
event.TASK_RELEASED_EVENT,
}
}
... ...
... ... @@ -5,3 +5,7 @@ import serviceGateway "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastruct
func CreateAbilityServiceGateway(options map[string]interface{}) (serviceGateway.AbilityServiceGateway, error) {
return serviceGateway.NewHttplibAbilityServiceGateway(), nil
}
func CreateMmmOpenApiServiceGateway(options map[string]interface{}) (serviceGateway.MmmOpenApiServiceGateway, error) {
return serviceGateway.NewHttplibMmmOpenApiServiceGateway(), nil
}
... ...
... ... @@ -252,6 +252,9 @@ func (taskService *TaskService) ReleaseTask(releaseTaskCommand *command.ReleaseT
} else {
releaseTaskService = value
releaseTaskService.Subscribe(&subscriber.AbilityServiceSubscriber{})
releaseTaskService.Subscribe(&subscriber.MmmOpenApiServiceServiceSubscriber{
TransactionContext: transactionContext.(*pgTransaction.TransactionContext),
})
}
if task, err := releaseTaskService.Release(releaseTaskCommand.TaskId, releaseTaskCommand.Operator); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ...
package constant
import "os"
var GETUI_APP_ID = "WgrbaaStTk7JElrXOCgUg6"
var GETUI_APP_KEY = "FG5lbqVrHa5rS9NVfxNP7"
var GETUI_APP_SECRET = "FW3jMNLJrRARYKv2iqA5H5"
func init() {
if os.Getenv("GETUI_APP_KEY") != "" {
GETUI_APP_KEY = os.Getenv("GETUI_APP_KEY")
}
if os.Getenv("GETUI_APP_ID") != "" {
GETUI_APP_ID = os.Getenv("GETUI_APP_ID")
}
if os.Getenv("GETUI_APP_SECRET") != "" {
GETUI_APP_SECRET = os.Getenv("GETUI_APP_SECRET")
}
}
... ... @@ -10,15 +10,13 @@ type HttplibMmmOpenApiServiceGateway struct {
httplibBaseServiceGateway
}
func (serviceGateway *HttplibMmmOpenApiServiceGateway) PushInfo(msgType int, clientIds []string, title string, content string, ext map[string]interface{}) (map[string]interface{}, error) {
url := strings.Join([]string{serviceGateway.baseURL, "push", "pushInfo"}, "/")
func (serviceGateway *HttplibMmmOpenApiServiceGateway) PushInfo(msgType int, uids []int64, title string, content string, ext map[string]interface{}) (map[string]interface{}, error) {
url := strings.Join([]string{serviceGateway.baseURL, "v1", "push", "pushInfo"}, "/")
request := serviceGateway.createRequest(url, "post")
options := make(map[string]interface{})
options["mmmType"] = 1
options["clientId"] = clientIds
options["appKey"] = constant.GETUI_APP_KEY
options["secret"] = constant.GETUI_APP_SECRET
options["appId"] = constant.GETUI_APP_ID
options["mmmType"] = msgType
options["project"] = "worth"
options["receivers"] = uids
options["title"] = title
options["content"] = content
options["ext"] = ext
... ... @@ -29,7 +27,7 @@ func (serviceGateway *HttplibMmmOpenApiServiceGateway) PushInfo(msgType int, cli
return data, err
}
func NewHttplibPushServiceGateway() *HttplibMmmOpenApiServiceGateway {
func NewHttplibMmmOpenApiServiceGateway() *HttplibMmmOpenApiServiceGateway {
return &HttplibMmmOpenApiServiceGateway{
httplibBaseServiceGateway: httplibBaseServiceGateway{
baseURL: constant.MMM_OPEN_API_SERVICE_HOST,
... ...
... ... @@ -10,3 +10,7 @@ type AbilityServiceGateway interface {
SaveTaskCallback(uid int64, taskId int64, serials []int64) (map[string]interface{}, error)
DeleteTaskCallback(uid int64, taskId int64, serials []int64) (map[string]interface{}, error)
}
type MmmOpenApiServiceGateway interface {
PushInfo(msgType int, uids []int64, title string, content string, ext map[string]interface{}) (map[string]interface{}, error)
}
... ...