project_account_api.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * @description: 项目账号相关
  3. * @Author: CP
  4. * @Date: 2020-09-25 14:42:31
  5. * @FilePath: \construction_management\web\api\project_account_api.go
  6. */
  7. package api
  8. import (
  9. "fmt"
  10. "strconv"
  11. "github.com/dgrijalva/jwt-go"
  12. "github.com/kataras/iris/v12"
  13. "go.mod/comm"
  14. "go.mod/conf"
  15. "go.mod/services"
  16. )
  17. type ProjectAccountApi struct {
  18. //框架-web应用上下文环境
  19. Ctx iris.Context
  20. // 需要用的service
  21. ServiceProjectAccount services.ProjectAccountService
  22. }
  23. // @Summary 获得登陆账号信息相关
  24. // @Tags 项目账号相关
  25. // @Description 获得登陆账号相关信息
  26. // @Security ApiKeyAuth
  27. // @Success 200 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
  28. // @Router /api/projectAccount [get]
  29. func (c *ProjectAccountApi) Get() {
  30. // 获得项目账号ID
  31. // projectAccountIdInt, err := utils.GetProjectAccountId(c.Ctx)
  32. // if err != nil {
  33. // c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  34. // return
  35. // }
  36. userInfo := c.Ctx.Values().Get("jwt").(*jwt.Token).Claims.(jwt.MapClaims)
  37. accountId := userInfo["identity"].(string)
  38. aid, err := comm.AesDecrypt(accountId, conf.CookieSecret)
  39. id, err := strconv.Atoi(aid)
  40. // 获得项目ID
  41. // projectIdInt, err := utils.GetProjectId(c.Ctx)
  42. if err != nil {
  43. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  44. return
  45. }
  46. // 获得登陆用户
  47. AccountData := c.ServiceProjectAccount.Get(id)
  48. c.Ctx.JSON(iris.Map{
  49. "code": 0,
  50. "msg": "",
  51. "data": AccountData,
  52. })
  53. }