real_fill_data.go 2.7 KB

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