提交 9651099a authored 作者: 孙洁清's avatar 孙洁清

路由规则

上级 e5dccc09
...@@ -7,6 +7,8 @@ import org.springframework.data.jpa.repository.Modifying; ...@@ -7,6 +7,8 @@ import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param; import org.springframework.data.repository.query.Param;
import javax.transaction.Transactional;
import java.beans.Transient;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -25,6 +27,10 @@ public interface TestReportDao extends JpaRepository<TestReport,String>, JpaSpec ...@@ -25,6 +27,10 @@ public interface TestReportDao extends JpaRepository<TestReport,String>, JpaSpec
TestReport findByResultId(@Param("resultId") String resultId); TestReport findByResultId(@Param("resultId") String resultId);
@Modifying @Modifying
int deleteByResultId(@Param("resultId") String resultId); int deleteByResultId(@Param("resultId") String resultId);
@Modifying
@Transactional
@Query("update TestReport set outReport=:outReport,status=1 where resultId=:resultId")
void updateOut(String outReport,String resultId);
@Query(value = "select result_id,status from test_report ",nativeQuery = true) @Query(value = "select result_id,status from test_report ",nativeQuery = true)
List<Map<String,Object>> findAllStatus(); List<Map<String,Object>> findAllStatus();
......
...@@ -17,6 +17,9 @@ import org.springframework.stereotype.Component; ...@@ -17,6 +17,9 @@ import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import java.util.*; import java.util.*;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@Component @Component
@Slf4j @Slf4j
...@@ -29,10 +32,10 @@ public class TestTask { ...@@ -29,10 +32,10 @@ public class TestTask {
@Scheduled(cron = "0/1 * * * * ?") @Scheduled(cron = "0/1 * * * * ?")
@Async("asyncServiceExecutor") @Async("asyncServiceExecutor")
public void getMessage(){ public void getMessage() {
String take = QueueManager.take(); String take = QueueManager.take();
log.info("获取到消息:{}",take); log.info("获取到消息:{}", take);
if(!StringUtils.isEmpty(take)){ if (!StringUtils.isEmpty(take)) {
doBusiness(take); doBusiness(take);
} }
} }
...@@ -42,7 +45,7 @@ public class TestTask { ...@@ -42,7 +45,7 @@ public class TestTask {
TestChannel testChannel = (TestChannel) CacheManager.getCache(id); TestChannel testChannel = (TestChannel) CacheManager.getCache(id);
if (testChannel != null) { if (testChannel != null) {
log.info("testChannel不为空:{}",testChannel); log.info("testChannel不为空:{}", testChannel);
try { try {
EvaReport evaReport = new EvaReport(); EvaReport evaReport = new EvaReport();
evaReport.setBrowser(testChannel.getBrowser()); evaReport.setBrowser(testChannel.getBrowser());
...@@ -101,25 +104,34 @@ public class TestTask { ...@@ -101,25 +104,34 @@ public class TestTask {
Thread.sleep(600); Thread.sleep(600);
if (testChannel.getCodeUrl() != null) { if (testChannel.getCodeUrl() != null) {
//解压上传得代码 //解压上传得代码
String fileRoutes = FileHtmlUtil.getFileRoutes(testChannel.getCodeUrl());
FileHtmlUtil.getFiles(testChannel.getCodeUrl(),null); FileHtmlUtil.getFiles(testChannel.getCodeUrl(), null);
Map<String, List<FileBean>> alls = FileHtmlUtil.getAlls(); Map<String, List<FileType>> alls = FileHtmlUtil.getAlls();
//所有的路由
List<String> allRouters=new ArrayList<>(); //获取项目类型
Set<String> all = alls.keySet(); FileHtmlUtil.getFileRoutes(testChannel.getCodeUrl());
for (String s1 : all) { int jspcount=FileHtmlUtil.jspNum;
List<FileBean> fileBeans = alls.get(s1); int jscount=FileHtmlUtil.jsNum;
if(fileRoutes!=null) { int vuecount=FileHtmlUtil.vueNum;
if (s1.contains("router")) { int angularcount=FileHtmlUtil.angularNum;
for (FileBean fileBean : fileBeans) { int htmlcount=FileHtmlUtil.count;
allRouters.addAll(FileHtmlUtil.readTxtFile(fileBean.getUrl(), "(\\/:*[a-zA-Z0-9]*)+")); String fileRoutes=null;
} if(jspcount>0){
} fileRoutes="jsp";
} }else if(vuecount>0){
fileRoutes="vue";
}else if(jscount>0){
fileRoutes="react";
}else if(angularcount>0){
fileRoutes="angular";
} }
for (String allRouter : allRouters) { if (fileRoutes != null) {
System.out.println("路由:"+allRouter); List<String> routerList = getRouterList(alls, fileRoutes);
List<String> collect = routerList.stream().map(String::toLowerCase).distinct().collect(Collectors.toList());
System.out.println(collect.toString());
} }
FileHtmlUtil.clearAll(); FileHtmlUtil.clearAll();
//获取前端代码中得网页路由地址 //获取前端代码中得网页路由地址
//比对黄承天代码中访问得地址和路由地址,黄承天是否访问全了。 //比对黄承天代码中访问得地址和路由地址,黄承天是否访问全了。
...@@ -141,4 +153,47 @@ public class TestTask { ...@@ -141,4 +153,47 @@ public class TestTask {
} }
} }
private List<String> getRouterList(Map<String, List<FileType>> alls, String fileRoutes) {
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(), "(\\/:*[a-zA-Z0-9]*)+"));
}
}
}
}
}else if(fileRoutes.equals("angular")||fileRoutes.equals("react")){
for (String s1 : all) {
List<FileType> fileBeans = alls.get(s1);
if (fileRoutes != null) {
if (s1.contains("router")||s1.contains("js")) {
for (FileType fileBean : fileBeans) {
allRouters.addAll(FileHtmlUtil.readTxtFile(fileBean.getAddress(), "(\\/:*[a-zA-Z0-9]*)+"));
}
}
}
}
}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(), "(\\/:*[a-zA-Z0-9]*)+"));
}
}
}
}
}
return allRouters;
}
} }
package com.zjty.autotest.pojo.sjq;
import io.swagger.annotations.ApiModel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
public class FileType {
private String address;
private String suffix;
private String fileName;
}
...@@ -105,6 +105,7 @@ public class AutoResultSetServiceImpl implements AutoResultSetService { ...@@ -105,6 +105,7 @@ public class AutoResultSetServiceImpl implements AutoResultSetService {
AutoResultSet save = autoResultSetDao.save(autoResultSet); AutoResultSet save = autoResultSetDao.save(autoResultSet);
String in = JSON.toJSONString(testChannel); String in = JSON.toJSONString(testChannel);
TestReport testReport = new TestReport(); TestReport testReport = new TestReport();
testReport.setId(idWorker.nextId()+"");
testReport.setResultId(tid); testReport.setResultId(tid);
testReport.setStatus(0); testReport.setStatus(0);
testReport.setInputReport(in); testReport.setInputReport(in);
......
...@@ -76,12 +76,7 @@ public class TestReportServiceImpl implements TestReportService { ...@@ -76,12 +76,7 @@ public class TestReportServiceImpl implements TestReportService {
* @param testReport * @param testReport
*/ */
public void update(TestReport testReport) { public void update(TestReport testReport) {
TestReport report = testReportDao.findByResultId(testReport.getResultId()); testReportDao.updateOut(testReport.getOutReport(),testReport.getResultId());
if(report!=null) {
report.setStatus(1);
report.setOutReport(testReport.getOutReport());
testReportDao.save(testReport);
}
} }
/** /**
...@@ -96,18 +91,9 @@ public class TestReportServiceImpl implements TestReportService { ...@@ -96,18 +91,9 @@ public class TestReportServiceImpl implements TestReportService {
@Transient @Transient
@Override @Override
public ResponseResult save(TestReport testReport) { public ResponseResult save(TestReport testReport) {
System.out.println(testReport);
if(testReport!=null){
testReport.setId(idWorker.nextId()+"");
// testReport.setOutReport(testReport.getOutReport());
testReport.setStatus(testReport.getStatus());
testReport.setInputReport(testReport.getInputReport());
testReport.setResultId(testReport.getResultId());
testReportDao.save(testReport); testReportDao.save(testReport);
return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS); return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
} }
return ResponseResult.errorResult(AppHttpCodeEnum.ERROR);
}
@Transient @Transient
@Override @Override
public ResponseResult addInReport(String id, String inReport) { public ResponseResult addInReport(String id, String inReport) {
......
package com.zjty.autotest.util; package com.zjty.autotest.util;
import com.zjty.autotest.pojo.sjq.FileBean; import com.zjty.autotest.pojo.sjq.FileBean;
import com.zjty.autotest.pojo.sjq.FileType;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import java.io.BufferedReader; import java.io.BufferedReader;
...@@ -13,31 +14,43 @@ import java.util.regex.Pattern; ...@@ -13,31 +14,43 @@ import java.util.regex.Pattern;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class FileHtmlUtil { public class FileHtmlUtil {
private static List<String> routes=new ArrayList<>(80); public static int count = 0;
private static List<String> urls=new ArrayList<>(200); public static int angularNum = 0;
private static HashMap<String,List<FileBean>> alls=new HashMap<>(200); public static int jsNum = 0;
public static int jspNum = 0;
public static int vueNum = 0;
private static List<String> routes = new ArrayList<>(80);
private static List<String> urls = new ArrayList<>(200);
private static HashMap<String, List<FileType>> alls = new HashMap<>(200);
public static HashMap<String,List<FileBean>> getAlls(){ public static HashMap<String, List<FileType>> getAlls() {
return alls; return alls;
} }
public static void clearAll(){
if(routes!=null) { public static void clearAll() {
if (routes != null) {
routes.clear(); routes.clear();
System.out.println("routes:="+routes); System.out.println("routes:=" + routes);
} }
if(urls!=null) { if (urls != null) {
urls.clear(); urls.clear();
System.out.println("urls:="+urls); System.out.println("urls:=" + urls);
} }
if(alls!=null) { if (alls != null) {
alls.clear(); alls.clear();
System.out.println("alls:="+alls); System.out.println("alls:=" + alls);
} }
count = 0;
jspNum = 0;
jsNum = 0;
vueNum = 0;
angularNum = 0;
} }
public static List<String> readTxtFile(String filePath, String pattern) { public static List<String> readTxtFile(String filePath, String pattern) {
Pattern p; Pattern p;
Matcher m; Matcher m;
Set<String> set=new HashSet<String>(); Set<String> set = new HashSet<String>();
try { try {
String encoding = "UTF-8"; String encoding = "UTF-8";
File file = new File(filePath); File file = new File(filePath);
...@@ -46,7 +59,7 @@ public class FileHtmlUtil { ...@@ -46,7 +59,7 @@ public class FileHtmlUtil {
new FileInputStream(file), encoding);// 考虑到编码格式 new FileInputStream(file), encoding);// 考虑到编码格式
BufferedReader bufferedReader = new BufferedReader(read); BufferedReader bufferedReader = new BufferedReader(read);
String lineTxt = null; String lineTxt = null;
StringBuilder sb=new StringBuilder(); StringBuilder sb = new StringBuilder();
if (pattern != null) { if (pattern != null) {
while ((lineTxt = bufferedReader.readLine()) != null) { while ((lineTxt = bufferedReader.readLine()) != null) {
sb.append(lineTxt); sb.append(lineTxt);
...@@ -55,9 +68,9 @@ public class FileHtmlUtil { ...@@ -55,9 +68,9 @@ public class FileHtmlUtil {
String s = sb.toString(); String s = sb.toString();
p = Pattern.compile(pattern); p = Pattern.compile(pattern);
m = p.matcher(s); m = p.matcher(s);
while(m.find()){ while (m.find()) {
String pp = m.group().substring(0, m.group().length()); String pp = m.group().substring(0, m.group().length());
if(!pp.equals("//")) { if (!pp.equals("//")) {
set.add(pp.toLowerCase()); set.add(pp.toLowerCase());
} }
} }
...@@ -75,83 +88,8 @@ public class FileHtmlUtil { ...@@ -75,83 +88,8 @@ public class FileHtmlUtil {
return null; return null;
} }
public static void main(String[] args) {
String str="import Vue from 'vue'\n" + public static void getFiles(String path, String dirName) {
"import Router from 'vue-router'\n" +
"import Index from '@/Index'\n" +
"import SocialIndex from '@/SocialIndex'\n" +
"import SocialDetail from '@/SocialDetail'\n" +
"import SocialPost from '@/SocialPost'\n" +
"\n" +
"Vue.use(Router)\n" +
"\n" +
"export default new Router({\n" +
" // mode: 'history',\n" +
" // hashbang: false,\n" +
" // history: false,\n" +
" routes: [\n" +
" {\n" +
" path: '/',\n" +
" name: 'index',\n" +
" component: Index,\n" +
" meta: {\n" +
" title: '这是个圈子',\n" +
" keepAlive: false\n" +
" }\n" +
" },\n" +
" {\n" +
" path: '/index',\n" +
" name: 'index',\n" +
" component: Index,\n" +
" meta: {\n" +
" title: '这是个圈子',\n" +
" keepAlive: false\n" +
" }\n" +
" },\n" +
" {\n" +
" path: '/circle/:circleId',\n" +
" name: 'circle',\n" +
" component: SocialIndex,\n" +
" meta: {\n" +
" title: '这是个圈子',\n" +
" keepAlive: false\n" +
" }\n" +
" },\n" +
" {\n" +
" path: '/post/:circleId/:postId/:onPage',\n" +
" name: 'post',\n" +
" component: SocialDetail,\n" +
" meta: {\n" +
" title: '这是个圈子',\n" +
" keepAlive: false\n" +
" }\n" +
" },\n" +
" {\n" +
" path: '/SocialPost/:circleId',\n" +
" name: 'SocialPost',\n" +
" component: SocialPost,\n" +
" meta: {\n" +
" title: '这是个圈子',\n" +
" keepAlive: false\n" +
" }\n" +
" }\n" +
" ]\n" +
"})\n";
Set<String> set=new HashSet<String>();
Pattern p = Pattern.compile("(\\/:*[a-zA-Z0-9]*)+");
Matcher m = p.matcher(str);
while(m.find()){
String substring = m.group().substring(0, m.group().length());
if(!substring.equals("//")) {
set.add(substring.toLowerCase());
}
// System.out.println(m.group().substring(0, m.group().length()));
}
for (String o : set) {
System.out.println(o);
}
}
public static void getFiles(String path, String dirName){
File file = new File(path); File file = new File(path);
// 如果这个路径是文件夹 // 如果这个路径是文件夹
...@@ -161,31 +99,34 @@ public class FileHtmlUtil { ...@@ -161,31 +99,34 @@ public class FileHtmlUtil {
for (int i = 0; i < files.length; i++) { for (int i = 0; i < files.length; i++) {
// 如果还是文件夹 递归获取里面的文件 文件夹 // 如果还是文件夹 递归获取里面的文件 文件夹
if (files[i].isDirectory()) { if (files[i].isDirectory()) {
if(!files[i].getName().equalsIgnoreCase("img")||!files[i].getName().equalsIgnoreCase("plugins") if (files[i].getName().contains("img") || files[i].getName().contains("plugins")
||!files[i].getName().equalsIgnoreCase("css")||!files[i].getName().equalsIgnoreCase("node_modules") || files[i].getName().contains("css") || files[i].getName().contains("node_modules")) {
) { continue;
// System.out.println("routes:" + files[i].getPath()); } else {
System.out.println("文件夹:" + files[i].getName());
getFiles(files[i].getPath(), files[i].getName()); getFiles(files[i].getPath(), files[i].getName());
} }
} else { } else {
if(alls.get(dirName)!=null){
List<FileBean> fileBeans = alls.get(dirName);
FileBean fileBean=new FileBean();
fileBean.setFileType(files[i].getName());
fileBean.setUrl(files[i].getAbsolutePath());
fileBeans.add(fileBean);
}else {
int pos = files[i].getName().lastIndexOf("."); int pos = files[i].getName().lastIndexOf(".");
String extName = files[i].getName().substring(pos + 1).toLowerCase(); String extName = files[i].getName().substring(pos + 1).toLowerCase();
if(extName.equals("js")||extName.equals("html")||extName.equals("jsp")) { if (extName.equals("js") || extName.equals("html") || extName.equals("jsp")) {
List<FileBean> fileBeans = new ArrayList<>(); System.out.println("文件:" + files[i].getName());
FileBean fileBean = new FileBean(); if (alls.get(dirName) != null) {
fileBean.setFileType(files[i].getName()); List<FileType> fileBeans = alls.get(dirName);
fileBean.setUrl(files[i].getAbsolutePath()); FileType fileBean = new FileType();
fileBean.setFileName(files[i].getName());
fileBean.setAddress(files[i].getAbsolutePath());
fileBean.setSuffix(extName);
fileBeans.add(fileBean);
} else {
List<FileType> fileBeans = new ArrayList<>();
FileType fileBean = new FileType();
fileBean.setFileName(files[i].getName());
fileBean.setAddress(files[i].getAbsolutePath());
fileBean.setSuffix(extName);
fileBeans.add(fileBean); fileBeans.add(fileBean);
alls.put(dirName, fileBeans); alls.put(dirName, fileBeans);
// System.out.println("文件名:" + files[i].getName());
// System.out.println("文件:" + files[i].getAbsolutePath());
} }
} }
} }
...@@ -195,7 +136,9 @@ public class FileHtmlUtil { ...@@ -195,7 +136,9 @@ public class FileHtmlUtil {
System.out.println("文件1:" + file.getPath()); System.out.println("文件1:" + file.getPath());
} }
} }
public static String getFileRoutes(String path){
public static void getFileRoutes(String path) {
File file = new File(path); File file = new File(path);
// 如果这个路径是文件夹 // 如果这个路径是文件夹
...@@ -205,33 +148,37 @@ public class FileHtmlUtil { ...@@ -205,33 +148,37 @@ public class FileHtmlUtil {
for (int i = 0; i < files.length; i++) { for (int i = 0; i < files.length; i++) {
// 如果还是文件夹 递归获取里面的文件 文件夹 // 如果还是文件夹 递归获取里面的文件 文件夹
if (files[i].isDirectory()) { if (files[i].isDirectory()) {
if(!files[i].getName().equalsIgnoreCase("img") ||!files[i].getName().equalsIgnoreCase("css") if (files[i].getName().contains("img") || files[i].getName().contains("css")
||!files[i].getName().equalsIgnoreCase("node_modules")){ || files[i].getName().contains("node_modules")) {
if(files[i].getName().contains("angular")){ continue;
return "angular"; } else {
} if (files[i].getName().contains("angular")) {
if(files[i].getName().contains("vue")){ angularNum++;
return "vue";
} }
// System.out.println("文件夹:"+files[i].getName());
getFileRoutes(files[i].getPath()); getFileRoutes(files[i].getPath());
} }
} else { } else {
// System.out.println("文件:"+files[i].getName());
int pos = files[i].getName().lastIndexOf("."); int pos = files[i].getName().lastIndexOf(".");
String extName = files[i].getName().substring(pos + 1).toLowerCase(); String extName = files[i].getName().substring(pos + 1).toLowerCase();
if(extName.equals("vue")){ if (extName.equals("vue")) {
return "vue"; vueNum++;
} } else if (extName.equals("jsp")) {
if(extName.equals("jsp")){ jspNum++;
return "jsp"; } else if (extName.equals("html")) {
count++;
} else if (extName.equals("js")) {
jsNum++;
} }
} }
} }
} else { } else {
System.out.println("文件:" + file.getPath()); System.out.println("文件:" + file.getPath());
} }
return null;
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论