提交 cc866ccb authored 作者: 马晨俊's avatar 马晨俊

mcj:

修复websocket输送问题,文件上传问题
上级 67b1e5a5
...@@ -91,18 +91,6 @@ public class EvaluationController { ...@@ -91,18 +91,6 @@ public class EvaluationController {
return ServerResponse.ok(null); return ServerResponse.ok(null);
} }
@ApiOperation("根据报告id查询excel输入")
@GetMapping(value = "/in/excel/{id}")
public ServerResponse<List<ExcelDataTemp>> exportInName(@PathVariable String id) {
Evaluation evaluation = evaluationService.findById(id);
if (evaluation != null) {
List<ExcelDataTemp> excelDataTemp = ExcelUtil.parseExcel2Entity(evaluation);
return ServerResponse.ok(excelDataTemp);
} else {
return ServerResponse.ok(new ArrayList<>());
}
}
/** /**
* 修改评估报告 * 修改评估报告
* *
......
...@@ -10,11 +10,15 @@ import com.zjty.inspect.utils.*; ...@@ -10,11 +10,15 @@ import com.zjty.inspect.utils.*;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*; import java.io.*;
import java.io.File; import java.io.File;
import java.util.*; import java.util.*;
...@@ -53,6 +57,8 @@ public class InspectController { ...@@ -53,6 +57,8 @@ public class InspectController {
//应用类型转换:大型4 //应用类型转换:大型4
private Integer[] big = {5, 9}; private Integer[] big = {5, 9};
@Value("${upload.location}")
private String uploadPath;
/** /**
* 上传代码进行评估 * 上传代码进行评估
* *
...@@ -381,23 +387,58 @@ public class InspectController { ...@@ -381,23 +387,58 @@ public class InspectController {
return ServerResponse.ok(save.getId()); return ServerResponse.ok(save.getId());
} }
@ApiOperation("大文件分片上传")
// @PostMapping("/chunkUpload")
@PostMapping("/uploads") @PostMapping("/uploads")
private ServerResponse uploads(@RequestParam(value = "file") MultipartFile multfile) { public ServerResponse fileChunkUpload(MultipartFileParam param, HttpServletRequest request, HttpServletResponse response){
// OSSInformation ossInformation = ossInformationService.queryOne();
// String root = ossInformation.getRoot();
String root = uploadPath;
//验证文件夹规则,不能包含特殊字符
java.io.File file = new java.io.File(root);
// createDirectoryQuietly(file);
System.out.println("88888888888888");
String path=file.getAbsolutePath();
response.setContentType("text/html;charset=UTF-8");
// response.setStatus对接前端插件
// 200, 201, 202: 当前块上传成功,不需要重传。
// 404, 415. 500, 501: 当前块上传失败,会取消整个文件上传。
// 其他状态码: 出错了,但是会自动重试上传。
try { try {
HashMap<String, String> map = new HashMap<>(); /**
map.put("unzip","获取压缩文件"); * 判断前端Form表单格式是否支持文件上传
File file = FileUtil.saveToLocal(multfile); */
map.put("unzip","压缩文件解压完毕"); boolean isMultipart = ServletFileUpload.isMultipartContent(request);
asyncTask.sendMessageToAll(map); if(!isMultipart){
String name = file.getName(); //这里是我向前端发送数据的代码,可理解为 return 数据; 具体的就不贴了
String path = file.getCanonicalPath(); System.out.println("不支持的表单格式");
return ServerResponse.ok(new com.zjty.inspect.entity.File(name, path)); return ServerResponse.badRequest();
} catch (IOException e) { }else {
param.setTaskId(param.getIdentifier());
File myfile = inspectService.chunkUploadByMappedByteBuffer(param,path);//service层
if (myfile!=null){
String name = myfile.getName();
String myPath = myfile.getCanonicalPath();
return ServerResponse.ok(new com.zjty.inspect.entity.File(name, myPath));
}else {
return ServerResponse.ok("继续断点传续!");
}
}
} catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return ServerResponse.error(500); // System.out.println("上传文件失败");
// response.setStatus(415);
return ServerResponse.error(415, "上传文件失败");
} }
} }
@PostMapping("/gitdownload") @PostMapping("/gitdownload")
private ServerResponse gitDownloads(String gitAddress, String username, String password) { private ServerResponse gitDownloads(String gitAddress, String username, String password) {
try { try {
...@@ -412,7 +453,6 @@ public class InspectController { ...@@ -412,7 +453,6 @@ public class InspectController {
private ServerResponse<Reform> uploadFileToInspect(MultipartFile file, String username) throws IOException { private ServerResponse<Reform> uploadFileToInspect(MultipartFile file, String username) throws IOException {
Reform reform = ExcelUtil.parseExcel(file.getInputStream(),file.getOriginalFilename()); Reform reform = ExcelUtil.parseExcel(file.getInputStream(),file.getOriginalFilename());
reform.setUsername(username); reform.setUsername(username);
System.out.println("1");
return ServerResponse.ok(reform); return ServerResponse.ok(reform);
} }
} }
...@@ -15,4 +15,6 @@ public class BaseDes { ...@@ -15,4 +15,6 @@ public class BaseDes {
private String des; private String des;
@ApiModelProperty(value = "版本号") @ApiModelProperty(value = "版本号")
private String version; private String version;
@ApiModelProperty(value = "是否为其他项")
private Integer other;
} }
...@@ -45,7 +45,9 @@ public class ServerResponse<T> implements Serializable { ...@@ -45,7 +45,9 @@ public class ServerResponse<T> implements Serializable {
} }
public static <T> ServerResponse error(int status,String data){
return new ServerResponse(status,"请求失败",data);
}
public static <T> ServerResponse error(Object data){ public static <T> ServerResponse error(Object data){
return new ServerResponse(400,"请求失败",data); return new ServerResponse(400,"请求失败",data);
} }
......
...@@ -156,10 +156,10 @@ public class Inspector { ...@@ -156,10 +156,10 @@ public class Inspector {
initData(); initData();
//扫描文件,进行文件分类 //扫描文件,进行文件分类
HashMap<String, String> map = new HashMap<>(); HashMap<String, String> map = new HashMap<>();
map.put("file","开始扫描文件"); map.put("msg","开始扫描文件");
asyncTask.sendMessageToAll(map); asyncTask.sendMessageToAll(map);
scanFiles(); scanFiles();
map.put("file","文件扫描结束"); map.put("msg","文件扫描结束");
asyncTask.sendMessageToAll(map); asyncTask.sendMessageToAll(map);
//配置参数 //配置参数
inspectParameter.setCodeSize((int) codeSize); inspectParameter.setCodeSize((int) codeSize);
...@@ -171,10 +171,10 @@ public class Inspector { ...@@ -171,10 +171,10 @@ public class Inspector {
//根据扫描结果以及用户配置得出需要使用的规则及技术 //根据扫描结果以及用户配置得出需要使用的规则及技术
ruleTransform(inspectParameter.getRecastMethod()); ruleTransform(inspectParameter.getRecastMethod());
//扫描源代码文件 //扫描源代码文件
map.put("file","开始扫描源代码文件"); map.put("msg","开始扫描源代码文件");
asyncTask.sendMessageToAll(map); asyncTask.sendMessageToAll(map);
forEachFilesMap(); forEachFilesMap();
map.put("file","源代码文件扫描结束"); map.put("msg","源代码文件扫描结束");
asyncTask.sendMessageToAll(map); asyncTask.sendMessageToAll(map);
//将得到的告警信息根据技术id进行转换 //将得到的告警信息根据技术id进行转换
Set<String> technologyIds = warns.stream().map(Warn::getTechnologyId).collect(Collectors.toSet()); Set<String> technologyIds = warns.stream().map(Warn::getTechnologyId).collect(Collectors.toSet());
...@@ -256,7 +256,7 @@ public class Inspector { ...@@ -256,7 +256,7 @@ public class Inspector {
for (Path path1 : entry.getValue()) { for (Path path1 : entry.getValue()) {
try { try {
fileNum = fileNum + 1; fileNum = fileNum + 1;
map.put("totalFile", fileNum + "/" + fileSize); map.put("msg", fileNum + "/" + fileSize);
System.out.println(fileNum + "/" + fileSize); System.out.println(fileNum + "/" + fileSize);
asyncTask.sendMessageToAll(map); asyncTask.sendMessageToAll(map);
//如果文件类型为jar活着class则不读取 //如果文件类型为jar活着class则不读取
......
...@@ -24,7 +24,6 @@ public class AsyncTask { ...@@ -24,7 +24,6 @@ public class AsyncTask {
* @Author: LiuJie * @Author: LiuJie
* @Date: 2019/5/20 * @Date: 2019/5/20
*/ */
@Async("myTaskAsyncPool")
public void sendMessageToAll(Map<String,String> map) { public void sendMessageToAll(Map<String,String> map) {
webSocketServer.sendMessageToAll(map); webSocketServer.sendMessageToAll(map);
} }
......
...@@ -311,9 +311,14 @@ public class ExcelUtil { ...@@ -311,9 +311,14 @@ public class ExcelUtil {
ArrayList<DatabaseType> databaseTypes = new ArrayList<>(); ArrayList<DatabaseType> databaseTypes = new ArrayList<>();
for (int i = 74; i < 77; i++) { for (int i = 74; i < 77; i++) {
String database = getExcelCell(i, 2, sheetAt); String database = getExcelCell(i, 2, sheetAt);
String version = getExcelCell(i, 3, sheetAt);
String remark = getExcelCell(i, 4, sheetAt);
if (!"".equals(database)) { if (!"".equals(database)) {
DatabaseType byName = DatabaseType.getByName(database); DatabaseType databaseType = DatabaseType.getByName(database);
databaseTypes.add(byName); databaseTypes.add(databaseType);
}
if(!"".equals(remark)){
database1.setOtherContent(remark);
} }
} }
database1.setDatabaseType(databaseTypes); database1.setDatabaseType(databaseTypes);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论