面包店
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 
 

122 řádky
2.5 KiB

  1. package hdl
  2. import (
  3. "applet/app/admin/md"
  4. "applet/app/admin/svc"
  5. "applet/app/bigData/lib/validate"
  6. "applet/app/db"
  7. "applet/app/e"
  8. "fmt"
  9. "github.com/gin-gonic/gin"
  10. "os"
  11. )
  12. func DataStatisticsList(c *gin.Context) {
  13. var req md.ExportRecordsListReq
  14. err := c.ShouldBindJSON(&req)
  15. if err != nil {
  16. err = validate.HandleValidateErr(err)
  17. err1 := err.(e.E)
  18. e.OutErr(c, err1.Code, err1.Error())
  19. return
  20. }
  21. if req.Limit == 0 {
  22. req.Limit = 10
  23. }
  24. if req.Page == 0 {
  25. req.Page = 10
  26. }
  27. exportRecordsDb := db.ExportRecordsDb{}
  28. exportRecordsDb.Set()
  29. list, total, err := exportRecordsDb.ExportRecordsExportRecordsList(req)
  30. if err != nil {
  31. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  32. return
  33. }
  34. e.OutSuc(c, map[string]interface{}{
  35. "list": list,
  36. "total": total,
  37. "kind": []map[string]interface{}{
  38. {
  39. "name": "商品销售明细表",
  40. "value": 1,
  41. },
  42. {
  43. "name": "对账单",
  44. "value": 2,
  45. },
  46. },
  47. }, nil)
  48. return
  49. }
  50. func DataStatisticsDelete(c *gin.Context) {
  51. var req struct {
  52. Ids []int `json:"ids"`
  53. }
  54. err := c.ShouldBindJSON(&req)
  55. if err != nil {
  56. err = validate.HandleValidateErr(err)
  57. err1 := err.(e.E)
  58. e.OutErr(c, err1.Code, err1.Error())
  59. return
  60. }
  61. for _, id := range req.Ids {
  62. exportRecordsDb := db.ExportRecordsDb{}
  63. exportRecordsDb.Set()
  64. exportRecords, err1 := exportRecordsDb.GetExportRecordsExportRecords(id)
  65. if err1 != nil {
  66. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  67. return
  68. }
  69. if exportRecords == nil {
  70. e.OutErr(c, e.ERR_NO_DATA, "未查询到相关记录")
  71. return
  72. }
  73. err = os.RemoveAll("./data/export/" + exportRecords.DownloadPath) //移除文件
  74. if err != nil {
  75. fmt.Println("err>>>>>>>>>>>>>>", err.Error())
  76. }
  77. _, err2 := exportRecordsDb.ExportRecordsExportRecordsDelete(id)
  78. if err2 != nil {
  79. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  80. return
  81. }
  82. }
  83. e.OutSuc(c, "success", nil)
  84. return
  85. }
  86. func DataStatisticsExport(c *gin.Context) {
  87. var req md.DataStatisticsExportReq
  88. err := c.ShouldBindJSON(&req)
  89. if err != nil {
  90. err = validate.HandleValidateErr(err)
  91. err1 := err.(e.E)
  92. e.OutErr(c, err1.Code, err1.Error())
  93. return
  94. }
  95. if req.EnterpriseId != 0 {
  96. enterpriseDb := db.EnterpriseDb{}
  97. enterpriseDb.Set()
  98. enterprise, err1 := enterpriseDb.GetEnterprise(req.EnterpriseId)
  99. if err1 != nil {
  100. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  101. return
  102. }
  103. req.EnterpriseName = enterprise.Name
  104. }
  105. go svc.DataStatisticsExport(req)
  106. e.OutSuc(c, map[string]interface{}{
  107. "msg": "导出成功,请稍后刷新数据列表",
  108. }, nil)
  109. return
  110. }