From 49f56cee1e2285fd32c43f35e3622d2ed6c5fec3 Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期六, 26 八月 2023 20:09:07 +0800 Subject: [PATCH] plc tag --- api/v1/task.go | 28 ++++++++++++++++++++++++---- 1 files changed, 24 insertions(+), 4 deletions(-) diff --git a/api/v1/task.go b/api/v1/task.go index 48484b3..d545b26 100644 --- a/api/v1/task.go +++ b/api/v1/task.go @@ -23,6 +23,28 @@ type TaskApi struct{} +// TaskCountdown +// @Tags Task +// @Summary 鏂颁换鍔″�掕鏃� +// @Produce application/json +// @Success 200 {object} contextx.Response{data=response.TaskCountdown} "鎴愬姛" +// @Router /v1/task/countdown [get] +func (slf *TaskApi) TaskCountdown(c *gin.Context) { + ctx, ok := contextx.NewContext(c, nil) + if !ok { + return + } + var resp response.TaskCountdown + workOrder, err := service.NewTaskService().GetComingTask() + if err == nil { + seconds := workOrder.StartTime - time.Now().Unix() + resp.CountDownHour = seconds / 3600 + resp.CountDownMinute = seconds % 3600 / 60 + resp.ShowCountDown = true + } + ctx.OkWithDetailed(resp) +} + // TaskGet // @Tags Task // @Summary 鑾峰彇浠诲姟 @@ -243,11 +265,10 @@ if code != ecode.OK { return errors.New("璇峰厛閰嶇疆PLC") } - conn, err := plc.NewModbusConnection(fmt.Sprintf("%s:%v", plcConfig.Address, plcConfig.Port)) + conn, err := plc.GetModbusConnection(fmt.Sprintf("%s:%v", plcConfig.Address, plcConfig.Port)) if err != nil { return errors.New(fmt.Sprintf("杩炴帴plc澶辫触: %v", err.Error())) } - defer conn.Close() logx.Info("----------------寮�濮嬩笅鍙戝伐鑹哄弬鏁�-----------------") for k, v := range paramsMap { @@ -275,11 +296,10 @@ if code != ecode.OK { return errors.New("璇峰厛閰嶇疆PLC") } - conn, err := plc.NewModbusConnection(fmt.Sprintf("%s:%v", plcConfig.Address, plcConfig.Port)) + conn, err := plc.GetModbusConnection(fmt.Sprintf("%s:%v", plcConfig.Address, plcConfig.Port)) if err != nil { return errors.New(fmt.Sprintf("杩炴帴plc澶辫触: %v", err.Error())) } - defer conn.Close() logx.Info("----------------寮�濮嬩笅鍙戝伐鑹哄弬鏁�-----------------") var missNumbers int -- Gitblit v1.8.0