优化系统

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

View File

@ -310,12 +310,12 @@ func (that *Application) handler(w http.ResponseWriter, req *http.Request) {
//session也没有则判断是否创建cookie
} else {
//跨域不再通过cookie校验
//if that.Config.GetString("crossDomain") == "" {
if that.Config.GetString("crossDomain") == "" {
http.SetCookie(w, &http.Cookie{Name: that.Config.GetString("sessionName"), Value: sessionId, Path: "/"})
//} else {
// //跨域允许需要设置cookie的允许跨域https才有效果
// w.Header().Set("Set-Cookie", that.Config.GetString("sessionName")+"="+sessionId+"; Path=/; SameSite=None; Secure")
//}
} else {
//跨域允许需要设置cookie的允许跨域https才有效果
w.Header().Set("Set-Cookie", that.Config.GetString("sessionName")+"="+sessionId+"; Path=/; SameSite=None; Secure")
}
}
unescapeUrl, err := url.QueryUnescape(req.RequestURI)
@ -436,7 +436,7 @@ func (that *Application) crossDomain(context *Context) {
//不跨域,则不设置
remoteHost := context.Req.Host
if context.Config.GetString("port") != "80" && context.Config.GetString("port") != "443" {
if context.Config.GetString("port") == "80" || context.Config.GetString("port") == "443" {
remoteHost = remoteHost + ":" + context.Config.GetString("port")
}
if context.Config.GetString("crossDomain") != "auto" {
@ -466,7 +466,7 @@ func (that *Application) crossDomain(context *Context) {
if origin != "" {
header.Set("Access-Control-Allow-Origin", origin)
return
//return
}
if refer != "" {

View File

@ -36,6 +36,42 @@ func StrFirstToUpper(str string) string {
return strings.ToUpper(first) + other
}
//相似度计算 ld compares two strings and returns the levenshtein distance between them.
func StrLd(s, t string, ignoreCase bool) int {
if ignoreCase {
s = strings.ToLower(s)
t = strings.ToLower(t)
}
d := make([][]int, len(s)+1)
for i := range d {
d[i] = make([]int, len(t)+1)
}
for i := range d {
d[i][0] = i
}
for j := range d[0] {
d[0][j] = j
}
for j := 1; j <= len(t); j++ {
for i := 1; i <= len(s); i++ {
if s[i-1] == t[j-1] {
d[i][j] = d[i-1][j-1]
} else {
min := d[i-1][j]
if d[i][j-1] < min {
min = d[i][j-1]
}
if d[i-1][j-1] < min {
min = d[i-1][j-1]
}
d[i][j] = min + 1
}
}
}
return d[len(s)][len(t)]
}
// Substr 字符串截取
func Substr(str string, start int, length int) string {
rs := []rune(str)

View File

@ -5,7 +5,7 @@ import (
. "../../../hotime/common"
)
var ID = "002842c27c0a29c2109f3b726c130e65"
var ID = "a549346388b58195866106b5f2072b26"
// Project 管理端项目
var Project = Proj{

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

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"
}

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)
}
}

Binary file not shown.