浏览代码

add:日志列表

zoie 2 年之前
父节点
当前提交
0afa38e24e
共有 10 个文件被更改,包括 104 次插入176 次删除
  1. 二进制
      ColdVerify_server
  2. 36 24
      controllers/Logs.go
  3. 0 1
      lastupdate.tmp
  4. 26 13
      lib/lib.go
  5. 0 95
      logs/Mqtt/Mqtt.2022-07-20.001.log
  6. 0 4
      logs/Mqtt/Mqtt.2022-07-21.001.log
  7. 0 5
      logs/Mqtt/Mqtt.log
  8. 16 15
      models/System/Logs.go
  9. 15 19
      models/System/UserLogs.go
  10. 11 0
      routers/Logs.go

二进制
ColdVerify_server


+ 36 - 24
controllers/Logs.go

@@ -14,48 +14,60 @@ type LogsController struct {
 
 // 列表 -
 func (c *LogsController) List() {
+	var log_jsons lib.LOG_JSONS
 	page, _ := c.GetInt("page")
-	println(page)
 	if page < 1 {
 		page = 1
 	}
+	page_z, _ := c.GetInt("page_z")
+	if page_z < 1 {
+		page_z = conf.Page_size
+	}
 
 	Class_1 := c.GetString("Class_1")
 
-	c.Data["Class_1"] = Class_1
-	c.Data["Class_List"] = System.Read_Logs_Class()
-
 	var cnt int64
-	c.Data["List"], cnt = System.Read_Logs_ALL(page, Class_1)
-	page_size := math.Ceil(float64(cnt) / float64(conf.Page_size))
-	c.Data["Page"] = page
-	c.Data["Page_size"] = page_size
-	c.Data["Pages"] = lib.Func_page(int64(page), int64(page_size))
-	c.Data["cnt"] = cnt
-
-	c.TplName = "System/Logs.html"
+	List, cnt := System.Read_Logs_ALL(page, page_z, Class_1)
+	page_size := math.Ceil(float64(cnt) / float64(page_z))
+	log_jsons.Class_1 = Class_1
+	log_jsons.Class_List = System.Read_Logs_Class()
+	log_jsons.List = List
+	log_jsons.Page = page
+	log_jsons.Page_size = int(page_size)
+	log_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
+	log_jsons.Num = int(cnt)
+
+	c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: log_jsons}
+	c.ServeJSON()
+	return
 }
 
 // 列表 -
 func (c *LogsController) UserLogs() {
+	var log_jsons lib.LOG_JSONS
 	page, _ := c.GetInt("page")
-	println(page)
 	if page < 1 {
 		page = 1
 	}
+	page_z, _ := c.GetInt("page_z")
+	if page_z < 1 {
+		page_z = conf.Page_size
+	}
 
 	Class_1 := c.GetString("Class_1")
 
-	c.Data["Class_1"] = Class_1
-	c.Data["Class_List"] = System.Read_UserLogs_Class()
-
 	var cnt int64
-	c.Data["List"], cnt = System.Read_UserLogs_ALL(page, Class_1)
-	page_size := math.Ceil(float64(cnt) / float64(conf.Page_size))
-	c.Data["Page"] = page
-	c.Data["Page_size"] = page_size
-	c.Data["Pages"] = lib.Func_page(int64(page), int64(page_size))
-	c.Data["cnt"] = cnt
-
-	c.TplName = "User/UserLogs.html"
+	List, cnt := System.Read_UserLogs_ALL(page, page_z, Class_1)
+	page_size := math.Ceil(float64(cnt) / float64(page_z))
+	log_jsons.Class_1 = Class_1
+	log_jsons.Class_List = System.Read_UserLogs_Class()
+	log_jsons.List = List
+	log_jsons.Page = page
+	log_jsons.Page_size = int(page_size)
+	log_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
+	log_jsons.Num = int(cnt)
+
+	c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: log_jsons}
+	c.ServeJSON()
+	return
 }

+ 0 - 1
lastupdate.tmp

@@ -1 +0,0 @@
-{"C:\\BZD\\冷链验证\\ColdVerify_server\\controllers":1658301624411005900}

+ 26 - 13
lib/lib.go

@@ -12,7 +12,8 @@ import (
 	"strings"
 	"time"
 )
-var Run_My_Server = false  // 运行当期服务
+
+var Run_My_Server = false // 运行当期服务
 
 type Cl_ struct {
 	Uuid_list map[string]string // 泛型
@@ -50,31 +51,43 @@ type R_JSONS_s struct {
 	Pages     []Page_T
 }
 
+type LOG_JSONS struct {
+	//必须的大写开头
+	Class_1    string
+	Class_List interface{}
+	List       interface{}
+	Num        int
+	Page       int
+	Page_size  int
+	Pages      []Page_T
+}
+
 // 登录验证
-func Verification(GetCookie string, GetString string) ( Account.User,bool) {
+func Verification(GetCookie string, GetString string) (Account.User, bool) {
 	// 自适应 参数
 	User_tokey := GetCookie
 	if len(User_tokey) == 0 {
 		User_tokey = GetString
 	}
 	if len(User_tokey) == 0 {
-		return  Account.User{},false
+		return Account.User{}, false
 	}
 	// 判断 tokey 是否存在
 	tokey, is := Account.Read_Tokey(User_tokey)
 	if !is {
-		return Account.User{},false
+		return Account.User{}, false
 	}
 
 	err, user_r := Account.Read_User_ByT_uuid(tokey)
 	if err != nil {
-		return Account.User{},false
+		return Account.User{}, false
 	}
 	log.Println("登录 User_name 为:", user_r.T_name)
-	return user_r,true
+	return user_r, true
 }
+
 // 登录验证
-func Verification_Admin(GetCookie string, GetString string) ( Account.Admin,bool) {
+func Verification_Admin(GetCookie string, GetString string) (Account.Admin, bool) {
 	Run_My_Server = true // 运行当期服务
 	// 自适应 参数
 	User_tokey := GetCookie
@@ -82,20 +95,20 @@ func Verification_Admin(GetCookie string, GetString string) ( Account.Admin,bool
 		User_tokey = GetString
 	}
 	if len(User_tokey) == 0 {
-		return  Account.Admin{},false
+		return Account.Admin{}, false
 	}
 	// 判断 tokey 是否存在
 	tokey, is := Account.Read_Tokey(User_tokey)
 	if !is {
-		return Account.Admin{},false
+		return Account.Admin{}, false
 	}
 
 	err, user_r := Account.Read_Admin_ByT_uuid(tokey)
 	if err != nil {
-		return Account.Admin{},false
+		return Account.Admin{}, false
 	}
 	log.Println("登录 Admin_name 为:", user_r.T_name)
-	return  user_r , true
+	return user_r, true
 }
 
 // func_page 分页   [{3 1} {4 2} {4 3} {4 4} {4 5} {4 6} {4 7} {4 8} {4 9} {5 2}]-
@@ -400,6 +413,7 @@ func GetYearMonthToDay(year int, month int) int {
 	// 得出2月的天数
 	return 28
 }
+
 const (
 	AlignLeft   = 4
 	AlignCenter = 5
@@ -419,7 +433,6 @@ func RectFillColor(pdf *gopdf.GoPdf,
 	align, valign int,
 ) {
 
-
 	pdf.SetLineWidth(0.1)
 	pdf.SetFillColor(r, g, b) //setup fill color
 	pdf.SetLineType("")       // 线条样式
@@ -444,4 +457,4 @@ func RectFillColor(pdf *gopdf.GoPdf,
 
 	pdf.SetY(y)
 	pdf.Cell(nil, text)
-}
+}

文件差异内容过多而无法显示
+ 0 - 95
logs/Mqtt/Mqtt.2022-07-20.001.log


+ 0 - 4
logs/Mqtt/Mqtt.2022-07-21.001.log

@@ -1,4 +0,0 @@
-2022/07/20 10:43:58.652 [I]  2022-07-20 10:43:58>%!(EXTRA []interface {}=[{"key":"redis_Device","conn":"localhost:6379","dbNum":"2","password":""}])
-2022/07/20 10:43:58.965 [I]  2022-07-20 10:43:58>%!(EXTRA []interface {}=[{"key":"redis_DeviceClass","conn":"localhost:6379","dbNum":"2","password":""}])
-2022/07/20 10:43:59.279 [I]  2022-07-20 10:43:59>%!(EXTRA []interface {}=[{"key":"redis_DeviceClassList","conn":"localhost:6379","dbNum":"2","password":""}])
-2022/07/20 10:43:59.900 [I]  2022-07-20 10:43:59>%!(EXTRA []interface {}=[{"key":"redis_Task","conn":"localhost:6379","dbNum":"2","password":""}])

+ 0 - 5
logs/Mqtt/Mqtt.log

@@ -1,5 +0,0 @@
-2022/07/25 10:00:34.354 [I]  2022-07-25 10:00:34>%!(EXTRA []interface {}=[{"key":"redis_Device","conn":"localhost:6379","dbNum":"2","password":""}])
-2022/07/25 10:00:34.668 [I]  2022-07-25 10:00:34>%!(EXTRA []interface {}=[{"key":"redis_DeviceClass","conn":"localhost:6379","dbNum":"2","password":""}])
-2022/07/25 10:00:34.982 [I]  2022-07-25 10:00:34>%!(EXTRA []interface {}=[{"key":"redis_DeviceClassList","conn":"localhost:6379","dbNum":"2","password":""}])
-2022/07/25 10:00:35.610 [I]  2022-07-25 10:00:35>%!(EXTRA []interface {}=[{"key":"redis_Task","conn":"localhost:6379","dbNum":"2","password":""}])
-2022/07/25 10:01:27.083 [I]  2022-07-25 10:01:27>%!(EXTRA []interface {}=[没有 找到key: d8qMyeXLzIxn])

+ 16 - 15
models/System/Logs.go

@@ -1,7 +1,6 @@
 package System
 
 import (
-	"bzd_server/conf"
 	"fmt"
 	"github.com/beego/beego/v2/adapter/orm"
 	orm2 "github.com/beego/beego/v2/client/orm"
@@ -10,12 +9,15 @@ import (
 
 type Logs struct {
 	Id         int    `orm:"column(ID);size(11);auto;pk"`
-	Logs_class string `orm:"size(256);null"` //
-	Logs_Title string `orm:"size(256);null"` // 标题
-	Logs_Txt string `orm:"type(text);null"` // 详情
+	Logs_class string `orm:"size(256);null"`  //
+	Logs_Title string `orm:"size(256);null"`  // 标题
+	Logs_Txt   string `orm:"type(text);null"` // 详情
 
-	CreateTime time.Time `orm:"column(create_time);type(timestamp);null;auto_now_add"`     //auto_now 每次 model 保存时都会对时间自动更新
-	UpdateTime time.Time `orm:"column(update_time);type(timestamp);null;auto_now"` //auto_now_add 第一次保存时才设置时间
+	CreateTime time.Time `orm:"column(create_time);type(timestamp);null;auto_now_add"` //auto_now 每次 model 保存时都会对时间自动更新
+	UpdateTime time.Time `orm:"column(update_time);type(timestamp);null;auto_now"`     //auto_now_add 第一次保存时才设置时间
+}
+
+type L_JSON struct {
 }
 
 func (t *Logs) TableName() string {
@@ -29,15 +31,14 @@ func init() {
 }
 
 // 添加  System.Add_Logs("MqttServer","参数请求 [Rt_Parameter]","base")
-func Add_Logs(Logs_class string,Logs_Title string,Logs_Txt string) {
+func Add_Logs(Logs_class string, Logs_Title string, Logs_Txt string) {
 	o := orm.NewOrm()
-	m := Logs{Logs_class:Logs_class,Logs_Title:Logs_Title,Logs_Txt:Logs_Txt}
+	m := Logs{Logs_class: Logs_class, Logs_Title: Logs_Title, Logs_Txt: Logs_Txt}
 	o.Insert(&m)
 }
 
-
 // 获取列表
-func Read_Logs_ALL(page int,Logs_class string) (r []Logs,cnt int64) {
+func Read_Logs_ALL(page, page_z int, Logs_class string) (r []Logs, cnt int64) {
 
 	o := orm.NewOrm()
 	// 也可以直接使用 Model 结构体作为表名
@@ -47,17 +48,19 @@ func Read_Logs_ALL(page int,Logs_class string) (r []Logs,cnt int64) {
 	if page <= 1 {
 		offset = 0
 	} else {
-		offset = int64((page - 1) * conf.Page_size)
+		offset = int64((page - 1) * page_z)
 	}
 
-	qs.Limit(conf.Page_size, offset).Filter("Logs_class__icontains", Logs_class).OrderBy("-Id").All(&r)
+	qs.Limit(page_z, offset).Filter("Logs_class__icontains", Logs_class).OrderBy("-Id").All(&r)
 	cnt, _ = qs.Filter("Logs_class__icontains", Logs_class).Count()
 
-	return r,cnt
+	return r, cnt
 }
+
 type CLASS_lists struct {
 	Logs_class string
 }
+
 // 获取列表
 func Read_Logs_Class() (lists orm2.ParamsList) {
 	o := orm.NewOrm()
@@ -68,7 +71,5 @@ func Read_Logs_Class() (lists orm2.ParamsList) {
 	}
 	fmt.Println(len(pl_lists))
 
-
 	return pl_lists
 }
-

+ 15 - 19
models/System/UserLogs.go

@@ -1,7 +1,6 @@
 package System
 
 import (
-	"bzd_server/conf"
 	"encoding/json"
 	"fmt"
 	"github.com/beego/beego/v2/adapter/orm"
@@ -11,13 +10,13 @@ import (
 
 type UserLogs struct {
 	Id         int    `orm:"column(ID);size(11);auto;pk"`
-	Logs_uuid string `orm:"size(256);null"` //
-	Logs_class string `orm:"size(256);null"` //
-	Logs_Title string `orm:"size(256);null"` // 标题
-	Logs_Txt string `orm:"type(text);null"` // 详情
+	Logs_uuid  string `orm:"size(256);null"`  //
+	Logs_class string `orm:"size(256);null"`  //
+	Logs_Title string `orm:"size(256);null"`  // 标题
+	Logs_Txt   string `orm:"type(text);null"` // 详情
 
-	CreateTime time.Time `orm:"column(create_time);type(timestamp);null;auto_now_add"`     //auto_now 每次 model 保存时都会对时间自动更新
-	UpdateTime time.Time `orm:"column(update_time);type(timestamp);null;auto_now"` //auto_now_add 第一次保存时才设置时间
+	CreateTime time.Time `orm:"column(create_time);type(timestamp);null;auto_now_add"` //auto_now 每次 model 保存时都会对时间自动更新
+	UpdateTime time.Time `orm:"column(update_time);type(timestamp);null;auto_now"`     //auto_now_add 第一次保存时才设置时间
 }
 
 func (t *UserLogs) TableName() string {
@@ -31,24 +30,23 @@ func init() {
 }
 
 // 添加  System.Add_UserLogs(user_r.T_user,"登陆", "管理员登陆", "")
-func Add_UserLogs(Logs_uuid string,Logs_class string,Logs_Title string,Logs_Txt string) {
+func Add_UserLogs(Logs_uuid string, Logs_class string, Logs_Title string, Logs_Txt string) {
 	o := orm.NewOrm()
-	m := UserLogs{Logs_uuid:Logs_uuid,Logs_class:Logs_class,Logs_Title:Logs_Title,Logs_Txt:Logs_Txt}
+	m := UserLogs{Logs_uuid: Logs_uuid, Logs_class: Logs_class, Logs_Title: Logs_Title, Logs_Txt: Logs_Txt}
 	o.Insert(&m)
 }
-func Add_UserLogs_T(Logs_uuid string,Logs_class string,Logs_Title string,Logs_Txt_T interface{}) {
+func Add_UserLogs_T(Logs_uuid string, Logs_class string, Logs_Title string, Logs_Txt_T interface{}) {
 	o := orm.NewOrm()
 	jsonStu, err := json.Marshal(Logs_Txt_T)
 	if err != nil {
-		fmt.Println("Add_UserLogs_T JSON ,err=",err)
+		fmt.Println("Add_UserLogs_T JSON ,err=", err)
 	}
-	m := UserLogs{Logs_uuid:Logs_uuid,Logs_class:Logs_class,Logs_Title:Logs_Title,Logs_Txt:string(jsonStu)}
+	m := UserLogs{Logs_uuid: Logs_uuid, Logs_class: Logs_class, Logs_Title: Logs_Title, Logs_Txt: string(jsonStu)}
 	o.Insert(&m)
 }
 
-
 // 获取列表
-func Read_UserLogs_ALL(page int,Logs_class string) (r []UserLogs,cnt int64) {
+func Read_UserLogs_ALL(page, page_z int, Logs_class string) (r []UserLogs, cnt int64) {
 
 	o := orm.NewOrm()
 	// 也可以直接使用 Model 结构体作为表名
@@ -58,13 +56,13 @@ func Read_UserLogs_ALL(page int,Logs_class string) (r []UserLogs,cnt int64) {
 	if page <= 1 {
 		offset = 0
 	} else {
-		offset = int64((page - 1) * conf.Page_size)
+		offset = int64((page - 1) * page_z)
 	}
 
-	qs.Limit(conf.Page_size, offset).Filter("Logs_class__icontains", Logs_class).OrderBy("-Id").All(&r)
+	qs.Limit(page_z, offset).Filter("Logs_class__icontains", Logs_class).OrderBy("-Id").All(&r)
 	cnt, _ = qs.Filter("Logs_class__icontains", Logs_class).Count()
 
-	return r,cnt
+	return r, cnt
 }
 
 // 获取列表
@@ -77,7 +75,5 @@ func Read_UserLogs_Class() (lists orm2.ParamsList) {
 	}
 	fmt.Println(len(pl_lists))
 
-
 	return pl_lists
 }
-

+ 11 - 0
routers/Logs.go

@@ -0,0 +1,11 @@
+package routers
+
+import (
+	"bzd_server/controllers"
+	beego "github.com/beego/beego/v2/server/web"
+)
+
+func init() {
+	beego.Router("/Logs/List", &controllers.LogsController{}, "*:List")         //
+	beego.Router("/UserLogs/List", &controllers.LogsController{}, "*:UserLogs") //
+}

部分文件因为文件数量过多而无法显示