提交 6a8d21f9 authored 作者: wyl's avatar wyl

合并分支 'wyl' 到 'master'

reStruct 查看合并请求 ty_wyl/adaptation-master1!4
package com.zjty.adaptationmaster.managerment.controller; package com.zjty.adaptationmaster.adaptor.controller;
import com.zjty.adaptationmaster.managerment.entity.response.ServerResponse; import com.zjty.adaptationmaster.adaptor.service.AdaptationService;
import com.zjty.adaptationmaster.managerment.service.AdaptationService; import com.zjty.adaptationmaster.base.response.ServerResponse;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
......
package com.zjty.adaptationmaster.managerment.controller; package com.zjty.adaptationmaster.adaptor.controller;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
......
package com.zjty.adaptationmaster.adaptor.enginer;
public class Inspector {
}
package com.zjty.adaptationmaster.adaptor.enginer;
import com.zjty.adaptationmaster.adaptor.entity.Rule;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.nio.file.Path;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.List;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ReadedFile {
private String content;
private BasicFileAttributes attributes;
private Path path;
private List<Rule> thisMatchedRule;
}
package com.zjty.adaptationmaster.adaptor.enginer.exception;
public class FileTypeNotMatchException extends Exception {
public FileTypeNotMatchException(){
super();
}
public FileTypeNotMatchException(String message){
super(message);
}
public FileTypeNotMatchException(String message,Throwable cause){
super(message,cause);
}
public FileTypeNotMatchException(Throwable cause){
super(cause);
}
}
package com.zjty.adaptationmaster.adaptor.enginer.util;
public class StringCompareUtil1 {
/**
* 长字符串中是否包含arg2
* 原生方法速度慢
* 用kmp重写之
*
*
* @param text
* @param pattern
* @return
*/
public int compare(String text,String pattern){
//return text.indexOf(pattern);
return KMP(text,pattern);
}
//KMP算法实现
private int KMP(String source, String pattern) {
int[] N=getN(pattern);
int res=0;
int sourceLength=source.length();
int patternLength=pattern.length();
for(int i=0;i<=(sourceLength-patternLength);){
res++;
String str=source.substring(i, i+patternLength);//要比较的字符串
int count=getNext(pattern, str,N);
if(count==0){
return i;
}
i=i+count;
}
return -1;
}
/**
* 得到下一次要移动的次数
*
* @param pattern
* @param str
* @param N
* @return 0,字符串匹配;
*/
private int getNext(String pattern,String str,int[] N) {
int n = pattern.length();
char v1[] = str.toCharArray();
char v2[] = pattern.toCharArray();
int x = 0;
while (n-- != 0) {
if (v1[x] != v2[x]){
if(x==0){
return 1;//如果第一个不相同,移动1步
}
return x-N[x-1];//x:第一次出现不同的索引的位置,即j
}
x++;
}
return 0;
}
private int[] getN(String pattern) {
char[] pat=pattern.toCharArray();
int j=pattern.length()-1;
int[] N=new int[j+1];
for(int i=j;i>=2;i--){
N[i-1]=getK(i,pat);
}
return N;
}
/**
*
* @param j 匹配字符长度-1,递减
* @param pat
* @return
*/
private int getK(int j, char[] pat) {
int x=j-2;//匹配字符长度-3
int y=1;
while (x>=0 && compare(pat, 0, x, y, j-1)) {
x--;
y++;
}
return x+1;
}
//逐字匹配,发现不对,返回true
private boolean compare(char[] pat,int b1,int e1,int b2,int e2){
int n = e1-b1+1;
while (n-- != 0) {
if (pat[b1] != pat[b2]){
return true;
}
b1++;
b2++;
}
return false;
}
}
package com.zjty.adaptationmaster.adaptor.examination; package com.zjty.adaptationmaster.adaptor.entity;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import java.nio.file.Path;
@Data @Data
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
...@@ -11,13 +13,14 @@ public class Report { ...@@ -11,13 +13,14 @@ public class Report {
public String type;//语言类型 public String type;//语言类型
public String structure;//项目架构 public String structure;//项目架构
public String sqlType;//数据库类型 public String sqlType;//数据库类型
public DependenceManagement dependenceManagement; public DependenceManagement dependenceManagement;//版本管理方式
public Path depMagFilepath;//版本管理文件地址
@Override @Override
public String toString(){ public String toString(){
return ""+type+structure+sqlType; return ""+type+structure+sqlType;
} }
private static enum DependenceManagement{ public static enum DependenceManagement{
MAVEN,GRADLE,ANT MAVEN,GRADLE,ANT
} }
} }
package com.zjty.adaptationmaster.managerment.dao; package com.zjty.adaptationmaster.adaptor.repository;
import com.zjty.adaptationmaster.adaptor.entity.AdaptationDetailsLogEntity; import com.zjty.adaptationmaster.adaptor.entity.AdaptationDetailsLogEntity;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
......
package com.zjty.adaptationmaster.managerment.dao; package com.zjty.adaptationmaster.adaptor.repository;
import com.zjty.adaptationmaster.adaptor.entity.OriginalFile; import com.zjty.adaptationmaster.adaptor.entity.OriginalFile;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
......
package com.zjty.adaptationmaster.managerment.service; package com.zjty.adaptationmaster.adaptor.service;
import com.zjty.adaptationmaster.managerment.entity.response.ServerResponse;
import com.zjty.adaptationmaster.base.response.ServerResponse;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
......
package com.zjty.adaptationmaster.managerment.service.impl; package com.zjty.adaptationmaster.adaptor.service.Impl;
import com.zjty.adaptationmaster.adaptor.enginer.Adaptor;
import com.zjty.adaptationmaster.adaptor.entity.Rule; import com.zjty.adaptationmaster.adaptor.entity.Rule;
import com.zjty.adaptationmaster.managerment.entity.response.ServerResponse; import com.zjty.adaptationmaster.base.response.ServerResponse;
import com.zjty.adaptationmaster.managerment.service.AdaptationService; import com.zjty.adaptationmaster.adaptor.service.AdaptationService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
......
package com.zjty.adaptationmaster.adaptor.enginer; package com.zjty.adaptationmaster.adaptor.service.Impl;
import com.zjty.adaptationmaster.adaptor.entity.AdaptationDetailsLogEntity; import com.zjty.adaptationmaster.utils.ReadedFileTask;
import com.zjty.adaptationmaster.adaptor.entity.OriginalFile; import com.zjty.adaptationmaster.adaptor.entity.OriginalFile;
import com.zjty.adaptationmaster.adaptor.entity.Rule; import com.zjty.adaptationmaster.adaptor.entity.Rule;
import com.zjty.adaptationmaster.base.enums.Const; import com.zjty.adaptationmaster.base.enums.Const;
import com.zjty.adaptationmaster.managerment.dao.AdaptationDetailLogEntityDao; import com.zjty.adaptationmaster.adaptor.repository.OriginalFileDao;
import com.zjty.adaptationmaster.managerment.dao.OriginalFileDao;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.io.*; import java.io.*;
...@@ -104,8 +102,8 @@ public class Adaptor { ...@@ -104,8 +102,8 @@ public class Adaptor {
bySort.setWriter(writer); bySort.setWriter(writer);
for (String s : Files.readAllLines(originalPath, Charset.forName("utf-8"))) { for (String s : Files.readAllLines(originalPath, Charset.forName("utf-8"))) {
if (linesRepository.put(s)) { if (linesRepository.put(s)) {
List<ReadedFile> readedFiles = new ArrayList<>(); List<ReadedFileTask.ReadedFile> readedFiles = new ArrayList<>();
readedFiles.add(new ReadedFile(linesRepository.getReadedFiles(), attrs, file,thisFileMatched)); readedFiles.add(new ReadedFileTask.ReadedFile(linesRepository.getReadedFiles(), attrs, file,thisFileMatched));
ReadedFileTask apacheTask = new ReadedFileTask(readedFiles); ReadedFileTask apacheTask = new ReadedFileTask(readedFiles);
apacheTask.setBySort(bySort); apacheTask.setBySort(bySort);
apacheTask.setIndex(i); apacheTask.setIndex(i);
...@@ -113,8 +111,8 @@ public class Adaptor { ...@@ -113,8 +111,8 @@ public class Adaptor {
i++; i++;
} }
} }
List<ReadedFile> readedFiles = new ArrayList<>(); List<ReadedFileTask.ReadedFile> readedFiles = new ArrayList<>();
readedFiles.add(new ReadedFile(linesRepository.getReadedFiles(), attrs, file,thisFileMatched)); readedFiles.add(new ReadedFileTask.ReadedFile(linesRepository.getReadedFiles(), attrs, file,thisFileMatched));
ReadedFileTask apacheTask = new ReadedFileTask(readedFiles); ReadedFileTask apacheTask = new ReadedFileTask(readedFiles);
apacheTask.setBySort(bySort); apacheTask.setBySort(bySort);
apacheTask.setIndex(i); apacheTask.setIndex(i);
...@@ -123,7 +121,7 @@ public class Adaptor { ...@@ -123,7 +121,7 @@ public class Adaptor {
bySort.setSize(i); bySort.setSize(i);
}else { }else {
String s = new String(Files.readAllBytes(originalPath)); String s = new String(Files.readAllBytes(originalPath));
ReadedFile readedFile = new ReadedFile(s, attrs, file,thisFileMatched); ReadedFileTask.ReadedFile readedFile = new ReadedFileTask.ReadedFile(s, attrs, file,thisFileMatched);
if (repository.put(readedFile)) { if (repository.put(readedFile)) {
ReadedFileTask apacheTask = new ReadedFileTask(repository.getReadedFiles()); ReadedFileTask apacheTask = new ReadedFileTask(repository.getReadedFiles());
pool.submit(apacheTask); pool.submit(apacheTask);
...@@ -204,14 +202,14 @@ public class Adaptor { ...@@ -204,14 +202,14 @@ public class Adaptor {
* 读取到的大量小文件,积累到一定的大小,才交给一个线程去处理 * 读取到的大量小文件,积累到一定的大小,才交给一个线程去处理
*/ */
private class ReadedFileRepository{ private class ReadedFileRepository{
private List<ReadedFile> readedFiles; private List<ReadedFileTask.ReadedFile> readedFiles;
private long count; private long count;
public List<ReadedFile> getReadedFiles() { public List<ReadedFileTask.ReadedFile> getReadedFiles() {
return readedFiles; return readedFiles;
} }
public boolean put(ReadedFile readedFile){ public boolean put(ReadedFileTask.ReadedFile readedFile){
if(readedFiles==null)readedFiles = new ArrayList<>(); if(readedFiles==null)readedFiles = new ArrayList<>();
readedFiles.add(readedFile); readedFiles.add(readedFile);
count+=readedFile.getAttributes().size(); count+=readedFile.getAttributes().size();
...@@ -265,4 +263,5 @@ public class Adaptor { ...@@ -265,4 +263,5 @@ public class Adaptor {
} }
} }
} }
package com.zjty.adaptationmaster.adaptor.examination; package com.zjty.adaptationmaster.adaptor.service.Impl;
import com.zjty.adaptationmaster.adaptor.enginer.util.StringCompareUtil; import com.zjty.adaptationmaster.utils.StringCompareUtil;
import com.zjty.adaptationmaster.adaptor.entity.Report;
import java.io.IOException; import java.io.IOException;
import java.nio.file.*; import java.nio.file.*;
...@@ -19,10 +20,17 @@ import java.util.Map; ...@@ -19,10 +20,17 @@ import java.util.Map;
public class Inspectors { public class Inspectors {
private String path; private String path;
private Map<String, Counter> matchMap; private Map<String, Counter> matchMap;//后缀计数器
//特定后缀文件的地址集合
private List<Path> propertiesConfigPaths = new ArrayList<>(); private List<Path> propertiesConfigPaths = new ArrayList<>();
private List<Path> ymlConfigPaths = new ArrayList<>(); private List<Path> ymlConfigPaths = new ArrayList<>();
private List<Path> xmlConfigPaths = new ArrayList<>(); private List<Path> xmlConfigPaths = new ArrayList<>();
//版本管理配置文件地址
private Path pomPath;
private boolean havePom = false;
private boolean haveIvy = false;
public List<String> matchStrings;
private Report report = new Report(); private Report report = new Report();
...@@ -64,7 +72,7 @@ public class Inspectors { ...@@ -64,7 +72,7 @@ public class Inspectors {
public void inspect(){ public void inspect(){
try { try {
String glob = "glob:**/*.txt"; String glob = "glob:**/*.txt";
final PathMatcher pathMatcher = FileSystems.getDefault().getPathMatcher( glob); final PathMatcher pathMatcher = FileSystems.getDefault().getPathMatcher(glob);
Files.walkFileTree(Paths.get(path), new FileVisitor<Path>() { Files.walkFileTree(Paths.get(path), new FileVisitor<Path>() {
@Override @Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
...@@ -80,6 +88,11 @@ public class Inspectors { ...@@ -80,6 +88,11 @@ public class Inspectors {
@Override @Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
boolean matches = pathMatcher.matches(file); boolean matches = pathMatcher.matches(file);
for(String s:matchStrings){
}
if (file.endsWith("properties")) { if (file.endsWith("properties")) {
propertiesConfigPaths.add(file); propertiesConfigPaths.add(file);
} }
...@@ -88,6 +101,13 @@ public class Inspectors { ...@@ -88,6 +101,13 @@ public class Inspectors {
} }
if(file.endsWith("xml")){ if(file.endsWith("xml")){
xmlConfigPaths.add(file); xmlConfigPaths.add(file);
if(file.endsWith("pom.xml")){
havePom = true;
pomPath = file;
}else if(file.endsWith("ivy.xml")){
haveIvy = true;
pomPath = file;
}
} }
return FileVisitResult.CONTINUE; return FileVisitResult.CONTINUE;
} }
...@@ -109,7 +129,6 @@ public class Inspectors { ...@@ -109,7 +129,6 @@ public class Inspectors {
public Report analysis(){ public Report analysis(){
if(matchMap.get("java").getI()>0){ if(matchMap.get("java").getI()>0){
report.setType("java"); report.setType("java");
} }
if(matchMap.get("jsp").getI()>0){ if(matchMap.get("jsp").getI()>0){
...@@ -175,6 +194,10 @@ public class Inspectors { ...@@ -175,6 +194,10 @@ public class Inspectors {
e.printStackTrace(); e.printStackTrace();
} }
} }
if(havePom){
report.setDependenceManagement(Report.DependenceManagement.MAVEN);
report.setDepMagFilepath(pomPath);
}
return null; return null;
} }
private static class Counter { private static class Counter {
......
package com.zjty.adaptationmaster.managerment.entity.response;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* <p>Description : 异常结果枚举类,用于统一异常状态码与相关描述信息
* @Date : 2017/12/13 0:51
* @author : M@tr!x [xhyrzldf@foxmail.com]
*/
@AllArgsConstructor
@Getter
public enum ResponseCode {
/**
* 服务器成功返回用户请求的数据
*/
OK(200, "[GET]:服务器成功返回用户请求的数据,返回资源对象"),
/**
* 用户新建或修改数据成功
*/
CREATED(201, "[POST/PUT/PATCH]:用户新建或修改数据成功,返回新生成或修改的资源对象"),
/**
* 表示一个请求已经进入后台排队(异步任务)
*/
ACCEPTED(202, "[*]:表示一个请求已经进入后台排队(异步任务)"),
/**
* 用户上传文件成功
*/
UPLOADED(203, "[POST]文件上传成功"),
/**
* 用户删除数据成功
*/
NO_CONTENT(204, " [DELETE]:用户删除数据成功"),
/**
* 用户发出的请求有错误,服务器没有进行新建或修改数据的操作
*/
INVALID_REQUEST(400, "[POST/PUT/PATCH]:用户发出的请求有错误,服务器没有进行新建或修改数据的操作"),
/**
* 表示用户没有权限(令牌、用户名、密码错误)
*/
UNAUTHORIZED(401, " [*]:表示用户没有权限(令牌、用户名、密码错误)"),
/**
* 表示用户登录超时
*/
LOGINOUTTIME(402, " [*]:表示用户登录超时"),
/**
* 表示用户得到授权(与401错误相对),但是访问是被禁止的
*/
FORBIDDEN(403, " [*] 表示用户得到授权(与401错误相对),但是访问是被禁止的"),
/**
* 用户发出的请求针对的是不存在的记录,服务器没有进行操作,该操作是幂等的
*/
NOT_FOUND(404, " [*]:用户发出的请求针对的是不存在的记录,服务器没有进行操作"),
/**
* 非法参数,请求中附带的参数不符合要求规范
*/
ILLEGAL_PARAMETER(405, "[*]:非法参数,请求中附带的参数不符合要求规范"),
/**
* 用户请求的格式不可得(比如用户请求JSON格式,但是只有XML格式)
*/
NOT_ACCEPTABLE(406, " [GET]:用户请求的格式不可得(比如用户请求JSON格式,但是只有XML格式)"),
/**
* 用户的参数不得为空
*/
NOT_NULL_PARAMETER(408, "传递的参数不能为空"),
/**
* 用户请求的资源被永久删除,且不会再得到的
*/
GONE(413, "[GET]:用户请求的资源被永久删除,且不会再得到的"),
/**
* [PUT,PATCH,POST,DELETE]:操作没有成功,并没有数据发生变化
*/
NO_CHANGED(414, "[PUT,PATCH,POST,DELETE]:操作没有成功,并没有数据发生变化"),
/**
* 创建一个对象时,发生一个验证错误
*/
UNPROCESSABLE_ENTITY(422, "[POST/PUT/PATCH] 当创建一个对象时,发生一个验证错误"),
/**
* 服务器发生错误
*/
INTERNAL_SERVER_ERROR(500, "服务器发生错误");
/**
* 结果代码编号
*/
private Integer code;
/**
* 结果信息
*/
private String msg;
}
package com.zjty.adaptationmaster.managerment.entity.response;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Getter;
import static com.zjty.adaptationmaster.managerment.entity.response.ResponseCode.*;
/**
* Description : 结果类,用于统一返回格式 对外提供关于响应结果的很多便利的静态方法
*
* @author : M@tr!x [xhyrzldf@foxmail.com]
* @Date : 2017/12/13 0:05
*/
@SuppressWarnings({"WeakerAccess", "unused"})
@Getter
public class ServerResponse<T> {
/**
* 错误码
*/
@JSONField(ordinal = 1)
private Integer code;
/**
* 提示信息
*/
@JSONField(ordinal = 2)
private String msg;
/**
* 具体的内容
*/
@JSONField(ordinal = 3)
private T data;
/* 以下为返回成功响应结果的各类重载静态方法 */
public static <T> ServerResponse<T> success() {
return new ServerResponse<>(OK.getCode(), OK.getMsg());
}
public static <T> ServerResponse<T> success(T data) {
return new ServerResponse<>(OK.getCode(), OK.getMsg(), data);
}
public static <T> ServerResponse<T> success(String msg, T data) {
return new ServerResponse<>(OK.getCode(), msg, data);
}
public static <T> ServerResponse<T> saveSuccess(T data) {
return new ServerResponse<>(CREATED.getCode(), CREATED.getMsg(), data);
}
public static <T> ServerResponse<T> deleteSuccess() {
return new ServerResponse<>(NO_CONTENT.getCode(), NO_CONTENT.getMsg());
}
public static <T> ServerResponse<T> deleteSuccessWithCount(Number effectCount) {
return new ServerResponse<>(NO_CONTENT.getCode(), "删除成功,操作删除的数据条数为: " + effectCount);
}
public static <T> ServerResponse<T> deleteSuccessWithId(Number id) {
return new ServerResponse<>(NO_CONTENT.getCode(), "删除成功,操作删除的数据id为: " + id);
}
public static <T> ServerResponse<T> uploadSuccess(T data) {
return new ServerResponse<>(UPLOADED.getCode(), UPLOADED.getMsg(), data);
}
public static <T> ServerResponse<T> messageSuccess(String msg) {
return new ServerResponse<>(OK.getCode(), msg);
}
/* 以下为返回失败响应结果的各类重载静态方法 */
public static <T> ServerResponse<T> error() {
return new ServerResponse<>(INTERNAL_SERVER_ERROR.getCode(), INTERNAL_SERVER_ERROR.getMsg());
}
public static <T> ServerResponse<T> error(String errorMessage) {
return new ServerResponse<>(INTERNAL_SERVER_ERROR.getCode(), errorMessage);
}
public static <T> ServerResponse<T> error(ResponseCode responseCode) {
return new ServerResponse<>(responseCode.getCode(), responseCode.getMsg());
}
public static <T> ServerResponse<T> error(ResponseCode responseCode, String errorMessage) {
return new ServerResponse<>(responseCode.getCode(), errorMessage);
}
public static <T> ServerResponse<T> error(ResponseCode responseCode, String errorMessage,T data) {
return new ServerResponse<>(responseCode.getCode(), errorMessage,data);
}
/* 以下为提供给CONTROL层向文件服务器操作文件获得相应结果的相关方法 */
// /**
// * <b>向文件服务器上传文件并且取得{@code {@link ServerResponse}}类型的响应结果</b>
// * <p>
// * <p>封装了control层的关于文件上传的代码
// * <p>
// * <p>例如file是a.txt,dirName=template, 在文件服务器上存放的位置就是{@code root(根目录)/template/a.txt }
// *
// * @param file {@link MultipartFile} 接受到的文件俺对象
// * @param dirName 在文件服务器上的文件夹名
// * @return {@link ServerResponse} (包含了成功与导致失败的结果)
// */
// public static ServerResponse uploadAndGet(
// @RequestParam("file") Optional<MultipartFile> file, String dirName) {
// // 空指针判断
// if (!file.isPresent()) return error(NOT_NULL_PARAMETER);
// // 上传文件并且获得相应结果
// MultipartFile uploadFile = file.get();
// FileServerResponse fsp =
// HttpClientUtil.uploadFileToServer(uploadFile, dirName, uploadFile.getOriginalFilename());
// // 根据返回结果的状态码确定相应的返回信息(200返回成功,否则error)
// return (fsp.getCode() == 200) ? uploadSuccess(fsp.getData()) : error(NO_CHANGED, fsp.getMsg());
// }
// /**
// * <b>向文件服务器删除文件并且取得{@code {@link ServerResponse}}类型的响应结果</b>
// * <p>
// * <p>封装了control层的关于文件上传的代码
// * <p>
// * <p>例如提供的参数如下
// * <li>fileName = reset-hv_20180115144834_wV9A9iVD.png
// * <li>dirName = templates
// * <li>那么实际删除的文件路径为: {@code root(根目录)/templates/reset-hv_20180115144834_wV9A9iVD.png}
// *
// * @param fileName 要删除的文件名<b>注意是文件服务器上的文件名,例如<b>reset-hv_20180115144834_wV9A9iVD.png</b> 格式为{@code
// * 原始文件名_timestamp_uuid8位}
// * @param dirName 要删除的文件所处的文件目录
// * @return {@link ServerResponse} (包含了成功与导致失败的结果)
// */
// public static ServerResponse deleteAndGet(
// @RequestParam(value = "fileName") Optional<String> fileName, String dirName) {
// // 空指针判断
// if (!fileName.isPresent()) return error(NOT_NULL_PARAMETER);
// // 发送删除文件的请求,附带文件所在的目录和在服务器中的文件名
// FileServerResponse fsp = HttpClientUtil.daleteFileToServer(dirName, fileName.get());
// // 根据返回结果的状态码确定相应的返回信息(200返回成功,否则error)
// return (fsp.getCode() == 200) ? deleteSuccess() : error(NO_CHANGED, fsp.getMsg());
// }
/* 将构造器私有,防止外部进行实例化 仅提供给内部静态方法调用 * */
private ServerResponse() {
}
private ServerResponse(Integer code) {
this.code = code;
}
private ServerResponse(Integer code, String msg) {
this.code = code;
this.msg = msg;
}
private ServerResponse(String msg, T data) {
this.msg = msg;
this.data = data;
}
private ServerResponse(Integer code, String msg, T data) {
this.code = code;
this.msg = msg;
this.data = data;
}
}
package com.zjty.adaptationmaster.adaptor.enginer; package com.zjty.adaptationmaster.utils;
import com.zjty.adaptationmaster.adaptor.entity.Rule; import com.zjty.adaptationmaster.adaptor.entity.Rule;
import com.zjty.adaptationmaster.adaptor.service.Impl.Adaptor;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.SimpMessagingTemplate; import org.springframework.messaging.simp.SimpMessagingTemplate;
import java.io.*; import java.io.*;
import java.nio.file.Path;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.List; import java.util.List;
public class ReadedFileTask implements Runnable { public class ReadedFileTask implements Runnable {
...@@ -64,7 +70,7 @@ public class ReadedFileTask implements Runnable { ...@@ -64,7 +70,7 @@ public class ReadedFileTask implements Runnable {
if(bySort!=null){ if(bySort!=null){
System.out.println("toBySort"); System.out.println("toBySort");
bySort.insert(index,content); bySort.insert(index,content);
}else { } else {
System.out.println("writerFile"); System.out.println("writerFile");
File file = readedFile.getPath().toFile(); File file = readedFile.getPath().toFile();
file.createNewFile(); file.createNewFile();
...@@ -77,4 +83,14 @@ public class ReadedFileTask implements Runnable { ...@@ -77,4 +83,14 @@ public class ReadedFileTask implements Runnable {
} }
} }
} }
@Data
@NoArgsConstructor
@AllArgsConstructor
public static class ReadedFile {
private String content;
private BasicFileAttributes attributes;
private Path path;
private List<Rule> thisMatchedRule;
}
} }
package com.zjty.adaptationmaster.adaptor.enginer.util; package com.zjty.adaptationmaster.utils;
public class StringCompareUtil { public class StringCompareUtil {
/** /**
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论