feat: add hosted message
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"message-nest/pkg/util"
|
||||
)
|
||||
|
||||
type HostedMessage struct {
|
||||
ID int `gorm:"primaryKey" json:"id" `
|
||||
Title string `json:"title" gorm:"type:text ;"`
|
||||
Content string `json:"content" gorm:"type:text ;"`
|
||||
Type string `json:"type" gorm:"type:varchar(100) ;default:'';index"`
|
||||
|
||||
CreatedAt util.Time `json:"created_on" gorm:"column:created_on;autoCreateTime "`
|
||||
UpdatedAt util.Time `json:"modified_on" gorm:"column:modified_on;autoUpdateTime ;"`
|
||||
}
|
||||
|
||||
// Add 添加托管消息
|
||||
func (message *HostedMessage) Add() error {
|
||||
if err := db.Create(&message).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// 托管消息的结果
|
||||
type HostMessageResult struct {
|
||||
ID int `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Content string `json:"content"`
|
||||
Type string `json:"type"`
|
||||
CreatedOn util.Time `json:"created_on"`
|
||||
ModifiedOn util.Time `json:"modified_on"`
|
||||
}
|
||||
|
||||
// GetHostMessages 获取所有托管消息记录
|
||||
func GetHostMessages(pageNum int, pageSize int, text string, maps map[string]interface{}) ([]HostMessageResult, error) {
|
||||
var datas []HostMessageResult
|
||||
hostMessageT := GetSchema(HostedMessage{})
|
||||
|
||||
query := db.Table(hostMessageT)
|
||||
|
||||
//dayVal, ok := maps["day_created_on"]
|
||||
//if ok {
|
||||
// delete(maps, "day_created_on")
|
||||
// query = query.Where(fmt.Sprintf("DATE(%s.created_on) = ?", logt), dayVal)
|
||||
//}
|
||||
|
||||
query = query.Where(maps)
|
||||
if text != "" {
|
||||
query = query.Where("title like ? or content like ?", fmt.Sprintf("%%%s%%", text), fmt.Sprintf("%%%s%%", text))
|
||||
}
|
||||
query = query.Order("created_on DESC")
|
||||
if pageSize > 0 || pageNum > 0 {
|
||||
query = query.Offset(pageNum).Limit(pageSize)
|
||||
}
|
||||
query.Scan(&datas)
|
||||
|
||||
return datas, nil
|
||||
}
|
||||
|
||||
// GetHostMessagesTotal 获取托管消息总数
|
||||
func GetHostMessagesTotal(text string, maps map[string]interface{}) (int64, error) {
|
||||
var total int64
|
||||
hostMessageT := GetSchema(HostedMessage{})
|
||||
|
||||
query := db.Table(hostMessageT)
|
||||
|
||||
//dayVal, ok := maps["day_created_on"]
|
||||
//if ok {
|
||||
// delete(maps, "day_created_on")
|
||||
// query = query.Where(fmt.Sprintf("DATE(%s.created_on) = ?", logt), dayVal)
|
||||
//}
|
||||
|
||||
query = query.Where(maps)
|
||||
if text != "" {
|
||||
query = query.Where("title like ? or content like ?", fmt.Sprintf("%%%s%%", text), fmt.Sprintf("%%%s%%", text))
|
||||
}
|
||||
query.Count(&total)
|
||||
return total, nil
|
||||
}
|
||||
@@ -34,6 +34,10 @@ type InsQyWeiXinConfig struct {
|
||||
type InsCustomConfig struct {
|
||||
}
|
||||
|
||||
// InsMessageNestConfig 实例里面的托管消息config
|
||||
type InsMessageNestConfig struct {
|
||||
}
|
||||
|
||||
// ManyAddTaskIns 批量添加实例
|
||||
func ManyAddTaskIns(taskIns []SendTasksIns) error {
|
||||
tx := db.Begin()
|
||||
|
||||
@@ -119,10 +119,11 @@ func DeleteOutDateLogs(keepNum int) (int, error) {
|
||||
}
|
||||
|
||||
type StatisticData struct {
|
||||
TodaySuccNum int `json:"today_succ_num"`
|
||||
TodayFailedNum int `json:"today_failed_num"`
|
||||
TodayTotalNum int `json:"today_total_num"`
|
||||
MessageTotalNum int `json:"message_total_num"`
|
||||
TodaySuccNum int `json:"today_succ_num"`
|
||||
TodayFailedNum int `json:"today_failed_num"`
|
||||
TodayTotalNum int `json:"today_total_num"`
|
||||
MessageTotalNum int `json:"message_total_num"`
|
||||
HostedMessageTotalNum int `json:"hosted_message_total_num"`
|
||||
|
||||
LatestSendData []LatestSendData `json:"latest_send_data" gorm:"many2many:latest_send_data;"`
|
||||
WayCateData []WayCateData `json:"way_cate_data" gorm:"many2many:way_cate_data;"`
|
||||
@@ -148,6 +149,7 @@ func GetStatisticData() (StatisticData, error) {
|
||||
var wayCateData []WayCateData
|
||||
logt := GetSchema(SendTasksLogs{})
|
||||
inst := GetSchema(SendTasksIns{})
|
||||
hostedt := GetSchema(HostedMessage{})
|
||||
wayst := GetSchema(SendWays{})
|
||||
currDay := util.GetNowTimeStr()[:10]
|
||||
|
||||
@@ -166,6 +168,10 @@ func GetStatisticData() (StatisticData, error) {
|
||||
totalQuery := db.Table(logt).Select(`COUNT(*) AS message_total_num`)
|
||||
totalQuery.Take(&statistic)
|
||||
|
||||
// 托管消息统计数据
|
||||
hostedMessageTotalQuery := db.Table(hostedt).Select(`COUNT(*) AS hosted_message_total_num`)
|
||||
hostedMessageTotalQuery.Take(&statistic)
|
||||
|
||||
// 最近30天数据
|
||||
days := 30
|
||||
now := util.GetNowTime()
|
||||
|
||||
Reference in New Issue
Block a user