智慧食堂
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

пре 11 месеци
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package main
  2. import (
  3. "applet/app/db"
  4. "applet/app/db/model"
  5. "context"
  6. "fmt"
  7. "log"
  8. "net/http"
  9. "os"
  10. "os/signal"
  11. "syscall"
  12. "time"
  13. "applet/app/cfg"
  14. "applet/app/router"
  15. )
  16. func main2() {
  17. var m []model.CentralKitchenForSchoolUserRefundDay
  18. if err := db.Db.Where("create_at >= '2024-01-15 18:00:00' AND state = 4").Desc("id").Find(&m); err != nil {
  19. fmt.Println(err)
  20. }
  21. var canUserIds []int
  22. var onlyCanUserIds []int
  23. var notCanUserIds []int
  24. for _, v := range m {
  25. var mm []model.CentralKitchenForSchoolUserRefundDay
  26. if err := db.Db.Where("uid = ?", v.Uid).And("state = 1").Desc("records_id").Find(&mm); err != nil {
  27. fmt.Println(err)
  28. }
  29. if len(mm) > 0 {
  30. canUserIds = append(canUserIds, v.Uid)
  31. for _, vv := range mm {
  32. mmm := new(model.CentralKitchenForSchoolUserWithDay)
  33. _, err := db.Db.Where("id =?", vv.RecordsId).Get(mmm)
  34. if err != nil {
  35. fmt.Println(err)
  36. }
  37. if mmm.Date == "2024-01-30" {
  38. onlyCanUserIds = append(onlyCanUserIds, v.Uid)
  39. }
  40. }
  41. } else {
  42. notCanUserIds = append(notCanUserIds, v.Uid)
  43. }
  44. }
  45. r := router.Init() //创建路由
  46. srv := &http.Server{ //设置http服务参数
  47. Addr: cfg.SrvAddr, //指定ip和端口
  48. Handler: r, //指定路由
  49. }
  50. go func() { //协程启动监听http服务
  51. fmt.Println("Listening and serving HTTP on " + cfg.SrvAddr)
  52. if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
  53. log.Fatalf("listen: %s\n", err)
  54. }
  55. }()
  56. //退出go守护进程
  57. quit := make(chan os.Signal)
  58. signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
  59. <-quit
  60. log.Println("Shutting down server...")
  61. ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
  62. defer cancel()
  63. if err := srv.Shutdown(ctx); err != nil {
  64. log.Fatal("Server forced to shutdown:", err)
  65. }
  66. log.Println("Server exiting")
  67. }