supplier.go 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. package storehouse
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "server/dao"
  5. "server/global"
  6. "server/model/common/request"
  7. "server/model/common/response"
  8. )
  9. type SupplierApi struct{}
  10. func (sa *SupplierApi) QueryAllSupplier(c *gin.Context) {
  11. suppliers, err := supplierService.QueryAllSupplier()
  12. if err != nil {
  13. response.FailWithMessage("查询失败", c)
  14. global.GVA_LOG.Error("QueryAllSupplier ====== " + err.Error())
  15. return
  16. }
  17. response.OkWithData(suppliers, c)
  18. }
  19. func (sa *SupplierApi) QuerySupplierList(c *gin.Context) {
  20. var info request.SearchSupplierList
  21. err := c.ShouldBindJSON(&info)
  22. if err != nil {
  23. response.FailWithMessage("参数解析失败", c)
  24. global.GVA_LOG.Error("QuerySupplierList ====== " + err.Error())
  25. return
  26. }
  27. list, total, err := supplierService.QuerySupplierList(info)
  28. if err != nil {
  29. response.FailWithMessage("查询失败", c)
  30. global.GVA_LOG.Error("QuerySupplierList ====== " + err.Error())
  31. return
  32. }
  33. response.OkWithDetailed(response.PageResult{
  34. List: list,
  35. Total: total,
  36. Page: info.PageInfo.Page,
  37. PageSize: info.PageInfo.PageSize,
  38. }, "获取成功", c)
  39. }
  40. func (sa *SupplierApi) CreateSupplier(c *gin.Context) {
  41. var supplier dao.Supplier
  42. err := c.ShouldBindJSON(&supplier)
  43. if err != nil {
  44. response.FailWithMessage("参数解析失败", c)
  45. global.GVA_LOG.Error("CreateSupplier ====== " + err.Error())
  46. return
  47. }
  48. err = supplierService.CreateSupplier(supplier)
  49. if err != nil {
  50. response.FailWithMessage("创建失败", c)
  51. global.GVA_LOG.Error("CreateSupplier ====== " + err.Error())
  52. return
  53. }
  54. response.OkWithMessage("创建成功", c)
  55. }
  56. func (sa *SupplierApi) UpdateSupplier(c *gin.Context) {
  57. var supplier dao.Supplier
  58. err := c.ShouldBindJSON(&supplier)
  59. if err != nil {
  60. response.FailWithMessage("参数解析失败", c)
  61. global.GVA_LOG.Error("UpdateSupplier ====== " + err.Error())
  62. return
  63. }
  64. err = supplierService.UpdateSupplier(supplier)
  65. if err != nil {
  66. response.FailWithMessage("更新失败", c)
  67. global.GVA_LOG.Error("UpdateSupplier ====== " + err.Error())
  68. return
  69. }
  70. response.OkWithMessage("更新成功", c)
  71. }
  72. func (sa *SupplierApi) DeleteSupplier(c *gin.Context) {
  73. var supplier dao.Supplier
  74. err := c.ShouldBindJSON(&supplier)
  75. if err != nil {
  76. response.FailWithMessage("参数解析失败", c)
  77. global.GVA_LOG.Error("DeleteSupplier ====== " + err.Error())
  78. return
  79. }
  80. err = supplierService.DeleteSupplier(supplier)
  81. if err != nil {
  82. response.FailWithMessage("删除失败", c)
  83. global.GVA_LOG.Error("DeleteSupplier ====== " + err.Error())
  84. return
  85. }
  86. response.OkWithMessage("删除成功", c)
  87. }