safe_rpc_api.go 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. "fmt"
  10. "github.com/kataras/iris/v12"
  11. "go.mod/services"
  12. "go.mod/web/utils"
  13. "google.golang.org/grpc"
  14. )
  15. type SafeRpcApi 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 *SafeRpcApi) Get() {
  32. RpcConnect := c.Ctx.Values().Get("RpcConnect").(*grpc.ClientConn)
  33. // 1.规则验证
  34. safeData, err := c.ServiceSafe.ValidRule(c.Ctx)
  35. if err != nil {
  36. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  37. return
  38. }
  39. bidsectionId, err := utils.GetDecryptId(safeData.BidsectionId)
  40. if err != nil {
  41. c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"})
  42. return
  43. }
  44. c.ServiceSafe.Get(bidsectionId, RpcConnect)
  45. code, msg, data := c.ServiceSafe.Get(bidsectionId)
  46. c.Ctx.JSON(iris.Map{
  47. "code": code,
  48. "msg": msg,
  49. "data": data,
  50. })
  51. }
  52. // @Summary 安全巡检列表
  53. // @Tags 安全巡检
  54. // @Description 创建新的安全巡检记录
  55. // @Accept json
  56. // @Produce json
  57. // @Security ApiKeyAuth
  58. // @Param bidsectionId body string true "标段ID"
  59. // @Param code body string true "编号"
  60. // @Param createTime body string true "日期"
  61. // @Param inspection body string true "检查部位"
  62. // @Param position body string true "部位"
  63. // @Success 200 {object} viewmodels.Safe "{code:0成功,msg:}"
  64. // @Failure 400 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
  65. // @Router /api/safe/create [post]
  66. func (c *SafeRpcApi) PostCreate() {
  67. // 1.规则验证
  68. safeData, err := c.ServiceSafe.ValidRule(c.Ctx)
  69. if err != nil {
  70. c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
  71. return
  72. }
  73. fmt.Println(safeData)
  74. bidsectionId, err := utils.GetDecryptId(safeData.BidsectionId)
  75. if err != nil {
  76. c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"})
  77. return
  78. }
  79. RpcConnect := c.Ctx.Values().Get("RpcConnect").(*grpc.ClientConn)
  80. code, msg := c.ServiceSafe.Post(bidsectionId, safeData.Position, safeData.Code, safeData.CreateTime, safeData.Inspection, RpcConnect)
  81. c.Ctx.JSON(iris.Map{
  82. "code": code,
  83. "msg": msg,
  84. })
  85. }