From f5461743f6542e6b4a793117e05777769f9c3377 Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期二, 15 八月 2023 10:51:52 +0800 Subject: [PATCH] 新增任务开启通知接口,接收到通知或去查询工艺模型 --- logs/apsClient.info.log | 32 ++++ api/v1/notice.go | 44 +++++ pkg/httpx/httpx.go | 17 + pkg/ecode/code.go | 38 ---- docs/swagger.yaml | 25 +- logs/apsClient.err.log | 10 + docs/docs.go | 26 +- model/request/task.go | 10 + docs/swagger.json | 26 +- constvar/const.go | 4 /dev/null | 129 ---------------- model/request/common.go | 4 service/process_model.go | 42 +++++ conf/config.go | 7 conf/apsClient.json | 3 router/index.go | 11 + pkg/ecode/msg.go | 23 -- 17 files changed, 230 insertions(+), 221 deletions(-) diff --git a/api/v1/notice.go b/api/v1/notice.go new file mode 100644 index 0000000..cd3bed8 --- /dev/null +++ b/api/v1/notice.go @@ -0,0 +1,44 @@ +package v1 + +import ( + "apsClient/model/request" + _ "apsClient/model/response" + "apsClient/pkg/contextx" + "apsClient/pkg/logx" + "apsClient/pkg/safe" + "apsClient/service" + "github.com/gin-gonic/gin" +) + +type NoticeApi struct{} + +// TaskStart +// @Tags Base +// @Summary 浠诲姟寮�鍚�氱煡 +// @Produce application/json +// @Param object body request.TaskInfo true "鏌ヨ鍙傛暟" +// @Success 200 {object} contextx.Response{data=response.LoginResponse} "鎴愬姛" +// @Router /v1/notice/task/start [post] +func (slf *NoticeApi) TaskStart(c *gin.Context) { + var params request.TaskInfo + ctx, ok := contextx.NewContext(c, ¶ms) + if !ok { + return + } + safe.Go(func() { + resp, err := service.ProcessModel{}.GetProcessModel(service.GetProcessModelParams{ + WorkOrder: params.WorkOrder, + OrderId: params.OrderId, + Product: params.Product, + Procedure: params.Procedure, + Device: params.Device, + }) + if err != nil { + logx.Errorf("TaskStart Notice GetProcessModel error: %v", err.Error()) + return + } + logx.Infof("TaskStart Notice GetProcessModel: %+v", resp) + }) + + ctx.Ok() +} diff --git a/api/v1/user.go b/api/v1/user.go deleted file mode 100644 index 113eff2..0000000 --- a/api/v1/user.go +++ /dev/null @@ -1,76 +0,0 @@ -package v1 - -import ( - "apsClient/conf" - "apsClient/constvar" - "apsClient/model" - "apsClient/model/request" - _ "apsClient/model/response" - "apsClient/pkg/contextx" - "apsClient/pkg/convertx" - "apsClient/pkg/ecode" - "apsClient/pkg/logx" - "apsClient/service" - "github.com/gin-gonic/gin" - "github.com/mojocn/base64Captcha" - "time" -) - -// 褰撳紑鍚鏈嶅姟鍣ㄩ儴缃叉椂锛屾浛鎹笅闈㈢殑閰嶇疆锛屼娇鐢╮edis鍏变韩瀛樺偍楠岃瘉鐮� -// var store = captcha.NewDefaultRedisStore() -var ( - store = base64Captcha.DefaultMemStore - userService = &service.UserService{} -) - -type UserApi struct{} - -// Login -// @Tags Base -// @Summary 鐢ㄦ埛鐧诲綍 -// @Produce application/json -// @Param object body request.Login true "鏌ヨ鍙傛暟" -// @Success 200 {object} contextx.Response{data=response.LoginResponse} "鎴愬姛" -// @Router /api/base/login [post] -func (slf *UserApi) Login(c *gin.Context) { - var params request.Login - ctx, ok := contextx.NewContext(c, ¶ms) - if !ok { - return - } - - // 鍒ゆ柇楠岃瘉鐮佹槸鍚﹀紑鍚� - key := c.ClientIP() - openCaptcha := conf.Conf.Captcha.OpenCaptcha // 鏄惁寮�鍚槻鐖嗘鏁� - openCaptchaTimeOut := conf.Conf.Captcha.OpenCaptchaTimeOut // 缂撳瓨瓒呮椂鏃堕棿 - v, ok := constvar.BlackCache.Get(key) - if !ok { - constvar.BlackCache.Set(key, 1, time.Second*time.Duration(openCaptchaTimeOut)) - } - - var oc bool = openCaptcha == 0 || convertx.InterfaceToInt(v) > openCaptcha // 0 琛ㄧず姣忔鐧诲綍閮介渶瑕侀獙璇佺爜 鎴栬�呭綋鍓嶆鏁板凡瓒呰繃闃茬垎娆℃暟 - - if !oc || store.Verify(params.CaptchaId, params.Captcha, true) { - u := &model.User{Username: params.Username, Password: params.Password} - user, errCode := userService.Login(u) - if errCode != ecode.OK { - logx.Errorf("鐧婚檰澶辫触! 鐢ㄦ埛鍚嶄笉瀛樺湪鎴栬�呭瘑鐮侀敊璇�! errCode:%v", errCode) - // 楠岃瘉鐮佹鏁�+1 - _ = constvar.BlackCache.Increment(key, 1) - ctx.Fail(errCode) - return - } - if !user.Enable { - logx.Errorf("鐧婚檰澶辫触! 鐢ㄦ埛琚姝㈢櫥褰�!") - // 楠岃瘉鐮佹鏁�+1 - _ = constvar.BlackCache.Increment(key, 1) - ctx.Fail(ecode.UserForbidden) - return - } - return - } - - // 楠岃瘉鐮佹鏁�+1 - _ = constvar.BlackCache.Increment(key, 1) - ctx.Fail(ecode.CaptchaErr) -} diff --git a/conf/apsClient.json b/conf/apsClient.json index 0790e9b..c5d81ae 100644 --- a/conf/apsClient.json +++ b/conf/apsClient.json @@ -62,6 +62,9 @@ "alHost": "172.20.11.128", "host": "172.20.11.127", "ip": "172.20.11.127" + }, + "Services":{ + "apsServer": "http://127.0.0.1:9081" } } diff --git a/conf/config.go b/conf/config.go index f9816ec..44b9eab 100644 --- a/conf/config.go +++ b/conf/config.go @@ -76,6 +76,10 @@ IP string // tmp ip } + Services struct { + ApsServer string + } + config struct { // 绯荤粺閰嶇疆 System System @@ -103,6 +107,9 @@ // k8s閰嶇疆 K8s K8s + + //Services Address + Services Services } ) diff --git a/constvar/const.go b/constvar/const.go index 4f6c64f..00642ca 100644 --- a/constvar/const.go +++ b/constvar/const.go @@ -9,3 +9,7 @@ UserTypePrimary // 涓昏处鎴� UserTypeSub // 瀛愯处鎴� ) + +const ( + ApsServerHost = "" +) diff --git a/docs/docs.go b/docs/docs.go index 833b4e0..40f438e 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -16,7 +16,7 @@ "host": "{{.Host}}", "basePath": "{{.BasePath}}", "paths": { - "/api/base/login": { + "/v1/notice/task/start": { "post": { "produces": [ "application/json" @@ -24,7 +24,7 @@ "tags": [ "Base" ], - "summary": "鐢ㄦ埛鐧诲綍", + "summary": "浠诲姟寮�鍚�氱煡", "parameters": [ { "description": "鏌ヨ鍙傛暟", @@ -32,7 +32,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/request.Login" + "$ref": "#/definitions/request.TaskInfo" } } ], @@ -173,23 +173,27 @@ } } }, - "request.Login": { + "request.TaskInfo": { "type": "object", "properties": { - "captcha": { - "description": "楠岃瘉鐮�", + "device": { + "description": "璁惧", "type": "string" }, - "captchaId": { - "description": "楠岃瘉鐮両D", + "orderId": { + "description": "璁㈠崟鍙�", "type": "string" }, "password": { - "description": "瀵嗙爜", + "description": "浜у搧", "type": "string" }, - "username": { - "description": "鐢ㄦ埛鍚�", + "procedure": { + "description": "宸ュ簭", + "type": "string" + }, + "workOrder": { + "description": "宸ュ崟", "type": "string" } } diff --git a/docs/swagger.json b/docs/swagger.json index f5af4d2..66654ce 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -4,7 +4,7 @@ "contact": {} }, "paths": { - "/api/base/login": { + "/v1/notice/task/start": { "post": { "produces": [ "application/json" @@ -12,7 +12,7 @@ "tags": [ "Base" ], - "summary": "鐢ㄦ埛鐧诲綍", + "summary": "浠诲姟寮�鍚�氱煡", "parameters": [ { "description": "鏌ヨ鍙傛暟", @@ -20,7 +20,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/request.Login" + "$ref": "#/definitions/request.TaskInfo" } } ], @@ -161,23 +161,27 @@ } } }, - "request.Login": { + "request.TaskInfo": { "type": "object", "properties": { - "captcha": { - "description": "楠岃瘉鐮�", + "device": { + "description": "璁惧", "type": "string" }, - "captchaId": { - "description": "楠岃瘉鐮両D", + "orderId": { + "description": "璁㈠崟鍙�", "type": "string" }, "password": { - "description": "瀵嗙爜", + "description": "浜у搧", "type": "string" }, - "username": { - "description": "鐢ㄦ埛鍚�", + "procedure": { + "description": "宸ュ簭", + "type": "string" + }, + "workOrder": { + "description": "宸ュ崟", "type": "string" } } diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 4af7f96..6f04fa0 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -77,19 +77,22 @@ username: type: string type: object - request.Login: + request.TaskInfo: properties: - captcha: - description: 楠岃瘉鐮� + device: + description: 璁惧 type: string - captchaId: - description: 楠岃瘉鐮両D + orderId: + description: 璁㈠崟鍙� type: string password: - description: 瀵嗙爜 + description: 浜у搧 type: string - username: - description: 鐢ㄦ埛鍚� + procedure: + description: 宸ュ簭 + type: string + workOrder: + description: 宸ュ崟 type: string type: object response.LoginResponse: @@ -104,7 +107,7 @@ info: contact: {} paths: - /api/base/login: + /v1/notice/task/start: post: parameters: - description: 鏌ヨ鍙傛暟 @@ -112,7 +115,7 @@ name: object required: true schema: - $ref: '#/definitions/request.Login' + $ref: '#/definitions/request.TaskInfo' produces: - application/json responses: @@ -125,7 +128,7 @@ data: $ref: '#/definitions/response.LoginResponse' type: object - summary: 鐢ㄦ埛鐧诲綍 + summary: 浠诲姟寮�鍚�氱煡 tags: - Base swagger: "2.0" diff --git a/logs/apsClient.err.log b/logs/apsClient.err.log index 33a12ab..92313f0 100644 --- a/logs/apsClient.err.log +++ b/logs/apsClient.err.log @@ -6,3 +6,13 @@ [2023-08-14 20:10:31] [error] [main.main:22] model Init err:Error 1067 (42000): Invalid default value for 'nick_name' [2023-08-14 20:10:43] [error] [gorm.io/gorm/migrator.Migrator.CreateTable.func1:281] trace {"error": "Error 1067 (42000): Invalid default value for 'nick_name'", "elapsed": 0.0010015, "rows": 0, "sql": "CREATE TABLE `user` (`id` varchar(255) COMMENT '鐢ㄦ埛ID',`username` varchar(255) COMMENT '鐢ㄦ埛鐧诲綍鍚�',`user_type` int(11) COMMENT '鐢ㄦ埛绫诲瀷 1瓒呯骇绠$悊鍛� 2涓昏处鎴� 3瀛愯处鎴�',`password` varchar(255) COMMENT '鐢ㄦ埛鐧诲綍瀵嗙爜',`nick_name` varchar(255) DEFAULT '绯荤粺鐢ㄦ埛' COMMENT '鐢ㄦ埛鏄电О',`header_image` mediumtext COMMENT '鐢ㄦ埛澶村儚',`phone` varchar(255) COMMENT '鐢ㄦ埛鎵嬫満鍙�',`enable` tinyint(1) COMMENT '鐢ㄦ埛鏄惁琚喕缁�',`parent_id` varchar(255) COMMENT '鐖剁敤鎴稩D',`parent_name` varchar(255) COMMENT '鐖剁敤鎴峰悕绉�',`company_name` varchar(255) COMMENT '鍏徃鍚嶇О',`company_email` varchar(255) COMMENT '鍏徃閭',`company_contact` varchar(255) COMMENT '鍏徃鑱旂郴浜哄鍚�',`company_province` varchar(255) COMMENT '鍏徃鎵�鍦ㄧ渷',`company_city` varchar(255) COMMENT '鍏徃鎵�鍦ㄥ競',`company_trade` varchar(255) COMMENT '鍏徃琛屼笟',`pos` varchar(255) COMMENT '宀椾綅',`modified_pwd` tinyint(1) COMMENT '鏄惁鏀硅繃瀵嗙爜',`create_time` bigint(20) COMMENT '鍒涘缓鏃堕棿',`update_time` bigint(20) COMMENT '鏇存柊鏃堕棿',`ip` varchar(255) COMMENT '闆嗙兢Ip',`port` varchar(255) COMMENT '绔彛鍙�',`status` int(11) COMMENT '鐢ㄦ埛瀹℃牳鐘舵�� 0:绂佺敤',`company_logo` mediumtext COMMENT '鍏徃logo',`system_name` varchar(255) COMMENT '绯荤粺鍚嶇О',PRIMARY KEY (`id`),INDEX `idx_user_username` (`username`))"} [2023-08-14 20:10:43] [error] [main.main:22] model Init err:Error 1067 (42000): Invalid default value for 'nick_name' +[2023-08-15 10:34:05] [error] [apsClient/api/v1.(*NoticeApi).TaskStart.func1:37] TaskStart Notice GetProcessModel error: Post "/api-s/v1/processParams/info": unsupported protocol scheme "" +[2023-08-15 10:38:12] [error] [apsClient/api/v1.(*NoticeApi).TaskStart.func1:37] TaskStart Notice GetProcessModel error: Post "/api-s/v1/processParams/info": unsupported protocol scheme "" +[2023-08-15 10:38:23] [error] [apsClient/api/v1.(*NoticeApi).TaskStart.func1:37] TaskStart Notice GetProcessModel error: Post "/api-s/v1/processParams/info": unsupported protocol scheme "" +[2023-08-15 10:38:28] [error] [apsClient/api/v1.(*NoticeApi).TaskStart.func1:37] TaskStart Notice GetProcessModel error: Post "/api-s/v1/processParams/info": unsupported protocol scheme "" +[2023-08-15 10:38:55] [error] [apsClient/api/v1.(*NoticeApi).TaskStart.func1:37] TaskStart Notice GetProcessModel error: parse "127.0.0.1:9081/api-s/v1/processParams/info": first path segment in URL cannot contain colon +[2023-08-15 10:40:21] [error] [apsClient/api/v1.(*NoticeApi).TaskStart.func1:37] TaskStart Notice GetProcessModel error: parse "127.0.0.1:9081/api-s/v1/processParams/info": first path segment in URL cannot contain colon +[2023-08-15 10:42:38] [error] [apsClient/api/v1.(*NoticeApi).TaskStart.func1:37] TaskStart Notice GetProcessModel error: invalid character 'p' after top-level value +[2023-08-15 10:43:02] [error] [apsClient/api/v1.(*NoticeApi).TaskStart.func1:37] TaskStart Notice GetProcessModel error: Post "http://127.0.0.1:9081/api-s/v1/processParams/info": EOF +[2023-08-15 10:48:32] [error] [apsClient/api/v1.(*NoticeApi).TaskStart.func1:37] TaskStart Notice GetProcessModel error: json: cannot unmarshal number into Go struct field GetProcessModelResponse.Code of type string +[2023-08-15 10:49:36] [error] [apsClient/api/v1.(*NoticeApi).TaskStart.func1:37] TaskStart Notice GetProcessModel error: json: cannot unmarshal number into Go struct field GetProcessModelResponse.Code of type string diff --git a/logs/apsClient.info.log b/logs/apsClient.info.log index 52a00b7..c21f8e3 100644 --- a/logs/apsClient.info.log +++ b/logs/apsClient.info.log @@ -8,3 +8,35 @@ [2023-08-14 20:10:43] [debug] [gorm.io/gorm/migrator.Migrator.HasTable.func1:309] trace {"elapsed": 0.0020024, "rows": 1, "sql": "SELECT SCHEMA_NAME from Information_schema.SCHEMATA where SCHEMA_NAME LIKE 'aps_client%' ORDER BY SCHEMA_NAME='aps_client' DESC,SCHEMA_NAME limit 1"} [2023-08-14 20:10:43] [debug] [gorm.io/gorm/migrator.Migrator.HasTable.func1:310] trace {"elapsed": 0.0010035, "rows": -1, "sql": "SELECT count(*) FROM information_schema.tables WHERE table_schema = 'aps_client' AND table_name = 'user' AND table_type = 'BASE TABLE'"} [2023-08-14 20:11:04] [info] [main.main:27] apsClient start serve... +[2023-08-15 10:32:54] [info] [main.main:27] apsClient start serve... +[2023-08-15 10:33:18] [info] [main.shutdown:42] apsClient exited... +[2023-08-15 10:33:20] [info] [main.main:27] apsClient start serve... +[2023-08-15 10:34:05] [info] [apsClient/pkg/contextx.NewContext.func1:38] 192.168.20.120 | POST /v1/notice/task/start | uid: | &{OrderId:string Product:string Procedure:string WorkOrder:string Device:string} +[2023-08-15 10:37:58] [info] [main.shutdown:42] apsClient exited... +[2023-08-15 10:38:01] [info] [main.main:27] apsClient start serve... +[2023-08-15 10:38:12] [info] [apsClient/pkg/contextx.NewContext.func1:38] 192.168.20.120 | POST /v1/notice/task/start | uid: | &{OrderId:string Product:string Procedure:string WorkOrder:string Device:string} +[2023-08-15 10:38:23] [info] [apsClient/pkg/contextx.NewContext.func1:38] 192.168.20.120 | POST /v1/notice/task/start | uid: | &{OrderId:string Product:string Procedure:string WorkOrder:string Device:string} +[2023-08-15 10:38:28] [info] [apsClient/pkg/contextx.NewContext.func1:38] 192.168.20.120 | POST /v1/notice/task/start | uid: | &{OrderId:string Product:string Procedure:string WorkOrder:string Device:string} +[2023-08-15 10:38:50] [info] [main.shutdown:42] apsClient exited... +[2023-08-15 10:38:52] [info] [main.main:27] apsClient start serve... +[2023-08-15 10:38:55] [info] [apsClient/pkg/contextx.NewContext.func1:38] 192.168.20.120 | POST /v1/notice/task/start | uid: | &{OrderId:string Product:string Procedure:string WorkOrder:string Device:string} +[2023-08-15 10:39:11] [info] [main.shutdown:42] apsClient exited... +[2023-08-15 10:39:19] [info] [main.main:27] apsClient start serve... +[2023-08-15 10:39:26] [info] [apsClient/pkg/contextx.NewContext.func1:38] 192.168.20.120 | POST /v1/notice/task/start | uid: | &{OrderId:string Product:string Procedure:string WorkOrder:string Device:string} +[2023-08-15 10:40:21] [info] [main.shutdown:42] apsClient exited... +[2023-08-15 10:40:22] [info] [main.main:27] apsClient start serve... +[2023-08-15 10:40:26] [info] [apsClient/pkg/contextx.NewContext.func1:38] 192.168.20.120 | POST /v1/notice/task/start | uid: | &{OrderId:string Product:string Procedure:string WorkOrder:string Device:string} +[2023-08-15 10:42:41] [info] [apsClient/pkg/contextx.NewContext.func1:38] 192.168.20.120 | POST /v1/notice/task/start | uid: | &{OrderId:string Product:string Procedure:string WorkOrder:string Device:string} +[2023-08-15 10:43:07] [info] [main.shutdown:42] apsClient exited... +[2023-08-15 10:43:09] [info] [main.main:27] apsClient start serve... +[2023-08-15 10:44:44] [info] [apsClient/pkg/contextx.NewContext.func1:38] 192.168.20.120 | POST /v1/notice/task/start | uid: | &{OrderId:string Product:string Procedure:string WorkOrder:string Device:string} +[2023-08-15 10:44:44] [info] [apsClient/api/v1.(*NoticeApi).TaskStart.func1:40] TaskStart Notice GetProcessModel: &{Number: OrderId: Product: Procedure: WorkOrder: Device: ParamsMap:map[]} +[2023-08-15 10:45:37] [info] [main.shutdown:42] apsClient exited... +[2023-08-15 10:45:39] [info] [main.main:27] apsClient start serve... +[2023-08-15 10:45:42] [info] [apsClient/pkg/contextx.NewContext.func1:38] 192.168.20.120 | POST /v1/notice/task/start | uid: | &{OrderId:string Product:string Procedure:string WorkOrder:string Device:string} +[2023-08-15 10:48:20] [info] [apsClient/api/v1.(*NoticeApi).TaskStart.func1:40] TaskStart Notice GetProcessModel: &{Number: OrderId: Product: Procedure: WorkOrder: Device: ParamsMap:map[]} +[2023-08-15 10:48:20] [info] [main.shutdown:42] apsClient exited... +[2023-08-15 10:48:23] [info] [main.main:27] apsClient start serve... +[2023-08-15 10:48:25] [info] [apsClient/pkg/contextx.NewContext.func1:38] 192.168.20.120 | POST /v1/notice/task/start | uid: | &{OrderId:string Product:string Procedure:string WorkOrder:string Device:string} +[2023-08-15 10:48:45] [info] [apsClient/pkg/contextx.NewContext.func1:38] 192.168.20.120 | POST /v1/notice/task/start | uid: | &{OrderId:string Product:string Procedure:string WorkOrder:string Device:string} +[2023-08-15 10:49:54] [info] [main.shutdown:42] apsClient exited... diff --git a/model/request/common.go b/model/request/common.go index 492de9d..952d6c6 100644 --- a/model/request/common.go +++ b/model/request/common.go @@ -8,7 +8,3 @@ type GetById struct { ID uint `json:"id"` // 涓婚敭ID } - -type GetByUserId struct { - UserId string `json:"userId"` // 鐢ㄦ埛ID -} diff --git a/model/request/menu.go b/model/request/menu.go deleted file mode 100644 index 25079a2..0000000 --- a/model/request/menu.go +++ /dev/null @@ -1,6 +0,0 @@ -package request - -type AddUserMenu struct { - MenuIds []uint `json:"menuIds"` - UserId string `json:"userId"` // 鐢ㄦ埛ID -} diff --git a/model/request/task.go b/model/request/task.go new file mode 100644 index 0000000..68b9357 --- /dev/null +++ b/model/request/task.go @@ -0,0 +1,10 @@ +package request + +// TaskInfo 浠诲姟寮�鍚�氱煡璇锋眰鍙傛暟 +type TaskInfo struct { + OrderId string `json:"orderId"` // 璁㈠崟鍙� + Product string `json:"password"` // 浜у搧 + Procedure string `json:"procedure"` // 宸ュ簭 + WorkOrder string `json:"workOrder"` // 宸ュ崟 + Device string `json:"device"` // 璁惧 +} diff --git a/pkg/ecode/code.go b/pkg/ecode/code.go index 515f5a8..84bfb0d 100644 --- a/pkg/ecode/code.go +++ b/pkg/ecode/code.go @@ -3,38 +3,8 @@ const ( OK = 200 - UnknownErr = 2001 // 鏈煡閿欒 - DBErr = 2002 // db閿欒 - RedisErr = 2003 // redis閿欒 - ParamsErr = 2004 // 璇锋眰鍙傛暟閿欒 - UserNotExist = 2005 // 鐢ㄦ埛涓嶅瓨鍦� - PasswordErr = 2006 // 瀵嗙爜閿欒 - UserForbidden = 2007 // 鐢ㄦ埛琚鐢� - CaptchaGenerateFailed = 2008 // 楠岃瘉鐮佺敓鎴愬け璐� - CaptchaErr = 2009 // 楠岃瘉鐮侀敊璇� - CreateTokenErr = 2010 // 鍒涘缓token澶辫触 - JWTInBlackList = 2011 // JWT鍦ㄧ櫧鍚嶅崟 - JWTDisabled = 2012 // JWT澶辨晥 - JWTEmpty = 2013 // JWT涓虹┖ - JWTExpire = 2014 // JWT杩囨湡 - JWTParseErr = 2015 // JWT瑙f瀽澶辫触 - UserNameExistErr = 2016 // 鐢ㄦ埛鍚嶅凡瀛樺湪 - ChildrenExistErr = 2017 // 瀛樺湪瀛愯彍鍗� - MenuNotExist = 2018 // 鑿滃崟涓嶅瓨鍦� - MenuNameExistErr = 2019 // 鑿滃崟鍚嶅凡瀛樺湪 - DeviceIPExistErr = 2020 // 璇ヨ澶嘔P宸插瓨鍦� - DeviceInstallRancherErr = 2021 // 瀹夎rancher澶辫触 - ClusterNameExistErr = 2022 // 瑭查泦缇ゅ凡缍撳瓨鍦� - CreateDatabaseErr = 2023 // 鍒涘缓鏁版嵁搴撻敊璇� - CreateDatabaseUserErr = 2024 // 鍒涘缓鏁版嵁搴撶敤鎴烽敊璇� - CreateClusterErr = 2025 // 鍒涘缓闆嗙兢澶辫触 - GetClusterErr = 2026 // 鑾峰彇闆嗙兢澶辫触 - GetClusterKubeConfigErr = 2027 // 鑾峰彇kube config澶辫触 - ClusterInstallDockerErr = 2028 // 瀹夎docker澶辫触 - ClusterInstallKubectlErr = 2029 // 瀹夎kubectl澶辫触 - ClusterDeployKubernetesRolesErr = 2030 // 閮ㄧ讲kubernetes瑙掕壊澶辫触 - ClusterGetNodeCommandErr = 2031 // 鑾峰彇node command澶辫触 - UserHasCluster = 2032 // 鍒犻櫎鐢ㄦ埛澶辫触锛岃鐢ㄦ埛涓嬪瓨鍦ㄩ泦缇� - NoPowerErr = 2033 //銆�娌℃湁鏉冮檺 - UploadImageErr = 2034 //銆�涓婁紶鍥惧儚澶辫触 + UnknownErr = 2001 // 鏈煡閿欒 + DBErr = 2002 // db閿欒 + RedisErr = 2003 // redis閿欒 + ParamsErr = 2004 // 璇锋眰鍙傛暟閿欒 ) diff --git a/pkg/ecode/msg.go b/pkg/ecode/msg.go index 5b43237..a56f586 100644 --- a/pkg/ecode/msg.go +++ b/pkg/ecode/msg.go @@ -1,25 +1,10 @@ package ecode var MsgFlags = map[int]string{ - UnknownErr: "鏈煡閿欒", - DBErr: "db閿欒", - RedisErr: "redis閿欒", - ParamsErr: "璇锋眰鍙傛暟閿欒", - UserNotExist: "鐢ㄦ埛涓嶅瓨鍦�", - PasswordErr: "瀵嗙爜閿欒", - UserForbidden: "鐢ㄦ埛琚鐢�", - CaptchaGenerateFailed: "楠岃瘉鐮佺敓鎴愬け璐�", - CaptchaErr: "楠岃瘉鐮侀敊璇�", - CreateTokenErr: "鍒涘缓token澶辫触", - JWTInBlackList: "JWT鍦ㄧ櫧鍚嶅崟", - JWTDisabled: "JWT澶辨晥", - JWTEmpty: "JWT涓虹┖", - JWTExpire: "JWT杩囨湡", - JWTParseErr: "JWT瑙f瀽澶辫触", - UserNameExistErr: "鐢ㄦ埛鍚嶅凡瀛樺湪", - ChildrenExistErr: "瀛樺湪瀛愯彍鍗�", - MenuNotExist: "鑿滃崟涓嶅瓨鍦�", - MenuNameExistErr: "鑿滃崟鍚嶅凡瀛樺湪", + UnknownErr: "鏈煡閿欒", + DBErr: "db閿欒", + RedisErr: "redis閿欒", + ParamsErr: "璇锋眰鍙傛暟閿欒", } func GetMsg(errCode int) (errMsg string) { diff --git a/pkg/httpx/httpx.go b/pkg/httpx/httpx.go index 4e286fe..c909811 100644 --- a/pkg/httpx/httpx.go +++ b/pkg/httpx/httpx.go @@ -3,7 +3,8 @@ import ( "bytes" "encoding/json" - "io/ioutil" + "errors" + "io" "net/http" "time" ) @@ -33,9 +34,21 @@ } defer resp.Body.Close() - respBytes, err := ioutil.ReadAll(resp.Body) + respBytes, err := io.ReadAll(resp.Body) if err != nil { return nil, err } return respBytes, nil } + +func SendPostAndParseJson(url string, post, response interface{}) (err error) { + if response == nil { + return errors.New("response is not set") + } + + respBytes, err := SendPost(http.Header{}, url, post) + if err != nil { + return err + } + return json.Unmarshal(respBytes, &response) +} diff --git a/router/index.go b/router/index.go index b3b8559..bf849d2 100644 --- a/router/index.go +++ b/router/index.go @@ -1,6 +1,7 @@ package router import ( + v1 "apsClient/api/v1" "apsClient/conf" _ "apsClient/docs" "github.com/gin-contrib/cors" @@ -28,5 +29,15 @@ c.JSON(http.StatusOK, "ok") }) } + + v1Group := Router.Group("v1") + + // 鎺ユ敹閫氱煡 + noticeApi := new(v1.NoticeApi) + noticeGroup := v1Group.Group("notice") + { + noticeGroup.POST("task/start", noticeApi.TaskStart) // 浠诲姟寮�鍚�氱煡 + } + return Router } diff --git a/service/process_model.go b/service/process_model.go new file mode 100644 index 0000000..d201167 --- /dev/null +++ b/service/process_model.go @@ -0,0 +1,42 @@ +package service + +import ( + "apsClient/conf" + "apsClient/pkg/httpx" +) + +type ProcessModel struct{} + +const ( + GetProcessModelUrl = "/api-s/v1/processParams/info" +) + +type GetProcessModelParams struct { + WorkOrder string `json:"workOrder,omitempty" form:"workOrder"` //宸ュ簭缂栧彿 + OrderId string `json:"orderId"` // 璁㈠崟鍙� + Product string `json:"password"` // 浜у搧 + Procedure string `json:"procedure"` // 宸ュ簭 + Device string `json:"device"` // 璁惧 +} +type GetProcessModel struct { + Number string `json:"number"` //宸ヨ壓妯″瀷缂栧彿 + OrderId string `json:"orderId"` //璁㈠崟id + Product string `json:"product"` //浜у搧鍚嶇О + Procedure string `json:"procedure"` //宸ュ簭 + WorkOrder string `json:"workOrder"` //宸ュ崟 + Device string `json:"device"` //璁惧 + ParamsMap map[string]interface{} `json:"paramsMap"` +} + +type GetProcessModelResponse struct { + Code int + Msg string + Data GetProcessModel +} + +// GetProcessModel 鑾峰彇宸ヨ壓妯″瀷 +func (slf ProcessModel) GetProcessModel(params GetProcessModelParams) (GetProcessModel GetProcessModel, err error) { + resp := new(GetProcessModelResponse) + err = httpx.SendPostAndParseJson(conf.Conf.Services.ApsServer+GetProcessModelUrl, params, resp) + return resp.Data, err +} diff --git a/service/user.go b/service/user.go deleted file mode 100644 index ccf3b62..0000000 --- a/service/user.go +++ /dev/null @@ -1,129 +0,0 @@ -package service - -import ( - "apsClient/constvar" - "apsClient/model" - "apsClient/model/request" - "apsClient/pkg/ecode" - "apsClient/pkg/encrypt" - "errors" - "gorm.io/gorm" -) - -type UserService struct{} - -func (userService *UserService) Login(u *model.User) (userInter *model.User, errCode int) { - userInter, err := model.NewUserSearch(nil).SetUserName(u.Username).First() - if err != nil { - return nil, ecode.UserNotExist - } - - if ok := encrypt.BcryptCheck(u.Password, userInter.Password); !ok { - return nil, ecode.PasswordErr - } - - if userInter.UserType == constvar.UserTypeSub { - parentUser, _ := model.NewUserSearch(nil).SetId(userInter.ParentId).First() - userInter.CompanyLogo = parentUser.CompanyLogo - userInter.SystemName = parentUser.SystemName - } - - return userInter, ecode.OK -} - -func (userService *UserService) Register(u *model.User) (userInter *model.User, errCode int) { - _, err := model.NewUserSearch(nil).SetUserName(u.Username).First() - if err != gorm.ErrRecordNotFound { - return userInter, ecode.UserNameExistErr - } - - err = model.NewUserSearch(nil).Create(u) - return u, ecode.OK -} - -func (userService *UserService) ChangePassword(u *model.User, newPassword string) (userInter *model.User, errCode int) { - user, err := model.NewUserSearch(nil).SetId(u.ID).First() - if err != nil { - return nil, ecode.UserNotExist - } - - if ok := encrypt.BcryptCheck(u.Password, user.Password); !ok { - return nil, ecode.PasswordErr - } - - user.Password = encrypt.BcryptHash(newPassword) - err = model.NewUserSearch(nil).SetId(u.ID).UpdateByMap(map[string]interface{}{ - "password": user.Password}) - - return user, ecode.OK - -} - -func (userService *UserService) DeleteUser(id string) (err error) { - user, err := model.NewUserSearch(nil).SetId(id).First() - if err != nil { - return err - } - if user.Ip != "" { - return errors.New("璇ョ敤鎴峰凡閰嶇疆闆嗙兢锛屾棤娉曞垹闄�") - } - if user.UserType != constvar.UserTypeSub { - return errors.New("璇ョ敤鎴烽潪瀛愯处鎴凤紝鏃犳硶鍒犻櫎") - } - - err = model.NewUserSearch(nil).SetId(id).Delete() - if err != nil { - return err - } - - return model.NewUserMenuSearch(nil).SetUserId(id).Delete() -} - -func (userService *UserService) SetUserInfo(req model.User) error { - return model.NewUserSearch(nil).SetId(req.ID).UpdateByMap(map[string]interface{}{ - "nick_name": req.NickName, - "phone": req.Phone, - "pos": req.Pos, - }) -} - -func (userService *UserService) SetSelfInfo(userId string, req request.SetSelfInfo) error { - return model.NewUserSearch(nil).SetId(userId).UpdateByMap(map[string]interface{}{ - "nick_name": req.NickName, - "phone": req.Phone, - "companyName": req.CompanyName, - "companyEmail": req.CompanyEmail, - "companyContact": req.CompanyContact, - "companyProvince": req.CompanyProvince, - "companyCity": req.CompanyCity, - "companyTrade": req.CompanyTrade, - "headerImage": req.HeaderImage, - }) -} - -func (userService *UserService) GetUserInfo(id string) (user *model.User, err error) { - user, err = model.NewUserSearch(nil).SetId(id).First() - if err != nil { - return - } - - if user.UserType == constvar.UserTypeSub { - parentUser, _ := model.NewUserSearch(nil).SetId(user.ParentId).First() - user.CompanyLogo = parentUser.CompanyLogo - user.SystemName = parentUser.SystemName - } - return -} - -func (userService *UserService) ResetPassword(id string) (err error) { - return model.NewUserSearch(nil).SetId(id).UpdateByMap(map[string]interface{}{ - "password": encrypt.BcryptHash("123456"), - }) -} - -func (userService *UserService) SetOtherInfo(userId string, req request.SetOtherInfo) error { - return model.NewUserSearch(nil).SetId(userId).UpdateByMap(map[string]interface{}{ - "company_logo": req.CompanyLogo, - "system_name": req.SystemName, - }) -} -- Gitblit v1.8.0