审查视图

pkg/application/notify/sms_staff_assess.go 1.8 KB
tangxvhui authored
1 2 3 4 5 6 7 8 9 10
package notify

import (
	"time"

	"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
	"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
)

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