正在显示
8 个修改的文件
包含
255 行增加
和
11 行删除
pkg/application/notify/sms_staff_assess.go
0 → 100644
1 | +package notify | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "time" | ||
6 | + | ||
7 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory" | ||
8 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/constant" | ||
9 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" | ||
10 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log" | ||
11 | +) | ||
12 | + | ||
13 | +// 短信通知 | ||
14 | + | ||
15 | +// 每日自评短信通知 | ||
16 | +// 条件:每日自评结束前30分钟,且还未完成评估填写 | ||
17 | +type NotifyStaffAssess struct { | ||
18 | + newSms chan *domain.LogSms | ||
19 | + interval time.Duration | ||
20 | +} | ||
21 | + | ||
22 | +func (notices *NotifyStaffAssess) init() { | ||
23 | + notices.newSms = make(chan *domain.LogSms, 50) | ||
24 | + notices.interval = 10 * time.Minute | ||
25 | + if constant.Env != "prd" { | ||
26 | + notices.interval = 1 * time.Minute | ||
27 | + } | ||
28 | +} | ||
29 | + | ||
30 | +func (notices *NotifyStaffAssess) From() string { | ||
31 | + return "StaffAssess" | ||
32 | +} | ||
33 | + | ||
34 | +// AddTask 添加待执行的短信通知任务 | ||
35 | +func (notices *NotifyStaffAssess) AddTask(index int, phone string, param map[string]string, executeAt time.Time) { | ||
36 | + newSms := &domain.LogSms{ | ||
37 | + Id: 0, | ||
38 | + Phone: phone, | ||
39 | + TemplateId: 5475050, | ||
40 | + Template: "您好,#name#,百忙之中不要忘记填写今天的绩效自评反馈哦", | ||
41 | + Value: param, | ||
42 | + Result: "", | ||
43 | + Status: domain.SmsWait, | ||
44 | + From: notices.From(), | ||
45 | + Index: index, | ||
46 | + ExecuteAt: executeAt, | ||
47 | + CreatedAt: time.Now(), | ||
48 | + } | ||
49 | + notices.newSms <- newSms | ||
50 | +} | ||
51 | + | ||
52 | +// RunTask 执行短信通知任务 | ||
53 | +func (notices *NotifyStaffAssess) RunTask() { | ||
54 | + notices.init() | ||
55 | + timer := time.NewTimer(notices.interval) | ||
56 | + for { | ||
57 | + select { | ||
58 | + case newSms := <-notices.newSms: | ||
59 | + err := notices.addNewSms(newSms) | ||
60 | + if err != nil { | ||
61 | + e := fmt.Sprintf("添加短信通知任务:%+v %s", newSms, err) | ||
62 | + log.Logger.Error(e) | ||
63 | + } | ||
64 | + case <-timer.C: | ||
65 | + err := notices.sendSms() | ||
66 | + if err != nil { | ||
67 | + log.Logger.Error("发送短信通知任务:" + err.Error()) | ||
68 | + } | ||
69 | + timer.Reset(notices.interval) // 重置定时 | ||
70 | + } | ||
71 | + } | ||
72 | +} | ||
73 | + | ||
74 | +func (notices *NotifyStaffAssess) addNewSms(newSms *domain.LogSms) error { | ||
75 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
76 | + if err != nil { | ||
77 | + return err | ||
78 | + } | ||
79 | + if err := transactionContext.StartTransaction(); err != nil { | ||
80 | + return err | ||
81 | + } | ||
82 | + defer func() { | ||
83 | + _ = transactionContext.RollbackTransaction() | ||
84 | + }() | ||
85 | + logSmsRepo := factory.CreateLogSmsRepository(map[string]interface{}{"transactionContext": transactionContext}) | ||
86 | + err = logSmsRepo.Save(newSms) | ||
87 | + if err != nil { | ||
88 | + return err | ||
89 | + } | ||
90 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
91 | + return err | ||
92 | + } | ||
93 | + return nil | ||
94 | +} | ||
95 | + | ||
96 | +func (notices *NotifyStaffAssess) sendSms() error { | ||
97 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
98 | + if err != nil { | ||
99 | + return err | ||
100 | + } | ||
101 | + if err := transactionContext.StartTransaction(); err != nil { | ||
102 | + return err | ||
103 | + } | ||
104 | + defer func() { | ||
105 | + _ = transactionContext.RollbackTransaction() | ||
106 | + }() | ||
107 | + logSmsRepo := factory.CreateLogSmsRepository(map[string]interface{}{"transactionContext": transactionContext}) | ||
108 | + _ = logSmsRepo | ||
109 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
110 | + return err | ||
111 | + } | ||
112 | + return nil | ||
113 | +} |
1 | +package notify | ||
2 | + | ||
3 | +import ( | ||
4 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" | ||
6 | +) | ||
7 | + | ||
8 | +// 周期评估短信通知 | ||
9 | +// 条件:周期自评结束前4个小时,且还未完成评估填写 | ||
10 | +type NotifySummaryEvaluation struct { | ||
11 | +} | ||
12 | + | ||
13 | +func (notices *NotifySummaryEvaluation) Init() *NotifySummaryEvaluation { | ||
14 | + return &NotifySummaryEvaluation{} | ||
15 | +} | ||
16 | + | ||
17 | +func (notices *NotifySummaryEvaluation) From() string { | ||
18 | + return "SummaryEvaluation" | ||
19 | +} | ||
20 | + | ||
21 | +// AddTask 添加待执行的短信通知任务 | ||
22 | +func (notices *NotifySummaryEvaluation) AddTask(index string, phone string, param map[string]string) error { | ||
23 | + | ||
24 | + return nil | ||
25 | +} | ||
26 | + | ||
27 | +// RunTask 执行短信通知任务 | ||
28 | +func (notice *NotifySummaryEvaluation) RunTask() error { | ||
29 | + | ||
30 | + return nil | ||
31 | +} | ||
32 | + | ||
33 | +func (notice *NotifySummaryEvaluation) addNewSms(newSms *domain.LogSms) error { | ||
34 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
35 | + if err != nil { | ||
36 | + return err | ||
37 | + } | ||
38 | + if err := transactionContext.StartTransaction(); err != nil { | ||
39 | + return err | ||
40 | + } | ||
41 | + defer func() { | ||
42 | + _ = transactionContext.RollbackTransaction() | ||
43 | + }() | ||
44 | + logSmsRepo := factory.CreateLogSmsRepository(map[string]interface{}{"transactionContext": transactionContext}) | ||
45 | + err = logSmsRepo.Save(newSms) | ||
46 | + if err != nil { | ||
47 | + return err | ||
48 | + } | ||
49 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
50 | + return err | ||
51 | + } | ||
52 | + return nil | ||
53 | +} |
@@ -20,8 +20,8 @@ type EvaluationItemUsed struct { | @@ -20,8 +20,8 @@ type EvaluationItemUsed struct { | ||
20 | RuleType int //评估方式(0评级、1评分) | 20 | RuleType int //评估方式(0评级、1评分) |
21 | Rule EvaluationRule //评估的选项规则 | 21 | Rule EvaluationRule //评估的选项规则 |
22 | Weight float64 //"权重" | 22 | Weight float64 //"权重" |
23 | - Required int // 必填项 | ||
24 | - EvaluatorId int // 项目评估人ID ( 0=无评估人、-1=HRBP、 >0 =员工的id ) | 23 | + Required int //必填项 |
24 | + EvaluatorId int //项目评估人ID ( 0=无评估人、-1=HRBP、 >0 =员工的id ) | ||
25 | CreatedAt time.Time //数据创建时间 | 25 | CreatedAt time.Time //数据创建时间 |
26 | UpdatedAt time.Time //数据更新时间 | 26 | UpdatedAt time.Time //数据更新时间 |
27 | } | 27 | } |
@@ -12,6 +12,9 @@ type LogSms struct { | @@ -12,6 +12,9 @@ type LogSms struct { | ||
12 | Value map[string]string | 12 | Value map[string]string |
13 | Result string | 13 | Result string |
14 | Status SmsStatus | 14 | Status SmsStatus |
15 | + From string //业务来源 | ||
16 | + Index int //业务数据索引 | ||
17 | + ExecuteAt time.Time | ||
15 | CreatedAt time.Time | 18 | CreatedAt time.Time |
16 | } | 19 | } |
17 | 20 | ||
@@ -41,4 +44,6 @@ func (sms *LogSms) SummaryEvaluationMessage(phone string, name string) { | @@ -41,4 +44,6 @@ func (sms *LogSms) SummaryEvaluationMessage(phone string, name string) { | ||
41 | 44 | ||
42 | type LogSmsRepository interface { | 45 | type LogSmsRepository interface { |
43 | Insert(param *LogSms) error | 46 | Insert(param *LogSms) error |
47 | + Save(param *LogSms) error | ||
48 | + Find(queryOptions map[string]interface{}) (int, []*LogSms, error) | ||
44 | } | 49 | } |
1 | package models | 1 | package models |
2 | 2 | ||
3 | -import "time" | 3 | +import ( |
4 | + "time" | ||
5 | +) | ||
4 | 6 | ||
5 | type LogSms struct { | 7 | type LogSms struct { |
6 | tableName struct{} `comment:"记录短信消息" pg:"log_sms"` | 8 | tableName struct{} `comment:"记录短信消息" pg:"log_sms"` |
@@ -11,4 +13,8 @@ type LogSms struct { | @@ -11,4 +13,8 @@ type LogSms struct { | ||
11 | Value map[string]string `pg:"value"` | 13 | Value map[string]string `pg:"value"` |
12 | CreatedAt time.Time `pg:"created_at"` | 14 | CreatedAt time.Time `pg:"created_at"` |
13 | Result string `pg:"result"` | 15 | Result string `pg:"result"` |
16 | + Status string `pg:"status"` | ||
17 | + From string `pg:"from"` //业务来源 | ||
18 | + Index int `pg:"index"` //业务数据索引 | ||
19 | + ExecuteAt time.Time `pg:"execute_at"` | ||
14 | } | 20 | } |
@@ -33,3 +33,76 @@ func (repo *LogSmsRepository) Insert(param *domain.LogSms) error { | @@ -33,3 +33,76 @@ func (repo *LogSmsRepository) Insert(param *domain.LogSms) error { | ||
33 | } | 33 | } |
34 | return nil | 34 | return nil |
35 | } | 35 | } |
36 | + | ||
37 | +func (repo *LogSmsRepository) Save(param *domain.LogSms) error { | ||
38 | + m := models.LogSms{ | ||
39 | + Id: param.Id, | ||
40 | + Phone: param.Phone, | ||
41 | + TemplateId: param.TemplateId, | ||
42 | + Template: param.Template, | ||
43 | + Value: param.Value, | ||
44 | + CreatedAt: param.CreatedAt, | ||
45 | + Result: param.Result, | ||
46 | + } | ||
47 | + tx := repo.transactionContext.PgTx | ||
48 | + _, err := tx.Model(&m).Insert() | ||
49 | + if err != nil { | ||
50 | + return err | ||
51 | + } | ||
52 | + return nil | ||
53 | +} | ||
54 | + | ||
55 | +func (repo *LogSmsRepository) Find(queryOptions map[string]interface{}) (int, []*domain.LogSms, error) { | ||
56 | + tx := repo.transactionContext.PgTx | ||
57 | + var m []*models.LogSms | ||
58 | + query := tx.Model(&m) | ||
59 | + if v, ok := queryOptions["limit"].(int); ok { | ||
60 | + query.Limit(v) | ||
61 | + } | ||
62 | + if v, ok := queryOptions["offset"].(int); ok { | ||
63 | + query.Offset(v) | ||
64 | + } | ||
65 | + | ||
66 | + if v, ok := queryOptions["form"]; ok { | ||
67 | + query.Where("from=?", v) | ||
68 | + } | ||
69 | + | ||
70 | + if v, ok := queryOptions["index"]; ok { | ||
71 | + query.Where("index=?", v) | ||
72 | + } | ||
73 | + | ||
74 | + if v, ok := queryOptions["status"]; ok { | ||
75 | + query.Where("status=?", v) | ||
76 | + } | ||
77 | + | ||
78 | + if v, ok := queryOptions["executeAt"]; ok { | ||
79 | + query.Where("execute_at=?", v) | ||
80 | + } | ||
81 | + | ||
82 | + count, err := query.SelectAndCount() | ||
83 | + if err != nil { | ||
84 | + return 0, nil, err | ||
85 | + } | ||
86 | + var datas []*domain.LogSms | ||
87 | + for _, v := range m { | ||
88 | + d := repo.TransformToDomain(v) | ||
89 | + datas = append(datas, d) | ||
90 | + } | ||
91 | + return count, datas, nil | ||
92 | +} | ||
93 | + | ||
94 | +func (repo *LogSmsRepository) TransformToDomain(d *models.LogSms) *domain.LogSms { | ||
95 | + return &domain.LogSms{ | ||
96 | + Id: d.Id, | ||
97 | + Phone: d.Phone, | ||
98 | + TemplateId: d.TemplateId, | ||
99 | + Template: d.Template, | ||
100 | + Value: d.Value, | ||
101 | + Result: d.Result, | ||
102 | + Status: domain.SmsStatus(d.Status), | ||
103 | + From: d.From, | ||
104 | + Index: d.Index, | ||
105 | + ExecuteAt: d.ExecuteAt, | ||
106 | + CreatedAt: d.CreatedAt, | ||
107 | + } | ||
108 | +} |
@@ -300,6 +300,8 @@ func (c *SummaryEvaluationController) GetTargetUserEvaluationSuper() { | @@ -300,6 +300,8 @@ func (c *SummaryEvaluationController) GetTargetUserEvaluationSuper() { | ||
300 | c.Response(nil, e) | 300 | c.Response(nil, e) |
301 | return | 301 | return |
302 | } | 302 | } |
303 | + userReq := middlewares.GetUser(c.Ctx) | ||
304 | + paramReq.CompanyId = int(userReq.CompanyId) | ||
303 | data, err := srv.GetTargetUserEvaluationSuper(paramReq) | 305 | data, err := srv.GetTargetUserEvaluationSuper(paramReq) |
304 | c.Response(data, err) | 306 | c.Response(data, err) |
305 | } | 307 | } |
-
请 注册 或 登录 后发表评论