project_setting_auth_api.go 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /*
  2. * @description:项目设置-权限管理
  3. * @Author: CP
  4. * @Date: 2020-10-20 15:47:07
  5. * @FilePath: \construction_management\web\api\project_setting_auth_api.go
  6. */
  7. package api
  8. import (
  9. "fmt"
  10. "github.com/kataras/iris/v12"
  11. "go.mod/web/utils"
  12. "go.mod/web/viewmodels"
  13. )
  14. // @Summary 获得标段账号
  15. // @Tags 项目设置-标段成员权限-管理员
  16. // @Description 获得标段账号
  17. // @Accept json
  18. // @Produce json
  19. // @Security ApiKeyAuth
  20. // @Param bidsectionId path string false "标段ID"
  21. // @Success 200 {object} viewmodels.ProjectAccount "{code:0成功,-1参数类错误,data:viewmodels.ProjectAccount,msg:错误信息}"
  22. // @Router /api/projectSetting/bid/account [get]
  23. func (c *ProjectSettingApi) GetBidAccount() {
  24. // 获得标段ID
  25. TreeData := viewmodels.Tree{}
  26. err := c.Ctx.ReadForm(&TreeData)
  27. if err != nil {
  28. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  29. return
  30. }
  31. if TreeData.BidsectionId == "" {
  32. c.Ctx.JSON(iris.Map{"code": -1, "msg": "标段ID不能为空"})
  33. return
  34. }
  35. // 解密标段ID
  36. bidsectionId, err := utils.GetDecryptId(TreeData.BidsectionId)
  37. if err != nil {
  38. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  39. return
  40. }
  41. // 获得项目ID
  42. projectIdInt, err := utils.GetProjectId(c.Ctx)
  43. if err != nil {
  44. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  45. return
  46. }
  47. // 获得项目账号ID
  48. projectAccountIdInt, err := utils.GetProjectAccountId(c.Ctx)
  49. if err != nil {
  50. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  51. return
  52. }
  53. dataList := c.ServiceProjectAccount.GetBidAccount(bidsectionId, projectIdInt, projectAccountIdInt)
  54. c.Ctx.JSON(iris.Map{
  55. "code": 0,
  56. "msg": "",
  57. "data": dataList,
  58. })
  59. }
  60. // @Summary 标段中添加成员-账号
  61. // @Tags 项目设置-标段成员权限-管理员
  62. // @Description 标段中添加成员-账号
  63. // @Accept json
  64. // @Produce json
  65. // @Security ApiKeyAuth
  66. // @Param bidsectionId body string false "标段ID"
  67. // @Param accountId body string false "账号ID"
  68. // @Success 200 {string} string "{code:0成功,-1参数类错误,data:viewmodels.ProjectAccount,msg:错误信息}"
  69. // @Router /api/projectSetting/bid/account/create [post]
  70. func (c *ProjectSettingApi) PostBidAccountCreate() {
  71. // 账号ID,标段ID,目录ID
  72. BidAccountData, err := c.ServiceBidAccount.ValidRule(c.Ctx)
  73. if err != nil {
  74. c.Ctx.JSON(iris.Map{"code": -1, "msg": utils.FormValidError(err)})
  75. return
  76. }
  77. // 获得项目ID
  78. projectIdInt, err := utils.GetProjectId(c.Ctx)
  79. if err != nil {
  80. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  81. return
  82. }
  83. // 创建标段和账号的关系
  84. err = c.ServiceBidAccount.Create(BidAccountData, projectIdInt)
  85. if err != nil {
  86. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  87. return
  88. }
  89. c.Ctx.JSON(iris.Map{
  90. "code": 0,
  91. "msg": "新增成功",
  92. })
  93. }
  94. // @Summary 设置成员权限
  95. // @Tags 项目设置-标段成员权限-管理员
  96. // @Description 设置成员权限
  97. // @Accept json
  98. // @Produce json
  99. // @Security ApiKeyAuth
  100. // @Param bidsectionId body string false "标段ID"
  101. // @Param accountId body string false "账号ID"
  102. // @Param contractAdd body int false "合同创建 1拥有0不拥有"
  103. // @Param contractDelete body int false "合同删除 1拥有0不拥有"
  104. // @Param contractAccess body int false "合同查看 1拥有0不拥有"
  105. // @Param safeAdd body int false "安全创建 1拥有0不拥有"
  106. // @Param safeDelete body int false "安全删除 1拥有0不拥有"
  107. // @Param safeAccess body int false "安全查看 1拥有0不拥有"
  108. // @Param qualityAdd body int false "合同创建 1拥有0不拥有"
  109. // @Param qualityDelete body int false "合同删除 1拥有0不拥有"
  110. // @Param qualityAccess body int false "合同查看 1拥有0不拥有"
  111. // @Success 200 {string} string "{code:0成功,-1参数类错误,data:viewmodels.ProjectAccount,msg:错误信息}"
  112. // @Router /api/projectSetting/bid/account/auth [post]
  113. func (c *ProjectSettingApi) PostBidAccountAuth() {
  114. // 1.验证消息
  115. PermissionData, err := c.ServiceProjectAccount.ValidRulePermission(c.Ctx)
  116. // 获得项目ID
  117. projectId, err := utils.GetProjectId(c.Ctx)
  118. if err != nil {
  119. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  120. return
  121. }
  122. // 账号ID
  123. accountId, err := utils.GetDecryptId(PermissionData.AccountId)
  124. if err != nil {
  125. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  126. return
  127. }
  128. // 保存设置的权限
  129. err = c.ServiceProjectAccount.SaveAuth(PermissionData, projectId, accountId)
  130. if err != nil {
  131. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  132. return
  133. }
  134. c.Ctx.JSON(iris.Map{
  135. "code": 0,
  136. "msg": "设置成功",
  137. })
  138. }
  139. // @Summary 移除标段成员-账号
  140. // @Tags 项目设置-标段成员权限-管理员
  141. // @Description 移除标段成员-账号
  142. // @Accept json
  143. // @Produce json
  144. // @Security ApiKeyAuth
  145. // @Param bidsectionId body string false "标段ID"
  146. // @Param accountId body string false "账号ID"
  147. // @Success 200 {string} string "{code:0成功,-1参数类错误,data:viewmodels.ProjectAccount,msg:错误信息}"
  148. // @Router /api/projectSetting/bid/account [delete]
  149. func (c *ProjectSettingApi) DeleteBidAccount() {
  150. // 账号ID,标段ID
  151. BidAccountData, err := c.ServiceBidAccount.ValidRule(c.Ctx)
  152. if err != nil {
  153. c.Ctx.JSON(iris.Map{"code": -1, "msg": utils.FormValidError(err)})
  154. return
  155. }
  156. // 获得项目ID
  157. projectIdInt, err := utils.GetProjectId(c.Ctx)
  158. if err != nil {
  159. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  160. return
  161. }
  162. // 创建标段和账号的关系
  163. err = c.ServiceBidAccount.Delete(BidAccountData, projectIdInt)
  164. if err != nil {
  165. c.Ctx.JSON(iris.Map{"code": -1, "msg": ""})
  166. return
  167. }
  168. c.Ctx.JSON(iris.Map{
  169. "code": 0,
  170. "msg": "移除成功",
  171. })
  172. }