project_setting_auth_api.go 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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. // @Param name path string false "账号名称"
  22. // @Success 200 {object} viewmodels.ProjectAccount "{code:0成功,-1参数类错误,data:viewmodels.ProjectAccount,msg:错误信息}"
  23. // @Router /api/projectSetting/bid/account [get]
  24. func (c *ProjectSettingApi) GetBidAccount() {
  25. // 获得标段ID
  26. TreeData := viewmodels.ProjectAccount{}
  27. err := c.Ctx.ReadForm(&TreeData)
  28. if err != nil {
  29. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  30. return
  31. }
  32. if TreeData.BidsectionId == "" {
  33. c.Ctx.JSON(iris.Map{"code": -1, "msg": "标段ID不能为空"})
  34. return
  35. }
  36. // 解密标段ID
  37. bidsectionId, err := utils.GetDecryptId(TreeData.BidsectionId)
  38. if err != nil {
  39. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  40. return
  41. }
  42. // 获得项目ID
  43. projectIdInt, err := utils.GetProjectId(c.Ctx)
  44. if err != nil {
  45. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  46. return
  47. }
  48. // 获得项目账号ID
  49. projectAccountIdInt, err := utils.GetProjectAccountId(c.Ctx)
  50. if err != nil {
  51. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  52. return
  53. }
  54. dataList := c.ServiceProjectAccount.GetBidAccount(bidsectionId, projectIdInt, projectAccountIdInt, TreeData.Name)
  55. c.Ctx.JSON(iris.Map{
  56. "code": 0,
  57. "msg": "",
  58. "data": dataList,
  59. })
  60. }
  61. // @Summary 标段中添加成员-账号
  62. // @Tags 项目设置-标段成员权限-管理员
  63. // @Description 标段中添加成员-账号
  64. // @Accept json
  65. // @Produce json
  66. // @Security ApiKeyAuth
  67. // @Param bidsectionId body string false "标段ID"
  68. // @Param accountId body string false "账号ID"
  69. // @Success 200 {string} string "{code:0成功,-1参数类错误,data:viewmodels.ProjectAccount,msg:错误信息}"
  70. // @Router /api/projectSetting/bid/account/create [post]
  71. func (c *ProjectSettingApi) PostBidAccountCreate() {
  72. // 账号ID,标段ID,目录ID
  73. BidAccountData, err := c.ServiceBidAccount.ValidRule(c.Ctx)
  74. if err != nil {
  75. c.Ctx.JSON(iris.Map{"code": -1, "msg": utils.FormValidError(err)})
  76. return
  77. }
  78. // 获得项目ID
  79. projectIdInt, err := utils.GetProjectId(c.Ctx)
  80. if err != nil {
  81. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  82. return
  83. }
  84. // 获得账号ID
  85. accountId, err := utils.GetProjectAccountId(c.Ctx)
  86. if err != nil {
  87. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  88. return
  89. }
  90. // 创建标段和账号的关系
  91. err = c.ServiceBidAccount.Create(BidAccountData, projectIdInt, accountId)
  92. if err != nil {
  93. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  94. return
  95. }
  96. c.Ctx.JSON(iris.Map{
  97. "code": 0,
  98. "msg": "新增成功",
  99. })
  100. }
  101. // @Summary 设置成员权限
  102. // @Tags 项目设置-标段成员权限-管理员
  103. // @Description 设置成员权限
  104. // @Accept json
  105. // @Produce json
  106. // @Security ApiKeyAuth
  107. // @Param bidsectionId body string false "标段ID"
  108. // @Param accountId body string false "账号ID"
  109. // @Param contractAdd body int false "合同创建 1拥有0不拥有"
  110. // @Param contractDelete body int false "合同删除 1拥有0不拥有"
  111. // @Param contractAccess body int false "合同查看 1拥有0不拥有"
  112. // @Param safeAdd body int false "安全创建 1拥有0不拥有"
  113. // @Param safeDelete body int false "安全删除 1拥有0不拥有"
  114. // @Param safeAccess body int false "安全查看 1拥有0不拥有"
  115. // @Param qualityAdd body int false "合同创建 1拥有0不拥有"
  116. // @Param qualityDelete body int false "合同删除 1拥有0不拥有"
  117. // @Param qualityAccess body int false "合同查看 1拥有0不拥有"
  118. // @Success 200 {string} string "{code:0成功,-1参数类错误,data:viewmodels.ProjectAccount,msg:错误信息}"
  119. // @Router /api/projectSetting/bid/account/auth [post]
  120. func (c *ProjectSettingApi) PostBidAccountAuth() {
  121. // 1.验证消息
  122. PermissionData, err := c.ServiceProjectAccount.ValidRulePermission(c.Ctx)
  123. // 获得项目ID
  124. projectId, err := utils.GetProjectId(c.Ctx)
  125. if err != nil {
  126. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  127. return
  128. }
  129. // 账号ID
  130. accountId, err := utils.GetDecryptId(PermissionData.AccountId)
  131. if err != nil {
  132. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  133. return
  134. }
  135. bidsectionId, err := utils.GetDecryptId(PermissionData.BidsectionId)
  136. if err != nil {
  137. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  138. return
  139. }
  140. // 保存设置的权限
  141. err = c.ServiceProjectAccount.SaveAuth(PermissionData, projectId, bidsectionId, accountId)
  142. if err != nil {
  143. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  144. return
  145. }
  146. c.Ctx.JSON(iris.Map{
  147. "code": 0,
  148. "msg": "设置成功",
  149. })
  150. }
  151. // @Summary 移除标段成员-账号
  152. // @Tags 项目设置-标段成员权限-管理员
  153. // @Description 移除标段成员-账号
  154. // @Accept json
  155. // @Produce json
  156. // @Security ApiKeyAuth
  157. // @Param bidsectionId body string false "标段ID"
  158. // @Param accountId body string false "账号ID"
  159. // @Success 200 {string} string "{code:0成功,-1参数类错误,data:viewmodels.ProjectAccount,msg:错误信息}"
  160. // @Router /api/projectSetting/bid/account [delete]
  161. func (c *ProjectSettingApi) DeleteBidAccount() {
  162. // 账号ID,标段ID
  163. BidAccountData, err := c.ServiceBidAccount.ValidRuleDelete(c.Ctx)
  164. if err != nil {
  165. c.Ctx.JSON(iris.Map{"code": -1, "msg": utils.FormValidError(err)})
  166. return
  167. }
  168. // 获得项目ID
  169. projectIdInt, err := utils.GetProjectId(c.Ctx)
  170. if err != nil {
  171. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  172. return
  173. }
  174. // 创建标段和账号的关系
  175. err = c.ServiceBidAccount.Delete(BidAccountData, projectIdInt)
  176. if err != nil {
  177. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  178. return
  179. }
  180. c.Ctx.JSON(iris.Map{
  181. "code": 0,
  182. "msg": "移除成功",
  183. })
  184. }
  185. // @Summary 获得标段权限
  186. // @Tags 项目设置-标段成员权限-管理员
  187. // @Description 获得当前用户下当前标段的权限
  188. // @Accept json
  189. // @Produce json
  190. // @Security ApiKeyAuth
  191. // @Param bidsectionId path string false "标段ID"
  192. // @Success 200 {object} viewmodels.PermissionView "{code:0成功,-1参数类错误,data:viewmodels.PermissionView,msg:错误信息}"
  193. // @Router /api/projectSetting/permission [get]
  194. func (c *ProjectSettingApi) GetPermission() {
  195. // 1.验证消息
  196. PermissionData, err := c.ServiceProjectAccount.ValidGetPermission(c.Ctx)
  197. // 账号ID
  198. accountId, err := utils.GetProjectAccountId(c.Ctx)
  199. if err != nil {
  200. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  201. return
  202. }
  203. bidsectionId, err := utils.GetDecryptId(PermissionData.BidsectionId)
  204. if err != nil {
  205. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  206. return
  207. }
  208. data, err := c.ServiceBidAccount.GetPermission(accountId, bidsectionId)
  209. if err != nil {
  210. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  211. return
  212. }
  213. c.Ctx.JSON(iris.Map{
  214. "code": 0,
  215. "msg": "请求成功",
  216. "data": data,
  217. })
  218. }