parent
57723b9ca1
commit
3603582c88
@ -0,0 +1,39 @@
|
||||
package com.ruoyi.auth.handler;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.security.authentication.event.AuthenticationSuccessEvent;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.stereotype.Component;
|
||||
import com.ruoyi.common.core.constant.Constants;
|
||||
import com.ruoyi.common.core.utils.StringUtils;
|
||||
import com.ruoyi.common.security.domain.LoginUser;
|
||||
import com.ruoyi.system.api.RemoteLogService;
|
||||
|
||||
/**
|
||||
* 认证成功处理
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Component
|
||||
public class AuthenticationSuccessEventHandler implements ApplicationListener<AuthenticationSuccessEvent>
|
||||
{
|
||||
@Autowired
|
||||
private RemoteLogService remoteLogService;
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(AuthenticationSuccessEvent event)
|
||||
{
|
||||
Authentication authentication = (Authentication) event.getSource();
|
||||
if (StringUtils.isNotEmpty(authentication.getAuthorities())
|
||||
&& authentication.getPrincipal() instanceof LoginUser)
|
||||
{
|
||||
LoginUser user = (LoginUser) authentication.getPrincipal();
|
||||
|
||||
String username = user.getUsername();
|
||||
|
||||
// 记录用户登录日志
|
||||
remoteLogService.saveLogininfor(username, Constants.LOGIN_SUCCESS, "登录成功");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package com.ruoyi.gateway.config;
|
||||
|
||||
import org.springframework.cloud.gateway.filter.GlobalFilter;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import com.alibaba.csp.sentinel.adapter.gateway.sc.SentinelGatewayFilter;
|
||||
import com.ruoyi.gateway.handler.SentinelFallbackHandler;
|
||||
|
||||
/**
|
||||
* 网关限流配置
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Configuration
|
||||
public class GatewayConfig
|
||||
{
|
||||
@Bean
|
||||
@Order(Ordered.HIGHEST_PRECEDENCE)
|
||||
public SentinelFallbackHandler sentinelGatewayExceptionHandler()
|
||||
{
|
||||
return new SentinelFallbackHandler();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Order(-1)
|
||||
public GlobalFilter sentinelGatewayFilter()
|
||||
{
|
||||
return new SentinelGatewayFilter();
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
package com.ruoyi.gateway.handler;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.reactive.function.BodyInserters;
|
||||
import org.springframework.web.reactive.function.server.HandlerFunction;
|
||||
import org.springframework.web.reactive.function.server.ServerRequest;
|
||||
import org.springframework.web.reactive.function.server.ServerResponse;
|
||||
import reactor.core.publisher.Mono;
|
||||
import java.util.Optional;
|
||||
import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.GATEWAY_ORIGINAL_REQUEST_URL_ATTR;
|
||||
|
||||
/**
|
||||
* 熔断降级处理
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Component
|
||||
public class HystrixFallbackHandler implements HandlerFunction<ServerResponse>
|
||||
{
|
||||
private static final Logger log = LoggerFactory.getLogger(HystrixFallbackHandler.class);
|
||||
|
||||
@Override
|
||||
public Mono<ServerResponse> handle(ServerRequest serverRequest)
|
||||
{
|
||||
Optional<Object> originalUris = serverRequest.attribute(GATEWAY_ORIGINAL_REQUEST_URL_ATTR);
|
||||
originalUris.ifPresent(originalUri -> log.error("网关执行请求:{}失败,hystrix服务降级处理", originalUri));
|
||||
return ServerResponse.status(HttpStatus.INTERNAL_SERVER_ERROR.value()).contentType(MediaType.APPLICATION_JSON)
|
||||
.body(BodyInserters.fromValue(JSON.toJSONString(R.failed("服务已被降级熔断"))));
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package com.ruoyi.gateway.handler;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import com.alibaba.csp.sentinel.adapter.gateway.sc.callback.GatewayCallbackManager;
|
||||
import com.alibaba.csp.sentinel.slots.block.BlockException;
|
||||
import org.springframework.core.io.buffer.DataBuffer;
|
||||
import org.springframework.http.server.reactive.ServerHttpResponse;
|
||||
import org.springframework.web.reactive.function.server.ServerResponse;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
import org.springframework.web.server.WebExceptionHandler;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
/**
|
||||
* 自定义限流异常处理
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class SentinelFallbackHandler implements WebExceptionHandler
|
||||
{
|
||||
private Mono<Void> writeResponse(ServerResponse response, ServerWebExchange exchange)
|
||||
{
|
||||
ServerHttpResponse serverHttpResponse = exchange.getResponse();
|
||||
serverHttpResponse.getHeaders().add("Content-Type", "application/json;charset=UTF-8");
|
||||
byte[] datas = "{\"status\":429,\"message\":\"请求超过最大数,请稍后再试\"}".getBytes(StandardCharsets.UTF_8);
|
||||
DataBuffer buffer = serverHttpResponse.bufferFactory().wrap(datas);
|
||||
return serverHttpResponse.writeWith(Mono.just(buffer));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Void> handle(ServerWebExchange exchange, Throwable ex)
|
||||
{
|
||||
if (exchange.getResponse().isCommitted())
|
||||
{
|
||||
return Mono.error(ex);
|
||||
}
|
||||
if (!BlockException.isBlockException(ex))
|
||||
{
|
||||
return Mono.error(ex);
|
||||
}
|
||||
return handleBlockedRequest(exchange, ex).flatMap(response -> writeResponse(response, exchange));
|
||||
}
|
||||
|
||||
private Mono<ServerResponse> handleBlockedRequest(ServerWebExchange exchange, Throwable throwable)
|
||||
{
|
||||
return GatewayCallbackManager.getBlockHandler().handleRequest(exchange, throwable);
|
||||
}
|
||||
}
|
@ -0,0 +1,94 @@
|
||||
package com.ruoyi.system.controller;
|
||||
|
||||
import java.util.List;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.ruoyi.common.core.utils.StringUtils;
|
||||
import com.ruoyi.common.core.web.controller.BaseController;
|
||||
import com.ruoyi.common.core.web.domain.AjaxResult;
|
||||
import com.ruoyi.common.core.web.page.TableDataInfo;
|
||||
import com.ruoyi.common.log.annotation.Log;
|
||||
import com.ruoyi.common.log.enums.BusinessType;
|
||||
import com.ruoyi.system.domain.SysClientDetails;
|
||||
import com.ruoyi.system.service.ISysClientDetailsService;
|
||||
|
||||
/**
|
||||
* 终端配置 信息操作处理
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/client")
|
||||
public class SysClientDetailsController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private ISysClientDetailsService sysClientDetailsService;
|
||||
|
||||
/**
|
||||
* 查询终端配置列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('system:client:list')")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(SysClientDetails sysClientDetails)
|
||||
{
|
||||
startPage();
|
||||
List<SysClientDetails> list = sysClientDetailsService.selectSysClientDetailsList(sysClientDetails);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取终端配置详细信息
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('system:client:query')")
|
||||
@GetMapping(value = "/{clientId}")
|
||||
public AjaxResult getInfo(@PathVariable("clientId") String clientId)
|
||||
{
|
||||
return AjaxResult.success(sysClientDetailsService.selectSysClientDetailsById(clientId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增终端配置
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('system:client:add')")
|
||||
@Log(title = "终端配置", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody SysClientDetails sysClientDetails)
|
||||
{
|
||||
String clientId = sysClientDetails.getClientId();
|
||||
if (StringUtils.isNotNull(sysClientDetailsService.selectSysClientDetailsById(clientId)))
|
||||
{
|
||||
return AjaxResult.error("新增终端'" + clientId + "'失败,编号已存在");
|
||||
}
|
||||
return toAjax(sysClientDetailsService.insertSysClientDetails(sysClientDetails));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改终端配置
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('system:client:edit')")
|
||||
@Log(title = "终端配置", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody SysClientDetails sysClientDetails)
|
||||
{
|
||||
return toAjax(sysClientDetailsService.updateSysClientDetails(sysClientDetails));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除终端配置
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('system:client:remove')")
|
||||
@Log(title = "终端配置", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{clientIds}")
|
||||
public AjaxResult remove(@PathVariable String[] clientIds)
|
||||
{
|
||||
return toAjax(sysClientDetailsService.deleteSysClientDetailsByIds(clientIds));
|
||||
}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
package com.ruoyi.system.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.system.domain.SysClientDetails;
|
||||
|
||||
/**
|
||||
* 终端配置Mapper接口
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public interface SysClientDetailsMapper
|
||||
{
|
||||
/**
|
||||
* 查询终端配置
|
||||
*
|
||||
* @param clientId 终端配置ID
|
||||
* @return 终端配置
|
||||
*/
|
||||
public SysClientDetails selectSysClientDetailsById(String clientId);
|
||||
|
||||
/**
|
||||
* 查询终端配置列表
|
||||
*
|
||||
* @param sysClientDetails 终端配置
|
||||
* @return 终端配置集合
|
||||
*/
|
||||
public List<SysClientDetails> selectSysClientDetailsList(SysClientDetails sysClientDetails);
|
||||
|
||||
/**
|
||||
* 新增终端配置
|
||||
*
|
||||
* @param sysClientDetails 终端配置
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertSysClientDetails(SysClientDetails sysClientDetails);
|
||||
|
||||
/**
|
||||
* 修改终端配置
|
||||
*
|
||||
* @param sysClientDetails 终端配置
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateSysClientDetails(SysClientDetails sysClientDetails);
|
||||
|
||||
/**
|
||||
* 删除终端配置
|
||||
*
|
||||
* @param clientId 终端配置ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteSysClientDetailsById(String clientId);
|
||||
|
||||
/**
|
||||
* 批量删除终端配置
|
||||
*
|
||||
* @param clientIds 需要删除的数据ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteSysClientDetailsByIds(String[] clientIds);
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
package com.ruoyi.system.service;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.system.domain.SysClientDetails;
|
||||
|
||||
/**
|
||||
* 终端配置Service接口
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public interface ISysClientDetailsService
|
||||
{
|
||||
/**
|
||||
* 查询终端配置
|
||||
*
|
||||
* @param clientId 终端配置ID
|
||||
* @return 终端配置
|
||||
*/
|
||||
public SysClientDetails selectSysClientDetailsById(String clientId);
|
||||
|
||||
/**
|
||||
* 查询终端配置列表
|
||||
*
|
||||
* @param sysClientDetails 终端配置
|
||||
* @return 终端配置集合
|
||||
*/
|
||||
public List<SysClientDetails> selectSysClientDetailsList(SysClientDetails sysClientDetails);
|
||||
|
||||
/**
|
||||
* 新增终端配置
|
||||
*
|
||||
* @param sysClientDetails 终端配置
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertSysClientDetails(SysClientDetails sysClientDetails);
|
||||
|
||||
/**
|
||||
* 修改终端配置
|
||||
*
|
||||
* @param sysClientDetails 终端配置
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateSysClientDetails(SysClientDetails sysClientDetails);
|
||||
|
||||
/**
|
||||
* 批量删除终端配置
|
||||
*
|
||||
* @param clientIds 需要删除的终端配置ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteSysClientDetailsByIds(String[] clientIds);
|
||||
|
||||
/**
|
||||
* 删除终端配置信息
|
||||
*
|
||||
* @param clientId 终端配置ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteSysClientDetailsById(String clientId);
|
||||
}
|
@ -0,0 +1,92 @@
|
||||
package com.ruoyi.system.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.ruoyi.system.mapper.SysClientDetailsMapper;
|
||||
import com.ruoyi.system.domain.SysClientDetails;
|
||||
import com.ruoyi.system.service.ISysClientDetailsService;
|
||||
|
||||
/**
|
||||
* 终端配置Service业务层处理
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Service
|
||||
public class SysClientDetailsServiceImpl implements ISysClientDetailsService
|
||||
{
|
||||
@Autowired
|
||||
private SysClientDetailsMapper sysClientDetailsMapper;
|
||||
|
||||
/**
|
||||
* 查询终端配置
|
||||
*
|
||||
* @param clientId 终端配置ID
|
||||
* @return 终端配置
|
||||
*/
|
||||
@Override
|
||||
public SysClientDetails selectSysClientDetailsById(String clientId)
|
||||
{
|
||||
return sysClientDetailsMapper.selectSysClientDetailsById(clientId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询终端配置列表
|
||||
*
|
||||
* @param sysClientDetails 终端配置
|
||||
* @return 终端配置
|
||||
*/
|
||||
@Override
|
||||
public List<SysClientDetails> selectSysClientDetailsList(SysClientDetails sysClientDetails)
|
||||
{
|
||||
return sysClientDetailsMapper.selectSysClientDetailsList(sysClientDetails);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增终端配置
|
||||
*
|
||||
* @param sysClientDetails 终端配置
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertSysClientDetails(SysClientDetails sysClientDetails)
|
||||
{
|
||||
return sysClientDetailsMapper.insertSysClientDetails(sysClientDetails);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改终端配置
|
||||
*
|
||||
* @param sysClientDetails 终端配置
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateSysClientDetails(SysClientDetails sysClientDetails)
|
||||
{
|
||||
return sysClientDetailsMapper.updateSysClientDetails(sysClientDetails);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除终端配置
|
||||
*
|
||||
* @param clientIds 需要删除的终端配置ID
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteSysClientDetailsByIds(String[] clientIds)
|
||||
{
|
||||
return sysClientDetailsMapper.deleteSysClientDetailsByIds(clientIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除终端配置信息
|
||||
*
|
||||
* @param clientId 终端配置ID
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteSysClientDetailsById(String clientId)
|
||||
{
|
||||
return sysClientDetailsMapper.deleteSysClientDetailsById(clientId);
|
||||
}
|
||||
}
|
@ -0,0 +1,95 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.ruoyi.system.mapper.SysClientDetailsMapper">
|
||||
|
||||
<resultMap type="SysClientDetails" id="SysClientDetailsResult">
|
||||
<result property="clientId" column="client_id" />
|
||||
<result property="resourceIds" column="resource_ids" />
|
||||
<result property="clientSecret" column="client_secret" />
|
||||
<result property="scope" column="scope" />
|
||||
<result property="authorizedGrantTypes" column="authorized_grant_types" />
|
||||
<result property="webServerRedirectUri" column="web_server_redirect_uri" />
|
||||
<result property="authorities" column="authorities" />
|
||||
<result property="accessTokenValidity" column="access_token_validity" />
|
||||
<result property="refreshTokenValidity" column="refresh_token_validity" />
|
||||
<result property="additionalInformation" column="additional_information" />
|
||||
<result property="autoapprove" column="autoapprove" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectSysClientDetailsVo">
|
||||
select client_id, resource_ids, client_secret, scope, authorized_grant_types, web_server_redirect_uri, authorities, access_token_validity, refresh_token_validity, additional_information, autoapprove from sys_oauth_client_details
|
||||
</sql>
|
||||
|
||||
<select id="selectSysClientDetailsList" parameterType="SysClientDetails" resultMap="SysClientDetailsResult">
|
||||
<include refid="selectSysClientDetailsVo"/>
|
||||
<where>
|
||||
<if test="clientId != null and clientId != ''"> and client_id = #{clientId}</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectSysClientDetailsById" parameterType="String" resultMap="SysClientDetailsResult">
|
||||
<include refid="selectSysClientDetailsVo"/>
|
||||
where client_id = #{clientId}
|
||||
</select>
|
||||
|
||||
<insert id="insertSysClientDetails" parameterType="SysClientDetails">
|
||||
insert into sys_oauth_client_details
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="clientId != null">client_id,</if>
|
||||
<if test="resourceIds != null">resource_ids,</if>
|
||||
<if test="clientSecret != null">client_secret,</if>
|
||||
<if test="scope != null">scope,</if>
|
||||
<if test="authorizedGrantTypes != null">authorized_grant_types,</if>
|
||||
<if test="webServerRedirectUri != null">web_server_redirect_uri,</if>
|
||||
<if test="authorities != null">authorities,</if>
|
||||
<if test="accessTokenValidity != null">access_token_validity,</if>
|
||||
<if test="refreshTokenValidity != null">refresh_token_validity,</if>
|
||||
<if test="additionalInformation != null">additional_information,</if>
|
||||
<if test="autoapprove != null">autoapprove,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="clientId != null">#{clientId},</if>
|
||||
<if test="resourceIds != null">#{resourceIds},</if>
|
||||
<if test="clientSecret != null">#{clientSecret},</if>
|
||||
<if test="scope != null">#{scope},</if>
|
||||
<if test="authorizedGrantTypes != null">#{authorizedGrantTypes},</if>
|
||||
<if test="webServerRedirectUri != null">#{webServerRedirectUri},</if>
|
||||
<if test="authorities != null">#{authorities},</if>
|
||||
<if test="accessTokenValidity != null">#{accessTokenValidity},</if>
|
||||
<if test="refreshTokenValidity != null">#{refreshTokenValidity},</if>
|
||||
<if test="additionalInformation != null">#{additionalInformation},</if>
|
||||
<if test="autoapprove != null ">#{autoapprove},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="updateSysClientDetails" parameterType="SysClientDetails">
|
||||
update sys_oauth_client_details
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
<if test="resourceIds != null">resource_ids = #{resourceIds},</if>
|
||||
<if test="clientSecret != null">client_secret = #{clientSecret},</if>
|
||||
<if test="scope != null">scope = #{scope},</if>
|
||||
<if test="authorizedGrantTypes != null">authorized_grant_types = #{authorizedGrantTypes},</if>
|
||||
<if test="webServerRedirectUri != null">web_server_redirect_uri = #{webServerRedirectUri},</if>
|
||||
<if test="authorities != null">authorities = #{authorities},</if>
|
||||
<if test="accessTokenValidity != null">access_token_validity = #{accessTokenValidity},</if>
|
||||
<if test="refreshTokenValidity != null">refresh_token_validity = #{refreshTokenValidity},</if>
|
||||
<if test="additionalInformation != null">additional_information = #{additionalInformation},</if>
|
||||
<if test="autoapprove != null">autoapprove = #{autoapprove},</if>
|
||||
</trim>
|
||||
where client_id = #{clientId}
|
||||
</update>
|
||||
|
||||
<delete id="deleteSysClientDetailsById" parameterType="String">
|
||||
delete from sys_oauth_client_details where client_id = #{clientId}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteSysClientDetailsByIds" parameterType="String">
|
||||
delete from sys_oauth_client_details where client_id in
|
||||
<foreach item="clientId" collection="array" open="(" separator="," close=")">
|
||||
#{clientId}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
</mapper>
|
@ -0,0 +1,44 @@
|
||||
import request from '@/utils/request'
|
||||
|
||||
// 查询终端配置列表
|
||||
export function listClient(query) {
|
||||
return request({
|
||||
url: '/system/client/list',
|
||||
method: 'get',
|
||||
params: query
|
||||
})
|
||||
}
|
||||
|
||||
// 查询终端配置详细
|
||||
export function getClient(clientId) {
|
||||
return request({
|
||||
url: '/system/client/' + clientId,
|
||||
method: 'get'
|
||||
})
|
||||
}
|
||||
|
||||
// 新增终端配置
|
||||
export function addClient(data) {
|
||||
return request({
|
||||
url: '/system/client',
|
||||
method: 'post',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
|
||||
// 修改终端配置
|
||||
export function updateClient(data) {
|
||||
return request({
|
||||
url: '/system/client',
|
||||
method: 'put',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
|
||||
// 删除终端配置
|
||||
export function delClient(clientId) {
|
||||
return request({
|
||||
url: '/system/client/' + clientId,
|
||||
method: 'delete'
|
||||
})
|
||||
}
|
After Width: | Height: | Size: 2.2 KiB |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 2.7 KiB |
@ -0,0 +1,271 @@
|
||||
<template>
|
||||
<div class="app-container">
|
||||
<el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
|
||||
<el-form-item label="终端编号" prop="clientId">
|
||||
<el-input
|
||||
v-model="queryParams.clientId"
|
||||
placeholder="终端编号"
|
||||
clearable
|
||||
size="small"
|
||||
@keyup.enter.native="handleQuery"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
|
||||
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<el-row :gutter="10" class="mb8">
|
||||
<el-col :span="1.5">
|
||||
<el-button
|
||||
type="primary"
|
||||
icon="el-icon-plus"
|
||||
size="mini"
|
||||
@click="handleAdd"
|
||||
v-hasPermi="['system:client:add']"
|
||||
>新增</el-button>
|
||||
</el-col>
|
||||
<el-col :span="1.5">
|
||||
<el-button
|
||||
type="success"
|
||||
icon="el-icon-edit"
|
||||
size="mini"
|
||||
:disabled="single"
|
||||
@click="handleUpdate"
|
||||
v-hasPermi="['system:client:edit']"
|
||||
>修改</el-button>
|
||||
</el-col>
|
||||
<el-col :span="1.5">
|
||||
<el-button
|
||||
type="danger"
|
||||
icon="el-icon-delete"
|
||||
size="mini"
|
||||
:disabled="multiple"
|
||||
@click="handleDelete"
|
||||
v-hasPermi="['system:client:remove']"
|
||||
>删除</el-button>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-table v-loading="loading" :data="clientList" @selection-change="handleSelectionChange">
|
||||
<el-table-column type="selection" width="55" align="center" />
|
||||
<el-table-column label="编号" align="center" prop="clientId" />
|
||||
<el-table-column label="安全码" align="center" prop="clientSecret" :show-overflow-tooltip="true" />
|
||||
<el-table-column label="授权范围" align="center" prop="scope" />
|
||||
<el-table-column label="授权类型" align="center" prop="authorizedGrantTypes" :show-overflow-tooltip="true" />
|
||||
<el-table-column label="令牌时效" align="center" prop="accessTokenValidity" />
|
||||
<el-table-column label="刷新时效" align="center" prop="refreshTokenValidity" />
|
||||
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
||||
<template slot-scope="scope">
|
||||
<el-button
|
||||
size="mini"
|
||||
type="text"
|
||||
icon="el-icon-edit"
|
||||
@click="handleUpdate(scope.row)"
|
||||
v-hasPermi="['system:client:edit']"
|
||||
>修改</el-button>
|
||||
<el-button
|
||||
size="mini"
|
||||
type="text"
|
||||
icon="el-icon-delete"
|
||||
@click="handleDelete(scope.row)"
|
||||
v-hasPermi="['system:client:remove']"
|
||||
>删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<pagination
|
||||
v-show="total>0"
|
||||
:total="total"
|
||||
:page.sync="queryParams.pageNum"
|
||||
:limit.sync="queryParams.pageSize"
|
||||
@pagination="getList"
|
||||
/>
|
||||
|
||||
<!-- 添加或修改终端对话框 -->
|
||||
<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
|
||||
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
|
||||
<el-form-item label="编号" prop="clientId">
|
||||
<el-input v-model="form.clientId" placeholder="请输入编号" :disabled="!isAdd" />
|
||||
</el-form-item>
|
||||
<el-form-item label="安全码" prop="clientSecret">
|
||||
<el-input v-model="form.clientSecret" placeholder="请输入安全码" />
|
||||
</el-form-item>
|
||||
<el-form-item label="授权范围" prop="scope">
|
||||
<el-input v-model="form.scope" placeholder="请输入授权范围" />
|
||||
</el-form-item>
|
||||
<el-form-item label="授权类型" prop="authorizedGrantTypes">
|
||||
<el-input v-model="form.authorizedGrantTypes" placeholder="请输入授权类型" />
|
||||
</el-form-item>
|
||||
<el-form-item label="令牌时效" prop="accessTokenValidity">
|
||||
<el-input-number v-model="form.accessTokenValidity" controls-position="right" :min="0" />
|
||||
</el-form-item>
|
||||
<el-form-item label="刷新时效" prop="refreshTokenValidity">
|
||||
<el-input-number v-model="form.refreshTokenValidity" controls-position="right" :min="0" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<div slot="footer" class="dialog-footer">
|
||||
<el-button type="primary" @click="submitForm">确 定</el-button>
|
||||
<el-button @click="cancel">取 消</el-button>
|
||||
</div>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { listClient, getClient, delClient, addClient, updateClient } from "@/api/system/client";
|
||||
|
||||
export default {
|
||||
name: "Client",
|
||||
data() {
|
||||
return {
|
||||
// 遮罩层
|
||||
loading: true,
|
||||
// 选中数组
|
||||
ids: [],
|
||||
// 非单个禁用
|
||||
single: true,
|
||||
// 非多个禁用
|
||||
multiple: true,
|
||||
// 总条数
|
||||
total: 0,
|
||||
// 终端表格数据
|
||||
clientList: [],
|
||||
// 弹出层标题
|
||||
title: "",
|
||||
// 是否显示弹出层
|
||||
open: false,
|
||||
// 查询参数
|
||||
queryParams: {
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
clientId: undefined
|
||||
},
|
||||
// 是否新增
|
||||
isAdd: false,
|
||||
// 表单参数
|
||||
form: {},
|
||||
// 表单校验
|
||||
rules: {
|
||||
clientId: [
|
||||
{ required: true, message: "编号不能为空", trigger: "blur" }
|
||||
],
|
||||
clientSecret: [
|
||||
{ required: true, message: "安全码不能为空", trigger: "blur" }
|
||||
],
|
||||
scope: [
|
||||
{ required: true, message: "授权范围不能为空", trigger: "blur" }
|
||||
],
|
||||
authorizedGrantTypes: [
|
||||
{ required: true, message: "授权类型不能为空", trigger: "blur" }
|
||||
]
|
||||
}
|
||||
};
|
||||
},
|
||||
created() {
|
||||
this.getList();
|
||||
},
|
||||
methods: {
|
||||
/** 查询终端列表 */
|
||||
getList() {
|
||||
this.loading = true;
|
||||
listClient(this.queryParams).then(response => {
|
||||
this.clientList = response.rows;
|
||||
this.total = response.total;
|
||||
this.loading = false;
|
||||
});
|
||||
},
|
||||
// 取消按钮
|
||||
cancel() {
|
||||
this.open = false;
|
||||
this.reset();
|
||||
},
|
||||
// 表单重置
|
||||
reset() {
|
||||
this.form = {
|
||||
clientId: undefined,
|
||||
clientSecret: undefined,
|
||||
scope: "server",
|
||||
authorizedGrantTypes: "password,refresh_token",
|
||||
accessTokenValidity: 3600,
|
||||
refreshTokenValidity: 7200
|
||||
};
|
||||
this.resetForm("form");
|
||||
},
|
||||
/** 搜索按钮操作 */
|
||||
handleQuery() {
|
||||
this.queryParams.pageNum = 1;
|
||||
this.getList();
|
||||
},
|
||||
/** 重置按钮操作 */
|
||||
resetQuery() {
|
||||
this.resetForm("queryForm");
|
||||
this.handleQuery();
|
||||
},
|
||||
// 多选框选中数据
|
||||
handleSelectionChange(selection) {
|
||||
this.ids = selection.map(item => item.clientId);
|
||||
this.single = selection.length != 1;
|
||||
this.multiple = !selection.length;
|
||||
},
|
||||
/** 新增按钮操作 */
|
||||
handleAdd() {
|
||||
this.reset();
|
||||
this.open = true;
|
||||
this.isAdd = true;
|
||||
this.title = "添加终端";
|
||||
},
|
||||
/** 修改按钮操作 */
|
||||
handleUpdate(row) {
|
||||
this.reset();
|
||||
this.isAdd = false;
|
||||
const clientId = row.clientId || this.ids;
|
||||
getClient(clientId).then(response => {
|
||||
this.form = response.data;
|
||||
this.open = true;
|
||||
this.title = "修改终端";
|
||||
});
|
||||
},
|
||||
/** 提交按钮 */
|
||||
submitForm: function() {
|
||||
this.$refs["form"].validate(valid => {
|
||||
if (valid) {
|
||||
if (!this.isAdd && this.form.clientId != undefined) {
|
||||
updateClient(this.form).then(response => {
|
||||
if (response.code === 200) {
|
||||
this.msgSuccess("修改成功");
|
||||
this.open = false;
|
||||
this.getList();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
addClient(this.form).then(response => {
|
||||
if (response.code === 200) {
|
||||
this.msgSuccess("新增成功");
|
||||
this.open = false;
|
||||
this.getList();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
/** 删除按钮操作 */
|
||||
handleDelete(row) {
|
||||
const clientIds = row.clientId || this.ids;
|
||||
this.$confirm('是否确认删除终端编号为"' + clientIds + '"的数据项?', "警告", {
|
||||
confirmButtonText: "确定",
|
||||
cancelButtonText: "取消",
|
||||
type: "warning"
|
||||
}).then(function() {
|
||||
return delClient(clientIds);
|
||||
}).then(() => {
|
||||
this.getList();
|
||||
this.msgSuccess("删除成功");
|
||||
}).catch(function() {});
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
Loading…
Reference in new issue