From 14fc2f577e2c0b7b146c1a430e9438f317ad5b0c Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期六, 23 九月 2023 14:14:27 +0800
Subject: [PATCH] 任务接收增加channel字段,postion字段改为channel

---
 api/v1/plc.go                |    6 
 service/plc.go               |    6 
 service/task.go              |   14 +-
 nsq/msg_handler.go           |    1 
 model/common/common.go       |    7 +
 model/procedures.go          |    2 
 docs/swagger.yaml            |   23 +++--
 crontask/cron_task.go        |   16 ++--
 docs/docs.go                 |   30 ++++---
 model/request/task.go        |    8 +-
 api/v1/task.go               |   14 +-
 docs/swagger.json            |   30 ++++---
 service/cache_store.go       |   38 ++++----
 service/progress.go          |   18 ++--
 model/device_plc.go          |    2 
 model/production_progress.go |   10 +-
 model/response/common.go     |    2 
 17 files changed, 120 insertions(+), 107 deletions(-)

diff --git a/api/v1/plc.go b/api/v1/plc.go
index 47cf4bc..85624bd 100644
--- a/api/v1/plc.go
+++ b/api/v1/plc.go
@@ -31,8 +31,8 @@
 	if !ok {
 		return
 	}
-	finishNumber, _ := service.PlcCacheGet(params.Position, constvar.PlcCacheKeyFinishNumber)
-	totalNumber, _ := service.PlcCacheGet(params.Position, constvar.PlcCacheKeyTotalNumber)
+	finishNumber, _ := service.PlcCacheGet(params.Channel, constvar.PlcCacheKeyFinishNumber)
+	totalNumber, _ := service.PlcCacheGet(params.Channel, constvar.PlcCacheKeyTotalNumber)
 	resp := new(response.ProductProgress)
 	resp.FinishNumber = cast.ToInt(finishNumber)
 	resp.TotalNumber = cast.ToInt(totalNumber)
@@ -40,7 +40,7 @@
 	plcStatus := 1 //鏂紑杩炴帴
 	isConnect := service.PlcIsConnect()
 	if isConnect {
-		lastUpdateTime := service.FinishUpdateTimeGet(params.Position)
+		lastUpdateTime := service.FinishUpdateTimeGet(params.Channel)
 		if time.Now().Unix()-cast.ToInt64(lastUpdateTime) < conf.Conf.PLC.StandbyTime { //鐢熶骇
 			plcStatus = 2
 		} else {
diff --git a/api/v1/task.go b/api/v1/task.go
index 675caa8..2a15943 100644
--- a/api/v1/task.go
+++ b/api/v1/task.go
@@ -107,7 +107,7 @@
 		params.Page = 1
 	}
 	if params.PageSize <= 0 {
-		params.PageSize = 1
+		params.PageSize = 100
 	}
 
 	taskResponse, code := service.NewTaskService().GetTask(params.Page, params.PageSize, service.TaskModeUnStarted) //鏃堕棿鍒颁簡鏈紑濮嬬殑
@@ -201,7 +201,7 @@
 		ctx.Fail(code)
 		return
 	}
-	err := service.NewTaskService().UpdateProcedureStatus(nil, id, model.ProcedureStatusFinished, procedure.Position)
+	err := service.NewTaskService().UpdateProcedureStatus(nil, id, model.ProcedureStatusFinished, procedure.Channel)
 	if err != nil {
 		logx.Errorf("UpdateProcedureStatus err: %v", err.Error())
 		ctx.Fail(ecode.UnknownErr)
@@ -262,11 +262,11 @@
 	}
 
 	err = model.WithTransaction(func(db *gorm.DB) error {
-		err = taskService.UpdateProcedureStatusAndPosition(db, params.ProcedureId, model.ProcedureStatusProcessing, params.Position)
+		err = taskService.UpdateProcedureStatusAndChannel(db, params.ProcedureId, model.ProcedureStatusProcessing, params.Channel)
 		if err != nil {
 			return err
 		}
-		procedure.Position = params.Position
+		procedure.Channel = params.Channel
 		err = taskService.UpdateOrderStatus(db, order.ID, model.OrderStatusProcessing)
 		if err != nil {
 			return err
@@ -288,11 +288,11 @@
 	if err != nil {
 		logx.Errorf("SendProcessParams: %v", err.Error())
 		err = model.WithTransaction(func(db *gorm.DB) error {
-			err = taskService.UpdateProcedureStatusAndPosition(db, params.ProcedureId, model.ProcedureStatusWaitProcess, params.Position)
+			err = taskService.UpdateProcedureStatusAndChannel(db, params.ProcedureId, model.ProcedureStatusWaitProcess, params.Channel)
 			if err != nil {
 				return err
 			}
-			procedure.Position = params.Position
+			procedure.Channel = params.Channel
 			err = taskService.UpdateOrderStatus(db, order.ID, model.OrderStatusWaitProcess)
 			if err != nil {
 				return err
@@ -307,7 +307,7 @@
 		return
 	}
 	plcConfig.CurrentTryTimes = 0
-	err = service.PlcWrite(plcConfig, constvar.PlcStartAddressTypeTotalNumber, params.Position, order.Amount.IntPart())
+	err = service.PlcWrite(plcConfig, constvar.PlcStartAddressTypeTotalNumber, params.Channel, order.Amount.IntPart())
 	if err != nil {
 		ctx.FailWithMsg(ecode.NeedConfirmedErr, "绯熺硶锛屽伐鑹轰笅鍙戝け璐ャ��")
 		return
diff --git a/crontask/cron_task.go b/crontask/cron_task.go
index 9938bb4..9454dbe 100644
--- a/crontask/cron_task.go
+++ b/crontask/cron_task.go
@@ -38,8 +38,8 @@
 				}
 				finishNumber := cast.ToInt64(value)
 				if finishNumber != 0 {
-					service.PlcCacheSet(addressItem.Position, constvar.PlcCacheKeyFinishNumber, finishNumber)
-					_ = service.NewProgressService().UpdateProgress(addressItem.Position, cast.ToInt64(finishNumber))
+					service.PlcCacheSet(addressItem.Channel, constvar.PlcCacheKeyFinishNumber, finishNumber)
+					_ = service.NewProgressService().UpdateProgress(addressItem.Channel, cast.ToInt64(finishNumber))
 				}
 				logx.Infof("plc read finish number: %v", finishNumber)
 			}
@@ -64,8 +64,8 @@
 				}
 				totalNumber := cast.ToInt64(value)
 				if totalNumber != 0 {
-					service.PlcCacheSet(addressItem.Position, constvar.PlcCacheKeyTotalNumber, totalNumber)
-					_ = service.NewProgressService().UpdateProgress(addressItem.Position, cast.ToInt64(totalNumber))
+					service.PlcCacheSet(addressItem.Channel, constvar.PlcCacheKeyTotalNumber, totalNumber)
+					_ = service.NewProgressService().UpdateProgress(addressItem.Channel, cast.ToInt64(totalNumber))
 				}
 				logx.Infof("plc read total number: %v", totalNumber)
 			}
@@ -83,14 +83,14 @@
 	if code != ecode.OK {
 		return
 	}
-	var positions []int
+	var channels []int32
 	for _, item := range plcConfig.Details {
 		if item.FieldName == constvar.PlcStartAddressTypeFinishNumber {
-			positions = append(positions, item.Position)
+			channels = append(channels, item.Channel)
 		}
 	}
-	for _, position := range positions {
-		progress, err := service.NewProgressService().GetCurrentProgress(position)
+	for _, channel := range channels {
+		progress, err := service.NewProgressService().GetCurrentProgress(channel)
 		if err != nil {
 			return
 		}
diff --git a/docs/docs.go b/docs/docs.go
index 87355c3..b41553d 100644
--- a/docs/docs.go
+++ b/docs/docs.go
@@ -634,6 +634,10 @@
                         "type": "string"
                     }
                 },
+                "channel": {
+                    "description": "閫氶亾搴忓彿",
+                    "type": "integer"
+                },
                 "deviceId": {
                     "type": "string"
                 },
@@ -775,6 +779,10 @@
         "model.DevicePlcAddress": {
             "type": "object",
             "properties": {
+                "channel": {
+                    "description": "鏁版嵁璧峰鍦板潃",
+                    "type": "integer"
+                },
                 "fieldName": {
                     "description": "瀵瑰簲绯荤粺瀛楁",
                     "allOf": [
@@ -785,10 +793,6 @@
                 },
                 "length": {
                     "description": "鏁版嵁闀垮害",
-                    "type": "integer"
-                },
-                "position": {
-                    "description": "鏁版嵁璧峰鍦板潃",
                     "type": "integer"
                 },
                 "startAddress": {
@@ -947,6 +951,10 @@
         "model.Procedures": {
             "type": "object",
             "properties": {
+                "channel": {
+                    "description": "閫氶亾",
+                    "type": "integer"
+                },
                 "deviceId": {
                     "type": "string"
                 },
@@ -954,10 +962,6 @@
                     "type": "integer"
                 },
                 "id": {
-                    "type": "integer"
-                },
-                "position": {
-                    "description": "姣忎釜璁惧鍙兘鏈夊涓満浣嶅悓鏃剁敓浜э紝鐢╬osition琛ㄧず浣嶇疆",
                     "type": "integer"
                 },
                 "procedure": {
@@ -996,7 +1000,7 @@
                 "procedureId"
             ],
             "properties": {
-                "position": {
+                "channel": {
                     "type": "integer"
                 },
                 "procedureId": {
@@ -1136,15 +1140,15 @@
                     "description": "鏄惁鍙互寮�濮嬬敓浜�",
                     "type": "boolean"
                 },
+                "channel": {
+                    "description": "褰撳墠浠诲姟鍦ㄨ澶囩鍑犱釜閫氶亾",
+                    "type": "integer"
+                },
                 "currentProcedureIndex": {
                     "type": "integer"
                 },
                 "order": {
                     "$ref": "#/definitions/model.Order"
-                },
-                "position": {
-                    "description": "褰撳墠浠诲姟鍦ㄨ澶囩鍑犱釜浣嶇疆",
-                    "type": "integer"
                 },
                 "procedure": {
                     "$ref": "#/definitions/model.Procedures"
diff --git a/docs/swagger.json b/docs/swagger.json
index e3d2b43..b8b0852 100644
--- a/docs/swagger.json
+++ b/docs/swagger.json
@@ -622,6 +622,10 @@
                         "type": "string"
                     }
                 },
+                "channel": {
+                    "description": "閫氶亾搴忓彿",
+                    "type": "integer"
+                },
                 "deviceId": {
                     "type": "string"
                 },
@@ -763,6 +767,10 @@
         "model.DevicePlcAddress": {
             "type": "object",
             "properties": {
+                "channel": {
+                    "description": "鏁版嵁璧峰鍦板潃",
+                    "type": "integer"
+                },
                 "fieldName": {
                     "description": "瀵瑰簲绯荤粺瀛楁",
                     "allOf": [
@@ -773,10 +781,6 @@
                 },
                 "length": {
                     "description": "鏁版嵁闀垮害",
-                    "type": "integer"
-                },
-                "position": {
-                    "description": "鏁版嵁璧峰鍦板潃",
                     "type": "integer"
                 },
                 "startAddress": {
@@ -935,6 +939,10 @@
         "model.Procedures": {
             "type": "object",
             "properties": {
+                "channel": {
+                    "description": "閫氶亾",
+                    "type": "integer"
+                },
                 "deviceId": {
                     "type": "string"
                 },
@@ -942,10 +950,6 @@
                     "type": "integer"
                 },
                 "id": {
-                    "type": "integer"
-                },
-                "position": {
-                    "description": "姣忎釜璁惧鍙兘鏈夊涓満浣嶅悓鏃剁敓浜э紝鐢╬osition琛ㄧず浣嶇疆",
                     "type": "integer"
                 },
                 "procedure": {
@@ -984,7 +988,7 @@
                 "procedureId"
             ],
             "properties": {
-                "position": {
+                "channel": {
                     "type": "integer"
                 },
                 "procedureId": {
@@ -1124,15 +1128,15 @@
                     "description": "鏄惁鍙互寮�濮嬬敓浜�",
                     "type": "boolean"
                 },
+                "channel": {
+                    "description": "褰撳墠浠诲姟鍦ㄨ澶囩鍑犱釜閫氶亾",
+                    "type": "integer"
+                },
                 "currentProcedureIndex": {
                     "type": "integer"
                 },
                 "order": {
                     "$ref": "#/definitions/model.Order"
-                },
-                "position": {
-                    "description": "褰撳墠浠诲姟鍦ㄨ澶囩鍑犱釜浣嶇疆",
-                    "type": "integer"
                 },
                 "procedure": {
                     "$ref": "#/definitions/model.Procedures"
diff --git a/docs/swagger.yaml b/docs/swagger.yaml
index db53996..3ad2a98 100644
--- a/docs/swagger.yaml
+++ b/docs/swagger.yaml
@@ -30,6 +30,9 @@
         items:
           type: string
         type: array
+      channel:
+        description: 閫氶亾搴忓彿
+        type: integer
       deviceId:
         type: string
       deviceName:
@@ -131,15 +134,15 @@
     type: object
   model.DevicePlcAddress:
     properties:
+      channel:
+        description: 鏁版嵁璧峰鍦板潃
+        type: integer
       fieldName:
         allOf:
         - $ref: '#/definitions/constvar.PlcStartAddressType'
         description: 瀵瑰簲绯荤粺瀛楁
       length:
         description: 鏁版嵁闀垮害
-        type: integer
-      position:
-        description: 鏁版嵁璧峰鍦板潃
         type: integer
       startAddress:
         description: 鏁版嵁璧峰鍦板潃
@@ -248,14 +251,14 @@
     - ProcedureStatusFinished
   model.Procedures:
     properties:
+      channel:
+        description: 閫氶亾
+        type: integer
       deviceId:
         type: string
       endTime:
         type: integer
       id:
-        type: integer
-      position:
-        description: 姣忎釜璁惧鍙兘鏈夊涓満浣嶅悓鏃剁敓浜э紝鐢╬osition琛ㄧず浣嶇疆
         type: integer
       procedure:
         allOf:
@@ -277,7 +280,7 @@
     type: object
   request.SendProcessParams:
     properties:
-      position:
+      channel:
         type: integer
       procedureId:
         type: integer
@@ -375,13 +378,13 @@
       canStarted:
         description: 鏄惁鍙互寮�濮嬬敓浜�
         type: boolean
+      channel:
+        description: 褰撳墠浠诲姟鍦ㄨ澶囩鍑犱釜閫氶亾
+        type: integer
       currentProcedureIndex:
         type: integer
       order:
         $ref: '#/definitions/model.Order'
-      position:
-        description: 褰撳墠浠诲姟鍦ㄨ澶囩鍑犱釜浣嶇疆
-        type: integer
       procedure:
         $ref: '#/definitions/model.Procedures'
     type: object
diff --git a/model/common/common.go b/model/common/common.go
index 5eafc0d..f169626 100644
--- a/model/common/common.go
+++ b/model/common/common.go
@@ -51,6 +51,7 @@
 		OutputMaterials   []*ProcedureMaterial `json:"outputMaterials"`   // 杈撳嚭鐗╂枡鍒楄〃
 		Workers           []*ProcedureWorker   `json:"workers"`           // 浜哄憳鍒楄〃
 		AllProcedureNames []string             `json:"allProcedureNames"` // 鎵�灞炲伐鍗曞伐搴忓垪琛�
+		Channel           int32                `json:"channel"`           //閫氶亾搴忓彿
 	}
 
 	DeliverScheduleTask struct {
@@ -68,8 +69,8 @@
 		KeyData        []byte
 		AddressData    []byte
 		DeviceId       string
-		PlcAddressList []*PlcAddress
-		PlcConfig      PlcConfig
+		PlcAddressList []*PlcAddress //plc 瀹屾垚閲忥紝鎬婚噺锛� 璇诲啓鍦板潃
+		PlcConfig      PlcConfig     //鐢ㄧ綉鍙h繕鏄鍙d互鍙婄綉鍙p port
 	}
 
 	PlcConfig struct {
@@ -86,7 +87,7 @@
 
 	PlcAddress struct {
 		DeviceID     string                       `json:"deviceID"`     // 璁惧id
-		Position     int                          `json:"position"`     // 鐢熶骇浣嶇疆锛屼竴涓満鍣ㄥ彲鑳芥湁澶氫釜鏈轰綅锛岄渶瑕佸垎鍒厤缃畃lc鍦板潃
+		Channel      int                          `json:"channel"`      // 鐢熶骇閫氶亾on锛屼竴涓満鍣ㄥ彲鑳芥湁澶氫釜鏈轰綅锛岄渶瑕佸垎鍒厤缃畃lc鍦板潃
 		StartAddress int                          `json:"startAddress"` // 鏁版嵁璧峰鍦板潃
 		Length       int                          `json:"length"`       // 鏁版嵁闀垮害
 		Type         string                       `json:"type"`         // 鏁版嵁绫诲瀷
diff --git a/model/device_plc.go b/model/device_plc.go
index 728488d..fc8330e 100644
--- a/model/device_plc.go
+++ b/model/device_plc.go
@@ -33,7 +33,7 @@
 	}
 
 	DevicePlcAddress struct {
-		Position     int                               `json:"position"`     // 鏁版嵁璧峰鍦板潃
+		Channel      int32                             `json:"channel"`      // 鏁版嵁璧峰鍦板潃
 		StartAddress int                               `json:"startAddress"` // 鏁版嵁璧峰鍦板潃
 		Length       int                               `json:"length"`       // 鏁版嵁闀垮害
 		Type         constvar.PlcStartAddressValueType `json:"type"`         // 鏁版嵁绫诲瀷
diff --git a/model/procedures.go b/model/procedures.go
index 8933c88..8d893e6 100644
--- a/model/procedures.go
+++ b/model/procedures.go
@@ -17,7 +17,7 @@
 		OrderID        string `gorm:"index;type:varchar(191);not null;comment:璁㈠崟ID" json:"-"`
 		DeviceID       string `gorm:"index;type:varchar(191);comment:璁惧ID" json:"deviceId"`
 		ProcedureID    string `gorm:"index;type:varchar(191);comment:宸ュ簭ID" json:"procedureId"`
-		Position       int    `gorm:"type:int;comment:宸ヤ綔浣嶇疆" json:"position"` //姣忎釜璁惧鍙兘鏈夊涓満浣嶅悓鏃剁敓浜э紝鐢╬osition琛ㄧず浣嶇疆
+		Channel        int32  `gorm:"index;comment:閫氶亾" json:"channel"` //閫氶亾
 		StartTime      int64  `gorm:"comment:璁″垝寮�濮嬫椂闂�" json:"startTime"`
 		EndTime        int64  `gorm:"comment:璁″垝缁撴潫鏃堕棿" json:"endTime"`
 		Status         ProcedureStatus
diff --git a/model/production_progress.go b/model/production_progress.go
index 898b186..4a159af 100644
--- a/model/production_progress.go
+++ b/model/production_progress.go
@@ -15,7 +15,7 @@
 		ProcedureID      string `gorm:"type:varchar(191);comment:宸ュ簭ID" json:"procedureId"`
 		DeviceID         string `gorm:"type:varchar(191);not null;comment:璁惧ID" json:"deviceId"`
 		FinishedQuantity int64  `gorm:"type:int;not null;comment:瀹屾垚鏁伴噺" json:"finishedQuantity"`
-		Position         int    `gorm:"type:int;comment:宸ヤ綔浣嶇疆" json:"position"` //姣忎釜璁惧鍙兘鏈夊涓満浣嶅悓鏃剁敓浜э紝鐢╬osition琛ㄧず浣嶇疆
+		Channel          int32  `gorm:"type:int;comment:宸ヤ綔閫氶亾" json:"channel"` //閫氶亾
 		TotalQuantity    int64  `gorm:"type:int;not null;comment:鎬婚噺" json:"totalQuantity"`
 	}
 
@@ -74,8 +74,8 @@
 	return slf
 }
 
-func (slf *ProductionProgressSearch) SetPosition(position int) *ProductionProgressSearch {
-	slf.Position = position
+func (slf *ProductionProgressSearch) SetChannel(channel int32) *ProductionProgressSearch {
+	slf.Channel = channel
 	return slf
 }
 
@@ -106,8 +106,8 @@
 		db = db.Where("device_id = ?", slf.DeviceID)
 	}
 
-	if slf.Position != 0 {
-		db = db.Where("position = ?", slf.Position)
+	if slf.Channel != 0 {
+		db = db.Where("channel = ?", slf.Channel)
 	}
 
 	return db
diff --git a/model/request/task.go b/model/request/task.go
index 37f4a66..a3d78b6 100644
--- a/model/request/task.go
+++ b/model/request/task.go
@@ -15,11 +15,11 @@
 }
 
 type SendProcessParams struct {
-	ProcedureId int `json:"procedureId" binding:"required"`
-	Position    int `json:"position"`
+	ProcedureId int   `json:"procedureId" binding:"required"`
+	Channel     int32 `json:"channel"`
 }
 
 type GetProductProgress struct {
-	ProcedureId int `json:"procedureId" binding:"required"`
-	Position    int `json:"position"`
+	ProcedureId int   `json:"procedureId" binding:"required"`
+	Channel     int32 `json:"channel"`
 }
diff --git a/model/response/common.go b/model/response/common.go
index 2779602..ee3ff27 100644
--- a/model/response/common.go
+++ b/model/response/common.go
@@ -24,7 +24,7 @@
 	Order     *model.Order
 	Procedure *model.Procedures
 
-	Position              int //褰撳墠浠诲姟鍦ㄨ澶囩鍑犱釜浣嶇疆
+	Channel               int32 //褰撳墠浠诲姟鍦ㄨ澶囩鍑犱釜閫氶亾
 	AllProcedures         []string
 	CurrentProcedureIndex int
 	CanStarted            bool //鏄惁鍙互寮�濮嬬敓浜�
diff --git a/nsq/msg_handler.go b/nsq/msg_handler.go
index b13dd4b..713c95a 100644
--- a/nsq/msg_handler.go
+++ b/nsq/msg_handler.go
@@ -59,6 +59,7 @@
 				StartTime:      procedure.StartTime,
 				EndTime:        procedure.EndTime,
 				Status:         model.ProcedureStatusWaitProcess,
+				Channel:        procedure.Channel,
 				ProceduresInfo: common.ProductProcedure{},
 			}
 			procedureData, err := json.Marshal(procedure)
diff --git a/service/cache_store.go b/service/cache_store.go
index 9b7b74d..325db21 100644
--- a/service/cache_store.go
+++ b/service/cache_store.go
@@ -47,36 +47,36 @@
 }
 
 const (
-	PlcCacheKey             = "plc:%v:%v" //plc:position:key
+	PlcCacheKey             = "plc:%v:%v" //plc:channel:key
 	CurrentTaskCacheKey     = "current_task"
-	CurrentProgressCacheKey = "current_progress:%v"          //current_progress:position
-	PlcCacheKeyUpdateTime   = "finish_number_update_time:%v" //finish_number_update_time:position
+	CurrentProgressCacheKey = "current_progress:%v"          //current_progress:channel
+	PlcCacheKeyUpdateTime   = "finish_number_update_time:%v" //finish_number_update_time:channel
 )
 
-func PlcCacheGet(position int, key string) (interface{}, bool) {
-	return defaultCacheStore.Get(fmt.Sprintf(PlcCacheKey, position, key))
+func PlcCacheGet(channel int32, key string) (interface{}, bool) {
+	return defaultCacheStore.Get(fmt.Sprintf(PlcCacheKey, channel, key))
 }
 
-func PlcCacheSet(position int, key string, value interface{}) {
+func PlcCacheSet(channel int32, key string, value interface{}) {
 	if key == constvar.PlcCacheKeyFinishNumber {
-		oldFinishNumber, exists := PlcCacheGet(position, key)
+		oldFinishNumber, exists := PlcCacheGet(channel, key)
 		if !exists || cast.ToInt(oldFinishNumber) != cast.ToInt(value) { //finishNumber鏈変簡鍙樺寲锛岃缃洿鏂版椂闂寸紦瀛�
-			FinishUpdateTimeSet(position, time.Now().Unix())
+			FinishUpdateTimeSet(channel, time.Now().Unix())
 		}
 	}
-	defaultCacheStore.Add(fmt.Sprintf(PlcCacheKey, position, key), value)
+	defaultCacheStore.Add(fmt.Sprintf(PlcCacheKey, channel, key), value)
 }
 
-func FinishUpdateTimeGet(position int) interface{} {
-	val, ok := defaultCacheStore.Get(fmt.Sprintf(PlcCacheKeyUpdateTime, position))
+func FinishUpdateTimeGet(channel int32) interface{} {
+	val, ok := defaultCacheStore.Get(fmt.Sprintf(PlcCacheKeyUpdateTime, channel))
 	if ok {
 		return val
 	}
 	return 0
 }
 
-func FinishUpdateTimeSet(position int, value interface{}) {
-	defaultCacheStore.Add(fmt.Sprintf(PlcCacheKeyUpdateTime, position), value)
+func FinishUpdateTimeSet(channel int32, value interface{}) {
+	defaultCacheStore.Add(fmt.Sprintf(PlcCacheKeyUpdateTime, channel), value)
 }
 
 func TaskCacheSet(value *response.TaskData) {
@@ -94,17 +94,17 @@
 	return nil, false
 }
 
-func ProgressCacheGet(position int) (*model.ProductionProgress, bool) {
-	if v, ok := defaultCacheStore.Get(fmt.Sprintf(CurrentProgressCacheKey, position)); ok {
+func ProgressCacheGet(channel int32) (*model.ProductionProgress, bool) {
+	if v, ok := defaultCacheStore.Get(fmt.Sprintf(CurrentProgressCacheKey, channel)); ok {
 		return v.(*model.ProductionProgress), ok
 	}
 	return nil, false
 }
 
-func ProgressCacheSet(position int, value *model.ProductionProgress) {
-	defaultCacheStore.Add(fmt.Sprintf(CurrentProgressCacheKey, position), value)
+func ProgressCacheSet(channel int32, value *model.ProductionProgress) {
+	defaultCacheStore.Add(fmt.Sprintf(CurrentProgressCacheKey, channel), value)
 }
 
-func ProgressCacheUnset(position int) {
-	defaultCacheStore.Remove(fmt.Sprintf(CurrentProgressCacheKey, position))
+func ProgressCacheUnset(channel int32) {
+	defaultCacheStore.Remove(fmt.Sprintf(CurrentProgressCacheKey, channel))
 }
diff --git a/service/plc.go b/service/plc.go
index 5388b0c..f73ec58 100644
--- a/service/plc.go
+++ b/service/plc.go
@@ -15,7 +15,7 @@
 	"github.com/spf13/cast"
 )
 
-func PlcWrite(plcConfig *model.DevicePlc, fieldType constvar.PlcStartAddressType, position int, value interface{}) (err error) {
+func PlcWrite(plcConfig *model.DevicePlc, fieldType constvar.PlcStartAddressType, channel int32, value interface{}) (err error) {
 	var (
 		startAddress int
 		ipAddr       string
@@ -27,7 +27,7 @@
 	plcConfig.CurrentTryTimes++
 
 	for _, pc := range plcConfig.Details {
-		if pc.FieldName == fieldType && pc.Position == position {
+		if pc.FieldName == fieldType && pc.Channel == channel {
 			startAddress = pc.StartAddress
 		}
 	}
@@ -39,7 +39,7 @@
 		if err != nil {
 			logx.Errorf("plc write failed, address: %v, value: %v, err: %v", startAddress, value, err.Error())
 			plcConfig.CurrentErr = err
-			return PlcWrite(plcConfig, fieldType, position, value)
+			return PlcWrite(plcConfig, fieldType, channel, value)
 		}
 		logx.Infof("plc write ok, address: %v, value: %v", startAddress, value)
 	} else if plcConfig.Method == constvar.PlcMethodSerial {
diff --git a/service/progress.go b/service/progress.go
index 9f19ae6..6eab830 100644
--- a/service/progress.go
+++ b/service/progress.go
@@ -22,20 +22,20 @@
 			ProcedureID:   procedure.ProceduresInfo.ProcedureID,
 			DeviceID:      procedure.DeviceID,
 			TotalQuantity: order.Amount.IntPart(),
-			Position:      procedure.Position,
+			Channel:       procedure.Channel,
 		}
 		err := model.NewProductionProgressSearch(db).Create(progress)
 		if err != nil {
 			return err
 		}
-		ProgressCacheSet(procedure.Position, progress)
+		ProgressCacheSet(procedure.Channel, progress)
 	}
 
 	return nil
 }
 
-func (slf ProgressService) UpdateProgress(position int, finishedQuantity int64) (err error) {
-	progressCache, err := slf.GetCurrentProgress(position)
+func (slf ProgressService) UpdateProgress(channel int32, finishedQuantity int64) (err error) {
+	progressCache, err := slf.GetCurrentProgress(channel)
 	if err != nil {
 		return err
 	}
@@ -44,17 +44,17 @@
 	}
 	if finishedQuantity > progressCache.FinishedQuantity { //褰撴湁鍙樺寲鏃舵墠鏇存柊
 		progressCache.FinishedQuantity = finishedQuantity
-		ProgressCacheSet(position, progressCache)
+		ProgressCacheSet(channel, progressCache)
 		return model.NewProductionProgressSearch(nil).SetId(progressCache.ID).Save(progressCache)
 	}
 	return nil
 }
 
-func (slf ProgressService) GetCurrentProgress(position int) (progressCache *model.ProductionProgress, err error) {
+func (slf ProgressService) GetCurrentProgress(channel int32) (progressCache *model.ProductionProgress, err error) {
 	var ok bool
-	progressCache, ok = ProgressCacheGet(position)
+	progressCache, ok = ProgressCacheGet(channel)
 	if !ok {
-		progressCache, err = model.NewProductionProgressSearch(nil).SetPosition(position).SetOrder("id desc").First()
+		progressCache, err = model.NewProductionProgressSearch(nil).SetChannel(channel).SetOrder("id desc").First()
 		if err == gorm.ErrRecordNotFound {
 			return nil, errors.New("progress not found")
 		}
@@ -66,7 +66,7 @@
 			progressCache = nil
 		}
 		if progressCache != nil {
-			ProgressCacheSet(position, progressCache)
+			ProgressCacheSet(channel, progressCache)
 		}
 	}
 	return
diff --git a/service/task.go b/service/task.go
index df0002e..30f5a3c 100644
--- a/service/task.go
+++ b/service/task.go
@@ -91,7 +91,7 @@
 			Procedure:             procedure,
 			AllProcedures:         procedure.ProceduresInfo.AllProcedureNames,
 			CurrentProcedureIndex: 0,
-			Position:              procedure.Position,
+			Channel:               procedure.Channel,
 		}
 		index := 0
 		for _, name := range procedure.ProceduresInfo.AllProcedureNames {
@@ -132,19 +132,19 @@
 	return procedure, ecode.OK
 }
 
-func (slf TaskService) UpdateProcedureStatusAndPosition(db *gorm.DB, id int, status model.ProcedureStatus, position int) error {
+func (slf TaskService) UpdateProcedureStatusAndChannel(db *gorm.DB, id int, status model.ProcedureStatus, channel int32) error {
 	if status == model.ProcedureStatusFinished {
-		ProgressCacheUnset(position)
+		ProgressCacheUnset(channel)
 	}
 	return model.NewProceduresSearch(db).SetId(id).UpdateByMap(map[string]interface{}{
-		"status":   status,
-		"position": position,
+		"status":  status,
+		"channel": channel,
 	})
 }
 
-func (slf TaskService) UpdateProcedureStatus(db *gorm.DB, id int, status model.ProcedureStatus, position int) error {
+func (slf TaskService) UpdateProcedureStatus(db *gorm.DB, id int, status model.ProcedureStatus, channel int32) error {
 	if status == model.ProcedureStatusFinished {
-		ProgressCacheUnset(position)
+		ProgressCacheUnset(channel)
 	}
 	return model.NewProceduresSearch(db).SetId(id).UpdateByMap(map[string]interface{}{
 		"status": status,

--
Gitblit v1.8.0