mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-11-10 02:57:17 +08:00
feat(system/client): 新增客户端管理
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.continew.admin.system.mapper;
|
||||
|
||||
import top.continew.starter.data.mp.base.BaseMapper;
|
||||
import top.continew.admin.system.model.entity.ClientDO;
|
||||
|
||||
/**
|
||||
* 客户端管理 Mapper
|
||||
*
|
||||
* @author MoChou
|
||||
* @since 2024/12/03 16:04
|
||||
*/
|
||||
public interface ClientMapper extends BaseMapper<ClientDO> {}
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.continew.admin.system.model.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
|
||||
import lombok.Data;
|
||||
import top.continew.admin.common.enums.DisEnableStatusEnum;
|
||||
import top.continew.starter.extension.crud.model.entity.BaseDO;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 客户端管理实体
|
||||
*
|
||||
* @author MoChou
|
||||
* @since 2024/12/03 16:04
|
||||
*/
|
||||
@Data
|
||||
@TableName(value = "sys_client", autoResultMap = true)
|
||||
public class ClientDO extends BaseDO {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 客户端ID
|
||||
*/
|
||||
private String clientId;
|
||||
|
||||
/**
|
||||
* 客户端Key
|
||||
*/
|
||||
private String clientKey;
|
||||
|
||||
/**
|
||||
* 客户端秘钥
|
||||
*/
|
||||
private String clientSecret;
|
||||
|
||||
/**
|
||||
* 登录类型
|
||||
*/
|
||||
@TableField(typeHandler = JacksonTypeHandler.class)
|
||||
private List<String> authType;
|
||||
|
||||
/**
|
||||
* 客户端类型
|
||||
*/
|
||||
private String clientType;
|
||||
|
||||
/**
|
||||
* Token最低活跃频率(-1为不限制)
|
||||
*/
|
||||
private Integer activeTimeout;
|
||||
|
||||
/**
|
||||
* Token有效期(默认30天,单位:秒)
|
||||
*/
|
||||
private Integer timeout;
|
||||
|
||||
/**
|
||||
* 状态(1:启用;2:禁用)
|
||||
*/
|
||||
private DisEnableStatusEnum status;
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.continew.admin.system.model.query;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import top.continew.admin.common.enums.DisEnableStatusEnum;
|
||||
import top.continew.starter.data.core.annotation.Query;
|
||||
import top.continew.starter.data.core.enums.QueryType;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 客户端管理查询条件
|
||||
*
|
||||
* @author MoChou
|
||||
* @since 2024/12/03 16:04
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "客户端管理查询条件")
|
||||
public class ClientQuery implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 客户端Key
|
||||
*/
|
||||
@Schema(description = "客户端Key")
|
||||
@Query(type = QueryType.EQ)
|
||||
private String clientKey;
|
||||
|
||||
/**
|
||||
* 客户端秘钥
|
||||
*/
|
||||
@Schema(description = "客户端秘钥")
|
||||
@Query(type = QueryType.EQ)
|
||||
private String clientSecret;
|
||||
|
||||
/**
|
||||
* 登录类型
|
||||
*/
|
||||
@Schema(description = "登录类型")
|
||||
@Query(type = QueryType.IN)
|
||||
private List<String> authType;
|
||||
/**
|
||||
* 客户端类型
|
||||
*/
|
||||
@Schema(description = "客户端类型")
|
||||
@Query(type = QueryType.EQ)
|
||||
private String clientType;
|
||||
|
||||
/**
|
||||
* 状态(1:启用;2:禁用)
|
||||
*/
|
||||
@Schema(description = "状态")
|
||||
@Query(type = QueryType.EQ)
|
||||
private DisEnableStatusEnum status;
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.continew.admin.system.model.req;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
import top.continew.admin.common.enums.DisEnableStatusEnum;
|
||||
import top.continew.starter.extension.crud.model.req.BaseReq;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 创建或修改客户端管理参数
|
||||
*
|
||||
* @author MoChou
|
||||
* @since 2024/12/03 16:04
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "创建或修改客户端管理参数")
|
||||
public class ClientReq extends BaseReq {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 客户端ID
|
||||
*/
|
||||
@Schema(description = "客户端ID")
|
||||
private String clientId;
|
||||
|
||||
/**
|
||||
* 客户端Key
|
||||
*/
|
||||
@Schema(description = "客户端Key")
|
||||
@NotBlank(message = "客户端Key不能为空")
|
||||
@Length(max = 32, message = "客户端Key长度不能超过 {max} 个字符")
|
||||
private String clientKey;
|
||||
|
||||
/**
|
||||
* 客户端秘钥
|
||||
*/
|
||||
@Schema(description = "客户端秘钥")
|
||||
@NotBlank(message = "客户端秘钥不能为空")
|
||||
@Length(max = 255, message = "客户端秘钥长度不能超过 {max} 个字符")
|
||||
private String clientSecret;
|
||||
|
||||
/**
|
||||
* 登录类型
|
||||
*/
|
||||
@Schema(description = "登录类型")
|
||||
@NotNull(message = "登录类型不能为空")
|
||||
private List<String> authType;
|
||||
/**
|
||||
* 客户端类型
|
||||
*/
|
||||
@Schema(description = "客户端类型")
|
||||
@NotBlank(message = "客户端类型不能为空")
|
||||
@Length(max = 32, message = "客户端类型长度不能超过 {max} 个字符")
|
||||
private String clientType;
|
||||
|
||||
/**
|
||||
* Token最低活跃频率(-1为不限制)
|
||||
*/
|
||||
@Schema(description = "Token最低活跃频率(-1为不限制)")
|
||||
private Integer activeTimeout;
|
||||
|
||||
/**
|
||||
* Token有效期(默认30天,单位:秒)
|
||||
*/
|
||||
@Schema(description = "Token有效期(默认30天,单位:秒)")
|
||||
private Integer timeout;
|
||||
|
||||
/**
|
||||
* 状态(1:启用;2:禁用)
|
||||
*/
|
||||
@Schema(description = "状态(1:启用;2:禁用)")
|
||||
@NotNull(message = "状态(1:启用;2:禁用)不能为空")
|
||||
private DisEnableStatusEnum status;
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.continew.admin.system.model.resp;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import top.continew.admin.common.enums.DisEnableStatusEnum;
|
||||
import top.continew.starter.extension.crud.model.resp.BaseDetailResp;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 客户端管理详情信息
|
||||
*
|
||||
* @author MoChou
|
||||
* @since 2024/12/03 16:04
|
||||
*/
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
@Schema(description = "客户端管理详情信息")
|
||||
public class ClientDetailResp extends BaseDetailResp {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 客户端ID
|
||||
*/
|
||||
@Schema(description = "客户端ID")
|
||||
@ExcelProperty(value = "客户端ID")
|
||||
private String clientId;
|
||||
|
||||
/**
|
||||
* 客户端Key
|
||||
*/
|
||||
@Schema(description = "客户端Key")
|
||||
@ExcelProperty(value = "客户端Key")
|
||||
private String clientKey;
|
||||
|
||||
/**
|
||||
* 客户端秘钥
|
||||
*/
|
||||
@Schema(description = "客户端秘钥")
|
||||
@ExcelProperty(value = "客户端秘钥")
|
||||
private String clientSecret;
|
||||
|
||||
/**
|
||||
* 登录类型
|
||||
*/
|
||||
@Schema(description = "登录类型")
|
||||
@ExcelProperty(value = "登录类型")
|
||||
private List<String> authType;
|
||||
|
||||
/**
|
||||
* 客户端类型
|
||||
*/
|
||||
@Schema(description = "客户端类型")
|
||||
@ExcelProperty(value = "客户端类型")
|
||||
private String clientType;
|
||||
|
||||
/**
|
||||
* Token最低活跃频率(-1为不限制)
|
||||
*/
|
||||
@Schema(description = "Token最低活跃频率(-1为不限制)")
|
||||
@ExcelProperty(value = "Token最低活跃频率(-1为不限制)")
|
||||
private Integer activeTimeout;
|
||||
|
||||
/**
|
||||
* Token有效期(默认30天,单位:秒)
|
||||
*/
|
||||
@Schema(description = "Token有效期(默认30天,单位:秒)")
|
||||
@ExcelProperty(value = "Token有效期(默认30天,单位:秒)")
|
||||
private Integer timeout;
|
||||
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
@Schema(description = "状态")
|
||||
@ExcelProperty(value = "状态")
|
||||
private DisEnableStatusEnum status;
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.continew.admin.system.model.resp;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import top.continew.admin.common.enums.DisEnableStatusEnum;
|
||||
import top.continew.starter.extension.crud.model.resp.BaseResp;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 客户端管理信息
|
||||
*
|
||||
* @author MoChou
|
||||
* @since 2024/12/03 16:04
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "客户端管理信息")
|
||||
public class ClientResp extends BaseResp {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 客户端ID
|
||||
*/
|
||||
@Schema(description = "客户端ID")
|
||||
private String clientId;
|
||||
|
||||
/**
|
||||
* 客户端Key
|
||||
*/
|
||||
@Schema(description = "客户端Key")
|
||||
private String clientKey;
|
||||
|
||||
/**
|
||||
* 客户端秘钥
|
||||
*/
|
||||
@Schema(description = "客户端秘钥")
|
||||
private String clientSecret;
|
||||
|
||||
/**
|
||||
* 认证类型
|
||||
*/
|
||||
@Schema(description = "认证类型")
|
||||
private List<String> authType;
|
||||
|
||||
/**
|
||||
* 客户端类型
|
||||
*/
|
||||
@Schema(description = "客户端类型")
|
||||
private String clientType;
|
||||
|
||||
/**
|
||||
* Token最低活跃频率(-1为不限制)
|
||||
*/
|
||||
@Schema(description = "Token最低活跃频率(-1为不限制)")
|
||||
private Integer activeTimeout;
|
||||
|
||||
/**
|
||||
* Token有效期(默认30天,单位:秒)
|
||||
*/
|
||||
@Schema(description = "Token有效期(默认30天,单位:秒)")
|
||||
private Integer timeout;
|
||||
|
||||
/**
|
||||
* 状态(1:启用;2:禁用)
|
||||
*/
|
||||
@Schema(description = "状态")
|
||||
private DisEnableStatusEnum status;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.continew.admin.system.service;
|
||||
|
||||
import top.continew.admin.system.model.query.ClientQuery;
|
||||
import top.continew.admin.system.model.req.ClientReq;
|
||||
import top.continew.admin.system.model.resp.ClientDetailResp;
|
||||
import top.continew.admin.system.model.resp.ClientResp;
|
||||
import top.continew.starter.extension.crud.service.BaseService;
|
||||
|
||||
/**
|
||||
* 客户端管理业务接口
|
||||
*
|
||||
* @author MoChou
|
||||
* @since 2024/12/03 16:04
|
||||
*/
|
||||
public interface ClientService extends BaseService<ClientResp, ClientDetailResp, ClientQuery, ClientReq> {
|
||||
|
||||
ClientResp getClientByClientId(String clientId);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.continew.admin.system.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.crypto.digest.DigestUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import top.continew.admin.auth.enums.AuthTypeEnum;
|
||||
import top.continew.admin.system.mapper.ClientMapper;
|
||||
import top.continew.admin.system.model.entity.ClientDO;
|
||||
import top.continew.admin.system.model.query.ClientQuery;
|
||||
import top.continew.admin.system.model.req.ClientReq;
|
||||
import top.continew.admin.system.model.resp.ClientDetailResp;
|
||||
import top.continew.admin.system.model.resp.ClientResp;
|
||||
import top.continew.admin.system.service.ClientService;
|
||||
import top.continew.starter.core.constant.StringConstants;
|
||||
import top.continew.starter.core.validation.ValidationUtils;
|
||||
import top.continew.starter.extension.crud.service.BaseServiceImpl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 客户端管理业务实现
|
||||
*
|
||||
* @author MoChou
|
||||
* @since 2024/12/03 16:04
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class ClientServiceImpl extends BaseServiceImpl<ClientMapper, ClientDO, ClientResp, ClientDetailResp, ClientQuery, ClientReq> implements ClientService {
|
||||
@Override
|
||||
protected void beforeAdd(ClientReq req) {
|
||||
String clientId = DigestUtil.md5Hex(req.getClientKey() + StringConstants.COLON + req.getClientSecret());
|
||||
req.setClientId(clientId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过ClientId获取客户端实例
|
||||
*
|
||||
* @param clientId 客户端id
|
||||
* @return 客户端响应对象
|
||||
*/
|
||||
@Override
|
||||
public ClientResp getClientByClientId(String clientId) {
|
||||
ClientDO clientDO = baseMapper.selectOne(new LambdaQueryWrapper<ClientDO>()
|
||||
.eq(ClientDO::getClientId, clientId));
|
||||
return BeanUtil.copyProperties(clientDO, ClientResp.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void beforeDelete(List<Long> ids) {
|
||||
// 查询如果删除客户端记录以后是否还存在账号认证的方式,不存在则不允许删除
|
||||
List<ClientDO> clientDOS = baseMapper.selectList(new LambdaQueryWrapper<ClientDO>().notIn(ClientDO::getId, ids)
|
||||
.like(ClientDO::getAuthType, AuthTypeEnum.ACCOUNT.getValue()));
|
||||
ValidationUtils.throwIfEmpty(clientDOS, StrUtil.format("请至少保留一条{}认证的方式", AuthTypeEnum.ACCOUNT
|
||||
.getDescription()));
|
||||
super.beforeDelete(ids);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user