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 := &param_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 := &param_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 := &param_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 := &param_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 := &param_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 := &param_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 := &param_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 := &param_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 := &param_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 := &param_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 := &param_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 := &param_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 := &param_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 := &param_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,
	)
}
