fix(接口自动化): 模块同级别排序

This commit is contained in:
fit2-zhao 2020-12-25 18:00:05 +08:00
parent 1e180af32d
commit ee27fa0c5e
11 changed files with 75 additions and 10 deletions

View File

@ -59,4 +59,10 @@ public class ApiModuleController {
public void dragNode(@RequestBody DragModuleRequest node) {
apiModuleService.dragNode(node);
}
@PostMapping("/pos")
public void treeSort(@RequestBody List<String> ids) {
apiModuleService.sort(ids);
}
}

View File

@ -59,4 +59,10 @@ public class ApiScenarioModuleController {
public void dragNode(@RequestBody DragApiScenarioModuleRequest node) {
apiScenarioModuleService.dragNode(node);
}
@PostMapping("/pos")
public void treeSort(@RequestBody List<String> ids) {
apiScenarioModuleService.sort(ids);
}
}

View File

@ -1,6 +1,7 @@
package io.metersphere.api.service;
import com.alibaba.fastjson.JSON;
import io.metersphere.api.dto.definition.ApiDefinitionRequest;
import io.metersphere.api.dto.definition.ApiDefinitionResult;
import io.metersphere.api.dto.definition.ApiModuleDTO;
@ -12,11 +13,9 @@ import io.metersphere.base.mapper.ext.ExtApiDefinitionMapper;
import io.metersphere.base.mapper.ext.ExtApiModuleMapper;
import io.metersphere.commons.constants.TestCaseConstants;
import io.metersphere.commons.exception.MSException;
import io.metersphere.i18n.Translator;
import io.metersphere.service.NodeTreeService;
import io.metersphere.service.ProjectService;
import io.metersphere.track.dto.TestCaseNodeDTO;
import io.metersphere.track.service.TestPlanApiCaseService;
import io.metersphere.track.service.TestPlanProjectService;
import org.apache.commons.lang3.StringUtils;
@ -148,7 +147,19 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
private void checkApiModuleExist(ApiModule node) {
if (node.getName() != null) {
if (selectSameModule(node).size() > 0) {
ApiModuleExample example = new ApiModuleExample();
ApiModuleExample.Criteria criteria = example.createCriteria();
criteria.andNameEqualTo(node.getName())
.andProjectIdEqualTo(node.getProjectId());
if (StringUtils.isNotBlank(node.getParentId())) {
criteria.andParentIdEqualTo(node.getParentId());
} else {
criteria.andParentIdIsNull();
}
if (StringUtils.isNotBlank(node.getId())) {
criteria.andIdNotEqualTo(node.getId());
}
if (apiModuleMapper.selectByExample(example).size() > 0) {
MSException.throwException(Translator.get("test_case_module_already_exists") + ": " + node.getName());
}
}
@ -216,6 +227,18 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
sqlSession.flushStatements();
}
@Override
public ApiModuleDTO getNode(String id) {
ApiModule module = apiModuleMapper.selectByPrimaryKey(id);
ApiModuleDTO dto = JSON.parseObject(JSON.toJSONString(module), ApiModuleDTO.class);
return dto;
}
@Override
public void updatePos(String id, Double pos) {
extApiModuleMapper.updatePos(id, pos);
}
public void dragNode(DragModuleRequest request) {
checkApiModuleExist(request);

View File

@ -1,6 +1,7 @@
package io.metersphere.api.service;
import com.alibaba.fastjson.JSON;
import io.metersphere.api.dto.automation.ApiScenarioDTO;
import io.metersphere.api.dto.automation.ApiScenarioModuleDTO;
import io.metersphere.api.dto.automation.ApiScenarioRequest;
@ -17,7 +18,6 @@ import io.metersphere.service.NodeTreeService;
import io.metersphere.service.ProjectService;
import io.metersphere.track.service.TestPlanProjectService;
import io.metersphere.track.service.TestPlanScenarioCaseService;
import io.metersphere.track.service.TestPlanTestCaseService;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
@ -186,6 +186,18 @@ public class ApiScenarioModuleService extends NodeTreeService<ApiScenarioModuleD
sqlSession.flushStatements();
}
@Override
public ApiScenarioModuleDTO getNode(String id) {
ApiScenarioModule module = apiScenarioModuleMapper.selectByPrimaryKey(id);
ApiScenarioModuleDTO dto = JSON.parseObject(JSON.toJSONString(module), ApiScenarioModuleDTO.class);
return dto;
}
@Override
public void updatePos(String id, Double pos) {
extApiScenarioModuleMapper.updatePos(id, pos);
}
public void dragNode(DragApiScenarioModuleRequest request) {
checkApiScenarioModuleExist(request);

View File

@ -8,5 +8,8 @@ import java.util.List;
public interface ExtApiModuleMapper {
int insertBatch(@Param("records") List<ApiModule> records);
List<ApiModuleDTO> getNodeTreeByProjectId(@Param("projectId") String projectId, @Param("protocol") String protocol);
void updatePos(String id, Double pos);
}

View File

@ -19,6 +19,10 @@
from api_module
where api_module.project_id = #{projectId}
and api_module.protocol = #{protocol}
order by create_time asc
order by api_module.pos asc
</select>
<update id="updatePos">
update api_module set pos = #{pos} where id = #{id}
</update>
</mapper>

View File

@ -7,4 +7,6 @@ import java.util.List;
public interface ExtApiScenarioModuleMapper {
List<ApiScenarioModuleDTO> getNodeTreeByProjectId(@Param("projectId") String projectId);
void updatePos(String id, Double pos);
}

View File

@ -6,6 +6,10 @@
<include refid="io.metersphere.base.mapper.ApiScenarioModuleMapper.Base_Column_List"/>
from api_scenario_module
where api_scenario_module.project_id = #{projectId}
order by create_time asc
order by api_scenario_module.pos asc
</select>
<update id="updatePos">
update api_scenario_module set pos = #{pos} where id = #{id}
</update>
</mapper>

View File

@ -0,0 +1,3 @@
set @rownum=0;
update api_module set pos=(select @rownum := @rownum +1) where pos is null;
update api_scenario_module set pos=(select @rownum := @rownum +1) where pos is null;

View File

@ -154,8 +154,9 @@
},
drag(param, list) {
this.$post("/api/automation/module/drag", param, () => {
// this.$post("/api/module/pos", list); //todo
this.list();
this.$post("/api/automation/module/pos", list, () => {
this.list();
});
}, (error) => {
this.list();
});

View File

@ -160,8 +160,9 @@
},
drag(param, list) {
this.$post("/api/module/drag", param, () => {
// this.$post("/api/module/pos", list); //todo
this.list();
this.$post("/api/module/pos", list, () => {
this.list();
});
}, (error) => {
this.list();
});