1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- package gn
- import (
- "eta_gn/eta_bridge/controller/resp"
- "eta_gn/eta_bridge/global"
- "eta_gn/eta_bridge/logic/gn"
- gnRequest "eta_gn/eta_bridge/models/request/gn"
- "fmt"
- "github.com/gin-gonic/gin"
- "github.com/go-playground/validator/v10"
- )
- // GuoNengController 国能
- type GuoNengController struct{}
- func (gc *GuoNengController) GetToken(c *gin.Context) {
- var req gnRequest.GetTokenReq
- if e := c.Bind(&req); e != nil {
- err, ok := e.(validator.ValidationErrors)
- if !ok {
- resp.FailData("参数解析失败", "Err:"+e.Error(), c)
- return
- }
- resp.FailData("参数解析失败", err.Translate(global.Trans), c)
- return
- }
- if req.Code == "" {
- resp.FailMsg("请传入code码", "请输入指标code码", c)
- return
- }
- result, err, errMsg := gn.LoginEta(req.Code)
- if err != nil {
- fmt.Printf("获取失败, Err: %v, ErrMsg: %s", err, errMsg)
- resp.FailData(errMsg, err.Error(), c)
- return
- }
- resp.OkData("获取成功", result, c)
- }
- // GetUserInfo
- // @Description: 根据sci的token获取用户信息
- // @author: Roc
- // @receiver gc
- // @datetime 2024-10-30 10:11:51
- // @param c *gin.Context
- func (gc *GuoNengController) GetUserInfo(c *gin.Context) {
- var req gnRequest.GetUserInfoReq
- if e := c.Bind(&req); e != nil {
- err, ok := e.(validator.ValidationErrors)
- if !ok {
- resp.FailData("参数解析失败", "Err:"+e.Error(), c)
- return
- }
- resp.FailData("参数解析失败", err.Translate(global.Trans), c)
- return
- }
- if req.Token == "" {
- resp.FailMsg("请传入token", "请传入token", c)
- return
- }
- // 根据token在卓创这边获取用户信息
- result, err, errMsg := gn.GetUserInfoByToken(req.Token)
- if err != nil {
- fmt.Printf("获取失败, Err: %v, ErrMsg: %s", err, errMsg)
- resp.FailData(errMsg, err.Error(), c)
- return
- }
- resp.OkData("获取成功", result, c)
- }
|