diff --git a/application.go b/application.go index 73fd13b..69b2805 100644 --- a/application.go +++ b/application.go @@ -310,12 +310,12 @@ func (that *Application) handler(w http.ResponseWriter, req *http.Request) { //session也没有则判断是否创建cookie } else { //跨域不再通过cookie校验 - //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") - //} + 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") + } } 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 != "" { diff --git a/common/func.go b/common/func.go index 8049ba6..92c4d71 100644 --- a/common/func.go +++ b/common/func.go @@ -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) diff --git a/example/admin/init.go b/example/admin/init.go index ac027fd..e1e1e79 100644 --- a/example/admin/init.go +++ b/example/admin/init.go @@ -5,7 +5,7 @@ import ( . "../../../hotime/common" ) -var ID = "002842c27c0a29c2109f3b726c130e65" +var ID = "a549346388b58195866106b5f2072b26" // Project 管理端项目 var Project = Proj{ diff --git a/example/app/produce_product.go b/example/app/produce_product.go index cfeb4f0..b2320be 100644 --- a/example/app/produce_product.go +++ b/example/app/produce_product.go @@ -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, diff --git a/example/config/app.json b/example/config/app.json deleted file mode 100644 index 57f43ea..0000000 --- a/example/config/app.json +++ /dev/null @@ -1,2500 +0,0 @@ -{ - "id": "002842c27c0a29c2109f3b726c130e65", - "label": "HoTime管理平台", - "menus": [ - { - "icon": "el-icon-s-home", - "label": "平台首页", - "name": "HelloWorld" - }, - { - "icon": "el-icon-setting", - "label": "系统管理", - "menus": [ - { - "label": "人员管理", - "table": "admin" - }, - { - "label": "角色管理", - "table": "role" - }, - { - "label": "炉温监控", - "table": "furnace_temperature" - }, - { - "label": "部门管理", - "table": "org" - }, - { - "label": "事项管理", - "table": "category" - }, - { - "label": "客户管理", - "table": "user" - } - ], - "name": "sys" - }, - { - "icon": "el-icon-setting", - "label": "消耗原材料", - "menus": [ - { - "label": "消耗原材料", - "table": "produce_material" - }, - { - "label": "生产计划", - "table": "produce" - }, - { - "label": "生产成品", - "table": "produce_product" - }, - { - "label": "生产计划", - "table": "produce" - }, - { - "label": "生产计划", - "table": "produce" - }, - { - "label": "生产计划", - "table": "produce" - } - ], - "name": "sys:produce" - }, - { - "icon": "el-icon-setting", - "label": "产线管理", - "menus": [ - { - "label": "产线管理", - "table": "product_line" - }, - { - "label": "成品管理", - "table": "product" - }, - { - "label": "质检管理", - "table": "product_check" - }, - { - "label": "抽检管理", - "table": "product_spot_check" - }, - { - "label": "成品管理", - "table": "product" - }, - { - "label": "成品管理", - "table": "product" - }, - { - "label": "成品管理", - "table": "product" - } - ], - "name": "sys:product" - }, - { - "icon": "el-icon-setting", - "label": "原材料管理", - "menus": [ - { - "label": "原材料管理", - "table": "material" - }, - { - "label": "出入库管理", - "table": "material_inout" - }, - { - "label": "原材料管理", - "table": "material" - }, - { - "label": "原材料管理", - "table": "material" - }, - { - "label": "原材料管理", - "table": "material" - } - ], - "name": "sys:material" - } - ], - "name": "admin", - "tables": { - "admin": { - "auth": [ - "add", - "delete", - "edit", - "info" - ], - "columns": [ - { - "add": false, - "edit": false, - "label": "ID", - "must": false, - "name": "id", - "sortable": true, - "type": "number" - }, - { - "label": "名称", - "name": "name", - "type": "text" - }, - { - "label": "手机号", - "name": "phone", - "type": "text" - }, - { - "add": false, - "edit": false, - "label": "创建时间", - "list": false, - "must": false, - "name": "create_time", - "type": "time" - }, - { - "add": false, - "edit": false, - "label": "变更时间", - "must": false, - "name": "modify_time", - "type": "time" - }, - { - "label": "状态", - "list": false, - "must": true, - "name": "state", - "options": [ - { - "name": "已启用", - "value": "0" - }, - { - "name": "未启用", - "value": "1" - }, - { - "name": "异常", - "value": "2" - } - ], - "type": "select" - }, - { - "info": false, - "label": "密码", - "list": false, - "must": false, - "name": "password", - "type": "password" - }, - { - "label": "头像", - "list": false, - "must": false, - "name": "avatar_img", - "type": "image" - }, - { - "label": "角色", - "link": "role", - "name": "role_id", - "sortable": true, - "type": "number", - "value": "name" - }, - { - "label": "部门", - "link": "org", - "name": "org_id", - "sortable": true, - "type": "number", - "value": "name" - } - ], - "label": "人员管理", - "search": [ - { - "label": "请输入关键词", - "name": "keyword", - "type": "search", - "value": null - }, - { - "label": "时间段", - "name": "daterange", - "type": "search", - "value": null - }, - { - "label": "排序", - "name": "sort", - "type": "search", - "value": null - }, - { - "label": "状态", - "list": false, - "must": true, - "name": "state", - "options": [ - { - "name": "已启用", - "value": "0" - }, - { - "name": "未启用", - "value": "1" - }, - { - "name": "异常", - "value": "2" - }, - { - "name": "全部", - "value": null - } - ], - "type": "select", - "value": null - }, - { - "label": "部门", - "link": "org", - "name": "org_id", - "type": "tree", - "value": "name" - } - ], - "table": "admin" - }, - "category": { - "auth": [ - "add", - "delete", - "edit", - "info" - ], - "columns": [ - { - "add": false, - "edit": false, - "label": "ID", - "must": false, - "name": "id", - "sortable": true, - "type": "number" - }, - { - "label": "名称", - "name": "name", - "type": "text" - }, - { - "label": "排序 序号越大越排前面", - "list": false, - "must": false, - "name": "sort", - "sortable": true, - "type": "number" - }, - { - "label": "归属专区", - "link": "category", - "must": false, - "name": "parent_id", - "sortable": true, - "type": "number", - "value": "name" - }, - { - "label": "创建人员", - "link": "admin", - "name": "admin_id", - "sortable": true, - "type": "number", - "value": "name" - }, - { - "add": false, - "edit": false, - "label": "创建时间", - "list": false, - "must": false, - "name": "create_time", - "type": "time" - }, - { - "add": false, - "edit": false, - "label": "变更时间", - "must": false, - "name": "modify_time", - "type": "time" - }, - { - "label": "状态", - "list": false, - "must": true, - "name": "state", - "options": [ - { - "name": "已启用", - "value": "0" - }, - { - "name": "未启用", - "value": "1" - }, - { - "name": "异常", - "value": "2" - } - ], - "type": "select" - }, - { - "label": "部门", - "link": "org", - "name": "org_id", - "sortable": true, - "type": "number", - "value": "name" - }, - { - "add": false, - "edit": false, - "info": false, - "label": "索引", - "list": false, - "must": false, - "name": "index", - "notUse": true, - "type": "index" - } - ], - "label": "事项管理", - "search": [ - { - "label": "请输入关键词", - "name": "keyword", - "type": "search", - "value": null - }, - { - "label": "时间段", - "name": "daterange", - "type": "search", - "value": null - }, - { - "label": "排序", - "name": "sort", - "type": "search", - "value": null - }, - { - "label": "状态", - "list": false, - "must": true, - "name": "state", - "options": [ - { - "name": "已启用", - "value": "0" - }, - { - "name": "未启用", - "value": "1" - }, - { - "name": "异常", - "value": "2" - }, - { - "name": "全部", - "value": null - } - ], - "type": "select", - "value": null - }, - { - "label": "部门", - "link": "org", - "name": "org_id", - "type": "tree", - "value": "name" - }, - { - "label": "归属专区", - "link": "category", - "name": "parent_id", - "type": "tree", - "value": "name" - } - ], - "table": "category" - }, - "furnace_temperature": { - "auth": [ - "add", - "delete", - "edit", - "info" - ], - "columns": [ - { - "add": false, - "edit": false, - "label": "ID", - "must": false, - "name": "id", - "sortable": true, - "type": "number" - }, - { - "label": "SN", - "name": "sn", - "type": "text" - }, - { - "label": "日期", - "name": "name", - "type": "text" - }, - { - "label": "炉温照片", - "list": false, - "must": false, - "name": "img", - "type": "image" - }, - { - "add": false, - "edit": false, - "label": "创建时间", - "list": false, - "must": false, - "name": "create_time", - "type": "time" - }, - { - "add": false, - "edit": false, - "label": "变更时间", - "must": false, - "name": "modify_time", - "type": "time" - }, - { - "label": "状态", - "list": false, - "must": true, - "name": "state", - "options": [ - { - "name": "已启用", - "value": "0" - }, - { - "name": "未启用", - "value": "1" - }, - { - "name": "异常", - "value": "2" - } - ], - "type": "select" - }, - { - "label": "产线", - "link": "product_line", - "name": "product_line_id", - "sortable": true, - "type": "number", - "value": "name" - } - ], - "label": "炉温监控", - "search": [ - { - "label": "请输入关键词", - "name": "keyword", - "type": "search", - "value": null - }, - { - "label": "时间段", - "name": "daterange", - "type": "search", - "value": null - }, - { - "label": "排序", - "name": "sort", - "type": "search", - "value": null - }, - { - "label": "状态", - "list": false, - "must": true, - "name": "state", - "options": [ - { - "name": "已启用", - "value": "0" - }, - { - "name": "未启用", - "value": "1" - }, - { - "name": "异常", - "value": "2" - }, - { - "name": "全部", - "value": null - } - ], - "type": "select", - "value": null - } - ], - "table": "furnace_temperature" - }, - "material": { - "auth": [ - "add", - "delete", - "edit", - "info" - ], - "columns": [ - { - "add": false, - "edit": false, - "label": "ID", - "must": false, - "name": "id", - "sortable": true, - "type": "number" - }, - { - "label": "SN", - "name": "sn", - "type": "text" - }, - { - "label": "原材料名称", - "name": "name", - "type": "text" - }, - { - "label": "图片", - "list": false, - "must": false, - "name": "img", - "type": "image" - }, - { - "label": "当前数量", - "name": "count", - "sortable": true, - "type": "number" - }, - { - "label": "总消耗数", - "name": "used", - "sortable": true, - "type": "number" - }, - { - "label": "总存储数", - "name": "saved", - "sortable": true, - "type": "number" - }, - { - "label": "默认添加数量", - "name": "num", - "sortable": true, - "type": "number" - }, - { - "label": "经办人", - "link": "admin", - "name": "admin_id", - "sortable": true, - "type": "number", - "value": "name" - }, - { - "add": false, - "edit": false, - "label": "创建时间", - "list": false, - "must": false, - "name": "create_time", - "type": "time" - }, - { - "add": false, - "edit": false, - "label": "变更时间", - "must": false, - "name": "modify_time", - "type": "time" - }, - { - "label": "状态", - "list": false, - "must": true, - "name": "state", - "options": [ - { - "name": "已启用", - "value": "0" - }, - { - "name": "未启用", - "value": "1" - }, - { - "name": "异常", - "value": "2" - } - ], - "type": "select" - }, - { - "label": "基本信息", - "list": false, - "must": false, - "name": "rule", - "type": "form" - }, - { - "label": "有效期", - "must": true, - "name": "validity", - "options": [ - { - "name": "半年", - "value": "0" - }, - { - "name": "一年", - "value": "1" - }, - { - "name": "两年", - "value": "2" - }, - { - "name": "三年", - "value": "3" - } - ], - "sortable": true, - "type": "select" - }, - { - "label": "识别数据", - "list": false, - "must": false, - "name": "content", - "type": "text" - }, - { - "label": "备注信息", - "list": false, - "must": false, - "name": "description", - "type": "text" - } - ], - "label": "原材料管理", - "search": [ - { - "label": "请输入关键词", - "name": "keyword", - "type": "search", - "value": null - }, - { - "label": "时间段", - "name": "daterange", - "type": "search", - "value": null - }, - { - "label": "排序", - "name": "sort", - "type": "search", - "value": null - }, - { - "label": "有效期", - "must": true, - "name": "validity", - "options": [ - { - "name": "半年", - "value": "0" - }, - { - "name": "一年", - "value": "1" - }, - { - "name": "两年", - "value": "2" - }, - { - "name": "三年", - "value": "3" - }, - { - "name": "全部", - "value": null - } - ], - "sortable": true, - "type": "select", - "value": null - }, - { - "label": "状态", - "list": false, - "must": true, - "name": "state", - "options": [ - { - "name": "已启用", - "value": "0" - }, - { - "name": "未启用", - "value": "1" - }, - { - "name": "异常", - "value": "2" - }, - { - "name": "全部", - "value": null - } - ], - "type": "select", - "value": null - } - ], - "table": "material" - }, - "material_inout": { - "auth": [ - "add", - "delete", - "edit", - "info" - ], - "columns": [ - { - "add": false, - "edit": false, - "label": "ID", - "must": false, - "name": "id", - "sortable": true, - "type": "number" - }, - { - "label": "SN", - "name": "sn", - "type": "text" - }, - { - "label": "图片", - "list": false, - "must": false, - "name": "img", - "type": "image" - }, - { - "label": "出入库数量", - "name": "count", - "sortable": true, - "type": "number" - }, - { - "label": "剩余数量", - "name": "saved", - "sortable": true, - "type": "number" - }, - { - "label": "对应原材料", - "link": "material", - "name": "material_id", - "sortable": true, - "type": "number", - "value": "name" - }, - { - "label": "经办人", - "link": "admin", - "name": "admin_id", - "sortable": true, - "type": "number", - "value": "name" - }, - { - "add": false, - "edit": false, - "label": "创建时间", - "list": false, - "must": false, - "name": "create_time", - "type": "time" - }, - { - "add": false, - "edit": false, - "label": "变更时间", - "must": false, - "name": "modify_time", - "type": "time" - }, - { - "label": "状态", - "list": false, - "must": true, - "name": "state", - "options": [ - { - "name": "入库", - "value": "0" - }, - { - "name": "出库", - "value": "1" - }, - { - "name": "退货", - "value": "2" - } - ], - "type": "select" - }, - { - "label": "基础信息", - "list": false, - "must": false, - "name": "rule", - "type": "form" - }, - { - "label": "关联生产计划", - "link": "produce", - "name": "produce_id", - "sortable": true, - "type": "number", - "value": "name" - }, - { - "label": "识别信息", - "list": false, - "must": false, - "name": "content", - "type": "text" - }, - { - "label": "备注信息", - "list": false, - "must": false, - "name": "description", - "type": "text" - } - ], - "label": "出入库管理", - "search": [ - { - "label": "请输入关键词", - "name": "keyword", - "type": "search", - "value": null - }, - { - "label": "时间段", - "name": "daterange", - "type": "search", - "value": null - }, - { - "label": "排序", - "name": "sort", - "type": "search", - "value": null - }, - { - "label": "状态", - "list": false, - "must": true, - "name": "state", - "options": [ - { - "name": "入库", - "value": "0" - }, - { - "name": "出库", - "value": "1" - }, - { - "name": "退货", - "value": "2" - }, - { - "name": "全部", - "value": null - } - ], - "type": "select", - "value": null - } - ], - "table": "material_inout" - }, - "org": { - "auth": [ - "add", - "delete", - "edit", - "info" - ], - "columns": [ - { - "add": false, - "edit": false, - "label": "ID", - "must": false, - "name": "id", - "sortable": true, - "type": "number" - }, - { - "label": "编号", - "name": "sn", - "type": "text" - }, - { - "label": "组织名称", - "name": "name", - "type": "text" - }, - { - "label": "上级组织", - "link": "org", - "must": false, - "name": "parent_id", - "sortable": true, - "type": "number", - "value": "name" - }, - { - "label": "状态", - "list": false, - "must": true, - "name": "state", - "options": [ - { - "name": "启用", - "value": "0" - }, - { - "name": "未启用", - "value": "1" - }, - { - "name": "异常", - "value": "2" - } - ], - "type": "select" - }, - { - "add": false, - "edit": false, - "label": "注册时间", - "list": false, - "must": false, - "name": "create_time", - "type": "time" - }, - { - "add": false, - "edit": false, - "label": "变更时间", - "must": false, - "name": "modify_time", - "type": "time" - }, - { - "label": "创建用户", - "link": "admin", - "name": "admin_id", - "sortable": true, - "type": "number", - "value": "name" - }, - { - "add": false, - "edit": false, - "info": false, - "label": "索引 格式为逗号分隔,1,2,", - "list": false, - "must": false, - "name": "index", - "notUse": true, - "type": "index" - } - ], - "label": "部门管理", - "search": [ - { - "label": "请输入关键词", - "name": "keyword", - "type": "search", - "value": null - }, - { - "label": "时间段", - "name": "daterange", - "type": "search", - "value": null - }, - { - "label": "排序", - "name": "sort", - "type": "search", - "value": null - }, - { - "label": "状态", - "list": false, - "must": true, - "name": "state", - "options": [ - { - "name": "启用", - "value": "0" - }, - { - "name": "未启用", - "value": "1" - }, - { - "name": "异常", - "value": "2" - }, - { - "name": "全部", - "value": null - } - ], - "type": "select", - "value": null - }, - { - "label": "上级组织", - "link": "org", - "name": "parent_id", - "type": "tree", - "value": "name" - } - ], - "table": "org" - }, - "produce": { - "auth": [ - "add", - "delete", - "edit", - "info" - ], - "columns": [ - { - "add": false, - "edit": false, - "label": "ID", - "must": false, - "name": "id", - "sortable": true, - "type": "number" - }, - { - "label": "二维码起始编码", - "name": "sn", - "type": "text" - }, - { - "label": "计划名", - "name": "name", - "type": "text" - }, - { - "label": "对应成品", - "link": "product", - "name": "product_id", - "sortable": true, - "type": "number", - "value": "name" - }, - { - "label": "经办人", - "link": "admin", - "name": "admin_id", - "sortable": true, - "type": "number", - "value": "name" - }, - { - "label": "客户", - "link": "user", - "name": "user_id", - "sortable": true, - "type": "number", - "value": "name" - }, - { - "add": false, - "edit": false, - "label": "开始时间", - "list": false, - "must": false, - "name": "create_time", - "type": "time" - }, - { - "add": false, - "edit": false, - "label": "变更时间", - "must": false, - "name": "modify_time", - "type": "time" - }, - { - "label": "生产状态", - "list": false, - "must": true, - "name": "state", - "options": [ - { - "name": "已完成", - "value": "0" - }, - { - "name": "待生产", - "value": "1" - }, - { - "name": "生产中", - "value": "2" - } - ], - "type": "select" - }, - { - "label": "计划生产总量", - "name": "count", - "sortable": true, - "type": "number" - }, - { - "label": "当前已生产", - "name": "now", - "sortable": true, - "type": "number" - }, - { - "label": "计划完成时间", - "name": "finish_time", - "type": "time" - }, - { - "label": "其他规则", - "list": false, - "must": false, - "name": "rule", - "type": "form" - }, - { - "label": "抽检覆盖量", - "name": "spot_check_count", - "sortable": true, - "type": "number" - }, - { - "label": "发货抽检总覆盖量", - "name": "spot_check_used", - "sortable": true, - "type": "number" - }, - { - "label": "总抽检总覆盖量", - "name": "spot_check_saved", - "sortable": true, - "type": "number" - } - ], - "label": "生产计划", - "search": [ - { - "label": "请输入关键词", - "name": "keyword", - "type": "search", - "value": null - }, - { - "label": "时间段", - "name": "daterange", - "type": "search", - "value": null - }, - { - "label": "排序", - "name": "sort", - "type": "search", - "value": null - }, - { - "label": "生产状态", - "list": false, - "must": true, - "name": "state", - "options": [ - { - "name": "已完成", - "value": "0" - }, - { - "name": "待生产", - "value": "1" - }, - { - "name": "生产中", - "value": "2" - }, - { - "name": "全部", - "value": null - } - ], - "type": "select", - "value": null - } - ], - "table": "produce" - }, - "produce_material": { - "auth": [ - "add", - "delete", - "edit", - "info" - ], - "columns": [ - { - "add": false, - "edit": false, - "label": "ID", - "must": false, - "name": "id", - "sortable": true, - "type": "number" - }, - { - "label": "SN", - "name": "sn", - "type": "text" - }, - { - "label": "原材料", - "link": "material", - "name": "material_id", - "sortable": true, - "type": "number", - "value": "name" - }, - { - "label": "计划使用数量", - "name": "count", - "sortable": true, - "type": "number" - }, - { - "label": "已使用数量", - "name": "used", - "sortable": true, - "type": "number" - }, - { - "label": "生产计划", - "link": "produce", - "name": "produce_id", - "sortable": true, - "type": "number", - "value": "name" - }, - { - "add": false, - "edit": false, - "label": "创建时间", - "list": false, - "must": false, - "name": "create_time", - "type": "time" - }, - { - "add": false, - "edit": false, - "label": "变更时间", - "must": false, - "name": "modify_time", - "type": "time" - }, - { - "label": "生产状态", - "list": false, - "must": true, - "name": "state", - "options": [ - { - "name": "正常", - "value": "0" - }, - { - "name": "异常", - "value": "1" - }, - { - "name": "其他", - "value": "2" - } - ], - "type": "select" - }, - { - "label": "经办人", - "link": "admin", - "name": "admin_id", - "sortable": true, - "type": "number", - "value": "name" - } - ], - "label": "消耗原材料", - "search": [ - { - "label": "请输入关键词", - "name": "keyword", - "type": "search", - "value": null - }, - { - "label": "时间段", - "name": "daterange", - "type": "search", - "value": null - }, - { - "label": "排序", - "name": "sort", - "type": "search", - "value": null - }, - { - "label": "生产状态", - "list": false, - "must": true, - "name": "state", - "options": [ - { - "name": "正常", - "value": "0" - }, - { - "name": "异常", - "value": "1" - }, - { - "name": "其他", - "value": "2" - }, - { - "name": "全部", - "value": null - } - ], - "type": "select", - "value": null - } - ], - "table": "produce_material" - }, - "produce_product": { - "auth": [ - "add", - "delete", - "edit", - "info" - ], - "columns": [ - { - "add": false, - "edit": false, - "label": "ID", - "must": false, - "name": "id", - "sortable": true, - "type": "number" - }, - { - "label": "SN", - "name": "sn", - "type": "text" - }, - { - "label": "成品", - "link": "product", - "name": "product_id", - "sortable": true, - "type": "number", - "value": "name" - }, - { - "label": "生产计划", - "link": "produce", - "name": "produce_id", - "sortable": true, - "type": "number", - "value": "name" - }, - { - "add": false, - "edit": false, - "label": "创建时间", - "list": false, - "must": false, - "name": "create_time", - "type": "time" - }, - { - "add": false, - "edit": false, - "label": "变更时间", - "must": false, - "name": "modify_time", - "type": "time" - }, - { - "label": "生产状态", - "list": false, - "must": true, - "name": "state", - "options": [ - { - "name": "正常", - "value": "0" - }, - { - "name": "异常", - "value": "1" - }, - { - "name": "其他", - "value": "2" - } - ], - "type": "select" - }, - { - "label": "炉温", - "link": "furnace_temperature", - "name": "furnace_temperature_id", - "sortable": true, - "type": "number", - "value": "name" - }, - { - "label": "生产线", - "link": "product_line", - "name": "product_line_id", - "sortable": true, - "type": "number", - "value": "name" - }, - { - "label": "经办人", - "link": "admin", - "name": "admin_id", - "sortable": true, - "type": "number", - "value": "name" - } - ], - "label": "生产成品", - "search": [ - { - "label": "请输入关键词", - "name": "keyword", - "type": "search", - "value": null - }, - { - "label": "时间段", - "name": "daterange", - "type": "search", - "value": null - }, - { - "label": "排序", - "name": "sort", - "type": "search", - "value": null - }, - { - "label": "生产状态", - "list": false, - "must": true, - "name": "state", - "options": [ - { - "name": "正常", - "value": "0" - }, - { - "name": "异常", - "value": "1" - }, - { - "name": "其他", - "value": "2" - }, - { - "name": "全部", - "value": null - } - ], - "type": "select", - "value": null - } - ], - "table": "produce_product" - }, - "product": { - "auth": [ - "add", - "delete", - "edit", - "info" - ], - "columns": [ - { - "add": false, - "edit": false, - "label": "ID", - "must": false, - "name": "id", - "sortable": true, - "type": "number" - }, - { - "label": "SN", - "name": "sn", - "type": "text" - }, - { - "label": "成品名称", - "name": "name", - "type": "text" - }, - { - "label": "图片", - "list": false, - "must": false, - "name": "img", - "type": "image" - }, - { - "label": "当前数量", - "name": "count", - "sortable": true, - "type": "number" - }, - { - "label": "总发货量", - "name": "used", - "sortable": true, - "type": "number" - }, - { - "label": "总生产量", - "name": "saved", - "sortable": true, - "type": "number" - }, - { - "label": "抽检覆盖量", - "name": "spot_check_count", - "sortable": true, - "type": "number" - }, - { - "label": "发货抽检总覆盖量", - "name": "spot_check_used", - "sortable": true, - "type": "number" - }, - { - "label": "总抽检总覆盖量", - "name": "spot_check_saved", - "sortable": true, - "type": "number" - }, - { - "label": "经办人", - "link": "admin", - "name": "admin_id", - "sortable": true, - "type": "number", - "value": "name" - }, - { - "add": false, - "edit": false, - "label": "创建时间", - "list": false, - "must": false, - "name": "create_time", - "type": "time" - }, - { - "add": false, - "edit": false, - "label": "变更时间", - "must": false, - "name": "modify_time", - "type": "time" - }, - { - "label": "状态", - "list": false, - "must": true, - "name": "state", - "options": [ - { - "name": "已启用", - "value": "0" - }, - { - "name": "未启用", - "value": "1" - }, - { - "name": "异常", - "value": "2" - } - ], - "type": "select" - }, - { - "label": "抽检参数", - "list": false, - "must": false, - "name": "rule_spot_check", - "type": "form" - }, - { - "label": "抽检百分比", - "list": false, - "must": false, - "name": "spot_check_percentage", - "sortable": true, - "type": "number" - }, - { - "label": "质检参数", - "list": false, - "must": false, - "name": "rule_check", - "type": "form" - } - ], - "label": "成品管理", - "search": [ - { - "label": "请输入关键词", - "name": "keyword", - "type": "search", - "value": null - }, - { - "label": "时间段", - "name": "daterange", - "type": "search", - "value": null - }, - { - "label": "排序", - "name": "sort", - "type": "search", - "value": null - }, - { - "label": "状态", - "list": false, - "must": true, - "name": "state", - "options": [ - { - "name": "已启用", - "value": "0" - }, - { - "name": "未启用", - "value": "1" - }, - { - "name": "异常", - "value": "2" - }, - { - "name": "全部", - "value": null - } - ], - "type": "select", - "value": null - } - ], - "table": "product" - }, - "product_check": { - "auth": [ - "add", - "delete", - "edit", - "info" - ], - "columns": [ - { - "add": false, - "edit": false, - "label": "ID", - "must": false, - "name": "id", - "sortable": true, - "type": "number" - }, - { - "label": "SN", - "name": "sn", - "type": "text" - }, - { - "label": "图片", - "list": false, - "must": false, - "name": "img", - "type": "image" - }, - { - "label": "生产成品", - "link": "produce_product", - "name": "produce_product_id", - "sortable": true, - "type": "number", - "value": "sn" - }, - { - "label": "经办人", - "link": "admin", - "name": "admin_id", - "sortable": true, - "type": "number", - "value": "name" - }, - { - "add": false, - "edit": false, - "label": "创建时间", - "list": false, - "must": false, - "name": "create_time", - "type": "time" - }, - { - "add": false, - "edit": false, - "label": "变更时间", - "must": false, - "name": "modify_time", - "type": "time" - }, - { - "label": "质检结论", - "list": false, - "must": true, - "name": "state", - "options": [ - { - "name": "正常", - "value": "0" - }, - { - "name": "异常", - "value": "1" - }, - { - "name": "其他", - "value": "2" - } - ], - "type": "select" - }, - { - "label": "基本信息", - "list": false, - "must": false, - "name": "rule", - "type": "form" - }, - { - "label": "生产计划", - "link": "produce", - "name": "produce_id", - "sortable": true, - "type": "number", - "value": "name" - }, - { - "label": "成品名称", - "link": "product", - "name": "product_id", - "sortable": true, - "type": "number", - "value": "name" - }, - { - "label": "备注信息", - "list": false, - "must": false, - "name": "description", - "type": "text" - } - ], - "label": "质检管理", - "search": [ - { - "label": "请输入关键词", - "name": "keyword", - "type": "search", - "value": null - }, - { - "label": "时间段", - "name": "daterange", - "type": "search", - "value": null - }, - { - "label": "排序", - "name": "sort", - "type": "search", - "value": null - }, - { - "label": "质检结论", - "list": false, - "must": true, - "name": "state", - "options": [ - { - "name": "正常", - "value": "0" - }, - { - "name": "异常", - "value": "1" - }, - { - "name": "其他", - "value": "2" - }, - { - "name": "全部", - "value": null - } - ], - "type": "select", - "value": null - } - ], - "table": "product_check" - }, - "product_line": { - "auth": [ - "add", - "delete", - "edit", - "info" - ], - "columns": [ - { - "add": false, - "edit": false, - "label": "ID", - "must": false, - "name": "id", - "sortable": true, - "type": "number" - }, - { - "label": "名称", - "name": "name", - "type": "text" - }, - { - "add": false, - "edit": false, - "label": "创建时间", - "list": false, - "must": false, - "name": "create_time", - "type": "time" - }, - { - "add": false, - "edit": false, - "label": "变更时间", - "must": false, - "name": "modify_time", - "type": "time" - }, - { - "label": "状态", - "list": false, - "must": true, - "name": "state", - "options": [ - { - "name": "已启用", - "value": "0" - }, - { - "name": "未启用", - "value": "1" - }, - { - "name": "异常", - "value": "2" - } - ], - "type": "select" - } - ], - "label": "产线管理", - "search": [ - { - "label": "请输入关键词", - "name": "keyword", - "type": "search", - "value": null - }, - { - "label": "时间段", - "name": "daterange", - "type": "search", - "value": null - }, - { - "label": "排序", - "name": "sort", - "type": "search", - "value": null - }, - { - "label": "状态", - "list": false, - "must": true, - "name": "state", - "options": [ - { - "name": "已启用", - "value": "0" - }, - { - "name": "未启用", - "value": "1" - }, - { - "name": "异常", - "value": "2" - }, - { - "name": "全部", - "value": null - } - ], - "type": "select", - "value": null - } - ], - "table": "product_line" - }, - "product_spot_check": { - "auth": [ - "add", - "delete", - "edit", - "info" - ], - "columns": [ - { - "add": false, - "edit": false, - "label": "ID", - "must": false, - "name": "id", - "sortable": true, - "type": "number" - }, - { - "label": "SN", - "name": "sn", - "type": "text" - }, - { - "label": "图片", - "list": false, - "must": false, - "name": "img", - "type": "image" - }, - { - "label": "成品", - "link": "product", - "name": "product_id", - "sortable": true, - "type": "number", - "value": "name" - }, - { - "label": "经办人", - "link": "admin", - "name": "admin_id", - "sortable": true, - "type": "number", - "value": "name" - }, - { - "add": false, - "edit": false, - "label": "创建时间", - "list": false, - "must": false, - "name": "create_time", - "type": "time" - }, - { - "add": false, - "edit": false, - "label": "变更时间", - "must": false, - "name": "modify_time", - "type": "time" - }, - { - "label": "抽检结论", - "list": false, - "must": true, - "name": "state", - "options": [ - { - "name": "正常", - "value": "0" - }, - { - "name": "异常", - "value": "1" - }, - { - "name": "其他", - "value": "2" - } - ], - "type": "select" - }, - { - "label": "基本信息", - "list": false, - "must": false, - "name": "rule", - "type": "form" - }, - { - "label": "生产计划", - "link": "produce", - "name": "produce_id", - "sortable": true, - "type": "number", - "value": "name" - }, - { - "label": "生产成品", - "link": "produce_product", - "name": "produce_product_id", - "sortable": true, - "type": "number", - "value": "sn" - }, - { - "label": "备注信息", - "list": false, - "must": false, - "name": "description", - "type": "text" - } - ], - "label": "抽检管理", - "search": [ - { - "label": "请输入关键词", - "name": "keyword", - "type": "search", - "value": null - }, - { - "label": "时间段", - "name": "daterange", - "type": "search", - "value": null - }, - { - "label": "排序", - "name": "sort", - "type": "search", - "value": null - }, - { - "label": "抽检结论", - "list": false, - "must": true, - "name": "state", - "options": [ - { - "name": "正常", - "value": "0" - }, - { - "name": "异常", - "value": "1" - }, - { - "name": "其他", - "value": "2" - }, - { - "name": "全部", - "value": null - } - ], - "type": "select", - "value": null - } - ], - "table": "product_spot_check" - }, - "role": { - "auth": [ - "add", - "delete", - "edit", - "info" - ], - "columns": [ - { - "add": false, - "edit": false, - "label": "ID", - "must": false, - "name": "id", - "sortable": true, - "type": "number" - }, - { - "label": "名称", - "name": "name", - "type": "text" - }, - { - "add": false, - "edit": false, - "label": "创建时间", - "list": false, - "must": false, - "name": "create_time", - "type": "time" - }, - { - "add": false, - "edit": false, - "label": "变更时间", - "must": false, - "name": "modify_time", - "type": "time" - }, - { - "label": "状态", - "list": false, - "must": true, - "name": "state", - "options": [ - { - "name": "已启用", - "value": "0" - }, - { - "name": "未启用", - "value": "1" - }, - { - "name": "异常", - "value": "2" - } - ], - "type": "select" - }, - { - "label": "规则", - "list": false, - "must": false, - "name": "rule", - "type": "form" - } - ], - "label": "角色管理", - "search": [ - { - "label": "请输入关键词", - "name": "keyword", - "type": "search", - "value": null - }, - { - "label": "时间段", - "name": "daterange", - "type": "search", - "value": null - }, - { - "label": "排序", - "name": "sort", - "type": "search", - "value": null - }, - { - "label": "状态", - "list": false, - "must": true, - "name": "state", - "options": [ - { - "name": "已启用", - "value": "0" - }, - { - "name": "未启用", - "value": "1" - }, - { - "name": "异常", - "value": "2" - }, - { - "name": "全部", - "value": null - } - ], - "type": "select", - "value": null - } - ], - "table": "role" - }, - "user": { - "auth": [ - "add", - "delete", - "edit", - "info" - ], - "columns": [ - { - "add": false, - "edit": false, - "label": "ID", - "must": false, - "name": "id", - "sortable": true, - "type": "number" - }, - { - "label": "SN", - "name": "sn", - "type": "text" - }, - { - "label": "用户姓名", - "name": "name", - "type": "text" - }, - { - "label": "公司名称", - "name": "company", - "type": "text" - }, - { - "label": "手机号码", - "name": "phone", - "type": "text" - }, - { - "label": "邮箱", - "list": false, - "must": false, - "name": "email", - "type": "text" - }, - { - "label": "状态", - "list": false, - "must": true, - "name": "state", - "options": [ - { - "name": "正常", - "value": "0" - }, - { - "name": "异常", - "value": "1" - }, - { - "name": "隐藏", - "value": "2" - } - ], - "type": "select" - }, - { - "label": "头像", - "list": false, - "must": false, - "name": "avatar", - "type": "image" - }, - { - "add": false, - "edit": false, - "label": "创建时间", - "list": false, - "must": false, - "name": "create_time", - "type": "time" - }, - { - "add": false, - "edit": false, - "label": "变更时间", - "must": false, - "name": "modify_time", - "type": "time" - } - ], - "label": "客户管理", - "search": [ - { - "label": "请输入关键词", - "name": "keyword", - "type": "search", - "value": null - }, - { - "label": "时间段", - "name": "daterange", - "type": "search", - "value": null - }, - { - "label": "排序", - "name": "sort", - "type": "search", - "value": null - }, - { - "label": "状态", - "list": false, - "must": true, - "name": "state", - "options": [ - { - "name": "正常", - "value": "0" - }, - { - "name": "异常", - "value": "1" - }, - { - "name": "隐藏", - "value": "2" - }, - { - "name": "全部", - "value": null - } - ], - "type": "select", - "value": null - } - ], - "table": "user" - } - } -} \ No newline at end of file diff --git a/example/config/config.json b/example/config/config.json index a17fdc9..0e31e49 100644 --- a/example/config/config.json +++ b/example/config/config.json @@ -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" } \ No newline at end of file diff --git a/example/main.go b/example/main.go index 081fa82..6238a78 100644 --- a/example/main.go +++ b/example/main.go @@ -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() // 客户端IP:port + 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) + } + +} diff --git a/example/myhs.exe b/example/myhs.exe index 911de22..a3f85ae 100644 Binary files a/example/myhs.exe and b/example/myhs.exe differ