org.projectlombok
lombok
diff --git a/src/main/java/com/jwl/driver/server/DriverServerApplication.java b/src/main/java/com/jwl/driver/server/DriverServerApplication.java
index b603dba..4b0d9d2 100644
--- a/src/main/java/com/jwl/driver/server/DriverServerApplication.java
+++ b/src/main/java/com/jwl/driver/server/DriverServerApplication.java
@@ -3,13 +3,21 @@ package com.jwl.driver.server;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
+import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@ComponentScan(basePackages = {"com.jwl.driver.server.*"})
@SpringBootApplication
-public class DriverServerApplication {
+public class DriverServerApplication implements WebMvcConfigurer {
public static void main(String[] args) {
SpringApplication.run(DriverServerApplication.class, args);
}
+ @Override
+ public void addResourceHandlers(ResourceHandlerRegistry registry) {
+ registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/");
+ registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
+ }
+
}
diff --git a/src/main/java/com/jwl/driver/server/config/CorsConfig.java b/src/main/java/com/jwl/driver/server/config/CorsConfig.java
new file mode 100644
index 0000000..3bed5b9
--- /dev/null
+++ b/src/main/java/com/jwl/driver/server/config/CorsConfig.java
@@ -0,0 +1,65 @@
+package com.jwl.driver.server.config;
+
+import com.jwl.driver.server.interceptor.AuthInterceptor;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.cors.CorsConfiguration;
+import org.springframework.web.cors.reactive.CorsWebFilter;
+import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;
+import org.springframework.web.servlet.config.annotation.CorsRegistry;
+import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
+import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+
+/**
+ * @author 曹林
+ * @description 跨域配置类
+ * @create 2023/8/11 22:39
+ */
+@Configuration
+public class CorsConfig implements WebMvcConfigurer {
+
+ @Bean
+ public AuthInterceptor initAuthInterceptor(){
+ return new AuthInterceptor();
+ }
+
+ @Override
+ public void addInterceptors(InterceptorRegistry registry) {
+ registry.addInterceptor(initAuthInterceptor()).addPathPatterns("/driver-api/**")
+ .excludePathPatterns("/login/**");
+ }
+
+ @Override
+ public void addCorsMappings(CorsRegistry registry) {
+ // 设置允许跨域的路径
+ registry.addMapping("/**")
+ // 设置允许跨域请求的域名
+ .allowedOriginPatterns("*")
+ // 是否允许cookie
+ .allowCredentials(true)
+ // 设置允许的请求方式
+ .allowedMethods("GET", "POST", "DELETE", "PUT")
+ // 设置允许的header属性
+ .allowedHeaders("*")
+ // 跨域允许时间
+ .maxAge(3600);
+ }
+
+ @Bean
+ public CorsWebFilter corsWebFilter(){
+ UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
+
+ CorsConfiguration corsConfiguration = new CorsConfiguration();
+ //1、配置跨域
+ corsConfiguration.addAllowedHeader("*");//允许哪些头进行跨域
+ corsConfiguration.addAllowedMethod("*");//允许哪些请求方式进行跨域
+ corsConfiguration.addAllowedOriginPattern("*");//允许哪些请求来源进行跨域
+ corsConfiguration.setAllowCredentials(true);//是否允许携带cookie进行跨域,否则跨域请求会丢失cookie信息
+
+ source.registerCorsConfiguration("/**",corsConfiguration);
+
+ return new CorsWebFilter(source);
+ }
+
+}
diff --git a/src/main/java/com/jwl/driver/server/config/SwaggerConfig.java b/src/main/java/com/jwl/driver/server/config/SwaggerConfig.java
index ccad151..2acb01f 100644
--- a/src/main/java/com/jwl/driver/server/config/SwaggerConfig.java
+++ b/src/main/java/com/jwl/driver/server/config/SwaggerConfig.java
@@ -47,9 +47,9 @@ public class SwaggerConfig {
.title("管理中心")
.description("管理中心接口文档")
.termsOfServiceUrl("http://127.0.0.1")
- .contact(new Contact("jslx",
+ .contact(new Contact("jwl",
"http://www.jslx.com",
- "jslx@equ-tech.com"))
+ "1149034574@qq.com"))
.version("1.0")
.build();
}
diff --git a/src/main/java/com/jwl/driver/server/controller/TdSysUserController.java b/src/main/java/com/jwl/driver/server/controller/TdSysUserController.java
index 87b43aa..89c32b9 100644
--- a/src/main/java/com/jwl/driver/server/controller/TdSysUserController.java
+++ b/src/main/java/com/jwl/driver/server/controller/TdSysUserController.java
@@ -1,9 +1,19 @@
package com.jwl.driver.server.controller;
+import com.jwl.driver.server.dto.LoginUserDto;
+import com.jwl.driver.server.response.BaseResponse;
+import com.jwl.driver.server.service.ITdSysUserService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RestController;
/**
*
@@ -13,8 +23,21 @@ import org.springframework.stereotype.Controller;
* @author Automated procedures
* @since 2023-08-10
*/
-@Controller
-@RequestMapping("//tdSysUser")
+@RestController
+@Api(tags = "用户管理")
+@RequestMapping("/tdSysUser")
+@Slf4j
public class TdSysUserController {
+ @Autowired
+ private ITdSysUserService userService;
+
+
+ @ApiOperation("用户登陆")
+ @PostMapping("/login")
+ public BaseResponse login(@RequestBody LoginUserDto loginUserDto) throws Exception {
+ log.info("用户登录======>loginUserDto:{}", loginUserDto);
+ return BaseResponse.success(userService.login(loginUserDto));
+ }
+
}
diff --git a/src/main/java/com/jwl/driver/server/dto/LoginUserDto.java b/src/main/java/com/jwl/driver/server/dto/LoginUserDto.java
new file mode 100644
index 0000000..aa80ef6
--- /dev/null
+++ b/src/main/java/com/jwl/driver/server/dto/LoginUserDto.java
@@ -0,0 +1,25 @@
+package com.jwl.driver.server.dto;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+import javax.validation.constraints.NotBlank;
+
+/**
+ * @author 曹林
+ * @description 登陆入参
+ * @create 2023/8/11 22:21
+ */
+@Data
+@Accessors(chain = true)
+public class LoginUserDto {
+
+ @ApiModelProperty("登陆手机号")
+ @NotBlank(message = "登陆手机号不能为空")
+ private String phone;
+
+ @ApiModelProperty("登陆验证码")
+ @NotBlank(message = "登陆验证码不能为空")
+ private String code;
+}
diff --git a/src/main/java/com/jwl/driver/server/interceptor/AuthInterceptor.java b/src/main/java/com/jwl/driver/server/interceptor/AuthInterceptor.java
new file mode 100644
index 0000000..87316cd
--- /dev/null
+++ b/src/main/java/com/jwl/driver/server/interceptor/AuthInterceptor.java
@@ -0,0 +1,52 @@
+package com.jwl.driver.server.interceptor;
+
+import com.jwl.driver.server.redis.RedisCache;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.util.StringUtils;
+import org.springframework.web.servlet.HandlerInterceptor;
+import org.springframework.web.servlet.ModelAndView;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.util.Objects;
+
+/**
+ * @author 曹林
+ * @description
+ * @create 2023/8/11 18:05
+ */
+
+public class AuthInterceptor implements HandlerInterceptor {
+
+ @Autowired
+ private RedisCache redisCache;
+
+ @Override
+ public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
+ response.setCharacterEncoding("UTF-8");
+ response.setContentType("text/html;charset=utf-8");
+ String token = request.getHeader("token");
+ if (StringUtils.isEmpty(token)) {
+ response.getWriter().print("用户未登录,请登录后操作!");
+ return false;
+ }
+ Object loginStatus = redisCache.getCacheObject(token);
+ if( Objects.isNull(loginStatus)){
+ response.getWriter().print("登陆异常,请查看!");
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
+
+ }
+
+ @Override
+ public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
+
+ }
+}
+
+
diff --git a/src/main/java/com/jwl/driver/server/redis/RedisCache.java b/src/main/java/com/jwl/driver/server/redis/RedisCache.java
new file mode 100644
index 0000000..0008e97
--- /dev/null
+++ b/src/main/java/com/jwl/driver/server/redis/RedisCache.java
@@ -0,0 +1,296 @@
+package com.jwl.driver.server.redis;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.*;
+import org.springframework.stereotype.Component;
+
+/**
+ * spring redis 工具类
+ *
+ * @author ruoyi
+ **/
+@SuppressWarnings(value = {"unchecked", "rawtypes"})
+@Component
+@Slf4j
+public class RedisCache {
+ @Autowired
+ public RedisTemplate redisTemplate;
+
+ @Autowired
+ private RedisTemplate stringRedisTemplate;
+
+ public boolean hasKey(final String key) {
+ return Boolean.TRUE.equals(redisTemplate.hasKey(key));
+ }
+
+ /**
+ * 缓存基本的对象,Integer、String、实体类等
+ *
+ * @param key 缓存的键值
+ * @param value 缓存的值
+ */
+ public void setCacheObject(final String key, final T value) {
+ redisTemplate.opsForValue().set(key, value);
+ }
+
+ /**
+ * 缓存基本的对象,Integer、String、实体类等
+ *
+ * @param key 缓存的键值
+ * @param value 缓存的值
+ * @param timeout 时间
+ * @param timeUnit 时间颗粒度
+ */
+ public void setCacheObject(final String key, final T value, final Integer timeout, final TimeUnit timeUnit) {
+ redisTemplate.opsForValue().set(key, value, timeout, timeUnit);
+ }
+
+ /**
+ * 缓存基本的对象,Integer、String、实体类等
+ *
+ * @param key 缓存的键值
+ * @param value 缓存的值
+ * @param timeout 时间
+ */
+ public void setCacheObject(final String key, final T value, final long timeout) {
+ redisTemplate.opsForValue().set(key, value, timeout, TimeUnit.SECONDS);
+ }
+
+ /**
+ * 设置有效时间
+ *
+ * @param key Redis键
+ * @param timeout 超时时间
+ * @return true=设置成功;false=设置失败
+ */
+ public boolean expire(final String key, final long timeout) {
+ return expire(key, timeout, TimeUnit.SECONDS);
+ }
+
+ /**
+ * 设置有效时间
+ *
+ * @param key Redis键
+ * @param timeout 超时时间
+ * @param unit 时间单位
+ * @return true=设置成功;false=设置失败
+ */
+ public boolean expire(final String key, final long timeout, final TimeUnit unit) {
+ return redisTemplate.expire(key, timeout, unit);
+ }
+
+ /**
+ * 获得缓存的基本对象。
+ *
+ * @param key 缓存键值
+ * @return 缓存键值对应的数据
+ */
+ public T getCacheObject(final String key) {
+ ValueOperations operation = redisTemplate.opsForValue();
+ return operation.get(key);
+ }
+
+ /**
+ * 删除单个对象
+ *
+ * @param key
+ */
+ public boolean deleteObject(final String key) {
+ return redisTemplate.delete(key);
+ }
+
+ /**
+ * 删除集合对象
+ *
+ * @param collection 多个对象
+ * @return
+ */
+ public long deleteObject(final Collection collection) {
+ return redisTemplate.delete(collection);
+ }
+
+ /**
+ * 删除单个对象
+ *
+ * @param key
+ */
+ public void deleteObjectLike(final String key) {
+ Set keys = redisTemplate.keys(key + "*");
+ redisTemplate.delete(keys);
+ }
+
+ /**
+ * 缓存List数据
+ *
+ * @param key 缓存的键值
+ * @param dataList 待缓存的List数据
+ * @return 缓存的对象
+ */
+ public long setCacheList(final String key, final List dataList) {
+ Long count = redisTemplate.opsForList().rightPushAll(key, dataList);
+ return count == null ? 0 : count;
+ }
+
+ /**
+ * 获得缓存的list对象
+ *
+ * @param key 缓存的键值
+ * @return 缓存键值对应的数据
+ */
+ public List getCacheList(final String key) {
+ return redisTemplate.opsForList().range(key, 0, -1);
+ }
+
+ /**
+ * 缓存Set
+ *
+ * @param key 缓存键值
+ * @param dataSet 缓存的数据
+ * @return 缓存数据的对象
+ */
+ public BoundSetOperations setCacheSet(final String key, final Set dataSet) {
+ BoundSetOperations setOperation = stringRedisTemplate.boundSetOps(key);
+ Iterator it = dataSet.iterator();
+ while (it.hasNext()) {
+ setOperation.add(it.next());
+ }
+ return setOperation;
+ }
+
+ /**
+ * 获得缓存的set
+ *
+ * @param key
+ * @return
+ */
+ public Set getCacheSet(final String key) {
+ return stringRedisTemplate.opsForSet().members(key);
+ }
+
+ public Long addCacheSet(final String key, String... value) {
+ SetOperations setOperations = stringRedisTemplate.opsForSet();
+ return setOperations.add(key, value);
+ }
+
+ public Long removeCacheSet(final String key, Object... value) {
+ return stringRedisTemplate.opsForSet().remove(key, value);
+ }
+
+ /**
+ * 缓存Map
+ *
+ * @param key
+ * @param dataMap
+ */
+ public void setCacheMap(final String key, final Map dataMap) {
+ if (dataMap != null) {
+ redisTemplate.opsForHash().putAll(key, dataMap);
+ }
+ }
+
+ /**
+ * 获得缓存的Map
+ *
+ * @param key
+ * @return
+ */
+ public Map getCacheMap(final String key) {
+ return redisTemplate.opsForHash().entries(key);
+ }
+
+ /**
+ * 往Hash中存入数据
+ *
+ * @param key Redis键
+ * @param hKey Hash键
+ * @param value 值
+ */
+ public void setCacheMapValue(final String key, final String hKey, final T value) {
+ redisTemplate.opsForHash().put(key, hKey, value);
+ }
+
+ /**
+ * 获取Hash中的数据
+ *
+ * @param key Redis键
+ * @param hKey Hash键
+ * @return Hash中的对象
+ */
+ public T getCacheMapValue(final String key, final String hKey) {
+ HashOperations opsForHash = redisTemplate.opsForHash();
+ return opsForHash.get(key, hKey);
+ }
+
+ /**
+ * 删除Hash中的数据
+ *
+ * @param key
+ * @param hkey
+ */
+ public void delCacheMapValue(final String key, final String hkey) {
+ HashOperations hashOperations = redisTemplate.opsForHash();
+ hashOperations.delete(key, hkey);
+ }
+
+ /**
+ * 获取多个Hash中的数据
+ *
+ * @param key Redis键
+ * @param hKeys Hash键集合
+ * @return Hash对象集合
+ */
+ public List getMultiCacheMapValue(final String key, final Collection