safe_rpc_api.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. "github.com/kataras/iris/v12"
  10. "go.mod/services"
  11. "go.mod/web/utils"
  12. )
  13. type SafeRpcApi struct {
  14. //框架-web应用上下文环境
  15. Ctx iris.Context
  16. // 需要用的service
  17. ServiceSafe services.SafeService
  18. }
  19. // @Summary 安全巡检列表
  20. // @Tags 安全巡检
  21. // @Description 获得列表数据
  22. // @Accept json
  23. // @Produce json
  24. // @Security ApiKeyAuth
  25. // @Success 200 {object} viewmodels.Safe "{code:0成功,data:viewmodels.Safe,msg:}"
  26. // @Failure 400 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
  27. // @Router /api/safe [get]
  28. func (c *SafeRpcApi) Get() {
  29. // 1.规则验证
  30. safeData, err := c.ServiceSafe.ValidRule(c.Ctx)
  31. if err != nil {
  32. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  33. return
  34. }
  35. bidsectionId, err := utils.GetDecryptId(safeData.BidsectionId)
  36. if err != nil {
  37. c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"})
  38. return
  39. }
  40. c.ServiceSafe.Get(bidsectionId)
  41. code, msg, data := c.ServiceSafe.Get(bidsectionId)
  42. c.Ctx.JSON(iris.Map{
  43. "code": code,
  44. "msg": msg,
  45. "data": data,
  46. })
  47. }
  48. // @Summary 安全巡检列表
  49. // @Tags 安全巡检
  50. // @Description 创建新的安全巡检记录
  51. // @Accept json
  52. // @Produce json
  53. // @Security ApiKeyAuth
  54. // @Success 200 {object} viewmodels.Safe "{code:0成功,msg:}"
  55. // @Failure 400 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
  56. // @Router /api/safe [post]
  57. func (c *SafeRpcApi) Post() {
  58. // 1.规则验证
  59. safeData, err := c.ServiceSafe.ValidRule(c.Ctx)
  60. if err != nil {
  61. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  62. return
  63. }
  64. bidsectionId, err := utils.GetDecryptId(safeData.BidsectionId)
  65. if err != nil {
  66. c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"})
  67. return
  68. }
  69. code, msg := c.ServiceSafe.Post(bidsectionId, safeData.Position, safeData.Code, safeData.CreateTime, safeData.Inspection)
  70. c.Ctx.JSON(iris.Map{
  71. "code": code,
  72. "msg": msg,
  73. })
  74. }