project_account_api.go 3.0 KB

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