Explorar el Código

update:日志打印优化

zoie hace 4 meses
padre
commit
06f462a5a8

+ 4 - 0
Nats/Nats.go

@@ -91,6 +91,10 @@ func NatsInit() {
 				if err == nil || strings.Contains(err.Error(), "doesn't exist") {
 					DeviceClassList.Delete(k)
 					count--
+				} else {
+					logs.Error("设备数据同步到任务数据失败", err)
+					DeviceClassList.Delete(k)
+					count--
 				}
 				return true
 			})

+ 1 - 1
controllers/TaskData.go

@@ -579,7 +579,7 @@ func (c *TaskDataController) Export_Data_Excel() {
 		f.SetCellValue("Sheet1", fmt.Sprintf("E%d", line), v.T_time)
 
 	}
-	fmt.Println("DeviceSensor_data:", len(DeviceSensor_data_list))
+	logs.Println("DeviceSensor_data:", len(DeviceSensor_data_list))
 
 	lib.Create_Dir("./ofile")
 

+ 2 - 3
models/Account/Admin.go

@@ -3,7 +3,6 @@ package Account
 import (
 	"ColdVerify_server/lib"
 	"ColdVerify_server/logs"
-	"fmt"
 	"github.com/beego/beego/v2/adapter/orm"
 	orm2 "github.com/beego/beego/v2/client/orm"
 	"time"
@@ -116,7 +115,7 @@ func Read_Admin_List(T_name string, page int, page_z int, powerMap map[int]strin
 func Update_Admin(m Admin, cols ...string) bool {
 	o := orm.NewOrm()
 	if num, err := o.Update(&m, cols...); err == nil {
-		fmt.Println("Number of records updated in database:", num)
+		logs.Println("Number of records updated in database:", num)
 
 		return true
 	}
@@ -140,7 +139,7 @@ func Delete_Admin_(v Admin) bool {
 	o := orm.NewOrm()
 	v.T_State = 0
 	if num, err := o.Update(&v, "T_State"); err == nil {
-		fmt.Println("Number of records updated in database:", num)
+		logs.Println("Number of records updated in database:", num)
 	} else {
 		return false
 	}

+ 2 - 3
models/Account/Power.go

@@ -4,7 +4,6 @@ import (
 	"ColdVerify_server/conf"
 	"ColdVerify_server/lib"
 	"ColdVerify_server/logs"
-	"fmt"
 	"github.com/beego/beego/v2/adapter/orm"
 	"time"
 )
@@ -40,7 +39,7 @@ func Update_UserPower_ById_Basics(m UserPower) (err error) {
 		var num int64
 		m.Id = v.Id
 		if num, err = o.Update(&m, "Power_name", "Power_Administration", "Power_User_r", "Power_User_entry", "Power_Device_r", "Power_Device_a", "Power_Device_Parameter_e", "Power_DeviceSensor_Class", "Power_DeviceSensor_Parameter_e", "Power_DeviceSensor_Compensate_e", "Power_Device_Bind_e", "Power_DataScreen_r", "Logs_Sys_r", "Logs_User_r"); err == nil {
-			fmt.Println("Number of records updated in database:", num)
+			logs.Println("Number of records updated in database:", num)
 		}
 	}
 	return err
@@ -118,7 +117,7 @@ func Update_Delete_UserPower_Byid(Id int) (err error) {
 		var num int64
 		v.T_State = 0
 		if num, err = o.Update(&v, "T_State"); err == nil {
-			fmt.Println("Number of records updated in database:", num)
+			logs.Println("Number of records updated in database:", num)
 		}
 	}
 	return err

+ 4 - 3
models/Account/Tokey.go

@@ -2,6 +2,7 @@ package Account
 
 import (
 	"ColdVerify_server/conf"
+	"ColdVerify_server/logs"
 	"fmt"
 	"github.com/astaxie/beego/cache"
 	_ "github.com/astaxie/beego/cache/redis"
@@ -18,12 +19,12 @@ func init() {
 
 	config := fmt.Sprintf(`{"key":"%s","conn":"%s","dbNum":"%s","password":"%s"}`,
 		"redis_Tokey", conf.Redis_address, conf.Redis_dbNum, conf.Redis_password)
-	fmt.Println(config)
+	logs.Println(config)
 	var err error
 	redisCache_Tokey, err = cache.NewCache("redis", config)
 	if err != nil || redisCache_Tokey == nil {
 		errMsg := "failed to init redis"
-		fmt.Println(errMsg, err)
+		logs.Println(errMsg, err)
 	}
 }
 
@@ -32,7 +33,7 @@ func init() {
 func Redis_Tokey_Set(key string, r string) (err error) {
 	err = redisCache_Tokey.Put(key, r, 24*7*time.Hour)
 	if err != nil {
-		fmt.Println("set key:", key, ",value:", r, err)
+		logs.Println("set key:", key, ",value:", r, err)
 	}
 	return
 }

+ 3 - 3
models/Account/User.go

@@ -3,11 +3,11 @@ package Account
 import (
 	"ColdVerify_server/lib"
 	"ColdVerify_server/logs"
-	"fmt"
 	"github.com/beego/beego/v2/adapter/orm"
 	orm2 "github.com/beego/beego/v2/client/orm"
 	_ "github.com/go-sql-driver/mysql"
 	uuid "github.com/satori/go.uuid"
+	"log"
 	"time"
 )
 
@@ -153,7 +153,7 @@ func Delete_User_(v User) bool {
 	o := orm.NewOrm()
 	v.T_State = 0
 	if num, err := o.Update(&v, "T_State"); err == nil {
-		fmt.Println("Number of records updated in database:", num)
+		log.Println("Number of records updated in database:", num)
 	} else {
 		return false
 	}
@@ -165,7 +165,7 @@ func Delete_User_(v User) bool {
 func Update_User(m User, cols ...string) bool {
 	o := orm.NewOrm()
 	if num, err := o.Update(&m, cols...); err == nil {
-		fmt.Println("Number of records updated in database:", num)
+		log.Println("Number of records updated in database:", num)
 
 		return true
 	}

+ 4 - 5
models/Certificate/Certificate.go

@@ -3,7 +3,6 @@ package Certificate
 import (
 	"ColdVerify_server/lib"
 	"ColdVerify_server/logs"
-	"fmt"
 	"github.com/beego/beego/v2/adapter/orm"
 	orm2 "github.com/beego/beego/v2/client/orm"
 	_ "github.com/go-sql-driver/mysql"
@@ -106,7 +105,7 @@ func Delete_Certificate_(v Certificate) bool {
 	o := orm.NewOrm()
 	v.T_State = 0
 	if num, err := o.Update(&v, "T_State"); err == nil {
-		fmt.Println("Number of records updated in database:", num)
+		logs.Println("Number of records updated in database:", num)
 	} else {
 		logs.Error(lib.FuncName(), err)
 		return false
@@ -119,7 +118,7 @@ func Delete_Certificate_(v Certificate) bool {
 func Update_Certificate(m Certificate, cols ...string) bool {
 	o := orm.NewOrm()
 	if num, err := o.Update(&m, cols...); err == nil {
-		fmt.Println("Number of records updated in database:", num)
+		logs.Println("Number of records updated in database:", num)
 		return true
 	} else {
 		logs.Error(lib.FuncName(), err)
@@ -168,7 +167,7 @@ func Read_Certificate_List(T_Certificate_sn, T_layout_no, Time_start, Time_end s
 	// 获取总条数
 	sql := "SELECT COUNT(ID) FROM certificate AS c LEFT JOIN (SELECT t_release_time,t_failure_time,t_pdf,t__certificate_sn,t_layout_no FROM (SELECT DISTINCT * FROM `certificate_pdf` WHERE t__state=1 ORDER BY id DESC) f GROUP BY t_layout_no) AS pdf ON pdf.t_layout_no=c.t_layout_no WHERE t__state=1"
 	sql = sql + sqlWhere
-	fmt.Println(sql)
+	logs.Println(sql)
 	_, err := o.Raw(sql).ValuesList(&maps_z)
 	if err != nil {
 		return maps, 0
@@ -204,7 +203,7 @@ func Read_Certificate_List(T_Certificate_sn, T_layout_no, Time_start, Time_end s
 	}
 	sql += " LIMIT " + strconv.Itoa(offset) + "," + strconv.Itoa(page_z)
 
-	fmt.Println(sql)
+	logs.Println(sql)
 	_, err = o.Raw(sql).QueryRows(&maps)
 
 	cnt, _ := strconv.Atoi(maps_z[0][0].(string))

+ 2 - 3
models/Certificate/CertificatePdf.go

@@ -3,7 +3,6 @@ package Certificate
 import (
 	"ColdVerify_server/lib"
 	"ColdVerify_server/logs"
-	"fmt"
 	"github.com/beego/beego/v2/adapter/orm"
 	orm2 "github.com/beego/beego/v2/client/orm"
 	_ "github.com/go-sql-driver/mysql"
@@ -144,7 +143,7 @@ func Delete_CertificatePdf_(v CertificatePdf) bool {
 	o := orm.NewOrm()
 	v.T_State = 0
 	if num, err := o.Update(&v, "T_State"); err == nil {
-		fmt.Println("Number of records updated in database:", num)
+		logs.Println("Number of records updated in database:", num)
 	} else {
 		logs.Println(lib.FuncName(), err)
 		return false
@@ -157,7 +156,7 @@ func Delete_CertificatePdf_(v CertificatePdf) bool {
 func Update_CertificatePdf(m CertificatePdf, cols ...string) bool {
 	o := orm.NewOrm()
 	if num, err := o.Update(&m, cols...); err == nil {
-		fmt.Println("Number of records updated in database:", num)
+		logs.Println("Number of records updated in database:", num)
 		return true
 	} else {
 		logs.Println(lib.FuncName(), err)

+ 2 - 2
models/Device/Device.go

@@ -201,7 +201,7 @@ func Delete_Device_(v Device) bool {
 	o := orm.NewOrm()
 	v.T_State = 0
 	if num, err := o.Update(&v, "T_State"); err == nil {
-		fmt.Println("Number of records updated in database:", num)
+		logs.Println("Number of records updated in database:", num)
 	} else {
 		logs.Println(lib.FuncName(), err)
 		return false
@@ -215,7 +215,7 @@ func Delete_Device_(v Device) bool {
 func Update_Device(m Device, cols ...string) bool {
 	o := orm.NewOrm()
 	if num, err := o.Update(&m, cols...); err == nil {
-		fmt.Println("Number of records updated in database:", num)
+		logs.Println("Number of records updated in database:", num)
 		Redis_Device_Set(m.T_sn, m)
 		return true
 	} else {

+ 2 - 2
models/Device/DeviceClass.go

@@ -126,7 +126,7 @@ func Delete_DeviceClass_(v DeviceClass) bool {
 	o := orm.NewOrm()
 	v.T_State = 0
 	if num, err := o.Update(&v, "T_State"); err == nil {
-		fmt.Println("Number of records updated in database:", num)
+		logs.Println("Number of records updated in database:", num)
 	} else {
 		logs.Println(lib.FuncName(), err)
 		return false
@@ -139,7 +139,7 @@ func Delete_DeviceClass_(v DeviceClass) bool {
 func Update_DeviceClass(m DeviceClass, cols ...string) bool {
 	o := orm.NewOrm()
 	if num, err := o.Update(&m, cols...); err == nil {
-		fmt.Println("Number of records updated in database:", num)
+		logs.Println("Number of records updated in database:", num)
 		return true
 	} else {
 		logs.Println(lib.FuncName(), err)

+ 5 - 5
models/Device/DeviceClassList.go

@@ -186,7 +186,7 @@ func Delete_DeviceClassList_(v DeviceClassList) bool {
 	o := orm.NewOrm()
 	v.T_State = 0
 	if num, err := o.Update(&v, "T_State"); err == nil {
-		fmt.Println("Number of records updated in database:", num)
+		logs.Println("Number of records updated in database:", num)
 	} else {
 		logs.Println(lib.FuncName(), err)
 		return false
@@ -200,7 +200,7 @@ func Delete_DeviceClassList_(v DeviceClassList) bool {
 func Update_DeviceClassList(m DeviceClassList, cols ...string) bool {
 	o := orm.NewOrm()
 	if num, err := o.Update(&m, cols...); err == nil {
-		fmt.Println("Number of records updated in database:", num)
+		logs.Println("Number of records updated in database:", num)
 		Redis_DeviceClassList_Set(m.T_sn, m)
 		return true
 	} else {
@@ -256,7 +256,7 @@ func Read_DeviceClassList_OrderList(T_class int, T_sn, T_remark string, page int
 	}
 
 	sql := "SELECT COUNT(ID) FROM device_class_list WHERE " + sqlWhere
-	fmt.Println(sql)
+	logs.Println(sql)
 	_, err := o.Raw(sql).ValuesList(&maps_z)
 	if err != nil {
 		return r, 0
@@ -264,13 +264,13 @@ func Read_DeviceClassList_OrderList(T_class int, T_sn, T_remark string, page int
 	if len(maps_z) == 0 {
 		return r, 0
 	}
-	//fmt.Println("maps_z;",maps_z[0][0])
+	//logs.Println("maps_z;",maps_z[0][0])
 	sql = "SELECT *  FROM device_class_list WHERE " + sqlWhere + " ORDER BY t_id+0 "
 	if page_z != 9999 {
 		sql = sql + " LIMIT " + strconv.Itoa(offset) + "," + strconv.Itoa(pagez)
 	}
 
-	fmt.Println(sql)
+	logs.Println(sql)
 	_, err = o.Raw(sql).QueryRows(&r)
 	if err != nil {
 		logs.Println(lib.FuncName(), err)

+ 32 - 32
models/Device/DeviceData.go

@@ -43,19 +43,19 @@ func init() {
 
 	configJPG := fmt.Sprintf(`{"key":"%s","conn":"%s","dbNum":"%s","password":"%s"}`,
 		"redis_DeviceDataJPG", conf.Redis_address, conf.Redis_dbNum, conf.Redis_password)
-	fmt.Println(config)
+	logs.Println(config)
 	var err error
 	redisCache_DeviceData, err = cache.NewCache("redis", config)
 	if err != nil || redisCache_DeviceData == nil {
 		errMsg := "failed to init redis"
-		fmt.Println(errMsg, err)
+		logs.Println(errMsg, err)
 
 	}
 
 	redisCache_DeviceDataJPG, err = cache.NewCache("redis", configJPG)
 	if err != nil || redisCache_DeviceDataJPG == nil {
 		errMsg := "failed to init redis"
-		fmt.Println(errMsg, err)
+		logs.Println(errMsg, err)
 
 	}
 }
@@ -64,7 +64,7 @@ func DeviceData_Set(key string) (err error) {
 
 	err = redisCache_DeviceData.Put(key, "", 2*time.Hour)
 	if err != nil {
-		fmt.Println("set key:", key, err)
+		logs.Println("set key:", key, err)
 	}
 	return
 }
@@ -81,7 +81,7 @@ func RedisDeviceData_Set(key string, r DeviceData_New) (err error) {
 
 	err = redisCache_DeviceData.Put(key, str, 24*time.Hour)
 	if err != nil {
-		fmt.Println("set key:", key, ",value:", str, err)
+		logs.Println("set key:", key, ",value:", str, err)
 	}
 	return
 }
@@ -173,7 +173,7 @@ func CREATE_DeviceData(SN string) bool {
 //// 添加
 //func Add_DeviceData(SN string, t_id string, t_t string, t_rh string, t_time string) bool {
 //	key := SN + "|" + t_id + "|" + t_time
-//	//fmt.Println(key)
+//	//logs.Println(key)
 //	if redisCache_DeviceData.IsExist(key) {
 //		//println("找到key:",key)
 //		return true
@@ -185,14 +185,14 @@ func CREATE_DeviceData(SN string) bool {
 //	var maps_z []orm2.ParamsList
 //
 //	sql := "SELECT COUNT(ID) FROM z_devicedata_" + SN + " WHERE t_time = '" + t_time + "' AND t_id = " + t_id
-//	//fmt.Println(sql)
+//	//logs.Println(sql)
 //	_, err := o.Raw(sql).ValuesList(&maps_z)
 //
 //	if err != nil {
 //		logs.Error(lib.FuncName(),err)
 //		return false
 //	}
-//	//fmt.Println("maps_z[0][0]:",maps_z[0][0])
+//	//logs.Println("maps_z[0][0]:",maps_z[0][0])
 //	if lib.To_int(maps_z[0][0]) > 0 {
 //		// 存在 写入 redis
 //		DeviceData_Set(key)
@@ -201,7 +201,7 @@ func CREATE_DeviceData(SN string) bool {
 //	// 开始插入数据
 //	sql = "INSERT INTO z_devicedata_" + SN + " (`t_id`, `t_t`, `t_rh`, `t_time`) VALUES (" + t_id + ", " + t_t + ", " + t_rh + ", '" + t_time + "')"
 //	//  这里有时间优化  用于一次 prepare 多次 exec,以提高批量执行的速度
-//	//fmt.Println(sql)
+//	//logs.Println(sql)
 //	res, err := o.Raw(sql).Exec()
 //	if err != nil {
 //		logs.Error(lib.FuncName(),err)
@@ -210,7 +210,7 @@ func CREATE_DeviceData(SN string) bool {
 //	res.RowsAffected()
 //	// 存在 写入 redis
 //	DeviceData_Set(key)
-//	//fmt.Println("mysql row affected nums: ", num)
+//	//logs.Println("mysql row affected nums: ", num)
 //	return true
 //}
 
@@ -263,7 +263,7 @@ func Read_DeviceSensorData_ById_List(SN string, Time_start_ string, Time_end_ st
 	if len(sql_time) > 0 {
 		sql += " WHERE " + sql_time
 	}
-	fmt.Println(sql)
+	logs.Println(sql)
 	_, err := o.Raw(sql).ValuesList(&maps_z)
 	if err != nil {
 		return maps, 0
@@ -271,7 +271,7 @@ func Read_DeviceSensorData_ById_List(SN string, Time_start_ string, Time_end_ st
 	if len(maps_z) == 0 {
 		return maps, 0
 	}
-	//fmt.Println("maps_z;",maps_z[0][0])
+	//logs.Println("maps_z;",maps_z[0][0])
 	//sql = "SELECT t_id,t_t,t_rh,DATE_FORMAT(t_time,'%Y-%m-%d %H:%i:%s') AS t_time  FROM z_devicedata_" + SN
 	sql = "SELECT t_t,t_rh,DATE_FORMAT(t_time,'%Y-%m-%d %H:%i:%s') AS t_time  FROM z_devicedata_" + SN
 	if len(sql_time) > 0 {
@@ -282,7 +282,7 @@ func Read_DeviceSensorData_ById_List(SN string, Time_start_ string, Time_end_ st
 		sql = sql + " LIMIT " + strconv.Itoa(offset) + "," + strconv.Itoa(pagez)
 	}
 
-	fmt.Println(sql)
+	logs.Println(sql)
 	_, err = o.Raw(sql).QueryRows(&maps)
 	if err != nil {
 		logs.Println(lib.FuncName(), err)
@@ -315,7 +315,7 @@ func Read_DeviceData_By_snid(SN string, T_id int, Time_start_ string, Time_end_
 	//sql := "SELECT t_id,t_t,t_rh,DATE_FORMAT(t_time,'%Y-%m-%d %H:%i:%s') AS t_time  FROM z_devicedata_" + SN + " WHERE " + sql_time + " t_id = " + strconv.Itoa(T_id) + " ORDER BY t_time DESC "
 	sql := "SELECT t_t,t_rh,DATE_FORMAT(t_time,'%Y-%m-%d %H:%i:%s') AS t_time  FROM z_devicedata_" + SN + " WHERE " + sql_time + " t_id = " + strconv.Itoa(T_id) + " ORDER BY t_time DESC "
 	sql = sql + " LIMIT " + strconv.Itoa(offset) + "," + strconv.Itoa(limit)
-	fmt.Println(sql)
+	logs.Println(sql)
 	_, err := o.Raw(sql).QueryRows(&maps)
 	if err != nil {
 		logs.Println(lib.FuncName(), err)
@@ -343,7 +343,7 @@ func Read_DeviceData_Count_By_snid(SN string, T_id int, Time_start_ string, Time
 	}
 
 	sql := "SELECT COUNT(ID) FROM z_devicedata_" + SN + " WHERE " + sql_time + " t_id = " + strconv.Itoa(T_id)
-	fmt.Println(sql)
+	logs.Println(sql)
 	_, err := o.Raw(sql).ValuesList(&maps_z)
 	if err != nil {
 		return 0
@@ -381,7 +381,7 @@ func Read_DeviceSensorData_List(SN string, Time_start_ string, Time_end_ string,
 	}
 
 	sql := "SELECT COUNT(ID) FROM z_devicedata_" + SN + " " + sql_time
-	fmt.Println(sql)
+	logs.Println(sql)
 	_, err := o.Raw(sql).ValuesList(&maps_z)
 	if err != nil {
 		return maps, 0
@@ -389,14 +389,14 @@ func Read_DeviceSensorData_List(SN string, Time_start_ string, Time_end_ string,
 	if len(maps_z) == 0 {
 		return maps, 0
 	}
-	//fmt.Println("maps_z;",maps_z[0][0])
+	//logs.Println("maps_z;",maps_z[0][0])
 	//sql = "SELECT t_id,t_t,t_rh,DATE_FORMAT(t_time,'%Y-%m-%d %H:%i:%s') AS t_time  FROM z_devicedata_" + SN + " " + sql_time + " ORDER BY t_time DESC "
 	sql = "SELECT t_t,t_rh,DATE_FORMAT(t_time,'%Y-%m-%d %H:%i:%s') AS t_time  FROM z_devicedata_" + SN + " " + sql_time + " ORDER BY t_time DESC "
 	if page_z != 9999 {
 		sql = sql + " LIMIT " + strconv.Itoa(offset) + "," + strconv.Itoa(pagez)
 	}
 
-	fmt.Println(sql)
+	logs.Println(sql)
 	_, err = o.Raw(sql).QueryRows(&maps)
 	if err != nil {
 		logs.Println(lib.FuncName(), err)
@@ -423,7 +423,7 @@ func Read_DeviceSensorData_List_z(SN string, Time_start_ string) int {
 	}
 
 	sql := "SELECT COUNT(ID) FROM z_devicedata_" + SN + " " + sql_time
-	fmt.Println(sql)
+	logs.Println(sql)
 	_, err := o.Raw(sql).ValuesList(&maps_z)
 	if err != nil {
 		logs.Println(lib.FuncName(), err)
@@ -450,18 +450,18 @@ func Read_DeviceSensorData_ById_New(SN string, T_id int) (DeviceData_New, bool)
 		return r, true
 	}
 
-	//fmt.Println("maps_z;",maps_z[0][0])
+	//logs.Println("maps_z;",maps_z[0][0])
 	//sql := "SELECT t_id,t_t,t_rh,t_time  FROM z_devicedata_" + SN + " WHERE " + " t_id = " + strconv.Itoa(T_id) + " ORDER BY t_time DESC "
 	sql := "SELECT t_t,t_rh,t_time  FROM z_devicedata_" + SN + " WHERE " + " t_id = " + strconv.Itoa(T_id) + " ORDER BY t_time DESC "
 	sql = sql + " LIMIT 0,1 "
 
-	fmt.Println(sql)
+	logs.Println(sql)
 	err := o.Raw(sql).QueryRow(&maps)
 	if err != nil {
 		logs.Error(lib.FuncName(), err)
 		return maps, false
 	}
-	fmt.Println("T_time:", maps.T_time)
+	logs.Println("T_time:", maps.T_time)
 	RedisDeviceData_Set(key_data, maps)
 	return maps, true
 }
@@ -479,7 +479,7 @@ func Read_DeviceSensorData_By_T_snid_List(T_snid string, Time_start_ string, Tim
 			maps = append(maps, r_maps...)
 			maps_num = maps_num + r_maps_num
 
-			fmt.Println("加载数据:", sn_id[0], sn_id[1], r_maps_num)
+			logs.Println("加载数据:", sn_id[0], sn_id[1], r_maps_num)
 		}
 	}
 	if page <= 1 {
@@ -495,10 +495,10 @@ func Read_DeviceSensorData_By_T_snid_List(T_snid string, Time_start_ string, Tim
 	}
 
 	if page_z == 9999 {
-		fmt.Println("总数据:", maps_num, " 导出")
+		logs.Println("总数据:", maps_num, " 导出")
 		return maps, maps_num
 	}
-	fmt.Println("总数据:", maps_num, " 截取", offset, offset+page_z)
+	logs.Println("总数据:", maps_num, " 截取", offset, offset+page_z)
 	return maps[offset:offset_z], maps_num
 }
 
@@ -512,10 +512,10 @@ func Read_DeviceData_ById_Year_List(SN string) []orm2.ParamsList {
 
 	//sql = "SELECT t_name,t_t,t_rh,t_tl,t_tu,t_rhl,t_rhu,t_site,DATE_FORMAT(t_time,'%Y-%m-%d %H:%i:%s') AS t_time  FROM z_devicedata_"+SN+" WHERE "+sql_time+" t_id = "+ strconv.Itoa(T_id) +" ORDER BY t_time DESC "
 	sql := "SELECT DATE_FORMAT(t_time,\"%m\") AS m ,DATE_FORMAT(t_time,\"%d\") AS d FROM z_devicedata_" + SN + "  WHERE t_time > '" + strconv.Itoa(time.Now().Year()) + "-0-0 00:00:00' GROUP BY DATE_FORMAT(t_time,\"%m\");"
-	fmt.Println(sql)
+	logs.Println(sql)
 	num, err := o.Raw(sql).ValuesList(&maps_z)
 	if err == nil && num > 0 {
-		fmt.Println(maps_z[0][0]) // slene
+		logs.Println("", maps_z[0][0]) // slene
 	}
 	//value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", cnt), 64)
 	//key,_ := strconv.Atoi(maps_z[0][0].(string))
@@ -534,7 +534,7 @@ func Read_DeviceData_ById_Month_List(SN string) []orm2.ParamsList {
 
 	//sql = "SELECT t_name,t_t,t_rh,t_tl,t_tu,t_rhl,t_rhu,t_site,DATE_FORMAT(t_time,'%Y-%m-%d %H:%i:%s') AS t_time  FROM z_devicedata_"+SN+" WHERE "+sql_time+" t_id = "+ strconv.Itoa(T_id) +" ORDER BY t_time DESC "
 	sql := "SELECT DATE_FORMAT(t_time,\"%d\") AS d FROM z_devicedata_" + SN + "  WHERE t_time > '" + time_x + "' GROUP BY DATE_FORMAT(t_time,\"%d\");"
-	fmt.Println(sql)
+	logs.Println(sql)
 	o.Raw(sql).ValuesList(&maps_z)
 
 	//value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", cnt), 64)
@@ -554,7 +554,7 @@ func Read_DeviceSensorData_ById_Day_List(SN string) []orm2.ParamsList {
 
 	//sql = "SELECT t_name,t_t,t_rh,t_tl,t_tu,t_rhl,t_rhu,t_site,DATE_FORMAT(t_time,'%Y-%m-%d %H:%i:%s') AS t_time  FROM z_devicedata_"+SN+" WHERE "+sql_time+" t_id = "+ strconv.Itoa(T_id) +" ORDER BY t_time DESC "
 	sql := "SELECT DATE_FORMAT(t_time,\"%H\") AS m FROM z_devicedata_" + SN + "  WHERE t_time > '" + time_x + "' GROUP BY DATE_FORMAT(t_time,\"%H\");"
-	fmt.Println(sql)
+	logs.Println(sql)
 	o.Raw(sql).ValuesList(&maps_z)
 
 	//value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", cnt), 64)
@@ -576,7 +576,7 @@ func Read_DeviceSensorData_List_GROUP_BY_t_time(SN string, Time_start_ string, T
 	}
 
 	sql := "SELECT DATE_FORMAT(t_time,'%Y-%m-%d %H:%i:%s') AS t_time FROM z_devicedata_" + SN + " WHERE " + sql_time + "   GROUP BY t_time  ORDER BY t_time DESC "
-	fmt.Println(sql)
+	logs.Println(sql)
 	o.Raw(sql).ValuesList(&maps_z)
 	return maps_z
 }
@@ -600,10 +600,10 @@ func Read_DeviceData_T_Min_Max_Time_Min_Max(SN string, Time_start_ string, Time_
 	if len(sql_condition) > 0 {
 		sql_condition = " WHERE " + strings.TrimLeft(sql_condition, " AND ")
 	}
-	//fmt.Println("maps_z;",maps_z[0][0])
+	//logs.Println("maps_z;",maps_z[0][0])
 	sql := "SELECT MIN(t_t) AS min_t, MAX(t_t) AS max_t,MIN(t_time) AS min_time, MAX(t_time) AS max_time FROM z_devicedata_" + SN + sql_condition
 
-	fmt.Println(sql)
+	logs.Println(sql)
 	err := o.Raw(sql).QueryRow(&minT, &maxT, &minTime, &maxTime)
 	if err != nil {
 		logs.Error(lib.FuncName(), err)

+ 2 - 3
models/System/Logs.go

@@ -1,7 +1,7 @@
 package System
 
 import (
-	"fmt"
+	"ColdVerify_server/logs"
 	"github.com/beego/beego/v2/adapter/orm"
 	orm2 "github.com/beego/beego/v2/client/orm"
 	"time"
@@ -67,9 +67,8 @@ func Read_Logs_Class() (lists orm2.ParamsList) {
 	var pl_lists orm2.ParamsList
 	num, err := o.Raw("SELECT DISTINCT logs_class FROM Logs LIMIT 0,1000").ValuesFlat(&pl_lists)
 	if err == nil {
-		fmt.Println("user nums: ", num)
+		logs.Println("user nums: ", num)
 	}
-	fmt.Println(len(pl_lists))
 
 	return pl_lists
 }

+ 2 - 2
models/System/News.go

@@ -1,7 +1,7 @@
 package System
 
 import (
-	"fmt"
+	"ColdVerify_server/logs"
 	"github.com/beego/beego/v2/adapter/orm"
 	"time"
 )
@@ -43,7 +43,7 @@ func Update_AdminNews_News_Tag_2(Id int) (err error) {
 		var num int64
 		v.News_Tag = 2
 		if num, err = o.Update(&v, "News_Tag"); err == nil {
-			fmt.Println("Number of records updated in database:", num)
+			logs.Println("Number of records updated in database:", num)
 		}
 	}
 

+ 3 - 5
models/System/UserLogs.go

@@ -1,8 +1,8 @@
 package System
 
 import (
+	"ColdVerify_server/logs"
 	"encoding/json"
-	"fmt"
 	"github.com/beego/beego/v2/adapter/orm"
 	orm2 "github.com/beego/beego/v2/client/orm"
 	"time"
@@ -39,7 +39,7 @@ func Add_UserLogs_T(Logs_uuid string, Logs_class string, Logs_Title string, Logs
 	o := orm.NewOrm()
 	jsonStu, err := json.Marshal(Logs_Txt_T)
 	if err != nil {
-		fmt.Println("Add_UserLogs_T JSON ,err=", err)
+		logs.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)}
 	o.Insert(&m)
@@ -71,9 +71,7 @@ func Read_UserLogs_Class() (lists orm2.ParamsList) {
 	var pl_lists orm2.ParamsList
 	num, err := o.Raw("SELECT DISTINCT logs_class FROM UserLogs LIMIT 0,1000").ValuesFlat(&pl_lists)
 	if err == nil {
-		fmt.Println("user nums: ", num)
+		logs.Println("user nums: ", num)
 	}
-	fmt.Println(len(pl_lists))
-
 	return pl_lists
 }

+ 4 - 4
models/Task/Task.go

@@ -294,7 +294,7 @@ func Delete_Task_(v Task) bool {
 	o := orm.NewOrm()
 	v.T_State = 0
 	if num, err := o.Update(&v, "T_State"); err == nil {
-		fmt.Println("Number of records updated in database:", num)
+		logs.Println("Number of records updated in database:", num)
 	} else {
 		logs.Error(lib.FuncName(), err)
 		return false
@@ -308,7 +308,7 @@ func Delete_Task_(v Task) bool {
 func Update_Task(m Task, cols ...string) bool {
 	o := orm.NewOrm()
 	if num, err := o.Update(&m, cols...); err == nil {
-		fmt.Println("Number of records updated in database:", num)
+		logs.Println("Number of records updated in database:", num)
 		Redis_Task_Set(m.T_task_id, m)
 		return true
 	} else {
@@ -322,7 +322,7 @@ func Add_Task_Visit(m Task) bool {
 	o := orm.NewOrm()
 	m.T_Visit += 1
 	if num, err := o.Update(&m, "T_Visit"); err == nil {
-		fmt.Println("Number of records updated in database:", num)
+		logs.Println("Number of records updated in database:", num)
 		Redis_Task_Set(m.T_task_id, m)
 		return true
 	} else {
@@ -445,7 +445,7 @@ func Read_Task_List_Time(page int, T_sn string, T_Title string, Time_start_ stri
 	}
 
 	if len(Time_start_) > 1 && len(Time_end_) > 1 {
-		fmt.Println(Time_start_, Time_end_)
+		logs.Println(Time_start_, Time_end_)
 		qs.Limit(conf.Page_size, offset).Filter("T_Ut__lte", Time_end_+" 23:59:59").Filter("T_Ut__gte", Time_start_+" 00:00:00").Filter("T_Title__icontains", T_Title).Filter("T_sn__icontains", T_sn).OrderBy("-Id").Filter("T_State", 1).All(&r)
 		cnt, _ = qs.Filter("T_Ut__lte", Time_end_+" 23:59:59").Filter("T_Ut__gte", Time_start_+" 00:00:00").Filter("T_Title__icontains", T_Title).Filter("T_sn__icontains", T_sn).Filter("T_State", 1).Count()
 		return []Task_R{}, cnt

+ 15 - 16
models/Task/TaskData.go

@@ -4,7 +4,6 @@ import (
 	"ColdVerify_server/lib"
 	"ColdVerify_server/logs"
 	"errors"
-	"fmt"
 	_ "github.com/astaxie/beego/cache/redis"
 	"github.com/beego/beego/v2/adapter/orm"
 	orm2 "github.com/beego/beego/v2/client/orm"
@@ -157,7 +156,7 @@ func Read_TaskData_Count(T_task_id string) int {
 
 	sql := "SELECT COUNT(ID) FROM z_task_data_" + T_task_id
 
-	fmt.Println(sql)
+	logs.Println(sql)
 	_, err := o.Raw(sql).ValuesList(&maps_z)
 	if err != nil {
 		logs.Error(lib.FuncName(), err)
@@ -221,7 +220,7 @@ func Read_TaskData_ById_List(T_task_id string, SN string, T_id int, Time_start_
 
 	sql := "SELECT COUNT(ID) FROM z_task_data_" + T_task_id + sql_condition
 
-	fmt.Println(sql)
+	logs.Println(sql)
 	_, err := o.Raw(sql).ValuesList(&maps_z)
 	if err != nil {
 		logs.Error(lib.FuncName(), err)
@@ -231,13 +230,13 @@ func Read_TaskData_ById_List(T_task_id string, SN string, T_id int, Time_start_
 		return maps, 0
 	}
 
-	//fmt.Println("maps_z;",maps_z[0][0])
+	//logs.Println("maps_z;",maps_z[0][0])
 	sql = "SELECT ID,t_sn,t_id,t_t,t_rh,DATE_FORMAT(t_time,'%Y-%m-%d %H:%i:%s') AS t_times,t_time FROM z_task_data_" + T_task_id + sql_condition + " ORDER BY t_time DESC "
 	if page_z != 9999 {
 		sql = sql + " LIMIT " + strconv.Itoa(offset) + "," + strconv.Itoa(pagez)
 	}
 
-	fmt.Println(sql)
+	logs.Println(sql)
 	_, err = o.Raw(sql).QueryRows(&maps)
 
 	//value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", cnt), 64)
@@ -254,10 +253,10 @@ func Read_TaskData_ById_List_(T_task_id string, SN string) []TaskData_ {
 	//sql_condition += " t_id = " + strconv.Itoa(T_id) + " AND "
 	sql_condition += "t_sn = '" + SN + "'"
 
-	//fmt.Println("maps_z;",maps_z[0][0])
+	//logs.Println("maps_z;",maps_z[0][0])
 	sql := "SELECT ID,t_sn,t_id,t_t,t_rh,DATE_FORMAT(t_time,'%Y-%m-%d %H:%i') AS t_times,t_time  FROM z_task_data_" + T_task_id + " WHERE " + sql_condition + " ORDER BY t_time "
 
-	fmt.Println(sql)
+	logs.Println(sql)
 	o.Raw(sql).QueryRows(&maps)
 
 	return maps
@@ -267,10 +266,10 @@ func Read_TaskData_ById_ClassList(T_task_id string) []TaskDataClass_ {
 	o := orm.NewOrm()
 	var maps []TaskDataClass_
 
-	//fmt.Println("maps_z;",maps_z[0][0])
+	//logs.Println("maps_z;",maps_z[0][0])
 	sql := "SELECT DISTINCT t_sn FROM z_task_data_" + T_task_id + " ORDER BY t_sn"
 
-	fmt.Println(sql)
+	logs.Println(sql)
 	o.Raw(sql).QueryRows(&maps)
 
 	return maps
@@ -291,7 +290,7 @@ func Add_TaskData(T_task_id string, T_sn string, T_id string, T_t string, T_rh s
 	//sql := "DELETE FROM z_task_data_" + T_task_id + "  WHERE " + " t_id = " + T_id + " AND "+ " t_sn = '"+T_sn+"' " + "AND t_time = '" + T_time + "'  "
 	//
 	////  这里有时间优化  用于一次 prepare 多次 exec,以提高批量执行的速度
-	//fmt.Println(sql)
+	//logs.Println(sql)
 	//res, err := o.Raw(sql).Exec()
 	//if err != nil {
 	//	logs.Error(lib.FuncName(),err)
@@ -302,7 +301,7 @@ func Add_TaskData(T_task_id string, T_sn string, T_id string, T_t string, T_rh s
 	sql := "INSERT INTO z_task_data_" + T_task_id + " (`t_sn`, `t_id`, `t_t`, `t_rh`, `t_time`) " +
 		"VALUES ('" + T_sn + "', " + T_id + ", " + T_t + "," + T_rh + ", '" + T_time + "')"
 
-	fmt.Println(sql)
+	logs.Println(sql)
 	res, err := o.Raw(sql).Exec()
 	if err != nil {
 		logs.Error(lib.FuncName(), err)
@@ -310,7 +309,7 @@ func Add_TaskData(T_task_id string, T_sn string, T_id string, T_t string, T_rh s
 	}
 	res.RowsAffected()
 
-	//fmt.Println("mysql row affected nums: ", num)
+	//logs.Println("mysql row affected nums: ", num)
 	return true
 }
 
@@ -336,7 +335,7 @@ func Up_TaskData(T_task_id string, Id string, T_t string, T_rh string, T_time st
 	// 开始插入数据 UPDATE `cold_verify`.`Z_TaskData_d8qMyeXLzIxn` SET `t_t` = 20.2 WHERE `ID` = 69
 	sql := "UPDATE z_task_data_" + T_task_id + " " + SET_str + " WHERE ID = " + Id
 	//  这里有时间优化  用于一次 prepare 多次 exec,以提高批量执行的速度
-	//fmt.Println(sql)
+	//logs.Println(sql)
 	res, err := o.Raw(sql).Exec()
 	if err != nil {
 		logs.Error(lib.FuncName(), err)
@@ -344,7 +343,7 @@ func Up_TaskData(T_task_id string, Id string, T_t string, T_rh string, T_time st
 	}
 	res.RowsAffected()
 
-	//fmt.Println("mysql row affected nums: ", num)
+	//logs.Println("mysql row affected nums: ", num)
 	return true
 }
 
@@ -364,7 +363,7 @@ func Del_TaskData(T_task_id string, Id string) bool {
 	}
 	res.RowsAffected()
 
-	//fmt.Println("mysql row affected nums: ", num)
+	//logs.Println("mysql row affected nums: ", num)
 	return true
 }
 
@@ -384,6 +383,6 @@ func Del_TaskData_t_id(T_task_id string, Id string) bool {
 	}
 	res.RowsAffected()
 
-	//fmt.Println("mysql row affected nums: ", num)
+	//logs.Println("mysql row affected nums: ", num)
 	return true
 }

+ 3 - 3
models/Template/Template.go

@@ -175,7 +175,7 @@ func Delete_Template_(v Template) bool {
 	o := orm.NewOrm()
 	v.T_State = 0
 	if num, err := o.Update(&v, "T_State"); err == nil {
-		fmt.Println("Number of records updated in database:", num)
+		logs.Println("Number of records updated in database:", num)
 	} else {
 		return false
 	}
@@ -188,7 +188,7 @@ func Delete_Template_(v Template) bool {
 func Update_Template(m Template, cols ...string) bool {
 	o := orm.NewOrm()
 	if num, err := o.Update(&m, cols...); err == nil {
-		fmt.Println("Number of records updated in database:", num)
+		logs.Println("Number of records updated in database:", num)
 		Redis_Template_Set(m.T_name, m)
 		return true
 	}
@@ -243,7 +243,7 @@ func Read_Template_List_Time(page int, T_sn string, T_Title string, Time_start_
 	}
 
 	if len(Time_start_) > 1 && len(Time_end_) > 1 {
-		fmt.Println(Time_start_, Time_end_)
+		logs.Println(Time_start_, Time_end_)
 		qs.Limit(conf.Page_size, offset).Filter("T_Ut__lte", Time_end_+" 23:59:59").Filter("T_Ut__gte", Time_start_+" 00:00:00").Filter("T_Title__icontains", T_Title).Filter("T_sn__icontains", T_sn).OrderBy("-Id").Filter("T_State", 1).All(&r)
 		cnt, _ = qs.Filter("T_Ut__lte", Time_end_+" 23:59:59").Filter("T_Ut__gte", Time_start_+" 00:00:00").Filter("T_Title__icontains", T_Title).Filter("T_sn__icontains", T_sn).Filter("T_State", 1).Count()
 		return []Template_R{}, cnt

+ 1 - 2
models/VerifyTemplate/VerifyTemplate.go

@@ -3,7 +3,6 @@ package VerifyTemplate
 import (
 	"ColdVerify_server/lib"
 	"ColdVerify_server/logs"
-	"fmt"
 	"github.com/beego/beego/v2/adapter/orm"
 	orm2 "github.com/beego/beego/v2/client/orm"
 	_ "github.com/go-sql-driver/mysql"
@@ -139,7 +138,7 @@ func Delete_VerifyTemplate(v VerifyTemplate) bool {
 func Update_VerifyTemplate(m VerifyTemplate, cols ...string) bool {
 	o := orm.NewOrm()
 	if num, err := o.Update(&m, cols...); err == nil {
-		fmt.Println("Number of records updated in database:", num)
+		logs.Println("Number of records updated in database:", num)
 		return true
 	}
 	return false

+ 1 - 2
models/VerifyTemplate/VerifyTemplateClass.go

@@ -3,7 +3,6 @@ package VerifyTemplate
 import (
 	"ColdVerify_server/lib"
 	"ColdVerify_server/logs"
-	"fmt"
 	_ "github.com/astaxie/beego/cache/redis"
 	"github.com/beego/beego/v2/adapter/orm"
 	orm2 "github.com/beego/beego/v2/client/orm"
@@ -88,7 +87,7 @@ func Add_VerifyTemplateClass(var_ VerifyTemplateClass) (id int64, err error) {
 func Update_VerifyTemplateClass(r VerifyTemplateClass, cols ...string) bool {
 	o := orm.NewOrm()
 	if num, err := o.Update(&r, cols...); err == nil {
-		fmt.Println("Number of records updated in database:", num)
+		logs.Println("Number of records updated in database:", num)
 		return true
 	}
 	return false

+ 2 - 2
models/VerifyTemplate/VerifyTemplateMap.go

@@ -3,10 +3,10 @@ package VerifyTemplate
 import (
 	"ColdVerify_server/lib"
 	"ColdVerify_server/logs"
-	"fmt"
 	"github.com/beego/beego/v2/adapter/orm"
 	orm2 "github.com/beego/beego/v2/client/orm"
 	_ "github.com/go-sql-driver/mysql"
+	"log"
 	"time"
 )
 
@@ -156,7 +156,7 @@ func Delete_VerifyTemplateMap(v VerifyTemplateMap) bool {
 func Update_VerifyTemplateMap(m VerifyTemplateMap, cols ...string) bool {
 	o := orm.NewOrm()
 	if num, err := o.Update(&m, cols...); err == nil {
-		fmt.Println("Number of records updated in database:", num)
+		log.Println("Number of records updated in database:", num)
 		return true
 	}
 	return false

+ 1 - 2
tests/default_test.go

@@ -3,7 +3,6 @@ package test
 import (
 	"ColdVerify_server/lib"
 	"ColdVerify_server/logs"
-	"fmt"
 	"testing"
 	"time"
 )
@@ -14,7 +13,7 @@ func TestBeego(t *testing.T) {
 	if err != nil {
 		logs.Error(lib.FuncName(), err)
 	}
-	fmt.Println(formatTime) //打印结果:2017-04-11 13:33:37 +0000 UTC
+	logs.Println("formatTime", formatTime) //打印结果:2017-04-11 13:33:37 +0000 UTC
 	//// Read from docx file
 	//r, err := docx.ReadDocxFile("./template.docx")
 	//// Or read from memory