result = new R<>();
53 | result.setCode(479);
54 | result.setMsg("演示环境,没有权限操作");
55 |
56 | ctx.setResponseStatusCode(479);
57 | ctx.setSendZuulResponse(false);
58 | ctx.getResponse().setContentType("application/json;charset=UTF-8");
59 | ctx.setResponseBody(JSONObject.toJSONString(result));
60 | return null;
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/xll-gateway/src/main/java/com/xll/upms/gateway/component/filter/XssSecurityFilter.java:
--------------------------------------------------------------------------------
1 | package com.xll.upms.gateway.component.filter;
2 |
3 | import com.xll.upms.common.bean.xss.XssHttpServletRequestWrapper;
4 | import lombok.extern.slf4j.Slf4j;
5 | import org.springframework.stereotype.Component;
6 | import org.springframework.web.filter.OncePerRequestFilter;
7 |
8 | import javax.servlet.FilterChain;
9 | import javax.servlet.ServletException;
10 | import javax.servlet.http.HttpServletRequest;
11 | import javax.servlet.http.HttpServletResponse;
12 | import java.io.IOException;
13 |
14 | /**
15 | * @Author 徐亮亮
16 | * @Description: XSS 过滤
17 | * @Date 2019/1/18 21:12
18 | */
19 | @Slf4j
20 | @Component
21 | public class XssSecurityFilter extends OncePerRequestFilter {
22 |
23 | /**
24 | * Same contract as for {@code doFilter}, but guaranteed to be
25 | * just invoked once per request within a single request thread.
26 | * See {@link #shouldNotFilterAsyncDispatch()} for details.
27 | * Provides HttpServletRequest and HttpServletResponse arguments instead of the
28 | * default ServletRequest and ServletResponse ones.
29 | *
30 | * @param request
31 | * @param response
32 | * @param filterChain
33 | */
34 | @Override
35 | protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
36 | XssHttpServletRequestWrapper xssRequest = new XssHttpServletRequestWrapper(request);
37 | filterChain.doFilter(xssRequest, response);
38 | }
39 | }
--------------------------------------------------------------------------------
/xll-gateway/src/main/java/com/xll/upms/gateway/component/handler/MetadataCanaryRuleHandler.java:
--------------------------------------------------------------------------------
1 | package com.xll.upms.gateway.component.handler;
2 |
3 | /**
4 | * @author lengleng
5 | * @date 2018/10/19
6 | */
7 |
8 | import com.xll.upms.common.constant.SecurityConstants;
9 | import com.xll.upms.gateway.util.RibbonVersionHolder;
10 | import com.netflix.loadbalancer.AbstractServerPredicate;
11 | import com.netflix.loadbalancer.PredicateKey;
12 | import com.netflix.loadbalancer.ZoneAvoidanceRule;
13 | import com.netflix.niws.loadbalancer.DiscoveryEnabledServer;
14 | import com.xiaoleilu.hutool.util.StrUtil;
15 | import lombok.extern.slf4j.Slf4j;
16 |
17 | import java.util.Map;
18 |
19 | /**
20 | * @author lengleng
21 | * @date 2018/10/16
22 | *
23 | *
24 | *
25 | *
26 | */
27 | /**
28 | * @Author 徐亮亮
29 | * @Description: 路由微服务断言
30 | * 1. eureka metadata 存在版本定义时候进行判断
31 | * 2. 不存在 metadata 直接返回true
32 | * @Date 2019/1/18 21:12
33 | */
34 | @Slf4j
35 | public class MetadataCanaryRuleHandler extends ZoneAvoidanceRule {
36 |
37 | @Override
38 | public AbstractServerPredicate getPredicate() {
39 | return new AbstractServerPredicate() {
40 | @Override
41 | public boolean apply(PredicateKey predicateKey) {
42 | String targetVersion = RibbonVersionHolder.getContext();
43 | RibbonVersionHolder.clearContext();
44 | if (StrUtil.isBlank(targetVersion)) {
45 | log.debug("客户端未配置目标版本直接路由");
46 | return true;
47 | }
48 |
49 | DiscoveryEnabledServer server = (DiscoveryEnabledServer) predicateKey.getServer();
50 | final Map metadata = server.getInstanceInfo().getMetadata();
51 | if (StrUtil.isBlank(metadata.get(SecurityConstants.VERSION))) {
52 | log.debug("当前微服务{} 未配置版本直接路由");
53 | return true;
54 | }
55 |
56 | if (metadata.get(SecurityConstants.VERSION).equals(targetVersion)) {
57 | return true;
58 | } else {
59 | log.debug("当前微服务{} 版本为{},目标版本{} 匹配失败", server.getInstanceInfo().getAppName()
60 | , metadata.get(SecurityConstants.VERSION), targetVersion);
61 | return false;
62 | }
63 | }
64 | };
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/xll-gateway/src/main/java/com/xll/upms/gateway/component/handler/PigAccessDeniedHandler.java:
--------------------------------------------------------------------------------
1 | package com.xll.upms.gateway.component.handler;
2 |
3 | import com.fasterxml.jackson.databind.ObjectMapper;
4 | import com.xll.upms.common.constant.CommonConstant;
5 | import com.xll.upms.common.util.R;
6 | import com.xll.upms.common.util.exception.PigDeniedException;
7 | import lombok.extern.slf4j.Slf4j;
8 | import org.apache.http.HttpStatus;
9 | import org.springframework.beans.factory.annotation.Autowired;
10 | import org.springframework.security.access.AccessDeniedException;
11 | import org.springframework.security.oauth2.provider.error.OAuth2AccessDeniedHandler;
12 | import org.springframework.stereotype.Component;
13 |
14 | import javax.servlet.ServletException;
15 | import javax.servlet.http.HttpServletRequest;
16 | import javax.servlet.http.HttpServletResponse;
17 | import java.io.IOException;
18 | import java.io.PrintWriter;
19 |
20 | /**
21 | * @Author 徐亮亮
22 | * @Description: 授权拒绝处理器,覆盖默认的OAuth2AccessDeniedHandler
23 | * 包装失败信息到PigDeniedException
24 | * @Date 2019/1/18 21:13
25 | */
26 | @Slf4j
27 | @Component
28 | public class PigAccessDeniedHandler extends OAuth2AccessDeniedHandler {
29 | @Autowired
30 | private ObjectMapper objectMapper;
31 |
32 | /**
33 | * 授权拒绝处理,使用R包装
34 | *
35 | * @param request request
36 | * @param response response
37 | * @param authException authException
38 | * @throws IOException IOException
39 | * @throws ServletException ServletException
40 | */
41 | @Override
42 | public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException authException) throws IOException, ServletException {
43 | log.info("授权失败,禁止访问 {}", request.getRequestURI());
44 | response.setCharacterEncoding(CommonConstant.UTF8);
45 | response.setContentType(CommonConstant.CONTENT_TYPE);
46 | R result = new R<>(new PigDeniedException("授权失败,禁止访问"));
47 | response.setStatus(HttpStatus.SC_FORBIDDEN);
48 | PrintWriter printWriter = response.getWriter();
49 | printWriter.append(objectMapper.writeValueAsString(result));
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/xll-gateway/src/main/java/com/xll/upms/gateway/component/handler/ZuulRateLimiterErrorHandler.java:
--------------------------------------------------------------------------------
1 | package com.xll.upms.gateway.component.handler;
2 |
3 | import com.marcosbarbero.cloud.autoconfigure.zuul.ratelimit.config.repository.DefaultRateLimiterErrorHandler;
4 | import com.marcosbarbero.cloud.autoconfigure.zuul.ratelimit.config.repository.RateLimiterErrorHandler;
5 | import lombok.extern.slf4j.Slf4j;
6 | import org.springframework.context.annotation.Bean;
7 | import org.springframework.context.annotation.Configuration;
8 |
9 | /**
10 | * @Author 徐亮亮
11 | * @Description:限流降级处理
12 | * @Date 2019/1/18 21:13
13 | */
14 | @Slf4j
15 | @Configuration
16 | public class ZuulRateLimiterErrorHandler {
17 |
18 | @Bean
19 | public RateLimiterErrorHandler rateLimitErrorHandler() {
20 | return new DefaultRateLimiterErrorHandler() {
21 | @Override
22 | public void handleSaveError(String key, Exception e) {
23 | log.error("保存key:[{}]异常", key, e);
24 | }
25 |
26 | @Override
27 | public void handleFetchError(String key, Exception e) {
28 | log.error("路由失败:[{}]异常", key);
29 | }
30 |
31 | @Override
32 | public void handleError(String msg, Exception e) {
33 | log.error("限流异常:[{}]", msg, e);
34 | }
35 | };
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/xll-gateway/src/main/java/com/xll/upms/gateway/component/listener/GroovyLoadInitListener.java:
--------------------------------------------------------------------------------
1 | package com.xll.upms.gateway.component.listener;
2 |
3 | import com.netflix.zuul.FilterFileManager;
4 | import com.netflix.zuul.FilterLoader;
5 | import com.netflix.zuul.groovy.GroovyCompiler;
6 | import com.netflix.zuul.groovy.GroovyFileFilter;
7 | import com.netflix.zuul.monitoring.MonitoringHelper;
8 | import lombok.extern.slf4j.Slf4j;
9 | import org.springframework.beans.factory.annotation.Value;
10 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
11 | import org.springframework.boot.context.embedded.EmbeddedServletContainerInitializedEvent;
12 | import org.springframework.context.event.EventListener;
13 | import org.springframework.stereotype.Component;
14 |
15 | /**
16 | * @Author 徐亮亮
17 | * @Description: 动态filter 初始化配置
18 | * @Date 2019/1/18 21:13
19 | */
20 | @Slf4j
21 | @Component
22 | @ConditionalOnProperty("zuul.groovy.path")
23 | public class GroovyLoadInitListener {
24 | @Value("${zuul.groovy.path}")
25 | private String groovyPath;
26 |
27 | @EventListener(value = {EmbeddedServletContainerInitializedEvent.class})
28 | public void init() {
29 | MonitoringHelper.initMocks();
30 | FilterLoader.getInstance().setCompiler(new GroovyCompiler());
31 | FilterFileManager.setFilenameFilter(new GroovyFileFilter());
32 | try {
33 | FilterFileManager.init(10, groovyPath);
34 | } catch (Exception e) {
35 | log.error("初始化网关Groovy 文件失败 {}", e);
36 | }
37 | log.warn("初始化网关Groovy 文件成功");
38 | }
39 | }
--------------------------------------------------------------------------------
/xll-gateway/src/main/java/com/xll/upms/gateway/feign/MenuService.java:
--------------------------------------------------------------------------------
1 | package com.xll.upms.gateway.feign;
2 |
3 | import com.xll.upms.common.vo.MenuVO;
4 | import com.xll.upms.gateway.feign.fallback.MenuServiceFallbackImpl;
5 | import org.springframework.cloud.netflix.feign.FeignClient;
6 | import org.springframework.web.bind.annotation.GetMapping;
7 | import org.springframework.web.bind.annotation.PathVariable;
8 |
9 | import java.util.Set;
10 |
11 | /**
12 | * @Author 徐亮亮
13 | * @Description: 调度服务upms接口
14 | * @Date 2019/1/18 21:15
15 | */
16 | @FeignClient(name = "xll-upms-service", fallback = MenuServiceFallbackImpl.class)
17 | public interface MenuService {
18 | /**
19 | * 通过角色名查询菜单
20 | *
21 | * @param role 角色名称
22 | * @return 菜单列表
23 | */
24 | @GetMapping(value = "/menu/findMenuByRole/{role}")
25 | Set findMenuByRole(@PathVariable("role") String role);
26 | }
27 |
--------------------------------------------------------------------------------
/xll-gateway/src/main/java/com/xll/upms/gateway/feign/fallback/MenuServiceFallbackImpl.java:
--------------------------------------------------------------------------------
1 | package com.xll.upms.gateway.feign.fallback;
2 |
3 | import com.xll.upms.common.vo.MenuVO;
4 | import com.xll.upms.gateway.feign.MenuService;
5 | import com.xiaoleilu.hutool.collection.CollUtil;
6 | import lombok.extern.slf4j.Slf4j;
7 | import org.springframework.stereotype.Service;
8 |
9 | import java.util.Set;
10 |
11 | /**
12 | * @Author 徐亮亮
13 | * @Description: 按钮业务逻辑回调类
14 | * @Date 2019/1/18 21:14
15 | */
16 | @Slf4j
17 | @Service
18 | public class MenuServiceFallbackImpl implements MenuService {
19 | @Override
20 | public Set findMenuByRole(String role) {
21 | log.error("调用{}异常{}","findMenuByRole",role);
22 | return CollUtil.newHashSet();
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/xll-gateway/src/main/java/com/xll/upms/gateway/service/LogSendService.java:
--------------------------------------------------------------------------------
1 | package com.xll.upms.gateway.service;
2 |
3 | import com.netflix.zuul.context.RequestContext;
4 |
5 | /**
6 | * @Author 徐亮亮
7 | * @Description: 日志发送业务逻辑
8 | * @Date 2019/1/18 21:17
9 | */
10 | public interface LogSendService {
11 | /**
12 | * 往消息通道发消息
13 | *
14 | * @param requestContext requestContext
15 | */
16 | void send(RequestContext requestContext);
17 | }
18 |
--------------------------------------------------------------------------------
/xll-gateway/src/main/java/com/xll/upms/gateway/service/PermissionService.java:
--------------------------------------------------------------------------------
1 | package com.xll.upms.gateway.service;
2 |
3 | import org.springframework.security.core.Authentication;
4 |
5 | import javax.servlet.http.HttpServletRequest;
6 |
7 | /**
8 | * @Author 徐亮亮
9 | * @Description:
10 | * @Date 2019/1/18 21:18
11 | */
12 | public interface PermissionService {
13 | /**
14 | * 判断请求是否有权限
15 | *
16 | * @param request HttpServletRequest
17 | * @param authentication 认证信息
18 | * @return 是否有权限
19 | */
20 | boolean hasPermission(HttpServletRequest request, Authentication authentication);
21 | }
22 |
--------------------------------------------------------------------------------
/xll-gateway/src/main/java/com/xll/upms/gateway/util/RibbonVersionHolder.java:
--------------------------------------------------------------------------------
1 | package com.xll.upms.gateway.util;
2 |
3 | import com.alibaba.ttl.TransmittableThreadLocal;
4 |
5 | /**
6 | * @Author 徐亮亮
7 | * @Description: 负载均衡处理器
8 | * @Date 2019/1/18 21:19
9 | */
10 | public class RibbonVersionHolder {
11 | private static final ThreadLocal context = new TransmittableThreadLocal<>();
12 |
13 |
14 | public static String getContext() {
15 | return context.get();
16 | }
17 |
18 | public static void setContext(String value) {
19 | context.set(value);
20 | }
21 |
22 | public static void clearContext() {
23 | context.remove();
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/xll-gateway/src/main/resources/bootstrap.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | application:
3 | name: pig-gateway
4 | profiles:
5 | active: dev
6 | cloud:
7 | config:
8 | fail-fast: true
9 | discovery:
10 | service-id: pig-config-server
11 | enabled: true
12 | profile: ${spring.profiles.active}
13 | label: master
14 |
15 | logging:
16 | level: error
17 |
18 | ---
19 | spring:
20 | profiles: dev
21 | eureka:
22 | instance:
23 | prefer-ip-address: true
24 | lease-renewal-interval-in-seconds: 5
25 | lease-expiration-duration-in-seconds: 20
26 | client:
27 | serviceUrl:
28 | defaultZone: http://xll:gip6666@localhost:1025/eureka
29 | registry-fetch-interval-seconds: 10
30 | #认证服务器地址
31 | security:
32 | auth:
33 | server: http://localhost:3000
34 | ---
35 | spring:
36 | profiles: prd
37 | eureka:
38 | instance:
39 | prefer-ip-address: true
40 | client:
41 | serviceUrl:
42 | defaultZone: http://xll:gip6666@eureka:1025/eureka
43 |
44 | #建议使用ng负载均衡
45 | security:
46 | auth:
47 | server: http://localhost:3000
48 |
--------------------------------------------------------------------------------
/xll-gateway/src/test/java/com/xll/upms/common/util/UserUtilsTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018-2025, lengleng All rights reserved.
3 | *
4 | * Redistribution and use in source and binary forms, with or without
5 | * modification, are permitted provided that the following conditions are met:
6 | *
7 | * Redistributions of source code must retain the above copyright notice,
8 | * this list of conditions and the following disclaimer.
9 | * Redistributions in binary form must reproduce the above copyright
10 | * notice, this list of conditions and the following disclaimer in the
11 | * documentation and/or other materials provided with the distribution.
12 | * Neither the name of the pig4cloud.com developer nor the names of its
13 | * contributors may be used to endorse or promote products derived from
14 | * this software without specific prior written permission.
15 | * Author: lengleng (wangiegie@gmail.com)
16 | */
17 |
18 | package com.xll.upms.common.util;
19 |
20 | import com.xll.upms.common.constant.CommonConstant;
21 | import org.apache.commons.lang.StringUtils;
22 | import org.junit.Test;
23 |
24 | import java.util.Optional;
25 |
26 | /**
27 | * @author lengleng
28 | * @date 2017/12/22
29 | */
30 | public class UserUtilsTest {
31 | @Test
32 | public void getToken() throws Exception {
33 | String authorization = null;
34 | System.out.println(StringUtils.substringAfter(authorization, CommonConstant.TOKEN_SPLIT));
35 | }
36 |
37 | @Test
38 | public void optionalTest() {
39 | Optional optional = Optional.ofNullable("");
40 | System.out.println(optional.isPresent());
41 | }
42 |
43 | }
--------------------------------------------------------------------------------
/xll-modules/pom.xml:
--------------------------------------------------------------------------------
1 |
17 |
18 |
20 |
21 | xll-upms
22 | com.xll
23 | 1.3.1
24 |
25 | 4.0.0
26 |
27 | com.xll.upms
28 | xll-modules
29 | 1.3.1
30 | pom
31 |
32 | xll-modules
33 | http://maven.apache.org
34 |
35 |
36 | UTF-8
37 |
38 |
39 |
40 | xll-daemon-service
41 | xll-mc-service
42 | xll-sso-client-demo
43 | xll-upms-service
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/xll-modules/xll-daemon-service/src/main/java/com/xll/upms/daemon/UPMSDaemonApplication.java:
--------------------------------------------------------------------------------
1 | package com.xll.upms.daemon;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
6 |
7 | /**
8 | * @Author 徐亮亮
9 | * @Description: 分布式任务调度模块
10 | * @Date 2019/1/18 21:22
11 | */
12 | @EnableDiscoveryClient
13 | @SpringBootApplication
14 | public class UPMSDaemonApplication {
15 |
16 | public static void main(String[] args) {
17 | SpringApplication.run(UPMSDaemonApplication.class, args);
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/xll-modules/xll-daemon-service/src/main/java/com/xll/upms/daemon/job/DemoSimpleJob.java:
--------------------------------------------------------------------------------
1 | package com.xll.upms.daemon.job;
2 |
3 | import com.dangdang.ddframe.job.api.ShardingContext;
4 | import com.dangdang.ddframe.job.api.simple.SimpleJob;
5 | import com.zen.elasticjob.spring.boot.annotation.ElasticJobConfig;
6 | import lombok.extern.slf4j.Slf4j;
7 |
8 | /**
9 | * @Author 徐亮亮
10 | * @Description: 测试Job
11 | * @Date 2019/1/18 21:20
12 | */
13 | @Slf4j
14 | @ElasticJobConfig(cron = "0 0 0/1 * * ?", shardingTotalCount = 3,
15 | shardingItemParameters = "0=pig1,1=pig2,2=pig3",
16 | startedTimeoutMilliseconds = 5000L,
17 | completedTimeoutMilliseconds = 10000L,
18 | eventTraceRdbDataSource = "dataSource")
19 | public class DemoSimpleJob implements SimpleJob {
20 | /**
21 | * 业务执行逻辑
22 | *
23 | * @param shardingContext 分片信息
24 | */
25 | @Override
26 | public void execute(ShardingContext shardingContext) {
27 | log.info("--------------");
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/xll-modules/xll-daemon-service/src/main/java/com/xll/upms/daemon/job/UmpsDataflowJob.java:
--------------------------------------------------------------------------------
1 | package com.xll.upms.daemon.job;
2 |
3 | import com.dangdang.ddframe.job.api.ShardingContext;
4 | import com.dangdang.ddframe.job.api.dataflow.DataflowJob;
5 | import com.zen.elasticjob.spring.boot.annotation.ElasticJobConfig;
6 |
7 | import java.util.List;
8 |
9 | /**
10 | * @Author 徐亮亮
11 | * @Description:数据流任务Job
12 | * @Date 2019/1/18 21:21
13 | */
14 | @ElasticJobConfig(cron = "0 0 0/1 * * ? ", shardingTotalCount = 3, shardingItemParameters = "0=Beijing,1=Shanghai,2=Guangzhou")
15 | public class UmpsDataflowJob implements DataflowJob {
16 |
17 |
18 | @Override
19 | public List fetchData(ShardingContext shardingContext) {
20 | return null;
21 | }
22 |
23 | @Override
24 | public void processData(ShardingContext shardingContext, List list) {
25 |
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/xll-modules/xll-daemon-service/src/main/java/com/xll/upms/daemon/job/UmpsSimpleJob.java:
--------------------------------------------------------------------------------
1 | package com.xll.upms.daemon.job;
2 |
3 | import com.dangdang.ddframe.job.api.ShardingContext;
4 | import com.dangdang.ddframe.job.api.simple.SimpleJob;
5 | import com.zen.elasticjob.spring.boot.annotation.ElasticJobConfig;
6 | import lombok.extern.slf4j.Slf4j;
7 |
8 | /**
9 | * @Author 徐亮亮
10 | * @Description: 简单任务调度
11 | * @Date 2019/1/18 21:21
12 | */
13 | @Slf4j
14 | @ElasticJobConfig(cron = "0 0 0/1 * * ?", shardingTotalCount = 3,
15 | shardingItemParameters = "0=pig1,1=pig2,2=pig3",
16 | startedTimeoutMilliseconds = 5000L,
17 | completedTimeoutMilliseconds = 10000L,
18 | eventTraceRdbDataSource = "dataSource")
19 | public class UmpsSimpleJob implements SimpleJob {
20 | /**
21 | * 业务执行逻辑
22 | *
23 | * @param shardingContext 分片信息
24 | */
25 | @Override
26 | public void execute(ShardingContext shardingContext) {
27 | log.info("shardingContext:{}", shardingContext);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/xll-modules/xll-daemon-service/src/main/resources/bootstrap.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | application:
3 | name: pig-daemon-service
4 | profiles:
5 | active: dev
6 | cloud:
7 | config:
8 | fail-fast: true
9 | discovery:
10 | service-id: pig-config-server
11 | enabled: true
12 | profile: ${spring.profiles.active}
13 | label: master
14 | ---
15 | spring:
16 | profiles: dev
17 | eureka:
18 | instance:
19 | prefer-ip-address: true
20 | lease-renewal-interval-in-seconds: 5
21 | lease-expiration-duration-in-seconds: 20
22 | client:
23 | serviceUrl:
24 | defaultZone: http://xll:gip6666@localhost:1025/eureka
25 | registry-fetch-interval-seconds: 10
26 |
27 | ---
28 | spring:
29 | profiles: prd
30 | eureka:
31 | instance:
32 | prefer-ip-address: true
33 | client:
34 | serviceUrl:
35 | defaultZone: http://xll:gip6666@eureka:1025/eureka
--------------------------------------------------------------------------------
/xll-modules/xll-mc-service/src/main/java/com/xll/upms/mc/UPMSMessageCenterApplication.java:
--------------------------------------------------------------------------------
1 | package com.xll.upms.mc;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
6 |
7 | /**
8 | * @Author 徐亮亮
9 | * @Description: 消息中心
10 | * @Date 2019/1/18 21:25
11 | */
12 | @EnableDiscoveryClient
13 | @SpringBootApplication
14 | public class UPMSMessageCenterApplication {
15 |
16 | public static void main(String[] args) {
17 | SpringApplication.run(UPMSMessageCenterApplication.class, args);
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/xll-modules/xll-mc-service/src/main/java/com/xll/upms/mc/config/DingTalkPropertiesConfig.java:
--------------------------------------------------------------------------------
1 | package com.xll.upms.mc.config;
2 |
3 | import lombok.Data;
4 | import org.springframework.boot.context.properties.ConfigurationProperties;
5 | import org.springframework.context.annotation.Configuration;
6 |
7 | /**
8 | * @Author 徐亮亮
9 | * @Description: 钉钉服务配置
10 | * @Date 2019/1/18 21:22
11 | */
12 | @Data
13 | @Configuration
14 | @ConfigurationProperties(prefix = "sms.dingtalk")
15 | public class DingTalkPropertiesConfig {
16 | /**
17 | * webhook
18 | */
19 | private String webhook;
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/xll-modules/xll-mc-service/src/main/java/com/xll/upms/mc/config/SmsAliyunPropertiesConfig.java:
--------------------------------------------------------------------------------
1 | package com.xll.upms.mc.config;
2 |
3 | import lombok.Data;
4 | import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
5 | import org.springframework.boot.context.properties.ConfigurationProperties;
6 | import org.springframework.context.annotation.Configuration;
7 |
8 | import java.util.Map;
9 |
10 | /**
11 | * @Author 徐亮亮
12 | * @Description: 阿里大鱼短息服务配置
13 | * @Date 2019/1/18 21:23
14 | */
15 | @Data
16 | @Configuration
17 | @ConditionalOnExpression("!'${sms.aliyun}'.isEmpty()")
18 | @ConfigurationProperties(prefix = "sms.aliyun")
19 | public class SmsAliyunPropertiesConfig {
20 | /**
21 | * 应用ID
22 | */
23 | private String accessKey;
24 |
25 | /**
26 | * 应用秘钥
27 | */
28 | private String secretKey;
29 |
30 | /**
31 | * 短信模板配置
32 | */
33 | private Map channels;
34 | }
35 |
--------------------------------------------------------------------------------
/xll-modules/xll-mc-service/src/main/java/com/xll/upms/mc/handler/AbstractMessageHandler.java:
--------------------------------------------------------------------------------
1 | package com.xll.upms.mc.handler;
2 |
3 | import com.xll.upms.common.util.template.MobileMsgTemplate;
4 |
5 | /**
6 | * @Author 徐亮亮
7 | * @Description: 抽象消息处理器
8 | * @Date 2019/1/18 21:23
9 | */
10 | public abstract class AbstractMessageHandler implements SmsMessageHandler {
11 |
12 | /**
13 | * 执行入口
14 | *
15 | * @param mobileMsgTemplate 信息
16 | */
17 | @Override
18 | public void execute(MobileMsgTemplate mobileMsgTemplate) {
19 | check(mobileMsgTemplate);
20 | if (!process(mobileMsgTemplate)) {
21 | fail(mobileMsgTemplate);
22 | }
23 | }
24 |
25 | /**
26 | * 数据校验
27 | *
28 | * @param mobileMsgTemplate 信息
29 | */
30 | @Override
31 | public abstract void check(MobileMsgTemplate mobileMsgTemplate);
32 |
33 | /**
34 | * 业务处理
35 | *
36 | * @param mobileMsgTemplate 信息
37 | * @return boolean
38 | */
39 | @Override
40 | public abstract boolean process(MobileMsgTemplate mobileMsgTemplate);
41 |
42 | /**
43 | * 失败处理
44 | *
45 | * @param mobileMsgTemplate 信息
46 | */
47 | @Override
48 | public abstract void fail(MobileMsgTemplate mobileMsgTemplate);
49 | }
50 |
--------------------------------------------------------------------------------
/xll-modules/xll-mc-service/src/main/java/com/xll/upms/mc/handler/DingTalkMessageHandler.java:
--------------------------------------------------------------------------------
1 | package com.xll.upms.mc.handler;
2 |
3 | import com.alibaba.fastjson.JSONObject;
4 | import com.xll.upms.common.util.template.DingTalkMsgTemplate;
5 | import com.xll.upms.mc.config.DingTalkPropertiesConfig;
6 | import com.xiaoleilu.hutool.http.HttpUtil;
7 | import com.xiaoleilu.hutool.util.StrUtil;
8 | import lombok.extern.slf4j.Slf4j;
9 | import org.springframework.beans.factory.annotation.Autowired;
10 | import org.springframework.stereotype.Component;
11 |
12 | /**
13 | * @Author 徐亮亮
14 | * @Description: 发送钉钉消息逻辑
15 | * @Date 2019/1/18 21:24
16 | */
17 | @Slf4j
18 | @Component
19 | public class DingTalkMessageHandler {
20 | @Autowired
21 | private DingTalkPropertiesConfig dingTalkPropertiesConfig;
22 |
23 | /**
24 | * 业务处理
25 | *
26 | * @param text 消息
27 | */
28 | public boolean process(String text) {
29 | String webhook = dingTalkPropertiesConfig.getWebhook();
30 | if (StrUtil.isBlank(webhook)) {
31 | log.error("钉钉配置错误,webhook为空");
32 | return false;
33 | }
34 |
35 | DingTalkMsgTemplate dingTalkMsgTemplate = new DingTalkMsgTemplate();
36 | dingTalkMsgTemplate.setMsgtype("text");
37 | DingTalkMsgTemplate.TextBean textBean = new DingTalkMsgTemplate.TextBean();
38 | textBean.setContent(text);
39 | dingTalkMsgTemplate.setText(textBean);
40 | String result = HttpUtil.post(webhook, JSONObject.toJSONString(dingTalkMsgTemplate));
41 | log.info("钉钉提醒成功,报文响应:{}", result);
42 | return true;
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/xll-modules/xll-mc-service/src/main/java/com/xll/upms/mc/handler/SmsMessageHandler.java:
--------------------------------------------------------------------------------
1 | package com.xll.upms.mc.handler;
2 |
3 | import com.xll.upms.common.util.template.MobileMsgTemplate;
4 |
5 | /**
6 | * @Author 徐亮亮
7 | * @Description: 消息处理器
8 | * @Date 2019/1/18 21:24
9 | */
10 | public interface SmsMessageHandler {
11 | /**
12 | * 执行入口
13 | *
14 | * @param mobileMsgTemplate 信息
15 | */
16 | void execute(MobileMsgTemplate mobileMsgTemplate);
17 |
18 | /**
19 | * 数据校验
20 | *
21 | * @param mobileMsgTemplate 信息
22 | */
23 | void check(MobileMsgTemplate mobileMsgTemplate);
24 |
25 | /**
26 | * 业务处理
27 | *
28 | * @param mobileMsgTemplate 信息
29 | * @return boolean
30 | */
31 | boolean process(MobileMsgTemplate mobileMsgTemplate);
32 |
33 | /**
34 | * 失败处理
35 | *
36 | * @param mobileMsgTemplate 信息
37 | */
38 | void fail(MobileMsgTemplate mobileMsgTemplate);
39 | }
40 |
--------------------------------------------------------------------------------
/xll-modules/xll-mc-service/src/main/java/com/xll/upms/mc/listener/DingTalkServiceChangeReceiveListener.java:
--------------------------------------------------------------------------------
1 | package com.xll.upms.mc.listener;
2 |
3 | import com.xll.upms.common.constant.MqQueueConstant;
4 | import com.xll.upms.mc.handler.DingTalkMessageHandler;
5 | import lombok.extern.slf4j.Slf4j;
6 | import org.springframework.amqp.rabbit.annotation.RabbitHandler;
7 | import org.springframework.amqp.rabbit.annotation.RabbitListener;
8 | import org.springframework.beans.factory.annotation.Autowired;
9 | import org.springframework.stereotype.Component;
10 |
11 | /**
12 | * @Author 徐亮亮
13 | * @Description: 监听服务状态改变发送请求
14 | * @Date 2019/1/18 21:25
15 | */
16 | @Slf4j
17 | @Component
18 | @RabbitListener(queues = MqQueueConstant.DINGTALK_SERVICE_STATUS_CHANGE)
19 | public class DingTalkServiceChangeReceiveListener {
20 | @Autowired
21 | private DingTalkMessageHandler dingTalkMessageHandler;
22 |
23 | @RabbitHandler
24 | public void receive(String text) {
25 | long startTime = System.currentTimeMillis();
26 | log.info("消息中心接收到钉钉发送请求-> 内容:{} ", text);
27 | dingTalkMessageHandler.process(text);
28 | long useTime = System.currentTimeMillis() - startTime;
29 | log.info("调用 钉钉网关处理完毕,耗时 {}毫秒", useTime);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/xll-modules/xll-mc-service/src/main/java/com/xll/upms/mc/listener/MobileCodeReceiveListener.java:
--------------------------------------------------------------------------------
1 | package com.xll.upms.mc.listener;
2 |
3 | import com.xll.upms.common.constant.MqQueueConstant;
4 | import com.xll.upms.common.util.template.MobileMsgTemplate;
5 | import com.xll.upms.mc.handler.SmsMessageHandler;
6 | import lombok.extern.slf4j.Slf4j;
7 | import org.springframework.amqp.rabbit.annotation.RabbitHandler;
8 | import org.springframework.amqp.rabbit.annotation.RabbitListener;
9 | import org.springframework.beans.factory.annotation.Autowired;
10 | import org.springframework.stereotype.Component;
11 |
12 | import java.util.Map;
13 |
14 | /**
15 | * @Author 徐亮亮
16 | * @Description: 监听短信发送请求
17 | * @Date 2019/1/18 21:25
18 | */
19 | @Slf4j
20 | @Component
21 | @RabbitListener(queues = MqQueueConstant.MOBILE_CODE_QUEUE)
22 | public class MobileCodeReceiveListener {
23 | @Autowired
24 | private Map messageHandlerMap;
25 |
26 | @RabbitHandler
27 | public void receive(MobileMsgTemplate mobileMsgTemplate) {
28 | long startTime = System.currentTimeMillis();
29 | log.info("消息中心接收到短信发送请求-> 手机号:{} -> 验证码: {} ", mobileMsgTemplate.getMobile(), mobileMsgTemplate.getContext());
30 | String channel = mobileMsgTemplate.getChannel();
31 | SmsMessageHandler messageHandler = messageHandlerMap.get(channel);
32 | if (messageHandler == null) {
33 | log.error("没有找到指定的路由通道,不进行发送处理完毕!");
34 | return;
35 | }
36 |
37 | messageHandler.execute(mobileMsgTemplate);
38 | long useTime = System.currentTimeMillis() - startTime;
39 | log.info("调用 {} 短信网关处理完毕,耗时 {}毫秒", channel, useTime);
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/xll-modules/xll-mc-service/src/main/java/com/xll/upms/mc/listener/MobileServiceChangeReceiveListener.java:
--------------------------------------------------------------------------------
1 | package com.xll.upms.mc.listener;
2 |
3 | import com.xll.upms.common.constant.MqQueueConstant;
4 | import com.xll.upms.common.util.template.MobileMsgTemplate;
5 | import com.xll.upms.mc.handler.SmsMessageHandler;
6 | import lombok.extern.slf4j.Slf4j;
7 | import org.springframework.amqp.rabbit.annotation.RabbitHandler;
8 | import org.springframework.amqp.rabbit.annotation.RabbitListener;
9 | import org.springframework.beans.factory.annotation.Autowired;
10 | import org.springframework.stereotype.Component;
11 |
12 | import java.util.Map;
13 |
14 | /**
15 | * @Author 徐亮亮
16 | * @Description: 监听服务状态改变发送请求
17 | * @Date 2019/1/18 21:25
18 | */
19 | @Slf4j
20 | @Component
21 | @RabbitListener(queues = MqQueueConstant.MOBILE_SERVICE_STATUS_CHANGE)
22 | public class MobileServiceChangeReceiveListener {
23 | @Autowired
24 | private Map messageHandlerMap;
25 |
26 |
27 | @RabbitHandler
28 | public void receive(MobileMsgTemplate mobileMsgTemplate) {
29 | long startTime = System.currentTimeMillis();
30 | log.info("消息中心接收到短信发送请求-> 手机号:{} -> 信息体:{} ", mobileMsgTemplate.getMobile(), mobileMsgTemplate.getContext());
31 | String channel = mobileMsgTemplate.getChannel();
32 | SmsMessageHandler messageHandler = messageHandlerMap.get(channel);
33 | if (messageHandler == null) {
34 | log.error("没有找到指定的路由通道,不进行发送处理完毕!");
35 | return;
36 | }
37 |
38 | messageHandler.execute(mobileMsgTemplate);
39 | long useTime = System.currentTimeMillis() - startTime;
40 | log.info("调用 {} 短信网关处理完毕,耗时 {}毫秒", mobileMsgTemplate.getType(), useTime);
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/xll-modules/xll-mc-service/src/main/resources/bootstrap.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | application:
3 | name: pig-mc-service
4 | profiles:
5 | active: dev
6 | cloud:
7 | config:
8 | fail-fast: true
9 | discovery:
10 | service-id: pig-config-server
11 | enabled: true
12 | profile: ${spring.profiles.active}
13 | label: master
14 | ---
15 | spring:
16 | profiles: dev
17 | eureka:
18 | instance:
19 | prefer-ip-address: true
20 | lease-renewal-interval-in-seconds: 5
21 | lease-expiration-duration-in-seconds: 20
22 | client:
23 | serviceUrl:
24 | defaultZone: http://xll:gip6666@localhost:1025/eureka
25 | registry-fetch-interval-seconds: 10
26 |
27 | ---
28 | spring:
29 | profiles: prd
30 | eureka:
31 | instance:
32 | prefer-ip-address: true
33 | client:
34 | serviceUrl:
35 | defaultZone: http://xll:gip6666@eureka:1025/eureka
--------------------------------------------------------------------------------
/xll-modules/xll-sso-client-demo/src/main/java/com/xll/upms/sso/UPMSSsoClientDemoApplication.java:
--------------------------------------------------------------------------------
1 | package com.xll.upms.sso;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.boot.autoconfigure.security.oauth2.client.EnableOAuth2Sso;
6 |
7 | /**
8 | * @Author 徐亮亮
9 | * @Description: 单点登录客户端
10 | * @Date 2019/1/18 21:27
11 | */
12 | @EnableOAuth2Sso
13 | @SpringBootApplication
14 | public class UPMSSsoClientDemoApplication {
15 |
16 | public static void main(String[] args) {
17 | SpringApplication.run(UPMSSsoClientDemoApplication.class, args);
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/xll-modules/xll-sso-client-demo/src/main/java/com/xll/upms/sso/config/ResourceServerConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.xll.upms.sso.config;
2 |
3 | import org.springframework.context.annotation.Configuration;
4 | import org.springframework.security.config.annotation.web.builders.HttpSecurity;
5 | import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
6 | import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
7 |
8 | /**
9 | * @Author 徐亮亮
10 | * @Description: 当前配置 暴露监控信息
11 | * @Date 2019/1/18 21:26
12 | */
13 | @Configuration
14 | @EnableResourceServer
15 | public class ResourceServerConfiguration extends ResourceServerConfigurerAdapter {
16 |
17 | @Override
18 | public void configure(HttpSecurity http) throws Exception {
19 | http
20 | .authorizeRequests()
21 | .anyRequest().authenticated()
22 | .and()
23 | .csrf().disable();
24 | }
25 |
26 | }
--------------------------------------------------------------------------------
/xll-modules/xll-sso-client-demo/src/main/java/com/xll/upms/sso/controller/DemoController.java:
--------------------------------------------------------------------------------
1 | package com.xll.upms.sso.controller;
2 |
3 | import org.springframework.security.core.Authentication;
4 | import org.springframework.web.bind.annotation.GetMapping;
5 | import org.springframework.web.bind.annotation.RestController;
6 |
7 | /**
8 | * @Author 徐亮亮
9 | * @Description: 测试
10 | * @Date 2019/1/18 21:26
11 | */
12 | @RestController
13 | public class DemoController {
14 | @GetMapping("/")
15 | public Authentication user(Authentication authentication) {
16 | return authentication;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/xll-modules/xll-sso-client-demo/src/main/resources/bootstrap.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 4040
3 | context-path: /sso1
4 |
5 | #监控短点配置
6 | management:
7 | security:
8 | enabled: false
9 | endpoints:
10 | actuator:
11 | enabled: true
12 | shutdown:
13 | enabled: false
14 |
15 | security:
16 | oauth2:
17 | client:
18 | client-id: pig
19 | client-secret: pig
20 | user-authorization-uri: http://localhost:3000/oauth/authorize
21 | access-token-uri: http://localhost:3000/oauth/token
22 | scope: server
23 | resource:
24 | jwt:
25 | key-uri: http://localhost:3000/oauth/token_key
26 |
27 | spring:
28 | application:
29 | name: pig-sso-client-demo
30 | profiles:
31 | active: dev
32 | ---
33 | spring:
34 | profiles: dev
35 | eureka:
36 | instance:
37 | prefer-ip-address: true
38 | lease-renewal-interval-in-seconds: 5
39 | lease-expiration-duration-in-seconds: 20
40 | client:
41 | serviceUrl:
42 | defaultZone: http://xll:gip6666@localhost:1025/eureka
43 |
44 | ---
45 | spring:
46 | profiles: prd
47 | eureka:
48 | instance:
49 | prefer-ip-address: true
50 | client:
51 | serviceUrl:
52 | defaultZone: http://xll:gip6666@eureka:1025/eureka
53 |
--------------------------------------------------------------------------------
/xll-modules/xll-sso-client-demo/src/main/resources/static/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Title
6 |
7 |
8 | 获取登录信息
9 |
10 |
--------------------------------------------------------------------------------
/xll-modules/xll-upms-service/src/main/java/com/xll/upms/admin/UPMSAdminApplication.java:
--------------------------------------------------------------------------------
1 | package com.xll.upms.admin;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
6 | import org.springframework.context.annotation.ComponentScan;
7 | import org.springframework.scheduling.annotation.EnableAsync;
8 |
9 | /**
10 | * @Author 徐亮亮
11 | * @Description: UPMS用户授权管理系统服务
12 | * @Date 2019/1/18 21:59
13 | */
14 |
15 | @EnableAsync
16 | @SpringBootApplication
17 | @EnableDiscoveryClient
18 | @ComponentScan(basePackages = {"com.xll.upms.admin", "com.xll.upms.common.bean"})
19 | //@ComponentScan(basePackages = {"com.xll.upms"})
20 | public class UPMSAdminApplication {
21 | public static void main(String[] args) {
22 | SpringApplication.run(UPMSAdminApplication.class, args);
23 | }
24 | }
--------------------------------------------------------------------------------
/xll-modules/xll-upms-service/src/main/java/com/xll/upms/admin/common/config/KaptchaConfig.java:
--------------------------------------------------------------------------------
1 | package com.xll.upms.admin.common.config;
2 |
3 | import com.xll.upms.common.constant.SecurityConstants;
4 | import com.google.code.kaptcha.impl.DefaultKaptcha;
5 | import com.google.code.kaptcha.util.Config;
6 | import org.springframework.context.annotation.Bean;
7 | import org.springframework.context.annotation.Configuration;
8 |
9 | import java.util.Properties;
10 |
11 | @Configuration
12 | public class KaptchaConfig {
13 |
14 | private static final String KAPTCHA_BORDER = "kaptcha.border";
15 | private static final String KAPTCHA_TEXTPRODUCER_FONT_COLOR = "kaptcha.textproducer.font.color";
16 | private static final String KAPTCHA_TEXTPRODUCER_CHAR_SPACE = "kaptcha.textproducer.char.space";
17 | private static final String KAPTCHA_IMAGE_WIDTH = "kaptcha.image.width";
18 | private static final String KAPTCHA_IMAGE_HEIGHT = "kaptcha.image.height";
19 | private static final String KAPTCHA_TEXTPRODUCER_CHAR_LENGTH = "kaptcha.textproducer.char.length";
20 | private static final Object KAPTCHA_IMAGE_FONT_SIZE = "kaptcha.textproducer.font.size";
21 |
22 | @Bean
23 | public DefaultKaptcha producer() {
24 | Properties properties = new Properties();
25 | properties.put(KAPTCHA_BORDER, SecurityConstants.DEFAULT_IMAGE_BORDER);
26 | properties.put(KAPTCHA_TEXTPRODUCER_FONT_COLOR, SecurityConstants.DEFAULT_COLOR_FONT);
27 | properties.put(KAPTCHA_TEXTPRODUCER_CHAR_SPACE, SecurityConstants.DEFAULT_CHAR_SPACE);
28 | properties.put(KAPTCHA_IMAGE_WIDTH, SecurityConstants.DEFAULT_IMAGE_WIDTH);
29 | properties.put(KAPTCHA_IMAGE_HEIGHT, SecurityConstants.DEFAULT_IMAGE_HEIGHT);
30 | properties.put(KAPTCHA_IMAGE_FONT_SIZE, SecurityConstants.DEFAULT_IMAGE_FONT_SIZE);
31 | properties.put(KAPTCHA_TEXTPRODUCER_CHAR_LENGTH, SecurityConstants.DEFAULT_IMAGE_LENGTH);
32 | Config config = new Config(properties);
33 | DefaultKaptcha defaultKaptcha = new DefaultKaptcha();
34 | defaultKaptcha.setConfig(config);
35 | return defaultKaptcha;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/xll-modules/xll-upms-service/src/main/java/com/xll/upms/admin/common/config/MybatisPlusConfig.java:
--------------------------------------------------------------------------------
1 | package com.xll.upms.admin.common.config;
2 |
3 | import com.baomidou.mybatisplus.plugins.PaginationInterceptor;
4 | import com.xll.upms.common.bean.interceptor.DataScopeInterceptor;
5 | import org.mybatis.spring.annotation.MapperScan;
6 | import org.springframework.context.annotation.Bean;
7 | import org.springframework.context.annotation.Configuration;
8 |
9 | /**
10 | * @Author 徐亮亮
11 | * @Description:Mapper映射文件配置类
12 | * @Date 2019/1/18 21:30
13 | */
14 | @Configuration
15 | @MapperScan("com.xll.upms.admin.mapper")
16 | public class MybatisPlusConfig {
17 | /**
18 | * 分页插件
19 | *
20 | * @return PaginationInterceptor
21 | */
22 | @Bean
23 | public PaginationInterceptor paginationInterceptor() {
24 | return new PaginationInterceptor();
25 | }
26 |
27 | /**
28 | * 数据权限插件
29 | *
30 | * @return DataScopeInterceptor
31 | */
32 | @Bean
33 | public DataScopeInterceptor dataScopeInterceptor() {
34 | return new DataScopeInterceptor();
35 | }
36 | }
--------------------------------------------------------------------------------
/xll-modules/xll-upms-service/src/main/java/com/xll/upms/admin/common/config/RabbitConfig.java:
--------------------------------------------------------------------------------
1 | package com.xll.upms.admin.common.config;
2 |
3 | import com.xll.upms.common.constant.MqQueueConstant;
4 | import org.springframework.amqp.core.Queue;
5 | import org.springframework.context.annotation.Bean;
6 | import org.springframework.context.annotation.Configuration;
7 |
8 | /**
9 | * @Author 徐亮亮
10 | * @Description: rabbit初始化配置
11 | * @Date 2019/1/18 21:30
12 | */
13 | @Configuration
14 | public class RabbitConfig {
15 | /**
16 | * 初始化 log队列
17 | *
18 | * @return
19 | */
20 | @Bean
21 | public Queue initLogQueue() {
22 | return new Queue(MqQueueConstant.LOG_QUEUE);
23 | }
24 |
25 | /**
26 | * 初始化 手机验证码通道
27 | *
28 | * @return
29 | */
30 | @Bean
31 | public Queue initMobileCodeQueue() {
32 | return new Queue(MqQueueConstant.MOBILE_CODE_QUEUE);
33 | }
34 |
35 | /**
36 | * 初始化服务状态改变队列
37 | *
38 | * @return
39 | */
40 | @Bean
41 | public Queue initMobileServiceStatusChangeQueue() {
42 | return new Queue(MqQueueConstant.MOBILE_SERVICE_STATUS_CHANGE);
43 | }
44 |
45 | /**
46 | * 初始化钉钉状态改变队列
47 | *
48 | * @return
49 | */
50 | @Bean
51 | public Queue initDingTalkServiceStatusChangeQueue() {
52 | return new Queue(MqQueueConstant.DINGTALK_SERVICE_STATUS_CHANGE);
53 | }
54 |
55 | /**
56 | * 初始化zipkin队列
57 | *
58 | * @return
59 | */
60 | @Bean
61 | public Queue initZipkinQueue() {
62 | return new Queue(MqQueueConstant.ZIPKIN_NAME_QUEUE);
63 | }
64 |
65 | /**
66 | * 初始化路由配置状态队列
67 | *
68 | * @return
69 | */
70 | @Bean
71 | public Queue initRouteConfigChangeQueue() {
72 | return new Queue(MqQueueConstant.ROUTE_CONFIG_CHANGE);
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/xll-modules/xll-upms-service/src/main/java/com/xll/upms/admin/common/listener/LogReceiveListener.java:
--------------------------------------------------------------------------------
1 | package com.xll.upms.admin.common.listener;
2 |
3 | import com.xll.upms.admin.service.SysLogService;
4 | import com.xll.upms.common.constant.MqQueueConstant;
5 | import com.xll.upms.common.entity.SysLog;
6 | import com.xll.upms.common.vo.LogVO;
7 | import org.slf4j.MDC;
8 | import org.springframework.amqp.rabbit.annotation.RabbitHandler;
9 | import org.springframework.amqp.rabbit.annotation.RabbitListener;
10 | import org.springframework.beans.factory.annotation.Autowired;
11 | import org.springframework.beans.factory.annotation.Qualifier;
12 | import org.springframework.stereotype.Component;
13 | import org.springframework.stereotype.Service;
14 |
15 | /**
16 | * @Author 徐亮亮
17 | * @Description: 日志接收监听器
18 | * @Date 2019/1/18 21:31
19 | */
20 | @Component
21 | //@Service
22 | @RabbitListener(queues = MqQueueConstant.LOG_QUEUE)
23 | public class LogReceiveListener {
24 | private static final String KEY_USER = "user";
25 |
26 | @Autowired
27 | private SysLogService sysLogService;
28 |
29 | @RabbitHandler
30 | public void receive(LogVO logVo) {
31 | SysLog sysLog = logVo.getSysLog();
32 | MDC.put(KEY_USER, logVo.getUsername());
33 | sysLog.setCreateBy(logVo.getUsername());
34 | sysLogService.insert(sysLog);
35 | MDC.remove(KEY_USER);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/xll-modules/xll-upms-service/src/main/java/com/xll/upms/admin/controller/DeptController.java:
--------------------------------------------------------------------------------
1 | package com.xll.upms.admin.controller;
2 |
3 | import com.baomidou.mybatisplus.mapper.EntityWrapper;
4 | import com.xll.upms.admin.model.dto.DeptTree;
5 | import com.xll.upms.admin.model.entity.SysDept;
6 | import com.xll.upms.admin.service.SysDeptService;
7 | import com.xll.upms.common.constant.CommonConstant;
8 | import com.xll.upms.common.web.BaseController;
9 | import org.springframework.beans.factory.annotation.Autowired;
10 | import org.springframework.web.bind.annotation.*;
11 |
12 | import java.util.Date;
13 | import java.util.List;
14 |
15 | /**
16 | * @Author 徐亮亮
17 | * @Description: 部门管理 前端控制器
18 | * @Date 2019/1/18 21:34
19 | */
20 | @RestController
21 | @RequestMapping("/dept")
22 | public class DeptController extends BaseController {
23 | @Autowired
24 | private SysDeptService sysDeptService;
25 |
26 | /**
27 | * 通过ID查询
28 | *
29 | * @param id ID
30 | * @return SysDept
31 | */
32 | @GetMapping("/{id}")
33 | public SysDept get(@PathVariable Integer id) {
34 | return sysDeptService.selectById(id);
35 | }
36 |
37 |
38 | /**
39 | * 返回树形菜单集合
40 | *
41 | * @return 树形菜单
42 | */
43 | @GetMapping(value = "/tree")
44 | public List getTree() {
45 | SysDept condition = new SysDept();
46 | condition.setDelFlag(CommonConstant.STATUS_NORMAL);
47 | return sysDeptService.selectListTree(new EntityWrapper<>(condition));
48 | }
49 |
50 | /**
51 | * 添加
52 | *
53 | * @param sysDept 实体
54 | * @return success/false
55 | */
56 | @PostMapping
57 | public Boolean add(@RequestBody SysDept sysDept) {
58 | return sysDeptService.insertDept(sysDept);
59 | }
60 |
61 | /**
62 | * 删除
63 | *
64 | * @param id ID
65 | * @return success/false
66 | */
67 | @DeleteMapping("/{id}")
68 | public Boolean delete(@PathVariable Integer id) {
69 | return sysDeptService.deleteDeptById(id);
70 | }
71 |
72 | /**
73 | * 编辑
74 | *
75 | * @param sysDept 实体
76 | * @return success/false
77 | */
78 | @PutMapping
79 | public Boolean edit(@RequestBody SysDept sysDept) {
80 | sysDept.setUpdateTime(new Date());
81 | return sysDeptService.updateDeptById(sysDept);
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/xll-modules/xll-upms-service/src/main/java/com/xll/upms/admin/controller/LogController.java:
--------------------------------------------------------------------------------
1 | package com.xll.upms.admin.controller;
2 |
3 |
4 | import com.baomidou.mybatisplus.mapper.EntityWrapper;
5 | import com.baomidou.mybatisplus.plugins.Page;
6 | import com.xll.upms.admin.service.SysLogService;
7 | import com.xll.upms.common.constant.CommonConstant;
8 | import com.xll.upms.common.util.Query;
9 | import com.xll.upms.common.util.R;
10 | import com.xll.upms.common.web.BaseController;
11 | import org.springframework.beans.factory.annotation.Autowired;
12 | import org.springframework.web.bind.annotation.*;
13 |
14 | import java.util.Map;
15 |
16 | /**
17 | * @Author 徐亮亮
18 | * @Description: 日志表 前端控制器
19 | * @Date 2019/1/18 21:35
20 | */
21 | @RestController
22 | @RequestMapping("/log")
23 | public class LogController extends BaseController {
24 | @Autowired
25 | private SysLogService sysLogService;
26 |
27 | /**
28 | * 分页查询日志信息
29 | *
30 | * @param params 分页对象
31 | * @return 分页对象
32 | */
33 | @RequestMapping("/logPage")
34 | public Page logPage(@RequestParam Map params) {
35 | params.put(CommonConstant.DEL_FLAG, CommonConstant.STATUS_NORMAL);
36 | return sysLogService.selectPage(new Query<>(params), new EntityWrapper<>());
37 | }
38 |
39 | /**
40 | * 根据ID
41 | *
42 | * @param id ID
43 | * @return success/false
44 | */
45 | @DeleteMapping("/{id}")
46 | public R delete(@PathVariable Long id) {
47 | return new R<>(sysLogService.updateByLogId(id));
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/xll-modules/xll-upms-service/src/main/java/com/xll/upms/admin/mapper/SysDeptMapper.java:
--------------------------------------------------------------------------------
1 | package com.xll.upms.admin.mapper;
2 |
3 | import com.baomidou.mybatisplus.mapper.BaseMapper;
4 | import com.xll.upms.admin.model.entity.SysDept;
5 | import org.apache.ibatis.annotations.Mapper;
6 |
7 | import java.util.List;
8 |
9 | /**
10 | * @Author 徐亮亮
11 | * @Description: 部门管理 Mapper 接口
12 | * @Date 2019/1/18 21:38
13 | */
14 | @Mapper
15 | public interface SysDeptMapper extends BaseMapper {
16 |
17 | /**
18 | * 关联dept——relation
19 | *
20 | * @param delFlag 删除标记
21 | * @return 数据列表
22 | */
23 | List selectDeptDtoList(String delFlag);
24 | }
--------------------------------------------------------------------------------
/xll-modules/xll-upms-service/src/main/java/com/xll/upms/admin/mapper/SysDeptRelationMapper.java:
--------------------------------------------------------------------------------
1 | package com.xll.upms.admin.mapper;
2 |
3 | import com.baomidou.mybatisplus.mapper.BaseMapper;
4 | import com.xll.upms.admin.model.entity.SysDeptRelation;
5 | import org.apache.ibatis.annotations.Mapper;
6 |
7 | /**
8 | * @Author 徐亮亮
9 | * @Description: 部门关系 Mapper
10 | * @Date 2019/1/18 21:39
11 | */
12 | @Mapper
13 | public interface SysDeptRelationMapper extends BaseMapper {
14 | /**
15 | * 删除部门关系表数据
16 | *
17 | * @param id 部门ID
18 | */
19 | void deleteAllDeptRealtion(Integer id);
20 |
21 | /**
22 | * 更改部分关系表数据
23 | *
24 | * @param deptRelation
25 | */
26 | void updateDeptRealtion(SysDeptRelation deptRelation);
27 | }
--------------------------------------------------------------------------------
/xll-modules/xll-upms-service/src/main/java/com/xll/upms/admin/mapper/SysDictMapper.java:
--------------------------------------------------------------------------------
1 | package com.xll.upms.admin.mapper;
2 |
3 | import com.baomidou.mybatisplus.mapper.BaseMapper;
4 | import com.xll.upms.admin.model.entity.SysDict;
5 | import org.apache.ibatis.annotations.Mapper;
6 |
7 | /**
8 | * @Author 徐亮亮
9 | * @Description: 字典表 Mapper 接口
10 | * @Date 2019/1/18 21:40
11 | */
12 | @Mapper
13 | public interface SysDictMapper extends BaseMapper {
14 |
15 | }
--------------------------------------------------------------------------------
/xll-modules/xll-upms-service/src/main/java/com/xll/upms/admin/mapper/SysLogMapper.java:
--------------------------------------------------------------------------------
1 | package com.xll.upms.admin.mapper;
2 |
3 | import com.baomidou.mybatisplus.mapper.BaseMapper;
4 | import com.xll.upms.common.entity.SysLog;
5 | import org.apache.ibatis.annotations.Mapper;
6 |
7 | /**
8 | * @Author 徐亮亮
9 | * @Description: 日志表 Mapper 接口
10 | * @Date 2019/1/18 21:40
11 | */
12 | @Mapper
13 | public interface SysLogMapper extends BaseMapper {
14 |
15 | }
--------------------------------------------------------------------------------
/xll-modules/xll-upms-service/src/main/java/com/xll/upms/admin/mapper/SysMenuMapper.java:
--------------------------------------------------------------------------------
1 | package com.xll.upms.admin.mapper;
2 |
3 | import com.baomidou.mybatisplus.mapper.BaseMapper;
4 | import com.xll.upms.admin.model.entity.SysMenu;
5 | import com.xll.upms.common.vo.MenuVO;
6 | import org.apache.ibatis.annotations.Mapper;
7 | import org.apache.ibatis.annotations.Param;
8 |
9 | import java.util.List;
10 |
11 | /**
12 | * @Author 徐亮亮
13 | * @Description: 菜单权限表 Mapper 接口
14 | * @Date 2019/1/18 21:40
15 | */
16 | @Mapper
17 | public interface SysMenuMapper extends BaseMapper {
18 |
19 | /**
20 | * 通过角色名查询菜单
21 | *
22 | * @param role 角色名称
23 | * @return 菜单列表
24 | */
25 | List findMenuByRoleName(@Param("role") String role);
26 | }
--------------------------------------------------------------------------------
/xll-modules/xll-upms-service/src/main/java/com/xll/upms/admin/mapper/SysOauthClientDetailsMapper.java:
--------------------------------------------------------------------------------
1 | package com.xll.upms.admin.mapper;
2 |
3 |
4 | import com.baomidou.mybatisplus.mapper.BaseMapper;
5 | import com.xll.upms.admin.model.entity.SysOauthClientDetails;
6 | import org.apache.ibatis.annotations.Mapper;
7 |
8 | /**
9 | * @Author 徐亮亮
10 | * @Description: 客户认证详情信息Mapper
11 | * @Date 2019/1/18 21:40
12 | */
13 | @Mapper
14 | public interface SysOauthClientDetailsMapper extends BaseMapper {
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/xll-modules/xll-upms-service/src/main/java/com/xll/upms/admin/mapper/SysRoleDeptMapper.java:
--------------------------------------------------------------------------------
1 | package com.xll.upms.admin.mapper;
2 |
3 | import com.baomidou.mybatisplus.mapper.BaseMapper;
4 | import com.xll.upms.admin.model.entity.SysRoleDept;
5 | import org.apache.ibatis.annotations.Mapper;
6 |
7 | /**
8 | * @Author 徐亮亮
9 | * @Description: 角色与部门对应关系 Mapper 接口
10 | * @Date 2019/1/18 21:42
11 | */
12 | @Mapper
13 | public interface SysRoleDeptMapper extends BaseMapper {
14 |
15 | }
--------------------------------------------------------------------------------
/xll-modules/xll-upms-service/src/main/java/com/xll/upms/admin/mapper/SysRoleMapper.java:
--------------------------------------------------------------------------------
1 | package com.xll.upms.admin.mapper;
2 |
3 | import com.baomidou.mybatisplus.mapper.BaseMapper;
4 | import com.xll.upms.admin.model.entity.SysRole;
5 | import com.xll.upms.common.util.Query;
6 | import org.apache.ibatis.annotations.Mapper;
7 |
8 | import java.util.List;
9 | import java.util.Map;
10 |
11 | /**
12 | * @Author 徐亮亮
13 | * @Description: 角色Mapper
14 | * @Date 2019/1/18 21:42
15 | */
16 | @Mapper
17 | public interface SysRoleMapper extends BaseMapper {
18 |
19 | /**
20 | * 查询角色列表含有部门信息
21 | * @param query 查询对象
22 | * @param condition 条件
23 | * @return List
24 | */
25 | List