提交 675c3740 authored 作者: 孙洁清's avatar 孙洁清

路由规则

上级 ddfa4f29
......@@ -6,7 +6,7 @@ import org.springframework.web.socket.server.standard.ServerEndpointExporter;
@Configuration
public class WebSocketConfig {
// @Bean
@Bean
public ServerEndpointExporter serverEndpointExporter() {
return new ServerEndpointExporter();
}
......
......@@ -14,6 +14,7 @@ import com.zjty.autotest.service.impl.SeleniumExecutor;
import com.zjty.autotest.util.FileHtmlUtil;
import com.zjty.autotest.util.IdWorker;
import com.zjty.autotest.util.UnZipRarUtil;
import com.zjty.autotest.websocket.WebSocketServer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
......@@ -22,6 +23,7 @@ import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import java.io.IOException;
import java.util.*;
import java.util.function.Predicate;
import java.util.stream.Collectors;
......@@ -80,7 +82,7 @@ public class TestTask {
Report report = seleniumExecutor.execute(project);
System.out.println(report);
List<Measure> measures = report.getMeasures();
if(measures!=null) {
if(measures!=null&&measures.size()>0) {
long count = measures.stream().filter(m -> !m.getSuccess()).count();
System.out.println(report);
EvaReport evaReport = new EvaReport();
......@@ -187,10 +189,10 @@ public class TestTask {
pageRoutes.add(route);
List<PageRoute> ps = routemap.get(s);
if(ps!=null){
routemap.put(s,pageRoutes);
}else{
ps.add(route);
routemap.put(s,ps);
}else{
routemap.put(s,pageRoutes);
}
}
......@@ -217,9 +219,15 @@ public class TestTask {
testReportService.update(testReport);
autoResultSetService.updateByid(id);
WebSocketServer.sendInfo("测试完成,"+id,"sjq110");
}
} catch (Exception e) {
e.printStackTrace();
try {
WebSocketServer.sendInfo("测试失败,"+id,"sjq110");
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
......@@ -229,36 +237,38 @@ public class TestTask {
String pattern="(\\/:*[a-zA-Z0-9]+)+";
List<String> allRouters = new ArrayList<>();
Set<String> all = alls.keySet();
//所有的路由
if (fileRoutes.equals("vue")) {
for (String s1 : all) {
List<FileType> fileBeans = alls.get(s1);
if (fileRoutes != null) {
if (s1.contains("router")) {
for (FileType fileBean : fileBeans) {
allRouters.addAll(FileHtmlUtil.readTxtFile(fileBean.getAddress(), pattern));
if(all!=null) {
//所有的路由
if (fileRoutes.equals("vue")) {
for (String s1 : all) {
List<FileType> fileBeans = alls.get(s1);
if (fileRoutes != null) {
if (s1.contains("router")) {
for (FileType fileBean : fileBeans) {
allRouters.addAll(FileHtmlUtil.readTxtFile(fileBean.getAddress(), pattern));
}
}
}
}
}
}else if(fileRoutes.equals("angular")||fileRoutes.equals("react")){
for (String s1 : all) {
List<FileType> fileBeans = alls.get(s1);
if (fileRoutes != null) {
for (FileType fileBean : fileBeans) {
if(fileBean.getSuffix().equals("js")) {
allRouters.addAll(FileHtmlUtil.readTxtFile(fileBean.getAddress(), pattern));
} else if (fileRoutes.equals("angular") || fileRoutes.equals("react")) {
for (String s1 : all) {
List<FileType> fileBeans = alls.get(s1);
if (fileRoutes != null) {
for (FileType fileBean : fileBeans) {
if (fileBean.getSuffix().equals("js")) {
allRouters.addAll(FileHtmlUtil.readTxtFile(fileBean.getAddress(), pattern));
}
}
}
}
}
}else{
for (String s1 : all) {
List<FileType> fileBeans = alls.get(s1);
if (fileRoutes != null) {
for (FileType fileBean : fileBeans) {
if(fileBean.getSuffix().equals("jsp")) {
allRouters.addAll(FileHtmlUtil.readTxtFile(fileBean.getAddress(), pattern));
} else {
for (String s1 : all) {
List<FileType> fileBeans = alls.get(s1);
if (fileRoutes != null) {
for (FileType fileBean : fileBeans) {
if (fileBean.getSuffix().equals("jsp")) {
allRouters.addAll(FileHtmlUtil.readTxtFile(fileBean.getAddress(), pattern));
}
}
}
}
......
......@@ -34,13 +34,13 @@ public class UploadCodeServiceImpl implements UploadCodeService {
return ResponseResult.errorResult(AppHttpCodeEnum.File_Empty);
}
String fileName = file.getOriginalFilename();
// String fileType = fileName.substring(fileName.lastIndexOf("."));
File dest = new File(uploadFile +File.separator+idWorker.nextId()+File.separator+fileName);
String fileType = fileName.substring(0,fileName.lastIndexOf("."));
File dest = new File(uploadFile +File.separator+idWorker.nextId()+File.separator+fileType);
if (!dest.getParentFile().exists()) {
dest.getParentFile().mkdirs();
}
file.transferTo(dest);
String toUrl=uploadUnFile+File.separator+idWorker.nextId()+File.separator+fileName;
String toUrl=uploadUnFile+idWorker.nextId()+File.separator+fileName;
String s = UnZipRarUtil.zipRarToFile(fileName, dest.getPath(), toUrl);
FileBean bean=new FileBean(s,fileName);
......@@ -53,4 +53,6 @@ public class UploadCodeServiceImpl implements UploadCodeService {
}
}
package com.zjty.autotest.websocket;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import javax.websocket.*;
import javax.websocket.server.PathParam;
import javax.websocket.server.ServerEndpoint;
import java.io.IOException;
import java.util.concurrent.ConcurrentHashMap;
@ServerEndpoint("/imserver/{userId}")
@Component
@Slf4j
public class WebSocketServer {
/**静态变量,用来记录当前在线连接数。应该把它设计成线程安全的。*/
private static int onlineCount = 0;
/**concurrent包的线程安全Set,用来存放每个客户端对应的MyWebSocket对象。*/
private static ConcurrentHashMap<String,WebSocketServer> webSocketMap = new ConcurrentHashMap<>();
/**与某个客户端的连接会话,需要通过它来给客户端发送数据*/
private Session session;
/**接收userId*/
private String userId="";
/**
* 连接建立成功调用的方法*/
@OnOpen
public void onOpen(Session session,@PathParam("userId") String userId) {
this.session = session;
this.userId=userId;
if(webSocketMap.containsKey(userId)){
webSocketMap.remove(userId);
webSocketMap.put(userId,this);
//加入set中
}else{
webSocketMap.put(userId,this);
//加入set中
addOnlineCount();
//在线数加1
}
log.info("用户连接:"+userId+",当前在线人数为:" + getOnlineCount());
try {
sendMessage("连接成功");
} catch (IOException e) {
log.error("用户:"+userId+",网络异常!!!!!!");
}
}
/**
* 连接关闭调用的方法
*/
@OnClose
public void onClose() {
if(webSocketMap.containsKey(userId)){
webSocketMap.remove(userId);
//从set中删除
subOnlineCount();
}
log.info("用户退出:"+userId+",当前在线人数为:" + getOnlineCount());
}
/**
* 收到客户端消息后调用的方法
*
* @param message 客户端发送过来的消息*/
@OnMessage
public void onMessage(String message, Session session) {
log.info("用户消息:"+userId+",报文:"+message);
//可以群发消息
//消息保存到数据库、redis
/*if(StringUtils.isNotBlank(message)){
try {
//解析发送的报文
JSONObject jsonObject = JSON.parseObject(message);
//追加发送人(防止串改)
jsonObject.put("fromUserId",this.userId);
String toUserId=jsonObject.getString("toUserId");
//传送给对应toUserId用户的websocket
if(StringUtils.isNotBlank(toUserId)&&webSocketMap.containsKey(toUserId)){
webSocketMap.get(toUserId).sendMessage(jsonObject.toJSONString());
}else{
log.error("请求的userId:"+toUserId+"不在该服务器上");
//否则不在这个服务器上,发送到mysql或者redis
}
}catch (Exception e){
e.printStackTrace();
}
}*/
}
/**
*
* @param session
* @param error
*/
@OnError
public void onError(Session session, Throwable error) {
log.error("用户错误:"+this.userId+",原因:"+error.getMessage());
error.printStackTrace();
}
/**
* 实现服务器主动推送
*/
public void sendMessage(String message) throws IOException {
this.session.getBasicRemote().sendText(message);
}
/**
* 发送自定义消息
* */
public static void sendInfo(String message,@PathParam("userId") String userId) throws IOException {
log.info("发送消息到:"+userId+",报文:"+message);
if(StringUtils.isNotBlank(userId)&&webSocketMap.containsKey(userId)){
webSocketMap.get(userId).sendMessage(message);
}else{
log.error("用户"+userId+",不在线!");
}
}
public static synchronized int getOnlineCount() {
return onlineCount;
}
public static synchronized void addOnlineCount() {
WebSocketServer.onlineCount++;
}
public static synchronized void subOnlineCount() {
WebSocketServer.onlineCount--;
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论