作者 tangxvhui

添加短信通知

@@ -140,7 +140,6 @@ func (notices *notifySms) sendSms(param *domain.LogSms) error { @@ -140,7 +140,6 @@ func (notices *notifySms) sendSms(param *domain.LogSms) error {
140 ok, err := sendOrNot.ifSend(param.Index) 140 ok, err := sendOrNot.ifSend(param.Index)
141 if err != nil { 141 if err != nil {
142 param.Result = err.Error() 142 param.Result = err.Error()
143 -  
144 } 143 }
145 sendOk = ok 144 sendOk = ok
146 } else { 145 } else {
@@ -9,6 +9,7 @@ import ( @@ -9,6 +9,7 @@ import (
9 "github.com/linmadan/egglib-go/core/application" 9 "github.com/linmadan/egglib-go/core/application"
10 "github.com/linmadan/egglib-go/utils/tool_funs" 10 "github.com/linmadan/egglib-go/utils/tool_funs"
11 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory" 11 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
  12 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/notify"
12 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/adapter" 13 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/adapter"
13 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/command" 14 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/command"
14 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/query" 15 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/query"
@@ -260,8 +261,11 @@ func (srv StaffAssessServeice) CreateStaffAssessTask(transactionContext applicat @@ -260,8 +261,11 @@ func (srv StaffAssessServeice) CreateStaffAssessTask(transactionContext applicat
260 if err != nil { 261 if err != nil {
261 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存个人评估项"+err.Error()) 262 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存个人评估项"+err.Error())
262 } 263 }
  264 + if assessList[i].Types == domain.AssessSelf {
  265 + //添加待发送的短信通知
  266 + notify.AddNotifyStaffAssess(&assessList[i])
  267 + }
263 } 268 }
264 -  
265 return map[string]interface{}{ 269 return map[string]interface{}{
266 "assessTaskId": assessTaskData.Id, 270 "assessTaskId": assessTaskData.Id,
267 }, nil 271 }, nil
@@ -5,12 +5,11 @@ import ( @@ -5,12 +5,11 @@ import (
5 "strconv" 5 "strconv"
6 "time" 6 "time"
7 7
8 - "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/constant"  
9 - "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/serviceGateway"  
10 - "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log"  
11 -  
12 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory" 8 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
  9 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/notify"
  10 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/constant"
13 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" 11 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
  12 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log"
14 ) 13 )
15 14
16 // sendSummaryEvaluafionTask 根据评估项目设置,确认是否下发评估任务 15 // sendSummaryEvaluafionTask 根据评估项目设置,确认是否下发评估任务
@@ -272,8 +271,8 @@ func TaskSendSummaryEvaluation() error { @@ -272,8 +271,8 @@ func TaskSendSummaryEvaluation() error {
272 if err := transactionContext.CommitTransaction(); err != nil { 271 if err := transactionContext.CommitTransaction(); err != nil {
273 return err 272 return err
274 } 273 }
275 - //发送短信通知  
276 - //err = sendSmsEvalation(createdEvalationList) 274 + //添加待发送的短信通知
  275 + err = sendSmsEvalation(createdEvalationList)
277 return err 276 return err
278 } 277 }
279 278
@@ -282,49 +281,53 @@ func sendSmsEvalation(param []domain.SummaryEvaluation) error { @@ -282,49 +281,53 @@ func sendSmsEvalation(param []domain.SummaryEvaluation) error {
282 if constant.Env != "prd" { 281 if constant.Env != "prd" {
283 return nil 282 return nil
284 } 283 }
  284 + for i := range param {
  285 + notify.AddNotifySummaryEvaluation(&param[i])
  286 + }
  287 +
285 //处理短信发送 288 //处理短信发送
286 //过滤去重 处理需要发送改执行人的消息 执行人id=>domain.LogSms 289 //过滤去重 处理需要发送改执行人的消息 执行人id=>domain.LogSms
287 - noticeMap := map[string]*domain.LogSms{}  
288 - for _, v := range param {  
289 - phone := v.Executor.Account  
290 - name := v.Executor.UserName  
291 - if _, ok := noticeMap[phone]; ok {  
292 - continue  
293 - }  
294 - if phone == "" {  
295 - continue  
296 - }  
297 - smsMessage := domain.LogSms{}  
298 - smsMessage.SummaryEvaluationMessage(phone, name)  
299 - noticeMap[phone] = &smsMessage  
300 - } 290 + // noticeMap := map[string]*domain.LogSms{}
  291 + // for _, v := range param {
  292 + // phone := v.Executor.Account
  293 + // name := v.Executor.UserName
  294 + // if _, ok := noticeMap[phone]; ok {
  295 + // continue
  296 + // }
  297 + // if phone == "" {
  298 + // continue
  299 + // }
  300 + // smsMessage := domain.LogSms{}
  301 + // smsMessage.SummaryEvaluationMessage(phone, name)
  302 + // noticeMap[phone] = &smsMessage
  303 + // }
301 304
302 - sms := serviceGateway.SmsService{}  
303 - for _, v := range noticeMap {  
304 - err := sms.SendNoticeSms(v.Phone, v.TemplateId, v.Value)  
305 - if err != nil {  
306 - v.Result = err.Error()  
307 - }  
308 - }  
309 - transactionContext, err := factory.CreateTransactionContext(nil)  
310 - if err != nil {  
311 - return err  
312 - }  
313 - if err := transactionContext.StartTransaction(); err != nil {  
314 - return err  
315 - }  
316 - defer func() {  
317 - _ = transactionContext.RollbackTransaction()  
318 - }()  
319 - logSmsRepo := factory.CreateLogSmsRepository(map[string]interface{}{"transactionContext": transactionContext})  
320 - for _, v := range noticeMap {  
321 - err = logSmsRepo.Insert(v)  
322 - if err != nil {  
323 - log.Logger.Error("TaskSendSummaryEvaluation 发送短信通知:" + err.Error())  
324 - }  
325 - }  
326 - if err := transactionContext.CommitTransaction(); err != nil {  
327 - return err  
328 - } 305 + // sms := serviceGateway.SmsService{}
  306 + // for _, v := range noticeMap {
  307 + // err := sms.SendNoticeSms(v.Phone, v.TemplateId, v.Value)
  308 + // if err != nil {
  309 + // v.Result = err.Error()
  310 + // }
  311 + // }
  312 + // transactionContext, err := factory.CreateTransactionContext(nil)
  313 + // if err != nil {
  314 + // return err
  315 + // }
  316 + // if err := transactionContext.StartTransaction(); err != nil {
  317 + // return err
  318 + // }
  319 + // defer func() {
  320 + // _ = transactionContext.RollbackTransaction()
  321 + // }()
  322 + // logSmsRepo := factory.CreateLogSmsRepository(map[string]interface{}{"transactionContext": transactionContext})
  323 + // for _, v := range noticeMap {
  324 + // err = logSmsRepo.Insert(v)
  325 + // if err != nil {
  326 + // log.Logger.Error("TaskSendSummaryEvaluation 发送短信通知:" + err.Error())
  327 + // }
  328 + // }
  329 + // if err := transactionContext.CommitTransaction(); err != nil {
  330 + // return err
  331 + // }
329 return nil 332 return nil
330 } 333 }