use of io.jpom.controller.manage.vo.DiffFileVo in project Jpom by dromara.
the class ProjectFileControl method batchDelete.
@RequestMapping(value = "batch_delete", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public String batchDelete(@RequestBody DiffFileVo diffFileVo) {
String id = diffFileVo.getId();
NodeProjectInfoModel projectInfoModel = super.getProjectInfoModel(id);
//
List<DiffFileVo.DiffItem> data = diffFileVo.getData();
Assert.notEmpty(data, "没有要对比的数据");
//
String path = projectInfoModel.allLib();
for (DiffFileVo.DiffItem datum : data) {
File file = FileUtil.file(path, datum.getName());
if (FileUtil.del(file)) {
continue;
}
return JsonMessage.getString(500, "删除失败");
}
return JsonMessage.getString(200, "删除成功");
}
use of io.jpom.controller.manage.vo.DiffFileVo in project Jpom by dromara.
the class ProjectFileControl method diffFile.
/**
* 对比文件
*
* @param diffFileVo 参数
* @return json
*/
@PostMapping(value = "diff_file", produces = MediaType.APPLICATION_JSON_VALUE)
public String diffFile(@RequestBody DiffFileVo diffFileVo) {
String id = diffFileVo.getId();
NodeProjectInfoModel projectInfoModel = super.getProjectInfoModel(id);
//
List<DiffFileVo.DiffItem> data = diffFileVo.getData();
Assert.notEmpty(data, "没有要对比的数据");
// 扫描项目目录下面的所有文件
String path = projectInfoModel.allLib();
List<File> files = FileUtil.loopFiles(path);
// 将所有的文件信息组装并签名
List<JSONObject> collect = files.stream().map(file -> {
//
JSONObject item = new JSONObject();
item.put("name", StringUtil.delStartPath(file, path, true));
item.put("sha1", SecureUtil.sha1(file));
return item;
}).collect(Collectors.toList());
// 得到 当前下面文件夹下面所有的文件信息 map
Map<String, String> nowMap = CollStreamUtil.toMap(collect, jsonObject12 -> jsonObject12.getString("name"), jsonObject1 -> jsonObject1.getString("sha1"));
// 将需要对应的信息转为 map
Map<String, String> tryMap = CollStreamUtil.toMap(data, DiffFileVo.DiffItem::getName, DiffFileVo.DiffItem::getSha1);
// 对应需要 当前项目文件夹下没有的和文件内容有变化的
List<JSONObject> canSync = tryMap.entrySet().stream().filter(stringStringEntry -> {
String nowSha1 = nowMap.get(stringStringEntry.getKey());
if (StrUtil.isEmpty(nowSha1)) {
// 不存在
return true;
}
// 如果 文件信息一致 则过滤
return !StrUtil.equals(stringStringEntry.getValue(), nowSha1);
}).map(stringStringEntry -> {
//
JSONObject item = new JSONObject();
item.put("name", stringStringEntry.getKey());
item.put("sha1", stringStringEntry.getValue());
return item;
}).collect(Collectors.toList());
// 对比项目文件夹下有对,但是需要对应对信息里面没有对。此类文件需要删除
List<JSONObject> delArray = nowMap.entrySet().stream().filter(stringStringEntry -> !tryMap.containsKey(stringStringEntry.getKey())).map(stringStringEntry -> {
//
JSONObject item = new JSONObject();
item.put("name", stringStringEntry.getKey());
item.put("sha1", stringStringEntry.getValue());
return item;
}).collect(Collectors.toList());
//
JSONObject result = new JSONObject();
result.put("diff", canSync);
result.put("del", delArray);
return JsonMessage.getString(200, "", result);
}
Aggregations