Skip to content

Commit

Permalink
feature:1.支持左侧目录移动;2.支持excel用例模板下载
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaofeng committed Dec 14, 2021
1 parent edf5d28 commit 894e8d8
Show file tree
Hide file tree
Showing 13 changed files with 227 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.xiaoju.framework.entity.exception.CaseServerException;
import com.xiaoju.framework.entity.request.dir.DirCreateReq;
import com.xiaoju.framework.entity.request.dir.DirDeleteReq;
import com.xiaoju.framework.entity.request.dir.DirMoveReq;
import com.xiaoju.framework.entity.request.dir.DirRenameReq;
import com.xiaoju.framework.entity.response.controller.Response;
import com.xiaoju.framework.service.DirService;
Expand Down Expand Up @@ -117,4 +118,27 @@ public Response<?> getDirCardTree(@RequestParam @NotNull(message = "业务线id
@RequestParam @NotNull(message = "渠道为空") Integer channel) {
return Response.success(dirService.getDirTree(productLineId, channel));
}

/**
* 移动文件夹,会文件夹下及其子文件夹全部移动
* 不允许移动root文件夹 -- 通过传参校验
* 不允许从父文件夹移动到子文件夹 -- 通过dfs路径计算
* 不允许移动不存在的文件夹,或者移动到不存在的文件夹 -- 通过dfs埋点
*
* @param req 请求体
* @return 响应体
*/
@PostMapping(value = "/move")
public Response<?> moveDir(@RequestBody DirMoveReq req) {
req.validate();
try {
return Response.success(dirService.moveDir(req));
} catch (CaseServerException e) {
throw new CaseServerException(e.getLocalizedMessage(), e.getStatus());
} catch (Exception e) {
LOGGER.error("[Dir move]move dir failed. params={} e={} ", req.toString(), e.getMessage());
e.printStackTrace();
return Response.build(StatusCode.SERVER_BUSY_ERROR);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.xiaoju.framework.entity.request.dir;

import com.xiaoju.framework.constants.BizConstant;
import com.xiaoju.framework.entity.request.ParamValidate;
import lombok.Data;
import org.springframework.util.StringUtils;

/**
* 目录下用例全部迁移的请求体
* Created by didi on 2021/12/14.
*/
@Data
public class DirMoveReq implements ParamValidate {
private Integer channel;

private Long productLineId;

/**
* 被选中文件夹的id
*/
private String fromId;

/**
* 如果想移到同级,设置为选中文件夹的parentId
* 如果想要移到自己,设为选中文件夹的Id
*/
private String toId;

@Override
public void validate() {
if (productLineId == null || productLineId <= 0) {
throw new IllegalArgumentException("业务线id为空或者非法");
}
if (StringUtils.isEmpty(fromId) || StringUtils.isEmpty(toId)) {
throw new IllegalArgumentException("来源或迁移文件夹id不能为空");
}
if (BizConstant.ROOT_BIZ_ID.equals(fromId)) {
throw new IllegalArgumentException("根文件夹暂不支持迁移");
}
if (fromId.equals(toId)) {
throw new IllegalArgumentException("相同的文件夹不需要迁移");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.xiaoju.framework.entity.dto.DirNodeDto;
import com.xiaoju.framework.entity.request.dir.DirCreateReq;
import com.xiaoju.framework.entity.request.dir.DirDeleteReq;
import com.xiaoju.framework.entity.request.dir.DirMoveReq;
import com.xiaoju.framework.entity.request.dir.DirRenameReq;
import com.xiaoju.framework.entity.response.dir.DirTreeResp;

Expand Down Expand Up @@ -75,4 +76,12 @@ public interface DirService {
* @return case-id-list
*/
List<Long> getCaseIds(Long productLineId, String bizId, Integer channel);

/**
* 移动文件夹
*
* @param req 请求体
* @return true 成功,实际上没什么用
*/
boolean moveDir(DirMoveReq req);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package com.xiaoju.framework.service.impl;

import com.xiaoju.framework.constants.enums.StatusCode;
import com.xiaoju.framework.entity.dto.DirNodeDto;
import com.xiaoju.framework.entity.exception.CaseServerException;
import lombok.Data;
import org.apache.commons.compress.utils.Sets;

import java.util.HashSet;

/**
* Created by didi on 2021/12/14.
*/
@Data
public class DirMoveDFS {
private String fromId;

private String toId;

private DirNodeDto fromObj;

private DirNodeDto toObj;

private DirNodeDto parent;

/**
* 用于记录找到set的id集合,用来判断是不是从父文件夹移到了子文件夹,这样的操作不允许
*/
private HashSet<String> toSet;

public DirMoveDFS(String fromId, String toId) {
this.fromId = fromId;
this.toId = toId;
this.fromObj = null;
this.toObj = null;
this.parent = null;
this.toSet = new HashSet<>();
}

public void findNodeAndDelete(DirNodeDto node) {
findNode(node, Sets.newHashSet(node.getId()));
if (parent == null) {
throw new CaseServerException("要去的文件夹不正确", StatusCode.INTERNAL_ERROR);
}
if (toSet.contains(fromObj.getId())) {
throw new CaseServerException("不能从父文件夹移到子文件夹", StatusCode.INTERNAL_ERROR);
}

parent.getChildren().remove(fromObj);
}

private void findNode(DirNodeDto node, HashSet<String> set) {
if (node == null) {
return ;
}
if(toId.equals(node.getId())){
toObj = node;
}
for (DirNodeDto child : node.getChildren()) {
set.add(node.getId());
if (fromId.equals(child.getId())) {
// 找到了需要移动的文件夹,并且记录其父节点和当前节点
fromObj = child;
parent = node;
}
if (toId.equals(child.getId())) {
// 找到了要移过去的文件夹,就记录是哪个节点,并且留存经过的id路径
toObj = child;
toSet = new HashSet<>(set);
}
findNode(child, set);
set.remove(node.getId());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.xiaoju.framework.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.xiaoju.framework.constants.BizConstant;
import com.xiaoju.framework.constants.enums.StatusCode;
Expand All @@ -8,6 +9,7 @@
import com.xiaoju.framework.entity.exception.CaseServerException;
import com.xiaoju.framework.entity.request.dir.DirCreateReq;
import com.xiaoju.framework.entity.request.dir.DirDeleteReq;
import com.xiaoju.framework.entity.request.dir.DirMoveReq;
import com.xiaoju.framework.entity.request.dir.DirRenameReq;
import com.xiaoju.framework.entity.response.dir.DirTreeResp;
import com.xiaoju.framework.mapper.BizMapper;
Expand Down Expand Up @@ -172,6 +174,32 @@ public List<Long> getCaseIds(Long productLineId, String bizId, Integer channel)
return caseIds.stream().map(Long::valueOf).collect(Collectors.toList());
}

@Override
@Transactional(rollbackFor = Exception.class)
public boolean moveDir(DirMoveReq req) {
Biz biz = bizMapper.selectOne(req.getProductLineId(), req.getChannel());
if (biz == null) {
throw new CaseServerException("目录节点获取为空", StatusCode.INTERNAL_ERROR);
}
DirNodeDto dataObj = JSONObject.parseObject(biz.getContent(), DirNodeDto.class);

// DFS
DirMoveDFS dfs = new DirMoveDFS(req.getFromId(), req.getToId());
dfs.findNodeAndDelete(dataObj);

if (dfs.getToObj() == null || dfs.getFromObj() == null) {
throw new CaseServerException("被迁移的文件夹或者要迁移的文件夹不存在", StatusCode.INTERNAL_ERROR);
}

// 剪下来的节点塞到要迁移到的地方去
dfs.getFromObj().setParentId(dfs.getToObj().getId());
dfs.getToObj().getChildren().add(dfs.getFromObj());

biz.setContent(JSON.toJSONString(dataObj));
bizMapper.update(biz);
return true;
}

/**
* 将子目录的所有caseId分配到父目录
*
Expand Down
2 changes: 1 addition & 1 deletion case-server/src/main/resources/web/dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
</head>
<body>
<div id="root"></div>
<script th:src="@{/umi.06ec6461.js}"></script>
<script th:src="@{/umi.a34a5352.js}"></script>
</body>
</html>

Large diffs are not rendered by default.

Binary file not shown.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
} from 'antd';
const { Dragger } = Upload;
import './index.scss';
import caseTemplate from './testcase-template.xlsx'
const initData = `{"root":{"data":{"id":"bv8nxhi3c800","created":1562059643204,"text":"中心主题"},"children":[]},"template":"default","theme":"fresh-blue","version":"1.4.43","base":0}`;
const formItemLayout = {
labelCol: { span: 6 },
Expand Down Expand Up @@ -363,7 +364,9 @@ class CaseModal extends React.Component {
上传文件(非必传)
</span>
<span className="span-text span-text-light">
支持.xmind和excel文件,excel请按照模板填写...
支持.xmind和excel文件,excel请按照<a href={caseTemplate} download="testcase-template.xlsx">
模板
</a>填写...
</span>
</div>
</div>
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,8 @@ class FileTree extends React.Component {
});
getTreeList();
} else {
this.editNode(null, this.state.treeData)
this.setState({treeData: this.state.treeData})
this.editNode(null, this.state.treeData);
this.setState({ treeData: this.state.treeData });
message.error(res.msg);
}
});
Expand Down Expand Up @@ -448,6 +448,42 @@ class FileTree extends React.Component {
this.props.getCaseList(caseIds);
});
};
onDrop = info => {
const dropNode = info.node.props;
const dragNode = info.dragNode.props;
// console.log(info);
if (dragNode.eventKey === '-1') {
message.error('未分类用例集不可移动!');
} else if (dropNode.eventKey === '-1') {
message.error('未分类用例集下不可有其他文件!');
} else {
const fromId = dragNode.eventKey;
let toId = '';
if (dropNode.dragOver) {
toId = dropNode.eventKey;
} else {
toId = dropNode.dataRef.parentId;
}
this.moveFolder({
productLineId: this.props.productLineId,
fromId,
toId,
channel: 1,
});
}
};
moveFolder = params => {
const url = `${this.props.doneApiPrefix}/dir/move`;
request(url, { method: 'POST', body: params }).then((res = {}) => {
if (res.code === 200) {
message.success('移动文件夹成功!');
this.props.getTreeList();
} else {
message.error(res.msg);
}
});
};

render() {
const { treeSelect, expandedKeys, autoExpandParent, treeData } = this.state;
return (
Expand All @@ -464,6 +500,8 @@ class FileTree extends React.Component {
onChange={this.onChange}
/>
<DirectoryTree
draggable
onDrop={this.onDrop}
multiple
selectedKeys={treeSelect ? [treeSelect] : []}
onExpand={this.onExpand}
Expand Down

0 comments on commit 894e8d8

Please sign in to comment.