From 8ea20bdcc450f9e1f2f32b89ec06d27b5d222097 Mon Sep 17 00:00:00 2001 From: yxh Date: Mon, 9 Mar 2020 18:14:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=A8=E7=BA=BF=E7=94=A8=E6=88=B7=E5=BC=BA?= =?UTF-8?q?=E9=80=80=EF=BC=8C=E5=88=A0=E9=99=A4=E6=95=B0=E6=8D=AE=E5=BA=93?= =?UTF-8?q?=E8=A1=A8=E5=89=8D=E7=BC=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/admin/monitor_job.go | 13 + ...rveillance_online.go => monitor_online.go} | 20 +- app/model/admin/auth_rule/auth_rule_entity.go | 2 +- app/model/admin/auth_rule/auth_rule_model.go | 8 +- .../admin/cms_category/cms_category_entity.go | 2 +- .../admin/cms_category/cms_category_model.go | 8 +- app/model/admin/role/role_entity.go | 6 +- app/model/admin/role/role_model.go | 8 +- .../admin/sys_config/sys_config_entity.go | 2 +- .../admin/sys_config/sys_config_model.go | 8 +- .../sys_dict_data/sys_dict_data_entity.go | 2 +- .../sys_dict_data/sys_dict_data_model.go | 8 +- .../sys_dict_type/sys_dict_type_entity.go | 2 +- .../sys_dict_type/sys_dict_type_model.go | 8 +- app/model/admin/sys_job/sys_job.go | 3 + app/model/admin/sys_job/sys_job_entity.go | 65 ++++ app/model/admin/sys_job/sys_job_model.go | 367 ++++++++++++++++++ app/model/admin/user/user_entity.go | 6 +- app/model/admin/user/user_model.go | 8 +- .../admin/user_online/user_online_entity.go | 2 +- .../admin/user_online/user_online_model.go | 8 +- .../online.go | 26 +- data/db.sql | 360 ----------------- library/utils/function.go | 16 +- {router => middleWare}/middleware.go | 2 +- router/router.go | 9 +- test/demo2_test.go | 28 +- 27 files changed, 559 insertions(+), 438 deletions(-) create mode 100644 app/controller/admin/monitor_job.go rename app/controller/admin/{surveillance_online.go => monitor_online.go} (53%) create mode 100644 app/model/admin/sys_job/sys_job.go create mode 100644 app/model/admin/sys_job/sys_job_entity.go create mode 100644 app/model/admin/sys_job/sys_job_model.go rename app/service/admin/{surveillance_service => monitor_service}/online.go (79%) delete mode 100644 data/db.sql rename {router => middleWare}/middleware.go (99%) diff --git a/app/controller/admin/monitor_job.go b/app/controller/admin/monitor_job.go new file mode 100644 index 0000000..5169610 --- /dev/null +++ b/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) { + +} diff --git a/app/controller/admin/surveillance_online.go b/app/controller/admin/monitor_online.go similarity index 53% rename from app/controller/admin/surveillance_online.go rename to app/controller/admin/monitor_online.go index 668f3b6..4f197d4 100644 --- a/app/controller/admin/surveillance_online.go +++ b/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, "用户已退出") +} diff --git a/app/model/admin/auth_rule/auth_rule_entity.go b/app/model/admin/auth_rule/auth_rule_entity.go index 7eb6373..7957102 100644 --- a/app/model/admin/auth_rule/auth_rule_entity.go +++ b/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为权限节点 diff --git a/app/model/admin/auth_rule/auth_rule_model.go b/app/model/admin/auth_rule/auth_rule_model.go index 4a2276b..545f3a5 100644 --- a/app/model/admin/auth_rule/auth_rule_model.go +++ b/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()} ) diff --git a/app/model/admin/cms_category/cms_category_entity.go b/app/model/admin/cms_category/cms_category_entity.go index c0d1006..d043a67 100644 --- a/app/model/admin/cms_category/cms_category_entity.go +++ b/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 diff --git a/app/model/admin/cms_category/cms_category_model.go b/app/model/admin/cms_category/cms_category_model.go index f9e40db..2ae6b74 100644 --- a/app/model/admin/cms_category/cms_category_model.go +++ b/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()} ) diff --git a/app/model/admin/role/role_entity.go b/app/model/admin/role/role_entity.go index 6da8311..344d713 100644 --- a/app/model/admin/role/role_entity.go +++ b/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. diff --git a/app/model/admin/role/role_model.go b/app/model/admin/role/role_model.go index e8ce62d..1789509 100644 --- a/app/model/admin/role/role_model.go +++ b/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()} ) diff --git a/app/model/admin/sys_config/sys_config_entity.go b/app/model/admin/sys_config/sys_config_entity.go index c6ef9e9..43dc7bf 100644 --- a/app/model/admin/sys_config/sys_config_entity.go +++ b/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"` // 参数名称 diff --git a/app/model/admin/sys_config/sys_config_model.go b/app/model/admin/sys_config/sys_config_model.go index 5174563..122d086 100644 --- a/app/model/admin/sys_config/sys_config_model.go +++ b/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()} ) diff --git a/app/model/admin/sys_dict_data/sys_dict_data_entity.go b/app/model/admin/sys_dict_data/sys_dict_data_entity.go index 3786390..f1c633e 100644 --- a/app/model/admin/sys_dict_data/sys_dict_data_entity.go +++ b/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"` // 字典排序 diff --git a/app/model/admin/sys_dict_data/sys_dict_data_model.go b/app/model/admin/sys_dict_data/sys_dict_data_model.go index bf21a80..e47fb2f 100644 --- a/app/model/admin/sys_dict_data/sys_dict_data_model.go +++ b/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()} ) diff --git a/app/model/admin/sys_dict_type/sys_dict_type_entity.go b/app/model/admin/sys_dict_type/sys_dict_type_entity.go index 8f1381c..24e7f21 100644 --- a/app/model/admin/sys_dict_type/sys_dict_type_entity.go +++ b/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"` // 字典名称 diff --git a/app/model/admin/sys_dict_type/sys_dict_type_model.go b/app/model/admin/sys_dict_type/sys_dict_type_model.go index cb857d1..9f1bbb8 100644 --- a/app/model/admin/sys_dict_type/sys_dict_type_model.go +++ b/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()} ) diff --git a/app/model/admin/sys_job/sys_job.go b/app/model/admin/sys_job/sys_job.go new file mode 100644 index 0000000..5258f82 --- /dev/null +++ b/app/model/admin/sys_job/sys_job.go @@ -0,0 +1,3 @@ +package sys_job + +// Fill with you ideas below. diff --git a/app/model/admin/sys_job/sys_job_entity.go b/app/model/admin/sys_job/sys_job_entity.go new file mode 100644 index 0000000..1d2f1f8 --- /dev/null +++ b/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() +} diff --git a/app/model/admin/sys_job/sys_job_model.go b/app/model/admin/sys_job/sys_job_model.go new file mode 100644 index 0000000..32b0d55 --- /dev/null +++ b/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 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 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 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 < 0, which means it clear the cache with given . +// If the parameter = 0, which means it never expires. +// If the parameter > 0, which means it expires after . +// +// The optional parameter is used to bind a name to the cache, which means you can later +// control the cache like changing the or clearing the cache with specified . +// +// 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 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 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 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 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 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 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 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 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 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 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) + }) +} diff --git a/app/model/admin/user/user_entity.go b/app/model/admin/user/user_entity.go index 31dbef3..b92cdd7 100644 --- a/app/model/admin/user/user_entity.go +++ b/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. diff --git a/app/model/admin/user/user_model.go b/app/model/admin/user/user_model.go index 116d4d5..011928e 100644 --- a/app/model/admin/user/user_model.go +++ b/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()} ) diff --git a/app/model/admin/user_online/user_online_entity.go b/app/model/admin/user_online/user_online_entity.go index 022b9df..e315ed6 100644 --- a/app/model/admin/user_online/user_online_entity.go +++ b/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"` // 用户标识 diff --git a/app/model/admin/user_online/user_online_model.go b/app/model/admin/user_online/user_online_model.go index 407bcd8..78072a0 100644 --- a/app/model/admin/user_online/user_online_model.go +++ b/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()} ) diff --git a/app/service/admin/surveillance_service/online.go b/app/service/admin/monitor_service/online.go similarity index 79% rename from app/service/admin/surveillance_service/online.go rename to app/service/admin/monitor_service/online.go index b586870..6faf984 100644 --- a/app/service/admin/surveillance_service/online.go +++ b/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 +} diff --git a/data/db.sql b/data/db.sql deleted file mode 100644 index b94d3ec..0000000 --- a/data/db.sql +++ /dev/null @@ -1,360 +0,0 @@ --- MySQL dump 10.13 Distrib 5.6.26, for Win64 (x86_64) --- --- Host: localhost Database: gfast --- ------------------------------------------------------ --- Server version 5.6.26 - -/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; -/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; -/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; -/*!40101 SET NAMES utf8 */; -/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; -/*!40103 SET TIME_ZONE='+00:00' */; -/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; -/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; -/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; -/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; - --- --- Table structure for table `casbin_rule` --- - -DROP TABLE IF EXISTS `casbin_rule`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `casbin_rule` ( - `ptype` varchar(10) DEFAULT NULL, - `v0` varchar(256) DEFAULT NULL, - `v1` varchar(256) DEFAULT NULL, - `v2` varchar(256) DEFAULT NULL, - `v3` varchar(256) DEFAULT NULL, - `v4` varchar(256) DEFAULT NULL, - `v5` varchar(256) DEFAULT NULL -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `casbin_rule` --- - -LOCK TABLES `casbin_rule` WRITE; -/*!40000 ALTER TABLE `casbin_rule` DISABLE KEYS */; -INSERT INTO `casbin_rule` VALUES ('p','g_2','r_5','All','','',''),('p','g_2','r_9','All','','',''),('p','g_2','r_41','All','','',''),('p','g_2','r_42','All','','',''),('p','g_2','r_43','All','','',''),('p','g_2','r_10','All','','',''),('p','g_2','r_11','All','','',''),('p','g_2','r_47','All','','',''),('p','g_2','r_48','All','','',''),('p','g_2','r_49','All','','',''),('p','g_2','r_12','All','','',''),('p','g_2','r_50','All','','',''),('p','g_2','r_51','All','','',''),('p','g_2','r_52','All','','',''),('p','g_2','r_53','All','','',''),('p','g_2','r_57','All','','',''),('p','g_2','r_58','All','','',''),('p','g_2','r_59','All','','',''),('p','g_2','r_60','All','','',''),('p','g_2','r_61','All','','',''),('p','g_2','r_62','All','','',''),('g','u_31','g_1','','','',''),('g','u_31','g_2','','','',''),('p','g_1','r_46','All','','',''),('p','g_1','r_63','All','','',''),('p','g_1','r_64','All','','',''),('p','g_1','r_65','All','','',''),('p','g_1','r_5','All','','',''),('p','g_1','r_9','All','','',''),('p','g_1','r_41','All','','',''),('p','g_1','r_42','All','','',''),('p','g_1','r_43','All','','',''),('p','g_1','r_10','All','','',''),('p','g_1','r_11','All','','',''),('p','g_1','r_47','All','','',''),('p','g_1','r_48','All','','',''),('p','g_1','r_49','All','','',''),('p','g_1','r_12','All','','',''),('p','g_1','r_50','All','','',''),('p','g_1','r_51','All','','',''),('p','g_1','r_52','All','','',''),('p','g_1','r_53','All','','',''),('p','g_1','r_57','All','','',''),('p','g_1','r_58','All','','',''),('p','g_1','r_59','All','','',''),('p','g_1','r_60','All','','',''),('p','g_1','r_61','All','','',''),('p','g_1','r_62','All','','',''),('p','g_8','r_46','All','','',''); -/*!40000 ALTER TABLE `casbin_rule` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `qxkj_auth_rule` --- - -DROP TABLE IF EXISTS `qxkj_auth_rule`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `qxkj_auth_rule` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `type` enum('menu','file') NOT NULL DEFAULT 'file' COMMENT 'menu为菜单,file为权限节点', - `pid` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '父ID', - `name` varchar(100) NOT NULL DEFAULT '' COMMENT '规则名称', - `title` varchar(50) NOT NULL DEFAULT '' COMMENT '规则名称', - `icon` varchar(50) NOT NULL DEFAULT '' COMMENT '图标', - `condition` varchar(255) NOT NULL DEFAULT '' COMMENT '条件', - `remark` varchar(255) NOT NULL DEFAULT '' COMMENT '备注', - `ismenu` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '是否为菜单', - `createtime` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '创建时间', - `updatetime` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '更新时间', - `weigh` int(10) NOT NULL DEFAULT '0' COMMENT '权重', - `status` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT '状态', - PRIMARY KEY (`id`), - UNIQUE KEY `name` (`name`) USING BTREE, - KEY `pid` (`pid`), - KEY `weigh` (`weigh`) -) ENGINE=MyISAM AUTO_INCREMENT=66 DEFAULT CHARSET=utf8mb4 ROW_FORMAT=COMPACT COMMENT='菜单节点表'; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `qxkj_auth_rule` --- - -LOCK TABLES `qxkj_auth_rule` WRITE; -/*!40000 ALTER TABLE `qxkj_auth_rule` DISABLE KEYS */; -INSERT INTO `qxkj_auth_rule` VALUES (5,'file',0,'/system/auth','权限管理','fa fa-users','','',1,1497429920,1582706271,80,1),(9,'file',5,'/system/auth/user-list','管理员管理','fa fa-user','','Admin tips',1,1497429920,1497430320,118,1),(10,'file',5,'/system/auth/adminlog','管理员日志','fa fa-list-alt','','Admin log tips',1,1497429920,1582731276,113,1),(11,'file',5,'/system/auth/role-list','角色组','fa fa-group','','Group tips',1,1497429920,1582706904,109,1),(12,'file',5,'/system/auth/menu-list','菜单规则','fa fa-bars','','Rule tips',1,1497429920,1582731459,104,1),(43,'file',9,'/system/auth/delete-admin','删除','fa fa-circle-o','','',0,1497429920,1582706783,1,1),(42,'file',9,'/system/auth/edit-user','修改','fa fa-circle-o','','',0,1497429920,1582706817,2,1),(41,'file',9,'/system/auth/add-user','添加','fa fa-circle-o','','',0,1497429920,1582726029,3,1),(47,'file',11,'/system/auth/add-role','添加角色','el-icon-document-add','','',0,1582706959,1582706959,50,1),(50,'file',12,'/system/auth/add-menu','添加菜单','el-icon-document-add','','',0,1582726105,1582726105,50,1),(46,'file',0,'/system/index/index','系统首页','el-icon-s-grid','noCheck','',1,1582704520,1582726295,100,1),(48,'file',11,'/system/auth/edit-role','修改角色','fa fa-pencil','','',0,1582706999,1582726035,50,1),(49,'file',11,'/system/auth/delete-role','删除角色','fa fa-institution','','',0,1582707051,1582726040,50,1),(51,'file',12,'/system/auth/edit-menu','修改菜单','fa fa-pencil','','',0,1582726145,1582726145,50,1),(52,'file',12,'/system/auth/delete-menu','删除菜单','fa fa-institution','','',0,1582726194,1582726194,50,1),(53,'file',12,'/system/auth/menu-sort','菜单排序','fa fa-list-ul','','',0,1582726229,1582726229,50,1),(57,'file',0,'/system/cms','CMS管理','fa fa-list','','',1,1582731636,1582731636,70,1),(58,'file',57,'/system/cms/menu-list','栏目管理','fa fa-list-ul','','',1,1582731762,1582732995,50,1),(59,'file',57,'/system/cms/news-list','内容管理','fa fa-th-list','','',1,1582731800,1582733003,50,1),(60,'file',57,'/system/cms/mode-list','模型管理','fa fa-codepen','','',1,1582731832,1582733011,50,1),(61,'file',57,'/system/cms/special-list','专题管理','fa fa-hand-pointer-o','','',1,1582732334,1582733018,50,1),(62,'file',57,'/system/cms/single-list','单页管理','fa fa-file-o','','',1,1582732373,1582733025,50,1),(63,'file',0,'/system/config','系统配置','fa fa-wrench','','',1,1582773590,1582773600,90,1),(64,'file',63,'/system/config/dict/list','字典管理','fa fa-sitemap','','',1,1582773640,1583457951,50,1),(65,'file',63,'/system/config/params/list','参数管理','fa fa-list-ul','','',1,1582773725,1583457960,50,1); -/*!40000 ALTER TABLE `qxkj_auth_rule` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `qxkj_cms_category` --- - -DROP TABLE IF EXISTS `qxkj_cms_category`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `qxkj_cms_category` ( - `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '分类id', - `parent_id` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '分类父id', - `status` tinyint(3) unsigned NOT NULL DEFAULT '1' COMMENT '状态,1:发布,0:不发布', - `delete_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '删除时间', - `list_order` float NOT NULL DEFAULT '10000' COMMENT '排序', - `name` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '分类名称', - `description` varchar(255) NOT NULL DEFAULT '' COMMENT '分类描述', - `seo_title` varchar(100) NOT NULL DEFAULT '', - `seo_keywords` varchar(255) NOT NULL DEFAULT '', - `seo_description` varchar(255) NOT NULL DEFAULT '', - `list_tpl` varchar(50) NOT NULL DEFAULT '' COMMENT '分类列表模板', - `one_tpl` varchar(50) NOT NULL DEFAULT '' COMMENT '分类文章页模板', - `more` text COMMENT '扩展属性', - `cate_type` tinyint(3) unsigned NOT NULL DEFAULT '1' COMMENT '分类类型', - `cate_address` varchar(255) NOT NULL DEFAULT '' COMMENT '跳转地址', - `cate_content` text COMMENT '单页内容', - PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8mb4; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `qxkj_cms_category` --- - -LOCK TABLES `qxkj_cms_category` WRITE; -/*!40000 ALTER TABLE `qxkj_cms_category` DISABLE KEYS */; -INSERT INTO `qxkj_cms_category` VALUES (1,0,1,0,0,'最新发布','最新发布','最新发布','最新发布','最新发布','','','',1,'',''),(2,1,1,0,0,'云南主要指标数据','云南主要指标数据','云南主要指标数据','云南主要指标数据','云南主要指标数据','','','',1,'',''),(3,2,1,0,0,'综合数据','综合数据','综合数据','综合数据','综合数据','','','',2,'',''),(4,0,1,0,0,'决策部署','决策部署','决策部署','决策部署','决策部署','','','',1,'',''),(5,0,1,0,0,'决策参考','决策参考','决策参考','决策参考','决策参考','','','',1,'',''),(6,0,1,0,0,'热点名词','热点名词','热点名词','热点名词','热点名词','','','',2,'',''),(7,0,1,0,0,'统计分析','统计分析','统计分析','统计分析','统计分析','','','',1,'',''); -/*!40000 ALTER TABLE `qxkj_cms_category` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `qxkj_role` --- - -DROP TABLE IF EXISTS `qxkj_role`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `qxkj_role` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `parent_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '父角色ID', - `status` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT '状态;0:禁用;1:正常', - `create_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '创建时间', - `update_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '更新时间', - `list_order` float NOT NULL DEFAULT '0' COMMENT '排序', - `name` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '角色名称', - `remark` varchar(255) NOT NULL DEFAULT '' COMMENT '备注', - PRIMARY KEY (`id`), - KEY `parent_id` (`parent_id`), - KEY `status` (`status`) -) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8mb4 COMMENT='角色表'; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `qxkj_role` --- - -LOCK TABLES `qxkj_role` WRITE; -/*!40000 ALTER TABLE `qxkj_role` DISABLE KEYS */; -INSERT INTO `qxkj_role` VALUES (1,0,1,1329633709,1582773740,0,'超级管理员','备注'),(2,0,1,1329633709,1582732392,0,'普通管理员','备注'),(3,0,1,0,0,0,'站点管理员','站点管理人员'),(4,0,1,0,0,0,'初级管理员','初级管理员'),(5,0,1,0,0,0,'高级管理员','高级管理员'),(8,3,1,0,1582860212,0,'区级管理员',''); -/*!40000 ALTER TABLE `qxkj_role` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `qxkj_role_user` --- - -DROP TABLE IF EXISTS `qxkj_role_user`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `qxkj_role_user` ( - `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, - `role_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '角色 id', - `user_id` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '用户id', - PRIMARY KEY (`id`), - KEY `role_id` (`role_id`), - KEY `user_id` (`user_id`) -) ENGINE=InnoDB AUTO_INCREMENT=54 DEFAULT CHARSET=utf8 COMMENT='用户角色对应表'; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `qxkj_role_user` --- - -LOCK TABLES `qxkj_role_user` WRITE; -/*!40000 ALTER TABLE `qxkj_role_user` DISABLE KEYS */; -INSERT INTO `qxkj_role_user` VALUES (6,3,4),(8,2,5),(10,2,6),(20,4,7),(21,7,2),(23,2,10),(27,2,14),(28,2,15),(29,2,16),(47,2,20),(48,7,3),(49,2,3),(50,2,23),(51,7,22),(52,2,24),(53,5,8); -/*!40000 ALTER TABLE `qxkj_role_user` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `qxkj_sys_config` --- - -DROP TABLE IF EXISTS `qxkj_sys_config`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `qxkj_sys_config` ( - `config_id` int(5) unsigned NOT NULL AUTO_INCREMENT COMMENT '参数主键', - `config_name` varchar(100) DEFAULT '' COMMENT '参数名称', - `config_key` varchar(100) DEFAULT '' COMMENT '参数键名', - `config_value` varchar(500) DEFAULT '' COMMENT '参数键值', - `config_type` tinyint(1) DEFAULT '0' COMMENT '系统内置(Y是 N否)', - `create_by` int(64) unsigned DEFAULT '0' COMMENT '创建者', - `create_time` bigint(20) unsigned DEFAULT '0' COMMENT '创建时间', - `update_by` int(64) unsigned DEFAULT '0' COMMENT '更新者', - `update_time` bigint(20) unsigned DEFAULT '0' COMMENT '更新时间', - `remark` varchar(500) DEFAULT NULL COMMENT '备注', - PRIMARY KEY (`config_id`), - UNIQUE KEY `uni_config_key` (`config_key`) USING BTREE -) ENGINE=MyISAM AUTO_INCREMENT=8 DEFAULT CHARSET=utf8mb4; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `qxkj_sys_config` --- - -LOCK TABLES `qxkj_sys_config` WRITE; -/*!40000 ALTER TABLE `qxkj_sys_config` DISABLE KEYS */; -INSERT INTO `qxkj_sys_config` VALUES (1,'文件上传-文件大小','sys.uploadFile.fileSize','50M',1,31,1582968376,0,0,'文件上传大小限制'),(2,'文件上传-文件类型','sys.uploadFile.fileType','doc,docx,zip,xls,xlsx,rar',1,31,1582968465,0,0,'文件上传后缀类型限制'),(3,'图片上传-图片类型','sys.uploadFile.imageType','jpg,jpeg,gif,npm,png',1,31,1582968519,0,0,'图片上传后缀类型限制'),(4,'图片上传-图片大小','sys.uploadFile.imageSize','50M',1,31,1582968538,31,1582991905,'图片上传大小限制'); -/*!40000 ALTER TABLE `qxkj_sys_config` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `qxkj_sys_dict_data` --- - -DROP TABLE IF EXISTS `qxkj_sys_dict_data`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `qxkj_sys_dict_data` ( - `dict_code` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '字典编码', - `dict_sort` int(4) DEFAULT '0' COMMENT '字典排序', - `dict_label` varchar(100) DEFAULT '' COMMENT '字典标签', - `dict_value` varchar(100) DEFAULT '' COMMENT '字典键值', - `dict_type` varchar(100) DEFAULT '' COMMENT '字典类型', - `css_class` varchar(100) DEFAULT NULL COMMENT '样式属性(其他样式扩展)', - `list_class` varchar(100) DEFAULT NULL COMMENT '表格回显样式', - `is_default` tinyint(1) DEFAULT '0' COMMENT '是否默认(1是 0否)', - `status` tinyint(1) DEFAULT '0' COMMENT '状态(0正常 1停用)', - `create_by` bigint(64) unsigned DEFAULT '0' COMMENT '创建者', - `create_time` bigint(20) unsigned DEFAULT '0' COMMENT '创建时间', - `update_by` bigint(64) unsigned DEFAULT '0' COMMENT '更新者', - `update_time` bigint(20) unsigned DEFAULT '0' COMMENT '更新时间', - `remark` varchar(500) DEFAULT NULL COMMENT '备注', - PRIMARY KEY (`dict_code`) -) ENGINE=InnoDB AUTO_INCREMENT=28 DEFAULT CHARSET=utf8mb4 COMMENT='字典数据表'; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `qxkj_sys_dict_data` --- - -LOCK TABLES `qxkj_sys_dict_data` WRITE; -/*!40000 ALTER TABLE `qxkj_sys_dict_data` DISABLE KEYS */; -INSERT INTO `qxkj_sys_dict_data` VALUES (1,0,'男','0','sys_user_sex','','default',1,1,31,1582884113,0,0,'备注信息'),(2,0,'女','0','sys_user_sex','','default',1,1,31,1582884125,31,1582885784,'备注信息'),(3,0,'保密','0','sys_user_sex','','default',1,1,31,1582884871,31,1582885799,'备注信息'),(4,0,'男','0','sys_user_sex','','default',1,1,31,1582899746,0,0,'备注信息'),(5,0,'男','0','sys_user_sex','','default',1,1,31,1582899747,0,0,'备注信息'),(6,0,'男','0','sys_user_sex','','default',1,1,31,1582899748,0,0,'备注信息'),(7,0,'男','0','sys_user_sex','','default',1,1,31,1582899748,0,0,'备注信息'),(8,0,'男','0','sys_user_sex','','default',1,1,31,1582899749,0,0,'备注信息'),(9,0,'男','0','sys_user_sex','','default',1,1,31,1582899750,0,0,'备注信息'),(10,0,'男','0','sys_user_sex','','default',1,1,31,1582899751,0,0,'备注信息'),(11,0,'男','0','sys_user_sex','','default',1,1,31,1582899752,0,0,'备注信息'),(12,0,'男','0','sys_user_sex','','default',1,1,31,1582899752,0,0,'备注信息'),(24,0,'作为频道页,不可作为栏目发布文章,可添加下级分类','1','cms_category_type','','default',1,1,31,1583131942,0,0,'作为频道页,不可作为栏目发布文章,可添加下级分类'),(25,0,'作为发布栏目,可添加文章','2','cms_category_type','','default',0,1,31,1583132032,0,0,'作为发布栏目,可添加文章'),(26,0,'不直接发布内容,用于跳转页面','3','cms_category_type','','default',0,1,31,1583132125,0,0,'不直接发布内容,用于跳转页面'),(27,0,'单页面模式,分类直接显示为文章','4','cms_category_type','','default',0,1,31,1583132145,0,0,'单页面模式,分类直接显示为文章'); -/*!40000 ALTER TABLE `qxkj_sys_dict_data` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `qxkj_sys_dict_type` --- - -DROP TABLE IF EXISTS `qxkj_sys_dict_type`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `qxkj_sys_dict_type` ( - `dict_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '字典主键', - `dict_name` varchar(100) DEFAULT '' COMMENT '字典名称', - `dict_type` varchar(100) DEFAULT '' COMMENT '字典类型', - `status` tinyint(1) unsigned DEFAULT '0' COMMENT '状态(0正常 1停用)', - `create_by` int(64) unsigned DEFAULT '0' COMMENT '创建者', - `create_time` bigint(20) unsigned DEFAULT '0' COMMENT '创建时间', - `update_by` int(64) unsigned DEFAULT '0' COMMENT '更新者', - `update_time` bigint(20) unsigned DEFAULT '0' COMMENT '更新时间', - `remark` varchar(500) DEFAULT NULL COMMENT '备注', - PRIMARY KEY (`dict_id`), - UNIQUE KEY `dict_type` (`dict_type`) -) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8mb4 COMMENT='字典类型表'; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `qxkj_sys_dict_type` --- - -LOCK TABLES `qxkj_sys_dict_type` WRITE; -/*!40000 ALTER TABLE `qxkj_sys_dict_type` DISABLE KEYS */; -INSERT INTO `qxkj_sys_dict_type` VALUES (1,'用户性别','sys_user_sex',1,31,1582789177,0,0,'用于选择用户性别'),(2,'分类类型','cms_category_type',1,31,1582789253,31,1583131577,'文章分类类型'),(3,'菜单状态2','sys_show_hide2',1,31,1582789296,0,0,'菜单状态列表'),(4,'菜单状态3','sys_show_hide3',1,31,1582789303,0,0,'菜单状态列表'),(5,'菜单状态4','sys_show_hide4',1,31,1582789307,0,0,'菜单状态列表'),(6,'菜单状态5','sys_show_hide5',1,31,1582789313,0,0,'菜单状态列表'),(7,'菜单状态6','sys_show_hide6',1,31,1582789321,0,0,'菜单状态列表'),(8,'菜单状态7','sys_show_hide7',1,31,1582789326,0,0,'菜单状态列表'),(9,'菜单状态8','sys_show_hide8',1,31,1582789332,0,0,'菜单状态列表'),(10,'菜单状态9','sys_show_hide9',1,31,1582789337,0,0,'菜单状态列表'),(11,'菜单状态10','sys_show_hide10',1,31,1582789344,0,0,'菜单状态列表'),(12,'菜单状态11','sys_show_hide11',1,31,1582789349,0,0,'菜单状态列表'); -/*!40000 ALTER TABLE `qxkj_sys_dict_type` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `qxkj_user` --- - -DROP TABLE IF EXISTS `qxkj_user`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `qxkj_user` ( - `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, - `user_name` varchar(60) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '用户名', - `mobile` varchar(20) NOT NULL DEFAULT '' COMMENT '中国手机不带国家代码,国际手机号格式为:国家代码-手机号', - `user_nickname` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '用户昵称', - `birthday` int(11) NOT NULL DEFAULT '0' COMMENT '生日', - `create_time` int(11) NOT NULL DEFAULT '0' COMMENT '注册时间', - `user_password` varchar(255) NOT NULL DEFAULT '' COMMENT '登录密码;cmf_password加密', - `user_status` tinyint(3) unsigned NOT NULL DEFAULT '1' COMMENT '用户状态;0:禁用,1:正常,2:未验证', - `user_email` varchar(100) NOT NULL DEFAULT '' COMMENT '用户登录邮箱', - `sex` tinyint(2) NOT NULL DEFAULT '0' COMMENT '性别;0:保密,1:男,2:女', - `avatar` varchar(255) NOT NULL DEFAULT '' COMMENT '用户头像', - `last_login_time` int(11) NOT NULL DEFAULT '0' COMMENT '最后登录时间', - `last_login_ip` varchar(15) NOT NULL DEFAULT '' COMMENT '最后登录ip', - PRIMARY KEY (`id`), - UNIQUE KEY `user_login` (`user_name`) USING BTREE, - UNIQUE KEY `mobile` (`mobile`) USING BTREE, - KEY `user_nickname` (`user_nickname`) -) ENGINE=InnoDB AUTO_INCREMENT=39 DEFAULT CHARSET=utf8mb4 COMMENT='用户表'; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `qxkj_user` --- - -LOCK TABLES `qxkj_user` WRITE; -/*!40000 ALTER TABLE `qxkj_user` DISABLE KEYS */; -INSERT INTO `qxkj_user` VALUES (1,'admin','18687460581','超级管理员',0,1557715675,'IJ1xz+Wve+ZONVMFfXJQMw==',1,'yxh669@qq.com',0,'',1583489149,'192.168.0.212'),(2,'yixiaohu','13699885599','易小虎',0,0,'IJ1xz+Wve+ZONVMFfXJQMw==',1,'yxh@qq.com',1,'',1583479226,'[::1]'),(3,'zs','16399669855','张三',0,0,'IJ1xz+Wve+ZONVMFfXJQMw==',1,'zs@qq.com',0,'',1559293160,'127.0.0.1'),(4,'qlgl','13758596696','测试c',0,0,'IJ1xz+Wve+ZONVMFfXJQMw==',1,'qlgl@qq.com',0,'',1559293134,'127.0.0.1'),(5,'test','13845696696','测试2',0,0,'9OFlt5qzzvCiZWhe7ilcLA==',1,'123@qq.com',0,'',0,''),(6,'18999998889','13755866654','刘大大',0,0,'IJ1xz+Wve+ZONVMFfXJQMw==',1,'1223@qq.com',0,'',0,''),(7,'zmm','13788566696','张明明',0,0,'IJ1xz+Wve+ZONVMFfXJQMw==',1,'11123@qq.com',0,'',0,''),(8,'lxx','13756566696','李小小',0,0,'IJ1xz+Wve+ZONVMFfXJQMw==',1,'123333@qq.com',0,'',1571729563,'127.0.0.1'),(10,'xmm','13588999969','小秘密',0,0,'IJ1xz+Wve+ZONVMFfXJQMw==',1,'',0,'',0,''),(14,'cd_19','123154564','看金利科技',0,0,'IJ1xz+Wve+ZONVMFfXJQMw==',1,'',0,'',0,''),(15,'lmm','135877545454','刘敏敏',0,0,'IJ1xz+Wve+ZONVMFfXJQMw==',1,'',0,'',0,''),(16,'ldn','13899658874','李大牛',0,0,'IJ1xz+Wve+ZONVMFfXJQMw==',1,'',0,'',0,''),(20,'dbc','13877555566','大百词',0,0,'IJ1xz+Wve+ZONVMFfXJQMw==',1,'',0,'',0,''),(22,'yxfmlbb','15969423326','袁学飞',0,1557715675,'IJ1xz+Wve+ZONVMFfXJQMw==',1,'yxh6691@qq.com',0,'',1565059554,'127.0.0.1'),(23,'wangming','13699888855','王明',0,0,'IJ1xz+Wve+ZONVMFfXJQMw==',1,'',0,'',0,''),(24,'zhk','13699885591','综合科',0,0,'IZNU7Pn91/++830Pi6HAWA==',1,'',0,'',1569288069,'192.168.0.146'),(28,'demo3','18699888855','测试账号1',0,1581314035,'9OFlt5qzzvCiZWhe7ilcLA==',1,'',0,'',0,''),(31,'demo','18699888856','测试账号1',0,1581314770,'9OFlt5qzzvCiZWhe7ilcLA==',1,'56@qq.com',0,'',1583479196,'[::1]'),(32,'demo100','18699888859','测试账号1',0,1582103659,'9OFlt5qzzvCiZWhe7ilcLA==',1,'',0,'',0,''),(33,'demo110','18699888853','测试账号1',0,1582109337,'9OFlt5qzzvCiZWhe7ilcLA==',1,'',0,'',0,''),(34,'demo101','13855774455','测试账号1',0,1582110232,'9OFlt5qzzvCiZWhe7ilcLA==',1,'',0,'',0,''),(38,'demo103','18699888833','测试账号103',0,1582188923,'9OFlt5qzzvCiZWhe7ilcLA==',1,'',0,'',1582188938,'[::1]'); -/*!40000 ALTER TABLE `qxkj_user` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `qxkj_user_online` --- - -DROP TABLE IF EXISTS `qxkj_user_online`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `qxkj_user_online` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `uuid` char(32) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL DEFAULT '' COMMENT '用户标识', - `token` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL DEFAULT '' COMMENT '用户token', - `create_time` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '登录时间', - `user_name` varchar(255) NOT NULL COMMENT '用户名', - `ip` varchar(120) NOT NULL DEFAULT '' COMMENT '登录ip', - `explorer` varchar(30) NOT NULL DEFAULT '' COMMENT '浏览器', - `os` varchar(30) NOT NULL DEFAULT '' COMMENT '操作系统', - PRIMARY KEY (`id`), - UNIQUE KEY `uni_token` (`token`) USING BTREE -) ENGINE=MyISAM AUTO_INCREMENT=16 DEFAULT CHARSET=utf8mb4 COMMENT='用户在线状态表'; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `qxkj_user_online` --- - -LOCK TABLES `qxkj_user_online` WRITE; -/*!40000 ALTER TABLE `qxkj_user_online` DISABLE KEYS */; -INSERT INTO `qxkj_user_online` VALUES (7,'','vioSknvS6SgsiXgxjbbHVNHdgC87adZccwHWRT4fO0hT3nFciqjy6b7axafxq2mlglIfz0STCz6VzmUW2c2UWg2uTkCjU1QaUIVhVEolmg1xOdPbVFaprVYMXIHlnVfh1Uf1SaHn2cr3iRUAObntNA==',1583479226,'yixiaohu','[::1]','PostmanRuntime',''),(6,'','fCLUxFpxP3QqVAezWSiqJ34BRz5YTp2qDGmH5L5jiv7IuTjnVwU1hMxIMAIJawrfKLOMWXhGk5vUMjduD7hQoTwkNXu+AvmpunrFa/acFCxhVqabFoMv0lIaDjkmRSp5',1583479196,'demo','[::1]','PostmanRuntime',''),(5,'','vioSknvS6SgsiXgxjbbHVNHdgC87adZccwHWRT4fO0hXe6W23Y91YbUSoiKJzqTRE3mCF75YaFTvrPT+6ntnLE37vtyio/VgRyDQfvvQSjACALG1KNCJw+9sI7VrJCwpK0PcK52Q9j6R4A/phtLYSA==',1583479116,'yixiaohu','192.168.0.212','Chrome','Windows 10'),(4,'','fCLUxFpxP3QqVAezWSiqJ7D3QYZ7jkylPshqw8BVzfJJfAHAbwsSFhjrTyqHZEnzBfZXf/9/EWR1jYD9wj1QwXVeoad3H8JkNfWceD34KWcs4r19sCG1wKkKmjB1fbcf',1583479045,'demo','192.168.0.212','Chrome','Windows 10'),(13,'bb91260dc63d00e51728fd3f791881fb','lpe0YG9uqSN+sc8zL1tF+9Wcdo668H3tXJxqoKs0sIpULsmmu8SNCn4Y7lyrWhX9KWpeeDIeGMZIwk9rT3+BgyqG27ezTPI4INWZTmz/NEyUEmYL2KhMtJlMHgzxbjfO',1583481865,'admin','[::1]','PostmanRuntime',''),(9,'','lpe0YG9uqSN+sc8zL1tF+0bVNmHSnBiJshz6cFTW0bO1YDzPEgiMyIy2o0szcsqqcnHlqbHN8VWqUeqIbrbOg3YPUGI/PCYgYZX2bUw0eAUGr48lTOCtejKSDmygL0ui',1583479253,'admin','192.168.0.212','Chrome','Windows 10'),(15,'d3cb2f2bc7846aa0b962366bc67bb234','lpe0YG9uqSN+sc8zL1tF+0bVNmHSnBiJshz6cFTW0bO1YDzPEgiMyIy2o0szcsqq89te5+yx+6Pz8G3gLrpKoSR7JEPD8YXqGwV3JOmcA23bjYRWtWoXlfQ51WSVEVgb',1583489149,'admin','192.168.0.212','Chrome','Windows 10'); -/*!40000 ALTER TABLE `qxkj_user_online` ENABLE KEYS */; -UNLOCK TABLES; -/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; - -/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; -/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; -/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; -/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; -/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; -/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; -/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; - --- Dump completed on 2020-03-06 18:10:15 diff --git a/library/utils/function.go b/library/utils/function.go index 58b7a04..acabc40 100644 --- a/library/utils/function.go +++ b/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 } diff --git a/router/middleware.go b/middleWare/middleware.go similarity index 99% rename from router/middleware.go rename to middleWare/middleware.go index 78952f3..db2e946 100644 --- a/router/middleware.go +++ b/middleWare/middleware.go @@ -1,4 +1,4 @@ -package router +package middleWare import ( "fmt" diff --git a/router/router.go b/router/router.go index df0afe2..212c4db 100644 --- a/router/router.go +++ b/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)) }) }) diff --git a/test/demo2_test.go b/test/demo2_test.go index 1b98600..55d8bb4 100644 --- a/test/demo2_test.go +++ b/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 }