wei 5 jaren geleden
bovenliggende
commit
72053a66ea
32 gewijzigde bestanden met toevoegingen van 412 en 1 verwijderingen
  1. 5 0
      .gitignore
  2. 8 1
      README.md
  3. 2 0
      base-springframework-starter/.gitignore
  4. 1 0
      base-springframework-starter/pom.xml
  5. 1 0
      base-springframework/.gitignore
  6. 5 0
      base-springframework/base-springframework-cloud/.gitignore
  7. 6 0
      base-springframework/base-springframework-constant/.gitignore
  8. 1 0
      base-springframework/base-springframework-core/.gitignore
  9. 5 0
      base-springframework/base-springframework-mysql/.gitignore
  10. 3 0
      wei-gateway/.gitignore
  11. 19 0
      wei-gateway/src/main/java/com/wei/gateway/config/GatewayConfigure.java
  12. 143 0
      wei-gateway/src/main/java/com/wei/gateway/filter/AuthSignatureFilter.java
  13. 1 0
      wei-test-cloud/.gitignore
  14. 3 0
      wei-test-cloud/wei-test-cloud-api/.gitignore
  15. BIN
      wei-test-cloud/wei-test-cloud-api/target/classes/com/wei/cloud/api/ApiService.class
  16. 3 0
      wei-test-cloud/wei-test-cloud-app/.gitignore
  17. 3 0
      wei-test/wei-test-api/.gitignore
  18. BIN
      wei-test/wei-test-api/target/classes/com/wei/cloud/vo/UserVO.class
  19. 3 0
      wei-test/wei-test-app/.gitignore
  20. BIN
      wei-test/wei-test-app/target/classes/com/wei/test/TestApplication.class
  21. BIN
      wei-test/wei-test-app/target/classes/com/wei/test/controller/TestController.class
  22. BIN
      wei-test/wei-test-app/target/classes/com/wei/test/vo/UserVO.class
  23. BIN
      wei-user/target/classes/com/wei/cloud/api/ApiService.class
  24. 14 0
      wei-user/wei-user-api/src/main/java/com/wei/user/api/ApiService.java
  25. 46 0
      wei-user/wei-user-app/src/main/java/com/wei/user/controller/UserController.java
  26. 55 0
      wei-user/wei-user-app/src/main/java/com/wei/user/entity/User.java
  27. 16 0
      wei-user/wei-user-app/src/main/java/com/wei/user/mapper/UserMapper.java
  28. 16 0
      wei-user/wei-user-app/src/main/java/com/wei/user/mapper/xml/UserMapper.xml
  29. 14 0
      wei-user/wei-user-app/src/main/java/com/wei/user/mapstruct/UserMapstruct.java
  30. 16 0
      wei-user/wei-user-app/src/main/java/com/wei/user/service/UserService.java
  31. 23 0
      wei-user/wei-user-app/src/main/java/com/wei/user/service/impl/UserServiceImpl.java
  32. BIN
      wei-user/wei-user-app/target/classes/com/wei/cloud/api/impl/ApiServiceImpl.class

+ 5 - 0
.gitignore

@@ -0,0 +1,5 @@
+/.project
+/base-framework.iml
+/Desktop.ini
+/config
+/description

+ 8 - 1
README.md

@@ -1 +1,8 @@
-"# base-framework" 
+#base-springframework
+基于spring各个组件进行二次封装
+
+#base-framework
+用于处理jar包版本统一依赖
+
+#consul
+consul安装教程

+ 2 - 0
base-springframework-starter/.gitignore

@@ -0,0 +1,2 @@
+/.project
+/base-springframework-starter.iml

+ 1 - 0
base-springframework-starter/pom.xml

@@ -10,6 +10,7 @@
     <modules>
         <module>../wei-test</module>
         <module>../wei-test-cloud</module>
+        <module>../wei-gateway</module>
     </modules>
 
     <properties>

+ 1 - 0
base-springframework/.gitignore

@@ -1 +1,2 @@
 /.project
+/base-springframework.iml

+ 5 - 0
base-springframework/base-springframework-cloud/.gitignore

@@ -0,0 +1,5 @@
+/target/
+/.classpath
+/.settings/
+/.project
+/base-springframework-cloud.iml

+ 6 - 0
base-springframework/base-springframework-constant/.gitignore

@@ -0,0 +1,6 @@
+/target/
+/.classpath
+/.settings/
+/.project
+/base-springframework-constant.iml
+/base-springframework-core.iml

+ 1 - 0
base-springframework/base-springframework-core/.gitignore

@@ -2,3 +2,4 @@
 /.classpath
 /.settings/
 /.project
+/base-springframework-core.iml

+ 5 - 0
base-springframework/base-springframework-mysql/.gitignore

@@ -0,0 +1,5 @@
+/target/
+/.classpath
+/.settings/
+/.project
+/base-springframework-mysql.iml

+ 3 - 0
wei-gateway/.gitignore

@@ -0,0 +1,3 @@
+/target/
+/.classpath
+/.project

+ 19 - 0
wei-gateway/src/main/java/com/wei/gateway/config/GatewayConfigure.java

@@ -0,0 +1,19 @@
+package com.wei.gateway.config;
+
+import lombok.Data;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Configuration;
+
+@Data
+@Configuration
+public class GatewayConfigure {
+
+    @Value("${filter.path}")
+    private String filterPath;
+
+    @Value("${login.invalidTime}")
+    private Long loginInvalidTime;
+
+    @Value("${login.token}")
+    private String loginToken;
+}

+ 143 - 0
wei-gateway/src/main/java/com/wei/gateway/filter/AuthSignatureFilter.java

@@ -0,0 +1,143 @@
+//package com.wei.gateway.filter;
+//
+//import com.alibaba.fastjson.JSONArray;
+//import com.honglinktech.zbgj.cloud.gateway.constants.RedisKeyConstant;
+//import com.honglinktech.zbgj.cloud.gateway.constants.ServletConstants;
+//import com.honglinktech.zbgj.cloud.gateway.enums.GatewayExceptionEnum;
+//import com.honglinktech.zbgj.springframework.core.vo.UserSession;
+//import com.honglinktech.zbgj.springframework.util.RegexUtil;
+//import com.honglinktech.zbgj.springframework.util.StringUtil;
+//import lombok.extern.slf4j.Slf4j;
+//import org.apache.commons.collections4.CollectionUtils;
+//import org.apache.commons.collections4.MapUtils;
+//import org.springframework.beans.factory.annotation.Value;
+//import org.springframework.cloud.gateway.filter.GatewayFilterChain;
+//import org.springframework.cloud.gateway.filter.GlobalFilter;
+//import org.springframework.core.Ordered;
+//import org.springframework.core.io.buffer.DataBuffer;
+//import org.springframework.data.redis.core.RedisTemplate;
+//import org.springframework.http.HttpHeaders;
+//import org.springframework.http.HttpStatus;
+//import org.springframework.http.server.reactive.ServerHttpRequest;
+//import org.springframework.http.server.reactive.ServerHttpResponse;
+//import org.springframework.stereotype.Component;
+//import org.springframework.web.server.ServerWebExchange;
+//import reactor.core.publisher.Mono;
+//
+//import javax.annotation.Resource;
+//import java.nio.charset.StandardCharsets;
+//import java.util.List;
+//import java.util.Map;
+//import java.util.concurrent.TimeUnit;
+//
+//@Slf4j
+//@Component
+//public class AuthSignatureFilter implements GlobalFilter, Ordered {
+//
+//    @Resource
+//    RedisTemplate<String, Object> redisTemplate;
+//
+//    @Value("${filter.path}")
+//    private String filterPath;
+//
+//    @Value("${login.invalidTime}")
+//    private Long loginInvalidTime;
+//
+//    @Value("${apiToken}")
+//    private String apiToken;
+//
+//    @SuppressWarnings("unchecked")
+//    @Override
+//    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
+//        ServerHttpRequest serverHttpRequest = exchange.getRequest();
+//
+//        String path = serverHttpRequest.getPath().pathWithinApplication().value();
+//        HttpHeaders httpHeaders = serverHttpRequest.getHeaders();
+//        UserSession userSession = new UserSession();
+//        ServerHttpResponse serverHttpResponse = exchange.getResponse();
+//
+//        // 判断url是否需要过滤
+//        if (!RegexUtil.matcher(filterPath, path)) {
+//            List<String> tokenHeaders = httpHeaders.get(ServletConstants.X_AUTH_TOKEN);
+//
+//            // 获取token 判断是否存在
+//            if (CollectionUtils.isEmpty(tokenHeaders) || StringUtil.isBlank(tokenHeaders.get(0))) {
+//                return getErrorMsg(serverHttpResponse, GatewayExceptionEnum.LOGON_FAILURE);
+//            }
+//
+//            String token = tokenHeaders.get(0);
+//            if (!StringUtil.equals(token, apiToken)) {
+//                try {
+//                    log.info("token:{}", token);
+//                    // 从redis中获取token 判断是否存在 如果不存在则提示错误
+//                    userSession = (UserSession) redisTemplate.opsForValue().get(RedisKeyConstant.USER_TOKEN + token);
+//                    if (userSession == null) {
+//                        return getErrorMsg(serverHttpResponse, GatewayExceptionEnum.LOGON_FAILURE);
+//                    }
+//
+//                    // 延长redis失效时间
+//                    redisTemplate.expire(RedisKeyConstant.USER_TOKEN + token, loginInvalidTime, TimeUnit.SECONDS);
+//                } catch (Exception e) {
+//                    log.info(e.getMessage(), e);
+//                    return getErrorMsg(serverHttpResponse, GatewayExceptionEnum.SYSTEM_ERROR);
+//                }
+//            }
+//
+//            // 判断用户是否有权限访问
+//            List<String> sourceHeaders = httpHeaders.get(ServletConstants.X_AUTH_SOURCE);
+//            if (CollectionUtils.isNotEmpty(sourceHeaders)) {
+//                Object object = redisTemplate.opsForValue()
+//                        .get(RedisKeyConstant.USER_ROLE + userSession.getUserId().toString());
+//
+//                if (object == null) {
+//                    return getErrorMsg(serverHttpResponse, GatewayExceptionEnum.PERMISSION_IS_NULL);
+//                }
+//
+//                Map<String, List<String>> map = (Map<String, List<String>>) object;
+//                if (MapUtils.isEmpty(map) || CollectionUtils.isEmpty(map.get(path))) {
+//                    return getErrorMsg(serverHttpResponse, GatewayExceptionEnum.PERMISSION_IS_NULL);
+//                }
+//
+//                String source = sourceHeaders.get(0);
+//                List<String> sources = map.get(path);
+//                if (!sources.contains(source)) {
+//                    return getErrorMsg(serverHttpResponse, GatewayExceptionEnum.PERMISSION_IS_NULL);
+//                }
+//            }
+//        }
+//
+//        log.info("request = {}", JSONArray.toJSONString(exchange.getRequest().getSslInfo()));
+//
+//        // 如果header中已存在 user-session 则以header中的为主
+//        serverHttpRequest.mutate().header(ServletConstants.USER_SESSION, JSONArray.toJSONString(userSession));
+//        ServerWebExchange build = exchange.mutate().request(serverHttpRequest).build();
+//        return chain.filter(build);
+//    }
+//
+//    /**
+//     * 封装异常用于gateway过滤器返回
+//     *
+//     * @param serverHttpResponse
+//     * @param gatewayExceptionEnum
+//     * @return
+//     */
+//    private Mono<Void> getErrorMsg(ServerHttpResponse serverHttpResponse, GatewayExceptionEnum gatewayExceptionEnum) {
+//        serverHttpResponse.setStatusCode(HttpStatus.OK);
+//        serverHttpResponse.getHeaders().add("Content-Type", "text/plain;charset=UTF-8");
+//
+//        String body = String.format("{\"code\":\"%s\",\"msg\":\"%s\"}", gatewayExceptionEnum.getCode(),
+//                gatewayExceptionEnum.getMsg());
+//
+//        log.info(body);
+//        byte[] bytes = body.getBytes(StandardCharsets.UTF_8);
+//        DataBuffer buffer = serverHttpResponse.bufferFactory().wrap(bytes);
+//
+//        Mono<DataBuffer> mono = Mono.just(buffer);
+//        return serverHttpResponse.writeWith(mono);
+//    }
+//
+//    @Override
+//    public int getOrder() {
+//        return -200;
+//    }
+//}

+ 1 - 0
wei-test-cloud/.gitignore

@@ -0,0 +1 @@
+/.project

+ 3 - 0
wei-test-cloud/wei-test-cloud-api/.gitignore

@@ -0,0 +1,3 @@
+/target/
+/.classpath
+/.project

BIN
wei-test-cloud/wei-test-cloud-api/target/classes/com/wei/cloud/api/ApiService.class


+ 3 - 0
wei-test-cloud/wei-test-cloud-app/.gitignore

@@ -0,0 +1,3 @@
+/target/
+/.classpath
+/.project

+ 3 - 0
wei-test/wei-test-api/.gitignore

@@ -0,0 +1,3 @@
+/target/
+/.classpath
+/.project

BIN
wei-test/wei-test-api/target/classes/com/wei/cloud/vo/UserVO.class


+ 3 - 0
wei-test/wei-test-app/.gitignore

@@ -0,0 +1,3 @@
+/target/
+/.classpath
+/.project

BIN
wei-test/wei-test-app/target/classes/com/wei/test/TestApplication.class


BIN
wei-test/wei-test-app/target/classes/com/wei/test/controller/TestController.class


BIN
wei-test/wei-test-app/target/classes/com/wei/test/vo/UserVO.class


BIN
wei-user/target/classes/com/wei/cloud/api/ApiService.class


+ 14 - 0
wei-user/wei-user-api/src/main/java/com/wei/user/api/ApiService.java

@@ -0,0 +1,14 @@
+package com.wei.cloud.api;
+
+import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestHeader;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+@FeignClient(name = "wei-test-cloud")
+@RequestMapping("/apiService")
+public interface ApiService {
+
+    @GetMapping("/test")
+    String test(@RequestHeader("Filter-Enabled") String filterEnabled);
+}

+ 46 - 0
wei-user/wei-user-app/src/main/java/com/wei/user/controller/UserController.java

@@ -0,0 +1,46 @@
+package com.wei.user.controller;
+
+import com.wei.base.springframework.constant.vo.RestfulVO;
+import com.wei.user.entity.User;
+import com.wei.user.service.UserService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * <p>
+ * 用户信息表 前端控制器
+ * </p>
+ *
+ * @author wei
+ * @since 2020-08-13
+ */
+@Api(tags = "test")
+@RestController
+@RequestMapping("/user")
+public class UserController {
+
+    @Autowired
+    private UserService userService;
+
+    @ApiOperation("分页查询所有数据")
+    @GetMapping("/test")
+    public User test() {
+        return userService.getById(1);
+    }
+
+    @ApiOperation("分页查询所有数据")
+    @GetMapping("/test2")
+    public RestfulVO<User> test2() {
+        return new RestfulVO(userService.getById(1));
+    }
+
+    @ApiOperation("分页查询所有数据")
+    @GetMapping("/test1")
+    public RestfulVO<String> test1() {
+        return new RestfulVO("1111");
+    }
+}

+ 55 - 0
wei-user/wei-user-app/src/main/java/com/wei/user/entity/User.java

@@ -0,0 +1,55 @@
+package com.wei.user.entity;
+
+import java.util.Date;
+import java.io.Serializable;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+/**
+ * <p>
+ * 用户信息表
+ * </p>
+ *
+ * @author wei
+ * @since 2020-08-13
+ */
+@Data
+@EqualsAndHashCode(callSuper = false)
+public class User implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    private Long id;
+
+    /**
+     * 用户名称
+     */
+    private String name;
+
+    /**
+     * 用户手机号
+     */
+    private String mobilePhone;
+
+    /**
+     * 用户邮箱
+     */
+    private String email;
+
+    /**
+     * 密码
+     */
+    private String password;
+
+    /**
+     * 用户头像地址
+     */
+    private String pictureUrl;
+
+    /**
+     * 创建时间
+     */
+    private Date createTime;
+
+
+}

+ 16 - 0
wei-user/wei-user-app/src/main/java/com/wei/user/mapper/UserMapper.java

@@ -0,0 +1,16 @@
+package com.wei.user.mapper;
+
+import com.wei.user.entity.User;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+ * <p>
+ * 用户信息表 Mapper 接口
+ * </p>
+ *
+ * @author wei
+ * @since 2020-08-13
+ */
+public interface UserMapper extends BaseMapper<User> {
+
+}

+ 16 - 0
wei-user/wei-user-app/src/main/java/com/wei/user/mapper/xml/UserMapper.xml

@@ -0,0 +1,16 @@
+<?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.wei.user.mapper.UserMapper">
+
+    <!-- 通用查询映射结果 -->
+    <resultMap id="BaseResultMap" type="com.wei.user.entity.User">
+        <id column="id" property="id" />
+        <result column="name" property="name" />
+        <result column="mobile_phone" property="mobilePhone" />
+        <result column="email" property="email" />
+        <result column="password" property="password" />
+        <result column="picture_url" property="pictureUrl" />
+        <result column="create_time" property="createTime" />
+    </resultMap>
+
+</mapper>

+ 14 - 0
wei-user/wei-user-app/src/main/java/com/wei/user/mapstruct/UserMapstruct.java

@@ -0,0 +1,14 @@
+package com.wei.user.mapstruct;
+
+import org.mapstruct.Mapper;
+
+/**
+* 用户信息表 服务类型实体转换
+*
+* @author wei
+* @since 2020-08-13
+*/
+@Mapper(componentModel = "spring")
+public interface UserMapstruct {
+
+}

+ 16 - 0
wei-user/wei-user-app/src/main/java/com/wei/user/service/UserService.java

@@ -0,0 +1,16 @@
+package com.wei.user.service;
+
+import com.wei.user.entity.User;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+/**
+ * <p>
+ * 用户信息表 服务类
+ * </p>
+ *
+ * @author wei
+ * @since 2020-08-13
+ */
+public interface UserService extends IService<User> {
+
+}

+ 23 - 0
wei-user/wei-user-app/src/main/java/com/wei/user/service/impl/UserServiceImpl.java

@@ -0,0 +1,23 @@
+package com.wei.user.service.impl;
+
+import com.wei.user.entity.User;
+import com.wei.user.mapper.UserMapper;
+import com.wei.user.service.UserService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+/**
+ * <p>
+ * 用户信息表 服务实现类
+ * </p>
+ *
+ * @author wei
+ * @since 2020-08-13
+ */
+@Service
+public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
+
+	@Autowired
+	private UserMapper userMapper;
+}

BIN
wei-user/wei-user-app/target/classes/com/wei/cloud/api/impl/ApiServiceImpl.class