safe_api.go 5.3 KB

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