diff --git a/pom.xml b/pom.xml index 938f0d3a5bd021b42d53b046f6d3a251c084297e..fe807cae82da9c275811aedb499601e58f8d94fd 100644 --- a/pom.xml +++ b/pom.xml @@ -235,6 +235,18 @@ 2.4 jdk15 + + + + + + + + + + + + diff --git a/src/main/java/yi/master/business/message/action/TestReportAction.java b/src/main/java/yi/master/business/message/action/TestReportAction.java index 49ba224bee79cdc2be591f62f15216ef291fcf62..774ae36f789313fe3d37fe6ab047dbee0ef580f0 100644 --- a/src/main/java/yi/master/business/message/action/TestReportAction.java +++ b/src/main/java/yi/master/business/message/action/TestReportAction.java @@ -1,26 +1,24 @@ package yi.master.business.message.action; -import java.io.File; -import java.util.List; - import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Controller; - import yi.master.business.base.action.BaseAction; import yi.master.business.message.bean.TestReport; import yi.master.business.message.bean.TestSet; import yi.master.business.message.service.TestReportService; import yi.master.business.message.service.TestSetService; -import yi.master.constant.ReturnCodeConsts; import yi.master.constant.SystemConsts; import yi.master.exception.AppErrorCode; import yi.master.exception.YiException; import yi.master.util.FrameworkUtil; import yi.master.util.PracticalUtils; -import yi.master.util.notify.NotifyMail; -import yi.master.util.notify.ReportEmailCreator; +import yi.master.util.notify.mail.NotifyMail; +import yi.master.util.notify.mail.ReportEmailCreator; + +import java.io.File; +import java.util.List; /** * 接口自动化
diff --git a/src/main/java/yi/master/business/message/bean/ComplexScene.java b/src/main/java/yi/master/business/message/bean/ComplexScene.java index 594b1ead690b625e4965948e6fb8a9ba572a69aa..eddd38725a8a53332aefeb08639361b6aa4f9ccb 100644 --- a/src/main/java/yi/master/business/message/bean/ComplexScene.java +++ b/src/main/java/yi/master/business/message/bean/ComplexScene.java @@ -1,29 +1,20 @@ package yi.master.business.message.bean; -import java.io.Serializable; -import java.sql.Timestamp; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; - import net.sf.json.JSONObject; - import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; import org.apache.struts2.json.annotations.JSON; - +import yi.master.annotation.FieldNameMapper; import yi.master.annotation.FieldRealSearch; import yi.master.business.message.service.ComplexSceneService; import yi.master.business.message.service.MessageSceneService; import yi.master.util.FrameworkUtil; import yi.master.util.PracticalUtils; +import java.io.Serializable; +import java.sql.Timestamp; +import java.util.*; + /** * 测试集中的组合场景 * @author xuwangcheng @@ -76,7 +67,8 @@ public class ComplexScene implements Serializable { * 对应测试集 */ private Set testSets = new HashSet(); - + + @FieldNameMapper(ifSearch = false, ifOrder = false) private Integer sceneNum; /** diff --git a/src/main/java/yi/master/business/testconfig/bean/GlobalVariable.java b/src/main/java/yi/master/business/testconfig/bean/GlobalVariable.java index c6730142ffa754b9ab0a5196c00b914024bec15b..78ccafb11dba820073229697d7544e035d322d2d 100644 --- a/src/main/java/yi/master/business/testconfig/bean/GlobalVariable.java +++ b/src/main/java/yi/master/business/testconfig/bean/GlobalVariable.java @@ -58,9 +58,9 @@ public class GlobalVariable implements Serializable { private String variableName; @FieldRealSearch(names = {"HTTP调用参数", "Socket调用参数", "WebService调用参数", "验证关联规则", "测试集运行时配置" - , "常量", "日期", "随机数", "时间戳", "随机字符串", "动态接口", "文件参数"}, + , "常量", "日期", "随机数", "时间戳", "随机字符串", "动态接口", "文件参数", "数据库取值"}, values = {"httpCallParameter", "socketCallParameter", "webServiceCallParameter", "relatedKeyWord", "setRuntimeSetting" - , "constant", "datetime", "randomNum", "currentTimestamp", "randomString", "dynamicInterface", "fileParameter"}) + , "constant", "datetime", "randomNum", "currentTimestamp", "randomString", "dynamicInterface", "fileParameter", "dbSql"}) private String variableType; /** * 如果这个变量可以被使用,则需要设置key值
@@ -383,6 +383,18 @@ public class GlobalVariable implements Serializable { return this.lastCreateValue; } + if (GlobalVariableType.dbSql.name().equalsIgnoreCase(this.variableType)) { + if (this.expiryDate.getTime() > System.currentTimeMillis() + && StringUtils.isNotBlank(this.lastCreateValue) + && !forceCreate) { + return this.lastCreateValue; + } + this.lastCreateValue = PracticalUtils.queryGlobalVariableValueByDBSql(maps); + update(); + + return this.lastCreateValue; + } + return this.value; } catch (Exception e) { LOGGER.error("获取变量" + this.variableName + "[" + this.key + "]失败:" + this.value, e); @@ -396,11 +408,7 @@ public class GlobalVariable implements Serializable { * @return */ public static boolean ifHasKey(String type) { - if (GlobalVariableType.httpCallParameter.name().equals(type) || - GlobalVariableType.socketCallParameter.name().equals(type) || - GlobalVariableType.webServiceCallParameter.name().equals(type) || - GlobalVariableType.setRuntimeSetting.name().equals(type) || - GlobalVariableType.relatedKeyWord.name().equals(type)) { + if (GlobalVariableType.setRuntimeSetting.name().equals(type)) { return false; } return true; diff --git a/src/main/java/yi/master/business/testconfig/enums/GlobalVariableType.java b/src/main/java/yi/master/business/testconfig/enums/GlobalVariableType.java index af87522fcc62eb343cef350fe60a7383d3c8fb87..90debed84de3ae78d4cbb2594d1e8148453c7ab7 100644 --- a/src/main/java/yi/master/business/testconfig/enums/GlobalVariableType.java +++ b/src/main/java/yi/master/business/testconfig/enums/GlobalVariableType.java @@ -56,5 +56,9 @@ public enum GlobalVariableType { /** * 文件 */ - fileParameter + fileParameter, + /** + * 数据库取值 + */ + dbSql } diff --git a/src/main/java/yi/master/constant/GlobalVariableConstant.java b/src/main/java/yi/master/constant/GlobalVariableConstant.java index 4f0896103509eab738afa6716d8be6642aed0ccb..0c4a0d8a0e1c750eceff757faa4ad6195ac398d2 100644 --- a/src/main/java/yi/master/constant/GlobalVariableConstant.java +++ b/src/main/java/yi/master/constant/GlobalVariableConstant.java @@ -10,46 +10,52 @@ package yi.master.constant; public interface GlobalVariableConstant { /**UUID*/ - public static final String UUID_SEPARATOR_ATTRIBUTE_NAME = "uuidSeparator"; + String UUID_SEPARATOR_ATTRIBUTE_NAME = "uuidSeparator"; /**随机数*/ - public static final String RANDOM_MIN_NUM_ATTRIBUTE_NAME = "randomMin"; - public static final String RANDOM_MAX_NUM_ATTRIBUTE_NAME = "randomNumMax"; + String RANDOM_MIN_NUM_ATTRIBUTE_NAME = "randomMin"; + String RANDOM_MAX_NUM_ATTRIBUTE_NAME = "randomNumMax"; /**格式化日期*/ - public static final String DATETIME_FORMAT_ATTRIBUTE_NAME = "datetimeFormat"; + String DATETIME_FORMAT_ATTRIBUTE_NAME = "datetimeFormat"; /**随机字符串*/ - public static final String RANDOM_STRING_MODE_ATTRIBUTE_NAME = "randomStringMode"; - public static final String RANDOM_STRING_NUM_ATTRIBUTE_NAME = "randomStringNum"; + String RANDOM_STRING_MODE_ATTRIBUTE_NAME = "randomStringMode"; + String RANDOM_STRING_NUM_ATTRIBUTE_NAME = "randomStringNum"; /**测试运行时配置*/ - public static final String SET_RUNTIME_SETTING_REQUEST_URL_FLAG = "requestUrlFlag"; - public static final String SET_RUNTIME_SETTING_CONNECT_TIMEOUT = "connectTimeOut"; - public static final String SET_RUNTIME_SETTING_READ_TIMEOUT = "readTimeOut"; - public static final String SET_RUNTIME_SETTING_RETRY_COUNT = "retryCount"; - public static final String SET_RUNTIME_SETTING_RUN_TYPE = "runType"; - public static final String SET_RUNTIME_SETTING_CHECK_DATA_FLAG = "checkDataFlag"; - public static final String SET_RUNTIME_SETTING_CUSTOMR_EQUEST_URL = "customRequestUrl"; + String SET_RUNTIME_SETTING_REQUEST_URL_FLAG = "requestUrlFlag"; + String SET_RUNTIME_SETTING_CONNECT_TIMEOUT = "connectTimeOut"; + String SET_RUNTIME_SETTING_READ_TIMEOUT = "readTimeOut"; + String SET_RUNTIME_SETTING_RETRY_COUNT = "retryCount"; + String SET_RUNTIME_SETTING_RUN_TYPE = "runType"; + String SET_RUNTIME_SETTING_CHECK_DATA_FLAG = "checkDataFlag"; + String SET_RUNTIME_SETTING_CUSTOMR_EQUEST_URL = "customRequestUrl"; /**验证模板*/ - public static final String RELATED_KEYWORD_VALIDATE_VALUE = "validateValue"; - public static final String RELATED_KEYWORD_VALUE_GET_METHOD = "getValueMethod"; + String RELATED_KEYWORD_VALIDATE_VALUE = "validateValue"; + String RELATED_KEYWORD_VALUE_GET_METHOD = "getValueMethod"; /**动态接口*/ - public static final String DYNAMIC_INTERFACE_SYSTEM_ID = "systemId"; - public static final String DYNAMIC_INTERFACE_SCENE_ID = "sceneId"; - public static final String DYNAMIC_INTERFACE_VALUE_EXPRESSION = "valueExpression"; + String DYNAMIC_INTERFACE_SYSTEM_ID = "systemId"; + String DYNAMIC_INTERFACE_SCENE_ID = "sceneId"; + String DYNAMIC_INTERFACE_VALUE_EXPRESSION = "valueExpression"; + + /**数据库取值*/ + String DB_SQL_DB_ID = "dbId"; + String DB_SQL_SQL_STR = "sql"; + String DB_SQL_ROW_SEQ = "rowSeq"; + String DB_SQL_COL_SEQ = "colSeq"; /** * 使用方式,左边界 */ - public static final String USE_VARIABLE_LEFT_BOUNDARY = "${__"; + String USE_VARIABLE_LEFT_BOUNDARY = "${__"; /** * 使用方式,右边界 */ - public static final String USE_VARIABLE_RIGHT_BOUNDARY = "}"; + String USE_VARIABLE_RIGHT_BOUNDARY = "}"; } diff --git a/src/main/java/yi/master/coretest/task/probe/ProbeTaskJobAction.java b/src/main/java/yi/master/coretest/task/probe/ProbeTaskJobAction.java index 5ecfca4d974886b91b1f7fc857de6aad4cba7210..c4fc420f45503262d1fad918d3c4b562309ad373 100644 --- a/src/main/java/yi/master/coretest/task/probe/ProbeTaskJobAction.java +++ b/src/main/java/yi/master/coretest/task/probe/ProbeTaskJobAction.java @@ -19,8 +19,8 @@ import yi.master.constant.ReturnCodeConsts; import yi.master.constant.SystemConsts; import yi.master.util.PracticalUtils; import yi.master.util.cache.CacheUtil; -import yi.master.util.notify.NotifyMail; -import yi.master.util.notify.ProbeEmailCreator; +import yi.master.util.notify.mail.NotifyMail; +import yi.master.util.notify.mail.ProbeEmailCreator; import java.sql.Timestamp; import java.util.Map; diff --git a/src/main/java/yi/master/coretest/task/time/TimeTaskJobListener.java b/src/main/java/yi/master/coretest/task/time/TimeTaskJobListener.java index 60a02dfae53609cba5871a5484d29c3a3d6a1bc9..8987f048364a6c9e016a01ac1998cd4c8f10cfa0 100644 --- a/src/main/java/yi/master/coretest/task/time/TimeTaskJobListener.java +++ b/src/main/java/yi/master/coretest/task/time/TimeTaskJobListener.java @@ -23,8 +23,8 @@ import yi.master.constant.ReturnCodeConsts; import yi.master.constant.SystemConsts; import yi.master.util.PracticalUtils; import yi.master.util.cache.CacheUtil; -import yi.master.util.notify.NotifyMail; -import yi.master.util.notify.ReportEmailCreator; +import yi.master.util.notify.mail.NotifyMail; +import yi.master.util.notify.mail.ReportEmailCreator; import java.sql.Timestamp; import java.util.HashSet; diff --git a/src/main/java/yi/master/util/CustomResultSetOperator.java b/src/main/java/yi/master/util/CustomResultSetOperator.java new file mode 100644 index 0000000000000000000000000000000000000000..10cb97d58cf0bd6d67d91f9960b5432c4e9c34bf --- /dev/null +++ b/src/main/java/yi/master/util/CustomResultSetOperator.java @@ -0,0 +1,21 @@ +package yi.master.util; + +import java.sql.ResultSet; + +/** + * 自定义的结果集处理 + * @author xuwangcheng14@163.com + * @version 1.0.0 + * @description + * @date 2020/1/2 22:04 + */ +public interface CustomResultSetOperator { + /** + * 处理执行SQL返回的结果集 + * @author xuwangcheng + * @date 2020/1/2 22:06 + * @param rs rs + * @return {@link String} + */ + String handle(ResultSet rs) throws Exception; +} diff --git a/src/main/java/yi/master/util/DBUtil.java b/src/main/java/yi/master/util/DBUtil.java index c7009ec8b70eafef7b3906ef80873e5fd5e55189..768ed785cd92e68ff6833a2f8b852df6ea682dc1 100644 --- a/src/main/java/yi/master/util/DBUtil.java +++ b/src/main/java/yi/master/util/DBUtil.java @@ -86,34 +86,37 @@ public class DBUtil { } } } - + /** - * 传入数据库连接和要执行的sql语句 - * 得到返回值,多个值只取第一个,没有值返回null - * @param dbInfo DataDB对象 - * @param sqlStr 需要执行的sql语句 - * @return - * @throws SQLException + * 传入数据库连接信息和执行SQL。获取执行结果 + * @author xuwangcheng + * @date 2020/1/2 22:10 + * @param dbInfo dbInfo 数据库连接信息 + * @param sqlStr sqlStr 执行SQL + * @param operator operator 自定义操作,如果不传则只获取第一条数据 + * @return {@link String} */ - public static String getDBData(DataDB dbInfo, String sqlStr) { - String returnStr = null; - PreparedStatement ps = null; - ResultSet rs = null; - Connection conn = null; - try { - conn = getConnection(dbInfo.getDbType(), dbInfo.getDbUrl(), dbInfo.getDbName(), dbInfo.getDbUsername(), dbInfo.getDbPasswd()); - ps = conn.prepareStatement(sqlStr); - rs = ps.executeQuery(); - while (rs.next()) { - //只取第一条记录 - returnStr = rs.getString(1); - break; - } - - } catch (SQLException | ClassNotFoundException e) { + public static String getDBData (DataDB dbInfo, String sqlStr,CustomResultSetOperator operator) throws Exception { + String returnStr = null; + PreparedStatement ps = null; + ResultSet rs = null; + Connection conn = null; + try { + conn = getConnection(dbInfo.getDbType(), dbInfo.getDbUrl(), dbInfo.getDbName(), dbInfo.getDbUsername(), dbInfo.getDbPasswd()); + ps = conn.prepareStatement(sqlStr); + rs = ps.executeQuery(); + if (operator != null) { + returnStr = operator.handle(rs); + } else { + while (rs.next()) { + //只取第一条记录 + returnStr = rs.getString(1); + break; + } + } + } catch (Exception e) { LOGGER.error("查询语句执行失败[" + sqlStr + "]", e); - e.printStackTrace(); - + throw e; } finally { if (ps != null) { try { @@ -129,14 +132,30 @@ public class DBUtil { e.printStackTrace(); } } - + try { close(conn); } catch (SQLException e) { e.printStackTrace(); } } - - return returnStr; + + return returnStr; + } + + /** + * 传入数据库连接和要执行的sql语句 + * 得到返回值,多个值只取第一个,没有值返回null + * @param dbInfo DataDB对象 + * @param sqlStr 需要执行的sql语句 + * @return + * @throws SQLException + */ + public static String getDBData(DataDB dbInfo, String sqlStr) { + try { + return getDBData(dbInfo, sqlStr, null); + } catch (Exception e) { + return null; + } } } diff --git a/src/main/java/yi/master/util/PracticalUtils.java b/src/main/java/yi/master/util/PracticalUtils.java index b5a9279bab158c2efab4982cd805571efc738e11..e4f7fbd9779efb92a9148573ba1020af15a0de71 100644 --- a/src/main/java/yi/master/util/PracticalUtils.java +++ b/src/main/java/yi/master/util/PracticalUtils.java @@ -1,6 +1,8 @@ package yi.master.util; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.NumberUtil; +import cn.hutool.core.util.StrUtil; import net.sf.json.JSONObject; import net.sf.json.JsonConfig; import org.apache.commons.lang3.StringUtils; @@ -16,9 +18,11 @@ import yi.master.business.message.bean.*; import yi.master.business.message.service.TestResultService; import yi.master.business.message.service.TestSetService; import yi.master.business.testconfig.bean.BusinessSystem; +import yi.master.business.testconfig.bean.DataDB; import yi.master.business.testconfig.bean.GlobalVariable; import yi.master.business.testconfig.service.BusinessSystemService; import yi.master.business.testconfig.service.GlobalVariableService; +import yi.master.constant.GlobalVariableConstant; import yi.master.constant.SystemConsts; import yi.master.coretest.message.parse.MessageParse; import yi.master.coretest.message.protocol.HTTPTestClient; @@ -31,6 +35,8 @@ import javax.servlet.http.HttpServletRequest; import java.io.*; import java.nio.file.Paths; import java.security.NoSuchAlgorithmException; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.*; @@ -705,6 +711,74 @@ public class PracticalUtils { } } + /** + * 获取数据库取值的变量值 + * @author xuwangcheng + * @date 2020/1/2 22:18 + * @param parameters parameters + * @return {@link String} + */ + public static String queryGlobalVariableValueByDBSql (Map parameters) throws Exception { + String dbId = parameters.get(GlobalVariableConstant.DB_SQL_DB_ID); + String sql = parameters.get(GlobalVariableConstant.DB_SQL_SQL_STR); + final String rowSeq = parameters.get(GlobalVariableConstant.DB_SQL_ROW_SEQ); + final String colSeq = parameters.get(GlobalVariableConstant.DB_SQL_COL_SEQ); + + DataDB db = CacheUtil.getQueryDBById(dbId); + if (db == null) { + throw new Exception(StrUtil.format("dbId={},没有找到此数据源信息", dbId)); + } + + if (StringUtils.isBlank(sql)) { + throw new Exception("执行SQL不能为空"); + } + + String querySql = PracticalUtils.replaceGlobalVariable(sql, null); + String result = DBUtil.getDBData(db, querySql, new CustomResultSetOperator() { + @Override + public String handle(ResultSet rs) throws Exception { + int rowCount = 1; + int colCount = 1; + if (StringUtils.isNotBlank(rowSeq) && NumberUtil.isInteger(rowSeq)) { + rowCount = Integer.valueOf(rowSeq); + } + if (StringUtils.isNotBlank(colSeq) && NumberUtil.isInteger(colSeq)) { + colCount = Integer.valueOf(colSeq); + } + + ResultSetMetaData rsmd = rs.getMetaData(); + if (rsmd.getColumnCount() < colCount) { + colCount = rsmd.getColumnCount(); + } + + rs.last(); + if (rs.getRow() < rowCount) { + rowCount = rs.getRow(); + } + rs.beforeFirst(); + + int i = 1; + String r = null; + + while (rs.next()) { + if (i == rowCount) { + r = rs.getString(colCount); + break; + } + i++; + } + + if (r == null) { + throw new Exception(StrUtil.format("dbId={},SQL={},没有查询到指定的数据", dbId, querySql)); + } + + return r; + } + }); + + return result; + } + /** * 检查最新版本 * @return diff --git a/src/main/java/yi/master/util/cache/CacheUtil.java b/src/main/java/yi/master/util/cache/CacheUtil.java index d857e0064015fbdb5b57f49ca82b42b7489dd7a8..7ed94d20ab4d52e21547a500251d3a2ed4858631 100644 --- a/src/main/java/yi/master/util/cache/CacheUtil.java +++ b/src/main/java/yi/master/util/cache/CacheUtil.java @@ -7,6 +7,7 @@ import yi.master.business.system.bean.GlobalSetting; import yi.master.business.system.bean.OperationInterface; import yi.master.business.system.service.OperationInterfaceService; import yi.master.business.testconfig.bean.DataDB; +import yi.master.constant.SystemConsts; import yi.master.coretest.message.test.mock.MockServer; import yi.master.coretest.message.test.performance.PerformanceTestObject; import yi.master.util.FrameworkUtil; @@ -299,7 +300,17 @@ public class CacheUtil { homeUrl = request.getRequestURL().toString().replace(request.getServletPath(), ""); } + /** + * 获取请求地址 + * @author xuwangcheng + * @date 2020/1/2 14:43 + * @param + * @return {@link String} + */ public static String getHomeUrl() { + if (StringUtils.isBlank(homeUrl)) { + return getSettingValue(SystemConsts.GLOBAL_SETTING_HOME); + } return homeUrl; } } diff --git a/src/main/java/yi/master/util/notify/EmailCreator.java b/src/main/java/yi/master/util/notify/mail/EmailCreator.java similarity index 88% rename from src/main/java/yi/master/util/notify/EmailCreator.java rename to src/main/java/yi/master/util/notify/mail/EmailCreator.java index f1611ed878e3568a0b3789ac9bc867f8f0f7886f..b4e559bfa2c14135eadfb7d9207b173eb4f9cb72 100644 --- a/src/main/java/yi/master/util/notify/EmailCreator.java +++ b/src/main/java/yi/master/util/notify/mail/EmailCreator.java @@ -1,4 +1,4 @@ -package yi.master.util.notify; +package yi.master.util.notify.mail; import javax.mail.Address; import javax.mail.Session; diff --git a/src/main/java/yi/master/util/notify/NotifyMail.java b/src/main/java/yi/master/util/notify/mail/NotifyMail.java similarity index 99% rename from src/main/java/yi/master/util/notify/NotifyMail.java rename to src/main/java/yi/master/util/notify/mail/NotifyMail.java index 6e2cfd783afb7a77de3a9d1820feb0d4c2f8062c..aafeb17ad85ffd2d326209019559e2c71e7ce067 100644 --- a/src/main/java/yi/master/util/notify/NotifyMail.java +++ b/src/main/java/yi/master/util/notify/mail/NotifyMail.java @@ -1,4 +1,4 @@ -package yi.master.util.notify; +package yi.master.util.notify.mail; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/yi/master/util/notify/ProbeEmailCreator.java b/src/main/java/yi/master/util/notify/mail/ProbeEmailCreator.java similarity index 98% rename from src/main/java/yi/master/util/notify/ProbeEmailCreator.java rename to src/main/java/yi/master/util/notify/mail/ProbeEmailCreator.java index 2de9572f62de74eb97adab2b911abae8a585d9bc..04424db449c0628a3af1c75bbb82560f57279da1 100644 --- a/src/main/java/yi/master/util/notify/ProbeEmailCreator.java +++ b/src/main/java/yi/master/util/notify/mail/ProbeEmailCreator.java @@ -1,4 +1,4 @@ -package yi.master.util.notify; +package yi.master.util.notify.mail; import java.util.Date; diff --git a/src/main/java/yi/master/util/notify/ReportEmailCreator.java b/src/main/java/yi/master/util/notify/mail/ReportEmailCreator.java similarity index 94% rename from src/main/java/yi/master/util/notify/ReportEmailCreator.java rename to src/main/java/yi/master/util/notify/mail/ReportEmailCreator.java index 07837d5eabcd01ad5bed7743c07d43947acfe3e4..17cd6974768df23a40204c63fa1b7bb87928d8f9 100644 --- a/src/main/java/yi/master/util/notify/ReportEmailCreator.java +++ b/src/main/java/yi/master/util/notify/mail/ReportEmailCreator.java @@ -1,27 +1,20 @@ -package yi.master.util.notify; - -import java.util.Date; - -import javax.activation.DataHandler; -import javax.activation.FileDataSource; -import javax.mail.Address; -import javax.mail.Session; -import javax.mail.internet.InternetAddress; -import javax.mail.internet.MimeBodyPart; -import javax.mail.internet.MimeMessage; -import javax.mail.internet.MimeMessage.RecipientType; -import javax.mail.internet.MimeMultipart; -import javax.mail.internet.MimeUtility; +package yi.master.util.notify.mail; +import net.sf.json.JSONObject; import org.apache.commons.lang3.StringUtils; - import yi.master.business.message.bean.TestReport; import yi.master.constant.SystemConsts; import yi.master.util.FrameworkUtil; import yi.master.util.PracticalUtils; import yi.master.util.cache.CacheUtil; -import net.sf.json.JSONObject; +import javax.activation.DataHandler; +import javax.activation.FileDataSource; +import javax.mail.Address; +import javax.mail.Session; +import javax.mail.internet.*; +import javax.mail.internet.MimeMessage.RecipientType; +import java.util.Date; /** * 定时任务推送邮件 diff --git a/src/main/java/yi/master/util/notify/sms/SmsType.java b/src/main/java/yi/master/util/notify/sms/SmsType.java new file mode 100644 index 0000000000000000000000000000000000000000..4f77169121542059131c11daefff2d563ec2df33 --- /dev/null +++ b/src/main/java/yi/master/util/notify/sms/SmsType.java @@ -0,0 +1,34 @@ +package yi.master.util.notify.sms; + +/** + * 通知短信类型 + * @author xuwangcheng14@163.com + * @version 1.0.0 + * @description + * @date 2020/1/3 22:52 + */ +public enum SmsType { + /** + * 1 - 验证码短信 + */ + AUTH_CODE(1), + /** + * 2 - 定时任务通知 + */ + TIME_TASK(2), + /** + * 3 - 接口探测通知 + */ + PROB_TASK(3); + + private Integer type; + + SmsType (Integer type) { + this.type = type; + } + + public Integer getType() { + return type; + } + +} diff --git a/src/main/resources/update/1.0.0 b/src/main/resources/update/1.0.0 index 921329d89bc4d84b362f0f98db44aec6909d8b44..818bd8d0f75d3bc04eb8800aaf1a70e457c55eb5 100644 --- a/src/main/resources/update/1.0.0 +++ b/src/main/resources/update/1.0.0 @@ -1,4 +1,4 @@ UPDATE `at_busi_menu_info` SET `menu_name` = '批量比对', `menu_url` = 'nopower.html?v=2', `icon_name` = '', `parent_id` = 9, `node_level` = 2, `seq` = 30, `status` = '0', `create_time` = '2018-12-28 09:30:38', `create_user` = 1, `mark` = '' WHERE `menu_id` = 12; UPDATE `at_busi_menu_info` SET `menu_name` = '服务调用地图', `menu_url` = 'resource/reporting/callMap.html', `icon_name` = '', `parent_id` = 22, `node_level` = 2, `seq` = 10, `status` = '0', `create_time` = '2018-12-28 09:39:00', `create_user` = 1, `mark` = '' WHERE `menu_id` = 23; UPDATE `at_busi_menu_info` SET `menu_name` = '测试报表', `menu_url` = 'resource/reporting/reportForm.html', `icon_name` = '', `parent_id` = 22, `node_level` = 2, `seq` = 20, `status` = '1', `create_time` = '2018-12-28 09:39:00', `create_user` = 1, `mark` = '' WHERE `menu_id` = 24; -INSERT INTO `at_parameter`(`parameter_id`, `parameter_identify`, `parameter_name`, `default_value`, `path`, `type`, `attributes`, `mark`, `interface_id`) VALUES (4, '', '', '', '', 'Outer_Array', NULL, NULL, NULL); +INSERT INTO `at_parameter`(`parameter_id`, `parameter_identify`, `parameter_name`, `default_value`, `path`, `type`, `attributes`, `mark`, `interface_id`) VALUES (4, '', '', '', '', 'Outer_Array', NULL, NULL, NULL); \ No newline at end of file diff --git a/src/main/resources/update/1.0.2 b/src/main/resources/update/1.0.2 new file mode 100644 index 0000000000000000000000000000000000000000..de0a2dcaa2400aacc3fbd1582f893b8b81a86947 --- /dev/null +++ b/src/main/resources/update/1.0.2 @@ -0,0 +1 @@ +update at_test_config set mail_copy_address='',mail_receive_address='' where config_id=1; \ No newline at end of file diff --git a/src/main/webapp/js/dcits.js b/src/main/webapp/js/dcits.js index 81789c9ea2509ea31bacf0623ef7db827cbd293a..c4652ed95c30a38f88642b4a26cb9323adc99a50 100644 --- a/src/main/webapp/js/dcits.js +++ b/src/main/webapp/js/dcits.js @@ -2085,6 +2085,48 @@ function isJSON(str) { return false; } +/** + * 获取数据源ID + * @param callback 回调方法,两个参数,分别为dbId,dbName + */ +function queryDb(callback) { + $.ajax({ + type:"POST", + url:REQUEST_URL.QUERY_DB.LIST_ALL, + success:function(data) { + if(data.returnCode == 0){ + if(data.data.length < 1){ + layer.alert('没有可用的数据库连接信息,请在系统设置模块添加可用的数据库信息', {icon:5}); + return false; + } + + var selectHtml = '
'; + let index_selectDb = layer.open({ + type: 1, + title: "选择数据库", + offset: '30px', + area: ['355px', '110px'], + content:selectHtml, + success:function(layero, index) { + $(layero).find('#select-db-btn').click(function(){ + if (typeof callback === 'function') { + callback($("#selectDb").val(), $("#selectDb option:selected").text()); + } + layer.close(index_selectDb); + }); + } + }); + }else{ + layer.alert(data.msg,{icon:5}); + } + } + }); +} + /*********************判断两个json对象是否一样*****************************/ function isObj(object) { return object && typeof(object) == 'object' && Object.prototype.toString.call(object).toLowerCase() == "[object object]"; diff --git a/src/main/webapp/resource/advanced/chooseMessageScene.js b/src/main/webapp/resource/advanced/chooseMessageScene.js index 7bbc86a00ab25ab114af954643d6f579c497dda2..b988e7e47a2ae06a11ae2667fb0d6b4fee856edc 100644 --- a/src/main/webapp/resource/advanced/chooseMessageScene.js +++ b/src/main/webapp/resource/advanced/chooseMessageScene.js @@ -269,7 +269,7 @@ function sceneTest() { var index = layer.msg('正在进行测试...', {icon:16, time:9999999, shade:0.35}); - $.post(REQUEST_URL.AUTO_TEST.TEST_SCENE_URL, {messageSceneId:messageSceneId, dataId:dataId, requestUrl:requestUrl, requestMessage:requestMessage},function(data) { + $.post(REQUEST_URL.AUTO_TEST.TEST_SCENE_URL, {systemId:$('#select-system').val(), messageSceneId:messageSceneId, dataId:dataId, requestUrl:requestUrl, requestMessage:requestMessage},function(data) { if (data.returnCode == 0) { layer.close(index); renderResultViewPage(data.data, messageSceneId); diff --git a/src/main/webapp/resource/message/autoTask.js b/src/main/webapp/resource/message/autoTask.js index 38e27aae20031e42785894a60794da602d6a73be..0919d0f1a5249ce7c4e3133f382e40c358fe076d 100644 --- a/src/main/webapp/resource/message/autoTask.js +++ b/src/main/webapp/resource/message/autoTask.js @@ -94,6 +94,20 @@ var templateParams = { }] }] }, + { + required:true, + label:"短信通知", + select:[{ + name:"smsNotify", + option:[{ + value:"0", + text:"否" + },{ + value:"1", + text:"是" + }] + }] + }, { name:"status", value:"1" diff --git a/src/main/webapp/resource/message/interfaceParameter.js b/src/main/webapp/resource/message/interfaceParameter.js index 3dfbf17592332c5c91cbb48be41737ed4ccb8ee1..8d71d0b1612891a7502d3fccfbd8a59c24b9d97c 100644 --- a/src/main/webapp/resource/message/interfaceParameter.js +++ b/src/main/webapp/resource/message/interfaceParameter.js @@ -291,7 +291,7 @@ var mySetting = { rules:{ parameterIdentify:{ required:true, - minlength:2, + minlength:1, maxlength:1000, } } diff --git a/src/main/webapp/resource/message/validateParameters.js b/src/main/webapp/resource/message/validateParameters.js index 5d8c3c7a4275a1674462cc1cf28586d1dde4d2f7..a5a8fd42fe22df195beb5aa14ddcf663cdcd7439 100644 --- a/src/main/webapp/resource/message/validateParameters.js +++ b/src/main/webapp/resource/message/validateParameters.js @@ -12,7 +12,7 @@ var selectGetValueMethodTip = { "4":["正则表达式", "使用JAVA正则表达式模板来进行验证", "正则表达式"], "5":["时间,单位毫秒", "不需要输入值", "响应时间"], "6":["状态码", "不需要输入值", "状态码"], - "7":["指定响应头的名称", "请输入响应头名称,例如:Content-Type, Set-Cookies等,不区分大小写", "响应头"] + "7":["比对内容", "请输入响应头名称,例如:Content-Type, Set-Cookies等,不区分大小写", "响应头"] }; @@ -32,8 +32,6 @@ var customValidateCondition = { * 1-节点参数验证
* 2-自定义验证
*/ - -var index_selectDb; var addValidateMethodFlag = 1; //添加的验证规则模式 var templateParams = { @@ -391,7 +389,9 @@ var eventList = { if (addValidateMethodFlag == 1) { layer.confirm('请选择预期比对数据类型',{btnAlign: 'l', offset: '30px',title:'提示',btn:['常量','入参节点','SQL语句', '全局变量', '正则表达式'], btn3:function(index) { - queryDb(); + queryDb(function(dbId, dbName) { + changeTigs(dbId, dbName); + }); }, btn4:function(index){//全局变量 changeTigs("3"); @@ -422,7 +422,9 @@ var eventList = { layer.close(index); }} ,function(index){//数据库变动 - queryDb(); + queryDb(function(dbId, dbName) { + changeTigs(dbId, dbName); + }); layer.close(index); } ,function(index){//响应时间 @@ -555,19 +557,12 @@ function updateStatus(validateId, flag, obj) { }); } -/** - * 选择查询数据库 - */ -function selectDB() { - changeTigs($("#selectDb").val()); - layer.close(index_selectDb); - -} /** * 节点验证编辑时,根据取值方式的选择不同,改变页面提示 * @param type 0 - 字符串 1 - 入参节点 其他为数据库的id + * @param dbName 数据库名称,选择数据库时才有 */ -function changeTigs(type) { +function changeTigs(type, dbName) { $("#select-get-value-method").siblings('strong').remove(); $("#getValueMethod").val(type); @@ -577,7 +572,7 @@ function changeTigs(type) { } else { type = "2-1"; } - selectGetValueMethodTip[type][2] = "数据库 " + $("#selectDb option:selected").text(); + selectGetValueMethodTip[type][2] = "数据库 " + dbName; } if (type == "1") { @@ -685,34 +680,3 @@ function saveValidateJson(){ } -function queryDb() { - $.ajax({ - type:"POST", - url:REQUEST_URL.QUERY_DB.LIST_ALL, - success:function(data) { - if(data.returnCode == 0){ - if(data.data.length < 1){ - layer.alert('没有可用的数据库连接信息,请在系统设置模块添加可用的数据库信息', {icon:5}); - return false; - } - - var selectHtml = '
'; - index_selectDb = layer.open({ - type: 1, - title: "选择数据库", - offset: '30px', - area: ['355px', '110px'], - content:selectHtml - }); - }else{ - layer.alert(data.msg,{icon:5}); - } - } - }); - -} - diff --git a/src/main/webapp/resource/setting/variable.js b/src/main/webapp/resource/setting/variable.js index 6140742d23caebc169c976f1babb7317b7b15d9d..a61fefc8080c9ed1564fd5e2e9280bcd8eff31d3 100644 --- a/src/main/webapp/resource/setting/variable.js +++ b/src/main/webapp/resource/setting/variable.js @@ -151,6 +151,20 @@ var variableTypeInfo = { layerHeight:"", keyIsNull:false, ifCreate:true + }, + dbSql: { + text:"数据库取值", + settingValue:{ + dbId: "", + sql: "", + rowSeq: "", //行号,如果查询出来有多行数据的话,默认为1 + colSeq: "" //列号,如果查询出来有多个列内容,默认为1 + + }, + layerHeight:"500", + layerWidth: "", + keyIsNull:false, + ifCreate:true } }; @@ -219,7 +233,8 @@ var templateParams = { {value:"randomString", text:variableTypeInfo.randomString.text}, {value:"uuid", text:variableTypeInfo.uuid.text}, {value:"dynamicInterface", text:variableTypeInfo.dynamicInterface.text}, - {value:"fileParameter", text:variableTypeInfo.fileParameter.text}] + {value:"fileParameter", text:variableTypeInfo.fileParameter.text}, + {value:"dbSql", text:variableTypeInfo.dbSql.text}] }] }, { @@ -370,6 +385,10 @@ var columnsSetting = [ fileParameter:{ status:"文件参数", btnStyle:"success" + }, + dbSql:{ + status:"数据库取值", + btnStyle:"danger" } }; return labelCreate(data, context); @@ -680,6 +699,7 @@ function changeFormByVariableType (variableType) { case "dynamicInterface": showOrHideInput('hidden', 'button', 'hidden', ''); break; + case "dbSql": case "datetime": case "randomNum": case "randomString": @@ -733,6 +753,13 @@ function showSettingPage(title) { settingLayerIndex = index; //该页面相关方法定义 + //选择查询数据库 + $(layero).find('#choose-db').click(function(){ + queryDb(function(dbId, dbName){ + $('#dbId').val(dbId); + }); + }); + //选择测试环境 $(layero).find('#choose-system').click(function(){ if (!strIsNotEmpty($(".dynamicInterface #protocolType").val())) { diff --git a/src/main/webapp/resource/system/globalSetting.html b/src/main/webapp/resource/system/globalSetting.html index 5963f6890c0692d5209b9bce95c4cd669c8ce015..2b5e2818b431077589a236734f08f3aee8e3eb96 100644 --- a/src/main/webapp/resource/system/globalSetting.html +++ b/src/main/webapp/resource/system/globalSetting.html @@ -29,7 +29,7 @@
-
网站设置邮件设置接口自动化设置WEB自动化设置
+
网站设置邮件设置阿里云短信接口配置接口自动化设置WEB自动化设置
@@ -175,6 +175,59 @@
+ + +
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
diff --git a/src/main/webapp/resource/template/customTemplate.htm b/src/main/webapp/resource/template/customTemplate.htm index 263af97d4522d01b4c78b2c7dae30f84ca585312..5a1d62c8920a7cd5975d39fcf40937642b24f5ed 100644 --- a/src/main/webapp/resource/template/customTemplate.htm +++ b/src/main/webapp/resource/template/customTemplate.htm @@ -231,7 +231,9 @@
@@ -606,6 +608,12 @@
+
+ +
+ +
+
@@ -985,13 +993,38 @@
-
+
+ +
+   + +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
diff --git a/update.md b/update.md index 3a5595d279e72c61afa07b60a77b648c25a3e51e..fe0dbf4df036ead3ed55f4e8d5a4aeb752afc8b9 100644 --- a/update.md +++ b/update.md @@ -1,3 +1,10 @@ +### v1.0.2 +#### 2020.1.2 +- 新增:全局变量 -> 数据库取值,可通过SQL语句从数据库获取指定变量; +- 修复:组合场景搜索出错问题; +- 修复:性能测试、接口探测等中新增编辑时在选择测试场景的窗口中调试报错的问题; + + ### v1.0.1 #### 2019.12.25 - 新增:验证规则增加自定义验证;