优化系统

This commit is contained in:
hoteas
2021-12-27 14:00:08 +08:00
parent eccab42fc8
commit 84ee0d259f
8 changed files with 144 additions and 2515 deletions
+1 -1
View File
@@ -5,7 +5,7 @@ import (
. "../../../hotime/common"
)
var ID = "002842c27c0a29c2109f3b726c130e65"
var ID = "a549346388b58195866106b5f2072b26"
// Project 管理端项目
var Project = Proj{
+1 -2
View File
@@ -34,7 +34,7 @@ var produce_productCtr = Ctr{
Map{"[><]product": "produce_product.product_id=product.id",
"[><]produce": "produce_product.produce_id=produce.id",
},
"produce_product.id,produce_product.product_id,product.name AS product_name,produce_product.admin_id,"+
"produce_product.id,produce_product.product_id,product.name AS product_name,"+
"produce_product.modify_time,produce_product.state,product.rule_spot_check,produce_product.produce_id,produce.name AS produce_name", where)
if re == nil {
@@ -66,7 +66,6 @@ var produce_productCtr = Ctr{
data := Map{
"admin_id": adminID,
"sn": sn,
"product_id": product_id,
"produce_id": produce_id,
File diff suppressed because it is too large Load Diff
+3 -3
View File
@@ -20,11 +20,11 @@
"rule": "config/rule.json"
}
},
"crossDomain": "",
"crossDomain": "auto",
"db": {
"mysql": {
"host": "192.168.6.253",
"name": "myhs_remote",
"name": "myhs",
"password": "dasda8454456",
"port": "3306",
"prefix": "",
@@ -43,7 +43,7 @@
"5": "数据结果异常"
},
"mode": 2,
"port": "80",
"port": "8080",
"sessionName": "HOTIME",
"tpt": "tpt"
}
+95 -1
View File
@@ -11,17 +11,18 @@ import (
"fmt"
"io"
"io/ioutil"
"net"
"os"
"strings"
"time"
)
func main() {
date, _ := time.Parse("2006-01-02 15:04", time.Now().Format("2006-01-02")+" 14:00")
fmt.Println(date, date.Unix())
//fmt.Println("0123456"[1:7])
appIns := hotime.Init("config/config.json")
go runTcpServer(&appIns) //运行tcp监测,产线监测使用
//RESTfull接口适配
appIns.SetConnectListener(func(context *hotime.Context) bool {
@@ -313,3 +314,96 @@ func main() {
//},
})
}
func Process(conn net.Conn, appIns *hotime.Application) {
// 循环接收客户端发送的数据
client := conn.RemoteAddr().String() // 客户端IPport
client = client[:strings.Index(client, ":")]
defer conn.Close() // 关闭conn
for {
// 创建一个新的切片
buf := make([]byte, 1024)
// fmt.Printf("服务器在等待客户端%s发送信息\n", conn.RemoteAddr().String())
n, err := conn.Read(buf) // 从conn中读取
// 等待客户端通过conn发送信息,
// 如果客户端没有发送(write),就会阻塞在这里
if err != nil {
// 一般为这个err
fmt.Printf("客户端%s已退出..\n", client)
return
}
// 显示客户端发送的内容到服务器的终端
sn := string(buf[:n])
sn = strings.Replace(sn, "\r", "", -1)
fmt.Println(client, sn) // 读到了n个数据
if len(sn) < 3 {
//that.Display(3, "参数不足,请补充参数")
fmt.Println(client, sn, "参数过短") // 读到了n个数据
continue
}
vs := appIns.Db.Select("produce", "sn,id,product_id",
common.Map{"AND": common.Map{"produce.sn[~]": sn[:len(sn)/2+1], "state[!]": 0}})
produce := common.Map{"ld": 10000}
for _, v := range vs {
ld := common.StrLd(v.GetString("sn"), sn, true)
if ld < produce.GetCeilInt("ld") {
v["ld"] = ld
produce = v
}
}
oldSn := appIns.Db.Get("produce_product", "id", common.Map{"sn": sn, "produce_id": produce.GetCeilInt("id")})
if oldSn != nil {
fmt.Println(client, sn, "已经添加请勿重复添加") // 读到了n个数据
continue
}
data := common.Map{
"sn": sn,
"product_id": produce.GetCeilInt("product_id"),
"produce_id": produce.GetCeilInt("id"),
"create_time": time.Now().Unix(),
"modify_time": time.Now().Unix(),
}
productLine := appIns.Db.Get("product_line", "id", common.Map{"ipaddr": client})
if productLine != nil {
data["product_line_id"] = productLine.GetCeilInt("id")
}
id := appIns.Db.Insert("produce_product", data)
if id == 0 {
//that.Display(4, "添加新成品失败,请重新添加")
fmt.Println(client, sn, "添加新成品失败,请重新添加") // 读到了n个数据
continue
}
}
}
func runTcpServer(appIns *hotime.Application) {
listen, err := net.Listen("tcp", "0.0.0.0:10000")
if err != nil {
fmt.Println("listen err =", err)
return
}
defer listen.Close() // 延时关闭listen
fmt.Println("listening success:", listen.Addr())
// 循环等待客户端来连接
fmt.Println("等待客户端来连接..")
for {
conn, err := listen.Accept()
if err != nil {
fmt.Println("Accept() err =", err)
} else {
fmt.Printf("客户端%s已连接..\n", conn.RemoteAddr().String())
}
// 准备一个协程,为客户端服务
go Process(conn, appIns)
}
}
BIN
View File
Binary file not shown.