作者 郑周

1. 消息列表 样式

... ... @@ -16,7 +16,7 @@ info(
service Core {
@doc "系统消息"
@handler miniSystem
post /mini/message/system (MessageSystemRequest) returns (MessageBusinessResponse)
post /mini/message/system (MessageSystemRequest) returns (MessageSystemResponse)
@doc "业务消息"
@handler miniBusiness
... ... @@ -37,6 +37,7 @@ type (
Type int `json:"type"` // 系统分类
Title string `json:"title"` // 标题
Content string `json:"content"` // 内容
CreatedAt int64 `json:"createdAt"` // 创建时间
}
MessageBusinessRequest struct {
... ...
package message
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
... ... @@ -19,10 +20,11 @@ func MiniSystemHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
l := message.NewMiniSystemLogic(r.Context(), svcCtx)
resp, err := l.MiniSystem(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
result.HttpResult(r, w, resp, err)
//if err != nil {
// httpx.ErrorCtx(r.Context(), w, err)
//} else {
// httpx.OkJsonCtx(r.Context(), w, resp)
//}
}
}
... ...
... ... @@ -2,11 +2,10 @@ package message
import (
"context"
"github.com/zeromicro/go-zero/core/logx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
)
type MiniSystemLogic struct {
... ... @@ -23,8 +22,37 @@ func NewMiniSystemLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniSy
}
}
func (l *MiniSystemLogic) MiniSystem(req *types.MessageSystemRequest) (resp *types.MessageBusinessResponse, err error) {
// todo: add your logic here and delete this line
func (l *MiniSystemLogic) MiniSystem(req *types.MessageSystemRequest) (resp *types.MessageSystemResponse, err error) {
queryOptions := domain.NewQueryOptions().WithOffsetLimit(req.Page, req.Size)
total, list, err := l.svcCtx.MessageSystemRepository.Find(l.ctx, l.svcCtx.DefaultDBConn(), queryOptions)
if err != nil {
return nil, err
}
resp = &types.MessageSystemResponse{}
resp.Total = total
resp.List = make([]types.MessageSystemItem, 0)
for _, item := range list {
to := types.MessageSystemItem{
Id: item.Id,
Type: item.Type,
Title: item.Title,
Content: item.Content,
CreatedAt: item.CreatedAt,
}
resp.List = append(resp.List, to)
}
return resp, nil
}
return
func (l *MiniSystemLogic) CreateMessage(dm *domain.MessageSystem) error {
_, err := l.svcCtx.MessageSystemRepository.Insert(l.ctx, l.svcCtx.DefaultDBConn(), dm)
l.Debugf("")
return err
}
//// CreateSystemMessage 生成一条信息
//func CreateSystemMessage(ctx context.Context, svcCtx *svc.ServiceContext, dm *domain.MessageSystem) error {
// l := NewMiniSystemLogic(ctx, svcCtx)
// err := l.CreateMessage(dm)
// return err
//}
... ...
... ... @@ -22,10 +22,11 @@ type MessageSystemResponse struct {
}
type MessageSystemItem struct {
Id int64 `json:"id"` // ID
Type int `json:"type"` // 系统分类
Title string `json:"title"` // 标题
Content string `json:"content"` // 内容
Id int64 `json:"id"` // ID
Type int `json:"type"` // 系统分类
Title string `json:"title"` // 标题
Content string `json:"content"` // 内容
CreatedAt int64 `json:"createdAt"` // 创建时间
}
type MessageBusinessRequest struct {
... ...
package db
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/models"
"gorm.io/gorm"
)
func Migrate(db *gorm.DB) {
db.AutoMigrate()
_ = db.AutoMigrate(models.MessageSystem{}, models.MessageBusiness{})
}
... ...
... ... @@ -5,16 +5,17 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gorm.io/gorm"
"gorm.io/plugin/soft_delete"
"time"
)
// MessageSystem 消息中心-系统消息
type MessageSystem struct {
Id int64 // 唯一标识
CompanyId int64 `json:"companyId"` // 公司ID
RecipientId int64 `json:"recipientId"` // 接收者ID
Type int `json:"type"` // 系统分类(0待定、1业务正常通知、2业务异常通知)
Title string `json:"title"` // 标题
Content string `json:"content"` // 内容
CompanyId int64 `json:"companyId"` // 公司ID
RecipientId int64 `json:"recipientId"` // 接收者ID
Type int `json:"type"` // 系统分类(0待定、1业务正常通知、2业务异常通知)
Title string `json:"title,omitempty"` // 标题
Content string `json:"content,omitempty"` // 内容
CreatedAt int64 `json:",omitempty"`
UpdatedAt int64 `json:",omitempty"`
DeletedAt int64 `json:",omitempty"`
... ... @@ -27,13 +28,13 @@ func (m *MessageSystem) TableName() string {
}
func (m *MessageSystem) BeforeCreate(tx *gorm.DB) (err error) {
// m.CreatedAt = time.Now().Unix()
// m.UpdatedAt = time.Now().Unix()
m.CreatedAt = time.Now().Unix()
m.UpdatedAt = time.Now().Unix()
return
}
func (m *MessageSystem) BeforeUpdate(tx *gorm.DB) (err error) {
// m.UpdatedAt = time.Now().Unix()
m.UpdatedAt = time.Now().Unix()
return
}
... ...
... ... @@ -120,7 +120,7 @@ func (repository *MessageSystemRepository) Find(ctx context.Context, conn transa
total int64
)
queryFunc := func() (interface{}, error) {
tx = tx.Model(&ms).Order("id desc")
tx = tx.Model(&ms).Order("created_at desc") // 创建时间降序
if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
return dms, tx.Error
}
... ...
... ... @@ -21,8 +21,8 @@ type MessageSystem struct {
type MsgSystemType int
const (
MsgTypeNormal MsgSystemType = 0
MsgTypeAbnormal MsgSystemType = 1
MsgTypeNormal MsgSystemType = 1
MsgTypeAbnormal MsgSystemType = 2
)
type MessageSystemRepository interface {
... ...