Merge branch 'dev' of http://gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss into dev
正在显示
8 个修改的文件
包含
62 行增加
和
27 行删除
@@ -16,7 +16,7 @@ info( | @@ -16,7 +16,7 @@ info( | ||
16 | service Core { | 16 | service Core { |
17 | @doc "系统消息" | 17 | @doc "系统消息" |
18 | @handler miniSystem | 18 | @handler miniSystem |
19 | - post /mini/message/system (MessageSystemRequest) returns (MessageBusinessResponse) | 19 | + post /mini/message/system (MessageSystemRequest) returns (MessageSystemResponse) |
20 | 20 | ||
21 | @doc "业务消息" | 21 | @doc "业务消息" |
22 | @handler miniBusiness | 22 | @handler miniBusiness |
@@ -37,6 +37,7 @@ type ( | @@ -37,6 +37,7 @@ type ( | ||
37 | Type int `json:"type"` // 系统分类 | 37 | Type int `json:"type"` // 系统分类 |
38 | Title string `json:"title"` // 标题 | 38 | Title string `json:"title"` // 标题 |
39 | Content string `json:"content"` // 内容 | 39 | Content string `json:"content"` // 内容 |
40 | + CreatedAt int64 `json:"createdAt"` // 创建时间 | ||
40 | } | 41 | } |
41 | 42 | ||
42 | MessageBusinessRequest struct { | 43 | MessageBusinessRequest struct { |
1 | package message | 1 | package message |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result" | ||
4 | "net/http" | 5 | "net/http" |
5 | 6 | ||
6 | "github.com/zeromicro/go-zero/rest/httpx" | 7 | "github.com/zeromicro/go-zero/rest/httpx" |
@@ -19,10 +20,11 @@ func MiniSystemHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | @@ -19,10 +20,11 @@ func MiniSystemHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
19 | 20 | ||
20 | l := message.NewMiniSystemLogic(r.Context(), svcCtx) | 21 | l := message.NewMiniSystemLogic(r.Context(), svcCtx) |
21 | resp, err := l.MiniSystem(&req) | 22 | resp, err := l.MiniSystem(&req) |
22 | - if err != nil { | ||
23 | - httpx.ErrorCtx(r.Context(), w, err) | ||
24 | - } else { | ||
25 | - httpx.OkJsonCtx(r.Context(), w, resp) | ||
26 | - } | 23 | + result.HttpResult(r, w, resp, err) |
24 | + //if err != nil { | ||
25 | + // httpx.ErrorCtx(r.Context(), w, err) | ||
26 | + //} else { | ||
27 | + // httpx.OkJsonCtx(r.Context(), w, resp) | ||
28 | + //} | ||
27 | } | 29 | } |
28 | } | 30 | } |
@@ -2,11 +2,10 @@ package message | @@ -2,11 +2,10 @@ package message | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "context" | 4 | "context" |
5 | - | 5 | + "github.com/zeromicro/go-zero/core/logx" |
6 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" | 6 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" |
7 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" | 7 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" |
8 | - | ||
9 | - "github.com/zeromicro/go-zero/core/logx" | 8 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" |
10 | ) | 9 | ) |
11 | 10 | ||
12 | type MiniSystemLogic struct { | 11 | type MiniSystemLogic struct { |
@@ -23,8 +22,37 @@ func NewMiniSystemLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniSy | @@ -23,8 +22,37 @@ func NewMiniSystemLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniSy | ||
23 | } | 22 | } |
24 | } | 23 | } |
25 | 24 | ||
26 | -func (l *MiniSystemLogic) MiniSystem(req *types.MessageSystemRequest) (resp *types.MessageBusinessResponse, err error) { | ||
27 | - // todo: add your logic here and delete this line | 25 | +func (l *MiniSystemLogic) MiniSystem(req *types.MessageSystemRequest) (resp *types.MessageSystemResponse, err error) { |
26 | + queryOptions := domain.NewQueryOptions().WithOffsetLimit(req.Page, req.Size) | ||
27 | + total, list, err := l.svcCtx.MessageSystemRepository.Find(l.ctx, l.svcCtx.DefaultDBConn(), queryOptions) | ||
28 | + if err != nil { | ||
29 | + return nil, err | ||
30 | + } | ||
31 | + resp = &types.MessageSystemResponse{} | ||
32 | + resp.Total = total | ||
33 | + resp.List = make([]types.MessageSystemItem, 0) | ||
34 | + for _, item := range list { | ||
35 | + to := types.MessageSystemItem{ | ||
36 | + Id: item.Id, | ||
37 | + Type: item.Type, | ||
38 | + Title: item.Title, | ||
39 | + Content: item.Content, | ||
40 | + CreatedAt: item.CreatedAt, | ||
41 | + } | ||
42 | + resp.List = append(resp.List, to) | ||
43 | + } | ||
44 | + return resp, nil | ||
45 | +} | ||
28 | 46 | ||
29 | - return | 47 | +func (l *MiniSystemLogic) CreateMessage(dm *domain.MessageSystem) error { |
48 | + _, err := l.svcCtx.MessageSystemRepository.Insert(l.ctx, l.svcCtx.DefaultDBConn(), dm) | ||
49 | + l.Debugf("") | ||
50 | + return err | ||
30 | } | 51 | } |
52 | + | ||
53 | +//// CreateSystemMessage 生成一条信息 | ||
54 | +//func CreateSystemMessage(ctx context.Context, svcCtx *svc.ServiceContext, dm *domain.MessageSystem) error { | ||
55 | +// l := NewMiniSystemLogic(ctx, svcCtx) | ||
56 | +// err := l.CreateMessage(dm) | ||
57 | +// return err | ||
58 | +//} |
@@ -22,10 +22,11 @@ type MessageSystemResponse struct { | @@ -22,10 +22,11 @@ type MessageSystemResponse struct { | ||
22 | } | 22 | } |
23 | 23 | ||
24 | type MessageSystemItem struct { | 24 | type MessageSystemItem struct { |
25 | - Id int64 `json:"id"` // ID | ||
26 | - Type int `json:"type"` // 系统分类 | ||
27 | - Title string `json:"title"` // 标题 | ||
28 | - Content string `json:"content"` // 内容 | 25 | + Id int64 `json:"id"` // ID |
26 | + Type int `json:"type"` // 系统分类 | ||
27 | + Title string `json:"title"` // 标题 | ||
28 | + Content string `json:"content"` // 内容 | ||
29 | + CreatedAt int64 `json:"createdAt"` // 创建时间 | ||
29 | } | 30 | } |
30 | 31 | ||
31 | type MessageBusinessRequest struct { | 32 | type MessageBusinessRequest struct { |
@@ -18,6 +18,8 @@ func Migrate(db *gorm.DB) { | @@ -18,6 +18,8 @@ func Migrate(db *gorm.DB) { | ||
18 | &models.Role{}, | 18 | &models.Role{}, |
19 | &models.Company{}, | 19 | &models.Company{}, |
20 | &models.UserFollow{}, | 20 | &models.UserFollow{}, |
21 | + &models.MessageSystem{}, | ||
22 | + &models.MessageBusiness{}, | ||
21 | } | 23 | } |
22 | 24 | ||
23 | db.AutoMigrate(modelsList...) | 25 | db.AutoMigrate(modelsList...) |
@@ -5,16 +5,17 @@ import ( | @@ -5,16 +5,17 @@ import ( | ||
5 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" | 5 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" |
6 | "gorm.io/gorm" | 6 | "gorm.io/gorm" |
7 | "gorm.io/plugin/soft_delete" | 7 | "gorm.io/plugin/soft_delete" |
8 | + "time" | ||
8 | ) | 9 | ) |
9 | 10 | ||
10 | // MessageSystem 消息中心-系统消息 | 11 | // MessageSystem 消息中心-系统消息 |
11 | type MessageSystem struct { | 12 | type MessageSystem struct { |
12 | Id int64 // 唯一标识 | 13 | Id int64 // 唯一标识 |
13 | - CompanyId int64 `json:"companyId"` // 公司ID | ||
14 | - RecipientId int64 `json:"recipientId"` // 接收者ID | ||
15 | - Type int `json:"type"` // 系统分类(0待定、1业务正常通知、2业务异常通知) | ||
16 | - Title string `json:"title"` // 标题 | ||
17 | - Content string `json:"content"` // 内容 | 14 | + CompanyId int64 `json:"companyId"` // 公司ID |
15 | + RecipientId int64 `json:"recipientId"` // 接收者ID | ||
16 | + Type int `json:"type"` // 系统分类(0待定、1业务正常通知、2业务异常通知) | ||
17 | + Title string `json:"title,omitempty"` // 标题 | ||
18 | + Content string `json:"content,omitempty"` // 内容 | ||
18 | CreatedAt int64 `json:",omitempty"` | 19 | CreatedAt int64 `json:",omitempty"` |
19 | UpdatedAt int64 `json:",omitempty"` | 20 | UpdatedAt int64 `json:",omitempty"` |
20 | DeletedAt int64 `json:",omitempty"` | 21 | DeletedAt int64 `json:",omitempty"` |
@@ -27,13 +28,13 @@ func (m *MessageSystem) TableName() string { | @@ -27,13 +28,13 @@ func (m *MessageSystem) TableName() string { | ||
27 | } | 28 | } |
28 | 29 | ||
29 | func (m *MessageSystem) BeforeCreate(tx *gorm.DB) (err error) { | 30 | func (m *MessageSystem) BeforeCreate(tx *gorm.DB) (err error) { |
30 | - // m.CreatedAt = time.Now().Unix() | ||
31 | - // m.UpdatedAt = time.Now().Unix() | 31 | + m.CreatedAt = time.Now().Unix() |
32 | + m.UpdatedAt = time.Now().Unix() | ||
32 | return | 33 | return |
33 | } | 34 | } |
34 | 35 | ||
35 | func (m *MessageSystem) BeforeUpdate(tx *gorm.DB) (err error) { | 36 | func (m *MessageSystem) BeforeUpdate(tx *gorm.DB) (err error) { |
36 | - // m.UpdatedAt = time.Now().Unix() | 37 | + m.UpdatedAt = time.Now().Unix() |
37 | return | 38 | return |
38 | } | 39 | } |
39 | 40 |
@@ -120,7 +120,7 @@ func (repository *MessageSystemRepository) Find(ctx context.Context, conn transa | @@ -120,7 +120,7 @@ func (repository *MessageSystemRepository) Find(ctx context.Context, conn transa | ||
120 | total int64 | 120 | total int64 |
121 | ) | 121 | ) |
122 | queryFunc := func() (interface{}, error) { | 122 | queryFunc := func() (interface{}, error) { |
123 | - tx = tx.Model(&ms).Order("id desc") | 123 | + tx = tx.Model(&ms).Order("created_at desc") // 创建时间降序 |
124 | if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil { | 124 | if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil { |
125 | return dms, tx.Error | 125 | return dms, tx.Error |
126 | } | 126 | } |
@@ -21,8 +21,8 @@ type MessageSystem struct { | @@ -21,8 +21,8 @@ type MessageSystem struct { | ||
21 | type MsgSystemType int | 21 | type MsgSystemType int |
22 | 22 | ||
23 | const ( | 23 | const ( |
24 | - MsgTypeNormal MsgSystemType = 0 | ||
25 | - MsgTypeAbnormal MsgSystemType = 1 | 24 | + MsgTypeNormal MsgSystemType = 1 |
25 | + MsgTypeAbnormal MsgSystemType = 2 | ||
26 | ) | 26 | ) |
27 | 27 | ||
28 | type MessageSystemRepository interface { | 28 | type MessageSystemRepository interface { |
-
请 注册 或 登录 后发表评论