123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934 |
- package ctrl_v1
- import (
- "gd_management_gateway/consts"
- "gd_management_gateway/errors"
- "gd_management_gateway/params/param_base"
- "gd_management_gateway/params/param_v1_0"
- "gd_management_gateway/rpc_apis"
- "gd_management_gateway/rpc_apis/gd_admin"
- "fmt"
- "strconv"
- "time"
- "gd_management_gateway/common.in/cache"
- "gd_management_gateway/common.in/config"
- "gd_management_gateway/common.in/httper"
- "gd_management_gateway/common.in/jsonrpc2"
- "gd_management_gateway/common.in/task"
- "gd_management_gateway/common.in/utils"
- "github.com/astaxie/beego"
- "github.com/go-redis/redis"
- "go.uber.org/zap"
- )
- // Operations about admin api
- type BaseAdminController struct {
- metadata interface{} // 中继元数据
- beego.Controller
- LogID string
- }
- // @Title 管理用户添加
- // @Description 管理用户添加
- // @Param token header string true "token"
- // @Param uid header int64 true "admin id"
- // @Param body body params.param_v1_0.AddAdminBody true ""
- // @Success 200 {object} params.param_v1_0.AdminRegisterResp "响应信息"
- // @Failure 500 服务器错误
- // @router /admin [post]
- func (u *BaseAdminController) AdminRegister() {
- u.LogID = fmt.Sprintf("AdminRegister[%d]", time.Now().UnixNano())
- req := ¶m_v1_0.AdminRegisterReq{}
- getParamsTask := func() error {
- httper.FillRequireParams(u.Ctx, req, u.LogID)
- return nil
- }
- handleTokenCheck := func() error {
- uid, _, err := utils.ParseToken(req.Token)
- if err != nil {
- return err
- }
- if uid != req.Uid {
- return errors.UserTokenillegality
- }
- return nil
- }
- handleDataTask := func() error {
- mreq := gd_admin.AdminRegisterReq{
- AdminName: req.Body.AdminName,
- AdminPasswd: req.Body.AdminPasswd,
- AdminPhone: req.Body.AdminPhone,
- AdminEmail: req.Body.AdminEmail,
- GroupId: req.Body.GroupId,
- NodeId: req.Body.NodeId,
- }
- reply, err := rpc_apis.Admin.AdminRegister(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
- if err != nil {
- l.Error("rpc",
- zap.String("call", "AdminRegister"),
- zap.String("args", utils.MarshalJsonString(req)),
- zap.String("error", err.Error()))
- return errors.ErrorTransform(err)
- }
- resp := param_v1_0.AdminRegisterResp{
- SimpleResp: param_base.SimpleResp{
- Code: 0,
- Msg: "SUCCESS",
- },
- Data: reply,
- }
- httper.JSON(u.Ctx, resp, u.LogID)
- return nil
- }
- // 执行以上定义的任务
- task.Do(&task.PanicRecover{
- Ctx: u.Ctx,
- LogID: u.LogID}, u.Ctx,
- getParamsTask, handleTokenCheck, handleDataTask,
- )
- }
- // @Title 管理用户删除
- // @Description 管理用户删除
- // @Param token header string true "token"
- // @Param uid header int64 true "admin id"
- // @Param admin_id query int64 true "要删除的admin id"
- // @Success 200 {object} params.param_v1_0.AdminDeleteResp "响应信息"
- // @Failure 500 服务器错误
- // @router /admin [delete]
- func (u *BaseAdminController) AdminDelete() {
- u.LogID = fmt.Sprintf("AdminDelete[%d]", time.Now().UnixNano())
- req := ¶m_v1_0.AdminDeleteReq{}
- getParamsTask := func() error {
- httper.FillRequireParams(u.Ctx, req, u.LogID)
- return nil
- }
- handleTokenCheck := func() error {
- uid, _, err := utils.ParseToken(req.Token)
- if err != nil {
- return err
- }
- if uid != req.Uid {
- return errors.UserTokenillegality
- }
- return nil
- }
- handleDataTask := func() error {
- mreq := gd_admin.AdminDeleteReq{}
- mreq.AdminId = req.AdminId
- _, err := rpc_apis.Admin.AdminDelete(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
- if err != nil {
- l.Error("rpc",
- zap.String("call", "AdminDelete"),
- zap.String("args", utils.MarshalJsonString(req)),
- zap.String("error", err.Error()))
- return errors.ErrorTransform(err)
- }
- resp := param_v1_0.AdminDeleteResp{
- SimpleResp: param_base.SimpleResp{
- Code: 0,
- Msg: "SUCCESS",
- },
- }
- httper.JSON(u.Ctx, resp, u.LogID)
- return nil
- }
- // 执行以上定义的任务
- task.Do(&task.PanicRecover{
- Ctx: u.Ctx,
- LogID: u.LogID}, u.Ctx,
- getParamsTask, handleTokenCheck, handleDataTask,
- )
- }
- // @Title 管理用户信息修改
- // @Description 管理用户信息修改
- // @Param token header string true "token"
- // @Param uid header int64 true "admin id"
- // @Param body body params.param_v1_0.AdminModifyBody true
- // @Success 200 {object} params.param_v1_0.AdminModifyResp "响应信息"
- // @Failure 500 服务器错误
- // @router /admin [put]
- func (u *BaseAdminController) AdminModify() {
- u.LogID = fmt.Sprintf("AdminModify[%d]", time.Now().UnixNano())
- req := ¶m_v1_0.AdminModifyReq{}
- getParamsTask := func() error {
- httper.FillRequireParams(u.Ctx, req, u.LogID)
- return nil
- }
- checkPasswordTask := func() error {
- return utils.VerifyPassword(req.Body.AdminPasswd)
- }
- handleTokenCheck := func() error {
- uid, _, err := utils.ParseToken(req.Token)
- if err != nil {
- return err
- }
- if uid != req.Uid {
- return errors.UserTokenillegality
- }
- return nil
- }
- handleDataTask := func() error {
- mreq := gd_admin.AdminModifyReq{}
- mreq.AdminId = req.Body.AdminId
- mreq.AdminPasswd = req.Body.AdminPasswd
- mreq.AdminPhone = req.Body.AdminPhone
- mreq.AdminEmail = req.Body.AdminEmail
- mreq.GroupId = req.Body.GroupId
- mreq.NodeId = req.Body.NodeId
- _, err := rpc_apis.Admin.AdminModify(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
- if err != nil {
- l.Error("rpc",
- zap.String("call", "AdminModify"),
- zap.String("args", utils.MarshalJsonString(req)),
- zap.String("error", err.Error()))
- return errors.ErrorTransform(err)
- }
- resp := param_v1_0.AdminModifyResp{
- SimpleResp: param_base.SimpleResp{
- Code: 0,
- Msg: "SUCCESS",
- },
- }
- httper.JSON(u.Ctx, resp, u.LogID)
- return nil
- }
- // 执行以上定义的任务
- task.Do(&task.PanicRecover{
- Ctx: u.Ctx,
- LogID: u.LogID}, u.Ctx,
- getParamsTask, checkPasswordTask, handleTokenCheck, handleDataTask,
- )
- }
- // @Title 管理用户列表
- // @Description 管理用户列表
- // @Param token header string true "token"
- // @Param uid header int64 true "admin id"
- // @Param page_size query string false "页大小"
- // @Param page_number query int64 false "页号"
- // @Param search query string false "搜索"
- // @Success 200 {object} params.param_v1_0.AdminGetAllResp "响应信息"
- // @Failure 500 服务器错误
- // @router /list [get]
- func (u *BaseAdminController) GetAdminList() {
- u.LogID = fmt.Sprintf("GetAdminList[%d]", time.Now().UnixNano())
- req := ¶m_v1_0.AdminGetAllReq{}
- getParamsTask := func() error {
- httper.FillRequireParams(u.Ctx, req, u.LogID)
- return nil
- }
- handleTokenCheck := func() error {
- uid, _, err := utils.ParseToken(req.Token)
- if err != nil {
- return err
- }
- if uid != req.Uid {
- return errors.UserTokenillegality
- }
- return nil
- }
- handleDataTask := func() error {
- mreq := gd_admin.AdminGetAllReq{}
- mreq.PageSize = req.PageSize
- mreq.PageNumber = req.PageNumber
- mreq.Search = req.Search
- reply, err := rpc_apis.Admin.AdminGetAll(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
- mreq.PageSize = req.PageSize
- mreq.PageNumber = req.PageNumber
- if err != nil {
- l.Error("rpc",
- zap.String("call", "AdminGetAll"),
- zap.String("args", utils.MarshalJsonString(req)),
- zap.String("error", err.Error()))
- return errors.ErrorTransform(err)
- }
- resp := param_v1_0.AdminGetAllResp{
- SimpleResp: param_base.SimpleResp{
- Code: 0,
- Msg: "SUCCESS",
- },
- }
- resp.Data = reply
- httper.JSON(u.Ctx, resp, u.LogID)
- return nil
- }
- // 执行以上定义的任务
- task.Do(&task.PanicRecover{
- Ctx: u.Ctx,
- LogID: u.LogID}, u.Ctx,
- getParamsTask, handleTokenCheck, handleDataTask,
- )
- }
- // @Title 管理用户登录
- // @Description 管理用户登录
- // @Param body body params.param_v1_0.AdminLoginBody true ""
- // @Success 200 {string} json "{}" "响应信息"
- // @Failure 500 服务器错误
- // @router /login [put]
- func (u *BaseAdminController) AdminLogin() {
- u.LogID = fmt.Sprintf("AdminLogin[%d]", time.Now().UnixNano())
- req := ¶m_v1_0.AdminLoginReq{}
- getParamsTask := func() error {
- httper.FillRequireParams(u.Ctx, req, u.LogID)
- return nil
- }
- checkoutTask := func() error {
- // 检查账户是否被锁定
- ts, _ := config.Conf.Cgi.Gateway.AccountLockTimestamp.Int64()
- errorTimes, _ := config.Conf.Cgi.Gateway.AccountLockErrors.Int64()
- if ts == 0 || errorTimes == 0 {
- return nil
- }
- times, err := cache.Redis.Get(fmt.Sprintf(consts.AccountLock, req.Body.AdminName))
- if err == nil {
- t, _ := strconv.Atoi(times)
- if t >= int(errorTimes) {
- return jsonrpc2.NewJsonError(201111, "账号登录频繁,请"+config.Conf.Cgi.Gateway.AccountLockTimestamp.String()+"秒后再试")
- }
- }
- return nil
- }
- checkPasswordTask := func() error {
- return utils.VerifyPassword(req.Body.AdminPasswd)
- }
- handleDataTask := func() error {
- mreq := gd_admin.AdminLoginReq{}
- mreq.AdminName = req.Body.AdminName
- mreq.AdminPasswd = req.Body.AdminPasswd
- reply, err := rpc_apis.Admin.AdminLogin(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
- if err != nil {
- l.Error("rpc",
- zap.String("call", "AdminLogin"),
- zap.String("args", utils.MarshalJsonString(req)),
- zap.String("error", err.Error()))
- // 发生错误锁定账户
- ts, _ := config.Conf.Cgi.Gateway.AccountLockTimestamp.Int64()
- errorTimes, _ := config.Conf.Cgi.Gateway.AccountLockErrors.Int64()
- if ts > 0 && errorTimes > 0 {
- key := fmt.Sprintf(consts.AccountLock, req.Body.AdminName)
- _, err := cache.Redis.Get(key)
- if err == redis.Nil {
- // 不存在
- cache.Redis.SetEx(key, ts, 1)
- } else {
- // 存在
- cache.Redis.IncrBy(key, 1)
- }
- }
- return errors.ErrorTransform(err)
- }
- resp := param_v1_0.AdminLoginResp{
- SimpleResp: param_base.SimpleResp{
- Code: 0,
- Msg: "SUCCESS",
- },
- }
- resp.Data = reply
- resp.Data.Token, err = utils.ProductToken(reply.AdminId, reply.Level,mreq.AdminName)
- if err != nil {
- return err
- }
- httper.JSON(u.Ctx, resp, u.LogID)
- return nil
- }
- // 执行以上定义的任务
- task.Do(&task.PanicRecover{
- Ctx: u.Ctx,
- LogID: u.LogID}, u.Ctx,
- getParamsTask, checkPasswordTask, checkoutTask, handleDataTask,
- )
- }
- // @Title 获取用户权限
- // @Description 获取用户权限
- // @Param token header string true "token"
- // @Param uid header int64 true "admin id"
- // @Success 200 {object} params.param_v1_0.GetAccessResp "响应信息"
- // @Failure 500 服务器错误
- // @router /access [get]
- func (u *BaseAdminController) GetAccess() {
- u.LogID = fmt.Sprintf("GetAccess[%d]", time.Now().UnixNano())
- req := ¶m_v1_0.GetAccessReq{}
- getParamsTask := func() error {
- httper.FillRequireParams(u.Ctx, req, u.LogID)
- return nil
- }
- handleTokenCheck := func() error {
- uid, _, err := utils.ParseToken(req.Token)
- if err != nil {
- return err
- }
- if uid != req.Uid {
- return errors.UserTokenillegality
- }
- return nil
- }
- handleDataTask := func() error {
- mreq := gd_admin.GetAccessReq{
- Uid: req.Uid,
- }
- reply, err := rpc_apis.Admin.GetRbacAccess(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
- if err != nil {
- l.Error("rpc",
- zap.String("call", "GetRbacAccess"),
- zap.String("args", utils.MarshalJsonString(req)),
- zap.String("error", err.Error()))
- return errors.ErrorTransform(err)
- }
- resp := param_v1_0.GetAccessResp{
- SimpleResp: param_base.SimpleResp{
- Code: 0,
- Msg: "SUCCESS",
- },
- }
- resp.Data = reply
- httper.JSON(u.Ctx, resp, u.LogID)
- return nil
- }
- // 执行以上定义的任务
- task.Do(&task.PanicRecover{
- Ctx: u.Ctx,
- LogID: u.LogID}, u.Ctx,
- getParamsTask, handleTokenCheck, handleDataTask,
- )
- }
- // @Title 获取权限分组信息
- // @Description 获取权限分组信息
- // @Param token header string true "token"
- // @Param uid header int64 true "admin id"
- // @Success 200 {object} params.param_v1_0.GetRbacGroupListResp "响应信息"
- // @Failure 500 服务器错误
- // @router /rbac_group_list [get]
- func (u *BaseAdminController) GetRbacGroupList() {
- u.LogID = fmt.Sprintf("GetRbacGroupList[%d]", time.Now().UnixNano())
- req := ¶m_v1_0.GetRbacGroupListReq{}
- getParamsTask := func() error {
- httper.FillRequireParams(u.Ctx, req, u.LogID)
- return nil
- }
- handleTokenCheck := func() error {
- uid, _, err := utils.ParseToken(req.Token)
- if err != nil {
- return err
- }
- if uid != req.Uid {
- return errors.UserTokenillegality
- }
- return nil
- }
- handleDataTask := func() error {
- mreq := gd_admin.GetRbacGroupListReq{}
- reply, err := rpc_apis.Admin.GetRbacGroupList(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
- if err != nil {
- l.Error("rpc",
- zap.String("call", "GetRbacGroupList"),
- zap.String("args", utils.MarshalJsonString(req)),
- zap.String("error", err.Error()))
- return errors.ErrorTransform(err)
- }
- resp := param_v1_0.GetRbacGroupListResp{
- SimpleResp: param_base.SimpleResp{
- Code: 0,
- Msg: "SUCCESS",
- },
- }
- resp.Data = reply
- httper.JSON(u.Ctx, resp, u.LogID)
- return nil
- }
- // 执行以上定义的任务
- task.Do(&task.PanicRecover{
- Ctx: u.Ctx,
- LogID: u.LogID}, u.Ctx,
- getParamsTask, handleTokenCheck, handleDataTask,
- )
- }
- // @Title 更新权限分组
- // @Description 更新权限分组
- // @Param token header string true "token"
- // @Param uid header int64 true "admin id"
- // @Param body body params.param_v1_0.UpdateRbacGroup true "body"
- // @Success 200 {object} params.param_v1_0.UpdateRbacGroupResp "响应信息"
- // @Failure 500 服务器错误
- // @router /rbac_group [put]
- func (u *BaseAdminController) UpdateRbacGroup() {
- u.LogID = fmt.Sprintf("UpdateRbacGroup[%d]", time.Now().UnixNano())
- req := ¶m_v1_0.UpdateRbacGroupReq{}
- getParamsTask := func() error {
- httper.FillRequireParams(u.Ctx, req, u.LogID)
- return nil
- }
- handleTokenCheck := func() error {
- uid, _, err := utils.ParseToken(req.Token)
- if err != nil {
- return err
- }
- if uid != req.Uid {
- return errors.UserTokenillegality
- }
- return nil
- }
- handleDataTask := func() error {
- mreq := gd_admin.UpdateRbacGroupReq{
- Id: req.Body.Id,
- Name: req.Body.Name,
- NodeId: req.Body.NodeId,
- }
- _, err := rpc_apis.Admin.UpdateRbacGroup(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
- if err != nil {
- l.Error("rpc",
- zap.String("call", "UpdateRbacGroup"),
- zap.String("args", utils.MarshalJsonString(req)),
- zap.String("error", err.Error()))
- return errors.ErrorTransform(err)
- }
- resp := param_v1_0.UpdateRbacGroupResp{
- SimpleResp: param_base.SimpleResp{
- Code: 0,
- Msg: "SUCCESS",
- },
- }
- httper.JSON(u.Ctx, resp, u.LogID)
- return nil
- }
- // 执行以上定义的任务
- task.Do(&task.PanicRecover{
- Ctx: u.Ctx,
- LogID: u.LogID}, u.Ctx,
- getParamsTask, handleTokenCheck, handleDataTask,
- )
- }
- // @Title 删除权限分组
- // @Description 删除权限分组
- // @Param token header string true "token"
- // @Param uid header int64 true "admin id"
- // @Param id query int true "id"
- // @Success 200 {object} params.param_v1_0.DeleteRbacGroupResp "响应信息"
- // @Failure 500 服务器错误
- // @router /rbac_group [delete]
- func (u *BaseAdminController) DeleteRbacGroup() {
- u.LogID = fmt.Sprintf("DeleteRbacGroup[%d]", time.Now().UnixNano())
- req := ¶m_v1_0.DeleteRbacGroupReq{}
- getParamsTask := func() error {
- httper.FillRequireParams(u.Ctx, req, u.LogID)
- return nil
- }
- handleTokenCheck := func() error {
- uid, _, err := utils.ParseToken(req.Token)
- if err != nil {
- return err
- }
- if uid != req.Uid {
- return errors.UserTokenillegality
- }
- return nil
- }
- handleDataTask := func() error {
- mreq := gd_admin.DeleteRbacGroupReq{
- Id: req.Id,
- }
- _, err := rpc_apis.Admin.DeleteRbacGroup(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
- if err != nil {
- l.Error("rpc",
- zap.String("call", "DeleteRbacGroup"),
- zap.String("args", utils.MarshalJsonString(req)),
- zap.String("error", err.Error()))
- return errors.ErrorTransform(err)
- }
- resp := param_v1_0.DeleteRbacGroupResp{
- SimpleResp: param_base.SimpleResp{
- Code: 0,
- Msg: "SUCCESS",
- },
- }
- httper.JSON(u.Ctx, resp, u.LogID)
- return nil
- }
- // 执行以上定义的任务
- task.Do(&task.PanicRecover{
- Ctx: u.Ctx,
- LogID: u.LogID}, u.Ctx,
- getParamsTask, handleTokenCheck, handleDataTask,
- )
- }
- // @Title 添加权限分组
- // @Description 添加权限分组
- // @Param token header string true "token"
- // @Param uid header int64 true "admin id"
- // @Param body body params.param_v1_0.UpdateRbacGroup true "body"
- // @Success 200 {object} params.param_v1_0.AddRbacGroupResp "响应信息"
- // @Failure 500 服务器错误
- // @router /rbac_group [post]
- func (u *BaseAdminController) AddRbacGroup() {
- u.LogID = fmt.Sprintf("AddRbacGroup[%d]", time.Now().UnixNano())
- req := ¶m_v1_0.AddRbacGroupReq{}
- getParamsTask := func() error {
- httper.FillRequireParams(u.Ctx, req, u.LogID)
- return nil
- }
- handleTokenCheck := func() error {
- uid, _, err := utils.ParseToken(req.Token)
- if err != nil {
- return err
- }
- if uid != req.Uid {
- return errors.UserTokenillegality
- }
- return nil
- }
- handleDataTask := func() error {
- mreq := gd_admin.AddRbacGroupReq{
- Name: req.Body.Name,
- NodeId: req.Body.NodeId,
- }
- _, err := rpc_apis.Admin.AddRbacGroup(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
- if err != nil {
- l.Error("rpc",
- zap.String("call", "AddRbacGroup"),
- zap.String("args", utils.MarshalJsonString(req)),
- zap.String("error", err.Error()))
- return errors.ErrorTransform(err)
- }
- resp := param_v1_0.AddRbacGroupResp{
- SimpleResp: param_base.SimpleResp{
- Code: 0,
- Msg: "SUCCESS",
- },
- }
- httper.JSON(u.Ctx, resp, u.LogID)
- return nil
- }
- // 执行以上定义的任务
- task.Do(&task.PanicRecover{
- Ctx: u.Ctx,
- LogID: u.LogID}, u.Ctx,
- getParamsTask, handleTokenCheck, handleDataTask,
- )
- }
- // @Title 获取所有的节点列表
- // @Description 获取所有的节点列表
- // @Param token header string true "token"
- // @Param uid header int64 true "admin id"
- // @Success 200 {object} params.param_v1_0.GetNodeListResp "响应信息"
- // @Failure 500 服务器错误
- // @router /node_list [get]
- func (u *BaseAdminController) GetNodeList() {
- u.LogID = fmt.Sprintf("GetNodeList[%d]", time.Now().UnixNano())
- req := ¶m_v1_0.GetNodeListReq{}
- getParamsTask := func() error {
- httper.FillRequireParams(u.Ctx, req, u.LogID)
- return nil
- }
- handleTokenCheck := func() error {
- uid, _, err := utils.ParseToken(req.Token)
- if err != nil {
- return err
- }
- if uid != req.Uid {
- return errors.UserTokenillegality
- }
- return nil
- }
- handleDataTask := func() error {
- mreq := gd_admin.GetNodeListReq{}
- reply, err := rpc_apis.Admin.GetNodeList(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
- if err != nil {
- l.Error("rpc",
- zap.String("call", "GetNodeList"),
- zap.String("args", utils.MarshalJsonString(req)),
- zap.String("error", err.Error()))
- return errors.ErrorTransform(err)
- }
- resp := param_v1_0.GetNodeListResp{
- SimpleResp: param_base.SimpleResp{
- Code: 0,
- Msg: "SUCCESS",
- },
- }
- resp.List = reply
- httper.JSON(u.Ctx, resp, u.LogID)
- return nil
- }
- // 执行以上定义的任务
- task.Do(&task.PanicRecover{
- Ctx: u.Ctx,
- LogID: u.LogID}, u.Ctx,
- getParamsTask, handleTokenCheck, handleDataTask,
- )
- }
- // @Title 修改管理用户状态
- // @Description 修改管理用户状态
- // @Param token header string true "token"
- // @Param uid header int64 true "admin id"
- // @Param body body param_base.param_v1_0.UpdateStatusBody true ""
- // @Success 200 {object} params.param_v1_0.UpdateStatusResp "响应信息"
- // @Failure 500 服务器错误
- // @router /status [put]
- func (u *BaseAdminController) UpdateStatus() {
- u.LogID = fmt.Sprintf("AdminModify[%d]", time.Now().UnixNano())
- req := ¶m_v1_0.UpdateStatusReq{}
- getParamsTask := func() error {
- httper.FillRequireParams(u.Ctx, req, u.LogID)
- return nil
- }
- handleTokenCheck := func() error {
- uid, _, err := utils.ParseToken(req.Token)
- if err != nil {
- return err
- }
- if uid != req.Uid {
- return errors.UserTokenillegality
- }
- return nil
- }
- handleDataTask := func() error {
- mreq := gd_admin.UpdateStatusReq{}
- mreq.AdminId = req.Body.AdminId
- reply, err := rpc_apis.Admin.UpdateAdminStatus(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
- if err != nil {
- l.Error("rpc",
- zap.String("call", "UpdateAdminStatus"),
- zap.String("args", utils.MarshalJsonString(req)),
- zap.String("error", err.Error()))
- return errors.ErrorTransform(err)
- }
- resp := param_v1_0.UpdateStatusResp{
- SimpleResp: param_base.SimpleResp{
- Code: 0,
- Msg: "SUCCESS",
- },
- Data: reply,
- }
- httper.JSON(u.Ctx, resp, u.LogID)
- return nil
- }
- // 执行以上定义的任务
- task.Do(&task.PanicRecover{
- Ctx: u.Ctx,
- LogID: u.LogID}, u.Ctx,
- getParamsTask, handleTokenCheck, handleDataTask,
- )
- }
- // @Title 管理用户状态
- // @Description 管理用户状态
- // @Param token header string true "token"
- // @Param uid header int64 true "admin id"
- // @param admin_id query int64 true "user_id"
- // @Success 200 {object} params.param_v1_0.GetInfoResp "响应信息"
- // @Failure 500 服务器错误
- // @router /info [get]
- func (u *BaseAdminController) GetInfo() {
- u.LogID = fmt.Sprintf("GetInfo[%d]", time.Now().UnixNano())
- req := ¶m_v1_0.GetInfoReq{}
- getParamsTask := func() error {
- httper.FillRequireParams(u.Ctx, req, u.LogID)
- return nil
- }
- handleTokenCheck := func() error {
- uid, _, err := utils.ParseToken(req.Token)
- if err != nil {
- return err
- }
- if uid != req.Uid {
- return errors.UserTokenillegality
- }
- return nil
- }
- handleDataTask := func() error {
- mreq := gd_admin.GetInfoReq{}
- mreq.Uid = req.AdminId
- reply, err := rpc_apis.Admin.GetInfo(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
- if err != nil {
- l.Error("rpc",
- zap.String("call", "GetInfo"),
- zap.String("args", utils.MarshalJsonString(req)),
- zap.String("error", err.Error()))
- return errors.ErrorTransform(err)
- }
- resp := param_v1_0.GetInfoResp{
- SimpleResp: param_base.SimpleResp{
- Code: 0,
- Msg: "SUCCESS",
- },
- Data: reply,
- }
- httper.JSON(u.Ctx, resp, u.LogID)
- return nil
- }
- // 执行以上定义的任务
- task.Do(&task.PanicRecover{
- Ctx: u.Ctx,
- LogID: u.LogID}, u.Ctx,
- getParamsTask, handleTokenCheck, handleDataTask,
- )
- }
- // @Title token check
- // @Description token验证
- // @Param token header string true "token"
- // @Param uid header int64 true "admin id"
- // @Success 200 {object} params.param_v1_0.AdminTokenVerifyResp "响应信息"
- // @Failure 500 服务器错误
- // @router /token_verify [get]
- func (u *BaseAdminController) AdminTokenVerify() {
- u.LogID = fmt.Sprintf("AdminRegister[%d]", time.Now().UnixNano())
- req := ¶m_v1_0.AdminTokenVerifyReq{}
- getParamsTask := func() error {
- httper.FillRequireParams(u.Ctx, req, u.LogID)
- return nil
- }
- adminId := int64(0)
- handleTokenCheck := func() error {
- uid, _, err := utils.ParseToken(req.Token)
- if err != nil {
- return err
- }
- if uid != req.Uid {
- return errors.UserTokenillegality
- }
- adminId = uid
- return nil
- }
- handleDataTask := func() error {
- mreq := gd_admin.AdminLoginReq{}
- mreq.Uid = adminId
- fmt.Println(req)
- reply, err := rpc_apis.Admin.AdminLogin(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
- if err != nil {
- l.Error("rpc",
- zap.String("call", "AdminLogin"),
- zap.String("args", utils.MarshalJsonString(req)),
- zap.String("error", err.Error()))
- return errors.ErrorTransform(err)
- }
- resp := param_v1_0.AdminTokenVerifyResp{
- SimpleResp: param_base.SimpleResp{
- Code: 0,
- Msg: "SUCCESS",
- },
- }
- resp.Data = reply
- resp.Data.Token = req.Token
- httper.JSON(u.Ctx, resp, u.LogID)
- return nil
- }
- // 执行以上定义的任务
- task.Do(&task.PanicRecover{
- Ctx: u.Ctx,
- LogID: u.LogID}, u.Ctx,
- getParamsTask, handleTokenCheck, handleDataTask,
- )
- }
|