审查视图

pkg/application/notify/sms_summary_evaluation.go 1.9 KB
tangxvhui authored
1 2 3
package notify

import (
tangxvhui authored
4 5
	"time"
tangxvhui authored
6 7 8 9 10 11
	"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
	"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
)

// 周期评估短信通知
// 条件:周期自评结束前4个小时,且还未完成评估填写
tangxvhui authored
12
type notifySummaryEvaluation struct {
tangxvhui authored
13 14
}
tangxvhui authored
15
func (notices notifySummaryEvaluation) from() string {
tangxvhui authored
16 17 18
	return "SummaryEvaluation"
}
tangxvhui authored
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
// makeNotify 生成待执行的短信通知内容
func (notices notifySummaryEvaluation) makeNotify(param *domain.SummaryEvaluation) *domain.LogSms {
	newSms := domain.LogSms{
		Id:         0,
		Phone:      param.Executor.Account,
		TemplateId: 5536232,
		Template:   "您好,#name#,百忙之中不要忘记填写本月综合自评哦",
		Value: map[string]string{
			"name": param.Executor.UserName,
		},
		Result: "",
		Status: domain.SmsWait,
		From:   notices.from(),
		Index:  param.Id,
		// ExecuteAt:  executeAt,
		CreatedAt: time.Now(),
	}
	// 周期自评结束前4个小时,
	newSms.ExecuteAt = param.EndTime.Add(-4 * time.Hour)
	return &newSms
tangxvhui authored
39 40
}
tangxvhui authored
41
// ifSend 确认是否发送通知
tangxvhui authored
42
func (notices notifySummaryEvaluation) ifSend(index int) (bool, error) {
tangxvhui authored
43 44
	transactionContext, err := factory.CreateTransactionContext(nil)
	if err != nil {
tangxvhui authored
45
		return false, err
tangxvhui authored
46 47
	}
	if err := transactionContext.StartTransaction(); err != nil {
tangxvhui authored
48
		return false, err
tangxvhui authored
49 50 51 52
	}
	defer func() {
		_ = transactionContext.RollbackTransaction()
	}()
tangxvhui authored
53 54
	summaryEvaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{"transactionContext": transactionContext})
	summaryEvaluationData, err := summaryEvaluationRepo.FindOne(map[string]interface{}{"id": index})
tangxvhui authored
55
	if err != nil {
tangxvhui authored
56 57 58 59 60
		return false, err
	}
	//还未完成评估填写,时发送短信
	if summaryEvaluationData.Status == domain.EvaluationUncompleted {
		return true, nil
tangxvhui authored
61 62
	}
	if err := transactionContext.CommitTransaction(); err != nil {
tangxvhui authored
63
		return false, err
tangxvhui authored
64
	}
tangxvhui authored
65
	return false, nil
tangxvhui authored
66
}