Compare commits

..

No commits in common. "cb04e54f2ecb8c8ba7c486c27ae2ee135f8648e8" and "06b2b04d079a22a8f2c38aaaa06720428ab4cf0f" have entirely different histories.

25 changed files with 737 additions and 6 deletions

View File

@ -9,6 +9,7 @@
<file url="file://$PROJECT_DIR$/bwie-common/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/bwie-gateway/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/bwie-gateway/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/bwie-models/bwie-user/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/bwie-models/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/bwie-models/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/bwie-mq/src/main/java" charset="UTF-8" />

View File

@ -1,5 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="EntryPointsManager">
<list size="1">
<item index="0" class="java.lang.String" itemvalue="lombok.NoArgsConstructor" />
</list>
</component>
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">

View File

@ -0,0 +1,17 @@
package com.bwie.auth;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;
/**
* @author 86175
*/
@EnableFeignClients
@SpringBootApplication
public class AuthApplication {
public static void main(String[] args) {
SpringApplication.run(AuthApplication.class,args);
}
}

View File

@ -0,0 +1,71 @@
package com.bwie.auth.controller;
import com.alibaba.fastjson.JSON;
import com.bwie.auth.service.AuthService;
import com.bwie.common.pojo.DTO.UserDto;
import com.bwie.common.pojo.User;
import com.bwie.common.pojo.vo.UserVo;
import com.bwie.common.result.Result;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
/**
* @author 86175
*/
@RestController
@RequestMapping("/auth")
@Log4j2
public class AuthController {
@Autowired
private AuthService authService;
@Autowired
private HttpServletRequest request;
/**
*
*
* @param userPhone
* @return
*/
@PostMapping("/sendCode/{userPhone}")
public Result sendCode(@PathVariable String userPhone) {
log.info("功能描述:发送验证码,请求URI:{},请求方式:{},请求参数:{}", request.getServletPath(), request.getMethod(), userPhone);
Result result = authService.sendCode(userPhone);
log.info("功能描述:发送验证码,请求URI:{},请求方式:{},响应结果:{}", request.getServletPath(), request.getMethod(), JSON.toJSONString(result));
return result;
}
/**
* +
*
*
*/
@PostMapping("/users")
public Result<UserDto> users(@RequestBody UserVo userVo) {
log.info("功能描述:登录进入停车页面,请求URI:{},请求方式:{},请求参数:{}", request.getServletPath(), request.getMethod(), userVo);
Result result = authService.users(userVo);
log.info("功能描述:登录进入停车页面,请求URI:{},请求方式:{},响应结果:{}", request.getServletPath(), request.getMethod(), JSON.toJSONString(result));
return result;
}
/**
*
*/
@PostMapping("/register")
public Result register(@RequestBody UserVo userVo){
log.info("功能描述:注册,请求URI:{},请求方式:{},请求参数:{}",request.getServletPath(),request.getMethod(),userVo);
Result result= authService.register(userVo);
log.info("功能描述:注册,请求URI:{},请求方式:{},响应结果:{}",request.getServletPath(),request.getMethod(), JSON.toJSONString(result));
return result;
}
}

View File

@ -0,0 +1,32 @@
package com.bwie.auth.fegin;
import com.bwie.common.pojo.User;
import com.bwie.common.pojo.vo.UserVo;
import com.bwie.common.result.Result;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
/**
* @author 86175
*/
@FeignClient("bwie-user")
public interface UserFeignService {
/**
*
*/
@PostMapping("/user/sendCode/{userPhone}")
public Result<User> sendCode(@PathVariable String userPhone);
@PostMapping("/user/findUserName/{userName}")
public Result<User> findUserName(@PathVariable String userName);
/**
*
*/
@PostMapping("/user/register")
public Result register(@RequestBody UserVo userVo);
}

View File

@ -0,0 +1,20 @@
package com.bwie.auth.service;
import com.bwie.common.pojo.vo.UserVo;
import com.bwie.common.result.Result;
import org.springframework.web.multipart.MultipartFile;
public interface AuthService {
Result sendCode(String userPhone);
/**
* @param userVo
* @return
*/
Result users(UserVo userVo);
Result register(UserVo userVo);
}

View File

@ -0,0 +1,98 @@
package com.bwie.auth.service.impl;
import com.alibaba.fastjson.JSON;
import com.bwie.auth.fegin.UserFeignService;
import com.bwie.auth.service.AuthService;
import com.bwie.common.constants.JwtConstants;
import com.bwie.common.constants.TokenConstants;
import com.bwie.common.pojo.DTO.UserDto;
import com.bwie.common.pojo.User;
import com.bwie.common.pojo.vo.UserVo;
import com.bwie.common.result.Result;
import com.bwie.common.utils.JwtUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.util.HashMap;
import java.util.Random;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
/**
* @author 86175
*
*/
@Service
public class AuthServiceImpl implements AuthService {
@Autowired
private UserFeignService userFeignService;
@Autowired
private StringRedisTemplate redisTemplate;
@Override
public Result sendCode(String userPhone) {
//feign调用查出sql数据
Result<User> userResult = userFeignService.sendCode(userPhone);
User user = userResult.getData();
if (user==null){
return Result.success("手机号不能为空");
}
String code="";
for (int i = 0; i < 4; i++) {
code+=new Random().nextInt(10);
}
redisTemplate.opsForValue().set(userPhone,code,15, TimeUnit.MINUTES);
return Result.success(code,"发送成功");
}
@Override
public Result users(UserVo userVo) {
//feign调用查出sql数据
Result<User> userName = userFeignService.sendCode(userVo.getUserPhone());
User user = userName.getData();
if (user==null){
return Result.error("该用户不存在,请先注册");
}
if (!userVo.getUserPhone().equals(user.getUserPhone())){
return Result.error("手机号不正确");
}
if (!redisTemplate.hasKey(userVo.getUserPhone())){
return Result.error("验证码已过期");
}
String code = redisTemplate.opsForValue().get(userVo.getUserPhone());
if (!code.equals(userVo.getCode())){
return Result.error("验证码失败");
}
HashMap<String, Object> map = new HashMap<>();
String userKey = UUID.randomUUID().toString();
map.put(JwtConstants.USER_KEY,userKey);
String token = JwtUtils.createToken(map);
redisTemplate.opsForValue().set(TokenConstants.LOGIN_TOKEN_KEY+userKey, JSON.toJSONString(user),30,TimeUnit.MINUTES);
UserDto userDto = new UserDto();
userDto.setToken(token);
userDto.setExpiredTime("token存储时间是30分钟");
if (user.getUserRole()==1){
return Result.success(userDto,"管理员登录");
}
return Result.success(userDto,"欢迎登录");
}
@Override
public Result register(UserVo userVo) {
userFeignService.register(userVo);
return Result.success("注册成功");
}
}

View File

@ -14,7 +14,7 @@ spring:
kafka:
producer:
# Kafka服务器
bootstrap-servers: 110.42.214.8:9092
bootstrap-servers: 111.229.234.119:9092
# 开启事务,必须在开启了事务的方法中发送,否则报错
transaction-id-prefix: kafkaTx-
# 发生错误后消息重发的次数开启事务必须设置大于0。
@ -35,7 +35,7 @@ spring:
consumer:
# Kafka服务器
bootstrap-servers: 110.42.214.8:9092
bootstrap-servers: 111.229.234.119:9092
group-id: firstGroup
# 自动提交的时间间隔 在spring boot 2.X 版本中这里采用的是值的类型为Duration 需要符合特定的格式如1S,1M,2H,5D
#auto-commit-interval: 2s
@ -90,10 +90,10 @@ spring:
nacos:
discovery:
# 服务注册地址
server-addr: 110.42.214.8:8848
server-addr: 111.229.234.119:8848
config:
# 配置中心地址
server-addr: 110.42.214.8:8848
server-addr: 111.229.234.119:8848
# 配置文件格式
file-extension: yml
# 共享配置

View File

@ -0,0 +1,18 @@
package com.bwie.common.pojo.DTO;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author 86175
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class UserDto {
private String token;
private String expiredTime;
}

View File

@ -0,0 +1,7 @@
package com.bwie.common.pojo;
public class Fang {
public void Fang(){
System.out.println("方十八帅比");
}
}

View File

@ -0,0 +1,4 @@
package com.bwie.common.pojo.vo;
public class CarVo {
}

View File

@ -0,0 +1,34 @@
package com.bwie.common.pojo.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author 86175
*
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class UserVo {
/*
*/
private String userName;
/*
*/
private String userPhone;
/*
*/
private String userImg;
private String userSex;
private String code;
}

View File

@ -0,0 +1,15 @@
package com.bwie.gateway;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* @author 86175
*/
@SpringBootApplication
public class GateWayApplication {
public static void main(String[] args) {
SpringApplication.run(GateWayApplication.class,args);
}
}

View File

@ -18,10 +18,10 @@ spring:
nacos:
discovery:
# 服务注册地址
server-addr: 110.42.214.8:8848
server-addr: 111.229.234.119:8848
config:
# 配置中心地址
server-addr: 110.42.214.8:8848
server-addr: 111.229.234.119:8848
# 配置文件格式
file-extension: yml
# 共享配置

View File

@ -0,0 +1,38 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store

View File

@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.bwie</groupId>
<artifactId>bwie-models</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>bwie-user</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- 系统公共 依赖 -->
<dependency>
<groupId>com.bwie</groupId>
<artifactId>bwie-common</artifactId>
</dependency>
<!-- SpringBoot Web-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- Druid -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.2.8</version>
</dependency>
<!-- Mysql Connector -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!-- Mybatis 依赖配置 -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.2.2</version>
</dependency>
<!-- Pagehelper -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.4.1</version>
</dependency>
<!-- test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,18 @@
package com.bwie.user;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* user
* @author 86175
*/
@SpringBootApplication
public class UserApplication {
public static void main(String[] args) {
SpringApplication.run(UserApplication.class,args);
}
}

View File

@ -0,0 +1,74 @@
package com.bwie.user.controller;
import com.alibaba.fastjson.JSON;
import com.bwie.common.pojo.User;
import com.bwie.common.pojo.vo.UserVo;
import com.bwie.common.result.Result;
import com.bwie.user.service.UserService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
/**
* @author 86175
*/
@RestController
@Log4j2
@RequestMapping("/user")
public class UserController {
@Autowired
private HttpServletRequest request;
@Autowired
private UserService userService;
/**
*
*/
@PostMapping("/sendCode/{userPhone}")
public Result<User> sendCode(@PathVariable String userPhone){
log.info("功能描述:查询后台是否存在这个手机号,请求URI:{},请求方式:{},请求参数:{}",request.getServletPath(),request.getMethod(),userPhone);
User user=userService.sendCode(userPhone);
Result result =Result.success(user);
log.info("功能描述:查询后台是否存在这个手机号,请求URI:{},请求方式:{},响应结果:{}",request.getServletPath(),request.getMethod(), JSON.toJSONString(result));
return result;
}
@PostMapping("/findUserName/{userName}")
public Result<User> findUserName(@PathVariable String userName){
log.info("功能描述:查询后台是否存在这个用户名,请求URI:{},请求方式:{},请求参数:{}",request.getServletPath(),request.getMethod(),userName);
User user=userService.findUserName(userName);
Result result =Result.success(user);
log.info("功能描述:查询后台是否存在这个用户名,请求URI:{},请求方式:{},响应结果:{}",request.getServletPath(),request.getMethod(), JSON.toJSONString(result));
return result;
}
/**
*
*/
@PostMapping("/register")
public Result register(@RequestBody UserVo userVo){
log.info("功能描述:当用户不存在时,请注册,请求URI:{},请求方式:{},请求参数:{}",request.getServletPath(),request.getMethod(),userVo);
Result result=userService.register(userVo);
log.info("功能描述:当用户不存在时,请注册,请求URI:{},请求方式:{},响应结果:{}",request.getServletPath(),request.getMethod(), JSON.toJSONString(result));
return result;
}
/**
*
*/
@PostMapping("/upload")
public Result upload(@RequestBody MultipartFile file){
log.info("功能描述:上传图片,请求URI:{},请求方式:{},请求参数:{}",request.getServletPath(),request.getMethod(),file);
Result result=userService.upload(file);
log.info("功能描述:上传图片,请求URI:{},请求方式:{},响应结果:{}",request.getServletPath(),request.getMethod(), JSON.toJSONString(result));
return result;
}
}

View File

@ -0,0 +1,26 @@
package com.bwie.user.mapper;
import com.bwie.common.pojo.User;
import com.bwie.common.pojo.vo.UserVo;
import org.apache.ibatis.annotations.Mapper;
/**
* @author 86175
* user
*/
@Mapper
public interface UserMapper {
/**
* sql
* @param userPhone
* @return
*/
User sendCode(String userPhone);
User findUserName(String userName);
void register(UserVo userVo);
}

View File

@ -0,0 +1,18 @@
package com.bwie.user.service;
import com.bwie.common.pojo.User;
import com.bwie.common.pojo.vo.UserVo;
import com.bwie.common.result.Result;
import org.springframework.web.multipart.MultipartFile;
public interface UserService {
User sendCode(String userPhone);
User findUserName(String userName);
Result register(UserVo userVo);
Result upload(MultipartFile file);
}

View File

@ -0,0 +1,60 @@
package com.bwie.user.service.impl;
import com.bwie.common.pojo.User;
import com.bwie.common.pojo.vo.UserVo;
import com.bwie.common.result.Result;
import com.bwie.user.mapper.UserMapper;
import com.bwie.user.service.UserService;
import com.bwie.user.util.FastUtil;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
/**
* @author 86175
* user
*/
@Service
@Log4j2
public class UserServiceImpl implements UserService {
@Autowired
private UserMapper userMapper;
@Autowired
private FastUtil fastUtil;
@Override
public User sendCode(String userPhone) {
return userMapper.sendCode(userPhone);
}
@Override
public User findUserName(String userName) {
return userMapper.findUserName(userName);
}
@Override
public Result register(UserVo userVo) {
userMapper.register(userVo);
return Result.success("注册成功");
}
@Override
public Result upload(MultipartFile file) {
String url="";
try {
url=fastUtil.upload(file);
log.info("上传地址为:"+url);
if (url==null){
return Result.error("上传失败");
}
} catch (Exception e) {
throw new RuntimeException(e);
}
return Result.success("http://111.229.234.119:8848/"+url,"上传成功");
}
}

View File

@ -0,0 +1,55 @@
package com.bwie.user.util;
import org.springframework.stereotype.Component;
import com.github.tobato.fastdfs.domain.fdfs.StorePath;
import com.github.tobato.fastdfs.service.FastFileStorageClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
/**
* @BelongsProject: 0107day02
* @BelongsPackage: com.bw.config
* @Author: zhupengfei
* @CreateTime: 2023-02-01 08:52
*/
@Component
public class FastUtil {
private static final Logger log = LoggerFactory.getLogger(FastUtil.class);
@Resource
private FastFileStorageClient storageClient ;
/**
*
*/
public String upload(MultipartFile multipartFile) throws Exception{
String originalFilename = multipartFile.getOriginalFilename().
substring(multipartFile.getOriginalFilename().
lastIndexOf(".") + 1);
StorePath storePath = this.storageClient.uploadImageAndCrtThumbImage(
multipartFile.getInputStream(),
multipartFile.getSize(),originalFilename , null);
return storePath.getFullPath() ;
}
/**
*
*/
public String deleteFile(String fileUrl) {
if (StringUtils.isEmpty(fileUrl)) {
log.info("fileUrl == >>文件路径为空...");
return "文件路径不能为空";
}
try {
StorePath storePath = StorePath.parseFromUrl(fileUrl);
storageClient.deleteFile(storePath.getGroup(), storePath.getPath());
} catch (Exception e) {
log.error(e.getMessage());
}
return "删除成功";
}
}

View File

@ -0,0 +1,30 @@
# Tomcat
server:
port: 9002
# Spring
spring:
main:
allow-circular-references: true
jackson:
date-format: yyyy-MM-dd HH:mm:ss
time-zone: GMT+8
application:
# 应用名称
name: bwie-user
profiles:
# 环境配置
active: dev
cloud:
nacos:
discovery:
# 服务注册地址
server-addr: 111.229.234.119:8848
config:
# 配置中心地址
server-addr: 111.229.234.119:8848
# 配置文件格式
file-extension: yml
# 共享配置
shared-configs:
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}

View File

@ -0,0 +1,26 @@
<?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.bwie.user.mapper.UserMapper">
<insert id="register">
INSERT INTO `dome02`.`t_user`
(
`user_name`,
`user_sex`,
`user_phone`,
`user_img`,
`user_role`,
`meal_id`,
`coupon_id`
)
VALUES
(#{userName}, #{userSex}, #{userPhone}, #{userImg}, 2, null, null);
</insert>
<select id="sendCode" resultType="com.bwie.common.pojo.User">
select * from t_user where user_phone=#{userPhone}
</select>
<select id="findUserName" resultType="com.bwie.common.pojo.User">
select * from t_user where user_name=#{userName}
</select>
</mapper>

View File

@ -10,6 +10,10 @@
</parent>
<artifactId>bwie-models</artifactId>
<packaging>pom</packaging>
<modules>
<module>bwie-user</module>
</modules>
<properties>
<maven.compiler.source>8</maven.compiler.source>