diff --git a/.gitignore b/.gitignore index de879199..f3aa43e1 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ /imageFiles/ /keepFiles/ /recordFiles/ +/packageFiles/ diff --git a/README.md b/README.md index 10585d6a..4bc54a9e 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@

- + diff --git a/README_CN.md b/README_CN.md index 17e5d623..f9bf2563 100644 --- a/README_CN.md +++ b/README_CN.md @@ -10,7 +10,7 @@

- + diff --git a/config/sonic-server-controller-dev.yml b/config/sonic-server-controller-dev.yml index 814b1d52..d8c5e677 100644 --- a/config/sonic-server-controller-dev.yml +++ b/config/sonic-server-controller-dev.yml @@ -11,6 +11,6 @@ robot: client: host: "http://localhost:3000" img: - success: "" - warning: "" - error: "" \ No newline at end of file + success: "https://gitee.com/ZhouYixun/sonic-official-website/raw/master/src/assets/suc.png" + warning: "https://gitee.com/ZhouYixun/sonic-official-website/raw/master/src/assets/warn.png" + error: "https://gitee.com/ZhouYixun/sonic-official-website/raw/master/src/assets/fail.png" \ No newline at end of file diff --git a/config/sonic-server-gateway-dev.yml b/config/sonic-server-gateway-dev.yml index f06df4ae..261e9a9c 100644 --- a/config/sonic-server-gateway-dev.yml +++ b/config/sonic-server-gateway-dev.yml @@ -2,7 +2,7 @@ server: port: 8094 filter: - white-list: /users/login,/users/register,/swagger-resources,/v2/api-docs,/folder/upload,/folder/recordFiles,/keepFiles/,/imageFiles/,/recordFiles/,/logFiles/ + white-list: /users/login,/users/register,/swagger-resources,/v2/api-docs,/folder/upload,/folder/recordFiles,/keepFiles/,/imageFiles/,/recordFiles/,/logFiles/,/packageFiles/ resetToken: true spring: @@ -27,5 +27,10 @@ spring: - id: transport uri: lb://sonic-server-transport predicates: Path=/api/transport/** + filters: + - StripPrefix=2 + - id: bus + uri: lb://sonic-server-bus + predicates: Path=/api/bus/** filters: - StripPrefix=2 \ No newline at end of file diff --git a/sonic-server-bus/pom.xml b/sonic-server-bus/pom.xml index 49d730f7..fcca32e0 100644 --- a/sonic-server-bus/pom.xml +++ b/sonic-server-bus/pom.xml @@ -10,7 +10,7 @@ 4.0.0 sonic-server-bus - 1.0.1 + 1.1.0 jar diff --git a/sonic-server-common/pom.xml b/sonic-server-common/pom.xml index c69633ad..424e4223 100644 --- a/sonic-server-common/pom.xml +++ b/sonic-server-common/pom.xml @@ -10,7 +10,7 @@ 4.0.0 sonic-server-common - 1.0.0 + 1.1.0 diff --git a/sonic-server-controller/pom.xml b/sonic-server-controller/pom.xml index f743d2b3..8ff99676 100644 --- a/sonic-server-controller/pom.xml +++ b/sonic-server-controller/pom.xml @@ -10,7 +10,7 @@ 4.0.0 sonic-server-controller - 1.0.1 + 1.1.0 jar @@ -60,7 +60,7 @@ com.sonic sonic-server-common - 1.0.0 + 1.1.0 org.springframework.boot diff --git a/sonic-server-controller/src/main/java/com/sonic/controller/models/Elements.java b/sonic-server-controller/src/main/java/com/sonic/controller/models/Elements.java index fa95fbaa..58f15760 100644 --- a/sonic-server-controller/src/main/java/com/sonic/controller/models/Elements.java +++ b/sonic-server-controller/src/main/java/com/sonic/controller/models/Elements.java @@ -31,7 +31,7 @@ public class Elements { @ApiModelProperty(value = "项目id", required = true, example = "1") int projectId; //因为一个控件可以存在于多个步骤,也可以一个步骤有多个同样的控件,所以是多对多关系 - @ManyToMany(mappedBy = "elements") + @ManyToMany(mappedBy = "elements", fetch = FetchType.EAGER) @JsonIgnore @JSONField(serialize = false) List steps; diff --git a/sonic-server-controller/src/main/java/com/sonic/controller/models/Projects.java b/sonic-server-controller/src/main/java/com/sonic/controller/models/Projects.java index 2b01cbe3..4e009ce5 100644 --- a/sonic-server-controller/src/main/java/com/sonic/controller/models/Projects.java +++ b/sonic-server-controller/src/main/java/com/sonic/controller/models/Projects.java @@ -24,11 +24,13 @@ public class Projects { @NotNull @ApiModelProperty(value = "项目描述", required = true, example = "Sonic项目描述") String projectDes; + @ApiModelProperty(value = "机器人类型", required = true, example = "1") + int robotType; @NotNull - @ApiModelProperty(value = "钉钉机器人token", required = true, example = "http://dingTalk.com?token=*****") + @ApiModelProperty(value = "机器人token", required = true, example = "http://dingTalk.com?token=*****") String robotToken; @NotNull - @ApiModelProperty(value = "钉钉机器人加签密钥", required = true, example = "qwe***") + @ApiModelProperty(value = "机器人加签密钥", required = true, example = "qwe***") String robotSecret; @NotNull @ApiModelProperty(value = "项目图标", required = true, example = "http://img.jpg") @@ -65,6 +67,14 @@ public void setProjectDes(String projectDes) { this.projectDes = projectDes; } + public int getRobotType() { + return robotType; + } + + public void setRobotType(int robotType) { + this.robotType = robotType; + } + public String getRobotToken() { return robotToken; } @@ -103,6 +113,7 @@ public String toString() { "id=" + id + ", projectName='" + projectName + '\'' + ", projectDes='" + projectDes + '\'' + + ", robotType=" + robotType + ", robotToken='" + robotToken + '\'' + ", robotSecret='" + robotSecret + '\'' + ", projectImg='" + projectImg + '\'' + diff --git a/sonic-server-controller/src/main/java/com/sonic/controller/models/Steps.java b/sonic-server-controller/src/main/java/com/sonic/controller/models/Steps.java index 8d252ecc..11caafa2 100644 --- a/sonic-server-controller/src/main/java/com/sonic/controller/models/Steps.java +++ b/sonic-server-controller/src/main/java/com/sonic/controller/models/Steps.java @@ -10,6 +10,7 @@ import javax.validation.constraints.NotNull; import javax.validation.constraints.Positive; import java.util.List; +import java.util.Set; @Entity @ApiModel("运行步骤模型") @@ -49,10 +50,10 @@ public class Steps { @ApiModelProperty(value = "包含元素列表") @ManyToMany(fetch = FetchType.EAGER) List elements; - @ManyToMany(mappedBy = "steps") + @ManyToMany(mappedBy = "steps",fetch = FetchType.EAGER) @JsonIgnore @JSONField(serialize = false) - List publicSteps; + Set publicSteps; public Steps() { } @@ -137,11 +138,11 @@ public void setElements(List elements) { this.elements = elements; } - public List getPublicSteps() { + public Set getPublicSteps() { return publicSteps; } - public void setPublicSteps(List publicSteps) { + public void setPublicSteps(Set publicSteps) { this.publicSteps = publicSteps; } diff --git a/sonic-server-controller/src/main/java/com/sonic/controller/models/interfaces/RobotType.java b/sonic-server-controller/src/main/java/com/sonic/controller/models/interfaces/RobotType.java new file mode 100644 index 00000000..af65e8d6 --- /dev/null +++ b/sonic-server-controller/src/main/java/com/sonic/controller/models/interfaces/RobotType.java @@ -0,0 +1,8 @@ +package com.sonic.controller.models.interfaces; + +public interface RobotType { + int DingTalk = 1; + int WeChat = 2; + int FeiShu = 3; + int YouSpace = 4; +} diff --git a/sonic-server-controller/src/main/java/com/sonic/controller/services/impl/ResultsServiceImpl.java b/sonic-server-controller/src/main/java/com/sonic/controller/services/impl/ResultsServiceImpl.java index 8de11ed8..b70d7601 100644 --- a/sonic-server-controller/src/main/java/com/sonic/controller/services/impl/ResultsServiceImpl.java +++ b/sonic-server-controller/src/main/java/com/sonic/controller/services/impl/ResultsServiceImpl.java @@ -220,9 +220,9 @@ public void sendDayReport() { break; } } - if (projects.getRobotToken().length() > 0 && projects.getRobotSecret().length() > 0) { + if (projects.getRobotType() != 0 && projects.getRobotToken().length() > 0 && projects.getRobotSecret().length() > 0) { robotMsgTool.sendDayReportMessage(projects.getRobotToken(), projects.getRobotSecret(), projects.getId() - , projects.getProjectName(), sf.format(yesterday), sf.format(today), suc, warn, fail); + , projects.getProjectName(), sf.format(yesterday), sf.format(today), suc, warn, fail, projects.getRobotType()); } } } @@ -253,9 +253,9 @@ public void sendWeekReport() { break; } } - if (projects.getRobotToken().length() > 0 && projects.getRobotSecret().length() > 0) { + if (projects.getRobotType() != 0 && projects.getRobotToken().length() > 0 && projects.getRobotSecret().length() > 0) { robotMsgTool.sendWeekReportMessage(projects.getRobotToken(), projects.getRobotSecret(), projects.getId() - , projects.getProjectName(), sf.format(lastWeek), sf.format(today), suc, warn, fail, count); + , projects.getProjectName(), sf.format(lastWeek), sf.format(today), suc, warn, fail, count, projects.getRobotType()); } } } @@ -317,9 +317,9 @@ public void setStatus(Results results) { results.setEndTime(new Date()); save(results); Projects projects = projectsService.findById(results.getProjectId()); - if (projects != null && projects.getRobotToken().length() > 0 && projects.getRobotSecret().length() > 0) { + if (projects != null && projects.getRobotType() != 0 && projects.getRobotToken().length() > 0 && projects.getRobotSecret().length() > 0) { robotMsgTool.sendResultFinishReport(projects.getRobotToken(), projects.getRobotSecret(), - results.getSuiteName(), sucCount, warnCount, failCount, projects.getId(), results.getId()); + results.getSuiteName(), sucCount, warnCount, failCount, projects.getId(), results.getId(), projects.getRobotType()); } } } diff --git a/sonic-server-controller/src/main/java/com/sonic/controller/services/impl/StepsServiceImpl.java b/sonic-server-controller/src/main/java/com/sonic/controller/services/impl/StepsServiceImpl.java index e3bcb7ef..bbc148b6 100644 --- a/sonic-server-controller/src/main/java/com/sonic/controller/services/impl/StepsServiceImpl.java +++ b/sonic-server-controller/src/main/java/com/sonic/controller/services/impl/StepsServiceImpl.java @@ -47,6 +47,11 @@ public boolean resetCaseId(int id) { @Override public boolean delete(int id) { if (stepsRepository.existsById(id)) { + Steps steps = stepsRepository.findById(id).get(); + for (PublicSteps publicSteps : steps.getPublicSteps()) { + publicSteps.getSteps().remove(steps); + publicStepsService.save(publicSteps); + } stepsRepository.deleteById(id); return true; } else { diff --git a/sonic-server-controller/src/main/java/com/sonic/controller/tools/RobotMsgTool.java b/sonic-server-controller/src/main/java/com/sonic/controller/tools/RobotMsgTool.java index 101ff074..e09f36d6 100644 --- a/sonic-server-controller/src/main/java/com/sonic/controller/tools/RobotMsgTool.java +++ b/sonic-server-controller/src/main/java/com/sonic/controller/tools/RobotMsgTool.java @@ -2,11 +2,11 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import com.sonic.controller.models.interfaces.RobotType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; -import org.springframework.cloud.context.config.annotation.RefreshScope; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Component; import org.springframework.util.Base64Utils; @@ -17,6 +17,9 @@ import java.math.BigDecimal; import java.math.RoundingMode; import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.List; /** * @author ZhouYiXun @@ -24,7 +27,6 @@ * @date 2021/8/15 18:20 */ @Component -@RefreshScope public class RobotMsgTool { private final Logger logger = LoggerFactory.getLogger(RobotMsgTool.class); @Autowired @@ -50,20 +52,43 @@ public class RobotMsgTool { * @des 钉钉官方签名方法 * @date 2021/8/20 18:20 */ - private void signAndSend(String token, String secret, JSONObject jsonObject) { + private void signAndSend(String token, String secret, int type, JSONObject jsonObject) { try { - Long timestamp = System.currentTimeMillis(); - String stringToSign = timestamp + "\n" + secret; - Mac mac = Mac.getInstance("HmacSHA256"); - mac.init(new SecretKeySpec(secret.getBytes("UTF-8"), "HmacSHA256")); - byte[] signData = mac.doFinal(stringToSign.getBytes("UTF-8")); - String sign = URLEncoder.encode(new String(Base64Utils.encode(signData)), "UTF-8"); - ResponseEntity responseEntity = - restTemplate.postForEntity(token + "×tamp=" + timestamp + "&sign=" + sign - , jsonObject, JSONObject.class); - logger.info("钉钉发送结果:" + responseEntity.getBody()); + switch (type) { + case RobotType.DingTalk: { + Long timestamp = System.currentTimeMillis(); + String stringToSign = timestamp + "\n" + secret; + Mac mac = Mac.getInstance("HmacSHA256"); + mac.init(new SecretKeySpec(secret.getBytes("UTF-8"), "HmacSHA256")); + byte[] signData = mac.doFinal(stringToSign.getBytes("UTF-8")); + String sign = URLEncoder.encode(new String(Base64Utils.encode(signData)), "UTF-8"); + ResponseEntity responseEntity = + restTemplate.postForEntity(token + "×tamp=" + timestamp + "&sign=" + sign + , jsonObject, JSONObject.class); + logger.info("机器人发送结果:" + responseEntity.getBody()); + break; + } + case RobotType.WeChat: + break; + case RobotType.FeiShu: { + String timestamp = String.valueOf(System.currentTimeMillis()).substring(0, 10); + String stringToSign = timestamp + "\n" + secret; + Mac mac = Mac.getInstance("HmacSHA256"); + mac.init(new SecretKeySpec(stringToSign.getBytes(StandardCharsets.UTF_8), "HmacSHA256")); + byte[] signData = mac.doFinal(new byte[]{}); + String sign = new String(Base64Utils.encode(signData)); + jsonObject.put("timestamp", timestamp); + jsonObject.put("sign", sign); + ResponseEntity responseEntity = + restTemplate.postForEntity(token, jsonObject, JSONObject.class); + logger.info("机器人发送结果:" + responseEntity.getBody()); + break; + } + case RobotType.YouSpace: + break; + } } catch (Exception e) { - logger.info("钉钉发送失败:" + e.getMessage()); + logger.info("机器人发送失败:" + e.getMessage()); } } @@ -82,25 +107,45 @@ private void signAndSend(String token, String secret, JSONObject jsonObject) { * @date 2021/8/20 18:29 */ public void sendResultFinishReport(String token, String secret, String suiteName, int pass, - int warn, int fail, int projectId, int resultId) { + int warn, int fail, int projectId, int resultId, int type) { JSONObject jsonObject = new JSONObject(); - JSONObject link = new JSONObject(); - link.put("text", "通过数:" + pass + - " \n异常数:" + warn + - " \n失败数:" + fail); - link.put("title", "测试套件: " + suiteName + " 运行完毕!"); - link.put("messageUrl", "http://" + clientHost + "/Home/" + projectId + "/ResultDetail/" + resultId); - //判断测试结果,来决定显示什么图片 - if (fail > 0) { - link.put("picUrl", errorUrl); - } else if (warn > 0) { - link.put("picUrl", warningUrl); - } else { - link.put("picUrl", successUrl); + if (type == RobotType.DingTalk) { + JSONObject link = new JSONObject(); + link.put("text", "通过数:" + pass + + " \n异常数:" + warn + + " \n失败数:" + fail); + link.put("title", "测试套件: " + suiteName + " 运行完毕!"); + link.put("messageUrl", clientHost + "/Home/" + projectId + "/ResultDetail/" + resultId); + //判断测试结果,来决定显示什么图片 + if (fail > 0) { + link.put("picUrl", errorUrl); + } else if (warn > 0) { + link.put("picUrl", warningUrl); + } else { + link.put("picUrl", successUrl); + } + jsonObject.put("msgtype", "link"); + jsonObject.put("link", link); } - jsonObject.put("msgtype", "link"); - jsonObject.put("link", link); - signAndSend(token, secret, jsonObject); + if (type == RobotType.FeiShu) { + jsonObject.put("msg_type", "interactive"); + JSONObject card = new JSONObject(); + JSONObject config = new JSONObject(); + config.put("wide_screen_mode", true); + card.put("config", config); + JSONObject element = new JSONObject(); + element.put("tag", "markdown"); + List elementList = new ArrayList<>(); + element.put("content", "**测试套件: " + suiteName + " 运行完毕!**\n" + + "通过数:" + pass + " \n" + + "异常数:" + warn + " \n" + + "失败数:" + fail + "\n" + + "测试报告:[点击查看](" + clientHost + "/Home/" + projectId + "/ResultDetail/" + resultId + ")"); + elementList.add(element); + card.put("elements", elementList); + jsonObject.put("card", card); + } + signAndSend(token, secret, type, jsonObject); } /** @@ -115,32 +160,32 @@ public void sendResultFinishReport(String token, String secret, String suiteName * @des 发送装包完毕通知 * @date 2021/8/20 18:33 */ - public void sendInstallPackageFinishReport(String token, String secret, String platform, - String version, String url, JSONArray detail) { - JSONObject jsonObject = new JSONObject(); - JSONObject markdown = new JSONObject(); - String device = ""; - //遍历详情里面的结果,组装成多条安装结果的markdown - for (Object o : detail) { - JSONObject deviceDetail = (JSONObject) o; - String statusColor; - if (deviceDetail.getString("status").equals("PASS")) { - statusColor = "PASS"; - } else { - statusColor = "FAIL"; - } - device += ("> ###### " + deviceDetail.getString("name") + " --- " + statusColor + " \n"); - } - markdown.put("text", "#### **Sonic装包完成通知** \n" + - " ###### 平台:" + platform + " \n" + - " ###### 版本号:" + (version.length() == 0 ? "未知版本" : version) + " \n" + - device + - " ###### 安装地址:[点击查看](" + url + ")"); - markdown.put("title", "Sonic装包完成通知"); - jsonObject.put("msgtype", "markdown"); - jsonObject.put("markdown", markdown); - signAndSend(token, secret, jsonObject); - } +// public void sendInstallPackageFinishReport(String token, String secret, String platform, +// String version, String url, JSONArray detail) { +// JSONObject jsonObject = new JSONObject(); +// JSONObject markdown = new JSONObject(); +// String device = ""; +// //遍历详情里面的结果,组装成多条安装结果的markdown +// for (Object o : detail) { +// JSONObject deviceDetail = (JSONObject) o; +// String statusColor; +// if (deviceDetail.getString("status").equals("PASS")) { +// statusColor = "PASS"; +// } else { +// statusColor = "FAIL"; +// } +// device += ("> ###### " + deviceDetail.getString("name") + " --- " + statusColor + " \n"); +// } +// markdown.put("text", "#### **Sonic装包完成通知** \n" + +// " ###### 平台:" + platform + " \n" + +// " ###### 版本号:" + (version.length() == 0 ? "未知版本" : version) + " \n" + +// device + +// " ###### 安装地址:[点击查看](" + url + ")"); +// markdown.put("title", "Sonic装包完成通知"); +// jsonObject.put("msgtype", "markdown"); +// jsonObject.put("markdown", markdown); +// signAndSend(token, secret, jsonObject); +// } /** * @param token 机器人token @@ -155,69 +200,120 @@ public void sendInstallPackageFinishReport(String token, String secret, String p * @date 2021/8/20 18:42 */ public void sendDayReportMessage(String token, String secret, int projectId, String projectName, - String yesterday, String today, int passCount, int warnCount, int failCount) { + String yesterday, String today, int passCount, int warnCount, int failCount, int type) { JSONObject jsonObject = new JSONObject(); - JSONObject markdown = new JSONObject(); - //根据三个数量来决定markdown的字体颜色 - String failColorString; - if (failCount == 0) { - failColorString = "" + failCount + ""; - } else { - failColorString = "" + failCount + ""; + if (type == RobotType.DingTalk) { + JSONObject markdown = new JSONObject(); + //根据三个数量来决定markdown的字体颜色 + String failColorString; + if (failCount == 0) { + failColorString = "" + failCount + ""; + } else { + failColorString = "" + failCount + ""; + } + String warnColorString; + if (warnCount == 0) { + warnColorString = "" + warnCount + ""; + } else { + warnColorString = "" + warnCount + ""; + } + int total = passCount + warnCount + failCount; + markdown.put("text", "### Sonic云真机测试平台日报 \n" + + "> ###### 项目:" + projectName + " \n" + + "> ###### 时间:" + yesterday + " ~ " + today + " \n" + + "> ###### 通过数:" + passCount + " \n" + + "> ###### 异常数:" + warnColorString + " \n" + + "> ###### 失败数:" + failColorString + " \n" + + "> ###### 测试通过率:" + (total > 0 ? + new BigDecimal((float) passCount / total).setScale(2, RoundingMode.HALF_UP).doubleValue() : 0) + "% \n" + + "> ###### 详细统计:[点击查看](" + clientHost + "/Home/" + projectId + ")"); + markdown.put("title", "Sonic云真机测试平台日报"); + jsonObject.put("msgtype", "markdown"); + jsonObject.put("markdown", markdown); } - String warnColorString; - if (warnCount == 0) { - warnColorString = "" + warnCount + ""; - } else { - warnColorString = "" + warnCount + ""; + if (type == RobotType.FeiShu) { + jsonObject.put("msg_type", "interactive"); + JSONObject card = new JSONObject(); + JSONObject config = new JSONObject(); + config.put("wide_screen_mode", true); + card.put("config", config); + JSONObject element = new JSONObject(); + element.put("tag", "markdown"); + int total = passCount + warnCount + failCount; + List elementList = new ArrayList<>(); + element.put("content", "**Sonic云真机测试平台日报**\n" + + "项目:" + projectName + " \n" + + "时间:" + yesterday + " ~ " + today + " \n" + + "通过数:" + passCount + "\n" + + "异常数:" + warnCount + " \n" + + "失败数:" + failCount + " \n" + + "测试通过率:" + (total > 0 ? + new BigDecimal((float) passCount / total).setScale(2, RoundingMode.HALF_UP).doubleValue() : 0) + "% \n" + + "详细统计:[点击查看](" + clientHost + "/Home/" + projectId + ")"); + elementList.add(element); + card.put("elements", elementList); + jsonObject.put("card", card); } - int total = passCount + warnCount + failCount; - markdown.put("text", "### Sonic云真机测试平台日报 \n" + - "> ###### 项目:" + projectName + " \n" + - "> ###### 时间:" + yesterday + " ~ " + today + " \n" + - "> ###### 通过数:" + passCount + " \n" + - "> ###### 异常数:" + warnColorString + " \n" + - "> ###### 失败数:" + failColorString + " \n" + - "> ###### 测试通过率:" + (total > 0 ? - new BigDecimal((float) passCount / total).setScale(2, RoundingMode.HALF_UP).doubleValue() : 0) + "% \n" + - "> ###### 详细统计:[点击查看](" + clientHost + "/Home/" + projectId + ")"); - markdown.put("title", "Sonic云真机测试平台日报"); - jsonObject.put("msgtype", "markdown"); - jsonObject.put("markdown", markdown); - signAndSend(token, secret, jsonObject); + signAndSend(token, secret, type, jsonObject); } public void sendWeekReportMessage(String token, String secret, int projectId, String projectName, - String yesterday, String today, int passCount, int warnCount, int failCount, int count) { + String yesterday, String today, int passCount, int warnCount, int failCount, int count, int type) { JSONObject jsonObject = new JSONObject(); - JSONObject markdown = new JSONObject(); - //根据三个数量来决定markdown的字体颜色 - String failColorString; - if (failCount == 0) { - failColorString = "" + failCount + ""; - } else { - failColorString = "" + failCount + ""; + if (type == RobotType.DingTalk) { + JSONObject markdown = new JSONObject(); + //根据三个数量来决定markdown的字体颜色 + String failColorString; + if (failCount == 0) { + failColorString = "" + failCount + ""; + } else { + failColorString = "" + failCount + ""; + } + String warnColorString; + if (warnCount == 0) { + warnColorString = "" + warnCount + ""; + } else { + warnColorString = "" + warnCount + ""; + } + int total = passCount + warnCount + failCount; + markdown.put("text", "### Sonic云真机测试平台周报 \n" + + "> ###### 项目:" + projectName + " \n" + + "> ###### 时间:" + yesterday + " ~ " + today + " \n" + + "> ###### 共测试:" + count + " 次\n" + + "> ###### 通过数:" + passCount + " \n" + + "> ###### 异常数:" + warnColorString + " \n" + + "> ###### 失败数:" + failColorString + " \n" + + "> ###### 测试通过率:" + (total > 0 ? + new BigDecimal((float) passCount / total).setScale(2, RoundingMode.HALF_UP).doubleValue() : 0) + "% \n" + + "> ###### 详细统计:[点击查看](" + clientHost + "/Home/" + projectId + ")"); + markdown.put("title", "Sonic云真机测试平台周报"); + jsonObject.put("msgtype", "markdown"); + jsonObject.put("markdown", markdown); } - String warnColorString; - if (warnCount == 0) { - warnColorString = "" + warnCount + ""; - } else { - warnColorString = "" + warnCount + ""; + if (type == RobotType.FeiShu) { + jsonObject.put("msg_type", "interactive"); + JSONObject card = new JSONObject(); + JSONObject config = new JSONObject(); + config.put("wide_screen_mode", true); + card.put("config", config); + JSONObject element = new JSONObject(); + element.put("tag", "markdown"); + int total = passCount + warnCount + failCount; + List elementList = new ArrayList<>(); + element.put("content", "**Sonic云真机测试平台周报**\n" + + "项目:" + projectName + " \n" + + "时间:" + yesterday + " ~ " + today + " \n" + + "共测试:" + count + " 次\n" + + "通过数:" + passCount + " \n" + + "异常数:" + warnCount + " \n" + + "失败数:" + failCount + " \n" + + "测试通过率:" + (total > 0 ? + new BigDecimal((float) passCount / total).setScale(2, RoundingMode.HALF_UP).doubleValue() : 0) + "% \n" + + "详细统计:[点击查看](" + clientHost + "/Home/" + projectId + ")"); + elementList.add(element); + card.put("elements", elementList); + jsonObject.put("card", card); } - int total = passCount + warnCount + failCount; - markdown.put("text", "### Sonic云真机测试平台周报 \n" + - "> ###### 项目:" + projectName + " \n" + - "> ###### 时间:" + yesterday + " ~ " + today + " \n" + - "> ###### 共测试:" + count + " 次\n" + - "> ###### 通过数:" + passCount + " \n" + - "> ###### 异常数:" + warnColorString + " \n" + - "> ###### 失败数:" + failColorString + " \n" + - "> ###### 测试通过率:" + (total > 0 ? - new BigDecimal((float) passCount / total).setScale(2, RoundingMode.HALF_UP).doubleValue() : 0) + "% \n" + - "> ###### 详细统计:[点击查看](" + clientHost + "/Home/" + projectId + ")"); - markdown.put("title", "Sonic云真机测试平台周报"); - jsonObject.put("msgtype", "markdown"); - jsonObject.put("markdown", markdown); - signAndSend(token, secret, jsonObject); + signAndSend(token, secret, type, jsonObject); } } diff --git a/sonic-server-eureka/pom.xml b/sonic-server-eureka/pom.xml index d9958dfb..8838262c 100644 --- a/sonic-server-eureka/pom.xml +++ b/sonic-server-eureka/pom.xml @@ -10,7 +10,7 @@ 4.0.0 sonic-server-eureka - 1.0.0 + 1.1.0 jar diff --git a/sonic-server-folder/pom.xml b/sonic-server-folder/pom.xml index 202e8f4e..d6976e13 100644 --- a/sonic-server-folder/pom.xml +++ b/sonic-server-folder/pom.xml @@ -10,7 +10,7 @@ 4.0.0 sonic-server-folder - 1.0.0 + 1.1.0 jar @@ -33,7 +33,7 @@ com.sonic sonic-server-common - 1.0.0 + 1.1.0 diff --git a/sonic-server-folder/src/main/java/com/sonic/folder/config/WebConfig.java b/sonic-server-folder/src/main/java/com/sonic/folder/config/WebConfig.java index ccf28898..550ee56d 100644 --- a/sonic-server-folder/src/main/java/com/sonic/folder/config/WebConfig.java +++ b/sonic-server-folder/src/main/java/com/sonic/folder/config/WebConfig.java @@ -22,6 +22,8 @@ protected void addResourceHandlers(ResourceHandlerRegistry registry) { .addResourceLocations("file:///" + System.getProperty("user.dir") + "/recordFiles/"); registry.addResourceHandler("/logFiles/**") .addResourceLocations("file:///" + System.getProperty("user.dir") + "/logFiles/"); + registry.addResourceHandler("/packageFiles/**") + .addResourceLocations("file:///" + System.getProperty("user.dir") + "/packageFiles/"); super.addResourceHandlers(registry); } } \ No newline at end of file diff --git a/sonic-server-folder/src/main/java/com/sonic/folder/controller/FilesController.java b/sonic-server-folder/src/main/java/com/sonic/folder/controller/FilesController.java index cac64f99..bfdf3c35 100644 --- a/sonic-server-folder/src/main/java/com/sonic/folder/controller/FilesController.java +++ b/sonic-server-folder/src/main/java/com/sonic/folder/controller/FilesController.java @@ -37,7 +37,7 @@ public class FilesController { public RespModel delete(@RequestParam(name = "day") int day) { long timeMillis = Calendar.getInstance().getTimeInMillis(); SimpleDateFormat sf = new SimpleDateFormat("yyyyMMdd"); - List fileList = Arrays.asList("imageFiles", "recordFiles", "logFiles"); + List fileList = Arrays.asList("imageFiles", "recordFiles", "logFiles", "packageFiles"); cachedThreadPool.execute(() -> { for (String fileType : fileList) { File[] type = new File(fileType).listFiles(); diff --git a/sonic-server-folder/src/main/java/com/sonic/folder/controller/UploadController.java b/sonic-server-folder/src/main/java/com/sonic/folder/controller/UploadController.java index 7f11cbbb..aadcba5a 100644 --- a/sonic-server-folder/src/main/java/com/sonic/folder/controller/UploadController.java +++ b/sonic-server-folder/src/main/java/com/sonic/folder/controller/UploadController.java @@ -30,7 +30,7 @@ public class UploadController { @ApiOperation(value = "上传文件", notes = "上传文件到服务器") @ApiImplicitParams(value = { @ApiImplicitParam(name = "file", value = "文件", dataTypeClass = MultipartFile.class), - @ApiImplicitParam(name = "type", value = "文件类型(只能为keepFiles、imageFiles、recordFiles、logFiles)", dataTypeClass = String.class), + @ApiImplicitParam(name = "type", value = "文件类型(只能为keepFiles、imageFiles、recordFiles、logFiles、packageFiles)", dataTypeClass = String.class), }) @PostMapping public RespModel uploadFiles(@RequestParam(name = "file") MultipartFile file, diff --git a/sonic-server-folder/src/main/java/com/sonic/folder/tools/FileTool.java b/sonic-server-folder/src/main/java/com/sonic/folder/tools/FileTool.java index c84f49d6..2a8eb259 100644 --- a/sonic-server-folder/src/main/java/com/sonic/folder/tools/FileTool.java +++ b/sonic-server-folder/src/main/java/com/sonic/folder/tools/FileTool.java @@ -45,8 +45,8 @@ public String upload(String folderName, MultipartFile file) throws IOException { } //防止文件重名 File local = new File(folder.getPath() + File.separator + - UUID.randomUUID().toString().replaceAll("-", "") - .substring(0, 6) + "-" + file.getOriginalFilename()); + UUID.randomUUID() + file.getOriginalFilename() + .substring(file.getOriginalFilename().lastIndexOf("."))); try { file.transferTo(local.getAbsoluteFile()); } catch (FileAlreadyExistsException e) { diff --git a/sonic-server-gateway/pom.xml b/sonic-server-gateway/pom.xml index 291b65ad..0f258b68 100644 --- a/sonic-server-gateway/pom.xml +++ b/sonic-server-gateway/pom.xml @@ -10,7 +10,7 @@ 4.0.0 sonic-server-gateway - 1.0.0 + 1.1.0 jar @@ -49,7 +49,7 @@ com.sonic sonic-server-common - 1.0.0 + 1.1.0 org.springframework.boot diff --git a/sonic-server-task/pom.xml b/sonic-server-task/pom.xml index 4c1ddcb9..71975957 100644 --- a/sonic-server-task/pom.xml +++ b/sonic-server-task/pom.xml @@ -10,7 +10,7 @@ 4.0.0 sonic-server-task - 1.0.0 + 1.1.0 jar @@ -59,7 +59,7 @@ com.sonic sonic-server-common - 1.0.0 + 1.1.0 org.springframework.boot diff --git a/sonic-server-transport/pom.xml b/sonic-server-transport/pom.xml index 296b8b0f..6f6fef55 100644 --- a/sonic-server-transport/pom.xml +++ b/sonic-server-transport/pom.xml @@ -10,7 +10,7 @@ 4.0.0 sonic-server-transport - 1.0.0 + 1.1.0 jar @@ -48,7 +48,7 @@ com.sonic sonic-server-common - 1.0.0 + 1.1.0 org.springframework.boot diff --git a/swarm.yml b/swarm.yml index c4a9c07b..545d66cc 100644 --- a/swarm.yml +++ b/swarm.yml @@ -74,7 +74,7 @@ services: delay: 20s max_attempts: 6 sonic-server-controller: - image: "zhouyixun/sonic-server-controller:v1.0.0" + image: "zhouyixun/sonic-server-controller:v1.0.1" environment: - PROFILE=prod - EUREKA_URL=http://sonic:sonic@sonic-server-eureka:9090/eureka/