Skip to content
This repository has been archived by the owner on May 9, 2024. It is now read-only.

Commit

Permalink
代码整理
Browse files Browse the repository at this point in the history
  • Loading branch information
LinuxSuRen committed Jun 17, 2017
1 parent d21aec2 commit ed1f8d4
Show file tree
Hide file tree
Showing 4 changed files with 193 additions and 45 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,11 @@
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>

<dependency>
<groupId>org.modelmapper</groupId>
<artifactId>modelmapper</artifactId>
<version>0.7.5</version>
</dependency>
</dependencies>
</project>
45 changes: 0 additions & 45 deletions src/main/java/com/surenpi/autotest/report/ExcelReport.java

This file was deleted.

62 changes: 62 additions & 0 deletions src/main/java/com/surenpi/autotest/report/ExcelReportWriter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.surenpi.autotest.report;

import com.surenpi.autotest.report.model.ExcelReport;
import com.surenpi.autotest.report.record.ExceptionRecord;
import com.surenpi.autotest.report.record.NormalRecord;
import com.surenpi.autotest.report.record.ProjectRecord;
import com.surenpi.autotest.report.util.DateUtils;
import org.modelmapper.ModelMapper;
import org.springframework.stereotype.Component;

import javax.annotation.PreDestroy;
import java.io.File;

/**
* Excel格式报告导出
* @author suren
*/
@Component
public class ExcelReportWriter implements RecordReportWriter
{
private ExcelUtils utils;

@Override
public void write(ExceptionRecord record)
{
NormalRecord normalRecord = record.getNormalRecord();

ModelMapper mapper = new ModelMapper();
ExcelReport excelReport = mapper.map(normalRecord, ExcelReport.class);
excelReport.setDetail(record.getStackTraceText());
excelReport.setStatus(ReportStatus.EXCEPTION.name());
excelReport.setBeginTime(DateUtils.getDateText(normalRecord.getBeginTime()));
excelReport.setEndTime(DateUtils.getDateText(normalRecord.getEndTime()));

utils.export(excelReport);
}

@Override
public void write(NormalRecord normalRecord)
{
ExcelReport excelReport = new ModelMapper().map(normalRecord, ExcelReport.class);
excelReport.setStatus(ReportStatus.NORMAL.name());
excelReport.setBeginTime(DateUtils.getDateText(normalRecord.getBeginTime()));
excelReport.setEndTime(DateUtils.getDateText(normalRecord.getEndTime()));

utils.export(excelReport);
}

@Override
public void write(ProjectRecord projectRecord)
{
utils = new ExcelUtils(
new File(projectRecord.getName() + "" + System.currentTimeMillis() + ".xls"));
utils.init();
}

@PreDestroy
public void saveFile()
{
utils.save();
}
}
125 changes: 125 additions & 0 deletions src/main/java/com/surenpi/autotest/report/model/ExcelReport.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/*
*
* * Copyright 2002-2007 the original author or authors.
* *
* * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
* *
* * http://www.apache.org/licenses/LICENSE-2.0
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the License for the specific language governing permissions and
* * limitations under the License.
*
*/

package com.surenpi.autotest.report.model;

/**
* @author suren
*/
public class ExcelReport
{
private String moduleName;
private String moduleDescription;
private String clazzName;
private String methodName;
private String status;
private String project;
private String beginTime;
private String endTime;
private String detail;

public String getModuleName()
{
return moduleName;
}

public void setModuleName(String moduleName)
{
this.moduleName = moduleName;
}

public String getModuleDescription()
{
return moduleDescription;
}

public void setModuleDescription(String moduleDescription)
{
this.moduleDescription = moduleDescription;
}

public String getClazzName()
{
return clazzName;
}

public void setClazzName(String clazzName)
{
this.clazzName = clazzName;
}

public String getMethodName()
{
return methodName;
}

public void setMethodName(String methodName)
{
this.methodName = methodName;
}

public String getStatus()
{
return status;
}

public void setStatus(String status)
{
this.status = status;
}

public String getProject()
{
return project;
}

public void setProject(String project)
{
this.project = project;
}

public String getBeginTime()
{
return beginTime;
}

public void setBeginTime(String beginTime)
{
this.beginTime = beginTime;
}

public String getEndTime()
{
return endTime;
}

public void setEndTime(String endTime)
{
this.endTime = endTime;
}

public String getDetail()
{
return detail;
}

public void setDetail(String detail)
{
this.detail = detail;
}
}

0 comments on commit ed1f8d4

Please sign in to comment.