From 6b3135d32fc3c84be81b0876f1961994088e5dbf Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期一, 09 十月 2023 20:57:05 +0800
Subject: [PATCH] 当前使用的工艺编号置顶

---
 api/v1/process_model.go |   26 ++++++++++++++++++++++++--
 1 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/api/v1/process_model.go b/api/v1/process_model.go
index c20214b..61dad3b 100644
--- a/api/v1/process_model.go
+++ b/api/v1/process_model.go
@@ -1,6 +1,7 @@
 package v1
 
 import (
+	"apsClient/model"
 	"apsClient/model/request"
 	"apsClient/pkg/contextx"
 	"apsClient/pkg/ecode"
@@ -15,7 +16,7 @@
 // @Summary   鑾峰彇宸ヨ壓妯″瀷鍒楄〃
 // @Produce   application/json
 // @Param     object  query    request.ProcessModelList true  "鏌ヨ鍙傛暟"
-// @Success   200   {object}  contextx.Response{data=response.TaskCountdown}  "鎴愬姛"
+// @Success   200   {object}  contextx.Response{data=[]model.ProcessModel}  "鎴愬姛"
 // @Router    /v1/processModel/list [get]
 func (slf *ProcessModelApi) List(c *gin.Context) {
 	var params request.ProcessModelList
@@ -23,10 +24,31 @@
 	if !ok {
 		return
 	}
-	list, total, err := service.GetProcessModelList(params.Page, params.PageSize)
+
+	oldProcessModel, _ := service.GetProcessModelByNumber(params.Number)
+
+	if params.Page == 1 && oldProcessModel.IsNew { //灏戞煡涓�涓�
+		params.PageSize--
+	}
+
+	list, total, err := service.GetProcessModelList(params.Page, params.PageSize, params.Number)
 	if err != nil {
 		ctx.Fail(ecode.DBErr)
 		return
 	}
+
+	if params.Page == 1 && oldProcessModel.IsNew { //绮樺湪鍓嶉潰
+		list = append([]*model.ProcessModel{oldProcessModel}, list...)
+	}
+	for _, processModel := range list {
+		if processModel.Procedure == oldProcessModel.Procedure && processModel.Product == oldProcessModel.Product {
+			processModel.IsUpdate = processModel.Number != params.Number
+		}
+		if processModel.IsUpdate {
+			processModel.NewNumber, processModel.NewParamsMap = processModel.Number, processModel.ParamsMap
+			processModel.Number, processModel.ParamsMap = oldProcessModel.Number, oldProcessModel.ParamsMap
+		}
+	}
+
 	ctx.ResultList(list, total)
 }

--
Gitblit v1.8.0