real_fill_data.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 RealFillDataController struct {
  14. api.Api
  15. }
  16. // GetPage 获取上报实时充装数据
  17. // @Summary 获取上报实时充装数据
  18. // @Description 获取上报实时充装数据
  19. // @Tags 上报实时充装数据
  20. // @Param gunCode 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.RealFillData}} "{"code": 200, "data": [...]}"
  24. // @Router /api/goods [get]
  25. // @Security Bearer
  26. func (e RealFillDataController) GetPage(c *gin.Context) {
  27. s := service.RealFillData{}
  28. req := dto.RealFillDataGetPageReq{}
  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.RealFillData, 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. // Insert 添加上报实时充装数据
  51. // @Summary 添加上报实时充装数据
  52. // @Description 添加上报实时充装数据
  53. // @Tags 上报实时充装数据
  54. // @Accept application/json
  55. // @Product application/json
  56. // @Param data body dto.RealFillDataInsertReq true "data"
  57. // @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
  58. // @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
  59. // @Router /api/goods [post]
  60. // @Security Bearer
  61. func (e RealFillDataController) Insert(c *gin.Context) {
  62. s := service.RealFillData{}
  63. fillGunSvc := service.FillGun{}
  64. req := dto.RealFillDataInsertReq{}
  65. err := e.MakeContext(c).
  66. MakeOrm().
  67. Bind(&req, binding.JSON).
  68. MakeService(&s.Service).
  69. MakeService(&fillGunSvc.Service).
  70. Errors
  71. if err != nil {
  72. e.Logger.Error(err)
  73. e.Error(500, err, err.Error())
  74. return
  75. }
  76. // 设置创建人
  77. //p := actions.GetPermissionFromContext(c)
  78. req.SetCreateBy(user.GetUserId(c))
  79. //req.SetDeptId(p.DeptId)
  80. // 获取充装枪信息
  81. var fillGun model.FillGun
  82. err = fillGunSvc.GetByCode(req.ScanGunCode, &fillGun)
  83. if err != nil {
  84. e.Error(500, err, err.Error())
  85. return
  86. }
  87. err = s.Insert(&req, fillGun)
  88. if err != nil {
  89. e.Error(500, err, err.Error())
  90. return
  91. }
  92. e.OK(req.GetId(), "创建成功")
  93. }