|
- package main
-
- import (
- "applet/app/db"
- "applet/app/db/model"
- "context"
- "fmt"
- "log"
- "net/http"
- "os"
- "os/signal"
- "syscall"
- "time"
-
- "applet/app/cfg"
- "applet/app/router"
- )
-
- func main2() {
- var m []model.CentralKitchenForSchoolUserRefundDay
- if err := db.Db.Where("create_at >= '2024-01-15 18:00:00' AND state = 4").Desc("id").Find(&m); err != nil {
- fmt.Println(err)
- }
- var canUserIds []int
- var onlyCanUserIds []int
- var notCanUserIds []int
- for _, v := range m {
- var mm []model.CentralKitchenForSchoolUserRefundDay
- if err := db.Db.Where("uid = ?", v.Uid).And("state = 1").Desc("records_id").Find(&mm); err != nil {
- fmt.Println(err)
- }
-
- if len(mm) > 0 {
- canUserIds = append(canUserIds, v.Uid)
- for _, vv := range mm {
- mmm := new(model.CentralKitchenForSchoolUserWithDay)
- _, err := db.Db.Where("id =?", vv.RecordsId).Get(mmm)
- if err != nil {
- fmt.Println(err)
- }
- if mmm.Date == "2024-01-30" {
- onlyCanUserIds = append(onlyCanUserIds, v.Uid)
- }
- }
- } else {
- notCanUserIds = append(notCanUserIds, v.Uid)
- }
- }
- r := router.Init() //创建路由
-
- srv := &http.Server{ //设置http服务参数
- Addr: cfg.SrvAddr, //指定ip和端口
- Handler: r, //指定路由
- }
-
- go func() { //协程启动监听http服务
- fmt.Println("Listening and serving HTTP on " + cfg.SrvAddr)
- if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
- log.Fatalf("listen: %s\n", err)
- }
- }()
-
- //退出go守护进程
- quit := make(chan os.Signal)
- signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
- <-quit
- log.Println("Shutting down server...")
- ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
- defer cancel()
- if err := srv.Shutdown(ctx); err != nil {
- log.Fatal("Server forced to shutdown:", err)
- }
- log.Println("Server exiting")
-
- }
|