sms_staff_assess.go
4.4 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package notify
import (
"time"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/constant"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
)
// 每日自评短信通知
type notifyStaffAssess struct {
}
var _ notifySendOrNot = (*notifyStaffAssess)(nil)
func (notices notifyStaffAssess) from() string {
return "StaffAssess"
}
// makeNotify 生成待执行的短信通知内容
func (notices notifyStaffAssess) makeNotify(param *domain.StaffAssess) *domain.LogSms {
year, month, dayNumber := param.BeginTime.Local().Date()
// 限制只有 在每月的15号进行每日评估填报时,才进行短信消息提醒
// if dayNumber != 15 {
// return nil
// }
// 每月15日的每日评估必做,未填写的在晚上10点下发短信提醒
dayTime := time.Date(year, month, dayNumber, 22, 0, 0, 0, time.Local)
newSms := domain.LogSms{
Id: 0,
Phone: param.Executor.Account,
TemplateId: 5833754,
Template: "您好,#name#,您还未完成#date#的绩效自评反馈,请及时完成哦",
Value: map[string]string{
"name": param.Executor.UserName,
"date": "本月15日",
},
Result: "",
Status: domain.SmsWait,
From: notices.from(),
Index: param.Id,
ExecuteAt: dayTime,
CreatedAt: time.Now(),
}
return &newSms
}
// ifSend 确认是否发送通知
func (notices notifyStaffAssess) ifSend(index int) (bool, error) {
if constant.Env != "prd" {
return false, nil
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return false, err
}
if err := transactionContext.StartTransaction(); err != nil {
return false, err
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
staffAssessRepo := factory.CreateStaffAssessRepository(map[string]interface{}{"transactionContext": transactionContext})
assessData, err := staffAssessRepo.FindOne(map[string]interface{}{"id": index})
if err != nil {
return false, err
}
_, _, dayNumber := assessData.BeginTime.Local().Date()
// 限制只有 在每月的15号进行每日评估填报时,才进行短信消息提醒
if dayNumber != 15 {
return false, nil
}
//还未完成评估填写,时发送短信
if assessData.Status == domain.StaffAssessUncompleted {
return true, nil
}
if err := transactionContext.CommitTransaction(); err != nil {
return false, err
}
return false, nil
}
// TODO
type notifyStaffAssess2 struct {
}
var _ notifySendOrNot = (*notifyStaffAssess2)(nil)
func (notices notifyStaffAssess2) from() string {
return "StaffAssess2"
}
// makeNotify 生成待执行的短信通知内容
func (notices notifyStaffAssess2) makeNotify(param *domain.StaffAssess) *domain.LogSms {
year, month, dayNumber := param.BeginTime.Local().Date()
// 限制只有 在每月的15号进行每日评估填报时,才进行短信消息提醒
// if dayNumber != 15 {
// return nil
// }
// 每月15日的每日评估必做,15日上午9点 发送短信提醒
dayTime := time.Date(year, month, dayNumber, 9, 0, 0, 0, time.Local)
newSms := domain.LogSms{
Id: 0,
Phone: param.Executor.Account,
TemplateId: 5824230,
Template: "您好,#name#,百忙之中不要忘记填写#date#的绩效自评反馈哦",
Value: map[string]string{
"name": param.Executor.UserName,
"date": "本月15日",
},
Result: "",
Status: domain.SmsWait,
From: notices.from(),
Index: param.Id,
ExecuteAt: dayTime,
CreatedAt: time.Now(),
}
return &newSms
}
// ifSend 确认是否发送通知
func (notices notifyStaffAssess2) ifSend(index int) (bool, error) {
if constant.Env != "prd" {
return false, nil
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return false, err
}
if err := transactionContext.StartTransaction(); err != nil {
return false, err
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
staffAssessRepo := factory.CreateStaffAssessRepository(map[string]interface{}{"transactionContext": transactionContext})
assessData, err := staffAssessRepo.FindOne(map[string]interface{}{"id": index})
if err != nil {
return false, err
}
_, _, dayNumber := assessData.BeginTime.Local().Date()
// 限制只有 在每月的15号进行每日评估填报时,才进行短信消息提醒
if dayNumber != 15 {
return false, nil
}
if err := transactionContext.CommitTransaction(); err != nil {
return false, err
}
return true, nil
}