From 0d20e7faa9bb7717705095af08e3cf32ed0ebb2e Mon Sep 17 00:00:00 2001 From: guoyuqi Date: Mon, 14 Feb 2022 19:05:13 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E9=A1=B9=E7=9B=AE=E8=AE=BE=E7=BD=AE):=20?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92&=E6=80=A7=E8=83=BD?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=9A=84=E6=B5=8B=E8=AF=95=E6=8A=A5=E5=91=8A?= =?UTF-8?q?=E5=88=86=E4=BA=AB=E9=93=BE=E6=8E=A5=E7=9A=84=E6=9C=89=E6=95=88?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E6=94=AF=E6=8C=81=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --user=郭雨琦 加时间选择与时间验证 --- .../api/service/ShareInfoService.java | 34 +- .../api/service/utils/ShareUtill.java | 41 ++ .../base/domain/ProjectApplication.java | 15 + .../domain/ProjectApplicationExample.java | 410 ++++++++++++++++++ .../base/mapper/ProjectApplicationMapper.java | 24 + .../base/mapper/ProjectApplicationMapper.xml | 153 +++++++ .../ProjectApplicationController.java | 28 ++ .../controller/ShareController.java | 1 + .../log/vo/system/SystemReference.java | 6 + .../service/ProjectApplicationService.java | 58 +++ .../metersphere/service/ProjectService.java | 25 ++ .../db/migration/V107__v1.18_release.sql | 40 ++ .../src/main/resources/generatorConfig.xml | 2 +- .../report/PerformanceReportView.vue | 13 +- .../project/menu/appmanage/AppManage.vue | 45 +- .../project/menu/appmanage/TimingItem.vue | 18 +- .../report/detail/TestPlanReportButtons.vue | 12 +- frontend/src/i18n/en-US.js | 2 + frontend/src/i18n/zh-CN.js | 2 + frontend/src/i18n/zh-TW.js | 2 + 20 files changed, 919 insertions(+), 12 deletions(-) create mode 100644 backend/src/main/java/io/metersphere/api/service/utils/ShareUtill.java create mode 100644 backend/src/main/java/io/metersphere/base/domain/ProjectApplication.java create mode 100644 backend/src/main/java/io/metersphere/base/domain/ProjectApplicationExample.java create mode 100644 backend/src/main/java/io/metersphere/base/mapper/ProjectApplicationMapper.java create mode 100644 backend/src/main/java/io/metersphere/base/mapper/ProjectApplicationMapper.xml create mode 100644 backend/src/main/java/io/metersphere/controller/ProjectApplicationController.java create mode 100644 backend/src/main/java/io/metersphere/service/ProjectApplicationService.java diff --git a/backend/src/main/java/io/metersphere/api/service/ShareInfoService.java b/backend/src/main/java/io/metersphere/api/service/ShareInfoService.java index 7c876d290f..5519485b37 100644 --- a/backend/src/main/java/io/metersphere/api/service/ShareInfoService.java +++ b/backend/src/main/java/io/metersphere/api/service/ShareInfoService.java @@ -15,6 +15,7 @@ import io.metersphere.commons.utils.BeanUtils; import io.metersphere.commons.utils.CommonBeanFactory; import io.metersphere.commons.utils.LogUtil; import io.metersphere.commons.utils.SessionUtils; +import io.metersphere.service.ProjectApplicationService; import io.metersphere.track.service.TestPlanApiCaseService; import io.metersphere.track.service.TestPlanScenarioCaseService; import org.apache.commons.lang3.StringUtils; @@ -25,6 +26,8 @@ import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.util.*; +import static io.metersphere.api.service.utils.ShareUtill.getTimeMills; + /** * @author song.tianyang * @Date 2021/2/7 10:37 上午 @@ -44,6 +47,8 @@ public class ShareInfoService { TestPlanScenarioCaseService testPlanScenarioCaseService; @Resource TestPlanReportMapper testPlanReportMapper; + @Resource + private ProjectApplicationService projectApplicationService; public List findApiDocumentSimpleInfoByRequest(ApiDocumentRequest request) { if (this.isParamLegitimacy(request)) { @@ -510,8 +515,33 @@ public class ShareInfoService { */ @Transactional(propagation = Propagation.NOT_SUPPORTED) public void validateExpired(ShareInfo shareInfo) { - // 有效期24小时 - if (shareInfo == null || System.currentTimeMillis() - shareInfo.getUpdateTime() > 1000 * 60 * 60 * 24) { + // 有效期根据类型从ProjectApplication中获取 + if(shareInfo == null ){ + MSException.throwException("连接已失效,请重新获取!"); + } + String type = ""; + if(shareInfo.getShareType().equals("PERFORMANCE_REPORT")){ + type = "PERFORMANCE"; + } + if(shareInfo.getShareType().equals("PLAN_DB_REPORT")){ + type = "TRACK"; + } + if(StringUtils.isBlank(type)){ + millisCheck(shareInfo,1000 * 60 * 60 * 24); + }else{ + ProjectApplication projectApplication = projectApplicationService.getProjectApplication(SessionUtils.getCurrentProjectId(),type); + if(projectApplication.getProjectId()==null){ + millisCheck(shareInfo,1000 * 60 * 60 * 24); + }else { + String expr= projectApplication.getShareReportExpr(); + long timeMills = getTimeMills(expr); + millisCheck(shareInfo,timeMills); + } + } + } + + private void millisCheck(ShareInfo shareInfo, long millis) { + if (System.currentTimeMillis() - shareInfo.getUpdateTime() > millis) { shareInfoMapper.deleteByPrimaryKey(shareInfo.getId()); MSException.throwException("连接已失效,请重新获取!"); } diff --git a/backend/src/main/java/io/metersphere/api/service/utils/ShareUtill.java b/backend/src/main/java/io/metersphere/api/service/utils/ShareUtill.java new file mode 100644 index 0000000000..d1ab6aa11d --- /dev/null +++ b/backend/src/main/java/io/metersphere/api/service/utils/ShareUtill.java @@ -0,0 +1,41 @@ +package io.metersphere.api.service.utils; + +import org.apache.commons.lang3.StringUtils; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.ZoneId; + +public class ShareUtill { + + private static final String UNIT_HOUR = "H"; + private static final String UNIT_DAY = "D"; + private static final String UNIT_MONTH = "M"; + private static final String UNIT_YEAR = "Y"; + + public static long getTimeMills(String expr) { + LocalDateTime localDateTime = LocalDateTime.of(LocalDate.now(), LocalTime.now().withMinute(0).withSecond(0).withNano(0)); + long timeMills = 0; + LocalDateTime date = exprToLocalDateTime(localDateTime, expr); + if (date != null) { + timeMills = date.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(); + } + return timeMills; + } + + public static LocalDateTime exprToLocalDateTime(LocalDateTime localDateTime, String expr) { + LocalDateTime date = null; + String unit = expr.substring(expr.length() - 1); + int quantity = Integer.parseInt(expr.substring(0, expr.length() - 1)); + if(StringUtils.equals(unit,UNIT_HOUR)){ + date = localDateTime.minusHours(quantity); + } else if (StringUtils.equals(unit, UNIT_DAY)) { + date = localDateTime.minusDays(quantity); + } else if (StringUtils.equals(unit, UNIT_MONTH)) { + date = localDateTime.minusMonths(quantity); + } else if (StringUtils.equals(unit, UNIT_YEAR)) { + date = localDateTime.minusYears(quantity); + } + return date; + } +} diff --git a/backend/src/main/java/io/metersphere/base/domain/ProjectApplication.java b/backend/src/main/java/io/metersphere/base/domain/ProjectApplication.java new file mode 100644 index 0000000000..155733479e --- /dev/null +++ b/backend/src/main/java/io/metersphere/base/domain/ProjectApplication.java @@ -0,0 +1,15 @@ +package io.metersphere.base.domain; + +import java.io.Serializable; +import lombok.Data; + +@Data +public class ProjectApplication implements Serializable { + private String projectId; + + private String type; + + private String shareReportExpr; + + private static final long serialVersionUID = 1L; +} \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/domain/ProjectApplicationExample.java b/backend/src/main/java/io/metersphere/base/domain/ProjectApplicationExample.java new file mode 100644 index 0000000000..4a2dd8e535 --- /dev/null +++ b/backend/src/main/java/io/metersphere/base/domain/ProjectApplicationExample.java @@ -0,0 +1,410 @@ +package io.metersphere.base.domain; + +import java.util.ArrayList; +import java.util.List; + +public class ProjectApplicationExample { + protected String orderByClause; + + protected boolean distinct; + + protected List oredCriteria; + + public ProjectApplicationExample() { + oredCriteria = new ArrayList(); + } + + public void setOrderByClause(String orderByClause) { + this.orderByClause = orderByClause; + } + + public String getOrderByClause() { + return orderByClause; + } + + public void setDistinct(boolean distinct) { + this.distinct = distinct; + } + + public boolean isDistinct() { + return distinct; + } + + public List getOredCriteria() { + return oredCriteria; + } + + public void or(Criteria criteria) { + oredCriteria.add(criteria); + } + + public Criteria or() { + Criteria criteria = createCriteriaInternal(); + oredCriteria.add(criteria); + return criteria; + } + + public Criteria createCriteria() { + Criteria criteria = createCriteriaInternal(); + if (oredCriteria.size() == 0) { + oredCriteria.add(criteria); + } + return criteria; + } + + protected Criteria createCriteriaInternal() { + Criteria criteria = new Criteria(); + return criteria; + } + + public void clear() { + oredCriteria.clear(); + orderByClause = null; + distinct = false; + } + + protected abstract static class GeneratedCriteria { + protected List criteria; + + protected GeneratedCriteria() { + super(); + criteria = new ArrayList(); + } + + public boolean isValid() { + return criteria.size() > 0; + } + + public List getAllCriteria() { + return criteria; + } + + public List getCriteria() { + return criteria; + } + + protected void addCriterion(String condition) { + if (condition == null) { + throw new RuntimeException("Value for condition cannot be null"); + } + criteria.add(new Criterion(condition)); + } + + protected void addCriterion(String condition, Object value, String property) { + if (value == null) { + throw new RuntimeException("Value for " + property + " cannot be null"); + } + criteria.add(new Criterion(condition, value)); + } + + protected void addCriterion(String condition, Object value1, Object value2, String property) { + if (value1 == null || value2 == null) { + throw new RuntimeException("Between values for " + property + " cannot be null"); + } + criteria.add(new Criterion(condition, value1, value2)); + } + + public Criteria andProjectIdIsNull() { + addCriterion("project_id is null"); + return (Criteria) this; + } + + public Criteria andProjectIdIsNotNull() { + addCriterion("project_id is not null"); + return (Criteria) this; + } + + public Criteria andProjectIdEqualTo(String value) { + addCriterion("project_id =", value, "projectId"); + return (Criteria) this; + } + + public Criteria andProjectIdNotEqualTo(String value) { + addCriterion("project_id <>", value, "projectId"); + return (Criteria) this; + } + + public Criteria andProjectIdGreaterThan(String value) { + addCriterion("project_id >", value, "projectId"); + return (Criteria) this; + } + + public Criteria andProjectIdGreaterThanOrEqualTo(String value) { + addCriterion("project_id >=", value, "projectId"); + return (Criteria) this; + } + + public Criteria andProjectIdLessThan(String value) { + addCriterion("project_id <", value, "projectId"); + return (Criteria) this; + } + + public Criteria andProjectIdLessThanOrEqualTo(String value) { + addCriterion("project_id <=", value, "projectId"); + return (Criteria) this; + } + + public Criteria andProjectIdLike(String value) { + addCriterion("project_id like", value, "projectId"); + return (Criteria) this; + } + + public Criteria andProjectIdNotLike(String value) { + addCriterion("project_id not like", value, "projectId"); + return (Criteria) this; + } + + public Criteria andProjectIdIn(List values) { + addCriterion("project_id in", values, "projectId"); + return (Criteria) this; + } + + public Criteria andProjectIdNotIn(List values) { + addCriterion("project_id not in", values, "projectId"); + return (Criteria) this; + } + + public Criteria andProjectIdBetween(String value1, String value2) { + addCriterion("project_id between", value1, value2, "projectId"); + return (Criteria) this; + } + + public Criteria andProjectIdNotBetween(String value1, String value2) { + addCriterion("project_id not between", value1, value2, "projectId"); + return (Criteria) this; + } + + public Criteria andTypeIsNull() { + addCriterion("`type` is null"); + return (Criteria) this; + } + + public Criteria andTypeIsNotNull() { + addCriterion("`type` is not null"); + return (Criteria) this; + } + + public Criteria andTypeEqualTo(String value) { + addCriterion("`type` =", value, "type"); + return (Criteria) this; + } + + public Criteria andTypeNotEqualTo(String value) { + addCriterion("`type` <>", value, "type"); + return (Criteria) this; + } + + public Criteria andTypeGreaterThan(String value) { + addCriterion("`type` >", value, "type"); + return (Criteria) this; + } + + public Criteria andTypeGreaterThanOrEqualTo(String value) { + addCriterion("`type` >=", value, "type"); + return (Criteria) this; + } + + public Criteria andTypeLessThan(String value) { + addCriterion("`type` <", value, "type"); + return (Criteria) this; + } + + public Criteria andTypeLessThanOrEqualTo(String value) { + addCriterion("`type` <=", value, "type"); + return (Criteria) this; + } + + public Criteria andTypeLike(String value) { + addCriterion("`type` like", value, "type"); + return (Criteria) this; + } + + public Criteria andTypeNotLike(String value) { + addCriterion("`type` not like", value, "type"); + return (Criteria) this; + } + + public Criteria andTypeIn(List values) { + addCriterion("`type` in", values, "type"); + return (Criteria) this; + } + + public Criteria andTypeNotIn(List values) { + addCriterion("`type` not in", values, "type"); + return (Criteria) this; + } + + public Criteria andTypeBetween(String value1, String value2) { + addCriterion("`type` between", value1, value2, "type"); + return (Criteria) this; + } + + public Criteria andTypeNotBetween(String value1, String value2) { + addCriterion("`type` not between", value1, value2, "type"); + return (Criteria) this; + } + + public Criteria andShareReportExprIsNull() { + addCriterion("share_report_expr is null"); + return (Criteria) this; + } + + public Criteria andShareReportExprIsNotNull() { + addCriterion("share_report_expr is not null"); + return (Criteria) this; + } + + public Criteria andShareReportExprEqualTo(String value) { + addCriterion("share_report_expr =", value, "shareReportExpr"); + return (Criteria) this; + } + + public Criteria andShareReportExprNotEqualTo(String value) { + addCriterion("share_report_expr <>", value, "shareReportExpr"); + return (Criteria) this; + } + + public Criteria andShareReportExprGreaterThan(String value) { + addCriterion("share_report_expr >", value, "shareReportExpr"); + return (Criteria) this; + } + + public Criteria andShareReportExprGreaterThanOrEqualTo(String value) { + addCriterion("share_report_expr >=", value, "shareReportExpr"); + return (Criteria) this; + } + + public Criteria andShareReportExprLessThan(String value) { + addCriterion("share_report_expr <", value, "shareReportExpr"); + return (Criteria) this; + } + + public Criteria andShareReportExprLessThanOrEqualTo(String value) { + addCriterion("share_report_expr <=", value, "shareReportExpr"); + return (Criteria) this; + } + + public Criteria andShareReportExprLike(String value) { + addCriterion("share_report_expr like", value, "shareReportExpr"); + return (Criteria) this; + } + + public Criteria andShareReportExprNotLike(String value) { + addCriterion("share_report_expr not like", value, "shareReportExpr"); + return (Criteria) this; + } + + public Criteria andShareReportExprIn(List values) { + addCriterion("share_report_expr in", values, "shareReportExpr"); + return (Criteria) this; + } + + public Criteria andShareReportExprNotIn(List values) { + addCriterion("share_report_expr not in", values, "shareReportExpr"); + return (Criteria) this; + } + + public Criteria andShareReportExprBetween(String value1, String value2) { + addCriterion("share_report_expr between", value1, value2, "shareReportExpr"); + return (Criteria) this; + } + + public Criteria andShareReportExprNotBetween(String value1, String value2) { + addCriterion("share_report_expr not between", value1, value2, "shareReportExpr"); + return (Criteria) this; + } + } + + public static class Criteria extends GeneratedCriteria { + + protected Criteria() { + super(); + } + } + + public static class Criterion { + private String condition; + + private Object value; + + private Object secondValue; + + private boolean noValue; + + private boolean singleValue; + + private boolean betweenValue; + + private boolean listValue; + + private String typeHandler; + + public String getCondition() { + return condition; + } + + public Object getValue() { + return value; + } + + public Object getSecondValue() { + return secondValue; + } + + public boolean isNoValue() { + return noValue; + } + + public boolean isSingleValue() { + return singleValue; + } + + public boolean isBetweenValue() { + return betweenValue; + } + + public boolean isListValue() { + return listValue; + } + + public String getTypeHandler() { + return typeHandler; + } + + protected Criterion(String condition) { + super(); + this.condition = condition; + this.typeHandler = null; + this.noValue = true; + } + + protected Criterion(String condition, Object value, String typeHandler) { + super(); + this.condition = condition; + this.value = value; + this.typeHandler = typeHandler; + if (value instanceof List) { + this.listValue = true; + } else { + this.singleValue = true; + } + } + + protected Criterion(String condition, Object value) { + this(condition, value, null); + } + + protected Criterion(String condition, Object value, Object secondValue, String typeHandler) { + super(); + this.condition = condition; + this.value = value; + this.secondValue = secondValue; + this.typeHandler = typeHandler; + this.betweenValue = true; + } + + protected Criterion(String condition, Object value, Object secondValue) { + this(condition, value, secondValue, null); + } + } +} \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/mapper/ProjectApplicationMapper.java b/backend/src/main/java/io/metersphere/base/mapper/ProjectApplicationMapper.java new file mode 100644 index 0000000000..58a568e5d5 --- /dev/null +++ b/backend/src/main/java/io/metersphere/base/mapper/ProjectApplicationMapper.java @@ -0,0 +1,24 @@ +package io.metersphere.base.mapper; + +import io.metersphere.base.domain.Project; +import io.metersphere.base.domain.ProjectApplication; +import io.metersphere.base.domain.ProjectApplicationExample; +import java.util.List; +import org.apache.ibatis.annotations.Param; + +public interface ProjectApplicationMapper { + long countByExample(ProjectApplicationExample example); + + int deleteByExample(ProjectApplicationExample example); + + int insert(ProjectApplication record); + + int insertSelective(ProjectApplication record); + + List selectByExample(ProjectApplicationExample example); + + int updateByExampleSelective(@Param("record") ProjectApplication record, @Param("example") ProjectApplicationExample example); + + int updateByExample(@Param("record") ProjectApplication record, @Param("example") ProjectApplicationExample example); + +} \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/mapper/ProjectApplicationMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ProjectApplicationMapper.xml new file mode 100644 index 0000000000..08ede9ac2f --- /dev/null +++ b/backend/src/main/java/io/metersphere/base/mapper/ProjectApplicationMapper.xml @@ -0,0 +1,153 @@ + + + + + + + + + + + + + + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value} + + + and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} + + + and ${criterion.condition} + + #{listItem} + + + + + + + + + + + + + + + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value} + + + and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} + + + and ${criterion.condition} + + #{listItem} + + + + + + + + + + + project_id, `type`, share_report_expr + + + + delete from project_application + + + + + + insert into project_application (project_id, `type`, share_report_expr + ) + values (#{projectId,jdbcType=VARCHAR}, #{type,jdbcType=VARCHAR}, #{shareReportExpr,jdbcType=VARCHAR} + ) + + + insert into project_application + + + project_id, + + + `type`, + + + share_report_expr, + + + + + #{projectId,jdbcType=VARCHAR}, + + + #{type,jdbcType=VARCHAR}, + + + #{shareReportExpr,jdbcType=VARCHAR}, + + + + + + update project_application + + + project_id = #{record.projectId,jdbcType=VARCHAR}, + + + `type` = #{record.type,jdbcType=VARCHAR}, + + + share_report_expr = #{record.shareReportExpr,jdbcType=VARCHAR}, + + + + + + + + update project_application + set project_id = #{record.projectId,jdbcType=VARCHAR}, + `type` = #{record.type,jdbcType=VARCHAR}, + share_report_expr = #{record.shareReportExpr,jdbcType=VARCHAR} + + + + + \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/controller/ProjectApplicationController.java b/backend/src/main/java/io/metersphere/controller/ProjectApplicationController.java new file mode 100644 index 0000000000..62f0f6f285 --- /dev/null +++ b/backend/src/main/java/io/metersphere/controller/ProjectApplicationController.java @@ -0,0 +1,28 @@ +package io.metersphere.controller; + +import io.metersphere.base.domain.ProjectApplication; +import io.metersphere.commons.constants.OperLogConstants; +import io.metersphere.commons.constants.OperLogModule; +import io.metersphere.log.annotation.MsAuditLog; +import io.metersphere.service.ProjectApplicationService; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; + +@RestController +@RequestMapping(value = "/project_application") +public class ProjectApplicationController { + @Resource + private ProjectApplicationService projectApplicationService; + + @PostMapping("/update") + @MsAuditLog(module = OperLogModule.PROJECT_PROJECT_MANAGER, type = OperLogConstants.UPDATE, beforeEvent = "#msClass.getLogDetails(#projectApplication)", content = "#msClass.getLogDetails(#projectApplication)", msClass = ProjectApplicationService.class) + public void updateProject(@RequestBody ProjectApplication projectApplication) { + projectApplicationService.updateProjectApplication(projectApplication); + } + + @GetMapping("/get/{projectId}/{type}") + public ProjectApplication getProjectApplication(@PathVariable String projectId,@PathVariable String type) { + return projectApplicationService.getProjectApplication(projectId,type); + } +} diff --git a/backend/src/main/java/io/metersphere/controller/ShareController.java b/backend/src/main/java/io/metersphere/controller/ShareController.java index b1ab20b89b..f25438c2f9 100644 --- a/backend/src/main/java/io/metersphere/controller/ShareController.java +++ b/backend/src/main/java/io/metersphere/controller/ShareController.java @@ -181,6 +181,7 @@ public class ShareController { @GetMapping("/performance/report/get-advanced-config/{shareId}/{reportId}") public String getAdvancedConfig(@PathVariable String shareId, @PathVariable String reportId) { + shareInfoService.validate(shareId, reportId); return performanceReportService.getAdvancedConfiguration(reportId); } diff --git a/backend/src/main/java/io/metersphere/log/vo/system/SystemReference.java b/backend/src/main/java/io/metersphere/log/vo/system/SystemReference.java index 0344a2c305..09bb3b1ac5 100644 --- a/backend/src/main/java/io/metersphere/log/vo/system/SystemReference.java +++ b/backend/src/main/java/io/metersphere/log/vo/system/SystemReference.java @@ -22,6 +22,7 @@ public class SystemReference { public static Map mailColumns = new LinkedHashMap<>(); public static Map baseColumns = new LinkedHashMap<>(); public static Map groupColumns = new LinkedHashMap<>(); + public static Map projectApplicationColumns = new LinkedHashMap<>(); static { @@ -42,6 +43,7 @@ public class SystemReference { ldapColumns.clear(); mailColumns.clear(); groupColumns.clear(); + projectApplicationColumns.clear(); userColumns.put("name", "用户名称"); userColumns.put("createUser", "创建人"); @@ -110,6 +112,10 @@ public class SystemReference { projectColumns.put("name", "名称"); projectColumns.put("description", "描述"); + projectApplicationColumns.put("projectId", "项目ID"); + projectApplicationColumns.put("type", "类型"); + projectApplicationColumns.put("shareReportExpr", "报告分享链接时间"); + jarColumns.put("name", "名称"); jarColumns.put("fileName", "文件名称"); jarColumns.put("description", "描述"); diff --git a/backend/src/main/java/io/metersphere/service/ProjectApplicationService.java b/backend/src/main/java/io/metersphere/service/ProjectApplicationService.java new file mode 100644 index 0000000000..10d5c0837d --- /dev/null +++ b/backend/src/main/java/io/metersphere/service/ProjectApplicationService.java @@ -0,0 +1,58 @@ +package io.metersphere.service; + +import com.alibaba.fastjson.JSON; +import io.metersphere.base.domain.*; +import io.metersphere.base.mapper.ProjectApplicationMapper; +import io.metersphere.base.mapper.ProjectMapper; +import io.metersphere.commons.utils.SessionUtils; +import io.metersphere.log.utils.ReflexObjectUtil; +import io.metersphere.log.vo.DetailColumn; +import io.metersphere.log.vo.OperatingLogDetails; +import io.metersphere.log.vo.system.SystemReference; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.List; +import java.util.Objects; + +@Service +@Transactional(rollbackFor = Exception.class) +public class ProjectApplicationService { + @Resource + private ProjectApplicationMapper projectApplicationMapper; + + @Resource + private ProjectMapper projectMapper; + + public void updateProjectApplication(ProjectApplication projectApplication){ + ProjectApplicationExample projectApplicationExample = new ProjectApplicationExample(); + projectApplicationExample.createCriteria().andProjectIdEqualTo(projectApplication.getProjectId()).andTypeEqualTo(projectApplication.getType()); + projectApplicationMapper.updateByExample(projectApplication,projectApplicationExample); + } + + public String getLogDetails(ProjectApplication projectApplication) { + if (projectApplication != null) { + List columns = ReflexObjectUtil.getColumns(projectApplication, SystemReference.projectApplicationColumns); + Project project = projectMapper.selectByPrimaryKey(projectApplication.getProjectId()); + if (project==null) { + return null; + } + DetailColumn column = new DetailColumn("项目名称", "projectName", project.getName(), null); + columns.add(column); + OperatingLogDetails details = new OperatingLogDetails(JSON.toJSONString(project.getId()), project.getId(), "修改链接报告时间", Objects.requireNonNull(SessionUtils.getUser()).getCreateUser(), columns); + return JSON.toJSONString(details); + } + return null; + } + + public ProjectApplication getProjectApplication(String projectId, String type) { + ProjectApplicationExample projectApplicationExample = new ProjectApplicationExample(); + projectApplicationExample.createCriteria().andProjectIdEqualTo(projectId).andTypeEqualTo(type); + List projectApplications = projectApplicationMapper.selectByExample(projectApplicationExample); + if(projectApplications==null||projectApplications.size()==0){ + return new ProjectApplication(); + } + return projectApplications.get(0); + } +} diff --git a/backend/src/main/java/io/metersphere/service/ProjectService.java b/backend/src/main/java/io/metersphere/service/ProjectService.java index a82dfe1611..b69b151624 100644 --- a/backend/src/main/java/io/metersphere/service/ProjectService.java +++ b/backend/src/main/java/io/metersphere/service/ProjectService.java @@ -108,6 +108,9 @@ public class ProjectService { private TestPlanReportService testPlanReportService; @Resource private ApiScenarioReportService apiScenarioReportService; + @Resource + private ProjectApplicationMapper projectApplicationMapper; + public Project addProject(Project project) { if (StringUtils.isBlank(project.getName())) { @@ -164,6 +167,15 @@ public class ProjectService { projectVersion.setStatus("open"); projectVersionService.addProjectVersion(projectVersion); } + + //创建新项目也创建相关新项目的应用(分测试跟踪,接口,性能) + ProjectApplication projectApplication = new ProjectApplication(); + projectApplication.setProjectId(project.getId()); + //每个新项目都会有测试跟踪/性能报告分享链接的有效时间,默认时间24H + projectApplication.setType("TRACK"); + projectApplicationMapper.insert(projectApplication); + projectApplication.setType("PERFORMANCE"); + projectApplicationMapper.insert(projectApplication); return project; } @@ -301,6 +313,14 @@ public class ProjectService { reportIdList.forEach(reportId -> performanceReportService.deleteReport(reportId)); } }); + //删除分享报告时间 + delReportTime(projectId,"PERFORMANCE"); + } + + private void delReportTime(String projectId,String type) { + ProjectApplicationExample projectApplicationExample = new ProjectApplicationExample(); + projectApplicationExample.createCriteria().andProjectIdEqualTo(projectId).andTypeEqualTo(type); + projectApplicationMapper.deleteByExample(projectApplicationExample); } private void deleteTrackResourceByProjectId(String projectId) { @@ -311,6 +331,8 @@ public class ProjectService { }); } testCaseService.deleteTestCaseByProjectId(projectId); + //删除分享报告时间 + delReportTime(projectId,"TRACK"); } private void deleteAPIResourceByProjectId(String projectId) { @@ -324,6 +346,9 @@ public class ProjectService { }); } + + + public void updateProject(Project project) { //查询之前的TCP端口,用于检查是否需要开启/关闭 TCP接口 int lastTcpNum = 0; diff --git a/backend/src/main/resources/db/migration/V107__v1.18_release.sql b/backend/src/main/resources/db/migration/V107__v1.18_release.sql index ef33887a37..bb5f0375cd 100644 --- a/backend/src/main/resources/db/migration/V107__v1.18_release.sql +++ b/backend/src/main/resources/db/migration/V107__v1.18_release.sql @@ -52,6 +52,46 @@ DELIMITER ; CALL test_personal(); DROP PROCEDURE IF EXISTS test_personal; + +DROP PROCEDURE IF EXISTS project_appl; +DELIMITER // +CREATE PROCEDURE project_appl() +BEGIN + #声明结束标识 + DECLARE end_flag int DEFAULT 0; + + DECLARE projectId varchar(64); + + #声明游标 group_curosr + DECLARE project_curosr CURSOR FOR SELECT DISTINCT id FROM project; + + #设置终止标志 + DECLARE CONTINUE HANDLER FOR NOT FOUND SET end_flag=1; + + #打开游标 + OPEN project_curosr; + + #遍历游标 + REPEAT + #获取当前游标指针记录,取出值赋给自定义的变量 + FETCH project_curosr INTO projectId; + #利用取到的值进行数据库的操作 + INSERT INTO project_application (project_id, type, share_report_expr) + VALUES (projectId, 'TRACK', '24H'), + (projectId, 'PERFORMANCE', '24H'); + # 根据 end_flag 判断是否结束 + UNTIL end_flag END REPEAT; + + #关闭游标 + close project_curosr; + +END +// +DELIMITER ; + +CALL project_appl(); +DROP PROCEDURE IF EXISTS project_appl; + ALTER TABLE api_definition_exec_result ADD project_id varchar(50); diff --git a/backend/src/main/resources/generatorConfig.xml b/backend/src/main/resources/generatorConfig.xml index 17fb27ac4d..02520779ea 100644 --- a/backend/src/main/resources/generatorConfig.xml +++ b/backend/src/main/resources/generatorConfig.xml @@ -71,7 +71,7 @@ - +