siked 2 rokov pred
rodič
commit
4e3b53bfb7

BIN
Cold_Api6200


BIN
Cold_Api6201


+ 14 - 0
conf/app.conf

@@ -3,6 +3,12 @@ HTTPPort = 6200
 runmode = dev
 EnableDocs = true
 copyrequestbody = true
+#热更新
+# Graceful = true
+#进程内监控
+# EnableAdmin = true
+# AdminAddr = "localhost"
+# AdminPort = 8088
 
 # Nats
 NatsServer_Url = "192.168.192.63:4222"
@@ -16,6 +22,14 @@ MysqlServer_Password = "j6WXwyEckZS7bJFM"
 MysqlServer_MaxIdleConnections = 100
 MysqlServer_MaxOpenConnections = 200
 
+# # Mysql
+# MysqlServer_UrlPort = "192.168.192.250:3306"
+# MysqlServer_Database = "culd"
+# MysqlServer_Username = "cold"
+# MysqlServer_Password = "j6WXwyEckZS7bJFM"
+# MysqlServer_MaxIdleConnections = 100
+# MysqlServer_MaxOpenConnections = 200
+
 
 # Redis
 Redis_address = "192.168.192.63:6379"

+ 4 - 4
controllers/Data.go

@@ -622,10 +622,10 @@ func (c *DataController) Device_Sensor_Data_Excel_m() {
 	}
 
 	//删除目录
-	err := os.Remove("ofile/" + timeStr + ".xlsx")
-	if err != nil {
-		fmt.Println(err)
-	}
+	//err := os.Remove("ofile/" + timeStr + ".xlsx")
+	//if err != nil {
+	//	fmt.Println(err)
+	//}
 
 	c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: url}
 	c.ServeJSON()

+ 10 - 0
controllers/Device.go

@@ -1136,6 +1136,16 @@ func (c *DeviceController) DeviceWarning_() {
 
 	c.TplName = "Device/DeviceWarning-.html"
 }
+func (c *DeviceController) DeviceWarning_log() {
+	id, _ := c.GetInt("id")
+
+	T_Log := Device.Read_DeviceWarning_ById(id).T_Log
+
+	T_Log = strings.Replace(T_Log, "\n", "<hr>", -1)
+
+	c.Data["T_Log"] = T_Log
+	c.TplName = "Device/DeviceWarning-log.html"
+}
 func (c *DeviceController) DeviceWarning_M() {
 	id := c.GetString("id")
 	c.Data["id"] = id

+ 20 - 0
controllers/lib/WritePid.go

@@ -0,0 +1,20 @@
+package lib
+
+import (
+	"bufio"
+	"os"
+	"strconv"
+)
+
+func WritePid() {
+	fileName := "./server.pid"
+	file, _ := os.OpenFile(fileName, os.O_RDWR|os.O_CREATE, 0666)
+	defer file.Close()
+
+	writer := bufio.NewWriter(file)
+
+	pid := strconv.Itoa(os.Getpid())
+	println("server_pid:", pid)
+	writer.Write([]byte(pid))
+	writer.Flush()
+}

+ 71 - 0
go.sh

@@ -0,0 +1,71 @@
+#!/bin/bash
+#这里可替换为你自己的执行程序,其他代码无需更改
+APP_NAME=Cold_Api6200
+#使用说明,用来提示输入参数
+usage() {
+  echo "Usage: sh 脚本名.sh [start|stop|restart|status]"
+  exit 1
+}
+#检查程序是否在运行
+is_exist() {
+  pid=$(ps -ef | grep $APP_NAME | grep -v grep | awk '{print $2}')
+  #如果不存在返回1,存在返回0
+  if [ -z "${pid}" ]; then
+    return 1
+  else
+    return 0
+  fi
+}
+#启动方法
+start() {
+  is_exist
+  if [ $? -eq "0" ]; then
+    echo "${APP_NAME} is already running. pid=${pid} ."
+  else
+    mkdir -p logs
+    export GO111MODULE=off
+    nohup ./${APP_NAME} >> ./logs/nohup.out 2>&1 &
+    echo "${APP_NAME} start success"
+  fi
+}
+#停止方法
+stop() {
+  is_exist
+  if [ $? -eq "0" ]; then
+    kill -9 $pid
+  else
+    echo "${APP_NAME} is not running"
+  fi
+}
+#输出运行状态
+status() {
+  is_exist
+  if [ $? -eq "0" ]; then
+    echo "${APP_NAME} is running. Pid is ${pid}"
+  else
+    echo "${APP_NAME} is NOT running."
+  fi
+}
+#重启
+restart() {
+  stop
+  start
+}
+#根据输入参数,选择执行对应方法,不输入则执行使用说明
+case "$1" in
+"start")
+  start
+  ;;
+"stop")
+  stop
+  ;;
+"status")
+  status
+  ;;
+"restart")
+  restart
+  ;;
+*)
+  usage
+  ;;
+esac

+ 1 - 1
lastupdate.tmp

@@ -1 +1 @@
-{"C:\\BZD\\Cold\\Cold_Api\\controllers":1658904582455047900}
+{"C:\\BZD\\Cold\\Cold_Api\\controllers":1659086817078270100}

+ 37 - 0
logs/logx/logx.log

@@ -0,0 +1,37 @@
+2022/07/28 09:12:50.128 [I]  2022-07-28 09:12:50>%!(EXTRA []interface {}=[============Nats init============])
+2022/07/28 09:12:50.251 [I]  2022-07-28 09:12:50>%!(EXTRA []interface {}=[nats OK!])
+2022/07/28 09:37:28.450 [I]  2022-07-28 09:37:28>%!(EXTRA []interface {}=[============Nats init============])
+2022/07/28 09:37:28.564 [I]  2022-07-28 09:37:28>%!(EXTRA []interface {}=[nats OK!])
+2022/07/28 09:56:10.428 [I]  2022-07-28 09:56:10>%!(EXTRA []interface {}=[============Nats init============])
+2022/07/28 09:56:10.546 [I]  2022-07-28 09:56:10>%!(EXTRA []interface {}=[nats OK!])
+2022/07/28 10:08:44.098 [I]  2022-07-28 10:08:44>%!(EXTRA []interface {}=[============Nats init============])
+2022/07/28 10:08:44.211 [I]  2022-07-28 10:08:44>%!(EXTRA []interface {}=[nats OK!])
+2022/07/28 10:53:19.635 [I]  2022-07-28 10:53:19>%!(EXTRA []interface {}=[Nats => Cold_Api/Nats/NatsServer.Qiniu_UploadFile C:/Users/SIKED/AppData/Local/Temp/GoLand/ofile/20220728105319.xlsx ofile/20220728105319.xlsx])
+2022/07/28 10:53:53.035 [I]  2022-07-28 10:53:53>%!(EXTRA []interface {}=[Nats => Cold_Api/Nats/NatsServer.Qiniu_UploadFile C:/Users/SIKED/AppData/Local/Temp/GoLand/ofile/20220728105352.xlsx ofile/20220728105352.xlsx])
+2022/07/28 10:54:31.011 [I]  2022-07-28 10:54:31>%!(EXTRA []interface {}=[Nats => Cold_Api/Nats/NatsServer.Qiniu_UploadFile C:/Users/SIKED/AppData/Local/Temp/GoLand/ofile/20220728105430.xlsx ofile/20220728105430.xlsx])
+2022/07/28 10:55:11.469 [I]  2022-07-28 10:55:11>%!(EXTRA []interface {}=[Nats => Cold_Api/Nats/NatsServer.Qiniu_UploadFile C:/Users/SIKED/AppData/Local/Temp/GoLand/ofile/20220728105511.xlsx ofile/20220728105511.xlsx])
+2022/07/28 10:56:25.794 [I]  2022-07-28 10:56:25>%!(EXTRA []interface {}=[============Nats init============])
+2022/07/28 10:56:25.910 [I]  2022-07-28 10:56:25>%!(EXTRA []interface {}=[nats OK!])
+2022/07/28 10:56:53.151 [I]  2022-07-28 10:56:53>%!(EXTRA []interface {}=[Nats => Cold_Api/Nats/NatsServer.Qiniu_UploadFile C:/Users/SIKED/AppData/Local/Temp/GoLand/ofile/20220728105653.xlsx ofile/20220728105653.xlsx])
+2022/07/28 10:57:44.594 [I]  2022-07-28 10:57:44>%!(EXTRA []interface {}=[Nats => Cold_Api/Nats/NatsServer.Qiniu_UploadFile C:/Users/SIKED/AppData/Local/Temp/GoLand/ofile/20220728105744.xlsx ofile/20220728105744.xlsx])
+2022/07/28 10:59:45.963 [I]  2022-07-28 10:59:45>%!(EXTRA []interface {}=[Nats => Cold_Api/Nats/NatsServer.Qiniu_UploadFile C:/Users/SIKED/AppData/Local/Temp/GoLand/ofile/20220728105945.xlsx ofile/20220728105945.xlsx])
+2022/07/28 11:01:15.508 [I]  2022-07-28 11:01:15>%!(EXTRA []interface {}=[Nats => Cold_Api/Nats/NatsServer.Qiniu_UploadFile C:/Users/SIKED/AppData/Local/Temp/GoLand/ofile/20220728110115.xlsx ofile/20220728110115.xlsx])
+2022/07/28 15:09:17.236 [I]  2022-07-28 15:09:17>%!(EXTRA []interface {}=[ => Nats Cold_Api/Nats/NatsServer.Wx_GenerateQRCode -|k89VXy/9K3m7RyAFLY6kow==|- @宝智达 微信公众号通知])
+2022/07/28 15:13:13.023 [I]  2022-07-28 15:13:13>%!(EXTRA []interface {}=[Nats => Cold_Api/Nats/NatsServer.Qiniu_UploadFile C:/Users/SIKED/AppData/Local/Temp/GoLand/ofile/20220728151313.xlsx ofile/20220728151313.xlsx])
+2022/07/28 15:16:44.602 [I]  2022-07-28 15:16:44>%!(EXTRA []interface {}=[Nats => Cold_Api/Nats/NatsServer.Qiniu_UploadFile C:/Users/SIKED/AppData/Local/Temp/GoLand/ofile/20220728151644.xlsx ofile/20220728151644.xlsx])
+2022/07/29 09:33:18.124 [I]  2022-07-29 09:33:18>%!(EXTRA []interface {}=[============Nats init============])
+2022/07/29 09:33:18.258 [I]  2022-07-29 09:33:18>%!(EXTRA []interface {}=[nats OK!])
+2022/07/29 10:41:19.609 [I]  2022-07-29 10:41:19>%!(EXTRA []interface {}=[============Nats init============])
+2022/07/29 10:41:19.735 [I]  2022-07-29 10:41:19>%!(EXTRA []interface {}=[nats OK!])
+2022/07/29 10:46:37.630 [I]  2022-07-29 10:46:37>%!(EXTRA []interface {}=[============Nats init============])
+2022/07/29 10:46:37.754 [I]  2022-07-29 10:46:37>%!(EXTRA []interface {}=[nats OK!])
+2022/07/29 10:47:27.545 [I]  2022-07-29 10:47:27>%!(EXTRA []interface {}=[============Nats init============])
+2022/07/29 10:47:27.667 [I]  2022-07-29 10:47:27>%!(EXTRA []interface {}=[nats OK!])
+2022/07/29 15:36:58.280 [I]  2022-07-29 15:36:58>%!(EXTRA []interface {}=[============Nats init============])
+2022/07/29 15:36:58.418 [I]  2022-07-29 15:36:58>%!(EXTRA []interface {}=[nats OK!])
+2022/07/29 15:53:01.559 [I]  2022-07-29 15:53:01>%!(EXTRA []interface {}=[============Nats init============])
+2022/07/29 15:53:01.685 [I]  2022-07-29 15:53:01>%!(EXTRA []interface {}=[nats OK!])
+2022/07/29 15:53:54.938 [I]  2022-07-29 15:53:54>%!(EXTRA []interface {}=[============Nats init============])
+2022/07/29 15:53:55.066 [I]  2022-07-29 15:53:55>%!(EXTRA []interface {}=[nats OK!])
+2022/08/01 11:50:58.724 [I]  2022-08-01 11:50:58>%!(EXTRA []interface {}=[============Nats init============])
+2022/08/01 11:50:58.851 [I]  2022-08-01 11:50:58>%!(EXTRA []interface {}=[nats OK!])

+ 4 - 0
main.go

@@ -3,6 +3,7 @@ package main
 import (
 	_ "Cold_Api/Nats"
 	"Cold_Api/conf"
+	"Cold_Api/controllers/lib"
 	"Cold_Api/models/Device"
 	_ "Cold_Api/routers"
 	"fmt"
@@ -17,6 +18,9 @@ import (
 )
 
 func init() {
+
+	lib.WritePid()
+
 	fmt.Println(runtime.GOOS)
 	orm.RegisterDriver("mysql", orm.DRMySQL)
 	//orm.RegisterDataBase("default", "mysql", "zdxq:7e5853d9178edfcc@tcp(47.108.133.234:3306)/zdxq?charset=utf8",100,200)

+ 1 - 1
models/Device/Device.go

@@ -49,7 +49,7 @@ type R_Device struct {
 	T_online      int              //  在线状态 1 在线  0 离线
 	T_Dattery     int              //电量
 	T_sensor_list []DeviceSensor_R //  传感器List
-	T_MSISDN      string           //设备名称
+	T_MSISDN      string           //MSISDN
 	UpdateTime    time.Time        //auto_now 每次 model 保存时都会对时间自动更新
 }
 type Device_task struct {

+ 5 - 2
models/Device/DeviceData.go

@@ -3,6 +3,7 @@ package Device
 import (
 	"Cold_Api/conf"
 	"Cold_Api/controllers/lib"
+	"Cold_Api/logs"
 	"encoding/json"
 	"fmt"
 	"github.com/astaxie/beego/cache"
@@ -120,8 +121,10 @@ func CREATE_DeviceData(SN string) bool {
 }
 
 func DELETE_DeviceDatar(SN string) bool {
-
-	sql := "DROP TABLE Z_DeviceData_" + SN
+	timeStr := time.Now().Format("2006_01_02_15_04_05")
+	//sql := "DROP TABLE Z_DeviceData_" + SN
+	sql := "ALTER TABLE Z_DeviceData_" + SN + " RENAME TO " + "Z_DeviceData_" + SN + "_dle_" + timeStr + ";"
+	logs.Println("DELETE_DeviceDatar:", sql)
 	o := orm.NewOrm()
 	_, err := o.Raw(sql).Exec()
 	if err != nil {

+ 3 - 1
models/Device/DeviceSensor.go

@@ -455,7 +455,9 @@ func Read_DeviceSensor_class_ALL_1(user_ Admin.Admin, T_Calss_id int, page int,
 	var r []DeviceSensor
 	cond := orm.NewCondition()
 	cond1 := cond.And("T_Bind__icontains", T_Bind).And("T_Calss__icontains", T_Calss).And("T_sn__icontains", SN_type).And("T_sn__icontains", T_sn).And("T_name__icontains", T_name).And("T_datashow", 1) // .AndNot("status__in", 1).Or("profile__age__gt", 2000)
-
+	if len(T_sn) < 6 {
+		cond1 = cond.AndCond(cond1).AndCond(cond.And("T_give", 1))
+	}
 	// 非内部权限
 	println("user_.Admin_power:", user_.Admin_power)
 	if len(T_sn) < 6 {

+ 20 - 5
models/Device/DeviceWarning.go

@@ -32,6 +32,7 @@ type DeviceWarning struct {
 
 	T_Ut   time.Time `orm:"type(timestamp);null;"` // 采集时间
 	T_Text string    `orm:"size(256);null"`        // 备注
+	T_Log  string    `orm:"type(text);null"`       // 处理日志
 
 	T_State    int       `orm:"size(2);1"`                                             // 0 删除   1 正常
 	CreateTime time.Time `orm:"column(create_time);type(timestamp);null;auto_now_add"` //auto_now_add 第一次保存时才设置时间
@@ -73,6 +74,16 @@ func Add_DeviceWarning(m DeviceWarning) (id int64, err error) {
 }
 
 // 修改
+func Update_DeviceWarning(r DeviceWarning, cols ...string) bool {
+	o := orm.NewOrm()
+	if num, err := o.Update(&r, cols...); err == nil {
+		fmt.Println("Number of records updated in database:", num)
+		return true
+	}
+	return false
+}
+
+// 修改
 func Update_DeviceWarning_ById(m DeviceWarning) (err error) {
 	o := orm.NewOrm()
 	v := DeviceWarning{Id: m.Id}
@@ -80,7 +91,7 @@ func Update_DeviceWarning_ById(m DeviceWarning) (err error) {
 	if err = o.Read(&v); err == nil {
 		var num int64
 		m.T_State = 2
-		if num, err = o.Update(&m, "T_Text", "T_State"); err == nil {
+		if num, err = o.Update(&m, "T_Text"); err == nil {
 			fmt.Println("Number of records updated in database:", num)
 		}
 	}
@@ -93,8 +104,8 @@ func Update_DeviceWarning_Delete(m DeviceWarning) (err error) {
 	v := DeviceWarning{Id: m.Id}
 	// ascertain id exists in the database
 	if err = o.Read(&v); err == nil {
-		var num int64
-		if num, err = o.Delete(&m); err == nil {
+		v.T_State = 0
+		if num, err := o.Update(&v, "T_State"); err == nil {
 			fmt.Println("Number of records updated in database:", num)
 		}
 	}
@@ -128,10 +139,14 @@ func Read_DeviceWarning_1(user_ Admin.Admin, page int, T_sn string, T_Name strin
 	fmt.Println("T_Bind:", T_Bind)
 
 	cond := orm.NewCondition()
-	cond1 := cond.And("T_Bind__icontains", T_Bind)
 
+	cond1 := cond.And("T_State__gt", 0)
+
+	if len(T_Bind) > 1 {
+		cond1 = cond.AndCond(cond1).And("T_Bind__icontains", T_Bind)
+	}
 	if len(T_Name) > 1 {
-		cond1 = cond.AndCond(cond.Or("T_Name__icontains", T_Name).Or("T_Title__icontains", T_Name).Or("T_Addr__icontains", T_Name).Or("T_sn__icontains", T_Name))
+		cond1 = cond.AndCond(cond1).AndCond(cond.Or("T_Name__icontains", T_Name).Or("T_Title__icontains", T_Name).Or("T_Addr__icontains", T_Name).Or("T_sn__icontains", T_Name))
 	}
 
 	if len(T_sn) > 1 {

+ 1 - 0
routers/Device.go

@@ -60,6 +60,7 @@ func init() {
 	beego.Router("/Device/DeviceWarning_List_html", &controllers.DeviceController{}, "*:DeviceWarning_List_html")         // 获取未读消息
 	beego.Router("/Device/DeviceWarning_List", &controllers.DeviceController{}, "*:DeviceWarning_List")                   // 获取未读消息
 	beego.Router("/Device/DeviceWarning_", &controllers.DeviceController{}, "*:DeviceWarning_")                           // 获取未读消息
+	beego.Router("/Device/DeviceWarning_log", &controllers.DeviceController{}, "*:DeviceWarning_log")                     // 获取未读消息
 	beego.Router("/Device/DeviceWarning_M", &controllers.DeviceController{}, "*:DeviceWarning_M")                         // 获取未读消息
 	beego.Router("/Device/DeviceWarning_Post", &controllers.DeviceController{}, "*:DeviceWarning_Post")                   // 获取未读消息
 	beego.Router("/Device/DeviceWarning_Data_Excel", &controllers.DeviceController{}, "*:DeviceWarning_Data_Excel")       // 获取未读消息

+ 1 - 0
server.pid

@@ -0,0 +1 @@
+20900

+ 5 - 0
tests/default_test.go

@@ -1,10 +1,15 @@
 package test
 
 import (
+	"fmt"
 	"testing"
+	"time"
 )
 
 // TestBeego is a sample to run an endpoint test
 func TestBeego(t *testing.T) {
 
+	timeStr := time.Now().Format("2006_01_02_15_04_05") //当前时间的字符串,2006-01-02 15:04:05据说是golang的诞生时间,固定写法
+	fmt.Println(timeStr)                                //打印结果:2017-04-11 13:24:04
+
 }

+ 2 - 2
views/Device/DeviceLogs.html

@@ -26,14 +26,14 @@
                                 <thead>
                                     <tr>
                                         <th>内容</th>
-<!--                                        <th>时间</th>-->
+                                        <th>时间</th>
                                     </tr>
                                 </thead>
                                 <tbody>
                                 {{range $index, $elem := .List}}
                                     <tr>
                                         <td>{{$elem.Logs_Txt}}</td>
-<!--                                        <td>{{$elem.CreateTime}}</td>-->
+                                        <td>{{$elem.CreateTime}}</td>
                                     </tr>
 
                                 {{end}}

+ 29 - 0
views/Device/DeviceWarning-log.html

@@ -0,0 +1,29 @@
+<!DOCTYPE html>
+<html class="x-admin-sm">
+    
+    <head>
+        <meta charset="UTF-8">
+        <meta name="renderer" content="webkit">
+        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
+        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
+        <link rel="stylesheet" href="https://osscold.baozhida.cn/css/font.css">
+        <link rel="stylesheet" href="https://osscold.baozhida.cn/css/xadmin.css">
+        <link rel="stylesheet" href="https://osscold.baozhida.cn/lib/layui/layui.css">
+        <script type="text/javascript" src="https://osscold.baozhida.cn/lib/layui/layui.js" charset="utf-8"></script>
+        <script type="text/javascript" src="https://osscold.baozhida.cn/js/xadmin.js"></script>
+        <!-- 让IE8/9支持媒体查询,从而兼容栅格 -->
+        <!--[if lt IE 9]>
+            <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
+            <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
+        <![endif]--></head>
+    
+    <body>
+        <div class="layui-fluid">
+            <div class="layui-row">
+                {{str2html  .T_Log}}
+            </div>
+        </div>
+
+    </body>
+
+</html>

+ 6 - 0
views/Device/DeviceWarning.html

@@ -108,6 +108,12 @@
                                                onclick="member_del('{{$elem.Id}}')" >&#xe640; 删除报警</i>
                                             {{end}}
 
+                                            {{if le $.Admin_r.Admin_power 6 }}
+
+                                            <i class="layui-icon" style="margin-right: 10px;float: left;color: #1E9FFF"
+                                               onclick="xadmin.open('处理记录','DeviceWarning_log?id={{$elem.Id}}',600,'')"  >&#xe60a; 处理记录</i>
+                                            {{end}}
+
                                             <div style="float: left;text-overflow:ellipsis;overflow:hidden;white-space:nowrap;width:120px;">{{$elem.T_Text}}</div>