Преглед изворни кода

在线用户强退,删除数据库表前缀

yxh пре 6 година
родитељ
комит
8ea20bdcc4

+ 13 - 0
app/controller/admin/monitor_job.go

@@ -0,0 +1,13 @@
+package admin
+
+import "github.com/gogf/gf/net/ghttp"
+
+type MonitorJob struct{}
+
+//任务列表
+func (c *MonitorJob) List(r *ghttp.Request) {}
+
+//添加任务
+func (c *MonitorJob) Add(r *ghttp.Request) {
+
+}

+ 16 - 4
app/controller/admin/surveillance_online.go → app/controller/admin/monitor_online.go

@@ -2,23 +2,23 @@ package admin
 
 import (
 	"gfast/app/model/admin/user_online"
-	"gfast/app/service/admin/surveillance_service"
+	"gfast/app/service/admin/monitor_service"
 	"gfast/library/response"
 	"github.com/gogf/gf/frame/g"
 	"github.com/gogf/gf/net/ghttp"
 	"github.com/gogf/gf/util/gvalid"
 )
 
-type SurveillanceOnline struct{}
+type MonitorOnline struct{}
 
 //用户状态列表
-func (c *SurveillanceOnline) List(r *ghttp.Request) {
+func (c *MonitorOnline) List(r *ghttp.Request) {
 	var req *user_online.ReqListSearch
 	//获取参数
 	if err := r.Parse(&req); err != nil {
 		response.FailJson(true, r, err.(*gvalid.Error).FirstString())
 	}
-	total, page, list, err := surveillance_service.GetOnlineListPage(req)
+	total, page, list, err := monitor_service.GetOnlineListPage(req)
 	if err != nil {
 		response.FailJson(true, r, err.Error())
 	}
@@ -29,3 +29,15 @@ func (c *SurveillanceOnline) List(r *ghttp.Request) {
 	}
 	response.SusJson(true, r, "用户在线状态", result)
 }
+
+//强制退出
+func (c *MonitorOnline) ForceLogout(r *ghttp.Request) {
+	ids := r.GetInts("ids")
+	if len(ids) == 0 {
+		response.FailJson(true, r, "参数错误")
+	}
+	if err := monitor_service.ForceLogout(ids); err != nil {
+		response.FailJson(true, r, err.Error())
+	}
+	response.SusJson(true, r, "用户已退出")
+}

+ 1 - 1
app/model/admin/auth_rule/auth_rule_entity.go

@@ -9,7 +9,7 @@ import (
 	"github.com/gogf/gf/database/gdb"
 )
 
-// Entity is the golang structure for table qxkj_auth_rule.
+// Entity is the golang structure for table auth_rule.
 type Entity struct {
 	Id         uint   `orm:"id,primary"  json:"id"`         //
 	Type       string `orm:"type"        json:"type"`       // menu为菜单,file为权限节点

+ 4 - 4
app/model/admin/auth_rule/auth_rule_model.go

@@ -11,15 +11,15 @@ import (
 	"time"
 )
 
-// arModel is a active record design model for table qxkj_auth_rule operations.
+// arModel is a active record design model for table auth_rule operations.
 type arModel struct {
 	M *gdb.Model
 }
 
 var (
-	// Table is the table name of qxkj_auth_rule.
-	Table = "qxkj_auth_rule"
-	// Model is the model object of qxkj_auth_rule.
+	// Table is the table name of auth_rule.
+	Table = "auth_rule"
+	// Model is the model object of auth_rule.
 	Model = &arModel{g.DB("default").Table(Table).Safe()}
 )
 

+ 1 - 1
app/model/admin/cms_category/cms_category_entity.go

@@ -9,7 +9,7 @@ import (
 	"github.com/gogf/gf/database/gdb"
 )
 
-// Entity is the golang structure for table qxkj_cms_category.
+// Entity is the golang structure for table cms_category.
 type Entity struct {
 	Id             uint64  `orm:"id,primary"      json:"id"`              // 分类id
 	ParentId       uint64  `orm:"parent_id"       json:"parent_id"`       // 分类父id

+ 4 - 4
app/model/admin/cms_category/cms_category_model.go

@@ -11,15 +11,15 @@ import (
 	"time"
 )
 
-// arModel is a active record design model for table qxkj_cms_category operations.
+// arModel is a active record design model for table cms_category operations.
 type arModel struct {
 	M *gdb.Model
 }
 
 var (
-	// Table is the table name of qxkj_cms_category.
-	Table = "qxkj_cms_category"
-	// Model is the model object of qxkj_cms_category.
+	// Table is the table name of cms_category.
+	Table = "cms_category"
+	// Model is the model object of cms_category.
 	Model = &arModel{g.DB("default").Table(Table).Safe()}
 )
 

+ 3 - 3
app/model/admin/role/role_entity.go

@@ -9,7 +9,7 @@ import (
 	"github.com/gogf/gf/database/gdb"
 )
 
-// Entity is the golang structure for table qxkj_role.
+// Entity is the golang structure for table _role.
 type Entity struct {
 	Id         int     `orm:"id,primary"  json:"id"`          //
 	ParentId   int     `orm:"parent_id"   json:"parent_id"`   // 父角色ID
@@ -21,8 +21,8 @@ type Entity struct {
 	Remark     string  `orm:"remark"      json:"remark"`      // 备注
 }
 
-// QxkjRole is alias of Entity, which some developers say they just want.
-type QxkjRole = Entity
+// Role is alias of Entity, which some developers say they just want.
+type Role = Entity
 
 // OmitEmpty sets OPTION_OMITEMPTY option for the model, which automatically filers
 // the data and where attributes for empty values.

+ 4 - 4
app/model/admin/role/role_model.go

@@ -11,15 +11,15 @@ import (
 	"time"
 )
 
-// arModel is a active record design model for table qxkj_role operations.
+// arModel is a active record design model for table _role operations.
 type arModel struct {
 	Model *gdb.Model
 }
 
 var (
-	// Table is the table name of qxkj_role.
-	Table = "qxkj_role"
-	// Model is the model object of qxkj_role.
+	// Table is the table name of _role.
+	Table = "role"
+	// Model is the model object of _role.
 	Model = &arModel{g.DB("default").Table(Table).Safe()}
 )
 

+ 1 - 1
app/model/admin/sys_config/sys_config_entity.go

@@ -9,7 +9,7 @@ import (
 	"github.com/gogf/gf/database/gdb"
 )
 
-// Entity is the golang structure for table qxkj_sys_config.
+// Entity is the golang structure for table sys_config.
 type Entity struct {
 	ConfigId    uint   `orm:"config_id,primary" json:"config_id"`    // 参数主键
 	ConfigName  string `orm:"config_name"       json:"config_name"`  // 参数名称

+ 4 - 4
app/model/admin/sys_config/sys_config_model.go

@@ -11,15 +11,15 @@ import (
 	"time"
 )
 
-// arModel is a active record design model for table qxkj_sys_config operations.
+// arModel is a active record design model for table sys_config operations.
 type arModel struct {
 	M *gdb.Model
 }
 
 var (
-	// Table is the table name of qxkj_sys_config.
-	Table = "qxkj_sys_config"
-	// Model is the model object of qxkj_sys_config.
+	// Table is the table name of sys_config.
+	Table = "sys_config"
+	// Model is the model object of sys_config.
 	Model = &arModel{g.DB("default").Table(Table).Safe()}
 )
 

+ 1 - 1
app/model/admin/sys_dict_data/sys_dict_data_entity.go

@@ -9,7 +9,7 @@ import (
 	"github.com/gogf/gf/database/gdb"
 )
 
-// Entity is the golang structure for table qxkj_sys_dict_data.
+// Entity is the golang structure for table sys_dict_data.
 type Entity struct {
 	DictCode   int64  `orm:"dict_code,primary" json:"dict_code"`   // 字典编码
 	DictSort   int    `orm:"dict_sort"         json:"dict_sort"`   // 字典排序

+ 4 - 4
app/model/admin/sys_dict_data/sys_dict_data_model.go

@@ -11,15 +11,15 @@ import (
 	"time"
 )
 
-// arModel is a active record design model for table qxkj_sys_dict_data operations.
+// arModel is a active record design model for table sys_dict_data operations.
 type arModel struct {
 	M *gdb.Model
 }
 
 var (
-	// Table is the table name of qxkj_sys_dict_data.
-	Table = "qxkj_sys_dict_data"
-	// Model is the model object of qxkj_sys_dict_data.
+	// Table is the table name of sys_dict_data.
+	Table = "sys_dict_data"
+	// Model is the model object of sys_dict_data.
 	Model = &arModel{g.DB("default").Table(Table).Safe()}
 )
 

+ 1 - 1
app/model/admin/sys_dict_type/sys_dict_type_entity.go

@@ -9,7 +9,7 @@ import (
 	"github.com/gogf/gf/database/gdb"
 )
 
-// Entity is the golang structure for table qxkj_sys_dict_type.
+// Entity is the golang structure for table sys_dict_type.
 type Entity struct {
 	DictId     uint64 `orm:"dict_id,primary"  json:"dict_id"`     // 字典主键
 	DictName   string `orm:"dict_name"        json:"dict_name"`   // 字典名称

+ 4 - 4
app/model/admin/sys_dict_type/sys_dict_type_model.go

@@ -11,15 +11,15 @@ import (
 	"time"
 )
 
-// arModel is a active record design model for table qxkj_sys_dict_type operations.
+// arModel is a active record design model for table sys_dict_type operations.
 type arModel struct {
 	M *gdb.Model
 }
 
 var (
-	// Table is the table name of qxkj_sys_dict_type.
-	Table = "qxkj_sys_dict_type"
-	// Model is the model object of qxkj_sys_dict_type.
+	// Table is the table name of sys_dict_type.
+	Table = "sys_dict_type"
+	// Model is the model object of sys_dict_type.
 	Model = &arModel{g.DB("default").Table(Table).Safe()}
 )
 

+ 3 - 0
app/model/admin/sys_job/sys_job.go

@@ -0,0 +1,3 @@
+package sys_job
+
+// Fill with you ideas below.

+ 65 - 0
app/model/admin/sys_job/sys_job_entity.go

@@ -0,0 +1,65 @@
+// ==========================================================================
+// This is auto-generated by gf cli tool. You may not really want to edit it.
+// ==========================================================================
+
+package sys_job
+
+import (
+	"database/sql"
+	"github.com/gogf/gf/database/gdb"
+)
+
+// Entity is the golang structure for table sys_job.
+type Entity struct {
+	JobId          int64  `orm:"job_id,primary"    json:"job_id"`          // 任务ID
+	JobName        string `orm:"job_name,primary"  json:"job_name"`        // 任务名称
+	JobParams      string `orm:"job_params"        json:"job_params"`      // 参数
+	JobGroup       string `orm:"job_group,primary" json:"job_group"`       // 任务组名
+	InvokeTarget   string `orm:"invoke_target"     json:"invoke_target"`   // 调用目标字符串
+	CronExpression string `orm:"cron_expression"   json:"cron_expression"` // cron执行表达式
+	MisfirePolicy  int    `orm:"misfire_policy"    json:"misfire_policy"`  // 计划执行策略(1多次执行 2执行一次)
+	Concurrent     int    `orm:"concurrent"        json:"concurrent"`      // 是否并发执行(0允许 1禁止)
+	Status         int    `orm:"status"            json:"status"`          // 状态(0正常 1暂停)
+	CreateBy       uint64 `orm:"create_by"         json:"create_by"`       // 创建者
+	CreateTime     uint64 `orm:"create_time"       json:"create_time"`     // 创建时间
+	UpdateBy       uint64 `orm:"update_by"         json:"update_by"`       // 更新者
+	UpdateTime     uint64 `orm:"update_time"       json:"update_time"`     // 更新时间
+	Remark         string `orm:"remark"            json:"remark"`          // 备注信息
+}
+
+// OmitEmpty sets OPTION_OMITEMPTY option for the model, which automatically filers
+// the data and where attributes for empty values.
+func (r *Entity) OmitEmpty() *arModel {
+	return Model.Data(r).OmitEmpty()
+}
+
+// Inserts does "INSERT...INTO..." statement for inserting current object into table.
+func (r *Entity) Insert() (result sql.Result, err error) {
+	return Model.Data(r).Insert()
+}
+
+// Replace does "REPLACE...INTO..." statement for inserting current object into table.
+// If there's already another same record in the table (it checks using primary key or unique index),
+// it deletes it and insert this one.
+func (r *Entity) Replace() (result sql.Result, err error) {
+	return Model.Data(r).Replace()
+}
+
+// Save does "INSERT...INTO..." statement for inserting/updating current object into table.
+// It updates the record if there's already another same record in the table
+// (it checks using primary key or unique index).
+func (r *Entity) Save() (result sql.Result, err error) {
+	return Model.Data(r).Save()
+}
+
+// Update does "UPDATE...WHERE..." statement for updating current object from table.
+// It updates the record if there's already another same record in the table
+// (it checks using primary key or unique index).
+func (r *Entity) Update() (result sql.Result, err error) {
+	return Model.Data(r).Where(gdb.GetWhereConditionOfStruct(r)).Update()
+}
+
+// Delete does "DELETE FROM...WHERE..." statement for deleting current object from table.
+func (r *Entity) Delete() (result sql.Result, err error) {
+	return Model.Where(gdb.GetWhereConditionOfStruct(r)).Delete()
+}

+ 367 - 0
app/model/admin/sys_job/sys_job_model.go

@@ -0,0 +1,367 @@
+// ==========================================================================
+// This is auto-generated by gf cli tool. You may not really want to edit it.
+// ==========================================================================
+
+package sys_job
+
+import (
+	"database/sql"
+	"github.com/gogf/gf/database/gdb"
+	"github.com/gogf/gf/frame/g"
+	"time"
+)
+
+// arModel is a active record design model for table sys_job operations.
+type arModel struct {
+	M *gdb.Model
+}
+
+var (
+	// Table is the table name of sys_job.
+	Table = "sys_job"
+	// Model is the model object of sys_job.
+	Model = &arModel{g.DB("default").Table(Table).Safe()}
+)
+
+// FindOne is a convenience method for Model.FindOne.
+// See Model.FindOne.
+func FindOne(where ...interface{}) (*Entity, error) {
+	return Model.FindOne(where...)
+}
+
+// FindAll is a convenience method for Model.FindAll.
+// See Model.FindAll.
+func FindAll(where ...interface{}) ([]*Entity, error) {
+	return Model.FindAll(where...)
+}
+
+// FindValue is a convenience method for Model.FindValue.
+// See Model.FindValue.
+func FindValue(fieldsAndWhere ...interface{}) (gdb.Value, error) {
+	return Model.FindValue(fieldsAndWhere...)
+}
+
+// FindCount is a convenience method for Model.FindCount.
+// See Model.FindCount.
+func FindCount(where ...interface{}) (int, error) {
+	return Model.FindCount(where...)
+}
+
+// Insert is a convenience method for Model.Insert.
+func Insert(data ...interface{}) (result sql.Result, err error) {
+	return Model.Insert(data...)
+}
+
+// Replace is a convenience method for Model.Replace.
+func Replace(data ...interface{}) (result sql.Result, err error) {
+	return Model.Replace(data...)
+}
+
+// Save is a convenience method for Model.Save.
+func Save(data ...interface{}) (result sql.Result, err error) {
+	return Model.Save(data...)
+}
+
+// Update is a convenience method for Model.Update.
+func Update(dataAndWhere ...interface{}) (result sql.Result, err error) {
+	return Model.Update(dataAndWhere...)
+}
+
+// Delete is a convenience method for Model.Delete.
+func Delete(where ...interface{}) (result sql.Result, err error) {
+	return Model.Delete(where...)
+}
+
+// As sets an alias name for current table.
+func (m *arModel) As(as string) *arModel {
+	return &arModel{m.M.As(as)}
+}
+
+// TX sets the transaction for current operation.
+func (m *arModel) TX(tx *gdb.TX) *arModel {
+	return &arModel{m.M.TX(tx)}
+}
+
+// Master marks the following operation on master node.
+func (m *arModel) Master() *arModel {
+	return &arModel{m.M.Master()}
+}
+
+// Slave marks the following operation on slave node.
+// Note that it makes sense only if there's any slave node configured.
+func (m *arModel) Slave() *arModel {
+	return &arModel{m.M.Slave()}
+}
+
+// LeftJoin does "LEFT JOIN ... ON ..." statement on the model.
+func (m *arModel) LeftJoin(joinTable string, on string) *arModel {
+	return &arModel{m.M.LeftJoin(joinTable, on)}
+}
+
+// RightJoin does "RIGHT JOIN ... ON ..." statement on the model.
+func (m *arModel) RightJoin(joinTable string, on string) *arModel {
+	return &arModel{m.M.RightJoin(joinTable, on)}
+}
+
+// InnerJoin does "INNER JOIN ... ON ..." statement on the model.
+func (m *arModel) InnerJoin(joinTable string, on string) *arModel {
+	return &arModel{m.M.InnerJoin(joinTable, on)}
+}
+
+// Fields sets the operation fields of the model, multiple fields joined using char ','.
+func (m *arModel) Fields(fields string) *arModel {
+	return &arModel{m.M.Fields(fields)}
+}
+
+// FieldsEx sets the excluded operation fields of the model, multiple fields joined using char ','.
+func (m *arModel) FieldsEx(fields string) *arModel {
+	return &arModel{m.M.FieldsEx(fields)}
+}
+
+// Option sets the extra operation option for the model.
+func (m *arModel) Option(option int) *arModel {
+	return &arModel{m.M.Option(option)}
+}
+
+// OmitEmpty sets OPTION_OMITEMPTY option for the model, which automatically filers
+// the data and where attributes for empty values.
+func (m *arModel) OmitEmpty() *arModel {
+	return &arModel{m.M.OmitEmpty()}
+}
+
+// Filter marks filtering the fields which does not exist in the fields of the operated table.
+func (m *arModel) Filter() *arModel {
+	return &arModel{m.M.Filter()}
+}
+
+// Where sets the condition statement for the model. The parameter <where> can be type of
+// string/map/gmap/slice/struct/*struct, etc. Note that, if it's called more than one times,
+// multiple conditions will be joined into where statement using "AND".
+// Eg:
+// Where("uid=10000")
+// Where("uid", 10000)
+// Where("money>? AND name like ?", 99999, "vip_%")
+// Where("uid", 1).Where("name", "john")
+// Where("status IN (?)", g.Slice{1,2,3})
+// Where("age IN(?,?)", 18, 50)
+// Where(User{ Id : 1, UserName : "john"})
+func (m *arModel) Where(where interface{}, args ...interface{}) *arModel {
+	return &arModel{m.M.Where(where, args...)}
+}
+
+// And adds "AND" condition to the where statement.
+func (m *arModel) And(where interface{}, args ...interface{}) *arModel {
+	return &arModel{m.M.And(where, args...)}
+}
+
+// Or adds "OR" condition to the where statement.
+func (m *arModel) Or(where interface{}, args ...interface{}) *arModel {
+	return &arModel{m.M.Or(where, args...)}
+}
+
+// Group sets the "GROUP BY" statement for the model.
+func (m *arModel) Group(groupBy string) *arModel {
+	return &arModel{m.M.Group(groupBy)}
+}
+
+// Order sets the "ORDER BY" statement for the model.
+func (m *arModel) Order(orderBy string) *arModel {
+	return &arModel{m.M.Order(orderBy)}
+}
+
+// Limit sets the "LIMIT" statement for the model.
+// The parameter <limit> can be either one or two number, if passed two number is passed,
+// it then sets "LIMIT limit[0],limit[1]" statement for the model, or else it sets "LIMIT limit[0]"
+// statement.
+func (m *arModel) Limit(limit ...int) *arModel {
+	return &arModel{m.M.Limit(limit...)}
+}
+
+// Offset sets the "OFFSET" statement for the model.
+// It only makes sense for some databases like SQLServer, PostgreSQL, etc.
+func (m *arModel) Offset(offset int) *arModel {
+	return &arModel{m.M.Offset(offset)}
+}
+
+// Page sets the paging number for the model.
+// The parameter <page> is started from 1 for paging.
+// Note that, it differs that the Limit function start from 0 for "LIMIT" statement.
+func (m *arModel) Page(page, limit int) *arModel {
+	return &arModel{m.M.Page(page, limit)}
+}
+
+// Batch sets the batch operation number for the model.
+func (m *arModel) Batch(batch int) *arModel {
+	return &arModel{m.M.Batch(batch)}
+}
+
+// Cache sets the cache feature for the model. It caches the result of the sql, which means
+// if there's another same sql request, it just reads and returns the result from cache, it
+// but not committed and executed into the database.
+//
+// If the parameter <duration> < 0, which means it clear the cache with given <name>.
+// If the parameter <duration> = 0, which means it never expires.
+// If the parameter <duration> > 0, which means it expires after <duration>.
+//
+// The optional parameter <name> is used to bind a name to the cache, which means you can later
+// control the cache like changing the <duration> or clearing the cache with specified <name>.
+//
+// Note that, the cache feature is disabled if the model is operating on a transaction.
+func (m *arModel) Cache(expire time.Duration, name ...string) *arModel {
+	return &arModel{m.M.Cache(expire, name...)}
+}
+
+// Data sets the operation data for the model.
+// The parameter <data> can be type of string/map/gmap/slice/struct/*struct, etc.
+// Eg:
+// Data("uid=10000")
+// Data("uid", 10000)
+// Data(g.Map{"uid": 10000, "name":"john"})
+// Data(g.Slice{g.Map{"uid": 10000, "name":"john"}, g.Map{"uid": 20000, "name":"smith"})
+func (m *arModel) Data(data ...interface{}) *arModel {
+	return &arModel{m.M.Data(data...)}
+}
+
+// Insert does "INSERT INTO ..." statement for the model.
+// The optional parameter <data> is the same as the parameter of Model.Data function,
+// see Model.Data.
+func (m *arModel) Insert(data ...interface{}) (result sql.Result, err error) {
+	return m.M.Insert(data...)
+}
+
+// Replace does "REPLACE INTO ..." statement for the model.
+// The optional parameter <data> is the same as the parameter of Model.Data function,
+// see Model.Data.
+func (m *arModel) Replace(data ...interface{}) (result sql.Result, err error) {
+	return m.M.Replace(data...)
+}
+
+// Save does "INSERT INTO ... ON DUPLICATE KEY UPDATE..." statement for the model.
+// It updates the record if there's primary or unique index in the saving data,
+// or else it inserts a new record into the table.
+//
+// The optional parameter <data> is the same as the parameter of Model.Data function,
+// see Model.Data.
+func (m *arModel) Save(data ...interface{}) (result sql.Result, err error) {
+	return m.M.Save(data...)
+}
+
+// Update does "UPDATE ... " statement for the model.
+//
+// If the optional parameter <dataAndWhere> is given, the dataAndWhere[0] is the updated
+// data field, and dataAndWhere[1:] is treated as where condition fields.
+// Also see Model.Data and Model.Where functions.
+func (m *arModel) Update(dataAndWhere ...interface{}) (result sql.Result, err error) {
+	return m.M.Update(dataAndWhere...)
+}
+
+// Delete does "DELETE FROM ... " statement for the model.
+// The optional parameter <where> is the same as the parameter of Model.Where function,
+// see Model.Where.
+func (m *arModel) Delete(where ...interface{}) (result sql.Result, err error) {
+	return m.M.Delete(where...)
+}
+
+// Count does "SELECT COUNT(x) FROM ..." statement for the model.
+// The optional parameter <where> is the same as the parameter of Model.Where function,
+// see Model.Where.
+func (m *arModel) Count(where ...interface{}) (int, error) {
+	return m.M.Count(where...)
+}
+
+// All does "SELECT FROM ..." statement for the model.
+// It retrieves the records from table and returns the result as []*Entity.
+// It returns nil if there's no record retrieved with the given conditions from table.
+//
+// The optional parameter <where> is the same as the parameter of Model.Where function,
+// see Model.Where.
+func (m *arModel) All(where ...interface{}) ([]*Entity, error) {
+	all, err := m.M.All(where...)
+	if err != nil {
+		return nil, err
+	}
+	var entities []*Entity
+	if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
+		return nil, err
+	}
+	return entities, nil
+}
+
+// One retrieves one record from table and returns the result as *Entity.
+// It returns nil if there's no record retrieved with the given conditions from table.
+//
+// The optional parameter <where> is the same as the parameter of Model.Where function,
+// see Model.Where.
+func (m *arModel) One(where ...interface{}) (*Entity, error) {
+	one, err := m.M.One(where...)
+	if err != nil {
+		return nil, err
+	}
+	var entity *Entity
+	if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
+		return nil, err
+	}
+	return entity, nil
+}
+
+// Value retrieves a specified record value from table and returns the result as interface type.
+// It returns nil if there's no record found with the given conditions from table.
+//
+// If the optional parameter <fieldsAndWhere> is given, the fieldsAndWhere[0] is the selected fields
+// and fieldsAndWhere[1:] is treated as where condition fields.
+// Also see Model.Fields and Model.Where functions.
+func (m *arModel) Value(fieldsAndWhere ...interface{}) (gdb.Value, error) {
+	return m.M.Value(fieldsAndWhere...)
+}
+
+// FindOne retrieves and returns a single Record by Model.WherePri and Model.One.
+// Also see Model.WherePri and Model.One.
+func (m *arModel) FindOne(where ...interface{}) (*Entity, error) {
+	one, err := m.M.FindOne(where...)
+	if err != nil {
+		return nil, err
+	}
+	var entity *Entity
+	if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
+		return nil, err
+	}
+	return entity, nil
+}
+
+// FindAll retrieves and returns Result by by Model.WherePri and Model.All.
+// Also see Model.WherePri and Model.All.
+func (m *arModel) FindAll(where ...interface{}) ([]*Entity, error) {
+	all, err := m.M.FindAll(where...)
+	if err != nil {
+		return nil, err
+	}
+	var entities []*Entity
+	if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
+		return nil, err
+	}
+	return entities, nil
+}
+
+// FindValue retrieves and returns single field value by Model.WherePri and Model.Value.
+// Also see Model.WherePri and Model.Value.
+func (m *arModel) FindValue(fieldsAndWhere ...interface{}) (gdb.Value, error) {
+	return m.M.FindValue(fieldsAndWhere...)
+}
+
+// FindCount retrieves and returns the record number by Model.WherePri and Model.Count.
+// Also see Model.WherePri and Model.Count.
+func (m *arModel) FindCount(where ...interface{}) (int, error) {
+	return m.M.FindCount(where...)
+}
+
+// Chunk iterates the table with given size and callback function.
+func (m *arModel) Chunk(limit int, callback func(entities []*Entity, err error) bool) {
+	m.M.Chunk(limit, func(result gdb.Result, err error) bool {
+		var entities []*Entity
+		err = result.Structs(&entities)
+		if err == sql.ErrNoRows {
+			return false
+		}
+		return callback(entities, err)
+	})
+}

+ 3 - 3
app/model/admin/user/user_entity.go

@@ -9,7 +9,7 @@ import (
 	"github.com/gogf/gf/database/gdb"
 )
 
-// Entity is the golang structure for table qxkj_user.
+// Entity is the golang structure for table user.
 type Entity struct {
 	Id            int    `orm:"id,primary"       json:"id"`              //
 	UserName      string `orm:"user_name,unique" json:"user_name"`       // 用户名
@@ -26,8 +26,8 @@ type Entity struct {
 	LastLoginIp   string `orm:"last_login_ip"    json:"last_login_ip"`   // 最后登录ip
 }
 
-// QxkjUser is alias of Entity, which some developers say they just want.
-type QxkjUser = Entity
+// User is alias of Entity, which some developers say they just want.
+type User = Entity
 
 // OmitEmpty sets OPTION_OMITEMPTY option for the model, which automatically filers
 // the data and where attributes for empty values.

+ 4 - 4
app/model/admin/user/user_model.go

@@ -11,15 +11,15 @@ import (
 	"time"
 )
 
-// arModel is a active record design model for table qxkj_user operations.
+// arModel is a active record design model for table user operations.
 type arModel struct {
 	Model *gdb.Model
 }
 
 var (
-	// Table is the table name of qxkj_user.
-	Table = "qxkj_user"
-	// Model is the model object of qxkj_user.
+	// Table is the table name of user.
+	Table = "user"
+	// Model is the model object of user.
 	Model = &arModel{g.DB("default").Table(Table).Safe()}
 )
 

+ 1 - 1
app/model/admin/user_online/user_online_entity.go

@@ -9,7 +9,7 @@ import (
 	"github.com/gogf/gf/database/gdb"
 )
 
-// Entity is the golang structure for table qxkj_user_online.
+// Entity is the golang structure for table user_online.
 type Entity struct {
 	Id         uint   `orm:"id,primary"   json:"id"`          //
 	Uuid       string `orm:"uuid"         json:"uuid"`        // 用户标识

+ 4 - 4
app/model/admin/user_online/user_online_model.go

@@ -11,15 +11,15 @@ import (
 	"time"
 )
 
-// arModel is a active record design model for table qxkj_user_online operations.
+// arModel is a active record design model for table user_online operations.
 type arModel struct {
 	M *gdb.Model
 }
 
 var (
-	// Table is the table name of qxkj_user_online.
-	Table = "qxkj_user_online"
-	// Model is the model object of qxkj_user_online.
+	// Table is the table name of user_online.
+	Table = "user_online"
+	// Model is the model object of _user_online.
 	Model = &arModel{g.DB("default").Table(Table).Safe()}
 )
 

+ 25 - 1
app/service/admin/surveillance_service/online.go → app/service/admin/monitor_service/online.go

@@ -1,4 +1,4 @@
-package surveillance_service
+package monitor_service
 
 import (
 	"gfast/app/model/admin/user_online"
@@ -89,3 +89,27 @@ func GetUuidUserKeyByToken(token string) (uuid, userKey string) {
 	uuid = decryptToken.GetString("uuid")
 	return
 }
+
+//强制退出操作
+func ForceLogout(ids []int) error {
+	for _, id := range ids {
+		entity, err := user_online.Model.FindOne("id", id)
+		if err != nil {
+			g.Log().Error(err)
+		}
+		if err != nil || entity == nil {
+			return gerror.New("获取用户在线信息失败")
+		}
+		_, userKey := GetUuidUserKeyByToken(entity.Token)
+		if userKey == "" {
+			return gerror.New("用户信息获取失败")
+		}
+		userKey = boot.AdminGfToken.CacheKey + userKey
+		_, err = g.Redis().Do("DEL", userKey)
+		if err != nil {
+			return err
+		}
+		entity.Delete()
+	}
+	return nil
+}

Разлика између датотеке није приказан због своје велике величине
+ 0 - 79
data/db.sql


+ 8 - 8
library/utils/function.go

@@ -195,23 +195,23 @@ func DecryptCBC(plainText, publicKey string) string {
 }
 
 // 用户登录,成功返回用户信息,否则返回nil
-func signIn(username, password string, r *ghttp.Request) (error, *user.QxkjUser) {
-	qxkjUser, err := user.Model.Where("user_name=? and user_password=?", username, password).One()
+func signIn(username, password string, r *ghttp.Request) (error, *user.User) {
+	user, err := user.Model.Where("user_name=? and user_password=?", username, password).One()
 	if err != nil && err != sql.ErrNoRows {
 		return err, nil
 	}
-	if qxkjUser == nil {
+	if user == nil {
 		return errors.New("账号或密码错误"), nil
 	}
 	//判断用户状态
-	if qxkjUser.UserStatus == 0 {
+	if user.UserStatus == 0 {
 		return errors.New("用户已被冻结"), nil
 	}
-	returnData := *qxkjUser
+	returnData := *user
 	//更新登陆时间及ip
-	qxkjUser.LastLoginTime = gconv.Int(gtime.Timestamp())
-	qxkjUser.LastLoginIp = r.GetClientIp()
-	qxkjUser.Update()
+	user.LastLoginTime = gconv.Int(gtime.Timestamp())
+	user.LastLoginIp = r.GetClientIp()
+	user.Update()
 	return nil, &returnData
 }
 

+ 1 - 1
router/middleware.go → middleWare/middleware.go

@@ -1,4 +1,4 @@
-package router
+package middleWare
 
 import (
 	"fmt"

+ 5 - 4
router/router.go

@@ -2,6 +2,7 @@ package router
 
 import (
 	"gfast/app/controller/admin"
+	"gfast/middleWare"
 	"github.com/gogf/gf/frame/g"
 	"github.com/gogf/gf/net/ghttp"
 )
@@ -9,13 +10,13 @@ import (
 // 统一路由注册.
 func init() {
 	s := g.Server()
-	s.Use(MiddlewareCORS)
+	s.Use(middleWare.MiddlewareCORS)
 	group := s.Group("/")
 	group.Group("/sysLogin", func(group *ghttp.RouterGroup) {
 		group.ALL("/public", new(admin.Public))
 	})
 	group.Group("/system", func(group *ghttp.RouterGroup) {
-		group.Middleware(MiddlewareAuth) //后台权限验证
+		group.Middleware(middleWare.MiddlewareAuth) //后台权限验证
 		group.ALL("/index", new(admin.Index))
 		group.ALL("/auth", new(admin.Auth))
 
@@ -29,8 +30,8 @@ func init() {
 			group.ALL("/params", new(admin.Params))
 		})
 
-		group.Group("/surveillance", func(group *ghttp.RouterGroup) {
-			group.ALL("/online", new(admin.SurveillanceOnline))
+		group.Group("/monitor", func(group *ghttp.RouterGroup) {
+			group.ALL("/online", new(admin.MonitorOnline))
 		})
 	})
 

+ 12 - 16
test/demo2_test.go

@@ -1,9 +1,8 @@
 package test
 
 import (
+	"fmt"
 	"github.com/gogf/gf/frame/g"
-	"github.com/gogf/gf/net/ghttp"
-	"github.com/gogf/gf/os/glog"
 	"testing"
 )
 
@@ -12,18 +11,15 @@ func TestDemo2(t *testing.T) {
 }
 
 func test21(t *testing.T) {
-	// 基本事件回调使用
-	p := "/:name/info/{uid}"
-	s := g.Server()
-	s.BindHookHandlerByMap(p, map[string]ghttp.HandlerFunc{
-		ghttp.HOOK_BEFORE_SERVE:  func(r *ghttp.Request) { glog.Println(ghttp.HOOK_BEFORE_SERVE) },
-		ghttp.HOOK_AFTER_SERVE:   func(r *ghttp.Request) { glog.Println(ghttp.HOOK_AFTER_SERVE) },
-		ghttp.HOOK_BEFORE_OUTPUT: func(r *ghttp.Request) { glog.Println(ghttp.HOOK_BEFORE_OUTPUT) },
-		ghttp.HOOK_AFTER_OUTPUT:  func(r *ghttp.Request) { glog.Println(ghttp.HOOK_AFTER_OUTPUT) },
-	})
-	s.BindHandler(p, func(r *ghttp.Request) {
-		r.Response.Write("用户:", r.Get("name"), ", uid:", r.Get("uid"))
-	})
-	s.SetPort(8299)
-	s.Run()
+	c := make(chan bool)
+	for i := 0; i < 10000; i++ {
+		go func() {
+			i, e := g.Redis().Do("get", "GToken:adminIJ1xz+Wve+ZONVMFfXJQMw==50607842719694a7380dc72aacc4a0b4")
+			if e != nil {
+				fmt.Println(e)
+			}
+			fmt.Println(string(i.([]byte)))
+		}()
+	}
+	<-c
 }

Неке датотеке нису приказане због велике количине промена