| | |
| | | ctx.Fail(code) |
| | | return |
| | | } |
| | | var oldProcessModel *model.ProcessModel |
| | | if procedure.ProcessModelNumber != "" { |
| | | oldProcessModel, _ = service.GetProcessModelByNumber(procedure.ProcessModelNumber) |
| | | } |
| | | |
| | | oldProcessModel, _ := service.GetProcessModelByNumber(procedure.ProcessModelNumber) |
| | | offset, limit, push := GetOffsetAndLimit(oldProcessModel, 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 |
| | | } |
| | | |
| | | if push { //粘在前面 |
| | | if unShift && oldProcessModel != nil { //粘在前面 |
| | | list = append([]*model.ProcessModel{oldProcessModel}, list...) |
| | | } |
| | | for _, processModel := range list { |
| | | if processModel.Procedure == oldProcessModel.Procedure && processModel.Product == oldProcessModel.Product { |
| | | if oldProcessModel != nil && processModel.Procedure == oldProcessModel.Procedure && processModel.Product == oldProcessModel.Product { |
| | | processModel.IsUpdate = processModel.Number != procedure.ProcessModelNumber |
| | | } |
| | | if processModel.IsUpdate { |
| | |
| | | ctx.ResultList(list, total) |
| | | } |
| | | |
| | | func GetOffsetAndLimit(current *model.ProcessModel, page, pageSize int) (offset, limit int, push bool) { |
| | | func GetOffsetAndLimit(current *model.ProcessModel, page, pageSize int) (offset, limit int, unShift bool) { |
| | | //isNew是要更新的 |
| | | unShift = current != nil && current.IsNew && page == 1 |
| | | limit = pageSize |
| | | if unShift { |
| | | limit-- //如果是新的,第一页少查一个 |
| | | } |
| | | offset = (page - 1) * pageSize |
| | | if current.IsNew { |
| | | if current != nil && current.IsNew && offset > 0 { //如果是新的,第二页开始偏移量左移一个 |
| | | offset-- |
| | | } |
| | | push = current.IsNew && page == 1 |
| | | limit = pageSize |
| | | if push { |
| | | limit-- |
| | | } |
| | | return offset, limit, push |
| | | |
| | | return offset, limit, unShift |
| | | } |