run.go
1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package notify
import (
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
)
// 执行定时任务检查是否发送短信通知
var taskSmsNotify *notifySms
// 检查并发送短信通知
func RunTaskSmsNotify() {
taskSmsNotify = ¬ifySms{}
taskSmsNotify.init()
taskSmsNotify.regist(notifyStaffAssess{})
taskSmsNotify.regist(notifySummaryEvaluation{})
taskSmsNotify.regist(notifyConfirmEvaluationScore{})
taskSmsNotify.runTask()
}
// 每日自评短信通知 ,预创建待发送的短信消息
func AddNotifyStaffAssess(param *domain.StaffAssess) {
newNotify := notifyStaffAssess{}
newSms := newNotify.makeNotify(param)
if newSms == nil {
return
}
taskSmsNotify.addTask(newSms)
}
// 周期自评短信通知 ,预创建待发送的短信消息
func AddNotifySummaryEvaluation(param *domain.SummaryEvaluation) {
newNotify := notifySummaryEvaluation{}
newSms := newNotify.makeNotify(param)
if newSms == nil {
return
}
taskSmsNotify.addTask(newSms)
}
// 确认周期评估短信提醒 ,预创建待发送的短信消息
func AddNotifyConfirmEvaluationScore(param *domain.SummaryEvaluation) error {
newNotify := notifyConfirmEvaluationScore{}
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})
cnt, _, err := logSmsRepo.Find(map[string]interface{}{"from": newNotify.from(), "index": param.Id, "limit": 1})
if err != nil {
return err
}
if cnt > 0 {
return nil
}
if err := transactionContext.CommitTransaction(); err != nil {
return err
}
newSms := newNotify.makeNotify(param)
if newSms == nil {
return nil
}
return taskSmsNotify.addTask(newSms)
}