feat(接口测试): 补充分享操作人字段

--bug=1047825 --user=宋昌昌 【接口测试】定义-分享-分享列表-操作人-用户A编辑完分享,查看操作人字段未更新为用户A https://www.tapd.cn/55049933/s/1596265
This commit is contained in:
song-cc-rock 2024-10-23 12:00:32 +08:00 committed by Craftsman
parent 465752d035
commit df33c9f426
10 changed files with 228 additions and 25 deletions

View File

@ -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 = "`";

View File

@ -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<Long> values) {
addCriterion("update_time in", values, "updateTime");
return (Criteria) this;
}
public Criteria andUpdateTimeNotIn(List<Long> 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<String> values) {
addCriterion("update_user in", values, "updateUser");
return (Criteria) this;
}
public Criteria andUpdateUserNotIn(List<String> 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 {

View File

@ -14,6 +14,8 @@
<result column="project_id" jdbcType="VARCHAR" property="projectId" />
<result column="create_time" jdbcType="BIGINT" property="createTime" />
<result column="create_user" jdbcType="VARCHAR" property="createUser" />
<result column="update_time" jdbcType="BIGINT" property="updateTime" />
<result column="update_user" jdbcType="VARCHAR" property="updateUser" />
</resultMap>
<sql id="Example_Where_Clause">
<where>
@ -75,7 +77,8 @@
</sql>
<sql id="Base_Column_List">
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
</sql>
<select id="selectByExample" parameterType="io.metersphere.api.domain.ApiDocShareExample" resultMap="BaseResultMap">
select
@ -111,13 +114,13 @@
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
)
project_id, create_time, create_user,
update_time, update_user)
values (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{isPrivate,jdbcType=BIT},
#{password,jdbcType=VARCHAR}, #{allowExport,jdbcType=BIT}, #{apiRange,jdbcType=VARCHAR},
#{rangeMatchSymbol,jdbcType=VARCHAR}, #{rangeMatchVal,jdbcType=VARCHAR}, #{invalidTime,jdbcType=BIGINT},
#{projectId,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT}, #{createUser,jdbcType=VARCHAR}
)
#{projectId,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT}, #{createUser,jdbcType=VARCHAR},
#{updateTime,jdbcType=BIGINT}, #{updateUser,jdbcType=VARCHAR})
</insert>
<insert id="insertSelective" parameterType="io.metersphere.api.domain.ApiDocShare">
insert into api_doc_share
@ -158,6 +161,12 @@
<if test="createUser != null">
create_user,
</if>
<if test="updateTime != null">
update_time,
</if>
<if test="updateUser != null">
update_user,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
@ -196,6 +205,12 @@
<if test="createUser != null">
#{createUser,jdbcType=VARCHAR},
</if>
<if test="updateTime != null">
#{updateTime,jdbcType=BIGINT},
</if>
<if test="updateUser != null">
#{updateUser,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="io.metersphere.api.domain.ApiDocShareExample" resultType="java.lang.Long">
@ -243,6 +258,12 @@
<if test="record.createUser != null">
create_user = #{record.createUser,jdbcType=VARCHAR},
</if>
<if test="record.updateTime != null">
update_time = #{record.updateTime,jdbcType=BIGINT},
</if>
<if test="record.updateUser != null">
update_user = #{record.updateUser,jdbcType=VARCHAR},
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
@ -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}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
@ -302,6 +325,12 @@
<if test="createUser != null">
create_user = #{createUser,jdbcType=VARCHAR},
</if>
<if test="updateTime != null">
update_time = #{updateTime,jdbcType=BIGINT},
</if>
<if test="updateUser != null">
update_user = #{updateUser,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=VARCHAR}
</update>
@ -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}
</update>
<insert id="batchInsert" parameterType="map">
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
<foreach collection="list" item="item" separator=",">
(#{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}
)
</foreach>
</insert>
<insert id="batchInsertSelective" parameterType="map">
@ -379,6 +412,12 @@
<if test="'create_user'.toString() == column.value">
#{item.createUser,jdbcType=VARCHAR}
</if>
<if test="'update_time'.toString() == column.value">
#{item.updateTime,jdbcType=BIGINT}
</if>
<if test="'update_user'.toString() == column.value">
#{item.updateUser,jdbcType=VARCHAR}
</if>
</foreach>
)
</foreach>

View File

@ -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

View File

@ -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}")

View File

@ -20,4 +20,7 @@ public class ApiDocShareDTO extends ApiDocShare {
@Schema(title = "创建人")
private String createUserName;
@Schema(title = "更新人")
private String updateUserName;
}

View File

@ -4,9 +4,10 @@
<mapper namespace="io.metersphere.api.mapper.ExtApiDocShareMapper">
<select id="list" resultType="io.metersphere.api.dto.definition.ApiDocShareDTO">
select id, name, is_private isPrivate, create_user createUser, create_time createTime, allow_export allowExport,
api_range apiRange, range_match_symbol rangeMatchSymbol, range_match_val rangeMatchVal,
invalid_time invalidTime, project_id projectId, password
select id, name, is_private isPrivate, create_user createUser, create_time createTime,
update_user updateUser, update_time updateTime, allow_export allowExport,
api_range apiRange, range_match_symbol rangeMatchSymbol, range_match_val rangeMatchVal,
invalid_time invalidTime, project_id projectId, password
from api_doc_share
<include refid="queryWhereCondition"/>
</select>
@ -29,8 +30,8 @@
<if test="values != null and values.size() > 0">
<choose>
<!-- 创建人 -->
<when test="key == 'createUser'">
and create_user in
<when test="key == 'updateUser'">
and update_user in
<include refid="io.metersphere.system.mapper.BaseMapper.filterInWrapper"/>
</when>
</choose>

View File

@ -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<ApiDocShareDTO> buildApiShareExtra(List<ApiDocShareDTO> docShares) {
List<String> distinctUserIds = docShares.stream().map(ApiDocShareDTO::getCreateUser).distinct().toList();
Map<String, String> userMap = userToolService.getUserMapByIds(distinctUserIds);
List<String> distinctCreateUserIds = docShares.stream().map(ApiDocShareDTO::getCreateUser).distinct().toList();
List<String> distinctUpdateUserIds = docShares.stream().map(ApiDocShareDTO::getUpdateUser).distinct().toList();
Map<String, String> 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;
}

View File

@ -59,7 +59,13 @@
</div>
</a-form-item>
<a-form-item field="invalidTime" :label="t('apiTestManagement.invalidTime')" asterisk-position="end">
<a-date-picker v-model:model-value="form.invalidTime" show-time value-format="timestamp" class="w-[400px]" />
<a-date-picker
v-model:model-value="form.invalidTime"
show-time
value-format="timestamp"
class="w-[400px]"
@change="(v) => setRangeValue(v)"
/>
</a-form-item>
<div class="mb-[16px] flex items-center">
<a-switch v-model:model-value="form.isPrivate" class="mr-[8px]" size="small" @change="changePrivate" />
@ -284,6 +290,12 @@
form.value.password = '';
}
function setRangeValue(v: any) {
if (!v) {
form.value.invalidTime = 0;
}
}
watch(
() => innerVisible.value,
(val) => {

View File

@ -31,9 +31,9 @@
<template #isPrivate="{ record }">
{{ record.isPrivate ? t('apiTestManagement.passwordView') : t('apiTestManagement.publicityView') }}
</template>
<template #createUserName="{ record }">
<a-tooltip :content="`${record.createUserName}`" position="tl">
<div class="one-line-text">{{ record.createUserName || '-' }}</div>
<template #updateUserName="{ record }">
<a-tooltip :content="`${record.updateUserName}`" position="tl">
<div class="one-line-text">{{ record.updateUserName || '-' }}</div>
</a-tooltip>
</template>
<template #invalidTime="{ record }">
@ -150,8 +150,8 @@
},
{
title: 'common.operator',
dataIndex: 'createUser',
slotName: 'createUserName',
dataIndex: 'updateUser',
slotName: 'updateUserName',
showInTable: true,
width: 200,
showDrag: true,