safe_rpc_api.go 2.6 KB

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