gas_cylinder.go 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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 GasCylinderController struct {
  14. api.Api
  15. }
  16. // GetPage 获取钢瓶档案列表
  17. // @Summary 获取钢瓶档案列表
  18. // @Description 获取钢瓶档案列表
  19. // @Tags 钢瓶档案
  20. // @Param innerCode query string false "单位内编码"
  21. // @Param pageSize query int false "页条数"
  22. // @Param page query int false "页码"
  23. // @Success 200 {object} response.Response{data=response.Page{list=[]model.GasCylinder}} "{"code": 200, "data": [...]}"
  24. // @Router /api/gas-cylinder [get]
  25. // @Security Bearer
  26. func (e GasCylinderController) GetPage(c *gin.Context) {
  27. s := service.GasCylinder{}
  28. req := dto.GasCylinderGetPageReq{}
  29. err := e.MakeContext(c).
  30. MakeOrm().
  31. Bind(&req, binding.Query).
  32. MakeService(&s.Service).
  33. Errors
  34. if err != nil {
  35. e.Logger.Error(err)
  36. e.Error(500, err, err.Error())
  37. return
  38. }
  39. //数据权限检查
  40. p := actions.GetPermissionFromContext(c)
  41. list := make([]model.GasCylinder, 0)
  42. var count int64
  43. err = s.GetPage(&req, &list, &count, p)
  44. if err != nil {
  45. e.Error(500, err, err.Error())
  46. return
  47. }
  48. e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
  49. }
  50. // Get 通过id获取钢瓶档案
  51. // @Summary 通过id获取钢瓶档案
  52. // @Description 通过id获取钢瓶档案
  53. // @Tags 钢瓶档案
  54. // @Param id path path true "钢瓶档案id"
  55. // @Success 200 {object} response.Response{data=model.GasCylinder} "{"code": 200, "data": [...]}"
  56. // @Router /api/gas-cylinder/{id} [get]
  57. // @Security Bearer
  58. func (e GasCylinderController) Get(c *gin.Context) {
  59. s := service.GasCylinder{}
  60. req := dto.GasCylinderGetReq{}
  61. err := e.MakeContext(c).
  62. MakeOrm().
  63. Bind(&req, nil).
  64. MakeService(&s.Service).
  65. Errors
  66. if err != nil {
  67. e.Logger.Error(err)
  68. e.Error(500, err, err.Error())
  69. return
  70. }
  71. var object model.GasCylinder
  72. p := actions.GetPermissionFromContext(c)
  73. //数据权限检查
  74. err = s.Get(&req, &object, p)
  75. if err != nil {
  76. e.Error(500, err, err.Error())
  77. return
  78. }
  79. e.OK(object, "查询成功")
  80. }
  81. // GetByUid 通过高频编码获取钢瓶信息
  82. // @Summary 通过高频编码获取钢瓶信息
  83. // @Description 通过高频编码获取钢瓶信息
  84. // @Tags 钢瓶档案
  85. // @Param chipUid path string true "高频编码"
  86. // @Success 200 {object} response.Response{data=model.GasCylinder} "{"code": 200, "data": [...]}"
  87. // @Router /api/gas-cylinder/uid/{chipUid} [get]
  88. // @Security Bearer
  89. func (e GasCylinderController) GetByUid(c *gin.Context) {
  90. s := service.GasCylinder{}
  91. operationLogSvc := service.OperationLog{}
  92. req := dto.GasCylinderGetByUidReq{}
  93. err := e.MakeContext(c).
  94. MakeOrm().
  95. Bind(&req, nil).
  96. MakeService(&s.Service).
  97. MakeService(&operationLogSvc.Service).
  98. Errors
  99. if err != nil {
  100. e.Logger.Error(err)
  101. e.Error(500, err, err.Error())
  102. return
  103. }
  104. var gasCylinder model.GasCylinder
  105. p := actions.GetPermissionFromContext(c)
  106. //数据权限检查
  107. err = s.GetByUid(&req, &gasCylinder, p)
  108. if err != nil {
  109. e.Error(500, err, err.Error())
  110. return
  111. }
  112. operationLogList := make([]model.OperationLog, 0)
  113. err = operationLogSvc.ListByUid(gasCylinder.InnerCode, &operationLogList)
  114. if err != nil {
  115. e.Error(500, err, err.Error())
  116. return
  117. }
  118. e.OK(map[string]interface{}{
  119. "gasCylinder": gasCylinder,
  120. "operationLog": operationLogList,
  121. }, "查询成功")
  122. }
  123. // Mock 模拟气瓶数据
  124. // @Summary 模拟气瓶数据
  125. // @Description 模拟气瓶数据
  126. // @Tags 钢瓶档案
  127. // @Param data body dto.GasCylinderMockReq true "data"
  128. // @Success 200 {object} response.Response{data=model.GasCylinder} "{"code": 200, "data": [...]}"
  129. // @Router /api/gas-cylinder/mock [get]
  130. // @Security Bearer
  131. func (e GasCylinderController) Mock(c *gin.Context) {
  132. s := service.GasCylinder{}
  133. req := dto.GasCylinderMockReq{}
  134. err := e.MakeContext(c).
  135. MakeOrm().
  136. Bind(&req, binding.JSON).
  137. MakeService(&s.Service).
  138. Errors
  139. if err != nil {
  140. e.Logger.Error(err)
  141. e.Error(500, err, err.Error())
  142. return
  143. }
  144. //数据权限检查
  145. err = s.Mock(&req)
  146. if err != nil {
  147. e.Error(500, err, err.Error())
  148. return
  149. }
  150. e.OK(nil, "生成成功")
  151. }
  152. // Insert 添加钢瓶
  153. // @Summary 添加钢瓶
  154. // @Description 添加钢瓶
  155. // @Tags 钢瓶
  156. // @Accept application/json
  157. // @Product application/json
  158. // @Param data body dto.GasCylinderInsertReq true "data"
  159. // @Param pageSize query int false "页条数"
  160. // @Param page query int false "页码"
  161. // @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
  162. // @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
  163. // @Router /api/gas-cylinder [post]
  164. // @Security Bearer
  165. func (e GasCylinderController) Insert(c *gin.Context) {
  166. s := service.GasCylinder{}
  167. req := dto.GasCylinderInsertReq{}
  168. err := e.MakeContext(c).
  169. MakeOrm().
  170. Bind(&req, binding.JSON).
  171. MakeService(&s.Service).
  172. Errors
  173. if err != nil {
  174. e.Logger.Error(err)
  175. e.Error(500, err, err.Error())
  176. return
  177. }
  178. p := actions.GetPermissionFromContext(c)
  179. // 设置创建人
  180. req.SetCreateBy(user.GetUserId(c))
  181. req.SetDeptId(p.DeptId)
  182. err = s.Insert(&req)
  183. if err != nil {
  184. e.Error(500, err, err.Error())
  185. return
  186. }
  187. e.OK(req.GetId(), "创建成功")
  188. }
  189. // Update 修改钢瓶
  190. // @Summary 修改钢瓶
  191. // @Description 修改钢瓶
  192. // @Tags 钢瓶
  193. // @Accept application/json
  194. // @Product application/json
  195. // @Param data body dto.GasCylinderUpdateReq true "body"
  196. // @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
  197. // @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
  198. // @Router /api/dispatch-cost [put]
  199. // @Security Bearer
  200. func (e GasCylinderController) Update(c *gin.Context) {
  201. s := service.GasCylinder{}
  202. req := dto.GasCylinderUpdateReq{}
  203. err := e.MakeContext(c).
  204. MakeOrm().
  205. Bind(&req).
  206. MakeService(&s.Service).
  207. Errors
  208. if err != nil {
  209. e.Logger.Error(err)
  210. e.Error(500, err, err.Error())
  211. return
  212. }
  213. p := actions.GetPermissionFromContext(c)
  214. req.SetUpdateBy(user.GetUserId(c))
  215. err = s.Update(&req, p)
  216. if err != nil {
  217. e.Error(500, err, err.Error())
  218. return
  219. }
  220. e.OK(req.GetId(), "更新成功")
  221. }
  222. // Delete 删除钢瓶
  223. // @Summary 删除钢瓶
  224. // @Description 删除钢瓶
  225. // @Tags 钢瓶
  226. // @Accept application/json
  227. // @Product application/json
  228. // @Param data body dto.GasCylinderDeleteReq true "body"
  229. // @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
  230. // @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
  231. // @Router /api/dispatch-cost [delete]
  232. // @Security Bearer
  233. func (e GasCylinderController) Delete(c *gin.Context) {
  234. s := service.GasCylinder{}
  235. req := dto.GasCylinderDeleteReq{}
  236. userSvc := service.SysUser{}
  237. err := e.MakeContext(c).
  238. MakeOrm().
  239. Bind(&req, binding.JSON, nil).
  240. MakeService(&s.Service).
  241. MakeService(&userSvc.Service).
  242. Errors
  243. if err != nil {
  244. e.Logger.Error(err)
  245. e.Error(500, err, err.Error())
  246. return
  247. }
  248. //数据权限检查
  249. p := actions.GetPermissionFromContext(c)
  250. err = s.Remove(&req, p)
  251. if err != nil {
  252. e.Error(500, err, err.Error())
  253. return
  254. }
  255. e.OK(req.GetId(), "删除成功")
  256. }