Explorar el Código

增加“获取登录ID”接口

Simon Zhou hace 5 años
padre
commit
1e79489580
Se han modificado 6 ficheros con 190 adiciones y 5 borrados
  1. 58 0
      controllers/login/login.go
  2. 34 0
      docs/docs.go
  3. 34 0
      docs/swagger.json
  4. 22 0
      docs/swagger.yaml
  5. 30 0
      models/accountModels.go
  6. 12 5
      routers/router.go

+ 58 - 0
controllers/login/login.go

@@ -0,0 +1,58 @@
+package login
+
+import (
+	"fmt"
+	"mtp2_if/db"
+	"mtp2_if/global/app"
+	"mtp2_if/global/e"
+	"mtp2_if/logger"
+	"mtp2_if/models"
+	"net/http"
+
+	"github.com/gin-gonic/gin"
+)
+
+// GetLoginIDReq 获取登录ID请求参数
+type GetLoginIDReq struct {
+	UserName string `form:"username" binding:"required"`
+}
+
+// GetLoginID 获取登录ID
+// @Summary 获取登录ID
+// @Produce json
+// @Param username query string true "登录代码"
+// @Success 200 {object} app.Response
+// @Failure 500 {object} app.Response
+// @Router /Login/GetLoginID [get]
+// @Tags 登录
+func GetLoginID(c *gin.Context) {
+	appG := app.Gin{C: c}
+
+	// 获取请求参数
+	var req GetLoginIDReq
+	if err := appG.C.ShouldBindQuery(&req); err != nil {
+		logger.GetLogger().Errorf("QueryPreasleApply failed: %s", err.Error())
+		appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
+		return
+	}
+
+	// 查询数据
+	engine := db.GetEngine()
+	var loginaccount models.Loginaccount
+
+	loginid := req.UserName // 如果找不到,则直接把登录代码返回去
+	has, err := engine.Where("Logincode = ?", req.UserName).Get(&loginaccount)
+	if err != nil {
+		// 查询失败
+		logger.GetLogger().Errorf("GetLoginID failed: %s", err.Error())
+		appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
+		return
+	}
+	if has {
+		loginid = fmt.Sprintf("%v", loginaccount.Loginid)
+	}
+
+	// 查询成功
+	logger.GetLogger().Infof("GetLoginID successed: %v", loginaccount)
+	appG.Response(http.StatusOK, e.SUCCESS, loginid)
+}

+ 34 - 0
docs/docs.go

@@ -548,6 +548,40 @@ var doc = `{
                 }
             }
         },
+        "/Login/GetLoginID": {
+            "get": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "登录"
+                ],
+                "summary": "获取登录ID",
+                "parameters": [
+                    {
+                        "type": "string",
+                        "description": "登录代码",
+                        "name": "username",
+                        "in": "query",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    },
+                    "500": {
+                        "description": "Internal Server Error",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/WRTrade/GetAllDeliveryGoods": {
             "get": {
                 "security": [

+ 34 - 0
docs/swagger.json

@@ -532,6 +532,40 @@
                 }
             }
         },
+        "/Login/GetLoginID": {
+            "get": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "登录"
+                ],
+                "summary": "获取登录ID",
+                "parameters": [
+                    {
+                        "type": "string",
+                        "description": "登录代码",
+                        "name": "username",
+                        "in": "query",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    },
+                    "500": {
+                        "description": "Internal Server Error",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/WRTrade/GetAllDeliveryGoods": {
             "get": {
                 "security": [

+ 22 - 0
docs/swagger.yaml

@@ -1413,6 +1413,28 @@ paths:
       summary: 查询现货合同表信息(指定策略ID、未结束的)
       tags:
       - 风险管理
+  /Login/GetLoginID:
+    get:
+      parameters:
+      - description: 登录代码
+        in: query
+        name: username
+        required: true
+        type: string
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/app.Response'
+        "500":
+          description: Internal Server Error
+          schema:
+            $ref: '#/definitions/app.Response'
+      summary: 获取登录ID
+      tags:
+      - 登录
   /WRTrade/GetAllDeliveryGoods:
     get:
       produces:

+ 30 - 0
models/accountModels.go

@@ -0,0 +1,30 @@
+package models
+
+import "time"
+
+// Loginaccount 登录账户
+type Loginaccount struct {
+	Loginid         uint64    `json:"loginid"  xorm:"'LOGINID'" binding:"required"` // 登陆账号
+	Userid          uint64    `json:"userid"  xorm:"'USERID'"`                      // 用户ID
+	Loginfailnum    uint32    `json:"loginfailnum"  xorm:"'LOGINFAILNUM'"`          // 连续登录失败次数(登录成功时清零)
+	Password        string    `json:"password"  xorm:"'PASSWORD'"`                  // 登陆密码
+	Loginusertype   uint32    `json:"loginusertype"  xorm:"'LOGINUSERTYPE'"`        // 登录账号类型 - 1:投资者 2:机构交易员
+	Loginstatus     uint32    `json:"loginstatus"  xorm:"'LOGINSTATUS'"`            // 登录账号状态 1:正常 2:冻结 3:无效
+	Lastlogintime   time.Time `json:"lastlogintime"  xorm:"'LASTLOGINTIME'"`        // 最新登录时间
+	Lastloginmode   uint32    `json:"lastloginmode"  xorm:"'LASTLOGINMODE'"`        // 最新登录方式(客户端类型) -  0:保留为未填终端类型 1:PC管理端 2:PC交易端 3:手机客户端_安卓 4:网页客户端 5:微信客户端 6:手机客户端_苹果 7:网上开户客户端 8:无效终端编号 9:报价终端(中江)
+	Lastloginip     string    `json:"lastloginip"  xorm:"'LASTLOGINIP'"`            // 最新登录地址
+	Loginport       uint32    `json:"loginport"  xorm:"'LOGINPORT'"`                // 最新登录端口
+	Lastloginremark string    `json:"lastloginremark"  xorm:"'LASTLOGINREMARK'"`    // 最新登录描述
+	Modifytime      time.Time `json:"modifytime"  xorm:"'MODIFYTIME'"`              // 修改时间
+	Modifierid      uint64    `json:"modifierid"  xorm:"'MODIFIERID'"`              // 修改人
+	Pwdwrongcount   uint32    `json:"pwdwrongcount"  xorm:"'PWDWRONGCOUNT'"`        // 密码错误次数
+	Unfreezetime    time.Time `json:"unfreezetime"  xorm:"'UNFREEZETIME'"`          // 账户解冻时间
+	Haslogined      uint32    `json:"haslogined"  xorm:"'HASLOGINED'"`              // 是否已登录 - 0:未登录 1:已登录
+	Hasupdatedpwd   uint32    `json:"hasupdatedpwd"  xorm:"'HASUPDATEDPWD'"`        // 是否已更改密码 - 0:未修改 1:已修改
+	Logincode       string    `json:"logincode"  xorm:"'LOGINCODE'"`                // 登录代码
+}
+
+// TableName is LOGINACCOUNT
+func (Loginaccount) TableName() string {
+	return "LOGINACCOUNT"
+}

+ 12 - 5
routers/router.go

@@ -5,6 +5,7 @@ import (
 	"mtp2_if/controllers/cptrade"
 	"mtp2_if/controllers/delivery"
 	"mtp2_if/controllers/erms2"
+	"mtp2_if/controllers/login"
 	"mtp2_if/controllers/wrtrade"
 	"mtp2_if/logger"
 	"mtp2_if/token"
@@ -36,16 +37,22 @@ func InitRouter() *gin.Engine {
 
 	// 主业务路由分组
 	apiR := r.Group("/api")
-	apiR.Use(token.Auth())
+	// apiR.Use(token.Auth())
+	// ************************ 账号登录 ************************
+	loginR := apiR.Group("Login")
+	loginR.Use()
+	{
+		loginR.GET("/GetLoginID", login.GetLoginID)
+	}
 	// ************************ 仓单贸易 ************************
 	wrTradeR := apiR.Group("WRTrade")
-	wrTradeR.Use()
+	wrTradeR.Use(token.Auth())
 	{
 		wrTradeR.GET("/GetAllDeliveryGoods", wrtrade.GetAllDeliveryGoods)
 	}
 	// ************************ 产能预售 ************************
 	cpTradeR := apiR.Group("CPTrade")
-	cpTradeR.Use()
+	cpTradeR.Use(token.Auth())
 	{
 		// 查询产能预售申请表
 		cpTradeR.GET("/QueryPreasleApply", cptrade.QueryPreasleApply)
@@ -64,14 +71,14 @@ func InitRouter() *gin.Engine {
 	}
 	// ************************ 交割服务 ************************
 	deliveryR := apiR.Group("Delivery")
-	deliveryR.Use()
+	deliveryR.Use(token.Auth())
 	{
 		// 查询商品交割关系表
 		deliveryR.GET("/QueryDeliveryRelation", delivery.QueryDeliveryRelation)
 	}
 	// ************************ 风险管理 ************************
 	erms2R := apiR.Group("Erms2")
-	erms2R.Use()
+	erms2R.Use(token.Auth())
 	{
 		// 查询内部成交单信息
 		erms2R.GET("/QueryInnerTradeDetail", erms2.QueryInnerTradeDetail)