safe_api.go 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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": fmt.Sprintf("%s", 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. // fmt.Println("-------------------------------", err)
  76. if err != nil {
  77. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  78. return
  79. }
  80. bidsectionId, err := utils.GetDecryptId(safeData.BidsectionId)
  81. if err != nil {
  82. c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"})
  83. return
  84. }
  85. data := models.CmSafe{}
  86. data.BidsectionId = bidsectionId
  87. data.Code = safeData.Code
  88. data.Inspection = safeData.Inspection
  89. uid, err := utils.GetProjectAccountId(c.Ctx)
  90. if err != nil {
  91. c.Ctx.JSON(iris.Map{"code": -1, "msg": "未登录或账号失效,请重新登录"})
  92. return
  93. }
  94. data.Uid = uid
  95. createTime, err := time.Parse(conf.SysTimeform, safeData.CreateTime)
  96. if err != nil {
  97. c.Ctx.JSON(iris.Map{"code": -1, "msg": "日期转换异常,请检查参数"})
  98. return
  99. }
  100. // fmt.Println(createTime)
  101. data.CreateTime = createTime
  102. err = c.ServiceSafe.Post(data)
  103. if err != nil {
  104. c.Ctx.JSON(iris.Map{
  105. "code": -1,
  106. "msg": fmt.Sprintf("%s", err),
  107. })
  108. return
  109. }
  110. c.Ctx.JSON(iris.Map{
  111. "code": 0,
  112. "msg": "插入成功",
  113. })
  114. }
  115. // @Summary 删除记录
  116. // @Tags 安全巡检
  117. // @Description 删除安全巡检记录
  118. // @Accept json
  119. // @Produce json
  120. // @Security ApiKeyAuth
  121. // @Param id body string true "安全巡检ID"
  122. // @Success 200 {object} viewmodels.Safe "{code:0成功,msg:}"
  123. // @Failure 400 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
  124. // @Router /api/safe [delete]
  125. func (c *SafeApi) Delete() {
  126. queryId := c.Ctx.URLParam("id")
  127. if queryId == "" {
  128. c.Ctx.JSON(iris.Map{"code": -1, "msg": "id不存在"})
  129. return
  130. }
  131. id, err := utils.GetDecryptId(queryId)
  132. if err != nil {
  133. c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"})
  134. return
  135. }
  136. err = c.ServiceSafe.Del(id)
  137. if err != nil {
  138. c.Ctx.JSON(iris.Map{
  139. "code": -1,
  140. "msg": fmt.Sprintf("%s", err),
  141. })
  142. return
  143. }
  144. c.Ctx.JSON(iris.Map{
  145. "code": 0,
  146. "msg": "删除成功",
  147. })
  148. }
  149. // @Summary 获取安全巡检详情
  150. // @Tags 安全巡检
  151. // @Description 获得安全巡检详情页面数据
  152. // @Accept json
  153. // @Produce json
  154. // @Security ApiKeyAuth
  155. // @Param id path string true "巡检ID"
  156. // @Success 200 {object} viewmodels.SafeDetail "{code:0成功,data:viewmodels.SafeDetail,msg:}"
  157. // @Failure 400 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
  158. // @Router /api/safe/detail [get]
  159. func (c *SafeApi) GetDetail() {
  160. // 1.规则验证
  161. safeData, err := c.ServiceSafe.ValidRule(c.Ctx)
  162. if err != nil {
  163. c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  164. return
  165. }
  166. id, err := utils.GetDecryptId(safeData.Id)
  167. if err != nil {
  168. c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadForm转换异常,请检查参数"})
  169. return
  170. }
  171. pid, _ := utils.GetProjectId(c.Ctx)
  172. SafeData := c.ServiceSafe.GetDetail(id, pid)
  173. c.Ctx.JSON(iris.Map{
  174. "code": 0,
  175. "msg": "请求成功",
  176. "data": SafeData,
  177. })
  178. }
  179. // @Summary 巡检附件记录
  180. // @Tags 安全巡检
  181. // @Description 上传附件巡检记录
  182. // @Accept json
  183. // @Produce json
  184. // @Security ApiKeyAuth
  185. // @Param bidsectionId body string true "标段ID"
  186. // @Success 200 {object} viewmodels.Safe "{code:0成功,msg:}"
  187. // @Failure 400 {string} string "{code:0成功,-1参数类错误,-2服务端内部错误,msg:错误信息}"
  188. // @Router /api/safe/file [post]
  189. // func (c *SafeApi) PostFile() {
  190. // // 1.规则验证
  191. // safeData, err := c.ServiceSafe.ValidFile(c.Ctx)
  192. // if err != nil {
  193. // c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
  194. // return
  195. // }
  196. // bidsectionId, err := utils.GetDecryptId(safeData.BidsectionId)
  197. // if err != nil {
  198. // c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"})
  199. // return
  200. // }
  201. // sId, err := utils.GetDecryptId(safeData.SaveId)
  202. // if err != nil {
  203. // c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"})
  204. // return
  205. // }
  206. // uid, err := utils.GetProjectAccountId(c.Ctx)
  207. // if err != nil {
  208. // c.Ctx.JSON(iris.Map{"code": -1, "msg": "未登录或账号失效,请重新登录"})
  209. // return
  210. // }
  211. // err = c.ServiceSafe.SaveFileInfo(bidsectionId, sId, uid, safeData.FileList)
  212. // if err != nil {
  213. // c.Ctx.JSON(iris.Map{
  214. // "code": -1,
  215. // "msg": fmt.Sprintf("%s", err),
  216. // })
  217. // return
  218. // }
  219. // c.Ctx.JSON(iris.Map{
  220. // "code": 0,
  221. // "msg": "请求成功",
  222. // })
  223. // }