message_personal.go
3.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package service
import (
"encoding/json"
"fmt"
"strconv"
"time"
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/notify/command"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
)
// 个人信息提示
type MessagePersonalService struct {
}
func NewMessagePersonalService() *MessagePersonalService {
newService := &MessagePersonalService{}
return newService
}
// 获取今天的周期综合自评消息提示
func (srv *MessagePersonalService) TodayMessageSummaryEvaluationSelf(param *command.GetUserMessageCommand) (map[string]interface{}, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
nowTime := time.Now()
evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
_, evaluationList, err := evaluationRepo.Find(map[string]interface{}{
"targetUserId": param.UserId,
"types": domain.EvaluationSelf,
"beginTime": nowTime,
"endTime": nowTime,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "周期综合自评"+err.Error())
}
resp := map[string]interface{}{
"needNotify": false,
"content": "",
}
if len(evaluationList) == 0 {
return resp, nil
}
messageRepo := factory.CreateMessagePersonalRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
newMessageList := []domain.MessagePersonal{}
for _, val := range evaluationList {
payload := map[string]string{
"id": strconv.Itoa(val.Id),
}
payloadStr, _ := json.Marshal(payload)
cnt, _, err := messageRepo.Find(map[string]interface{}{
"types": domain.MessageTypesOther,
"targetUserId": param.UserId,
"payload": string(payloadStr),
"limit": 1,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "检查自评消息记录"+err.Error())
}
if cnt == 0 {
newMessageList = append(newMessageList, domain.MessagePersonal{
Id: 0,
Types: domain.MessageTypesOther,
TargetUserId: val.TargetUser.UserId,
ReadFlag: domain.MessageIsRead,
Title: fmt.Sprintf("%s综合自评已开启,请前往进行评估.", val.CycleName),
Content: fmt.Sprintf("%s综合自评已开启,请前往进行评估.", val.CycleName),
CreatedAt: time.Time{},
UpdatedAt: time.Time{},
Payload: string(payloadStr),
})
resp["needNotify"] = true
resp["content"] = fmt.Sprintf("%s综合自评已开启,请前往进行评估.", val.CycleName)
break
}
}
for i := range newMessageList {
err = messageRepo.Save(&newMessageList[i])
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存自评消息记录"+err.Error())
}
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
return resp, nil
}
// 获取关于任务里程碑异常的消息
// 每日一次
func (srv *MessagePersonalService) TodayMessageTaskStageAnomaly(param *command.GetUserMessageCommand) (map[string]interface{}, error) {
return nil, nil
}
// 获取关于任务反馈碑异常的消息
// 每日一次
func (srv *MessagePersonalService) TodayMessageTaskRecordAnomaly(param *command.GetUserMessageCommand) (map[string]interface{}, error) {
return nil, nil
}