stock.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package routers
  2. import (
  3. "fmt"
  4. "github.com/astaxie/beego/logs"
  5. "github.com/gin-gonic/gin"
  6. "kpt.xdmy/apiserver/model"
  7. "kpt.xdmy/pkg/app"
  8. "kpt.xdmy/pkg/e"
  9. "strconv"
  10. )
  11. func GetStockList(c *gin.Context) {
  12. req := new(model.GetStockListReq)
  13. req.PastureId = c.Query("pastureId")
  14. req.DepartmentId = c.Query("departmentId")
  15. offsetStr := c.Query("offset")
  16. pagecountStr := c.Query("pagecount")
  17. req.StartDate = c.Query("startdate")
  18. req.EndDate = c.Query("enddate")
  19. req.Offset, _ = strconv.Atoi(offsetStr)
  20. req.Pagecount, _ = strconv.Atoi(pagecountStr)
  21. req.Offset = req.Offset - 1
  22. resp, err := svc.GetStockList(req)
  23. if err != nil {
  24. fmt.Println(err)
  25. c.JSON(500, map[string]interface{}{"code": 500, "data": "查询失败!", "msg": err})
  26. return
  27. }
  28. resp.Offset = req.Offset + 1
  29. resp.Pagecount = req.Pagecount
  30. c.JSON(200, map[string]interface{}{"code": 200, "data": resp, "msg": "ok"})
  31. }
  32. func StockExcel(c *gin.Context) {
  33. appG := app.Gin{C: c}
  34. data := svc.StockExcel(c)
  35. appG.Response(200, e.SUCCESS, data)
  36. }
  37. func DelStockList(c *gin.Context) {
  38. req := new(model.DelStockListReq)
  39. err := c.ShouldBind(&req)
  40. if err != nil {
  41. logs.Error(err)
  42. c.JSON(500, map[string]interface{}{"code": 500, "data": "参数有误!", "msg": err})
  43. return
  44. }
  45. var idList []string
  46. for _, id := range req.Id {
  47. idStr := strconv.Itoa(id)
  48. idList = append(idList, idStr)
  49. }
  50. err = svc.DelStockList(idList)
  51. if err != nil {
  52. logs.Error(err)
  53. c.JSON(500, map[string]interface{}{"code": 500, "data": "删除失败!", "msg": err})
  54. return
  55. }
  56. c.JSON(200, map[string]interface{}{"code": 200, "data": true, "msg": "ok"})
  57. }