From df33c9f42682167594726c3e08b24c9ea244f048 Mon Sep 17 00:00:00 2001 From: song-cc-rock Date: Wed, 23 Oct 2024 12:00:32 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E8=A1=A5=E5=85=85=E5=88=86=E4=BA=AB=E6=93=8D=E4=BD=9C=E4=BA=BA?= =?UTF-8?q?=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1047825 --user=宋昌昌 【接口测试】定义-分享-分享列表-操作人-用户A编辑完分享,查看操作人字段未更新为用户A https://www.tapd.cn/55049933/s/1596265 --- .../metersphere/api/domain/ApiDocShare.java | 10 +- .../api/domain/ApiDocShareExample.java | 130 ++++++++++++++++++ .../api/mapper/ApiDocShareMapper.xml | 57 ++++++-- .../migration/3.4.0/ddl/V3.4.0_2__ga_ddl.sql | 2 + .../definition/ApiDocShareController.java | 2 +- .../api/dto/definition/ApiDocShareDTO.java | 3 + .../api/mapper/ExtApiDocShareMapper.xml | 11 +- .../definition/ApiDocShareService.java | 14 +- .../management/api/createShareModal.vue | 14 +- .../management/api/shareListDrawer.vue | 10 +- 10 files changed, 228 insertions(+), 25 deletions(-) diff --git a/backend/framework/domain/src/main/java/io/metersphere/api/domain/ApiDocShare.java b/backend/framework/domain/src/main/java/io/metersphere/api/domain/ApiDocShare.java index 091f463d83..212578562a 100644 --- a/backend/framework/domain/src/main/java/io/metersphere/api/domain/ApiDocShare.java +++ b/backend/framework/domain/src/main/java/io/metersphere/api/domain/ApiDocShare.java @@ -60,6 +60,12 @@ public class ApiDocShare implements Serializable { @Schema(title = "创建人") private String createUser; + @Schema(title = "更新时间") + private Long updateTime; + + @Schema(title = "更新人") + private String updateUser; + private static final long serialVersionUID = 1L; public enum Column { @@ -74,7 +80,9 @@ public class ApiDocShare implements Serializable { invalidTime("invalid_time", "invalidTime", "BIGINT", false), projectId("project_id", "projectId", "VARCHAR", false), createTime("create_time", "createTime", "BIGINT", false), - createUser("create_user", "createUser", "VARCHAR", false); + createUser("create_user", "createUser", "VARCHAR", false), + updateTime("update_time", "updateTime", "BIGINT", false), + updateUser("update_user", "updateUser", "VARCHAR", false); private static final String BEGINNING_DELIMITER = "`"; diff --git a/backend/framework/domain/src/main/java/io/metersphere/api/domain/ApiDocShareExample.java b/backend/framework/domain/src/main/java/io/metersphere/api/domain/ApiDocShareExample.java index 6c59cb6c49..42c4524bcf 100644 --- a/backend/framework/domain/src/main/java/io/metersphere/api/domain/ApiDocShareExample.java +++ b/backend/framework/domain/src/main/java/io/metersphere/api/domain/ApiDocShareExample.java @@ -903,6 +903,136 @@ public class ApiDocShareExample { addCriterion("create_user not between", value1, value2, "createUser"); return (Criteria) this; } + + public Criteria andUpdateTimeIsNull() { + addCriterion("update_time is null"); + return (Criteria) this; + } + + public Criteria andUpdateTimeIsNotNull() { + addCriterion("update_time is not null"); + return (Criteria) this; + } + + public Criteria andUpdateTimeEqualTo(Long value) { + addCriterion("update_time =", value, "updateTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeNotEqualTo(Long value) { + addCriterion("update_time <>", value, "updateTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeGreaterThan(Long value) { + addCriterion("update_time >", value, "updateTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeGreaterThanOrEqualTo(Long value) { + addCriterion("update_time >=", value, "updateTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeLessThan(Long value) { + addCriterion("update_time <", value, "updateTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeLessThanOrEqualTo(Long value) { + addCriterion("update_time <=", value, "updateTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeIn(List values) { + addCriterion("update_time in", values, "updateTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeNotIn(List values) { + addCriterion("update_time not in", values, "updateTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeBetween(Long value1, Long value2) { + addCriterion("update_time between", value1, value2, "updateTime"); + return (Criteria) this; + } + + public Criteria andUpdateTimeNotBetween(Long value1, Long value2) { + addCriterion("update_time not between", value1, value2, "updateTime"); + return (Criteria) this; + } + + public Criteria andUpdateUserIsNull() { + addCriterion("update_user is null"); + return (Criteria) this; + } + + public Criteria andUpdateUserIsNotNull() { + addCriterion("update_user is not null"); + return (Criteria) this; + } + + public Criteria andUpdateUserEqualTo(String value) { + addCriterion("update_user =", value, "updateUser"); + return (Criteria) this; + } + + public Criteria andUpdateUserNotEqualTo(String value) { + addCriterion("update_user <>", value, "updateUser"); + return (Criteria) this; + } + + public Criteria andUpdateUserGreaterThan(String value) { + addCriterion("update_user >", value, "updateUser"); + return (Criteria) this; + } + + public Criteria andUpdateUserGreaterThanOrEqualTo(String value) { + addCriterion("update_user >=", value, "updateUser"); + return (Criteria) this; + } + + public Criteria andUpdateUserLessThan(String value) { + addCriterion("update_user <", value, "updateUser"); + return (Criteria) this; + } + + public Criteria andUpdateUserLessThanOrEqualTo(String value) { + addCriterion("update_user <=", value, "updateUser"); + return (Criteria) this; + } + + public Criteria andUpdateUserLike(String value) { + addCriterion("update_user like", value, "updateUser"); + return (Criteria) this; + } + + public Criteria andUpdateUserNotLike(String value) { + addCriterion("update_user not like", value, "updateUser"); + return (Criteria) this; + } + + public Criteria andUpdateUserIn(List values) { + addCriterion("update_user in", values, "updateUser"); + return (Criteria) this; + } + + public Criteria andUpdateUserNotIn(List values) { + addCriterion("update_user not in", values, "updateUser"); + return (Criteria) this; + } + + public Criteria andUpdateUserBetween(String value1, String value2) { + addCriterion("update_user between", value1, value2, "updateUser"); + return (Criteria) this; + } + + public Criteria andUpdateUserNotBetween(String value1, String value2) { + addCriterion("update_user not between", value1, value2, "updateUser"); + return (Criteria) this; + } } public static class Criteria extends GeneratedCriteria { diff --git a/backend/framework/domain/src/main/java/io/metersphere/api/mapper/ApiDocShareMapper.xml b/backend/framework/domain/src/main/java/io/metersphere/api/mapper/ApiDocShareMapper.xml index e617aacf9f..061a10afc4 100644 --- a/backend/framework/domain/src/main/java/io/metersphere/api/mapper/ApiDocShareMapper.xml +++ b/backend/framework/domain/src/main/java/io/metersphere/api/mapper/ApiDocShareMapper.xml @@ -14,6 +14,8 @@ + + @@ -75,7 +77,8 @@ id, `name`, is_private, `password`, allow_export, api_range, range_match_symbol, - range_match_val, invalid_time, project_id, create_time, create_user + range_match_val, invalid_time, project_id, create_time, create_user, update_time, + update_user @@ -243,6 +258,12 @@ create_user = #{record.createUser,jdbcType=VARCHAR}, + + update_time = #{record.updateTime,jdbcType=BIGINT}, + + + update_user = #{record.updateUser,jdbcType=VARCHAR}, + @@ -261,7 +282,9 @@ invalid_time = #{record.invalidTime,jdbcType=BIGINT}, project_id = #{record.projectId,jdbcType=VARCHAR}, create_time = #{record.createTime,jdbcType=BIGINT}, - create_user = #{record.createUser,jdbcType=VARCHAR} + create_user = #{record.createUser,jdbcType=VARCHAR}, + update_time = #{record.updateTime,jdbcType=BIGINT}, + update_user = #{record.updateUser,jdbcType=VARCHAR} @@ -302,6 +325,12 @@ create_user = #{createUser,jdbcType=VARCHAR}, + + update_time = #{updateTime,jdbcType=BIGINT}, + + + update_user = #{updateUser,jdbcType=VARCHAR}, + where id = #{id,jdbcType=VARCHAR} @@ -317,20 +346,24 @@ invalid_time = #{invalidTime,jdbcType=BIGINT}, project_id = #{projectId,jdbcType=VARCHAR}, create_time = #{createTime,jdbcType=BIGINT}, - create_user = #{createUser,jdbcType=VARCHAR} + create_user = #{createUser,jdbcType=VARCHAR}, + update_time = #{updateTime,jdbcType=BIGINT}, + update_user = #{updateUser,jdbcType=VARCHAR} where id = #{id,jdbcType=VARCHAR} insert into api_doc_share (id, `name`, is_private, `password`, allow_export, api_range, range_match_symbol, - range_match_val, invalid_time, project_id, create_time, create_user) + range_match_val, invalid_time, project_id, create_time, create_user, update_time, + update_user) values (#{item.id,jdbcType=VARCHAR}, #{item.name,jdbcType=VARCHAR}, #{item.isPrivate,jdbcType=BIT}, #{item.password,jdbcType=VARCHAR}, #{item.allowExport,jdbcType=BIT}, #{item.apiRange,jdbcType=VARCHAR}, #{item.rangeMatchSymbol,jdbcType=VARCHAR}, #{item.rangeMatchVal,jdbcType=VARCHAR}, #{item.invalidTime,jdbcType=BIGINT}, #{item.projectId,jdbcType=VARCHAR}, #{item.createTime,jdbcType=BIGINT}, - #{item.createUser,jdbcType=VARCHAR}) + #{item.createUser,jdbcType=VARCHAR}, #{item.updateTime,jdbcType=BIGINT}, #{item.updateUser,jdbcType=VARCHAR} + ) @@ -379,6 +412,12 @@ #{item.createUser,jdbcType=VARCHAR} + + #{item.updateTime,jdbcType=BIGINT} + + + #{item.updateUser,jdbcType=VARCHAR} + ) diff --git a/backend/framework/domain/src/main/resources/migration/3.4.0/ddl/V3.4.0_2__ga_ddl.sql b/backend/framework/domain/src/main/resources/migration/3.4.0/ddl/V3.4.0_2__ga_ddl.sql index 8602b4a07b..5de5dd4c72 100644 --- a/backend/framework/domain/src/main/resources/migration/3.4.0/ddl/V3.4.0_2__ga_ddl.sql +++ b/backend/framework/domain/src/main/resources/migration/3.4.0/ddl/V3.4.0_2__ga_ddl.sql @@ -93,6 +93,8 @@ CREATE TABLE api_doc_share ( `project_id` VARCHAR(50) NOT NULL COMMENT '项目ID' , `create_time` BIGINT NOT NULL COMMENT '创建时间' , `create_user` VARCHAR(50) NOT NULL COMMENT '创建人' , + `update_time` BIGINT NOT NULL COMMENT '更新时间' , + `update_user` VARCHAR(50) NOT NULL COMMENT '更新人' , PRIMARY KEY (id) ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiDocShareController.java b/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiDocShareController.java index 11af07de4b..6aecf66717 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiDocShareController.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiDocShareController.java @@ -71,7 +71,7 @@ public class ApiDocShareController { @CheckOwner(resourceId = "#request.getId()", resourceType = "api_doc_share") @Log(type = OperationLogType.UPDATE, expression = "#msClass.updateLog(#request)", msClass = ApiDocShareLogService.class) public ApiDocShare update(@Validated({Updated.class}) @RequestBody ApiDocShareEditRequest request) { - return apiDocShareService.update(request); + return apiDocShareService.update(request, SessionUtils.getUserId()); } @GetMapping("/delete/{id}") diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/ApiDocShareDTO.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/ApiDocShareDTO.java index c3502ef4aa..360f72b862 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/ApiDocShareDTO.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/definition/ApiDocShareDTO.java @@ -20,4 +20,7 @@ public class ApiDocShareDTO extends ApiDocShare { @Schema(title = "创建人") private String createUserName; + + @Schema(title = "更新人") + private String updateUserName; } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiDocShareMapper.xml b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiDocShareMapper.xml index cbb3d410f9..d5ab769302 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiDocShareMapper.xml +++ b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiDocShareMapper.xml @@ -4,9 +4,10 @@ @@ -29,8 +30,8 @@ - - and create_user in + + and update_user in diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDocShareService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDocShareService.java index e9beab1f8b..8da2752cdf 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDocShareService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDocShareService.java @@ -19,6 +19,7 @@ import io.metersphere.system.service.UserToolService; import io.metersphere.system.uid.IDGenerator; import jakarta.annotation.Resource; import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.collections4.ListUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -77,6 +78,8 @@ public class ApiDocShareService { docShare.setId(IDGenerator.nextStr()); docShare.setCreateUser(currentUser); docShare.setCreateTime(System.currentTimeMillis()); + docShare.setUpdateUser(currentUser); + docShare.setUpdateTime(System.currentTimeMillis()); apiDocShareMapper.insert(docShare); return docShare; } @@ -86,11 +89,13 @@ public class ApiDocShareService { * @param request 请求参数 * @return 分享 */ - public ApiDocShare update(ApiDocShareEditRequest request) { + public ApiDocShare update(ApiDocShareEditRequest request, String currentUser) { checkExit(request.getId()); checkDuplicateName(request); ApiDocShare docShare = new ApiDocShare(); BeanUtils.copyBean(docShare, request); + docShare.setUpdateUser(currentUser); + docShare.setUpdateTime(System.currentTimeMillis()); apiDocShareMapper.updateByPrimaryKeySelective(docShare); return docShare; } @@ -176,12 +181,15 @@ public class ApiDocShareService { * @return 分享列表 */ public List buildApiShareExtra(List docShares) { - List distinctUserIds = docShares.stream().map(ApiDocShareDTO::getCreateUser).distinct().toList(); - Map userMap = userToolService.getUserMapByIds(distinctUserIds); + List distinctCreateUserIds = docShares.stream().map(ApiDocShareDTO::getCreateUser).distinct().toList(); + List distinctUpdateUserIds = docShares.stream().map(ApiDocShareDTO::getUpdateUser).distinct().toList(); + Map userMap = userToolService.getUserMapByIds(ListUtils.union(distinctCreateUserIds, distinctUpdateUserIds)); docShares.forEach(docShare -> { docShare.setInvalid(docShare.getInvalidTime() != null && docShare.getInvalidTime() != 0 && docShare.getInvalidTime() < System.currentTimeMillis()); docShare.setApiShareNum(countApiShare(docShare)); docShare.setCreateUserName(userMap.get(docShare.getCreateUser())); + docShare.setUpdateUserName(userMap.get(docShare.getUpdateUser())); + }); return docShares; } diff --git a/frontend/src/views/api-test/management/components/management/api/createShareModal.vue b/frontend/src/views/api-test/management/components/management/api/createShareModal.vue index defc465e75..a8821d09e1 100644 --- a/frontend/src/views/api-test/management/components/management/api/createShareModal.vue +++ b/frontend/src/views/api-test/management/components/management/api/createShareModal.vue @@ -59,7 +59,13 @@ - +
@@ -284,6 +290,12 @@ form.value.password = ''; } + function setRangeValue(v: any) { + if (!v) { + form.value.invalidTime = 0; + } + } + watch( () => innerVisible.value, (val) => { diff --git a/frontend/src/views/api-test/management/components/management/api/shareListDrawer.vue b/frontend/src/views/api-test/management/components/management/api/shareListDrawer.vue index 70e9b8fe4e..0d96b1fea0 100644 --- a/frontend/src/views/api-test/management/components/management/api/shareListDrawer.vue +++ b/frontend/src/views/api-test/management/components/management/api/shareListDrawer.vue @@ -31,9 +31,9 @@ -