mirror of
https://github.com/bufanyun/hotgo.git
synced 2025-01-23 02:40:23 +08:00
优化服务监控定时器,移除notify
功能包
This commit is contained in:
parent
3df5236623
commit
90d09deeff
@ -1,3 +1,8 @@
|
||||
// Package smslog
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package smslog
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,8 @@
|
||||
// Package pay
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package pay
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,8 @@
|
||||
// Package servmsg
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package servmsg
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,8 @@
|
||||
// Package servmsg
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package servmsg
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,8 @@
|
||||
// Package servmsg
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package servmsg
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,8 @@
|
||||
// Package base
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package base
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,8 @@
|
||||
// Package consts
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package consts
|
||||
|
||||
const (
|
||||
|
@ -1,3 +1,8 @@
|
||||
// Package consts
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package consts
|
||||
|
||||
const (
|
||||
|
@ -1,3 +1,8 @@
|
||||
// Package consts
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package consts
|
||||
|
||||
// 授权分组
|
||||
|
@ -1,3 +1,8 @@
|
||||
// Package consts
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package consts
|
||||
|
||||
// 授权类型
|
||||
|
@ -130,6 +130,8 @@ func (c *cMonitor) NetOnlineList(ctx context.Context, req *monitor.NetOnlineList
|
||||
|
||||
conns := serv.GetClients()
|
||||
if len(conns) == 0 {
|
||||
res = new(monitor.NetOnlineListRes)
|
||||
res.PageRes.Pack(req, 0)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -70,7 +70,7 @@ func (c *cRole) UpdatePermissions(ctx context.Context, req *role.UpdatePermissio
|
||||
// DataScopeSelect 获取数据权限选项
|
||||
func (c *cRole) DataScopeSelect(_ context.Context, _ *role.DataScopeSelectReq) (res *role.DataScopeSelectRes, err error) {
|
||||
res = new(role.DataScopeSelectRes)
|
||||
res.List = consts.DataScopeSelect //service.AdminRole().DataScopeSelect()
|
||||
res.List = consts.DataScopeSelect
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -5,11 +5,7 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"hotgo/internal/consts"
|
||||
"hotgo/internal/dao/internal"
|
||||
"hotgo/internal/model/entity"
|
||||
)
|
||||
|
||||
// internalAdminDeptDao is internal type for wrapping internal DAO implements.
|
||||
@ -28,23 +24,4 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
// IsUniqueName 判断名称是否唯一
|
||||
func (dao *adminDeptDao) IsUniqueName(ctx context.Context, id int64, name string) (bool, error) {
|
||||
var data *entity.AdminDept
|
||||
m := dao.Ctx(ctx).Where("name", name)
|
||||
|
||||
if id > 0 {
|
||||
m = m.WhereNot("id", id)
|
||||
}
|
||||
|
||||
if err := m.Scan(&data); err != nil {
|
||||
err = gerror.Wrap(err, consts.ErrorORM)
|
||||
return false, err
|
||||
}
|
||||
|
||||
if data == nil {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
return false, nil
|
||||
}
|
||||
// Fill with you ideas below.
|
||||
|
@ -5,10 +5,7 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"hotgo/internal/dao/internal"
|
||||
"hotgo/internal/model/entity"
|
||||
)
|
||||
|
||||
// internalAdminMemberPostDao is internal type for wrapping internal DAO implements.
|
||||
@ -27,27 +24,4 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
// UpdatePostIds 更新管理员岗位
|
||||
func (dao *adminMemberPostDao) UpdatePostIds(ctx context.Context, memberId int64, postIds []int64) (err error) {
|
||||
_, err = dao.Ctx(ctx).
|
||||
Where("member_id", memberId).
|
||||
Delete()
|
||||
if err != nil {
|
||||
err = gerror.Wrap(err, "删除失败")
|
||||
return err
|
||||
}
|
||||
|
||||
for i := 0; i < len(postIds); i++ {
|
||||
_, err = dao.Ctx(ctx).
|
||||
Insert(entity.AdminMemberPost{
|
||||
MemberId: memberId,
|
||||
PostId: postIds[i],
|
||||
})
|
||||
if err != nil {
|
||||
err = gerror.Wrap(err, "插入用户岗位失败")
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
// Fill with you ideas below.
|
||||
|
@ -23,3 +23,5 @@ var (
|
||||
internal.NewAdminMenuDao(),
|
||||
}
|
||||
)
|
||||
|
||||
// Fill with you ideas below.
|
||||
|
@ -5,11 +5,7 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"hotgo/internal/consts"
|
||||
"hotgo/internal/dao/internal"
|
||||
"hotgo/internal/model/entity"
|
||||
)
|
||||
|
||||
// internalAdminPostDao is internal type for wrapping internal DAO implements.
|
||||
@ -28,44 +24,4 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
// IsUniqueName 判断名称是否唯一
|
||||
func (dao *adminPostDao) IsUniqueName(ctx context.Context, id int64, name string) (bool, error) {
|
||||
var data *entity.AdminPost
|
||||
m := dao.Ctx(ctx).Where("name", name)
|
||||
|
||||
if id > 0 {
|
||||
m = m.WhereNot("id", id)
|
||||
}
|
||||
|
||||
if err := m.Scan(&data); err != nil {
|
||||
err = gerror.Wrap(err, consts.ErrorORM)
|
||||
return false, err
|
||||
}
|
||||
|
||||
if data == nil {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// IsUniqueCode 判断编码是否唯一
|
||||
func (dao *adminPostDao) IsUniqueCode(ctx context.Context, id int64, code string) (bool, error) {
|
||||
var data *entity.AdminPost
|
||||
m := dao.Ctx(ctx).Where("code", code)
|
||||
|
||||
if id > 0 {
|
||||
m = m.WhereNot("id", id)
|
||||
}
|
||||
|
||||
if err := m.Scan(&data); err != nil {
|
||||
err = gerror.Wrap(err, consts.ErrorORM)
|
||||
return false, err
|
||||
}
|
||||
|
||||
if data == nil {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
return false, nil
|
||||
}
|
||||
// Fill with you ideas below.
|
||||
|
@ -5,11 +5,7 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"hotgo/internal/consts"
|
||||
"hotgo/internal/dao/internal"
|
||||
"hotgo/internal/model/entity"
|
||||
)
|
||||
|
||||
// internalAdminRoleDao is internal type for wrapping internal DAO implements.
|
||||
@ -28,44 +24,4 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
// IsUniqueName 判断名称是否唯一
|
||||
func (dao *adminRoleDao) IsUniqueName(ctx context.Context, id int64, name string) (bool, error) {
|
||||
var data *entity.AdminRole
|
||||
m := dao.Ctx(ctx).Where("name", name)
|
||||
|
||||
if id > 0 {
|
||||
m = m.WhereNot("id", id)
|
||||
}
|
||||
|
||||
if err := m.Scan(&data); err != nil {
|
||||
err = gerror.Wrap(err, consts.ErrorORM)
|
||||
return false, err
|
||||
}
|
||||
|
||||
if data == nil {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// IsUniqueCode 判断编码是否唯一
|
||||
func (dao *adminRoleDao) IsUniqueCode(ctx context.Context, id int64, code string) (bool, error) {
|
||||
var data *entity.AdminRole
|
||||
m := dao.Ctx(ctx).Where("key", code)
|
||||
|
||||
if id > 0 {
|
||||
m = m.WhereNot("id", id)
|
||||
}
|
||||
|
||||
if err := m.Scan(&data); err != nil {
|
||||
err = gerror.Wrap(err, consts.ErrorORM)
|
||||
return false, err
|
||||
}
|
||||
|
||||
if data == nil {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
return false, nil
|
||||
}
|
||||
// Fill with you ideas below.
|
||||
|
@ -23,3 +23,5 @@ var (
|
||||
internal.NewSysAttachmentDao(),
|
||||
}
|
||||
)
|
||||
|
||||
// Fill with you ideas below.
|
||||
|
@ -5,9 +5,6 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"hotgo/internal/consts"
|
||||
"hotgo/internal/dao/internal"
|
||||
)
|
||||
|
||||
@ -27,14 +24,4 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
// GetName 获取分组名称
|
||||
func (dao *sysCronGroupDao) GetName(ctx context.Context, id int64) (name string, err error) {
|
||||
m := dao.Ctx(ctx).Fields("name").Where("id", id)
|
||||
list, err := m.Value()
|
||||
if err != nil {
|
||||
err = gerror.Wrap(err, consts.ErrorORM)
|
||||
return name, err
|
||||
}
|
||||
|
||||
return list.String(), nil
|
||||
}
|
||||
// Fill with you ideas below.
|
||||
|
@ -5,12 +5,7 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"hotgo/internal/consts"
|
||||
"hotgo/internal/dao/internal"
|
||||
"hotgo/internal/model/entity"
|
||||
)
|
||||
|
||||
// internalSysDictTypeDao is internal type for wrapping internal DAO implements.
|
||||
@ -30,60 +25,3 @@ var (
|
||||
)
|
||||
|
||||
// Fill with you ideas below.
|
||||
|
||||
// IsUniqueType 判断类型是否唯一
|
||||
func (dao *sysDictTypeDao) IsUniqueType(ctx context.Context, id int64, typeName string) (bool, error) {
|
||||
var data *entity.SysDictType
|
||||
m := dao.Ctx(ctx).Where("type", typeName)
|
||||
|
||||
if id > 0 {
|
||||
m = m.WhereNot("id", id)
|
||||
}
|
||||
|
||||
if err := m.Scan(&data); err != nil {
|
||||
err = gerror.Wrap(err, consts.ErrorORM)
|
||||
return false, err
|
||||
}
|
||||
|
||||
if data == nil {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// GetTypes 获取指定ID的所有类型标识,包含下级
|
||||
func (dao *sysDictTypeDao) GetTypes(ctx context.Context, id int64) (types []string, err error) {
|
||||
columns, err := dao.Ctx(ctx).Fields("type").
|
||||
Where("id", id).
|
||||
WhereOr("pid", id).
|
||||
Where("status", consts.StatusEnabled).Array()
|
||||
types = g.NewVar(columns).Strings()
|
||||
return
|
||||
}
|
||||
|
||||
// GetType 获取指定ID的类型标识
|
||||
func (dao *sysDictTypeDao) GetType(ctx context.Context, id int64) (types string, err error) {
|
||||
m := dao.Ctx(ctx).Fields("type").Where("id", id).
|
||||
Where("status", consts.StatusEnabled)
|
||||
list, err := m.Value()
|
||||
if err != nil {
|
||||
err = gerror.Wrap(err, consts.ErrorORM)
|
||||
return types, err
|
||||
}
|
||||
|
||||
return list.String(), nil
|
||||
}
|
||||
|
||||
// GetId 获取指定类型的ID
|
||||
func (dao *sysDictTypeDao) GetId(ctx context.Context, t string) (id int64, err error) {
|
||||
m := dao.Ctx(ctx).Fields("id").Where("type", t).
|
||||
Where("status", consts.StatusEnabled)
|
||||
list, err := m.Value()
|
||||
if err != nil {
|
||||
err = gerror.Wrap(err, consts.ErrorORM)
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return list.Int64(), nil
|
||||
}
|
||||
|
@ -5,8 +5,6 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
"hotgo/internal/dao/internal"
|
||||
)
|
||||
|
||||
@ -27,17 +25,3 @@ var (
|
||||
)
|
||||
|
||||
// Fill with you ideas below.
|
||||
|
||||
// NowDayCount 当天发送次数
|
||||
func (dao *sysEmsLogDao) NowDayCount(ctx context.Context, event, email string) (count int, err error) {
|
||||
count, err = dao.Ctx(ctx).
|
||||
Where("email", email).
|
||||
Where("event", event).
|
||||
WhereGTE("created_at", gtime.Now().Format("Y-m-d")).
|
||||
Count()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
@ -5,8 +5,6 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
"hotgo/internal/dao/internal"
|
||||
)
|
||||
|
||||
@ -27,17 +25,3 @@ var (
|
||||
)
|
||||
|
||||
// Fill with you ideas below.
|
||||
|
||||
// NowDayCount 当天发送次数
|
||||
func (dao *sysSmsLogDao) NowDayCount(ctx context.Context, event, mobile string) (count int, err error) {
|
||||
count, err = dao.Ctx(ctx).
|
||||
Where("mobile", mobile).
|
||||
Where("event", event).
|
||||
WhereGTE("created_at", gtime.Now().Format("Y-m-d")).
|
||||
Count()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
@ -41,14 +41,13 @@ func PublishClusterSync(ctx context.Context, channel string, message interface{}
|
||||
}
|
||||
|
||||
mutex := lock.Mutex(fmt.Sprintf("%s:%s", "lock", channel))
|
||||
if err := mutex.Lock(ctx); err != nil {
|
||||
g.Log().Warningf(ctx, "PublishClusterSync %v lock err:%v", channel, err)
|
||||
return
|
||||
}
|
||||
_ = mutex.Unlock(ctx)
|
||||
|
||||
if _, err := pubsub.Publish(ctx, channel, message); err != nil {
|
||||
g.Log().Warningf(ctx, "PublishClusterSync %v err:%v", channel, err)
|
||||
err := mutex.LockFunc(ctx, func() {
|
||||
if _, err := pubsub.Publish(ctx, channel, message); err != nil {
|
||||
g.Log().Warningf(ctx, "PublishClusterSync %v err:%v", channel, err)
|
||||
}
|
||||
})
|
||||
if err != nil {
|
||||
g.Log().Warningf(ctx, "PublishClusterSync %v LockFunc err:%v", channel, err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -1,3 +1,8 @@
|
||||
// Package addons
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package addons
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,8 @@
|
||||
// Package addons
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package addons
|
||||
|
||||
const (
|
||||
|
5
server/internal/library/cache/file/file.go
vendored
5
server/internal/library/cache/file/file.go
vendored
@ -1,3 +1,8 @@
|
||||
// Package file
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package file
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,8 @@
|
||||
// Package contexts
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package contexts
|
||||
|
||||
import (
|
||||
|
@ -116,6 +116,33 @@ func (l *Lock) Unlock(ctx context.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (l *Lock) LockFunc(ctx context.Context, f func()) error {
|
||||
if err := l.Lock(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
defer func() {
|
||||
_ = l.Unlock(ctx)
|
||||
}()
|
||||
f()
|
||||
return nil
|
||||
}
|
||||
|
||||
// TryLockFunc tries locking the mutex for writing with given callback function `f`.
|
||||
// it returns true immediately if success, or if there's a lock on the mutex,
|
||||
// it returns error immediately.
|
||||
//
|
||||
// It releases the lock after `f` is executed.
|
||||
func (l *Lock) TryLockFunc(ctx context.Context, f func()) error {
|
||||
err := l.TryLock(ctx)
|
||||
if err != nil {
|
||||
defer func() {
|
||||
_ = l.Unlock(ctx)
|
||||
}()
|
||||
f()
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// startWatchDog 看门狗
|
||||
func (l *Lock) startWatchDog() {
|
||||
resetTTLInterval := l.ttl / 3
|
||||
|
@ -32,9 +32,6 @@ func SubscribeMap(channels map[string]SubHandler) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
subscribes.mutex.Lock()
|
||||
defer subscribes.mutex.Unlock()
|
||||
|
||||
for channel, hr := range channels {
|
||||
if err = Subscribe(channel, hr); err != nil {
|
||||
return
|
||||
|
@ -1,79 +0,0 @@
|
||||
package feishu
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gctx"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"hotgo/internal/library/notify/feishu/internal/security"
|
||||
)
|
||||
|
||||
const feishuAPI = "https://open.feishu.cn/open-apis/bot/v2/hook/"
|
||||
|
||||
// Client feishu client
|
||||
type Client struct {
|
||||
AccessToken string
|
||||
Secret string
|
||||
}
|
||||
|
||||
// NewClient new client
|
||||
func NewClient(accessToken, secret string) *Client {
|
||||
return &Client{
|
||||
AccessToken: accessToken,
|
||||
Secret: secret,
|
||||
}
|
||||
}
|
||||
|
||||
// Response response struct
|
||||
type Response struct {
|
||||
Code int64 `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
Data interface{} `json:"data"`
|
||||
|
||||
Extra interface{} `json:"Extra"`
|
||||
StatusCode int64 `json:"StatusCode"`
|
||||
StatusMessage string `json:"StatusMessage"`
|
||||
}
|
||||
|
||||
// Send send message
|
||||
func (d *Client) Send(message Message) (string, *Response, error) {
|
||||
res := &Response{}
|
||||
|
||||
if len(d.AccessToken) < 1 {
|
||||
return "", res, fmt.Errorf("accessToken is empty")
|
||||
}
|
||||
|
||||
timestamp := time.Now().Unix()
|
||||
sign, err := security.GenSign(d.Secret, timestamp)
|
||||
if err != nil {
|
||||
return "", res, err
|
||||
}
|
||||
|
||||
body := message.Body()
|
||||
body["timestamp"] = strconv.FormatInt(timestamp, 10)
|
||||
body["sign"] = sign
|
||||
|
||||
reqBytes, err := json.Marshal(body)
|
||||
if err != nil {
|
||||
return "", res, err
|
||||
}
|
||||
|
||||
var (
|
||||
result *Response
|
||||
URL = fmt.Sprintf("%v%v", feishuAPI, d.AccessToken)
|
||||
reqString = string(reqBytes)
|
||||
)
|
||||
|
||||
g.Client().
|
||||
Retry(3, time.Second).
|
||||
SetHeader("Accept", "application/json").
|
||||
SetHeader("Content-Type", "application/json").
|
||||
PostVar(gctx.New(), URL, &result)
|
||||
if result.Code != 0 {
|
||||
return reqString, result, fmt.Errorf("send message to feishu error = %s", result.Msg)
|
||||
}
|
||||
return reqString, result, nil
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
package feishu
|
||||
|
||||
type ImageMessage struct {
|
||||
MsgType MsgType `json:"msg_type"`
|
||||
Content ImageContent `json:"content"`
|
||||
}
|
||||
|
||||
type ImageContent struct {
|
||||
ImageKey string `json:"image_key"`
|
||||
}
|
||||
|
||||
func (m *ImageMessage) Body() map[string]interface{} {
|
||||
m.MsgType = MsgTypeImage
|
||||
return structToMap(m)
|
||||
}
|
||||
|
||||
func NewImageMessage() *ImageMessage {
|
||||
return &ImageMessage{}
|
||||
}
|
||||
|
||||
func (m *ImageMessage) SetImageKey(key string) *ImageMessage {
|
||||
m.Content.ImageKey = key
|
||||
return m
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
package feishu
|
||||
|
||||
type InteractiveMessage struct {
|
||||
MsgType MsgType `json:"msg_type"`
|
||||
Card string `json:"card"`
|
||||
}
|
||||
|
||||
func (m *InteractiveMessage) Body() map[string]interface{} {
|
||||
m.MsgType = MsgTypeInteractive
|
||||
return structToMap(m)
|
||||
}
|
||||
|
||||
func NewInteractiveMessage() *InteractiveMessage {
|
||||
return &InteractiveMessage{}
|
||||
}
|
||||
|
||||
// SetCard set card with cardbuilder https://open.feishu.cn/tool/cardbuilder?from=custom_bot_doc
|
||||
func (m *InteractiveMessage) SetCard(card string) *InteractiveMessage {
|
||||
m.Card = card
|
||||
return m
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
package security
|
||||
|
||||
import (
|
||||
"crypto/hmac"
|
||||
"crypto/sha256"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// GenSign generate sign
|
||||
func GenSign(secret string, timestamp int64) (string, error) {
|
||||
stringToSign := fmt.Sprintf("%v", timestamp) + "\n" + secret
|
||||
var data []byte
|
||||
h := hmac.New(sha256.New, []byte(stringToSign))
|
||||
_, err := h.Write(data)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
signature := base64.StdEncoding.EncodeToString(h.Sum(nil))
|
||||
return signature, nil
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
package feishu
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type MsgType string
|
||||
|
||||
// MsgType
|
||||
const (
|
||||
MsgTypeText MsgType = "text"
|
||||
MsgTypePost MsgType = "post"
|
||||
MsgTypeImage MsgType = "image"
|
||||
MsgTypeShareChat MsgType = "share_chat"
|
||||
MsgTypeInteractive MsgType = "interactive"
|
||||
)
|
||||
|
||||
// Message interface
|
||||
type Message interface {
|
||||
Body() map[string]interface{}
|
||||
}
|
||||
|
||||
func structToMap(item interface{}) map[string]interface{} {
|
||||
res := map[string]interface{}{}
|
||||
if item == nil {
|
||||
return res
|
||||
}
|
||||
v := reflect.TypeOf(item)
|
||||
reflectValue := reflect.ValueOf(item)
|
||||
reflectValue = reflect.Indirect(reflectValue)
|
||||
|
||||
if v.Kind() == reflect.Ptr {
|
||||
v = v.Elem()
|
||||
}
|
||||
|
||||
for i := 0; i < v.NumField(); i++ {
|
||||
tag := v.Field(i).Tag.Get("json")
|
||||
|
||||
// remove omitEmpty
|
||||
omitEmpty := false
|
||||
if strings.HasSuffix(tag, "omitempty") {
|
||||
omitEmpty = true
|
||||
idx := strings.Index(tag, ",")
|
||||
if idx > 0 {
|
||||
tag = tag[:idx]
|
||||
} else {
|
||||
tag = ""
|
||||
}
|
||||
}
|
||||
|
||||
field := reflectValue.Field(i).Interface()
|
||||
if tag != "" && tag != "-" {
|
||||
if omitEmpty && reflectValue.Field(i).IsZero() {
|
||||
continue
|
||||
}
|
||||
|
||||
if v.Field(i).Type.Kind() == reflect.Struct {
|
||||
res[tag] = structToMap(field)
|
||||
} else {
|
||||
res[tag] = field
|
||||
}
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
@ -1,170 +0,0 @@
|
||||
package feishu
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
)
|
||||
|
||||
type PostMessage struct {
|
||||
MsgType MsgType `json:"msg_type"`
|
||||
Content PostContent `json:"content"`
|
||||
}
|
||||
|
||||
func NewPostMessage() *PostMessage {
|
||||
return &PostMessage{}
|
||||
}
|
||||
|
||||
func (m *PostMessage) Body() map[string]interface{} {
|
||||
m.MsgType = MsgTypePost
|
||||
return structToMap(m)
|
||||
}
|
||||
|
||||
func (m *PostMessage) SetZH(u PostUnit) *PostMessage {
|
||||
m.Content.Post.ZH = u
|
||||
return m
|
||||
}
|
||||
|
||||
func (m *PostMessage) SetZHTitle(t string) *PostMessage {
|
||||
m.Content.Post.ZH.Title = t
|
||||
return m
|
||||
}
|
||||
|
||||
func (m *PostMessage) AppendZHContent(i []PostItem) *PostMessage {
|
||||
m.Content.Post.ZH.Content = append(m.Content.Post.ZH.Content, i)
|
||||
return m
|
||||
}
|
||||
|
||||
func (m *PostMessage) SetJA(u PostUnit) *PostMessage {
|
||||
m.Content.Post.JA = u
|
||||
return m
|
||||
}
|
||||
|
||||
func (m *PostMessage) SetJATitle(t string) *PostMessage {
|
||||
m.Content.Post.JA.Title = t
|
||||
return m
|
||||
}
|
||||
|
||||
func (m *PostMessage) AppendJAContent(i []PostItem) *PostMessage {
|
||||
m.Content.Post.JA.Content = append(m.Content.Post.JA.Content, i)
|
||||
return m
|
||||
}
|
||||
|
||||
func (m *PostMessage) SetEN(u PostUnit) *PostMessage {
|
||||
m.Content.Post.EN = u
|
||||
return m
|
||||
}
|
||||
|
||||
func (m *PostMessage) SetENTitle(t string) *PostMessage {
|
||||
m.Content.Post.EN.Title = t
|
||||
return m
|
||||
}
|
||||
|
||||
func (m *PostMessage) AppendENContent(i []PostItem) *PostMessage {
|
||||
m.Content.Post.EN.Content = append(m.Content.Post.EN.Content, i)
|
||||
return m
|
||||
}
|
||||
|
||||
type PostContent struct {
|
||||
Post PostBody `json:"post"`
|
||||
}
|
||||
|
||||
type PostBody struct {
|
||||
ZH PostUnit `json:"zh_cn,omitempty"`
|
||||
JA PostUnit `json:"ja_jp,omitempty"`
|
||||
EN PostUnit `json:"en_us,omitempty"`
|
||||
}
|
||||
|
||||
type PostUnit struct {
|
||||
Title string `json:"title,omitempty"`
|
||||
Content [][]PostItem `json:"content"`
|
||||
}
|
||||
|
||||
type PostItem interface{}
|
||||
|
||||
type Text struct {
|
||||
Tag string `json:"tag"`
|
||||
Text string `json:"text"`
|
||||
UnEscape bool `json:"un_escape,omitempty"`
|
||||
}
|
||||
|
||||
func NewText(text string) Text {
|
||||
t := Text{
|
||||
Tag: "text",
|
||||
Text: text,
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
type A struct {
|
||||
Tag string `json:"tag"`
|
||||
Text string `json:"text"`
|
||||
Href string `json:"href"`
|
||||
UnEscape bool `json:"un_escape,omitempty"`
|
||||
}
|
||||
|
||||
func NewA(text, href string) A {
|
||||
t := A{
|
||||
Tag: "a",
|
||||
Text: text,
|
||||
Href: href,
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
type AT struct {
|
||||
Tag string `json:"tag"`
|
||||
UserID string `json:"user_id"`
|
||||
}
|
||||
|
||||
func NewAT(userID string) AT {
|
||||
t := AT{
|
||||
Tag: "at",
|
||||
UserID: userID,
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
type Image struct {
|
||||
Tag string `json:"tag"`
|
||||
ImageKey string `json:"image_key"`
|
||||
Height int `json:"height"`
|
||||
Width int `json:"width"`
|
||||
}
|
||||
|
||||
func NewImage(imageKey string, height, width int) Image {
|
||||
t := Image{
|
||||
Tag: "image",
|
||||
ImageKey: imageKey,
|
||||
Height: height,
|
||||
Width: width,
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
type PostCMDMessage struct {
|
||||
MsgType MsgType `json:"msg_type"`
|
||||
Content PostCMDContent `json:"content"`
|
||||
}
|
||||
|
||||
func (m *PostCMDMessage) Body() map[string]interface{} {
|
||||
m.MsgType = MsgTypePost
|
||||
return structToMap(m)
|
||||
}
|
||||
|
||||
type PostCMDContent struct {
|
||||
Post map[string]interface{} `json:"post"`
|
||||
}
|
||||
|
||||
func NewPostCMDMessage() *PostCMDMessage {
|
||||
return &PostCMDMessage{}
|
||||
}
|
||||
|
||||
func (m *PostCMDMessage) SetPost(post string) *PostCMDMessage {
|
||||
var result map[string]interface{}
|
||||
err := json.Unmarshal([]byte(post), &result)
|
||||
if err != nil {
|
||||
log.Print("SetPost err: ", err)
|
||||
}
|
||||
m.Content.Post = result
|
||||
return m
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
package feishu
|
||||
|
||||
type ShareChatMessage struct {
|
||||
MsgType MsgType `json:"msg_type"`
|
||||
Content ShareChatContent `json:"content"`
|
||||
}
|
||||
|
||||
type ShareChatContent struct {
|
||||
ShareChatID string `json:"share_chat_id"`
|
||||
}
|
||||
|
||||
func (m *ShareChatMessage) Body() map[string]interface{} {
|
||||
m.MsgType = MsgTypeShareChat
|
||||
return structToMap(m)
|
||||
}
|
||||
|
||||
func NewShareChatMessage() *ShareChatMessage {
|
||||
return &ShareChatMessage{}
|
||||
}
|
||||
|
||||
func (m *ShareChatMessage) SetShareChatID(id string) *ShareChatMessage {
|
||||
m.Content.ShareChatID = id
|
||||
return m
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
package feishu
|
||||
|
||||
type TextMessage struct {
|
||||
MsgType MsgType `json:"msg_type"`
|
||||
Content Content `json:"content"`
|
||||
}
|
||||
|
||||
type Content struct {
|
||||
Text string `json:"text"`
|
||||
}
|
||||
|
||||
func (m *TextMessage) Body() map[string]interface{} {
|
||||
m.MsgType = MsgTypeText
|
||||
return structToMap(m)
|
||||
}
|
||||
|
||||
func NewTextMessage() *TextMessage {
|
||||
return &TextMessage{}
|
||||
}
|
||||
|
||||
func (m *TextMessage) SetText(text string) *TextMessage {
|
||||
m.Content.Text = text
|
||||
return m
|
||||
}
|
@ -1,3 +1,8 @@
|
||||
// Package alipay
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package alipay
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,8 @@
|
||||
// Package alipay
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package alipay
|
||||
|
||||
import "github.com/gogf/gf/v2/os/gtime"
|
||||
|
@ -1,3 +1,8 @@
|
||||
// Package payment
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package payment
|
||||
|
||||
import "hotgo/internal/model"
|
||||
|
@ -1,3 +1,8 @@
|
||||
// Package payment
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package payment
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,8 @@
|
||||
// Package payment
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package payment
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,8 @@
|
||||
// Package qqpay
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package qqpay
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,8 @@
|
||||
// Package qqpay
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package qqpay
|
||||
|
||||
// NotifyRequest QQ支付异步通知参数
|
||||
|
@ -1,3 +1,8 @@
|
||||
// Package wxpay
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package wxpay
|
||||
|
||||
import (
|
||||
|
@ -1 +1,6 @@
|
||||
// Package wxpay
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package wxpay
|
||||
|
@ -1,3 +1,8 @@
|
||||
// Package queue
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package queue
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,8 @@
|
||||
// Package queue
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package queue
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,8 @@
|
||||
// Package disk
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package disk
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,8 @@
|
||||
// Package disk
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package disk
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,8 @@
|
||||
// Package disk
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package disk
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,8 @@
|
||||
// Package queue
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package queue
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,8 @@
|
||||
// Package queue
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package queue
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,8 @@
|
||||
// Package sms
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package sms
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,8 @@
|
||||
// Package sms
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package sms
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,8 @@
|
||||
// Package sms
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package sms
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,8 @@
|
||||
// Package sms
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package sms
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,8 @@
|
||||
// Package storager
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package storager
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,8 @@
|
||||
// Package storager
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package storager
|
||||
|
||||
// FileMeta 文件元数据
|
||||
|
@ -1,3 +1,8 @@
|
||||
// Package storager
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package storager
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,8 @@
|
||||
// Package storager
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package storager
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,8 @@
|
||||
// Package storager
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package storager
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,8 @@
|
||||
// Package storager
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package storager
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,8 @@
|
||||
// Package storager
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package storager
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,8 @@
|
||||
// Package storager
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package storager
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,8 @@
|
||||
// Package token
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package token
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,8 @@
|
||||
// Package wechat
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package wechat
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,8 @@
|
||||
// Package wechat
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package wechat
|
||||
|
||||
import "hotgo/internal/model"
|
||||
|
@ -1,3 +1,8 @@
|
||||
// Package wechat
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package wechat
|
||||
|
||||
import (
|
||||
|
@ -521,7 +521,7 @@ func (s *sAdminMember) Edit(ctx context.Context, in *adminin.MemberEditInp) (err
|
||||
}
|
||||
|
||||
// 更新岗位
|
||||
if err = dao.AdminMemberPost.UpdatePostIds(ctx, in.Id, in.PostIds); err != nil {
|
||||
if err = service.AdminMemberPost().UpdatePostIds(ctx, in.Id, in.PostIds); err != nil {
|
||||
err = gerror.Wrap(err, "更新用户岗位失败,请稍后重试!")
|
||||
}
|
||||
|
||||
@ -557,7 +557,7 @@ func (s *sAdminMember) Edit(ctx context.Context, in *adminin.MemberEditInp) (err
|
||||
}
|
||||
|
||||
// 更新岗位
|
||||
if err = dao.AdminMemberPost.UpdatePostIds(ctx, id, in.PostIds); err != nil {
|
||||
if err = service.AdminMemberPost().UpdatePostIds(ctx, id, in.PostIds); err != nil {
|
||||
err = gerror.Wrap(err, "新增用户岗位失败,请稍后重试!")
|
||||
}
|
||||
|
||||
|
@ -132,7 +132,7 @@ func (s *sAdminSite) Register(ctx context.Context, in *adminin.RegisterInp) (err
|
||||
}
|
||||
|
||||
// 更新岗位
|
||||
if err = dao.AdminMemberPost.UpdatePostIds(ctx, id, config.PostIds); err != nil {
|
||||
if err = service.AdminMemberPost().UpdatePostIds(ctx, id, config.PostIds); err != nil {
|
||||
err = gerror.Wrap(err, consts.ErrorORM)
|
||||
}
|
||||
return
|
||||
|
@ -183,11 +183,22 @@ func (s *sSysCron) List(ctx context.Context, in *sysin.CronListInp) (list []*sys
|
||||
}
|
||||
|
||||
for _, v := range list {
|
||||
v.GroupName, _ = dao.SysCronGroup.GetName(ctx, v.GroupId)
|
||||
v.GroupName, _ = s.GetName(ctx, v.GroupId)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// GetName 获取分组名称
|
||||
func (s *sSysCron) GetName(ctx context.Context, id int64) (name string, err error) {
|
||||
m := dao.SysCronGroup.Ctx(ctx).Fields("name").Where("id", id)
|
||||
list, err := m.Value()
|
||||
if err != nil {
|
||||
err = gerror.Wrap(err, consts.ErrorORM)
|
||||
return name, err
|
||||
}
|
||||
return list.String(), nil
|
||||
}
|
||||
|
||||
// OnlineExec 在线执行
|
||||
func (s *sSysCron) OnlineExec(ctx context.Context, in *sysin.OnlineExecInp) (err error) {
|
||||
var data *entity.SysCron
|
||||
|
@ -8,6 +8,7 @@ package sys
|
||||
import (
|
||||
"context"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"hotgo/internal/consts"
|
||||
"hotgo/internal/dao"
|
||||
"hotgo/internal/model/input/sysin"
|
||||
@ -47,7 +48,7 @@ func (s *sSysDictData) Edit(ctx context.Context, in *sysin.DictDataEditInp) (err
|
||||
}
|
||||
|
||||
// 新增
|
||||
in.Type, err = dao.SysDictType.GetType(ctx, in.TypeID)
|
||||
in.Type, err = s.GetType(ctx, in.TypeID)
|
||||
if err != nil {
|
||||
err = gerror.Wrap(err, consts.ErrorORM)
|
||||
return err
|
||||
@ -70,7 +71,7 @@ func (s *sSysDictData) List(ctx context.Context, in *sysin.DictDataListInp) (lis
|
||||
mod := dao.SysDictData.Ctx(ctx)
|
||||
// 类型ID
|
||||
if in.TypeID > 0 {
|
||||
types, err := dao.SysDictType.GetTypes(ctx, in.TypeID)
|
||||
types, err := s.GetTypes(ctx, in.TypeID)
|
||||
if err != nil {
|
||||
return list, totalCount, err
|
||||
}
|
||||
@ -107,11 +108,42 @@ func (s *sSysDictData) List(ctx context.Context, in *sysin.DictDataListInp) (lis
|
||||
}
|
||||
|
||||
for _, v := range list {
|
||||
v.TypeID, _ = dao.SysDictType.GetId(ctx, v.Type)
|
||||
v.TypeID, _ = s.GetId(ctx, v.Type)
|
||||
}
|
||||
return list, totalCount, err
|
||||
}
|
||||
|
||||
// GetId 获取指定类型的ID
|
||||
func (s *sSysDictData) GetId(ctx context.Context, t string) (id int64, err error) {
|
||||
m := dao.SysDictType.Ctx(ctx).Fields("id").Where("type", t).Where("status", consts.StatusEnabled)
|
||||
val, err := m.Value()
|
||||
if err != nil {
|
||||
err = gerror.Wrap(err, consts.ErrorORM)
|
||||
return 0, err
|
||||
}
|
||||
return val.Int64(), nil
|
||||
}
|
||||
|
||||
// GetType 获取指定ID的类型标识
|
||||
func (s *sSysDictData) GetType(ctx context.Context, id int64) (types string, err error) {
|
||||
m := dao.SysDictType.Ctx(ctx).Fields("type").Where("id", id).Where("status", consts.StatusEnabled)
|
||||
val, err := m.Value()
|
||||
if err != nil {
|
||||
err = gerror.Wrap(err, consts.ErrorORM)
|
||||
return types, err
|
||||
}
|
||||
return val.String(), nil
|
||||
}
|
||||
|
||||
// GetTypes 获取指定ID的所有类型标识,包含下级
|
||||
func (s *sSysDictData) GetTypes(ctx context.Context, id int64) (types []string, err error) {
|
||||
columns, err := dao.SysDictType.Ctx(ctx).Fields("type").
|
||||
Where("id", id).WhereOr("pid", id).Where("status", consts.StatusEnabled).
|
||||
Array()
|
||||
types = g.NewVar(columns).Strings()
|
||||
return
|
||||
}
|
||||
|
||||
// Select 获取列表
|
||||
func (s *sSysDictData) Select(ctx context.Context, in *sysin.DataSelectInp) (list sysin.DataSelectModel, err error) {
|
||||
mod := dao.SysDictData.Ctx(ctx).Where("type", in.Type)
|
||||
|
@ -335,7 +335,7 @@ func (s *sSysEmsLog) AllowSend(ctx context.Context, models *entity.SysEmsLog, co
|
||||
}
|
||||
|
||||
if config.MaxIpLimit > 0 {
|
||||
count, err := dao.SysEmsLog.NowDayCount(ctx, models.Event, models.Email)
|
||||
count, err := s.NowDayCount(ctx, models.Event, models.Email)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -348,6 +348,15 @@ func (s *sSysEmsLog) AllowSend(ctx context.Context, models *entity.SysEmsLog, co
|
||||
return
|
||||
}
|
||||
|
||||
// NowDayCount 当天发送次数
|
||||
func (s *sSysEmsLog) NowDayCount(ctx context.Context, event, email string) (count int, err error) {
|
||||
return dao.SysEmsLog.Ctx(ctx).
|
||||
Where("email", email).
|
||||
Where("event", event).
|
||||
WhereGTE("created_at", gtime.Now().Format("Y-m-d")).
|
||||
Count()
|
||||
}
|
||||
|
||||
// VerifyCode 效验验证码
|
||||
func (s *sSysEmsLog) VerifyCode(ctx context.Context, in *sysin.VerifyEmsCodeInp) (err error) {
|
||||
if in.Event == "" {
|
||||
|
@ -245,7 +245,7 @@ func (s *sSysSmsLog) AllowSend(ctx context.Context, models *entity.SysSmsLog, co
|
||||
}
|
||||
|
||||
if config.SmsMaxIpLimit > 0 {
|
||||
count, err := dao.SysSmsLog.NowDayCount(ctx, models.Event, models.Mobile)
|
||||
count, err := s.NowDayCount(ctx, models.Event, models.Mobile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -258,6 +258,15 @@ func (s *sSysSmsLog) AllowSend(ctx context.Context, models *entity.SysSmsLog, co
|
||||
return
|
||||
}
|
||||
|
||||
// NowDayCount 当天发送次数
|
||||
func (s *sSysSmsLog) NowDayCount(ctx context.Context, event, mobile string) (count int, err error) {
|
||||
return dao.SysSmsLog.Ctx(ctx).
|
||||
Where("mobile", mobile).
|
||||
Where("event", event).
|
||||
WhereGTE("created_at", gtime.Now().Format("Y-m-d")).
|
||||
Count()
|
||||
}
|
||||
|
||||
// VerifyCode 效验验证码
|
||||
func (s *sSysSmsLog) VerifyCode(ctx context.Context, in *sysin.VerifyCodeInp) (err error) {
|
||||
if in.Event == "" {
|
||||
|
@ -1,3 +1,8 @@
|
||||
// Package model
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package model
|
||||
|
||||
// 后台配置.
|
||||
|
@ -1,3 +1,8 @@
|
||||
// Package model
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package model
|
||||
|
||||
// 本地配置.
|
||||
|
@ -1,3 +1,8 @@
|
||||
// Package model
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package model
|
||||
|
||||
// GenCodesColumn 生成表字段属性
|
||||
|
@ -1,3 +1,8 @@
|
||||
// Package form
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package form
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,8 @@
|
||||
// Package form
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package form
|
||||
|
||||
import "github.com/gogf/gf/v2/util/gconv"
|
||||
|
@ -1,3 +1,8 @@
|
||||
// Package payin
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package payin
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,8 @@
|
||||
// Package servmsgin
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package servmsgin
|
||||
|
||||
import "github.com/gogf/gf/v2/os/gtime"
|
||||
|
@ -1,3 +1,8 @@
|
||||
// Package servmsgin
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package servmsgin
|
||||
|
||||
import "github.com/gogf/gf/v2/os/gtime"
|
||||
|
@ -1,3 +1,8 @@
|
||||
// Package convert
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package convert
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,8 @@
|
||||
// Package simple
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package simple
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,8 @@
|
||||
// Package url
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
package url
|
||||
|
||||
import (
|
||||
|
@ -56,7 +56,7 @@
|
||||
import GroupModal from './modal/modal.vue';
|
||||
import Edit from '@/views/monitor/netconn/modal/edit.vue';
|
||||
import { newState, options, State } from '@/views/monitor/netconn/modal/model';
|
||||
import { defRangeShortcuts } from "@/utils/dateUtil";
|
||||
import { defRangeShortcuts } from '@/utils/dateUtil';
|
||||
|
||||
const message = useMessage();
|
||||
const dialog = useDialog();
|
||||
|
@ -93,7 +93,7 @@
|
||||
import DataItem from './components/DataItem.vue';
|
||||
import LoadChart from './components/chart/LoadChart.vue';
|
||||
import FullYearSalesChart from './components/chart/FullYearSalesChart.vue';
|
||||
import { defineComponent, inject, onMounted, ref, onUpdated } from 'vue';
|
||||
import { defineComponent, inject, onMounted, ref, onUnmounted } from 'vue';
|
||||
import { SocketEnum } from '@/enums/socketEnum';
|
||||
import { addOnMessage, sendMsg } from '@/utils/websocket';
|
||||
import { formatBefore } from '@/utils/dateUtil';
|
||||
@ -107,6 +107,7 @@
|
||||
FullYearSalesChart,
|
||||
},
|
||||
setup() {
|
||||
const timer = ref(0);
|
||||
const dataRunInfo = ref({
|
||||
arch: '',
|
||||
goMem: '0MB',
|
||||
@ -180,7 +181,7 @@
|
||||
const fullYearSalesChartRef = ref<InstanceType<typeof FullYearSalesChart>>();
|
||||
const onMessageList = inject('onMessageList');
|
||||
|
||||
const onAdminMonitor = (res) => {
|
||||
const onAdminMonitor = (res: { data: string }) => {
|
||||
const data = JSON.parse(res.data);
|
||||
if (data.event === SocketEnum.EventAdminMonitorRunInfo) {
|
||||
loading.value = false;
|
||||
@ -207,7 +208,14 @@
|
||||
addOnMessage(onMessageList, onAdminMonitor);
|
||||
|
||||
onMounted(() => {
|
||||
getInfo();
|
||||
loading.value = true;
|
||||
sendMsg(SocketEnum.EventAdminMonitorTrends);
|
||||
sendMsg(SocketEnum.EventAdminMonitorRunInfo);
|
||||
|
||||
timer.value = window.setInterval(function () {
|
||||
sendMsg(SocketEnum.EventAdminMonitorTrends);
|
||||
sendMsg(SocketEnum.EventAdminMonitorRunInfo);
|
||||
}, 2000);
|
||||
|
||||
setTimeout(() => {
|
||||
if (loading.value) {
|
||||
@ -221,28 +229,10 @@
|
||||
}, 5000);
|
||||
});
|
||||
|
||||
onUpdated(() => {
|
||||
// 切换页面后直接出发一次
|
||||
if (loading.value === false) {
|
||||
sendMsg(SocketEnum.EventAdminMonitorTrends);
|
||||
sendMsg(SocketEnum.EventAdminMonitorRunInfo);
|
||||
}
|
||||
onUnmounted(() => {
|
||||
window.clearInterval(timer.value);
|
||||
});
|
||||
|
||||
function getInfo() {
|
||||
loading.value = true;
|
||||
sendMsg(SocketEnum.EventAdminMonitorTrends);
|
||||
sendMsg(SocketEnum.EventAdminMonitorRunInfo);
|
||||
|
||||
setInterval(function () {
|
||||
sendMsg(SocketEnum.EventAdminMonitorTrends);
|
||||
}, 1000 * 2);
|
||||
|
||||
setInterval(function () {
|
||||
sendMsg(SocketEnum.EventAdminMonitorRunInfo);
|
||||
}, 1000 * 10);
|
||||
}
|
||||
|
||||
return {
|
||||
loading,
|
||||
collapse,
|
||||
|
Loading…
Reference in New Issue
Block a user