sys messaged
This commit is contained in:
@@ -212,7 +212,9 @@ func GetMessageGroupByUser(ctx *jxcontext.Context, userID string) (messageGroupR
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
)
|
||||
messageGroups, err := dao.GetMessageGroups(db, userID, 0, 0, true, "")
|
||||
messageGroups, err := dao.GetMessageGroups(db, "", model.SysGroupID, 0, false, "")
|
||||
messageGroups2, err := dao.GetMessageGroups(db, userID, 0, 0, true, "")
|
||||
messageGroups = append(messageGroups, messageGroups2...)
|
||||
messageGroupMembers, err := dao.GetMessageGroupMembers(db, 0, 0, userID)
|
||||
for _, v := range messageGroupMembers {
|
||||
if messageGroupList, err := dao.GetMessageGroups(db, "", v.GroupID, 0, false, ""); err == nil {
|
||||
@@ -374,3 +376,23 @@ func DeleteMessageGroup(ctx *jxcontext.Context, groupID int, userID string) (err
|
||||
}
|
||||
return errCode, err
|
||||
}
|
||||
|
||||
func SendSysMessage(ctx *jxcontext.Context, imMessageRecord *model.ImMessageRecord) (err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
userID = imMessageRecord.UserID
|
||||
)
|
||||
if userID == "" {
|
||||
return fmt.Errorf("系统用户不存在!")
|
||||
}
|
||||
user, err := dao.GetUserByID(db, "user_id", userID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if user.Type != model.UserTypeBoss {
|
||||
return fmt.Errorf("抱歉只有系统管理员才能发系统消息!")
|
||||
}
|
||||
dao.WrapAddIDCULDEntity(imMessageRecord, ctx.GetUserName())
|
||||
err = dao.CreateEntity(db, imMessageRecord)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ func GetOperateEvents(db *DaoDB, name string, apiFunctions []string, operateType
|
||||
return operateEventExt, totalCount, err
|
||||
}
|
||||
|
||||
func GetImMessageRecord(db *DaoDB, groupID int, userID string, storeID, vendorID, offset, pageSize int) (pagedInfo *model.PagedInfo, err error) {
|
||||
func GetImMessageRecord(db *DaoDB, groupID int, userID string, storeID, vendorID int, fromTime, toTime time.Time, offset, pageSize int) (pagedInfo *model.PagedInfo, err error) {
|
||||
var msg []*model.ImMessageRecord
|
||||
sql := `
|
||||
SELECT SQL_CALC_FOUND_ROWS *
|
||||
@@ -168,6 +168,14 @@ func GetImMessageRecord(db *DaoDB, groupID int, userID string, storeID, vendorID
|
||||
sql += " AND vendor_id = ?"
|
||||
sqlParams = append(sqlParams, vendorID)
|
||||
}
|
||||
if fromTime != utils.ZeroTimeValue {
|
||||
sql += " AND created_at >= ?"
|
||||
sqlParams = append(sqlParams, fromTime)
|
||||
}
|
||||
if toTime != utils.ZeroTimeValue {
|
||||
sql += " AND created_at <= ?"
|
||||
sqlParams = append(sqlParams, toTime)
|
||||
}
|
||||
sql += `
|
||||
ORDER BY created_at DESC
|
||||
LIMIT ? OFFSET ?
|
||||
|
||||
@@ -2,6 +2,10 @@ package model
|
||||
|
||||
import "time"
|
||||
|
||||
const (
|
||||
SysGroupID = 666666
|
||||
)
|
||||
|
||||
type OperateEvent struct {
|
||||
ID int64 `orm:"column(id)" json:"id"`
|
||||
CreatedAt time.Time `orm:"auto_now_add;type(datetime)" json:"createdAt"`
|
||||
|
||||
@@ -174,6 +174,8 @@ func handleMessages() {
|
||||
// @Description 查询聊天记录
|
||||
// @Param token header string true "认证token"
|
||||
// @Param groupID query int true "组ID"
|
||||
// @Param fromTime query string false "开始时间"
|
||||
// @Param toTime query string false "结束时间"
|
||||
// @Param offset query int false "门店列表起始序号(以0开始,缺省为0)"
|
||||
// @Param pageSize query int false "门店列表页大小(缺省为50,-1表示全部)"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
@@ -181,7 +183,24 @@ func handleMessages() {
|
||||
// @router /GetImMessageRecord [get]
|
||||
func (c *EventController) GetImMessageRecord() {
|
||||
c.callGetImMessageRecord(func(params *tEventGetImMessageRecordParams) (retVal interface{}, errCode string, err error) {
|
||||
retVal, err = dao.GetImMessageRecord(dao.GetDB(), params.GroupID, "", 0, -1, params.Offset, params.PageSize)
|
||||
retVal, err = dao.GetImMessageRecord(dao.GetDB(), params.GroupID, "", 0, -1, utils.Str2Time(params.FromTime), utils.Str2Time(params.ToTime), params.Offset, params.PageSize)
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
// @Title 发送聊天消息(限定系统消息)
|
||||
// @Description 发送聊天消息(限定系统消息)
|
||||
// @Param token header string true "认证token"
|
||||
// @Param payload formData string true "immessageRecord 类型"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /SendSysMessage [post]
|
||||
func (c *EventController) SendSysMessage() {
|
||||
c.callSendSysMessage(func(params *tEventSendSysMessageParams) (retVal interface{}, errCode string, err error) {
|
||||
var imMessageRecord *model.ImMessageRecord
|
||||
if err = jxutils.Strings2Objs(params.Payload, &imMessageRecord); err == nil {
|
||||
err = event.SendSysMessage(params.Ctx, imMessageRecord)
|
||||
}
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
@@ -268,6 +268,15 @@ func init() {
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:EventController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:EventController"],
|
||||
beego.ControllerComments{
|
||||
Method: "SendSysMessage",
|
||||
Router: `/SendSysMessage`,
|
||||
AllowHTTPMethods: []string{"post"},
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:EventController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:EventController"],
|
||||
beego.ControllerComments{
|
||||
Method: "TestWebsocket",
|
||||
|
||||
Reference in New Issue
Block a user