Compare commits
20 Commits
db7295465c
...
c7dd994543
| Author | SHA1 | Date |
|---|---|---|
|
|
c7dd994543 | |
|
|
8607efd319 | |
|
|
beaecbbb01 | |
|
|
785779d0c5 | |
|
|
3135efa1b0 | |
|
|
8e5ecc98ce | |
|
|
8d0617c74e | |
|
|
3b6b3612fb | |
|
|
7bfe7b5855 | |
|
|
3cb71c1bbf | |
|
|
8daa1612c1 | |
|
|
d6b1788ae5 | |
|
|
b9025cf5d1 | |
|
|
9cc3234a61 | |
|
|
2854365ea5 | |
|
|
fae1b378a7 | |
|
|
729f333fb0 | |
|
|
63215bba4a | |
|
|
13d21bb22e | |
|
|
356ab8962b |
24
dao/cid.go
24
dao/cid.go
|
|
@ -27,7 +27,7 @@ type CIDRunLog struct {
|
|||
// CreateCID 创建持续集成、部署
|
||||
func CreateCID(name, url, script, token string, time, auth_id int) uint {
|
||||
cid := CID{Name: name, Url: url, Script: script, Token: token, Auth_id: auth_id, Time: time}
|
||||
result := DB.Debug().Create(&cid)
|
||||
result := DB.Create(&cid)
|
||||
if result.Error != nil {
|
||||
return 0
|
||||
}
|
||||
|
|
@ -36,7 +36,7 @@ func CreateCID(name, url, script, token string, time, auth_id int) uint {
|
|||
|
||||
// DeleteCIDByID 删除持续集成、部署
|
||||
func DeleteCIDByID(id, auth_id int) bool {
|
||||
res := DB.Debug().Model(&CID{}).Where("id = ? and auth_id = ?", id, auth_id).Delete(&CID{})
|
||||
res := DB.Model(&CID{}).Where("id = ? and auth_id = ?", id, auth_id).Delete(&CID{})
|
||||
if res.Error != nil {
|
||||
return false
|
||||
}
|
||||
|
|
@ -46,14 +46,14 @@ func DeleteCIDByID(id, auth_id int) bool {
|
|||
// FindCIDByID 查找持续集成、部署
|
||||
func FindCIDByID(id, auth_id int) CID {
|
||||
var cid CID
|
||||
DB.Debug().Where("id = ? and auth_id = ?", id, auth_id).First(&cid)
|
||||
DB.Where("id = ? and auth_id = ?", id, auth_id).First(&cid)
|
||||
return cid
|
||||
}
|
||||
|
||||
// FindCIDByAuthID 查找持续集成、部署
|
||||
func FindCIDByAuthID(auth_id int) []CID {
|
||||
var cids []CID
|
||||
DB.Debug().Where("auth_id = ?", auth_id).Find(&cids)
|
||||
DB.Where("auth_id = ?", auth_id).Find(&cids)
|
||||
return cids
|
||||
}
|
||||
|
||||
|
|
@ -67,7 +67,7 @@ func UpdateCIDByID(id, auth_id, time int, name, url, script, token string) bool
|
|||
if token == "" {
|
||||
token = pd.Token
|
||||
}
|
||||
result := DB.Debug().Model(&CID{}).Where("id = ? and auth_id = ?", id, auth_id).Updates(CID{Name: name, Url: url, Script: script, Token: token, Time: time})
|
||||
result := DB.Model(&CID{}).Where("id = ? and auth_id = ?", id, auth_id).Updates(CID{Name: name, Url: url, Script: script, Token: token, Time: time})
|
||||
if result.Error != nil {
|
||||
return false
|
||||
}
|
||||
|
|
@ -77,7 +77,7 @@ func UpdateCIDByID(id, auth_id, time int, name, url, script, token string) bool
|
|||
// CreateRunLog,添加执行日志
|
||||
func CreateRunLog(cid_id, auth_id int, script, log, err string) uint {
|
||||
cidRunLog := CIDRunLog{CID_id: cid_id, Auth_id: auth_id, Log: log, Error: err, Script: script}
|
||||
result := DB.Debug().Create(&cidRunLog)
|
||||
result := DB.Create(&cidRunLog)
|
||||
if result != nil {
|
||||
fmt.Println(err)
|
||||
return 0
|
||||
|
|
@ -87,36 +87,36 @@ func CreateRunLog(cid_id, auth_id int, script, log, err string) uint {
|
|||
|
||||
func FindRunLogByAuthID(auth_id int) []CIDRunLog {
|
||||
var cidRunLogs []CIDRunLog
|
||||
DB.Debug().Where(" auth_id = ?", auth_id).Order("created_at desc").Find(&cidRunLogs)
|
||||
DB.Where(" auth_id = ?", auth_id).Order("created_at desc").Find(&cidRunLogs)
|
||||
return cidRunLogs
|
||||
}
|
||||
|
||||
func FindRunLogByID(auth_id, cid_id int) []CIDRunLog {
|
||||
var cidRunLog []CIDRunLog
|
||||
DB.Debug().Where("cid_id = ? and auth_id = ?", cid_id, auth_id).Order("created_at desc").Limit(30).Find(&cidRunLog)
|
||||
DB.Where("cid_id = ? and auth_id = ?", cid_id, auth_id).Order("created_at desc").Limit(30).Find(&cidRunLog)
|
||||
return cidRunLog
|
||||
}
|
||||
func FindRunLogByCIDLogID(id, auth_id int) []CIDRunLog {
|
||||
var cidRunLogs []CIDRunLog
|
||||
DB.Debug().Where("id = ? and auth_id = ?", id, auth_id).Order("created_at desc").Limit(30).Find(&cidRunLogs)
|
||||
DB.Where("id = ? and auth_id = ?", id, auth_id).Order("created_at desc").Limit(30).Find(&cidRunLogs)
|
||||
return cidRunLogs
|
||||
}
|
||||
|
||||
func FindCIDByIDAndToken(id int, token string) CID {
|
||||
var cid CID
|
||||
DB.Debug().Where("id = ? and token = ?", id, token).First(&cid)
|
||||
DB.Where("id = ? and token = ?", id, token).First(&cid)
|
||||
return cid
|
||||
}
|
||||
|
||||
func FindCIDByTime() []CID {
|
||||
var cids []CID
|
||||
DB.Debug().Where("time > 0").Find(&cids)
|
||||
DB.Where("time > 0").Find(&cids)
|
||||
return cids
|
||||
}
|
||||
|
||||
// FindCIDByID 查找持续集成、部署
|
||||
func FindCIDByCID(id uint) CID {
|
||||
var cid CID
|
||||
DB.Debug().Where("id = ? ", id).First(&cid)
|
||||
DB.Where("id = ? ", id).First(&cid)
|
||||
return cid
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ type Device struct {
|
|||
|
||||
func CreateDevice(authID int, deviceName, deviceType string, deviceStatus, deviceLocation, deviceIP, deviceInfo string) uint {
|
||||
device := Device{AuthID: authID, DeviceName: deviceName, DeviceType: deviceType, DeviceStatus: deviceStatus, DeviceLocation: deviceLocation, DeviceIP: deviceIP, DeviceInfo: deviceInfo}
|
||||
result := DB.Debug().Create(&device)
|
||||
result := DB.Create(&device)
|
||||
if result.Error != nil {
|
||||
fmt.Println("CreateDevice failed", result.Error)
|
||||
return 0
|
||||
|
|
@ -27,7 +27,7 @@ func CreateDevice(authID int, deviceName, deviceType string, deviceStatus, devic
|
|||
}
|
||||
|
||||
func DeleteDeviceByID(id, user int) bool {
|
||||
res := DB.Debug().Model(&Device{}).Where("id = ? and auth_id = ?", id, user).Delete(&Device{})
|
||||
res := DB.Model(&Device{}).Where("id = ? and auth_id = ?", id, user).Delete(&Device{})
|
||||
if res.Error != nil {
|
||||
return false
|
||||
}
|
||||
|
|
@ -36,18 +36,18 @@ func DeleteDeviceByID(id, user int) bool {
|
|||
|
||||
func FindDeviceByID(id, auth_id int) Device {
|
||||
var device Device
|
||||
DB.Debug().Where("id = ? and auth_id = ?", id, auth_id).First(&device)
|
||||
DB.Where("id = ? and auth_id = ?", id, auth_id).First(&device)
|
||||
return device
|
||||
}
|
||||
|
||||
func FindDeviceByAuthID(auth_id int) []Device {
|
||||
var devices []Device
|
||||
DB.Debug().Where("auth_id = ?", auth_id).Find(&devices)
|
||||
DB.Where("auth_id = ?", auth_id).Find(&devices)
|
||||
return devices
|
||||
}
|
||||
|
||||
func SetDeviceStatus(status string, id, auth_id int) bool {
|
||||
result := DB.Debug().Model(&Device{}).Where("id = ? and auth_id = ?", id, auth_id).Updates(Device{DeviceStatus: status})
|
||||
result := DB.Model(&Device{}).Where("id = ? and auth_id = ?", id, auth_id).Updates(Device{DeviceStatus: status})
|
||||
if result.Error != nil {
|
||||
return false
|
||||
}
|
||||
|
|
@ -78,7 +78,7 @@ func UpdateDeviceByID(id, auth_id int, deviceName, deviceType, deviceStatus, dev
|
|||
deviceInfo = pd.DeviceInfo
|
||||
}
|
||||
}
|
||||
res := DB.Debug().Model(&Device{}).Where("id = ? and auth_id = ?", id, auth_id).Updates(Device{DeviceName: deviceName, DeviceType: deviceType, DeviceStatus: deviceStatus, DeviceLocation: deviceLocation, DeviceIP: deviceIP, DeviceInfo: deviceInfo})
|
||||
res := DB.Model(&Device{}).Where("id = ? and auth_id = ?", id, auth_id).Updates(Device{DeviceName: deviceName, DeviceType: deviceType, DeviceStatus: deviceStatus, DeviceLocation: deviceLocation, DeviceIP: deviceIP, DeviceInfo: deviceInfo})
|
||||
if res.Error != nil {
|
||||
return false
|
||||
}
|
||||
|
|
|
|||
16
dao/file.go
16
dao/file.go
|
|
@ -15,7 +15,7 @@ type File struct {
|
|||
|
||||
func CreateFile(fileStoreName, fileName, fileType, filePath string, fileSize, authID int) uint {
|
||||
file := File{FileStoreName: fileStoreName, FileName: fileName, FileType: fileType, FilePath: filePath, FileSize: fileSize, AuthID: authID}
|
||||
result := DB.Debug().Create(&file)
|
||||
result := DB.Create(&file)
|
||||
if result.Error != nil {
|
||||
return 0
|
||||
}
|
||||
|
|
@ -23,7 +23,7 @@ func CreateFile(fileStoreName, fileName, fileType, filePath string, fileSize, au
|
|||
}
|
||||
|
||||
func DeleteFileByID(id, user int) bool {
|
||||
res := DB.Debug().Model(&File{}).Where("id = ? and auth_id = ?", id, user).Delete(&File{})
|
||||
res := DB.Model(&File{}).Where("id = ? and auth_id = ?", id, user).Delete(&File{})
|
||||
if res.Error != nil {
|
||||
return false
|
||||
}
|
||||
|
|
@ -32,19 +32,19 @@ func DeleteFileByID(id, user int) bool {
|
|||
|
||||
func FindFileByID(id, auth_id int) File {
|
||||
var file File
|
||||
DB.Debug().Where("id = ? and auth_id = ?", id, auth_id).First(&file)
|
||||
DB.Where("id = ? and auth_id = ?", id, auth_id).First(&file)
|
||||
return file
|
||||
}
|
||||
|
||||
func FindFileByNames(fileName string, auth_id int) File {
|
||||
var file File
|
||||
DB.Debug().Where("file_name = ? and auth_id = ?", fileName, auth_id).First(&file)
|
||||
DB.Where("file_name = ? and auth_id = ?", fileName, auth_id).First(&file)
|
||||
return file
|
||||
}
|
||||
|
||||
func FindFileByAuthID(auth_id int) []File {
|
||||
var files []File
|
||||
DB.Debug().Where("auth_id = ?", auth_id).Find(&files)
|
||||
DB.Where("auth_id = ?", auth_id).Find(&files)
|
||||
return files
|
||||
}
|
||||
|
||||
|
|
@ -53,7 +53,7 @@ func UpdateFileByID(id, auth_id int, fileStoreName, fileName, fileType, filePath
|
|||
if pd.ID == 0 {
|
||||
return false
|
||||
}
|
||||
result := DB.Debug().Model(&File{}).Where("id = ? and auth_id = ?", id, auth_id).Updates(File{FileStoreName: fileStoreName, FileName: fileName, FileType: fileType, FilePath: filePath, FileSize: fileSize})
|
||||
result := DB.Model(&File{}).Where("id = ? and auth_id = ?", id, auth_id).Updates(File{FileStoreName: fileStoreName, FileName: fileName, FileType: fileType, FilePath: filePath, FileSize: fileSize})
|
||||
if result.Error != nil {
|
||||
return false
|
||||
}
|
||||
|
|
@ -61,7 +61,7 @@ func UpdateFileByID(id, auth_id int, fileStoreName, fileName, fileType, filePath
|
|||
}
|
||||
|
||||
func DeleteFileByAuthID(auth_id int) bool {
|
||||
res := DB.Debug().Model(&File{}).Where("auth_id = ?", auth_id).Delete(&File{})
|
||||
res := DB.Model(&File{}).Where("auth_id = ?", auth_id).Delete(&File{})
|
||||
if res.Error != nil {
|
||||
return false
|
||||
}
|
||||
|
|
@ -69,7 +69,7 @@ func DeleteFileByAuthID(auth_id int) bool {
|
|||
}
|
||||
|
||||
func DeleteFileById(id int) bool {
|
||||
res := DB.Debug().Model(&File{}).Where("id = ?", id).Delete(&File{})
|
||||
res := DB.Model(&File{}).Where("id = ?", id).Delete(&File{})
|
||||
if res.Error != nil {
|
||||
return false
|
||||
}
|
||||
|
|
|
|||
60
dao/im.go
60
dao/im.go
|
|
@ -40,13 +40,13 @@ type Friend struct {
|
|||
// 创建单聊消息
|
||||
func CreateSimpleMessage(from_user_id, to_user_id int, message string) (error, uint) {
|
||||
msg := Message{FromUserID: from_user_id, ToUserID: to_user_id, Msg: message, Type: proto.MSG_TYPE_SIMPLE, Status: proto.MSG_STATUS_UNREAD}
|
||||
res := DB.Debug().Create(&msg)
|
||||
res := DB.Create(&msg)
|
||||
return res.Error, msg.ID
|
||||
}
|
||||
|
||||
func CreateGeneralMessage(from_user_id, to_user_id, msg_type, status, group_id int, message string) (error error, id uint) {
|
||||
msg := Message{FromUserID: from_user_id, ToUserID: to_user_id, Msg: message, Type: msg_type, Status: status, GroupID: group_id}
|
||||
res := DB.Debug().Create(&msg)
|
||||
res := DB.Create(&msg)
|
||||
return res.Error, msg.ID
|
||||
}
|
||||
|
||||
|
|
@ -55,13 +55,13 @@ func GetMsgUserByIndex(from_user_id, to_user_id, msg_type, index, status int) ([
|
|||
var msgs []Message
|
||||
var res *gorm.DB
|
||||
if msg_type == 4 {
|
||||
res = DB.Debug().Where("from_user_id = ? and to_user_id = ? and type = ? and status = ? ", from_user_id, to_user_id, msg_type, status).Order("created_at DESC").Limit(20 * index).Find(&msgs)
|
||||
res = DB.Where("from_user_id = ? and to_user_id = ? and type = ? and status = ? ", from_user_id, to_user_id, msg_type, status).Order("created_at DESC").Limit(20 * index).Find(&msgs)
|
||||
} else if msg_type == 1 {
|
||||
//单聊,只有两个人的消息
|
||||
res = DB.Debug().Raw("select * from messages where (from_user_id = ? AND to_user_id = ?) and type = ? or (from_user_id = ? AND to_user_id = ?) and type = ? order by created_at desc limit ?", from_user_id, to_user_id, msg_type, to_user_id, from_user_id, msg_type, 20*index).Scan(&msgs)
|
||||
//res = DB.Debug().Where("(from_user_id = ? AND to_user_id = ?) or (from_user_id = ? AND to_user_id = ?) and type = ? ", from_user_id, to_user_id, to_user_id, from_user_id, msg_type).Order("created_at DESC").Limit(20 * index).Find(&msgs)
|
||||
res = DB.Raw("select * from messages where (from_user_id = ? AND to_user_id = ?) and type = ? or (from_user_id = ? AND to_user_id = ?) and type = ? order by created_at desc limit ?", from_user_id, to_user_id, msg_type, to_user_id, from_user_id, msg_type, 20*index).Scan(&msgs)
|
||||
//res = DB.Where("(from_user_id = ? AND to_user_id = ?) or (from_user_id = ? AND to_user_id = ?) and type = ? ", from_user_id, to_user_id, to_user_id, from_user_id, msg_type).Order("created_at DESC").Limit(20 * index).Find(&msgs)
|
||||
} else {
|
||||
res = DB.Debug().Where("from_user_id = ? and to_user_id = ? and type = ? ", from_user_id, to_user_id, msg_type).Order("created_at DESC").Limit(20 * index).Find(&msgs)
|
||||
res = DB.Where("from_user_id = ? and to_user_id = ? and type = ? ", from_user_id, to_user_id, msg_type).Order("created_at DESC").Limit(20 * index).Find(&msgs)
|
||||
}
|
||||
return msgs, res.Error
|
||||
}
|
||||
|
|
@ -73,27 +73,27 @@ type GroupMessage struct {
|
|||
|
||||
func GetMsgGroupByIndex(group_id, index int) ([]GroupMessage, error) {
|
||||
var msgs []GroupMessage
|
||||
res := DB.Debug().Raw("select messages.*,users.name from messages join users on messages.from_user_id = users.id where type = 2 and group_id = ? order by created_at desc limit ?", group_id, 20*index).Scan(&msgs)
|
||||
res := DB.Raw("select messages.*,users.name from messages join users on messages.from_user_id = users.id where type = 2 and group_id = ? order by created_at desc limit ?", group_id, 20*index).Scan(&msgs)
|
||||
return msgs, res.Error
|
||||
|
||||
}
|
||||
|
||||
func GetGroupRequestUsers(user_id int) []GroupRequestUsers {
|
||||
var users []GroupRequestUsers
|
||||
DB.Debug().Raw("select id,im_id,name,email,group_id FROM (SELECT im_id,from_user_id,group_id FROM (( SELECT id as im_id,from_user_id,group_id FROM messages WHERE type=? and status=? ) as m JOIN groups as g on g.id=m.group_id ) where g.auth_id=? ) as e JOIN users as u ON e.from_user_id=u.id", proto.MSG_TYPE_GROUP_ADD, 0, user_id).Scan(&users)
|
||||
DB.Raw("select id,im_id,name,email,group_id FROM (SELECT im_id,from_user_id,group_id FROM (( SELECT id as im_id,from_user_id,group_id FROM messages WHERE type=? and status=? ) as m JOIN groups as g on g.id=m.group_id ) where g.auth_id=? ) as e JOIN users as u ON e.from_user_id=u.id", proto.MSG_TYPE_GROUP_ADD, 0, user_id).Scan(&users)
|
||||
return users
|
||||
}
|
||||
|
||||
func GetMsgUserGroupReq(from_user_id, group_id int) ([]Message, error) {
|
||||
var msgs []Message
|
||||
res := DB.Debug().Where("from_user_id = ? and group_id = ? and type = ? and status = ?", from_user_id, group_id, 5, 0).Find(&msgs)
|
||||
res := DB.Where("from_user_id = ? and group_id = ? and type = ? and status = ?", from_user_id, group_id, 5, 0).Find(&msgs)
|
||||
return msgs, res.Error
|
||||
}
|
||||
|
||||
// 获取邀请消息
|
||||
func GetFriendGroupReq(user_id int) ([]Message, error) {
|
||||
var msgs []Message
|
||||
res := DB.Debug().Where("to_user_id = ? and type = ?", user_id, proto.MSG_TYPE_FRIEND).Find(&msgs)
|
||||
res := DB.Where("to_user_id = ? and type = ?", user_id, proto.MSG_TYPE_FRIEND).Find(&msgs)
|
||||
return msgs, res.Error
|
||||
}
|
||||
|
||||
|
|
@ -146,21 +146,21 @@ func DeleteFriend(user_id, friend_id int) error {
|
|||
// 通过id查找消息
|
||||
func FindMessageByID(id uint) []Message {
|
||||
var msgs []Message
|
||||
DB.Debug().Where("id = ?", id).Find(&msgs)
|
||||
DB.Where("id = ?", id).Find(&msgs)
|
||||
return msgs
|
||||
}
|
||||
|
||||
// 通过id查找消息(包括name)
|
||||
func FindMessageByID2(id uint) []GroupMessage {
|
||||
var msgs []GroupMessage
|
||||
DB.Debug().Raw("select messages.*,users.name from messages join users on messages.from_user_id = users.id where messages.id = ?", id).Scan(&msgs)
|
||||
DB.Raw("select messages.*,users.name from messages join users on messages.from_user_id = users.id where messages.id = ?", id).Scan(&msgs)
|
||||
return msgs
|
||||
|
||||
}
|
||||
|
||||
// 更新消息状态
|
||||
func UpdateMessageStatus(id uint, status int) error {
|
||||
res := DB.Debug().Model(&Message{}).Where("id = ?", id).Update("status", status)
|
||||
res := DB.Model(&Message{}).Where("id = ?", id).Update("status", status)
|
||||
return res.Error
|
||||
}
|
||||
|
||||
|
|
@ -188,45 +188,45 @@ func CreateGroup(groupName, groupInfo, groupType, groupIcon string, user_id int)
|
|||
// 查找用户是否在群聊
|
||||
func FindGroupUser(user_id, group_id int) []GroupUser {
|
||||
var groupUsers []GroupUser
|
||||
DB.Debug().Where("user_id = ? and group_id = ?", user_id, group_id).Find(&groupUsers)
|
||||
DB.Where("user_id = ? and group_id = ?", user_id, group_id).Find(&groupUsers)
|
||||
return groupUsers
|
||||
}
|
||||
|
||||
// 加入群聊
|
||||
func JoinGroup(group_id, user_id int) (error, uint) {
|
||||
groupUser := GroupUser{GroupID: group_id, UserID: user_id}
|
||||
res := DB.Debug().Create(&groupUser)
|
||||
res := DB.Create(&groupUser)
|
||||
return res.Error, groupUser.ID
|
||||
}
|
||||
|
||||
// 退出群聊
|
||||
func QuitGroup(group_id, user_id int) error {
|
||||
res := DB.Debug().Delete(&GroupUser{}, "group_id = ? and user_id = ?", group_id, user_id)
|
||||
res := DB.Delete(&GroupUser{}, "group_id = ? and user_id = ?", group_id, user_id)
|
||||
return res.Error
|
||||
}
|
||||
|
||||
// 根据群id查找群
|
||||
func FindGroup(group_id int) []Group {
|
||||
var groups []Group
|
||||
DB.Debug().Where("id = ?", group_id).Find(&groups)
|
||||
DB.Where("id = ?", group_id).Find(&groups)
|
||||
return groups
|
||||
}
|
||||
|
||||
// 删除群聊
|
||||
func DeleteGroup(group_id int, auth_id int) error {
|
||||
res := DB.Debug().Delete(&Group{}, "id = ? and auth_id = ?", group_id, auth_id)
|
||||
res := DB.Delete(&Group{}, "id = ? and auth_id = ?", group_id, auth_id)
|
||||
return res.Error
|
||||
}
|
||||
|
||||
// 删除群里的用户
|
||||
func DeleteGroupUsers(group_id int) error {
|
||||
res := DB.Debug().Delete(&GroupUser{}, "group_id = ?", group_id)
|
||||
res := DB.Delete(&GroupUser{}, "group_id = ?", group_id)
|
||||
return res.Error
|
||||
}
|
||||
|
||||
func FindFriend(from_user_id, to_user_id int) []Friend {
|
||||
var friends []Friend
|
||||
DB.Debug().Where("user_id = ? and friend_id = ?", from_user_id, to_user_id).Find(&friends)
|
||||
DB.Where("user_id = ? and friend_id = ?", from_user_id, to_user_id).Find(&friends)
|
||||
return friends
|
||||
}
|
||||
|
||||
|
|
@ -238,35 +238,35 @@ type FriendRet struct {
|
|||
|
||||
func FindFriendsIDs(user_id int) []Friend {
|
||||
var friends []Friend
|
||||
DB.Debug().Where("user_id = ?", user_id).Find(&friends)
|
||||
DB.Where("user_id = ?", user_id).Find(&friends)
|
||||
return friends
|
||||
}
|
||||
|
||||
func FindFriends(user_id int) []FriendRet {
|
||||
var friends []FriendRet
|
||||
DB.Debug().Raw("select distinct users.id, users.name, users.email from users join friends on users.id = friends.friend_id where friends.user_id = ? and friends.deleted_at is null", user_id).Scan(&friends)
|
||||
DB.Raw("select distinct users.id, users.name, users.email from users join friends on users.id = friends.friend_id where friends.user_id = ? and friends.deleted_at is null", user_id).Scan(&friends)
|
||||
return friends
|
||||
}
|
||||
func GetGroups(user_id int) []Group {
|
||||
var groups []Group
|
||||
DB.Debug().Where("auth_id = ?", user_id).Find(&groups)
|
||||
DB.Where("auth_id = ?", user_id).Find(&groups)
|
||||
return groups
|
||||
}
|
||||
|
||||
func FindGroups(user_id int) []Group {
|
||||
var groups []Group
|
||||
DB.Debug().Raw("select groups.* from groups join group_users on groups.id = group_users.group_id where group_users.user_id = ? and group_users.deleted_at is null", user_id).Scan(&groups)
|
||||
DB.Raw("select groups.* from groups join group_users on groups.id = group_users.group_id where group_users.user_id = ? and group_users.deleted_at is null", user_id).Scan(&groups)
|
||||
return groups
|
||||
}
|
||||
|
||||
func FindGroupByID(group_id int) []Group {
|
||||
var groups []Group
|
||||
DB.Debug().Where("id = ?", group_id).Find(&groups)
|
||||
DB.Where("id = ?", group_id).Find(&groups)
|
||||
return groups
|
||||
}
|
||||
|
||||
func UpdateGroup(group_id int, groupName, groupInfo, groupType, groupIcon string, user_id int) error {
|
||||
res := DB.Debug().Model(&Group{}).Where("id = ? and auth_id = ? ", group_id, user_id).Updates(map[string]interface{}{"group_name": groupName, "group_info": groupInfo, "group_icon": groupIcon, "group_type": groupType})
|
||||
res := DB.Model(&Group{}).Where("id = ? and auth_id = ? ", group_id, user_id).Updates(map[string]interface{}{"group_name": groupName, "group_info": groupInfo, "group_icon": groupIcon, "group_type": groupType})
|
||||
return res.Error
|
||||
}
|
||||
|
||||
|
|
@ -285,23 +285,23 @@ type GroupRequestUsers struct {
|
|||
|
||||
func GetFriendRequest(user_id int) []FriendRequest {
|
||||
var users []FriendRequest
|
||||
DB.Debug().Raw("select users.id,users.name,users.email,users.age,messages.id as im_id from users join messages on users.id = messages.from_user_id where messages.to_user_id = ? and messages.type = ? and status = ?", user_id, proto.MSG_TYPE_FRIEND, 0).Scan(&users)
|
||||
DB.Raw("select users.id,users.name,users.email,users.age,messages.id as im_id from users join messages on users.id = messages.from_user_id where messages.to_user_id = ? and messages.type = ? and status = ?", user_id, proto.MSG_TYPE_FRIEND, 0).Scan(&users)
|
||||
return users
|
||||
}
|
||||
|
||||
func FindGroupUsers(group_id int) []GroupUser {
|
||||
var groupUsers []GroupUser
|
||||
DB.Debug().Where("group_id = ?", group_id).Find(&groupUsers)
|
||||
DB.Where("group_id = ?", group_id).Find(&groupUsers)
|
||||
return groupUsers
|
||||
}
|
||||
func FindGroupUsersInfo(group_id int) []FriendRet {
|
||||
var groupUsers []FriendRet
|
||||
DB.Debug().Raw("select distinct users.id, users.name, users.email from users join group_users on users.id = group_users.user_id where group_users.group_id = ? and group_users.deleted_at is null", group_id).Scan(&groupUsers)
|
||||
DB.Raw("select distinct users.id, users.name, users.email from users join group_users on users.id = group_users.user_id where group_users.group_id = ? and group_users.deleted_at is null", group_id).Scan(&groupUsers)
|
||||
return groupUsers
|
||||
}
|
||||
|
||||
func FindGroupByNameLike(groupName string) []Group {
|
||||
var groups []Group
|
||||
DB.Debug().Where("group_name like ?", "%"+groupName+"%").Limit(20).Find(&groups)
|
||||
DB.Where("group_name like ?", "%"+groupName+"%").Limit(20).Find(&groups)
|
||||
return groups
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,3 +26,13 @@ func deleteByID(id int) bool {
|
|||
DB.Where("ID = ?", id).Delete(&Logger{})
|
||||
return true
|
||||
}
|
||||
|
||||
// 删除3天前的日志
|
||||
func DeleteLog(days int) bool {
|
||||
res := DB.Exec("delete from loggers where created_at < DATE_SUB(CURDATE(), INTERVAL ? DAY)", days)
|
||||
if res.Error != nil {
|
||||
fmt.Println("DeleteLog error", res.Error)
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
|
|
|||
24
dao/user.go
24
dao/user.go
|
|
@ -17,6 +17,9 @@ type User struct {
|
|||
Redis bool `gorm:"column:redis"`
|
||||
Run bool `gorm:"column:run"`
|
||||
Upload bool `gorm:"column:upload"`
|
||||
VideoFunc bool `gorm:"column:video_func"` //视频功能
|
||||
DeviceFunc bool `gorm:"column:device_func"` //设备功能
|
||||
CIDFunc bool `gorm:"column:cid_func"` //持续集成功能
|
||||
Avatar string `gorm:"column:avatar"`
|
||||
CreateTime string `gorm:"column:create_time"`
|
||||
UpdateTime string `gorm:"column:update_time"`
|
||||
|
|
@ -24,7 +27,7 @@ type User struct {
|
|||
|
||||
func CreateUser(name, password, email, gender string, age int) uint {
|
||||
user := User{Name: name, Email: email, Password: password, Gender: gender, Age: age}
|
||||
res := DB.Debug().Create(&user)
|
||||
res := DB.Create(&user)
|
||||
if res.Error != nil {
|
||||
return 0
|
||||
}
|
||||
|
|
@ -38,38 +41,38 @@ func DeleteUserByID(id int) int {
|
|||
|
||||
func FindUserByID(id int) []proto.User {
|
||||
var users []proto.User
|
||||
DB.Debug().Where("id = ?", id).First(&users)
|
||||
DB.Where("id = ?", id).First(&users)
|
||||
return users
|
||||
}
|
||||
func FindUserByID2(id int) User {
|
||||
var user User
|
||||
DB.Debug().Where("id = ?", id).First(&user)
|
||||
DB.Where("id = ?", id).First(&user)
|
||||
return user
|
||||
}
|
||||
|
||||
func FindUserByUserID(id int) User {
|
||||
var user User
|
||||
DB.Debug().Where("id = ?", id).First(&user)
|
||||
DB.Where("id = ?", id).First(&user)
|
||||
return user
|
||||
}
|
||||
|
||||
func FindUserByName(name string) User {
|
||||
var user User
|
||||
fmt.Println("name:", name)
|
||||
DB.Debug().Where("name = ?", name).First(&user)
|
||||
DB.Where("name = ?", name).First(&user)
|
||||
return user
|
||||
}
|
||||
|
||||
// 根据name模糊查询,邮箱也是,不查询密码
|
||||
func FindUserByNameLike(name string) []proto.User {
|
||||
var users []proto.User
|
||||
DB.Debug().Where("name LIKE ? OR email LIKE ?", "%"+name+"%", "%"+name+"%").Find(&users).Limit(32)
|
||||
DB.Where("name LIKE ? OR email LIKE ?", "%"+name+"%", "%"+name+"%").Find(&users).Limit(32)
|
||||
return users
|
||||
}
|
||||
|
||||
func FindUserByEmail(email string) User {
|
||||
var user User
|
||||
DB.Debug().Where("email = ?", email).First(&user)
|
||||
DB.Where("email = ?", email).First(&user)
|
||||
return user
|
||||
}
|
||||
|
||||
|
|
@ -86,12 +89,15 @@ func UpdateUserByID2(id int, req proto.UpdateUserInfoReq) {
|
|||
updateData["Run"] = req.Run
|
||||
updateData["Redis"] = req.Redis
|
||||
updateData["Upload"] = req.Upload
|
||||
updateData["VideoFunc"] = req.VideoFunc
|
||||
updateData["DeviceFunc"] = req.DeviceFunc
|
||||
updateData["CIDFunc"] = req.CIDFunc
|
||||
updateData["Avatar"] = req.Avatar
|
||||
updateData["Gender"] = req.Gender
|
||||
DB.Debug().Model(&User{}).Where("id =?", id).Updates(updateData)
|
||||
DB.Model(&User{}).Where("id =?", id).Updates(updateData)
|
||||
}
|
||||
|
||||
// 用户修改自己的信息
|
||||
func UpdateUserByID3(id int, req proto.UpdateUserInfoReq) {
|
||||
DB.Debug().Model(&User{}).Where("id = ?", id).Updates(User{Name: req.Username, Age: req.Age, Avatar: req.Avatar, Gender: req.Gender})
|
||||
DB.Model(&User{}).Where("id = ?", id).Updates(User{Name: req.Username, Age: req.Age, Avatar: req.Avatar, Gender: req.Gender})
|
||||
}
|
||||
|
|
|
|||
30
dao/video.go
30
dao/video.go
|
|
@ -21,35 +21,35 @@ type Video struct {
|
|||
|
||||
func FindWillDelVideoList(id int) []Video {
|
||||
var videos []Video
|
||||
DB.Debug().Where("auth_id = ?", id).Where("delete_time<=now()").Where("isdelete=0").Find(&videos)
|
||||
DB.Where("auth_id = ?", id).Where("delete_time<=now()").Where("isdelete=0").Find(&videos)
|
||||
return videos
|
||||
}
|
||||
|
||||
func CreateVideo(videoPath, videoName string, cameraID, authID, human, isDelete int, createTime, endTime, deleteTime string, fileSize int) uint {
|
||||
video := Video{VideoPath: videoPath, VideoName: videoName, CameraID: cameraID, AuthId: authID, Human: human, IsDelete: isDelete, CreateTime: createTime, EndTime: endTime, DeleteTime: deleteTime, FileSize: fileSize}
|
||||
res := DB.Debug().Create(&video)
|
||||
res := DB.Create(&video)
|
||||
if res.Error != nil {
|
||||
return 0
|
||||
}
|
||||
if deleteTime == "" {
|
||||
DB.Debug().Exec("update videos set delete_time= DATE_ADD(NOW(), INTERVAL 20 DAY) where id=?", video.ID) //delete_time= DATE_ADD(NOW(), INTERVAL 20 DAY)
|
||||
DB.Exec("update videos set delete_time= DATE_ADD(NOW(), INTERVAL 20 DAY) where id=?", video.ID) //delete_time= DATE_ADD(NOW(), INTERVAL 20 DAY)
|
||||
}
|
||||
return video.ID
|
||||
}
|
||||
|
||||
func DeleteVideoByID(id, user int) int {
|
||||
delete_time := time.Now().Format("2006-01-02 15:04:05")
|
||||
DB.Debug().Where("id = ? and auth_id = ?", id, user).Updates(&Video{DeleteTime: delete_time, IsDelete: 1})
|
||||
DB.Debug().Where("id = ? and auth_id = ?", id, user).Delete(&Video{})
|
||||
DB.Where("id = ? and auth_id = ?", id, user).Updates(&Video{DeleteTime: delete_time, IsDelete: 1})
|
||||
DB.Where("id = ? and auth_id = ?", id, user).Delete(&Video{})
|
||||
return id
|
||||
}
|
||||
|
||||
func UpdateVideo(videoPath, videoName string, cameraID, videoID, authID, human, isDelete int, createTime, endTime string, fileSize int) bool {
|
||||
res := DB.Debug().Model(&Video{}).Where("id = ? and auth_id = ?", videoID, authID).Updates(Video{VideoPath: videoPath, VideoName: videoName, CameraID: cameraID, AuthId: authID, Human: human, IsDelete: isDelete, CreateTime: createTime, EndTime: endTime, FileSize: fileSize})
|
||||
res := DB.Model(&Video{}).Where("id = ? and auth_id = ?", videoID, authID).Updates(Video{VideoPath: videoPath, VideoName: videoName, CameraID: cameraID, AuthId: authID, Human: human, IsDelete: isDelete, CreateTime: createTime, EndTime: endTime, FileSize: fileSize})
|
||||
if res.Error != nil {
|
||||
return false
|
||||
}
|
||||
res = DB.Debug().Exec("update videos set delete_time= DATE_ADD(NOW(), INTERVAL 20 DAY) where id=? and auth_id=?", videoID, authID) //delete_time= DATE_ADD(NOW(), INTERVAL 20 DAY)
|
||||
res = DB.Exec("update videos set delete_time= DATE_ADD(NOW(), INTERVAL 20 DAY) where id=? and auth_id=?", videoID, authID) //delete_time= DATE_ADD(NOW(), INTERVAL 20 DAY)
|
||||
if res.Error != nil {
|
||||
return false
|
||||
}
|
||||
|
|
@ -58,26 +58,26 @@ func UpdateVideo(videoPath, videoName string, cameraID, videoID, authID, human,
|
|||
|
||||
func FindVideoByID(id, auth_id int) Video {
|
||||
var video Video
|
||||
DB.Debug().Where("id = ? and auth_id = ?", id, auth_id).Where("isdelete = ?", 0).First(&video)
|
||||
DB.Where("id = ? and auth_id = ?", id, auth_id).Where("isdelete = ?", 0).First(&video)
|
||||
return video
|
||||
}
|
||||
|
||||
// 根据用户id查找视频列表,返回最新30条
|
||||
func FindVideoListsByAuthID(auth_id int) []Video {
|
||||
var videos []Video
|
||||
DB.Debug().Where("auth_id = ? and isdelete =? ", auth_id, 0).Order("created_at DESC").Limit(30).Find(&videos)
|
||||
DB.Where("auth_id = ? and isdelete =? ", auth_id, 0).Order("created_at DESC").Limit(30).Find(&videos)
|
||||
return videos
|
||||
}
|
||||
|
||||
func FindVideoListByTime(auth_id int, startTime, endTime string) []Video {
|
||||
var videos []Video
|
||||
DB.Debug().Where("auth_id = ?", auth_id).Where("isdelete=0").Where("created_at > ? and created_at < ?", startTime, endTime).Find(&videos)
|
||||
DB.Where("auth_id = ?", auth_id).Where("isdelete=0").Where("created_at > ? and created_at < ?", startTime, endTime).Find(&videos)
|
||||
return videos
|
||||
}
|
||||
|
||||
// id 为视频id,auth_id为用户id,day为延长天数,返回修改的行数
|
||||
func DelayVideo(id, auth_id, day int) int {
|
||||
res := DB.Debug().Exec("update videos set delete_time = date_add(delete_time, interval ? day) where id = ? and auth_id = ? and isdelete=0", day, id, auth_id)
|
||||
res := DB.Exec("update videos set delete_time = date_add(delete_time, interval ? day) where id = ? and auth_id = ? and isdelete=0", day, id, auth_id)
|
||||
if res.Error != nil {
|
||||
return 0
|
||||
}
|
||||
|
|
@ -86,7 +86,7 @@ func DelayVideo(id, auth_id, day int) int {
|
|||
|
||||
// id 为用户id,day为延长天数,返回修改的行数
|
||||
func DelayAllVideo(id, day int) int {
|
||||
res := DB.Debug().Exec("update videos set delete_time = date_add(delete_time, interval ? day) where auth_id = ? and isdelete = 0", day, id)
|
||||
res := DB.Exec("update videos set delete_time = date_add(delete_time, interval ? day) where auth_id = ? and isdelete = 0", day, id)
|
||||
if res.Error != nil {
|
||||
return 0
|
||||
}
|
||||
|
|
@ -94,7 +94,7 @@ func DelayAllVideo(id, day int) int {
|
|||
}
|
||||
|
||||
func QuashOneDelay(id, user_id int, day int) int {
|
||||
res := DB.Debug().Exec("update videos set delete_time = date_sub(delete_time, interval ? day) where id = ? and auth_id = ? and isdelete=0", day, id, user_id)
|
||||
res := DB.Exec("update videos set delete_time = date_sub(delete_time, interval ? day) where id = ? and auth_id = ? and isdelete=0", day, id, user_id)
|
||||
if res.Error != nil {
|
||||
return 0
|
||||
}
|
||||
|
|
@ -102,7 +102,7 @@ func QuashOneDelay(id, user_id int, day int) int {
|
|||
}
|
||||
|
||||
func QuashAllDelay(user_id int, day int) int {
|
||||
res := DB.Debug().Exec("update videos set delete_time = date_sub(delete_time, interval ? day) where auth_id = ? and isdelete=0", day, user_id)
|
||||
res := DB.Exec("update videos set delete_time = date_sub(delete_time, interval ? day) where auth_id = ? and isdelete=0", day, user_id)
|
||||
if res.Error != nil {
|
||||
return 0
|
||||
}
|
||||
|
|
@ -112,6 +112,6 @@ func QuashAllDelay(user_id int, day int) int {
|
|||
// 获取视频列表分页
|
||||
func GetVideoListByPage(auth_id, page, pageSize int) []Video {
|
||||
var videos []Video
|
||||
DB.Debug().Where("auth_id = ? and isdelete = ?", auth_id, 0).Order("created_at DESC").Offset((page - 1) * pageSize).Limit(pageSize).Find(&videos) //Offset((page - 1) * pageSize).Limit(pageSize),分页,page从1开始,pageSize每页多少条,Offset是偏移量,Limit是限制条数
|
||||
DB.Where("auth_id = ? and isdelete = ?", auth_id, 0).Order("created_at DESC").Offset((page - 1) * pageSize).Limit(pageSize).Find(&videos) //Offset((page - 1) * pageSize).Limit(pageSize),分页,page从1开始,pageSize每页多少条,Offset是偏移量,Limit是限制条数
|
||||
return videos
|
||||
}
|
||||
|
|
|
|||
141
main.go
141
main.go
|
|
@ -1,6 +1,8 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/golang-jwt/jwt"
|
||||
"github.com/robfig/cron/v3"
|
||||
|
|
@ -43,6 +45,8 @@ func main() {
|
|||
log.Fatal("添加定时任务失败: ", err)
|
||||
}
|
||||
c.Start()
|
||||
//读取配置文件,设置系统
|
||||
ReadConfigToSetSystem()
|
||||
r.Run(":" + proto.Config.SERVER_PORT) // listen and serve on 0.0.0.0:8083
|
||||
}
|
||||
func init() {
|
||||
|
|
@ -86,7 +90,9 @@ func writeLogger(c *gin.Context) {
|
|||
|
||||
func JWTAuthMiddleware() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
if proto.Config.LOG_SAVE_DAYS > 0 {
|
||||
writeLogger(c)
|
||||
}
|
||||
// 从请求头中获取 JWT 令牌
|
||||
tokenString := c.Request.Header.Get("token")
|
||||
|
||||
|
|
@ -123,6 +129,22 @@ func JWTAuthMiddleware() gin.HandlerFunc {
|
|||
return
|
||||
}
|
||||
}
|
||||
//查看token是否在超级token中
|
||||
if worker.IsContainSet("super_permission_tokens", tokenString) {
|
||||
s_id := c.Request.Header.Get("super_id")
|
||||
if s_id == "" {
|
||||
c.AbortWithStatus(200)
|
||||
c.JSON(200, gin.H{
|
||||
"message": "NOT_LOGIN",
|
||||
"error": "super_id is empty",
|
||||
"code": proto.TokenIsNull,
|
||||
})
|
||||
return
|
||||
}
|
||||
c.Set("id", s_id)
|
||||
c.Next()
|
||||
return
|
||||
}
|
||||
|
||||
// 使用加密secret 解析 JWT 令牌
|
||||
token, err := jwt.Parse(tokenString, func(token *jwt.Token) (interface{}, error) {
|
||||
|
|
@ -144,6 +166,16 @@ func JWTAuthMiddleware() gin.HandlerFunc {
|
|||
c.Set("id", token.Claims.(jwt.MapClaims)["id"])
|
||||
c.Set("username", token.Claims.(jwt.MapClaims)["username"])
|
||||
|
||||
if UserFuncIntercept(int(token.Claims.(jwt.MapClaims)["id"].(float64)), c.Request.URL.Path) {
|
||||
c.AbortWithStatus(200)
|
||||
c.JSON(200, gin.H{
|
||||
"message": "no function permission",
|
||||
"error": "no permission",
|
||||
"code": proto.NoPermission,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 继续处理请求
|
||||
c.Next()
|
||||
}
|
||||
|
|
@ -156,4 +188,113 @@ func myTask() {
|
|||
if proto.Config.MONITOR {
|
||||
handler.ScanDeviceStatus()
|
||||
}
|
||||
//其它定时任务-通用
|
||||
RunGeneralCron()
|
||||
|
||||
}
|
||||
|
||||
func ReadConfigToSetSystem() {
|
||||
//redis添加通用定时任务
|
||||
key := "cron_info"
|
||||
//日志清理
|
||||
res := worker.GetRedis(key)
|
||||
var cron_infos []proto.CronInfo
|
||||
if res != "" {
|
||||
err := json.Unmarshal([]byte(res), &cron_infos)
|
||||
if err != nil {
|
||||
fmt.Println("Error decoding config")
|
||||
}
|
||||
|
||||
//查看清除日志任务是否存在
|
||||
if proto.Config.LOG_SAVE_DAYS > 0 {
|
||||
var is_exist bool
|
||||
for _, v := range cron_infos {
|
||||
if v.Type == 1 {
|
||||
is_exist = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !is_exist {
|
||||
var logClean proto.CronInfo
|
||||
logClean.Type = 1
|
||||
logClean.Info = "日志清理"
|
||||
logClean.Curr = 86400
|
||||
logClean.Every = 86400
|
||||
cron_infos = append(cron_infos, logClean)
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
if proto.Config.LOG_SAVE_DAYS > 0 {
|
||||
var logClean proto.CronInfo
|
||||
logClean.Type = 1
|
||||
logClean.Info = "日志清理"
|
||||
logClean.Curr = 86400
|
||||
logClean.Every = 86400
|
||||
cron_infos = append(cron_infos, logClean)
|
||||
}
|
||||
}
|
||||
//存入redis
|
||||
data, err := json.Marshal(cron_infos)
|
||||
if err != nil {
|
||||
fmt.Println("Error encoding config")
|
||||
}
|
||||
worker.SetRedis(key, string(data))
|
||||
}
|
||||
|
||||
func RunGeneralCron() {
|
||||
//redis添加通用定时任务
|
||||
key := "cron_info"
|
||||
//日志清理
|
||||
res := worker.GetRedis(key)
|
||||
var cron_infos []proto.CronInfo
|
||||
if res != "" {
|
||||
err := json.Unmarshal([]byte(res), cron_infos)
|
||||
if err != nil {
|
||||
fmt.Println("Error decoding config")
|
||||
}
|
||||
for _, v := range cron_infos {
|
||||
//1:日志清理,其他待定
|
||||
if v.Type == 1 {
|
||||
//日志清理
|
||||
if v.Curr <= 0 {
|
||||
//执行日志清理
|
||||
go dao.DeleteLog(proto.Config.LOG_SAVE_DAYS)
|
||||
v.Curr = v.Every
|
||||
} else {
|
||||
v.Curr -= 10
|
||||
}
|
||||
}
|
||||
}
|
||||
//存入redis
|
||||
data, err := json.Marshal(cron_infos)
|
||||
if err != nil {
|
||||
fmt.Println("Error encoding config")
|
||||
}
|
||||
worker.SetRedis(key, string(data))
|
||||
}
|
||||
}
|
||||
|
||||
// 用户功能拦截,返回true表示拦截,false表示不拦截
|
||||
func UserFuncIntercept(id int, url string) bool {
|
||||
//先查看是否有权限
|
||||
user := dao.FindUserByUserID(id)
|
||||
//如果用户有权限,则不拦截
|
||||
for k, v := range proto.Per_menu_map {
|
||||
if strings.Contains(url, k) {
|
||||
if v == 1 && user.VideoFunc == true {
|
||||
return false
|
||||
}
|
||||
if v == 2 && user.DeviceFunc == true {
|
||||
return false
|
||||
}
|
||||
if v == 3 && user.CIDFunc == true {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
if strings.Contains(url, "/callback") {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import (
|
|||
var Config ConfigStruct
|
||||
var SigningKey = []byte{}
|
||||
var Url_map = map[string]bool{"/login": true, "/register": true, "/uuid": true, "/gqr": true, "/cid/callback": true, "/tool/monitor": true} // 不需要token验证的url
|
||||
var Per_menu_map = map[string]int{"/video/": 1, "/device/": 2, "/cid/": 3}
|
||||
|
||||
const (
|
||||
MYSQL_USER = "video_t2"
|
||||
|
|
@ -75,6 +76,7 @@ type ConfigStruct struct {
|
|||
FILE_BASE_DIR string `json:"file_base_dir"`
|
||||
MONITOR bool `json:"monitor"` // 状态监控及邮件通知
|
||||
SERVER_PORT string `json:"server_port"` // 服务端口
|
||||
LOG_SAVE_DAYS int `json:"log_save_days"` // 日志保存天数,-1表示不保存,0表示永久保存
|
||||
}
|
||||
|
||||
// 读取配置文件
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ const (
|
|||
NoRedisPermissions = 51
|
||||
NoRunPermissions = 52
|
||||
NoDevicePermissions = 53
|
||||
NoPermission = 54
|
||||
|
||||
//消息错误码
|
||||
MsgSendFailed = 61 // 消息发送失败
|
||||
|
|
|
|||
|
|
@ -8,6 +8,9 @@ type UpdateUserInfoReq struct {
|
|||
Gender string `json:"gender" form:"gender"` //性别
|
||||
Redis bool `json:"redis" form:"redis"` //是否刷新redis
|
||||
Upload bool `json:"upload" form:"upload"` //是否上传头像
|
||||
VideoFunc bool `json:"video_func" form:"video_func"` //视频功能
|
||||
DeviceFunc bool `json:"device_func" form:"device_func"` //设备功能
|
||||
CIDFunc bool `json:"cid_func" form:"cid_func"` //持续集成功能
|
||||
Run bool `json:"run" form:"run"` //是否运行
|
||||
Avatar string `json:"avatar" form:"avatar"` //头像
|
||||
}
|
||||
|
|
@ -17,3 +20,11 @@ type CIDRUN struct {
|
|||
Curr int `json:"curr" form:"curr"` //当前剩余时间,每次执行减10s小于等于0则执行
|
||||
Every int `json:"every" form:"every"` //每隔多少秒执行一次,小于等于0表示不执行,时间粒度为10s
|
||||
}
|
||||
|
||||
// 用于执行函数,方法
|
||||
type CronInfo struct {
|
||||
Type int `json:"type" form:"type"` //类型编码,1日志清理(且只会有一个),其他待定
|
||||
Info string `json:"info" form:"info"` //信息
|
||||
Curr int `json:"curr" form:"curr"` //当前剩余时间,每次执行减10s小于等于0则执行
|
||||
Every int `json:"every" form:"every"` //每隔多少秒执行一次,小于等于0表示不执行,时间粒度为10s
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue