Merge branch 'dev-tangxvhui' into test
正在显示
10 个修改的文件
包含
246 行增加
和
48 行删除
@@ -208,3 +208,11 @@ func CreateLogSmsRepository(options map[string]interface{}) domain.LogSmsReposit | @@ -208,3 +208,11 @@ func CreateLogSmsRepository(options map[string]interface{}) domain.LogSmsReposit | ||
208 | } | 208 | } |
209 | return repository.NewLogSmsRepository(transactionContext) | 209 | return repository.NewLogSmsRepository(transactionContext) |
210 | } | 210 | } |
211 | + | ||
212 | +func CreateMessagePersonalRepository(options map[string]interface{}) domain.MessagePersonalRepository { | ||
213 | + var transactionContext *pg.TransactionContext | ||
214 | + if value, ok := options["transactionContext"]; ok { | ||
215 | + transactionContext = value.(*pg.TransactionContext) | ||
216 | + } | ||
217 | + return repository.NewMessagePersonalRepository(transactionContext) | ||
218 | +} |
1 | -package notify | ||
2 | - | ||
3 | -import ( | ||
4 | - "github.com/linmadan/egglib-go/core/application" | ||
5 | - "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory" | ||
6 | - "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/notify/command" | ||
7 | -) | ||
8 | - | ||
9 | -// 个人信息提示 | ||
10 | - | ||
11 | -type MessagePersonalService struct { | ||
12 | -} | ||
13 | - | ||
14 | -func NewMessagePersonalService() *MessagePersonalService { | ||
15 | - newService := &MessagePersonalService{} | ||
16 | - return newService | ||
17 | -} | ||
18 | - | ||
19 | -// 获取今天的周期综合自评消息提示 | ||
20 | -func (srv *MessagePersonalService) TodayMessageSummaryEvaluationSelf(param *command.GetUserMessageCommand) (interface{}, error) { | ||
21 | - transactionContext, err := factory.CreateTransactionContext(nil) | ||
22 | - if err != nil { | ||
23 | - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
24 | - } | ||
25 | - if err := transactionContext.StartTransaction(); err != nil { | ||
26 | - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
27 | - } | ||
28 | - defer func() { | ||
29 | - _ = transactionContext.RollbackTransaction() | ||
30 | - }() | ||
31 | - // nowTime := time.Now() | ||
32 | - | ||
33 | - if err := transactionContext.CommitTransaction(); err != nil { | ||
34 | - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
35 | - } | ||
36 | - return nil, nil | ||
37 | -} |
1 | +package notify | ||
2 | + | ||
3 | +import ( | ||
4 | + "encoding/json" | ||
5 | + "fmt" | ||
6 | + "strconv" | ||
7 | + "time" | ||
8 | + | ||
9 | + "github.com/linmadan/egglib-go/core/application" | ||
10 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory" | ||
11 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/notify/command" | ||
12 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" | ||
13 | +) | ||
14 | + | ||
15 | +// 个人信息提示 | ||
16 | + | ||
17 | +type MessagePersonalService struct { | ||
18 | +} | ||
19 | + | ||
20 | +func NewMessagePersonalService() *MessagePersonalService { | ||
21 | + newService := &MessagePersonalService{} | ||
22 | + return newService | ||
23 | +} | ||
24 | + | ||
25 | +// 获取今天的周期综合自评消息提示 | ||
26 | +func (srv *MessagePersonalService) TodayMessageSummaryEvaluationSelf(param *command.GetUserMessageCommand) (map[string]interface{}, error) { | ||
27 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
28 | + if err != nil { | ||
29 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
30 | + } | ||
31 | + if err := transactionContext.StartTransaction(); err != nil { | ||
32 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
33 | + } | ||
34 | + defer func() { | ||
35 | + _ = transactionContext.RollbackTransaction() | ||
36 | + }() | ||
37 | + | ||
38 | + nowTime := time.Now() | ||
39 | + evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{ | ||
40 | + "transactionContext": transactionContext, | ||
41 | + }) | ||
42 | + _, evaluationList, err := evaluationRepo.Find(map[string]interface{}{ | ||
43 | + "targetUserId": param.UserId, | ||
44 | + "types": domain.EvaluationSelf, | ||
45 | + "beginTime": nowTime, | ||
46 | + "endTime": nowTime, | ||
47 | + }) | ||
48 | + if err != nil { | ||
49 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "周期综合自评"+err.Error()) | ||
50 | + } | ||
51 | + resp := map[string]interface{}{ | ||
52 | + "needNotify": false, | ||
53 | + "content": "", | ||
54 | + } | ||
55 | + if len(evaluationList) == 0 { | ||
56 | + return resp, nil | ||
57 | + } | ||
58 | + | ||
59 | + messageRepo := factory.CreateMessagePersonalRepository(map[string]interface{}{ | ||
60 | + "transactionContext": transactionContext, | ||
61 | + }) | ||
62 | + newMessageList := []domain.MessagePersonal{} | ||
63 | + for _, val := range evaluationList { | ||
64 | + payload := map[string]string{ | ||
65 | + "id": strconv.Itoa(val.Id), | ||
66 | + } | ||
67 | + payloadStr, _ := json.Marshal(payload) | ||
68 | + cnt, _, err := messageRepo.Find(map[string]interface{}{ | ||
69 | + "types": domain.MessageTypesOther, | ||
70 | + "targetUserId": param.UserId, | ||
71 | + "playload": string(payloadStr), | ||
72 | + "limit": 1, | ||
73 | + }) | ||
74 | + if err != nil { | ||
75 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "检查自评消息记录"+err.Error()) | ||
76 | + } | ||
77 | + if cnt == 0 { | ||
78 | + newMessageList = append(newMessageList, domain.MessagePersonal{ | ||
79 | + Id: 0, | ||
80 | + Types: domain.MessageTypesOther, | ||
81 | + TargetUserId: val.TargetUser.UserId, | ||
82 | + ReadFlag: domain.MessageIsRead, | ||
83 | + Title: fmt.Sprintf("%s综合自评已开启,请前往进行评估.", val.CycleName), | ||
84 | + Content: fmt.Sprintf("%s综合自评已开启,请前往进行评估.", val.CycleName), | ||
85 | + CreatedAt: time.Time{}, | ||
86 | + UpdatedAt: time.Time{}, | ||
87 | + Payload: string(payloadStr), | ||
88 | + }) | ||
89 | + resp["needNotify"] = true | ||
90 | + resp["content"] = fmt.Sprintf("%s综合自评已开启,请前往进行评估.", val.CycleName) | ||
91 | + break | ||
92 | + } | ||
93 | + } | ||
94 | + for i := range newMessageList { | ||
95 | + err = messageRepo.Save(&newMessageList[i]) | ||
96 | + if err != nil { | ||
97 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存自评消息记录"+err.Error()) | ||
98 | + } | ||
99 | + } | ||
100 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
101 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
102 | + } | ||
103 | + return resp, nil | ||
104 | +} |
@@ -4,15 +4,15 @@ import "time" | @@ -4,15 +4,15 @@ import "time" | ||
4 | 4 | ||
5 | // MessagePersonal 个人的消息提示 | 5 | // MessagePersonal 个人的消息提示 |
6 | type MessagePersonal struct { | 6 | type MessagePersonal struct { |
7 | - Id int // | ||
8 | - Types string //消息类型 | ||
9 | - TargetUserId int //消息指向的用户 | ||
10 | - ReadFlag MessageReadFlag //1:已读、2:未读 | ||
11 | - Title string //消息的标题 | ||
12 | - Content string //消息的内容 | ||
13 | - CreatedAt time.Time | ||
14 | - UpdatedAt time.Time | ||
15 | - Payload string //消息的额外承载的数据 | 7 | + Id int `json:"id"` // |
8 | + Types MessageTypes `json:"types"` //消息类型 | ||
9 | + TargetUserId int `json:"targetUserId"` //消息指向的用户 | ||
10 | + ReadFlag MessageReadFlag `json:"readFlag"` //1:已读、2:未读 | ||
11 | + Title string `json:"title"` //消息的标题 | ||
12 | + Content string `json:"content"` //消息的内容 | ||
13 | + CreatedAt time.Time `json:"createdAt"` | ||
14 | + UpdatedAt time.Time `json:"updatedAt"` | ||
15 | + Payload string `json:"payload"` //消息的额外承载的数据 | ||
16 | } | 16 | } |
17 | 17 | ||
18 | type MessageTypes string | 18 | type MessageTypes string |
@@ -27,3 +27,8 @@ const ( | @@ -27,3 +27,8 @@ const ( | ||
27 | MessageIsRead MessageReadFlag = "read" | 27 | MessageIsRead MessageReadFlag = "read" |
28 | MessageUnread MessageReadFlag = "unread" | 28 | MessageUnread MessageReadFlag = "unread" |
29 | ) | 29 | ) |
30 | + | ||
31 | +type MessagePersonalRepository interface { | ||
32 | + Save(param *MessagePersonal) error | ||
33 | + Find(queryOptions map[string]interface{}) (int, []*MessagePersonal, error) | ||
34 | +} |
@@ -9,8 +9,8 @@ import ( | @@ -9,8 +9,8 @@ import ( | ||
9 | func TestGenerateToken(t *testing.T) { | 9 | func TestGenerateToken(t *testing.T) { |
10 | ut := UserAuth{ | 10 | ut := UserAuth{ |
11 | CompanyId: 8, | 11 | CompanyId: 8, |
12 | - UserId: 3435675157551872, | ||
13 | - Phone: "18060823798", | 12 | + UserId: 3422181461696000, |
13 | + Phone: "13066667702", | ||
14 | PlatformId: 29, | 14 | PlatformId: 29, |
15 | AdminType: 1, | 15 | AdminType: 1, |
16 | } | 16 | } |
@@ -51,6 +51,7 @@ func init() { | @@ -51,6 +51,7 @@ func init() { | ||
51 | &models.SummaryEvaluationValue{}, | 51 | &models.SummaryEvaluationValue{}, |
52 | &models.Permission{}, | 52 | &models.Permission{}, |
53 | &models.LogSms{}, | 53 | &models.LogSms{}, |
54 | + &models.MessagePersonal{}, | ||
54 | } | 55 | } |
55 | for _, model := range tables { | 56 | for _, model := range tables { |
56 | err := DB.Model(model).CreateTable(&orm.CreateTableOptions{ | 57 | err := DB.Model(model).CreateTable(&orm.CreateTableOptions{ |
1 | +package models | ||
2 | + | ||
3 | +import "time" | ||
4 | + | ||
5 | +// MessagePersonal 记录个人的提示消息 | ||
6 | +type MessagePersonal struct { | ||
7 | + tableName struct{} `comment:"记录个人的提示消息" pg:"message_personal"` | ||
8 | + Id int `pg:"id,pk"` // | ||
9 | + Types string `pg:"types"` //消息类型 | ||
10 | + TargetUserId int `pg:"target_user_id"` //消息指向的用户 | ||
11 | + ReadFlag string `pg:"read_flag"` //1:已读、2:未读 | ||
12 | + Title string `pg:"title"` //消息的标题 | ||
13 | + Content string `pg:"content"` //消息的内容 | ||
14 | + CreatedAt time.Time `pg:"created_at"` | ||
15 | + UpdatedAt time.Time `pg:"updated_at"` | ||
16 | + Payload string `pg:"payload,type:jsonb"` //消息的额外承载的数据 | ||
17 | +} |
1 | +package repository | ||
2 | + | ||
3 | +import ( | ||
4 | + "time" | ||
5 | + | ||
6 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
7 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" | ||
8 | + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/pg/models" | ||
9 | +) | ||
10 | + | ||
11 | +type MessagePersonalRepository struct { | ||
12 | + transactionContext *pgTransaction.TransactionContext | ||
13 | +} | ||
14 | + | ||
15 | +var _ domain.MessagePersonalRepository = (*MessagePersonalRepository)(nil) | ||
16 | + | ||
17 | +func NewMessagePersonalRepository(tx *pgTransaction.TransactionContext) *MessagePersonalRepository { | ||
18 | + return &MessagePersonalRepository{ | ||
19 | + transactionContext: tx, | ||
20 | + } | ||
21 | +} | ||
22 | + | ||
23 | +func (repo *MessagePersonalRepository) TransformToDomain(param *models.MessagePersonal) *domain.MessagePersonal { | ||
24 | + return &domain.MessagePersonal{ | ||
25 | + Id: param.Id, | ||
26 | + Types: domain.MessageTypes(param.Types), | ||
27 | + TargetUserId: param.TargetUserId, | ||
28 | + ReadFlag: domain.MessageReadFlag(param.ReadFlag), | ||
29 | + Title: param.Title, | ||
30 | + Content: param.Content, | ||
31 | + Payload: param.Payload, | ||
32 | + UpdatedAt: param.UpdatedAt, | ||
33 | + CreatedAt: param.CreatedAt, | ||
34 | + } | ||
35 | +} | ||
36 | + | ||
37 | +func (repo *MessagePersonalRepository) Save(param *domain.MessagePersonal) error { | ||
38 | + message := &models.MessagePersonal{ | ||
39 | + Id: param.Id, | ||
40 | + Types: string(param.Types), | ||
41 | + TargetUserId: param.TargetUserId, | ||
42 | + ReadFlag: string(param.ReadFlag), | ||
43 | + Title: param.Title, | ||
44 | + Content: param.Content, | ||
45 | + Payload: param.Payload, | ||
46 | + UpdatedAt: time.Now(), | ||
47 | + CreatedAt: param.CreatedAt, | ||
48 | + } | ||
49 | + tx := repo.transactionContext.PgTx | ||
50 | + if message.Id == 0 { | ||
51 | + message.CreatedAt = time.Now() | ||
52 | + _, err := tx.Model(message).Insert() | ||
53 | + | ||
54 | + return err | ||
55 | + } | ||
56 | + _, err := tx.Model(message).WherePK().Update() | ||
57 | + return err | ||
58 | +} | ||
59 | + | ||
60 | +func (repo *MessagePersonalRepository) Find(param map[string]interface{}) (int, []*domain.MessagePersonal, error) { | ||
61 | + tx := repo.transactionContext.PgTx | ||
62 | + var m []*models.MessagePersonal | ||
63 | + query := tx.Model(&m).Limit(20) | ||
64 | + if v, ok := param["targetUserId"]; ok { | ||
65 | + query.Where("target_user_id=?", v) | ||
66 | + } | ||
67 | + if v, ok := param["types"]; ok { | ||
68 | + query.Where("types=?", v) | ||
69 | + } | ||
70 | + if v, ok := param["playload"]; ok { | ||
71 | + query.Where("playload @>?", v) | ||
72 | + } | ||
73 | + query.Order("id desc") | ||
74 | + count, err := query.SelectAndCount() | ||
75 | + if err != nil { | ||
76 | + return 0, nil, err | ||
77 | + } | ||
78 | + var datas []*domain.MessagePersonal | ||
79 | + for _, v := range m { | ||
80 | + d := repo.TransformToDomain(v) | ||
81 | + datas = append(datas, d) | ||
82 | + } | ||
83 | + return count, datas, nil | ||
84 | + | ||
85 | +} |
1 | +package controllers |
sql/2023-03-24.sql
0 → 100644
1 | +-- summary_evaluation_value表添加字段 | ||
2 | +ALTER TABLE public.summary_evaluation_value | ||
3 | + ADD executor jsonb NULL; | ||
4 | + | ||
5 | +-- 初始化旧数据的summary_evaluation_value.executor | ||
6 | +UPDATE | ||
7 | + public.summary_evaluation_value | ||
8 | +SET | ||
9 | + executor = public.summary_evaluation.executor | ||
10 | +FROM | ||
11 | + public.summary_evaluation | ||
12 | +WHERE | ||
13 | + public.summary_evaluation_value.summary_evaluation_id = public.summary_evaluation.id; | ||
14 | + |
-
请 注册 或 登录 后发表评论