inspect_expand.go 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. )
  12. type InspectExpandController struct {
  13. api.Api
  14. }
  15. // GetPage 获取入户安全检查项项列表
  16. // @Summary 获取入户安全检查项项列表
  17. // @Description 获取入户安全检查项项列表
  18. // @Tags 入户安全检查项项
  19. // @Param state query int false "订单状态 状态 0-待整改 1-整改中 2-已整改 -1 合格"
  20. // @Param inspectStartTime query string false "检查开始时间"
  21. // @Param inspectEndTime query string false "检查结束时间"
  22. // @Param customerName query string false "客户名称"
  23. // @Param inspectorName query string false "检查人"
  24. // @Param pageSize query int false "页条数"
  25. // @Param page query int false "页码"
  26. // @Success 200 {object} response.Response{data=response.Page{list=[]model.InspectExpand}} "{"code": 200, "data": [...]}"
  27. // @Router /api/inspect_record [get]
  28. // @Security Bearer
  29. func (e InspectExpandController) GetPage(c *gin.Context) {
  30. s := service.InspectExpand{}
  31. req := dto.InspectExpandGetPageReq{}
  32. err := e.MakeContext(c).
  33. MakeOrm().
  34. Bind(&req, binding.Query).
  35. MakeService(&s.Service).
  36. Errors
  37. if err != nil {
  38. e.Logger.Error(err)
  39. e.Error(500, err, err.Error())
  40. return
  41. }
  42. //数据权限检查
  43. p := actions.GetPermissionFromContext(c)
  44. list := make([]model.InspectExpand, 0)
  45. var count int64
  46. err = s.GetPage(&req, &list, &count, p)
  47. if err != nil {
  48. e.Error(500, err, err.Error())
  49. return
  50. }
  51. e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
  52. }
  53. // Insert 添加入户安全检查项项
  54. // @Summary 添加入户安全检查项项
  55. // @Description 添加入户安全检查项项
  56. // @Tags 入户安全检查项项
  57. // @Accept application/json
  58. // @Product application/json
  59. // @Param data body dto.InspectExpandInsertReq true "data"
  60. // @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
  61. // @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
  62. // @Router /api/inspect_record [post]
  63. // @Security Bearer
  64. func (e InspectExpandController) Insert(c *gin.Context) {
  65. s := service.InspectExpand{}
  66. req := dto.InspectExpandInsertReq{}
  67. err := e.MakeContext(c).
  68. MakeOrm().
  69. Bind(&req, binding.JSON).
  70. MakeService(&s.Service).
  71. Errors
  72. if err != nil {
  73. e.Logger.Error(err)
  74. e.Error(500, err, err.Error())
  75. return
  76. }
  77. //数据权限检查
  78. p := actions.GetPermissionFromContext(c)
  79. // 设置创建人
  80. req.SetCreateBy(user.GetUserId(c))
  81. req.SetDeptId(user.GetDeptId(c))
  82. err = s.Insert(&req, p)
  83. if err != nil {
  84. e.Error(500, err, err.Error())
  85. return
  86. }
  87. e.OK(req.GetId(), "创建成功")
  88. }
  89. // Update 修改入户安全检查项项
  90. // @Summary 修改入户安全检查项项
  91. // @Description 修改入户安全检查项项
  92. // @Tags 入户安全检查项项
  93. // @Accept application/json
  94. // @Product application/json
  95. // @Param data body dto.InspectExpandInsertReq true "data"
  96. // @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
  97. // @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
  98. // @Router /api/inspect_record [post]
  99. // @Security Bearer
  100. func (e InspectExpandController) Update(c *gin.Context) {
  101. s := service.InspectExpand{}
  102. userSvc := service.SysUser{}
  103. req := dto.InspectExpandInsertReq{}
  104. err := e.MakeContext(c).
  105. MakeOrm().
  106. Bind(&req, binding.JSON).
  107. MakeService(&s.Service).
  108. MakeService(&userSvc.Service).
  109. Errors
  110. if err != nil {
  111. e.Logger.Error(err)
  112. e.Error(500, err, err.Error())
  113. return
  114. }
  115. // 设置创建人
  116. req.SetCreateBy(user.GetUserId(c))
  117. req.SetDeptId(user.GetDeptId(c))
  118. err = s.Update(&req)
  119. if err != nil {
  120. e.Error(500, err, err.Error())
  121. return
  122. }
  123. e.OK(req.GetId(), "修改成功")
  124. }
  125. // Delete 删除钢瓶状态
  126. // @Summary 删除钢瓶状态
  127. // @Description 删除钢瓶状态
  128. // @Tags 钢瓶状态
  129. // @Accept application/json
  130. // @Product application/json
  131. // @Param data body dto.GasCylinderStatusDeleteReq true "body"
  132. // @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
  133. // @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
  134. // @Router /api/dispatch-cost [delete]
  135. // @Security Bearer
  136. func (e InspectExpandController) Delete(c *gin.Context) {
  137. s := service.InspectExpand{}
  138. req := dto.InspectExpandDeleteReq{}
  139. userSvc := service.SysUser{}
  140. err := e.MakeContext(c).
  141. MakeOrm().
  142. Bind(&req, binding.JSON, nil).
  143. MakeService(&s.Service).
  144. MakeService(&userSvc.Service).
  145. Errors
  146. if err != nil {
  147. e.Logger.Error(err)
  148. e.Error(500, err, err.Error())
  149. return
  150. }
  151. //数据权限检查
  152. p := actions.GetPermissionFromContext(c)
  153. err = s.Remove(&req, p)
  154. if err != nil {
  155. e.Error(500, err, err.Error())
  156. return
  157. }
  158. e.OK(req.GetId(), "删除成功")
  159. }
  160. // SyncStore 删除钢瓶状态
  161. // @Summary 删除钢瓶状态
  162. // @Description 删除钢瓶状态
  163. // @Tags 钢瓶状态
  164. // @Accept application/json
  165. // @Product application/json
  166. // @Param data body dto.InspectExpandSyncStoreReq true "body"
  167. // @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
  168. // @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
  169. // @Router /api/dispatch-cost [delete]
  170. // @Security Bearer
  171. func (e InspectExpandController) SyncStore(c *gin.Context) {
  172. s := service.InspectExpand{}
  173. req := dto.InspectExpandSyncStoreReq{}
  174. err := e.MakeContext(c).
  175. MakeOrm().
  176. Bind(&req, binding.JSON, nil).
  177. MakeService(&s.Service).
  178. Errors
  179. if err != nil {
  180. e.Logger.Error(err)
  181. e.Error(500, err, err.Error())
  182. return
  183. }
  184. //数据权限检查
  185. p := actions.GetPermissionFromContext(c)
  186. err = s.SyncStore(&req, p)
  187. if err != nil {
  188. e.Error(500, err, err.Error())
  189. return
  190. }
  191. e.OK(req.StoreIds, "同步成功")
  192. }