inspect_record.go 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. package controller
  2. import (
  3. "gas-cylinder-api/app/admin/model"
  4. "gas-cylinder-api/app/admin/service"
  5. "gas-cylinder-api/app/admin/service/dto"
  6. "gas-cylinder-api/common/actions"
  7. "github.com/gin-gonic/gin"
  8. "github.com/gin-gonic/gin/binding"
  9. "gogs.baozhida.cn/zoie/OAuth-core/api"
  10. "gogs.baozhida.cn/zoie/OAuth-core/pkg/jwtauth/user"
  11. _ "gogs.baozhida.cn/zoie/OAuth-core/pkg/response"
  12. )
  13. type InspectRecordController struct {
  14. api.Api
  15. }
  16. // GetPage 获取入户安全检查列表
  17. // @Summary 获取入户安全检查列表
  18. // @Description 获取入户安全检查列表
  19. // @Tags 入户安全检查
  20. // @Param deptName query string false "入户安全检查名称"
  21. // @Success 200 {object} response.Response{data=response.Page{list=[]model.InspectRecord}} "{"code": 200, "data": [...]}"
  22. // @Router /api/goods [get]
  23. // @Security Bearer
  24. func (e InspectRecordController) GetPage(c *gin.Context) {
  25. s := service.InspectRecord{}
  26. req := dto.InspectRecordGetPageReq{}
  27. err := e.MakeContext(c).
  28. MakeOrm().
  29. Bind(&req, binding.Query).
  30. MakeService(&s.Service).
  31. Errors
  32. if err != nil {
  33. e.Logger.Error(err)
  34. e.Error(500, err, err.Error())
  35. return
  36. }
  37. //数据权限检查
  38. p := actions.GetPermissionFromContext(c)
  39. list := make([]model.InspectRecord, 0)
  40. var count int64
  41. err = s.GetPage(&req, &list, &count, p)
  42. if err != nil {
  43. e.Error(500, err, err.Error())
  44. return
  45. }
  46. e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
  47. }
  48. // Get 通过id获取入户安全检查
  49. // @Summary 通过id获取入户安全检查
  50. // @Description 通过id获取入户安全检查
  51. // @Tags 入户安全检查
  52. // @Param id path string true "入户安全检查id"
  53. // @Success 200 {object} response.Response{data=model.InspectRecord} "{"code": 200, "data": [...]}"
  54. // @Router /api/goods/{id} [get]
  55. // @Security Bearer
  56. func (e InspectRecordController) Get(c *gin.Context) {
  57. s := service.InspectRecord{}
  58. req := dto.InspectRecordGetReq{}
  59. err := e.MakeContext(c).
  60. MakeOrm().
  61. Bind(&req, nil).
  62. MakeService(&s.Service).
  63. Errors
  64. if err != nil {
  65. e.Logger.Error(err)
  66. e.Error(500, err, err.Error())
  67. return
  68. }
  69. var object model.InspectRecord
  70. p := actions.GetPermissionFromContext(c)
  71. //数据权限检查
  72. err = s.Get(&req, &object, p)
  73. if err != nil {
  74. e.Error(500, err, err.Error())
  75. return
  76. }
  77. e.OK(object, "查询成功")
  78. }
  79. // Insert 添加入户安全检查
  80. // @Summary 添加入户安全检查
  81. // @Description 添加入户安全检查
  82. // @Tags 入户安全检查
  83. // @Accept application/json
  84. // @Product application/json
  85. // @Param data body dto.InspectRecordInsertReq true "data"
  86. // @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
  87. // @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
  88. // @Router /api/goods [post]
  89. // @Security Bearer
  90. func (e InspectRecordController) Insert(c *gin.Context) {
  91. s := service.InspectRecord{}
  92. userSvc := service.SysUser{}
  93. req := dto.InspectRecordInsertReq{}
  94. err := e.MakeContext(c).
  95. MakeOrm().
  96. Bind(&req, binding.JSON).
  97. MakeService(&s.Service).
  98. MakeService(&userSvc.Service).
  99. Errors
  100. if err != nil {
  101. e.Logger.Error(err)
  102. e.Error(500, err, err.Error())
  103. return
  104. }
  105. // 设置创建人
  106. req.SetCreateBy(user.GetUserId(c))
  107. req.SetDeptId(user.GetDeptId(c))
  108. var userObj model.SysUser
  109. err = userSvc.Get(&dto.SysUserGetReq{Id: user.GetUserId(c)}, nil, &userObj)
  110. if err != nil {
  111. e.Error(500, err, err.Error())
  112. return
  113. }
  114. req.InspectorId = userObj.ProvUserId
  115. req.CreatorId = userObj.ProvUserId
  116. req.UserId = userObj.Id
  117. err = s.Insert(&req)
  118. if err != nil {
  119. e.Error(500, err, err.Error())
  120. return
  121. }
  122. e.OK(req.GetId(), "创建成功")
  123. }
  124. // Update 修改入户安全检查
  125. // @Summary 修改入户安全检查
  126. // @Description 修改入户安全检查
  127. // @Tags 入户安全检查
  128. // @Accept application/json
  129. // @Product application/json
  130. // @Param data body dto.InspectRecordInsertReq true "data"
  131. // @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
  132. // @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
  133. // @Router /api/goods [post]
  134. // @Security Bearer
  135. func (e InspectRecordController) Update(c *gin.Context) {
  136. s := service.InspectRecord{}
  137. userSvc := service.SysUser{}
  138. req := dto.InspectRecordInsertReq{}
  139. err := e.MakeContext(c).
  140. MakeOrm().
  141. Bind(&req, binding.JSON).
  142. MakeService(&s.Service).
  143. MakeService(&userSvc.Service).
  144. Errors
  145. if err != nil {
  146. e.Logger.Error(err)
  147. e.Error(500, err, err.Error())
  148. return
  149. }
  150. // 设置创建人
  151. req.SetCreateBy(user.GetUserId(c))
  152. req.SetDeptId(user.GetDeptId(c))
  153. err = s.Update(&req)
  154. if err != nil {
  155. e.Error(500, err, err.Error())
  156. return
  157. }
  158. e.OK(req.GetId(), "修改成功")
  159. }