project_setting_auth_api.go 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. // 获得账号ID
  84. accountId, err := utils.GetProjectAccountId(c.Ctx)
  85. if err != nil {
  86. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  87. return
  88. }
  89. // 创建标段和账号的关系
  90. err = c.ServiceBidAccount.Create(BidAccountData, projectIdInt, accountId)
  91. if err != nil {
  92. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  93. return
  94. }
  95. c.Ctx.JSON(iris.Map{
  96. "code": 0,
  97. "msg": "新增成功",
  98. })
  99. }
  100. // @Summary 设置成员权限
  101. // @Tags 项目设置-标段成员权限-管理员
  102. // @Description 设置成员权限
  103. // @Accept json
  104. // @Produce json
  105. // @Security ApiKeyAuth
  106. // @Param bidsectionId body string false "标段ID"
  107. // @Param accountId body string false "账号ID"
  108. // @Param contractAdd body int false "合同创建 1拥有0不拥有"
  109. // @Param contractDelete body int false "合同删除 1拥有0不拥有"
  110. // @Param contractAccess body int false "合同查看 1拥有0不拥有"
  111. // @Param safeAdd body int false "安全创建 1拥有0不拥有"
  112. // @Param safeDelete body int false "安全删除 1拥有0不拥有"
  113. // @Param safeAccess body int false "安全查看 1拥有0不拥有"
  114. // @Param qualityAdd body int false "合同创建 1拥有0不拥有"
  115. // @Param qualityDelete body int false "合同删除 1拥有0不拥有"
  116. // @Param qualityAccess body int false "合同查看 1拥有0不拥有"
  117. // @Success 200 {string} string "{code:0成功,-1参数类错误,data:viewmodels.ProjectAccount,msg:错误信息}"
  118. // @Router /api/projectSetting/bid/account/auth [post]
  119. func (c *ProjectSettingApi) PostBidAccountAuth() {
  120. // 1.验证消息
  121. PermissionData, err := c.ServiceProjectAccount.ValidRulePermission(c.Ctx)
  122. // 获得项目ID
  123. projectId, err := utils.GetProjectId(c.Ctx)
  124. if err != nil {
  125. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  126. return
  127. }
  128. // 账号ID
  129. accountId, err := utils.GetDecryptId(PermissionData.AccountId)
  130. if err != nil {
  131. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  132. return
  133. }
  134. // 保存设置的权限
  135. err = c.ServiceProjectAccount.SaveAuth(PermissionData, projectId, accountId)
  136. if err != nil {
  137. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  138. return
  139. }
  140. c.Ctx.JSON(iris.Map{
  141. "code": 0,
  142. "msg": "设置成功",
  143. })
  144. }
  145. // @Summary 移除标段成员-账号
  146. // @Tags 项目设置-标段成员权限-管理员
  147. // @Description 移除标段成员-账号
  148. // @Accept json
  149. // @Produce json
  150. // @Security ApiKeyAuth
  151. // @Param bidsectionId body string false "标段ID"
  152. // @Param accountId body string false "账号ID"
  153. // @Success 200 {string} string "{code:0成功,-1参数类错误,data:viewmodels.ProjectAccount,msg:错误信息}"
  154. // @Router /api/projectSetting/bid/account [delete]
  155. func (c *ProjectSettingApi) DeleteBidAccount() {
  156. // 账号ID,标段ID
  157. BidAccountData, err := c.ServiceBidAccount.ValidRuleDelete(c.Ctx)
  158. if err != nil {
  159. c.Ctx.JSON(iris.Map{"code": -1, "msg": utils.FormValidError(err)})
  160. return
  161. }
  162. // 获得项目ID
  163. projectIdInt, err := utils.GetProjectId(c.Ctx)
  164. if err != nil {
  165. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  166. return
  167. }
  168. // 创建标段和账号的关系
  169. err = c.ServiceBidAccount.Delete(BidAccountData, projectIdInt)
  170. if err != nil {
  171. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  172. return
  173. }
  174. c.Ctx.JSON(iris.Map{
  175. "code": 0,
  176. "msg": "移除成功",
  177. })
  178. }