From 3bf242225e26ee3b967461ac43df1eb8e0f6e424 Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期二, 14 十一月 2023 13:39:21 +0800 Subject: [PATCH] fix --- api/v1/process_model.go | 39 +++++++++++++++++++++++++++++++++------ 1 files changed, 33 insertions(+), 6 deletions(-) diff --git a/api/v1/process_model.go b/api/v1/process_model.go index 64becd0..c15b609 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" @@ -23,23 +24,49 @@ if !ok { return } + procedure, code := service.NewTaskService().GetProcedureById(params.ProcedureId) + if code != ecode.OK { + ctx.Fail(code) + return + } + var oldProcessModel *model.ProcessModel + if procedure.ProcessModelNumber != "" { + oldProcessModel, _ = service.GetProcessModelByNumber(procedure.ProcessModelNumber) + } - list, total, err := service.GetProcessModelList(params.Page, params.PageSize) + offset, limit, unShift := GetOffsetAndLimit(oldProcessModel, params.Page, params.PageSize) + list, total, err := service.GetProcessModelList(offset, limit, procedure.ProcessModelNumber) if err != nil { ctx.Fail(ecode.DBErr) return } - oldProcessModel, _ := service.GetProcessModelByNumber(params.Number) + + if unShift && oldProcessModel != nil { //绮樺湪鍓嶉潰 + 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 oldProcessModel != nil && processModel.Procedure == oldProcessModel.Procedure && processModel.Product == oldProcessModel.Product { + processModel.IsUpdate = processModel.Number != procedure.ProcessModelNumber } if processModel.IsUpdate { - processModel.NewNumber, processModel.NewParamsMap = processModel.Number, processModel.ParamsMap processModel.Number, processModel.ParamsMap = oldProcessModel.Number, oldProcessModel.ParamsMap } } - ctx.ResultList(list, total) } + +func GetOffsetAndLimit(current *model.ProcessModel, page, pageSize int) (offset, limit int, unShift bool) { + //isNew鏄鏇存柊鐨� + unShift = current != nil && page == 1 + limit = pageSize + if unShift { + limit-- //濡傛灉鏄柊鐨勶紝绗竴椤靛皯鏌ヤ竴涓� + } + offset = (page - 1) * pageSize + if current != nil && offset > 0 { //濡傛灉鏄柊鐨勶紝绗簩椤靛紑濮嬪亸绉婚噺宸︾Щ涓�涓� + offset-- + } + + return offset, limit, unShift +} -- Gitblit v1.8.0