作者 tangxvhui

添加短信通知

... ... @@ -140,7 +140,6 @@ func (notices *notifySms) sendSms(param *domain.LogSms) error {
ok, err := sendOrNot.ifSend(param.Index)
if err != nil {
param.Result = err.Error()
}
sendOk = ok
} else {
... ...
... ... @@ -9,6 +9,7 @@ import (
"github.com/linmadan/egglib-go/core/application"
"github.com/linmadan/egglib-go/utils/tool_funs"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/notify"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/adapter"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/command"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/query"
... ... @@ -260,8 +261,11 @@ func (srv StaffAssessServeice) CreateStaffAssessTask(transactionContext applicat
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存个人评估项"+err.Error())
}
if assessList[i].Types == domain.AssessSelf {
//添加待发送的短信通知
notify.AddNotifyStaffAssess(&assessList[i])
}
}
return map[string]interface{}{
"assessTaskId": assessTaskData.Id,
}, nil
... ...
... ... @@ -5,12 +5,11 @@ import (
"strconv"
"time"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/constant"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/serviceGateway"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/notify"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/constant"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log"
)
// sendSummaryEvaluafionTask 根据评估项目设置,确认是否下发评估任务
... ... @@ -272,8 +271,8 @@ func TaskSendSummaryEvaluation() error {
if err := transactionContext.CommitTransaction(); err != nil {
return err
}
//发送短信通知
//err = sendSmsEvalation(createdEvalationList)
//添加待发送的短信通知
err = sendSmsEvalation(createdEvalationList)
return err
}
... ... @@ -282,49 +281,53 @@ func sendSmsEvalation(param []domain.SummaryEvaluation) error {
if constant.Env != "prd" {
return nil
}
for i := range param {
notify.AddNotifySummaryEvaluation(&param[i])
}
//处理短信发送
//过滤去重 处理需要发送改执行人的消息 执行人id=>domain.LogSms
noticeMap := map[string]*domain.LogSms{}
for _, v := range param {
phone := v.Executor.Account
name := v.Executor.UserName
if _, ok := noticeMap[phone]; ok {
continue
}
if phone == "" {
continue
}
smsMessage := domain.LogSms{}
smsMessage.SummaryEvaluationMessage(phone, name)
noticeMap[phone] = &smsMessage
}
// noticeMap := map[string]*domain.LogSms{}
// for _, v := range param {
// phone := v.Executor.Account
// name := v.Executor.UserName
// if _, ok := noticeMap[phone]; ok {
// continue
// }
// if phone == "" {
// continue
// }
// smsMessage := domain.LogSms{}
// smsMessage.SummaryEvaluationMessage(phone, name)
// noticeMap[phone] = &smsMessage
// }
sms := serviceGateway.SmsService{}
for _, v := range noticeMap {
err := sms.SendNoticeSms(v.Phone, v.TemplateId, v.Value)
if err != nil {
v.Result = err.Error()
}
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return err
}
if err := transactionContext.StartTransaction(); err != nil {
return err
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
logSmsRepo := factory.CreateLogSmsRepository(map[string]interface{}{"transactionContext": transactionContext})
for _, v := range noticeMap {
err = logSmsRepo.Insert(v)
if err != nil {
log.Logger.Error("TaskSendSummaryEvaluation 发送短信通知:" + err.Error())
}
}
if err := transactionContext.CommitTransaction(); err != nil {
return err
}
// sms := serviceGateway.SmsService{}
// for _, v := range noticeMap {
// err := sms.SendNoticeSms(v.Phone, v.TemplateId, v.Value)
// if err != nil {
// v.Result = err.Error()
// }
// }
// transactionContext, err := factory.CreateTransactionContext(nil)
// if err != nil {
// return err
// }
// if err := transactionContext.StartTransaction(); err != nil {
// return err
// }
// defer func() {
// _ = transactionContext.RollbackTransaction()
// }()
// logSmsRepo := factory.CreateLogSmsRepository(map[string]interface{}{"transactionContext": transactionContext})
// for _, v := range noticeMap {
// err = logSmsRepo.Insert(v)
// if err != nil {
// log.Logger.Error("TaskSendSummaryEvaluation 发送短信通知:" + err.Error())
// }
// }
// if err := transactionContext.CommitTransaction(); err != nil {
// return err
// }
return nil
}
... ...