fix(接口定义): 修复已知问题并完成优化需求 #1003813

--story=1003813 --user=赵勇 场景上传 csv 文件优化 https://www.tapd.cn/55049933/s/1065761
This commit is contained in:
fit2-zhao 2021-11-09 18:49:27 +08:00 committed by fit2-zhao
parent 07b58b41c5
commit 6fb6884093
4 changed files with 26 additions and 24 deletions

View File

@ -35,8 +35,8 @@ public class FixedTask {
ReportCounter counter = MessageCache.cache.get(key); ReportCounter counter = MessageCache.cache.get(key);
LogUtil.info("集成报告:【" + key + "】总执行场景:【" + counter.getReportIds().size() + "】已经执行完成场景:【" + counter.getCompletedIds().size() + ""); LogUtil.info("集成报告:【" + key + "】总执行场景:【" + counter.getReportIds().size() + "】已经执行完成场景:【" + counter.getCompletedIds().size() + "");
List<String> filterList = counter.getReportIds().stream().filter(t -> !counter.getCompletedIds().contains(t)).collect(Collectors.toList()); List<String> filterList = counter.getReportIds().stream().filter(t -> !counter.getCompletedIds().contains(t)).collect(Collectors.toList());
LogUtil.info("剩余要执行的报告" + JSON.toJSONString(filterList));
LogUtil.debug("剩余要执行的报告" + JSON.toJSONString(filterList));
// 合并 // 合并
if (counter.getCompletedIds().size() >= counter.getReportIds().size()) { if (counter.getCompletedIds().size() >= counter.getReportIds().size()) {
scenarioReportService.margeReport(key, counter.getReportIds()); scenarioReportService.margeReport(key, counter.getReportIds());
@ -55,7 +55,7 @@ public class FixedTask {
// 资源池中已经没有执行的请求了 // 资源池中已经没有执行的请求了
int runningCount = scenarioReportService.get(key, counter); int runningCount = scenarioReportService.get(key, counter);
if (runningCount == 0) { if (runningCount == 0) {
LogUtil.info("发生未知异常,进行资源合并,请检查资源池是否正常运行"); LogUtil.error("发生未知异常,进行资源合并,请检查资源池是否正常运行");
scenarioReportService.margeReport(key, counter.getReportIds()); scenarioReportService.margeReport(key, counter.getReportIds());
guardTask.remove(key); guardTask.remove(key);
MessageCache.cache.remove(key); MessageCache.cache.remove(key);

View File

@ -1361,23 +1361,16 @@ public class ApiAutomationService {
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH); SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
ApiScenarioReportMapper batchMapper = sqlSession.getMapper(ApiScenarioReportMapper.class); ApiScenarioReportMapper batchMapper = sqlSession.getMapper(ApiScenarioReportMapper.class);
// 开始并发执行 // 开始并发执行
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
for (String reportId : executeQueue.keySet()) { for (String reportId : executeQueue.keySet()) {
//存储报告 //存储报告
APIScenarioReportResult report = executeQueue.get(reportId).getReport(); APIScenarioReportResult report = executeQueue.get(reportId).getReport();
batchMapper.insert(report); batchMapper.insert(report);
// 增加一个本地锁防止并发找不到资源
MessageCache.scenarioExecResourceLock.put(reportId, report); MessageCache.scenarioExecResourceLock.put(reportId, report);
} }
sqlSession.flushStatements(); sqlSession.flushStatements();
sqlSession.commit();
}
});
thread.start();
for (String reportId : executeQueue.keySet()) { for (String reportId : executeQueue.keySet()) {
// 增加一个本地锁防止并发找不到资源
if (request.getConfig() != null && StringUtils.isNotEmpty(request.getConfig().getResourcePoolId())) { if (request.getConfig() != null && StringUtils.isNotEmpty(request.getConfig().getResourcePoolId())) {
String testPlanScenarioId = ""; String testPlanScenarioId = "";
if (request.getScenarioTestPlanIdMap() != null && request.getScenarioTestPlanIdMap().containsKey(executeQueue.get(reportId).getTestId())) { if (request.getScenarioTestPlanIdMap() != null && request.getScenarioTestPlanIdMap().containsKey(executeQueue.get(reportId).getTestId())) {

View File

@ -519,11 +519,18 @@ public class ApiScenarioReportService {
ApiScenarioReportExample scenarioReportExample = new ApiScenarioReportExample(); ApiScenarioReportExample scenarioReportExample = new ApiScenarioReportExample();
scenarioReportExample.createCriteria().andScenarioIdIn(list); scenarioReportExample.createCriteria().andScenarioIdIn(list);
List<ApiScenarioReport> reportList = apiScenarioReportMapper.selectByExample(scenarioReportExample); List<ApiScenarioReport> reportList = apiScenarioReportMapper.selectByExample(scenarioReportExample);
list.forEach(item ->{
if(MessageCache.scenarioExecResourceLock.containsKey(item)) { if (CollectionUtils.isEmpty(reportList)) {
ApiScenarioReportExample example = new ApiScenarioReportExample();
example.createCriteria().andIdIn(list);
reportList = apiScenarioReportMapper.selectByExample(example);
}
for (String item : list) {
if (MessageCache.scenarioExecResourceLock.containsKey(item)) {
reportList.add(MessageCache.scenarioExecResourceLock.get(item)); reportList.add(MessageCache.scenarioExecResourceLock.get(item));
} }
}); }
for (ApiScenarioReport report : reportList) { for (ApiScenarioReport report : reportList) {
report.setStatus("Error"); report.setStatus("Error");
apiScenarioReportMapper.updateByPrimaryKey(report); apiScenarioReportMapper.updateByPrimaryKey(report);

View File

@ -33,6 +33,8 @@
</template> </template>
<script> <script>
import {downloadFile} from "@/common/js/utils";
export default { export default {
name: "MsApiBodyFileUpload", name: "MsApiBodyFileUpload",
data() { data() {
@ -50,7 +52,7 @@ export default {
download() { download() {
// //
if (this.parameter.files && this.parameter.files.length > 0 && this.parameter.files[0].file) { if (this.parameter.files && this.parameter.files.length > 0 && this.parameter.files[0].file) {
console.log("local",this.parameter.files[0].file) downloadFile(this.parameter.files[0].file.name, this.parameter.files[0].file);
} }
// //
if (this.parameter.files && this.parameter.files.length > 0 && !this.parameter.files[0].file) { if (this.parameter.files && this.parameter.files.length > 0 && !this.parameter.files[0].file) {
@ -63,9 +65,9 @@ export default {
}; };
this.result = this.$request(conf).then(response => { this.result = this.$request(conf).then(response => {
const content = response.data; const content = response.data;
const blob = new Blob([content]); if(content && this.parameter.files[0]) {
console.log(content) downloadFile(this.parameter.files[0].name, content);
}
}); });
} }
}, },