rule_api.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * @description: 编号规则
  3. * @Author: LanJianRong
  4. * @Date: 2020-11-27
  5. * @FilePath: \construction_management\web\api\rule_api.go
  6. */
  7. package api
  8. import (
  9. "github.com/kataras/iris/v12"
  10. "go.mod/services"
  11. "go.mod/web/utils"
  12. )
  13. type RuleApi struct {
  14. //框架-web应用上下文环境
  15. Ctx iris.Context
  16. // 需要用的service
  17. RuleService services.RuleService
  18. }
  19. // @Summary 获取编号规则
  20. // @Tags 编号规则
  21. // @Description 获得制定pid、bid的编号规则
  22. // @Accept json
  23. // @Produce json
  24. // @Security ApiKeyAuth
  25. // @Param bidsectionId path string true "标段ID"
  26. // @Param projectId path string true "项目ID"
  27. // @Success 200 {object} viewmodels.ViewRule "{code:0成功,data:viewmodels.Safe,msg:}"
  28. // @Failure 400 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
  29. // @Router /api/rule [get]
  30. func (c *RuleApi) Get() {
  31. // 1.规则验证
  32. safeData, err := c.RuleService.ValidRule(c.Ctx)
  33. if err != nil {
  34. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  35. return
  36. }
  37. pid, err := utils.GetProjectId(c.Ctx)
  38. if err != nil {
  39. c.Ctx.JSON(iris.Map{"code": -1, "msg": "项目id不存在, 请重新登录"})
  40. return
  41. }
  42. bidsectionId, err := utils.GetDecryptId(safeData.BidsectionId)
  43. if err != nil {
  44. c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"})
  45. return
  46. }
  47. rule := c.RuleService.Get(pid, bidsectionId)
  48. c.Ctx.JSON(iris.Map{
  49. "code": 0,
  50. "msg": "请求成功",
  51. "data": rule,
  52. })
  53. }
  54. // @Summary 提交编号规则
  55. // @Tags 编号规则
  56. // @Description 提交规则
  57. // @Accept json
  58. // @Produce json
  59. // @Security ApiKeyAuth
  60. // @Param bidsectionId body string true "标段ID"
  61. // @Param type body string true "规则类型" eg:"safeRule、qualityRule、contractRule"
  62. // @Param value body string true "编号规则" eg:"'['202011', 'cc3']'"
  63. // @Success 200 {object} "{code:0成功,msg:}"
  64. // @Failure 400 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
  65. // @Router /api/rule [post]
  66. func (c *RuleApi) Post() {
  67. // 1.规则验证
  68. safeData, err := c.RuleService.ValidRule(c.Ctx)
  69. if err != nil {
  70. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  71. return
  72. }
  73. pid, err := utils.GetProjectId(c.Ctx)
  74. if err != nil {
  75. c.Ctx.JSON(iris.Map{"code": -1, "msg": "项目id不存在, 请重新登录"})
  76. return
  77. }
  78. bidsectionId, err := utils.GetDecryptId(safeData.BidsectionId)
  79. if err != nil {
  80. c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"})
  81. return
  82. }
  83. err = c.RuleService.Post(pid, bidsectionId, safeData.Type, safeData.Rule)
  84. if err == nil {
  85. c.Ctx.JSON(iris.Map{
  86. "code": 0,
  87. "msg": "请求成功",
  88. })
  89. } else {
  90. c.Ctx.JSON(iris.Map{
  91. "code": -1,
  92. "msg": err,
  93. })
  94. }
  95. }
  96. // @Summary 生成编号
  97. // @Tags 编号规则
  98. // @Description 提交规则
  99. // @Accept json
  100. // @Produce json
  101. // @Security ApiKeyAuth
  102. // @Param bidsectionId body string true "标段ID"
  103. // @Param type body string true "规则类型" eg:"safeRule、qualityRule、contractRule"
  104. // @Success 200 {object} "{code:0成功,data:"",msg:""}"
  105. // @Failure 400 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
  106. // @Router /api/rule/auto [post]
  107. func (c *RuleApi) PostAuto() {
  108. // 1.规则验证
  109. safeData, err := c.RuleService.ValidRule(c.Ctx)
  110. if err != nil {
  111. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  112. return
  113. }
  114. pid, err := utils.GetProjectId(c.Ctx)
  115. if err != nil {
  116. c.Ctx.JSON(iris.Map{"code": -1, "msg": "项目id不存在, 请重新登录"})
  117. return
  118. }
  119. bidsectionId, err := utils.GetDecryptId(safeData.BidsectionId)
  120. if err != nil {
  121. c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"})
  122. return
  123. }
  124. code, err := c.RuleService.AutoCode(bidsectionId, pid, safeData.Type)
  125. if err != nil {
  126. c.Ctx.JSON(iris.Map{
  127. "code": -1,
  128. "msg": err,
  129. })
  130. } else {
  131. c.Ctx.JSON(iris.Map{
  132. "code": 0,
  133. "msg": "请求成功",
  134. "data": code,
  135. })
  136. }
  137. }