safe_api.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. * @description: rpc - 安全巡检
  3. * @Author: LanJianRong
  4. * @Date: 2020-11-18
  5. * @FilePath: \construction_management\web\api\safe_rpc_api.go
  6. */
  7. package api
  8. import (
  9. "time"
  10. "github.com/kataras/iris/v12"
  11. "go.mod/models"
  12. "go.mod/services"
  13. "go.mod/web/utils"
  14. )
  15. type SafeApi struct {
  16. //框架-web应用上下文环境
  17. Ctx iris.Context
  18. // 需要用的service
  19. ServiceSafe services.SafeService
  20. }
  21. // @Summary 安全巡检列表
  22. // @Tags 安全巡检
  23. // @Description 获得列表数据
  24. // @Accept json
  25. // @Produce json
  26. // @Security ApiKeyAuth
  27. // @Param bidsectionId path string true "标段ID"
  28. // @Success 200 {object} viewmodels.Safe "{code:0成功,data:viewmodels.Safe,msg:}"
  29. // @Failure 400 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
  30. // @Router /api/safe [get]
  31. func (c *SafeApi) Get() {
  32. // 1.规则验证
  33. safeData, err := c.ServiceSafe.ValidRule(c.Ctx)
  34. if err != nil {
  35. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  36. return
  37. }
  38. bidsectionId, err := utils.GetDecryptId(safeData.BidsectionId)
  39. if err != nil {
  40. c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"})
  41. return
  42. }
  43. // c.ServiceSafe.Get(bidsectionId, RpcConnect)
  44. SafeData := c.ServiceSafe.Get(bidsectionId)
  45. c.Ctx.JSON(iris.Map{
  46. "code": 0,
  47. "msg": "请求成功",
  48. "data": SafeData,
  49. })
  50. }
  51. // @Summary 安全巡检列表
  52. // @Tags 安全巡检
  53. // @Description 创建新的安全巡检记录
  54. // @Accept json
  55. // @Produce json
  56. // @Security ApiKeyAuth
  57. // @Param bidsectionId body string true "标段ID"
  58. // @Param code body string true "编号"
  59. // @Param createTime body string true "日期"
  60. // @Param inspection body string true "检查部位"
  61. // @Param position body string true "部位"
  62. // @Success 200 {object} viewmodels.Safe "{code:0成功,msg:}"
  63. // @Failure 400 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
  64. // @Router /api/safe [post]
  65. func (c *SafeApi) Post() {
  66. // 1.规则验证
  67. safeData, err := c.ServiceSafe.ValidRule(c.Ctx)
  68. if err != nil {
  69. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  70. return
  71. }
  72. bidsectionId, err := utils.GetDecryptId(safeData.BidsectionId)
  73. if err != nil {
  74. c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"})
  75. return
  76. }
  77. data := models.CmSafe{}
  78. data.BidsectionId = bidsectionId
  79. data.Code = safeData.Code
  80. data.Inspection = safeData.Inspection
  81. createTime, err := time.Parse("2006-11-01 08:11:11", safeData.CreateTime)
  82. if err != nil {
  83. c.Ctx.JSON(iris.Map{"code": -1, "msg": "日期转换异常,请检查参数"})
  84. return
  85. }
  86. data.CreateTime = createTime
  87. err1 := c.ServiceSafe.Post(data)
  88. if err != nil {
  89. c.Ctx.JSON(iris.Map{
  90. "code": -1,
  91. "msg": err1,
  92. })
  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 id body string true "安全巡检ID"
  107. // @Success 200 {object} viewmodels.Safe "{code:0成功,msg:}"
  108. // @Failure 400 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
  109. // @Router /api/safe [delete]
  110. func (c *SafeApi) Delete() {
  111. queryId := c.Ctx.URLParam("id")
  112. if queryId == "" {
  113. c.Ctx.JSON(iris.Map{"code": -1, "msg": "id不存在"})
  114. return
  115. }
  116. id, err := utils.GetDecryptId(queryId)
  117. if err != nil {
  118. c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"})
  119. return
  120. }
  121. err1 := c.ServiceSafe.Del(id)
  122. if err1 != nil {
  123. c.Ctx.JSON(iris.Map{
  124. "code": -1,
  125. "msg": err1,
  126. })
  127. return
  128. }
  129. c.Ctx.JSON(iris.Map{
  130. "code": 0,
  131. "msg": "删除成功",
  132. })
  133. }
  134. // @Summary 安全巡检列表
  135. // @Tags 安全巡检
  136. // @Description 获得安全巡检详情页面数据
  137. // @Accept json
  138. // @Produce json
  139. // @Security ApiKeyAuth
  140. // @Param id path string true "巡检ID"
  141. // @Success 200 {object} viewmodels.Safe "{code:0成功,data:viewmodels.Safe,msg:}"
  142. // @Failure 400 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
  143. // @Router /api/safe/detail [get]
  144. // func (c *SafeApi) GetDetail() {
  145. // // 1.规则验证
  146. // safeData, err := c.ServiceSafe.ValidRule(c.Ctx)
  147. // if err != nil {
  148. // c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  149. // return
  150. // }
  151. // id, err := utils.GetDecryptId(safeData.Id)
  152. // if err != nil {
  153. // c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadForm转换异常,请检查参数"})
  154. // return
  155. // }
  156. // SafeData := c.ServiceSafe.GetDetail(id)
  157. // c.Ctx.JSON(iris.Map{
  158. // "code": 0,
  159. // "msg": "请求成功",
  160. // "data": SafeData,
  161. // })
  162. // }