智慧食堂
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

main_back.go 1.7 KiB

há 10 meses
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 main1() {
  17. var m []model.CentralKitchenForSchoolUserRefundDay
  18. if err := db.Db.Where("1=1").Desc("id").Find(&m); err != nil {
  19. fmt.Println(err)
  20. }
  21. var alreadyIds = map[int]bool{}
  22. for _, v := range m {
  23. if v.State != 3 && !alreadyIds[v.Id] {
  24. var mm []model.CentralKitchenForSchoolUserRefundDay
  25. if err := db.Db.Where("records_id = ?", v.RecordsId).And("state != 3").And("id != ?", v.Id).Find(&mm); err != nil {
  26. fmt.Println(err)
  27. }
  28. var ids []int
  29. for _, vv := range mm {
  30. if vv.State == 4 {
  31. if v.State == 4 {
  32. fmt.Println(v, vv)
  33. }
  34. ids = append(ids, v.Id)
  35. alreadyIds[v.Id] = true
  36. } else {
  37. ids = append(ids, vv.Id)
  38. alreadyIds[vv.Id] = true
  39. }
  40. }
  41. if len(ids) > 0 {
  42. db.Db.In("id", ids).Delete(model.CentralKitchenForSchoolUserRefundDay{})
  43. }
  44. }
  45. }
  46. r := router.Init() //创建路由
  47. srv := &http.Server{ //设置http服务参数
  48. Addr: cfg.SrvAddr, //指定ip和端口
  49. Handler: r, //指定路由
  50. }
  51. go func() { //协程启动监听http服务
  52. fmt.Println("Listening and serving HTTP on " + cfg.SrvAddr)
  53. if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
  54. log.Fatalf("listen: %s\n", err)
  55. }
  56. }()
  57. //退出go守护进程
  58. quit := make(chan os.Signal)
  59. signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
  60. <-quit
  61. log.Println("Shutting down server...")
  62. ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
  63. defer cancel()
  64. if err := srv.Shutdown(ctx); err != nil {
  65. log.Fatal("Server forced to shutdown:", err)
  66. }
  67. log.Println("Server exiting")
  68. }