project_setting_auth_api.go 5.9 KB

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