From 73b6baf6af3d88cdcb0e2df7932a9bd96b0b85c5 Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期一, 01 七月 2024 22:32:34 +0800 Subject: [PATCH] 月度统计出入库按类型汇总报表定时任务和手动跑任务接口 --- main.go | 76 +++++++++++++++++++++++++++++++++---- 1 files changed, 67 insertions(+), 9 deletions(-) diff --git a/main.go b/main.go index caf375b..a2ea7c2 100644 --- a/main.go +++ b/main.go @@ -1,16 +1,26 @@ package main import ( + "context" + "fmt" + "google.golang.org/grpc" + "net" "net/http" "os" "os/signal" "syscall" "time" "wms/conf" - "wms/constvar" "wms/models" "wms/pkg/logx" + "wms/proto/init_client" + "wms/proto/inventory_order" + "wms/proto/product_inventory" + "wms/proto/purchase_wms" "wms/router" + "wms/service" + "wms/task" + "wms/utils/dingtalkrobot" ) func main() { @@ -30,10 +40,6 @@ return } - // 鍚姩APS RPC鏈嶅姟 - //safe.Go(service.StartAPServer) - - go shutdown() logx.Infof("aps-server start serve...") server := &http.Server{ Addr: ":" + conf.WebConf.Port, @@ -41,16 +47,68 @@ ReadTimeout: 5 * time.Second, WriteTimeout: 5 * time.Second, } + go shutdown(server) + //鍚姩grpc瀹㈡埛绔� + //go controllers.InitInventoryOrderServiceConn() + //go controllers.InitProductInventoryServiceConn() + //go controllers.InitCodeServiceConn() + //go supplier.InitConn() + //go client.InitConn() + go init_client.InitClient() + //鍚姩grpc鏈嶅姟 + go func() { + ln, err := net.Listen("tcp", ":"+conf.WebConf.GrpcPort) + if err != nil { + logx.Errorf("grpc server init error: %v", err.Error()) + panic(fmt.Sprintf("grpc server init error: %v", err.Error())) + } + s := grpc.NewServer() + //todo 娣诲姞鍏蜂綋鏈嶅姟 + product_inventory.RegisterProductInventoryServiceServer(s, &product_inventory.Server{}) + purchase_wms.RegisterPurchaseServiceServer(s, &purchase_wms.Server{}) + inventory_order.RegisterInventoryOrderServiceServer(s, &inventory_order.Server{}) + err = s.Serve(ln) + if err != nil { + logx.Errorf("grpc server init error: %v", err.Error()) + panic(fmt.Sprintf("grpc server init error: %v", err.Error())) + } + }() + + go service.InitLocationReportData() + go service.InitHistoryReportData() + + //瀹氭椂浠诲姟鍒濆鍖� + if err := task.Init(); err != nil { + logx.Errorf("task init error: %v", err.Error()) + return + } + + //閽夐拤鏈哄櫒浜哄垵濮嬪寲 + dingtalkrobot.Init(conf.DingTalkConf.AlarmKey, conf.DingTalkConf.AlarmUrl) logx.Error(server.ListenAndServe().Error()) } -func shutdown() { +func shutdown(server *http.Server) { quit := make(chan os.Signal, 1) signal.Notify(quit, syscall.SIGKILL, syscall.SIGQUIT, syscall.SIGINT, syscall.SIGTERM) <-quit - _ = constvar.GrpcClient.Close() - logx.Infof("aps-server exited...") - os.Exit(0) + logx.Infof("server exiting...") + // 鍒涘缓涓�涓笂涓嬫枃锛岃缃秴鏃舵椂闂� + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + + //controllers.CloseInventoryOrderServiceConn() + //controllers.CloseProductInventoryServiceConn() + //controllers.CloseCodeServiceConn() + //supplier.CloseConn() + //client.CloseConn() + init_client.CloseClient() + // 鍏抽棴HTTP鏈嶅姟鍣� + if err := server.Shutdown(ctx); err != nil { + logx.Infof("鏈嶅姟浼橀泤閫�鍑哄け璐�: %v", err) + return + } + logx.Infof("server exited") } -- Gitblit v1.8.0