正在显示
5 个修改的文件
包含
96 行增加
和
8 行删除
| 1 | package notify | 1 | package notify |
| 2 | 2 | ||
| 3 | -import "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" | 3 | +import ( |
| 4 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory" | ||
| 5 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" | ||
| 6 | +) | ||
| 4 | 7 | ||
| 5 | // 执行定时任务检查是否发送短信通知 | 8 | // 执行定时任务检查是否发送短信通知 |
| 6 | var taskSmsNotify *notifySms | 9 | var taskSmsNotify *notifySms |
| @@ -28,3 +31,33 @@ func AddNotifySummaryEvaluation(param *domain.SummaryEvaluation) { | @@ -28,3 +31,33 @@ func AddNotifySummaryEvaluation(param *domain.SummaryEvaluation) { | ||
| 28 | newSms := newNotify.makeNotify(param) | 31 | newSms := newNotify.makeNotify(param) |
| 29 | taskSmsNotify.addTask(newSms) | 32 | taskSmsNotify.addTask(newSms) |
| 30 | } | 33 | } |
| 34 | + | ||
| 35 | +// 确认周期评估短信提醒 ,预创建待发送的短信消息 | ||
| 36 | +func AddNotifyConfirmEvaluationScore(param *domain.SummaryEvaluation) error { | ||
| 37 | + newNotify := notifyConfirmEvaluationScore{} | ||
| 38 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
| 39 | + if err != nil { | ||
| 40 | + return err | ||
| 41 | + } | ||
| 42 | + if err := transactionContext.StartTransaction(); err != nil { | ||
| 43 | + return err | ||
| 44 | + } | ||
| 45 | + defer func() { | ||
| 46 | + _ = transactionContext.RollbackTransaction() | ||
| 47 | + }() | ||
| 48 | + logSmsRepo := factory.CreateLogSmsRepository(map[string]interface{}{"transactionContext": transactionContext}) | ||
| 49 | + | ||
| 50 | + cnt, _, err := logSmsRepo.Find(map[string]interface{}{"from": newNotify.from(), "index": param.Id, "limit": 1}) | ||
| 51 | + if err != nil { | ||
| 52 | + return err | ||
| 53 | + } | ||
| 54 | + if cnt > 0 { | ||
| 55 | + return nil | ||
| 56 | + } | ||
| 57 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 58 | + return err | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + newSms := newNotify.makeNotify(param) | ||
| 62 | + return taskSmsNotify.addTask(newSms) | ||
| 63 | +} |
| @@ -36,13 +36,15 @@ func (notices *notifySms) regist(ifsend notifySendOrNot) { | @@ -36,13 +36,15 @@ func (notices *notifySms) regist(ifsend notifySendOrNot) { | ||
| 36 | notices.sendOrNot[ifsend.from()] = ifsend | 36 | notices.sendOrNot[ifsend.from()] = ifsend |
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | -func (notices *notifySms) addTask(task *domain.LogSms) { | 39 | +func (notices *notifySms) addTask(task *domain.LogSms) error { |
| 40 | // notices.newSms <- task | 40 | // notices.newSms <- task |
| 41 | err := notices.addNewSms(task) | 41 | err := notices.addNewSms(task) |
| 42 | if err != nil { | 42 | if err != nil { |
| 43 | e := fmt.Sprintf("添加短信通知任务:%+v %s", task, err) | 43 | e := fmt.Sprintf("添加短信通知任务:%+v %s", task, err) |
| 44 | log.Logger.Error(e) | 44 | log.Logger.Error(e) |
| 45 | + return fmt.Errorf("添加短信通知任务:%s", err) | ||
| 45 | } | 46 | } |
| 47 | + return nil | ||
| 46 | } | 48 | } |
| 47 | 49 | ||
| 48 | // RunTask 执行短信通知任务 | 50 | // RunTask 执行短信通知任务 |
| @@ -3,6 +3,7 @@ package notify | @@ -3,6 +3,7 @@ package notify | ||
| 3 | import ( | 3 | import ( |
| 4 | "time" | 4 | "time" |
| 5 | 5 | ||
| 6 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory" | ||
| 6 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" | 7 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" |
| 7 | ) | 8 | ) |
| 8 | 9 | ||
| @@ -21,8 +22,8 @@ func (notices notifyConfirmEvaluationScore) makeNotify(param *domain.SummaryEval | @@ -21,8 +22,8 @@ func (notices notifyConfirmEvaluationScore) makeNotify(param *domain.SummaryEval | ||
| 21 | newSms := domain.LogSms{ | 22 | newSms := domain.LogSms{ |
| 22 | Id: 0, | 23 | Id: 0, |
| 23 | Phone: param.Executor.Account, | 24 | Phone: param.Executor.Account, |
| 24 | - TemplateId: 5475050, | ||
| 25 | - Template: "您好,#name#,#periodName#成绩已出,请前往绩效系统PC端进行确认哦,逾期未确认可能会影响当月绩效工资哦~ ", | 25 | + TemplateId: 5634326, |
| 26 | + Template: "您好,#name#,#periodName#成绩已出,请前往绩效系统PC端进行确认哦,超时未确认可能会影响当月绩效工资哦~ ", | ||
| 26 | Value: map[string]string{ | 27 | Value: map[string]string{ |
| 27 | "name": param.Executor.UserName, | 28 | "name": param.Executor.UserName, |
| 28 | "periodName": param.CycleName, | 29 | "periodName": param.CycleName, |
| @@ -37,12 +38,53 @@ func (notices notifyConfirmEvaluationScore) makeNotify(param *domain.SummaryEval | @@ -37,12 +38,53 @@ func (notices notifyConfirmEvaluationScore) makeNotify(param *domain.SummaryEval | ||
| 37 | return &newSms | 38 | return &newSms |
| 38 | } | 39 | } |
| 39 | 40 | ||
| 41 | +// 适配规则:上级提交评估后 到10号晚23:59前,可以发送 | ||
| 42 | +// 适配规则 对未确认的被评估人每隔6个小时进行提醒(23:00-7:00期间不提醒),直到确认 | ||
| 40 | func (notices notifyConfirmEvaluationScore) ifSend(index int) (bool, error) { | 43 | func (notices notifyConfirmEvaluationScore) ifSend(index int) (bool, error) { |
| 44 | + | ||
| 41 | //检查时间 | 45 | //检查时间 |
| 42 | - //适配规则:上级提交评估后 到10号晚23:59前,可以发送 | 46 | + // |
| 47 | + nowTime := time.Now() | ||
| 48 | + if nowTime.Day() > 10 { | ||
| 49 | + return false, nil | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
| 53 | + if err != nil { | ||
| 54 | + return false, err | ||
| 55 | + } | ||
| 56 | + if err := transactionContext.StartTransaction(); err != nil { | ||
| 57 | + return false, err | ||
| 58 | + } | ||
| 59 | + defer func() { | ||
| 60 | + _ = transactionContext.RollbackTransaction() | ||
| 61 | + }() | ||
| 62 | + summaryEvaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{"transactionContext": transactionContext}) | ||
| 63 | + summaryEvaluationData, err := summaryEvaluationRepo.FindOne(map[string]interface{}{"id": index}) | ||
| 64 | + if err != nil { | ||
| 65 | + return false, err | ||
| 66 | + } | ||
| 67 | + if summaryEvaluationData.Types == domain.EvaluationFinish { | ||
| 68 | + return false, nil | ||
| 69 | + } | ||
| 70 | + //已确认 成绩,不在发送成绩 | ||
| 71 | + if summaryEvaluationData.CheckResult == domain.EvaluationCheckCompleted { | ||
| 72 | + return false, nil | ||
| 73 | + } | ||
| 43 | 74 | ||
| 44 | //检查数据 SummaryEvaluation ,types=5,并添加短信数据 | 75 | //检查数据 SummaryEvaluation ,types=5,并添加短信数据 |
| 45 | - //适配规则 对未确认的被评估人每隔6个小时进行提醒(23:00-7:00期间不提醒),直到确认 | 76 | + //计算下一条短信 |
| 77 | + smsMessage := notices.makeNotify(summaryEvaluationData) | ||
| 78 | + nextTime := nowTime.Add(6 * time.Hour) | ||
| 79 | + smsMessage.ExecuteAt = notices.getTimeExecuteAt(nextTime) | ||
| 80 | + logSmsRepo := factory.CreateLogSmsRepository(map[string]interface{}{"transactionContext": transactionContext}) | ||
| 81 | + err = logSmsRepo.Save(smsMessage) | ||
| 82 | + if err != nil { | ||
| 83 | + return true, err | ||
| 84 | + } | ||
| 85 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 86 | + return false, err | ||
| 87 | + } | ||
| 46 | 88 | ||
| 47 | return true, nil | 89 | return true, nil |
| 48 | } | 90 | } |
| @@ -10,6 +10,7 @@ import ( | @@ -10,6 +10,7 @@ import ( | ||
| 10 | "github.com/linmadan/egglib-go/core/application" | 10 | "github.com/linmadan/egglib-go/core/application" |
| 11 | "github.com/linmadan/egglib-go/utils/tool_funs" | 11 | "github.com/linmadan/egglib-go/utils/tool_funs" |
| 12 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory" | 12 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory" |
| 13 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/notify" | ||
| 13 | roleService "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/role" | 14 | roleService "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/role" |
| 14 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/summary_evaluation/adapter" | 15 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/summary_evaluation/adapter" |
| 15 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/summary_evaluation/command" | 16 | "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/summary_evaluation/command" |
| @@ -821,10 +822,15 @@ func (srv *SummaryEvaluationService) AfterCompletedEvaluationSuper(param *domain | @@ -821,10 +822,15 @@ func (srv *SummaryEvaluationService) AfterCompletedEvaluationSuper(param *domain | ||
| 821 | return application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存考核结果,"+err.Error()) | 822 | return application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存考核结果,"+err.Error()) |
| 822 | } | 823 | } |
| 823 | } | 824 | } |
| 824 | - //添加确认绩效成绩提醒短信提醒 | 825 | + |
| 825 | if err := transactionContext.CommitTransaction(); err != nil { | 826 | if err := transactionContext.CommitTransaction(); err != nil { |
| 826 | return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 827 | return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
| 827 | } | 828 | } |
| 829 | + //添加确认绩效成绩提醒短信提醒 | ||
| 830 | + err = notify.AddNotifyConfirmEvaluationScore(param) | ||
| 831 | + if err != nil { | ||
| 832 | + return application.ThrowError(application.TRANSACTION_ERROR, "创建短信提醒失败"+err.Error()) | ||
| 833 | + } | ||
| 828 | return nil | 834 | return nil |
| 829 | } | 835 | } |
| 830 | 836 |
| @@ -68,7 +68,12 @@ func (repo *LogSmsRepository) Find(queryOptions map[string]interface{}) (int, [] | @@ -68,7 +68,12 @@ func (repo *LogSmsRepository) Find(queryOptions map[string]interface{}) (int, [] | ||
| 68 | if v, ok := queryOptions["executeAtEnd"]; ok { | 68 | if v, ok := queryOptions["executeAtEnd"]; ok { |
| 69 | query.Where("execute_at<=?", v) | 69 | query.Where("execute_at<=?", v) |
| 70 | } | 70 | } |
| 71 | - | 71 | + if v, ok := queryOptions["from"]; ok { |
| 72 | + query.Where("from=?", v) | ||
| 73 | + } | ||
| 74 | + if v, ok := queryOptions["index"]; ok { | ||
| 75 | + query.Where("index=?", v) | ||
| 76 | + } | ||
| 72 | count, err := query.SelectAndCount() | 77 | count, err := query.SelectAndCount() |
| 73 | if err != nil { | 78 | if err != nil { |
| 74 | return 0, nil, err | 79 | return 0, nil, err |
-
请 注册 或 登录 后发表评论