diff --git a/dsDataex/MyService/DataEX/DataexService/DataexService.go b/dsDataex/MyService/DataEX/DataexService/DataexService.go index 44b1249a..591963be 100644 --- a/dsDataex/MyService/DataEX/DataexService/DataexService.go +++ b/dsDataex/MyService/DataEX/DataexService/DataexService.go @@ -336,7 +336,7 @@ func DataexCollect(systemID string,users []MySwagger.User,events []MySwagger.Eve func DataexSetBatch(systemID string, datas []MySwagger.Data,datasource *models.TDataexDatasource)(bool,string,[]string,[]MySwagger.FailResult) { //add by zhangjun 2020-07-15 //处理组织机构树同步 - if datasource.DatasourceCode=="org_school2" && systemID=="BASE_GO"{ + if datasource.DatasourceCode=="org_school" && systemID=="BASE_GO"{ OrgtreeProcBatch(datas) } if datasource.DatasourceCode=="org_school_lua" && systemID=="BASE_LUA"{ diff --git a/dsSupport/Config/Config.ini b/dsSupport/Config/Config.ini index ea1d44e8..ebb28dc9 100644 --- a/dsSupport/Config/Config.ini +++ b/dsSupport/Config/Config.ini @@ -41,3 +41,6 @@ project_name = dsSupport ip = 127.0.0.1 port = 8001 +[account] +users = admin:dsideal,administrator:dsideal123@321 + diff --git a/dsSupport/MyModel/Account/AccountController/DataerrorController.go b/dsSupport/MyModel/Account/AccountController/DataerrorController.go new file mode 100644 index 00000000..32045d16 --- /dev/null +++ b/dsSupport/MyModel/Account/AccountController/DataerrorController.go @@ -0,0 +1,23 @@ +/** + * @Title: + * @Description: + * @Author: Yuki Wong(iyuki0430@msn.com) + * @Update: + * @Date: 2020/7/20 11:49 + * @File: AccountController.go + * @Software: GoLand + **/ +package AccountController + +import ( + "dsSupport/MyModel/Account/AccountOpenAPI" + "github.com/gin-gonic/gin" +) + +func Routers(r *gin.RouterGroup) { + rr := r.Group("/openapi") + + rr.POST("/account/login", AccountOpenAPI.Login) + + return +} diff --git a/dsSupport/MyModel/Account/AccountDAO/AccountDAO.go b/dsSupport/MyModel/Account/AccountDAO/AccountDAO.go new file mode 100644 index 00000000..1d63468d --- /dev/null +++ b/dsSupport/MyModel/Account/AccountDAO/AccountDAO.go @@ -0,0 +1,45 @@ +/** + * @Title: + * @Description: + * @Author: Yuki Wong(iyuki0430@msn.com) + * @Update: + * @Date: 2020/7/20 11:49 + * @File: AccountDAO.go + * @Software: GoLand + **/ +package AccountDAO + +import ( + "dsSupport/Utils/ConfigUtil" + "dsSupport/Utils/DbUtil" + "strings" +) + +//数据库 +var db = DbUtil.Engine + +func Login(username string, password string) (bool, string) { + var flag bool + var msg string + + if username != "" && password != ""{ + flag = false + msg = "账号或密码不能为空" + } + + if len(ConfigUtil.AccountUsers) > 0 { + for _, v := range ConfigUtil.AccountUsers { + UserPwd := strings.Split(v, ":") + if UserPwd[0] == username && UserPwd[1] == password { + flag = true + msg = "登陆成功" + } + } + } else { + flag = false + msg = "配置文件错误" + } + + return flag, msg +} + diff --git a/dsSupport/MyModel/Account/AccountOpenAPI/AccountOpenAPI.go b/dsSupport/MyModel/Account/AccountOpenAPI/AccountOpenAPI.go new file mode 100644 index 00000000..c2bbb8d9 --- /dev/null +++ b/dsSupport/MyModel/Account/AccountOpenAPI/AccountOpenAPI.go @@ -0,0 +1,62 @@ +/** + * @Title: + * @Description: + * @Author: Yuki Wong(iyuki0430@msn.com) + * @Update: + * @Date: 2020/7/20 11:50 + * @File: AccountOpenAPI.go + * @Software: GoLand + **/ +package AccountOpenAPI + +import ( + "dsSupport/MyModel/Account/AccountService" + "dsSupport/MyModel/MySwagger" + "github.com/gin-gonic/gin" + "net/http" +) + +// 后台登陆 godoc +// @Summary 后台登陆 +// @Description json:"username" xorm:"not null comment('账号') VARCHAR(100)" example:"example" +// @Description json:"password" xorm:"not null comment('密码') VARCHAR(100)" example:"123456" +// @Tags account +// @ID loginAccount +// @Accept json +// @Produce json +// @Param input body MySwagger.AccountSwag true "账号密码" +// @Success 200 {object} MySwagger.Result +// @Failure 400 {object} MySwagger.Result +// @Router /v1/openapi/datasource/ReadESDoc [post] +func Login(c *gin.Context) { + var raw MySwagger.AccountSwag + + if err := c.ShouldBindJSON(&raw); err != nil { + c.JSON(http.StatusBadRequest, MySwagger.Result{Success: false, Message: "接入系统数据JSON格式错误"}) + return + } + username := raw.Username + password := raw.Password + + success, _ := AccountService.Login(username, password) + + if success { + c.JSON(http.StatusOK, gin.H{ + "status" : "ok", + "type" : "account", + "currentAuthority" : username, + }) + + return + } else { + c.JSON(http.StatusOK, gin.H{ + "status" : "error", + "type" : "account", + "currentAuthority" : "guest", + }) + + return + } + + return +} diff --git a/dsSupport/MyModel/Account/AccountService/AccountService.go b/dsSupport/MyModel/Account/AccountService/AccountService.go new file mode 100644 index 00000000..429b9d1d --- /dev/null +++ b/dsSupport/MyModel/Account/AccountService/AccountService.go @@ -0,0 +1,21 @@ +/** + * @Title: + * @Description: + * @Author: Yuki Wong(iyuki0430@msn.com) + * @Update: + * @Date: 2020/7/20 11:50 + * @File: AccountService.go + * @Software: GoLand + **/ +package AccountService + +import ( + "dsSupport/MyModel/Account/AccountDAO" +) + +func Login(username string, password string) (bool, string) { + result, message := AccountDAO.Login(username, password) + + return result, message +} + diff --git a/dsSupport/MyModel/Login/LoginController/LoginController.go b/dsSupport/MyModel/Login/LoginController/LoginController.go index f76415a5..ac1ba41d 100644 --- a/dsSupport/MyModel/Login/LoginController/LoginController.go +++ b/dsSupport/MyModel/Login/LoginController/LoginController.go @@ -12,6 +12,7 @@ func Routers(r *gin.RouterGroup) { rr := r.Group("/login") //配置接口 rr.POST("/DoLogin", DoLogin) + return } diff --git a/dsSupport/MyModel/Login/LoginDao/LoginDao.go b/dsSupport/MyModel/Login/LoginDao/LoginDao.go index 58772185..a788509f 100644 --- a/dsSupport/MyModel/Login/LoginDao/LoginDao.go +++ b/dsSupport/MyModel/Login/LoginDao/LoginDao.go @@ -63,3 +63,4 @@ func Login(username string, password string) (bool, string, string, string, erro } } } + diff --git a/dsSupport/MyModel/MySwagger/AccountSwag.go b/dsSupport/MyModel/MySwagger/AccountSwag.go new file mode 100644 index 00000000..28b54a52 --- /dev/null +++ b/dsSupport/MyModel/MySwagger/AccountSwag.go @@ -0,0 +1,16 @@ +/** + * @Title: AccountSwag + * @Description: 后台登陆查询条件 + * @Author: Yuki Wong(iyuki0430@msn.com) + * @Update: + * @Date: 2020/7/9 10:24 + * @File: Jyt2012Swag.go + * @Software: GoLand + **/ +package MySwagger + +type AccountSwag struct { + Username string `json:"username" xorm:"not null comment('账号') VARCHAR(100)" example:"example"` + Password string `json:"password" xorm:"not null comment('密码') VARCHAR(100)" example:"123456"` +} + diff --git a/dsSupport/Utils/ConfigUtil/ConfigUtil.go b/dsSupport/Utils/ConfigUtil/ConfigUtil.go index 0102b1c2..86902eb3 100644 --- a/dsSupport/Utils/ConfigUtil/ConfigUtil.go +++ b/dsSupport/Utils/ConfigUtil/ConfigUtil.go @@ -47,12 +47,14 @@ var ( //ES Nodes 地址 ESNodes string - ESAddress []string //rpc服务IP和端口 RpcServerIp string RpcServerPort string + + AccountNodes string + AccountUsers []string ) func init() { @@ -117,6 +119,10 @@ func init() { RpcServerIp = iniParser.GetString("rpcServer", "ip") //rpc服务器的端口 RpcServerPort = iniParser.GetString("rpcServer", "port") + + // 数据中心后台登陆账号密码 + AccountNodes = iniParser.GetString("account", "users") + AccountUsers = strings.Split(AccountNodes, ",") } type IniParser struct { diff --git a/dsSupport/docs/docs.go b/dsSupport/docs/docs.go index 3d232511..067d94e8 100644 --- a/dsSupport/docs/docs.go +++ b/dsSupport/docs/docs.go @@ -1227,6 +1227,47 @@ var doc = `{ ] } }, + "/support/login/account": { + "post": { + "description": "json:\"datasource_name\" xorm:\"not null comment('数据源名称') VARCHAR(100)\" example:\"组织机构信息\"\njson:\"datasource_code\" xorm:\"not null comment('数据源编码') VARCHAR(8)\" example:\"org_tree\"", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "登录" + ], + "summary": "登录", + "operationId": "Account", + "parameters": [ + { + "description": "登录", + "name": "input", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/MySwagger.AccountSwag" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/MySwagger.Result" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/MySwagger.Result" + } + } + } + } + }, "/v1/openapi/dataaccess/CreateDataaccess": { "post": { "description": "` + "`" + `*` + "`" + `json:\"datasource_id\" xorm:\"not null comment('数据源ID') index VARCHAR(36)\" example:\"F38BD0DB-0142-4356-8F2B-623813FC2578\"\n` + "`" + `*` + "`" + `json:\"datasource_code\" xorm:\"comment('数据源编码') default 'NULL' VARCHAR(255)\"\n` + "`" + `*` + "`" + `json:\"` + "`" + `source_systemid` + "`" + `\" xorm:\"not null comment('源系统编码') index VARCHAR(36)\" example:\"F38BD0DB-0142-4356-8F2B-623813FC2578\"\n` + "`" + `*` + "`" + `json:\"` + "`" + `consume_systemid` + "`" + `\" xorm:\"not null comment('数据使用系统编码') index VARCHAR(36)\" example:\"F38BD0DB-0142-4356-8F2B-623813FC2578\"\njson:\"query_flag\" xorm:\"not null default 1 comment('可查【1:是,-1:否】') INT(11)\" example:\"1\"\njson:\"set_flag\" xorm:\"not null default -1 comment('可修改【1:是,-1:否】') INT(11)\" example:\"1\"\n` + "`" + `*` + "`" + `json:\"consume_type\" xorm:\"not null comment('使用数据范围【1:本机构,2:本机构以及下属机构,-1:不限制】') INT(11)\" example:\"-1\"\n` + "`" + `*` + "`" + `json:\"consume_orgid\" xorm:\"not null comment('使用数据机构ID【-1:不限制】') index VARCHAR(36)\" example:\"-1\"\njson:\"create_time\" xorm:\"default 'NULL' created comment('建立时间') DATETIME\" example:\"2020-06-22 17:26:53\"\njson:\"change_time\" xorm:\"default 'NULL' updated comment('最近修改时间') DATETIME\" example:\"2020-06-22 17:26:53\"\njson:\"delete_time\" xorm:\"default 'NULL' deleted comment('删除时间') DATETIME\" example:\"2020-06-22 17:26:53\"\njson:\"delete_flag\" xorm:\"not null default -1 comment('删除标志【默认-1,1:删除,-1:正常】') INT(11)\" example:\"1\"\njson:\"enable_flag\" xorm:\"not null default 1 comment('启用标志【默认1,1:启用,-1:禁用】') INT(11)\" example:\"1\"", @@ -2347,6 +2388,19 @@ var doc = `{ } } }, + "MySwagger.AccountSwag": { + "type": "object", + "properties": { + "password": { + "type": "string", + "example": "123456" + }, + "username": { + "type": "string", + "example": "example" + } + } + }, "MySwagger.DataaccessSwag": { "type": "object", "properties": { diff --git a/dsSupport/docs/swagger.json b/dsSupport/docs/swagger.json index a4893c12..4df5116b 100644 --- a/dsSupport/docs/swagger.json +++ b/dsSupport/docs/swagger.json @@ -1211,6 +1211,47 @@ ] } }, + "/support/login/account": { + "post": { + "description": "json:\"datasource_name\" xorm:\"not null comment('数据源名称') VARCHAR(100)\" example:\"组织机构信息\"\njson:\"datasource_code\" xorm:\"not null comment('数据源编码') VARCHAR(8)\" example:\"org_tree\"", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "登录" + ], + "summary": "登录", + "operationId": "Account", + "parameters": [ + { + "description": "登录", + "name": "input", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/MySwagger.AccountSwag" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/MySwagger.Result" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/MySwagger.Result" + } + } + } + } + }, "/v1/openapi/dataaccess/CreateDataaccess": { "post": { "description": "`*`json:\"datasource_id\" xorm:\"not null comment('数据源ID') index VARCHAR(36)\" example:\"F38BD0DB-0142-4356-8F2B-623813FC2578\"\n`*`json:\"datasource_code\" xorm:\"comment('数据源编码') default 'NULL' VARCHAR(255)\"\n`*`json:\"`source_systemid`\" xorm:\"not null comment('源系统编码') index VARCHAR(36)\" example:\"F38BD0DB-0142-4356-8F2B-623813FC2578\"\n`*`json:\"`consume_systemid`\" xorm:\"not null comment('数据使用系统编码') index VARCHAR(36)\" example:\"F38BD0DB-0142-4356-8F2B-623813FC2578\"\njson:\"query_flag\" xorm:\"not null default 1 comment('可查【1:是,-1:否】') INT(11)\" example:\"1\"\njson:\"set_flag\" xorm:\"not null default -1 comment('可修改【1:是,-1:否】') INT(11)\" example:\"1\"\n`*`json:\"consume_type\" xorm:\"not null comment('使用数据范围【1:本机构,2:本机构以及下属机构,-1:不限制】') INT(11)\" example:\"-1\"\n`*`json:\"consume_orgid\" xorm:\"not null comment('使用数据机构ID【-1:不限制】') index VARCHAR(36)\" example:\"-1\"\njson:\"create_time\" xorm:\"default 'NULL' created comment('建立时间') DATETIME\" example:\"2020-06-22 17:26:53\"\njson:\"change_time\" xorm:\"default 'NULL' updated comment('最近修改时间') DATETIME\" example:\"2020-06-22 17:26:53\"\njson:\"delete_time\" xorm:\"default 'NULL' deleted comment('删除时间') DATETIME\" example:\"2020-06-22 17:26:53\"\njson:\"delete_flag\" xorm:\"not null default -1 comment('删除标志【默认-1,1:删除,-1:正常】') INT(11)\" example:\"1\"\njson:\"enable_flag\" xorm:\"not null default 1 comment('启用标志【默认1,1:启用,-1:禁用】') INT(11)\" example:\"1\"", @@ -2331,6 +2372,19 @@ } } }, + "MySwagger.AccountSwag": { + "type": "object", + "properties": { + "password": { + "type": "string", + "example": "123456" + }, + "username": { + "type": "string", + "example": "example" + } + } + }, "MySwagger.DataaccessSwag": { "type": "object", "properties": { diff --git a/dsSupport/docs/swagger.yaml b/dsSupport/docs/swagger.yaml index 8ceee9fb..af68c59d 100644 --- a/dsSupport/docs/swagger.yaml +++ b/dsSupport/docs/swagger.yaml @@ -28,6 +28,15 @@ definitions: description: omitempty有值就输出,没值则不输出 type: object type: object + MySwagger.AccountSwag: + properties: + password: + example: "123456" + type: string + username: + example: example + type: string + type: object MySwagger.DataaccessSwag: properties: change_time: @@ -1116,6 +1125,35 @@ paths: - 2 x-tablename: - t_app_base + /support/login/account: + post: + consumes: + - application/json + description: |- + json:"datasource_name" xorm:"not null comment('数据源名称') VARCHAR(100)" example:"组织机构信息" + json:"datasource_code" xorm:"not null comment('数据源编码') VARCHAR(8)" example:"org_tree" + operationId: Account + parameters: + - description: 登录 + in: body + name: input + required: true + schema: + $ref: '#/definitions/MySwagger.AccountSwag' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/MySwagger.Result' + "400": + description: Bad Request + schema: + $ref: '#/definitions/MySwagger.Result' + summary: 登录 + tags: + - 登录 /v1/openapi/dataaccess/CreateDataaccess: post: consumes: diff --git a/dsSupport/main.go b/dsSupport/main.go index 5303bd8e..94882cc8 100644 --- a/dsSupport/main.go +++ b/dsSupport/main.go @@ -1,6 +1,7 @@ package main import ( + "dsSupport/MyModel/Account/AccountController" "dsSupport/MyModel/DataAccess/DataaccessController" "dsSupport/MyModel/DataError/DataerrorController" "dsSupport/MyModel/DataSource/DatasourceController" @@ -41,6 +42,8 @@ import ( // @tag.description 元数据 // @tag.name orgtree // @tag.description 机构目录 +// @tag.name account +// @tag.description 后台登陆 // @host 127.0.0.1:8005 func main() { // 发布模式 @@ -83,6 +86,9 @@ func main() { // 数据统计 DatastatisticController.Routers(rgroup) + // 后台登陆 + AccountController.Routers(rgroup) + //注册swagger r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))