project_account_api.go 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. roleDate := map[int]string{
  75. 1: "建设单位",
  76. 2: "监理单位",
  77. 3: "施工单位",
  78. 4: "设计单位",
  79. }
  80. c.Ctx.JSON(iris.Map{
  81. "code": 0,
  82. "msg": "",
  83. "data": roleDate,
  84. })
  85. }