project_account_api.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. "github.com/kataras/iris/v12"
  11. "go.mod/services"
  12. "go.mod/web/utils"
  13. )
  14. type ProjectAccountApi struct {
  15. //框架-web应用上下文环境
  16. Ctx iris.Context
  17. // 需要用的service
  18. ServiceProjectAccount services.ProjectAccountService
  19. }
  20. // @Summary 获得登陆账号信息相关
  21. // @Tags 项目账号相关
  22. // @Description 获得登陆账号相关信息
  23. // @Security ApiKeyAuth
  24. // @Success 200 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
  25. // @Router /api/projectAccount [get]
  26. func (c *ProjectAccountApi) Get() {
  27. // 获得项目账号ID
  28. projectAccountIdInt, err := utils.GetProjectAccountId(c.Ctx)
  29. if err != nil {
  30. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  31. return
  32. }
  33. // 获得项目ID
  34. projectIdInt, err := utils.GetProjectId(c.Ctx)
  35. if err != nil {
  36. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  37. return
  38. }
  39. // 获得登陆用户
  40. AccountData := c.ServiceProjectAccount.Get(projectAccountIdInt, projectIdInt)
  41. c.Ctx.JSON(iris.Map{
  42. "code": 0,
  43. "msg": "",
  44. "data": AccountData,
  45. })
  46. }
  47. // @Summary 获得项目账号列表
  48. // @Tags 项目账号相关
  49. // @Description 获得项目账号列表
  50. // @Security ApiKeyAuth
  51. // @Success 200 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
  52. // @Router /api/projectAccount/list [get]
  53. func (c *ProjectAccountApi) GetList() {
  54. // 获得项目ID
  55. projectIdInt, err := utils.GetProjectId(c.Ctx)
  56. if err != nil {
  57. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  58. return
  59. }
  60. AccountData := c.ServiceProjectAccount.GetAll(projectIdInt)
  61. c.Ctx.JSON(iris.Map{
  62. "code": 0,
  63. "msg": "",
  64. "data": AccountData,
  65. })
  66. }
  67. // @Summary 获得项目账号角色列表
  68. // @Tags 项目账号相关
  69. // @Description 获得项目账号角色列表
  70. // @Security ApiKeyAuth
  71. // @Success 200 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
  72. // @Router /api/projectAccount/role [get]
  73. func (c *ProjectAccountApi) GetRole() {
  74. // 获得项目ID
  75. projectId, err := utils.GetProjectId(c.Ctx)
  76. if err != nil {
  77. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  78. return
  79. }
  80. accountData := c.ServiceProjectAccount.GetAll(projectId)
  81. roleDate := map[int]string{
  82. 1: "建设单位",
  83. 2: "监理单位",
  84. 3: "施工单位",
  85. 4: "设计单位",
  86. }
  87. c.Ctx.JSON(iris.Map{
  88. "code": 0,
  89. "msg": "",
  90. "roleDate": roleDate,
  91. "accountData": accountData,
  92. })
  93. }