2021与蓝度共同重构项目,服务端
chenjiantian
2021-12-02 3e77538aa01616597bfe52a60d7b256011be9b6e
基础功能完善
已修改5个文件
155 ■■■■■ 文件已修改
pom.xml 23 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ximon-admin/pom.xml 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ximon-admin/src/main/java/com/sandu/ximon/admin/context/CustomerInspectContextHolder.java 62 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ximon-admin/src/main/java/com/sandu/ximon/admin/filter/CustomerInspectContextHolderFilter.java 42 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ximon-admin/src/main/java/com/sandu/ximon/admin/security/SecurityUtils.java 10 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pom.xml
@@ -73,6 +73,29 @@
                <artifactId>weixin-java-miniapp</artifactId>
                <version>${weixin-java.version}</version>
            </dependency>
            <!-- amqp 1.0 qpid client -->
            <dependency>
                <groupId>org.apache.qpid</groupId>
                <artifactId>qpid-jms-client</artifactId>
                <version>0.57.0</version>
            </dependency>
            <!-- util for base64-->
            <dependency>
                <groupId>commons-codec</groupId>
                <artifactId>commons-codec</artifactId>
                <version>1.10</version>
            </dependency>
            <dependency>
                <groupId>com.aliyun</groupId>
                <artifactId>aliyun-java-sdk-core</artifactId>
                <version>4.5.6</version>
            </dependency>
            <dependency>
                <groupId>com.aliyun</groupId>
                <artifactId>aliyun-java-sdk-iot</artifactId>
                <version>7.29.0</version>
            </dependency>
        </dependencies>
    </dependencyManagement>
ximon-admin/pom.xml
@@ -23,6 +23,24 @@
            <groupId>com.sandu.ximon</groupId>
            <artifactId>sandu-common</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.qpid</groupId>
            <artifactId>qpid-jms-client</artifactId>
        </dependency>
        <!-- util for base64-->
        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
        </dependency>
        <dependency>
            <groupId>com.aliyun</groupId>
            <artifactId>aliyun-java-sdk-core</artifactId>
        </dependency>
        <dependency>
            <groupId>com.aliyun</groupId>
            <artifactId>aliyun-java-sdk-iot</artifactId>
        </dependency>
    </dependencies>
    <!-- Maven控制Spring Profile -->
ximon-admin/src/main/java/com/sandu/ximon/admin/context/CustomerInspectContextHolder.java
@@ -12,35 +12,35 @@
public class CustomerInspectContextHolder {
    /**
     * 支持父子线程之间的数据传递
     */
    private final ThreadLocal<String> THREAD_LOCAL_TENANT = new ThreadLocal<>();
    /**
     * TTL 设置客户ID<br/>
     *
     */
    public void setCustomerId(String tenantId) {
        THREAD_LOCAL_TENANT.set(tenantId);
    }
    /**
     * 获取TTL中的客户ID
     *
     * @return String
     */
    public Long getCustomerId() {
        String s = THREAD_LOCAL_TENANT.get();
        if(StrUtil.isNotBlank(s)){
            return Long.parseLong(s);
        }
        return null;
    }
    /**
     * 清除Id
     */
    public void clear() {
        THREAD_LOCAL_TENANT.remove();
    }
//     * 支持父子线程之间的数据传递
//     */
//    private final ThreadLocal<String> THREAD_LOCAL_TENANT = new ThreadLocal<>();
//
//    /**
//     * TTL 设置客户ID<br/>
//     *
//     */
//    public void setCustomerId(String tenantId) {
//        THREAD_LOCAL_TENANT.set(tenantId);
//    }
//
//    /**
//     * 获取TTL中的客户ID
//     *
//     * @return String
//     */
//    public Long getCustomerId() {
//        String s = THREAD_LOCAL_TENANT.get();
//        if(StrUtil.isNotBlank(s)){
//            return Long.parseLong(s);
//        }
//        return null;
//    }
//
//    /**
//     * 清除Id
//     */
//    public void clear() {
//        THREAD_LOCAL_TENANT.remove();
//    }
}
ximon-admin/src/main/java/com/sandu/ximon/admin/filter/CustomerInspectContextHolderFilter.java
@@ -21,24 +21,24 @@
 * 管理员访客过滤
 * @author chenjiantian
 */
@Slf4j
@Component
@Order(Ordered.HIGHEST_PRECEDENCE)
public class CustomerInspectContextHolderFilter extends GenericFilterBean {
    @Override
    @SneakyThrows
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        HttpServletResponse response = (HttpServletResponse) servletResponse;
        try {
            String customer = request.getHeader("customer");
            if (StringUtil.isNotBlank(customer)) {
                CustomerInspectContextHolder.setCustomerId(customer);
            }
            filterChain.doFilter(request, response);
        } finally {
            CustomerInspectContextHolder.clear();
        }
    }
}
//@Slf4j
//@Component
//@Order(Ordered.HIGHEST_PRECEDENCE)
//public class CustomerInspectContextHolderFilter extends GenericFilterBean {
//    @Override
//    @SneakyThrows
//    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
//        HttpServletRequest request = (HttpServletRequest) servletRequest;
//        HttpServletResponse response = (HttpServletResponse) servletResponse;
//        try {
//            String customer = request.getHeader("customer");
//
//            if (StringUtil.isNotBlank(customer)) {
//                CustomerInspectContextHolder.setCustomerId(customer);
//            }
//            filterChain.doFilter(request, response);
//        } finally {
//            CustomerInspectContextHolder.clear();
//        }
//    }
//}
ximon-admin/src/main/java/com/sandu/ximon/admin/security/SecurityUtils.java
@@ -32,7 +32,7 @@
public class SecurityUtils {
    /**
     * 获取用户信息
     * 获取当前登录用户信息
     */
    private static UserDetails getUserDetails() {
        final Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
@@ -54,9 +54,9 @@
    }
    /**
     * 获取系统用户名称 登录名
     * 获取当前登录用户登录名
     *
     * @return 系统用户名称
     * @return 当前登录用户登录名
     */
    public static String getUsername() {
        final Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
@@ -81,9 +81,9 @@
    }
    /**
     * 获取系统用户id
     * 获取当前登录账号的id
     *
     * @return 系统用户id
     * @return 当前登录账号的id
     */
    public static Long getUserId() {
        SecurityProperties properties = SpringContextHolder.getBean(SecurityProperties.class);