作者 郑周

Merge branch 'test' into dev-zhengzhou

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
@@ -11,6 +14,7 @@ func RunTaskSmsNotify() { @@ -11,6 +14,7 @@ func RunTaskSmsNotify() {
11 taskSmsNotify.init() 14 taskSmsNotify.init()
12 taskSmsNotify.regist(notifyStaffAssess{}) 15 taskSmsNotify.regist(notifyStaffAssess{})
13 taskSmsNotify.regist(notifySummaryEvaluation{}) 16 taskSmsNotify.regist(notifySummaryEvaluation{})
  17 + taskSmsNotify.regist(notifyConfirmEvaluationScore{})
14 taskSmsNotify.runTask() 18 taskSmsNotify.runTask()
15 } 19 }
16 20
@@ -27,3 +31,33 @@ func AddNotifySummaryEvaluation(param *domain.SummaryEvaluation) { @@ -27,3 +31,33 @@ func AddNotifySummaryEvaluation(param *domain.SummaryEvaluation) {
27 newSms := newNotify.makeNotify(param) 31 newSms := newNotify.makeNotify(param)
28 taskSmsNotify.addTask(newSms) 32 taskSmsNotify.addTask(newSms)
29 } 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,17 +36,22 @@ func (notices *notifySms) regist(ifsend notifySendOrNot) { @@ -36,17 +36,22 @@ 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 执行短信通知任务
49 func (notices *notifySms) runTask() { 51 func (notices *notifySms) runTask() {
  52 + if constant.Env != "prd" {
  53 + return
  54 + }
50 timer := time.NewTimer(notices.interval) 55 timer := time.NewTimer(notices.interval)
51 for { 56 for {
52 select { 57 select {
@@ -130,9 +135,7 @@ func (notices *notifySms) checkSendSms() error { @@ -130,9 +135,7 @@ func (notices *notifySms) checkSendSms() error {
130 135
131 // sendSms 发送短信消息 136 // sendSms 发送短信消息
132 func (notices *notifySms) sendSms(param *domain.LogSms) error { 137 func (notices *notifySms) sendSms(param *domain.LogSms) error {
133 - if constant.Env != "prd" {  
134 - return nil  
135 - } 138 +
136 //单开处理 数据保存操作,发一条短信更新一条数据 139 //单开处理 数据保存操作,发一条短信更新一条数据
137 transactionContext, err := factory.CreateTransactionContext(nil) 140 transactionContext, err := factory.CreateTransactionContext(nil)
138 if err != nil { 141 if err != nil {
  1 +package notify
  2 +
  3 +import (
  4 + "time"
  5 +
  6 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
  7 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
  8 +)
  9 +
  10 +// 短信提醒确认周期评估成绩
  11 +// 条件:上级提交评估后 到10号晚23:59前,对未确认的被评估人每隔6个小时进行提醒(23:00-7:00期间不提醒),直到确认
  12 +type notifyConfirmEvaluationScore struct {
  13 +}
  14 +
  15 +var _ notifySendOrNot = (*notifyConfirmEvaluationScore)(nil)
  16 +
  17 +func (notices notifyConfirmEvaluationScore) from() string {
  18 + return "ConfirmEvaluationScore"
  19 +}
  20 +
  21 +func (notices notifyConfirmEvaluationScore) makeNotify(param *domain.SummaryEvaluation) *domain.LogSms {
  22 + newSms := domain.LogSms{
  23 + Id: 0,
  24 + Phone: param.Executor.Account,
  25 + TemplateId: 5634326,
  26 + Template: "您好,#name#,#periodName#成绩已出,请前往绩效系统PC端进行确认哦,超时未确认可能会影响当月绩效工资哦~ ",
  27 + Value: map[string]string{
  28 + "name": param.Executor.UserName,
  29 + "periodName": param.CycleName,
  30 + },
  31 + Result: "",
  32 + Status: domain.SmsWait,
  33 + From: notices.from(),
  34 + Index: param.Id,
  35 + ExecuteAt: notices.getTimeExecuteAt(time.Now()),
  36 + CreatedAt: time.Now(),
  37 + }
  38 + return &newSms
  39 +}
  40 +
  41 +// 适配规则:上级提交评估后 到10号晚23:59前,可以发送
  42 +// 适配规则 对未确认的被评估人每隔6个小时进行提醒(23:00-7:00期间不提醒),直到确认
  43 +func (notices notifyConfirmEvaluationScore) ifSend(index int) (bool, error) {
  44 +
  45 + //检查时间
  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 + }
  74 +
  75 + //检查数据 SummaryEvaluation ,types=5,并添加短信数据
  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 + }
  88 +
  89 + return true, nil
  90 +}
  91 +
  92 +// 输入的时间为基础微调短信的执行时间
  93 +// 适配规则 :(23:00-7:00期间不提醒)
  94 +func (notices notifyConfirmEvaluationScore) getTimeExecuteAt(nowTime time.Time) time.Time {
  95 + nowHour := nowTime.Local().Hour()
  96 + if nowHour < 23 && nowHour > 7 {
  97 + return nowTime
  98 + }
  99 + year, month, day := nowTime.Local().Date()
  100 + //微调执行时间
  101 + if nowHour >= 23 {
  102 + //第二天:7:00
  103 + t1 := time.Date(year, month, day, 23, 59, 59, 0, time.Local)
  104 + return t1.Add(7 * time.Hour)
  105 + }
  106 + if nowHour <= 7 {
  107 + //当天 7:00
  108 + t1 := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  109 + return t1.Add(7 * time.Hour)
  110 + }
  111 + return nowTime
  112 +}
@@ -11,6 +11,8 @@ import ( @@ -11,6 +11,8 @@ import (
11 type notifyStaffAssess struct { 11 type notifyStaffAssess struct {
12 } 12 }
13 13
  14 +var _ notifySendOrNot = (*notifyStaffAssess)(nil)
  15 +
14 func (notices notifyStaffAssess) from() string { 16 func (notices notifyStaffAssess) from() string {
15 return "StaffAssess" 17 return "StaffAssess"
16 } 18 }
@@ -12,6 +12,8 @@ import ( @@ -12,6 +12,8 @@ import (
12 type notifySummaryEvaluation struct { 12 type notifySummaryEvaluation struct {
13 } 13 }
14 14
  15 +var _ notifySendOrNot = (*notifySummaryEvaluation)(nil)
  16 +
15 func (notices notifySummaryEvaluation) from() string { 17 func (notices notifySummaryEvaluation) from() string {
16 return "SummaryEvaluation" 18 return "SummaryEvaluation"
17 } 19 }
@@ -7,6 +7,7 @@ type EvaluationSuperListAdapter struct { @@ -7,6 +7,7 @@ type EvaluationSuperListAdapter struct {
7 EvaluationStatus string `json:"evaluationStatus"` //上级评估完成状态 7 EvaluationStatus string `json:"evaluationStatus"` //上级评估完成状态
8 EndTime string `json:"endTime"` //截止时间 8 EndTime string `json:"endTime"` //截止时间
9 TotalScoreSelf string `json:"totalScoreSelf"` //综合自评总分 9 TotalScoreSelf string `json:"totalScoreSelf"` //综合自评总分
  10 + TotalScoreSuper string `json:"totalScoreSuper"` //综合自评总分
10 Department string `json:"department"` //部门 11 Department string `json:"department"` //部门
11 Position string `json:"position"` //职位 12 Position string `json:"position"` //职位
12 EntryTime string `json:"entryTime"` //入职时间 13 EntryTime string `json:"entryTime"` //入职时间
@@ -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,9 +822,15 @@ func (srv *SummaryEvaluationService) AfterCompletedEvaluationSuper(param *domain @@ -821,9 +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 }
  825 +
824 if err := transactionContext.CommitTransaction(); err != nil { 826 if err := transactionContext.CommitTransaction(); err != nil {
825 return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 827 return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
826 } 828 }
  829 + //添加确认绩效成绩提醒短信提醒
  830 + err = notify.AddNotifyConfirmEvaluationScore(param)
  831 + if err != nil {
  832 + return application.ThrowError(application.TRANSACTION_ERROR, "创建短信提醒失败"+err.Error())
  833 + }
827 return nil 834 return nil
828 } 835 }
829 836
@@ -1572,6 +1579,7 @@ func (srv *SummaryEvaluationService) ListExecutorEvaluationSuper(param *command. @@ -1572,6 +1579,7 @@ func (srv *SummaryEvaluationService) ListExecutorEvaluationSuper(param *command.
1572 Department: "", 1579 Department: "",
1573 Position: "", 1580 Position: "",
1574 EntryTime: "", 1581 EntryTime: "",
  1582 + TotalScoreSuper: v.TotalScore,
1575 } 1583 }
1576 for _, dep := range v.TargetDepartment { 1584 for _, dep := range v.TargetDepartment {
1577 item.Department += dep.DepartmentName + " " 1585 item.Department += dep.DepartmentName + " "
@@ -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
@@ -7,7 +7,7 @@ func TestPushInfo(t *testing.T) { @@ -7,7 +7,7 @@ func TestPushInfo(t *testing.T) {
7 c := NewHttplibMmmOpenApiServiceGateway() 7 c := NewHttplibMmmOpenApiServiceGateway()
8 //3436890424617728 8 //3436890424617728
9 //3422173870118400 9 //3422173870118400
10 - resp, err := c.PushInfo(0, "mmm.ability.performance", []int64{3436890424617728}, "ceshi推送一个消息233", "消息内容xxxx332") 10 + resp, err := c.PushInfo(0, "mmm.ability.performance", []int64{3422173870118400}, "ceshi推送一个消息233", "消息内容xxxx332")
11 if err != nil { 11 if err != nil {
12 t.Error(err) 12 t.Error(err)
13 } 13 }