From dfd43d9dd92124e5ed7e0aa20191f71c049f0c78 Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Fri, 16 Sep 2022 11:05:52 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA):=20?= =?UTF-8?q?=E6=A8=A1=E6=9D=BF=E4=BF=9D=E5=AD=98=E5=90=8E=E5=85=B3=E8=81=94?= =?UTF-8?q?=E7=9A=84=E8=87=AA=E5=AE=9A=E4=B9=89=E5=AD=97=E6=AE=B5=E5=B1=95?= =?UTF-8?q?=E7=A4=BA=E9=A1=BA=E5=BA=8F=E4=BC=9A=E5=8F=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1016758 --user=陈建星 【项目设置】模版管理-缺陷模版,编辑模版,不做任何操作,点击保存,字段顺序会变+【github #17895】 https://www.tapd.cn/55049933/s/1243736 --- .../base/mapper/ext/ExtCustomFieldTemplateMapper.java | 2 ++ .../base/mapper/ext/ExtCustomFieldTemplateMapper.xml | 8 ++++++++ .../service/CustomFieldTemplateService.java | 10 +++++++--- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtCustomFieldTemplateMapper.java b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtCustomFieldTemplateMapper.java index edd8cea635..4ba95979b7 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtCustomFieldTemplateMapper.java +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtCustomFieldTemplateMapper.java @@ -17,4 +17,6 @@ public interface ExtCustomFieldTemplateMapper { List getSystemCustomField(@Param("templateId") String templateId, @Param("fieldName") String fieldName); void batchInsert(@Param("customFieldTemplates") List customFieldTemplates); + + Long getLastOrder(@Param("templateId") String templateId, @Param("baseOrder") Long baseOrder); } diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtCustomFieldTemplateMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtCustomFieldTemplateMapper.xml index b626176385..7d36db607a 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtCustomFieldTemplateMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtCustomFieldTemplateMapper.xml @@ -18,6 +18,7 @@ where cft.template_id = #{request.templateId} + order by `order` asc + INSERT INTO diff --git a/backend/src/main/java/io/metersphere/service/CustomFieldTemplateService.java b/backend/src/main/java/io/metersphere/service/CustomFieldTemplateService.java index 5755748cac..5626f7e8fe 100644 --- a/backend/src/main/java/io/metersphere/service/CustomFieldTemplateService.java +++ b/backend/src/main/java/io/metersphere/service/CustomFieldTemplateService.java @@ -1,12 +1,12 @@ package io.metersphere.service; - import io.metersphere.base.domain.CustomField; import io.metersphere.base.domain.CustomFieldTemplate; import io.metersphere.base.domain.CustomFieldTemplateExample; import io.metersphere.base.mapper.CustomFieldMapper; import io.metersphere.base.mapper.CustomFieldTemplateMapper; import io.metersphere.base.mapper.ext.ExtCustomFieldTemplateMapper; +import io.metersphere.commons.utils.ServiceUtils; import io.metersphere.dto.CustomFieldDao; import io.metersphere.dto.CustomFieldTemplateDao; import org.apache.commons.collections.CollectionUtils; @@ -44,6 +44,7 @@ public class CustomFieldTemplateService { public List getCustomFields(String templateId) { CustomFieldTemplateExample example = new CustomFieldTemplateExample(); example.createCriteria().andTemplateIdEqualTo(templateId); + example.setOrderByClause("`order` asc"); return customFieldTemplateMapper.selectByExample(example); } @@ -110,15 +111,18 @@ public class CustomFieldTemplateService { CustomFieldTemplateMapper customFieldTemplateMapper = sqlSession.getMapper(CustomFieldTemplateMapper.class); if (CollectionUtils.isNotEmpty(customFields)) { - customFields.forEach(item -> { + Long nextOrder = ServiceUtils.getNextOrder(templateId, extCustomFieldTemplateMapper::getLastOrder); + for (CustomFieldTemplate item : customFields) { item.setId(UUID.randomUUID().toString()); item.setTemplateId(templateId); item.setScene(scene); if (item.getRequired() == null) { item.setRequired(false); } + nextOrder += ServiceUtils.ORDER_STEP; + item.setOrder((int) nextOrder.longValue()); customFieldTemplateMapper.insert(item); - }); + } } sqlSession.flushStatements(); if (sqlSession != null && sqlSessionFactory != null) {