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 main1() { var m []model.CentralKitchenForSchoolUserRefundDay if err := db.Db.Where("1=1").Desc("id").Find(&m); err != nil { fmt.Println(err) } var alreadyIds = map[int]bool{} for _, v := range m { if v.State != 3 && !alreadyIds[v.Id] { var mm []model.CentralKitchenForSchoolUserRefundDay if err := db.Db.Where("records_id = ?", v.RecordsId).And("state != 3").And("id != ?", v.Id).Find(&mm); err != nil { fmt.Println(err) } var ids []int for _, vv := range mm { if vv.State == 4 { if v.State == 4 { fmt.Println(v, vv) } ids = append(ids, v.Id) alreadyIds[v.Id] = true } else { ids = append(ids, vv.Id) alreadyIds[vv.Id] = true } } if len(ids) > 0 { db.Db.In("id", ids).Delete(model.CentralKitchenForSchoolUserRefundDay{}) } } } 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") }