初始化

master
86199 2023-11-07 21:26:41 +08:00
commit 3aea2b6e09
73 changed files with 2748 additions and 0 deletions

38
.gitignore vendored 100644
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

8
.idea/.gitignore vendored 100644
View File

@ -0,0 +1,8 @@
# 默认忽略的文件
/shelf/
/workspace.xml
# 基于编辑器的 HTTP 客户端请求
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
<data-source source="LOCAL" name="lx@165.154.161.166" uuid="ea1eff1a-17b8-428c-8022-fb4a83dd2f3c">
<driver-ref>mysql.8</driver-ref>
<synchronize>true</synchronize>
<jdbc-driver>com.mysql.cj.jdbc.Driver</jdbc-driver>
<jdbc-url>jdbc:mysql://165.154.161.166:3306/lx</jdbc-url>
<working-dir>$ProjectFileDir$</working-dir>
</data-source>
</component>
</project>

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/wzy-auth/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/wzy-auth/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/wzy-common/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/wzy-common/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/wzy-gateway/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/wzy-gateway/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/wzy-models/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/wzy-models/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/wzy-models/wzy-es/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/wzy-models/wzy-product/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/wzy-models/wzy-product/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/wzy-models/wzy-user/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/wzy-models/wzy-user/src/main/resources" charset="UTF-8" />
</component>
</project>

14
.idea/misc.xml 100644
View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

6
.idea/vcs.xml 100644
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

67
pom.xml 100644
View File

@ -0,0 +1,67 @@
<?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>
<groupId>com.wzy</groupId>
<artifactId>wzy-11.7yk</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>wzy-auth</module>
<module>wzy-common</module>
<module>wzy-gateway</module>
<module>wzy-models</module>
<module>wzy-models/wzy-user</module>
<module>wzy-models/wzy-product</module>
<module>wzy-models/wzy-es</module>
</modules>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<!-- 规定SpringBoot版本 -->
<!-- 父级pom文件 主要用于规定项目依赖的各个版本,用于进行项目版本约束 -->
<parent>
<artifactId>spring-boot-starter-parent</artifactId>
<groupId>org.springframework.boot</groupId>
<version>2.6.2</version>
<relativePath/>
</parent>
<!-- 依赖声明 -->
<dependencyManagement>
<dependencies>
<!-- SpringCloud 微服务 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>2021.0.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- SpringCloud Alibaba 微服务 -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>2021.1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- Alibaba Nacos 配置 -->
<dependency>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-client</artifactId>
<version>2.0.4</version>
</dependency>
<!-- 公共模块 -->
<dependency>
<groupId>com.wzy</groupId>
<artifactId>wzy-common</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>

38
wzy-auth/.gitignore vendored 100644
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

31
wzy-auth/pom.xml 100644
View File

@ -0,0 +1,31 @@
<?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.wzy</groupId>
<artifactId>wzy-11.7yk</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>wzy-auth</artifactId>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- 项目公共 依赖 -->
<dependency>
<groupId>com.wzy</groupId>
<artifactId>wzy-common</artifactId>
</dependency>
<!-- SpringBoot Web-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
</project>

View File

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

View File

@ -0,0 +1,46 @@
package com.wzy.auth.controller;
import com.alibaba.fastjson.JSONObject;
import com.wzy.auth.service.AuthService;
import com.wzy.common.domain.User;
import com.wzy.common.domain.request.LoginRequest;
import com.wzy.common.domain.response.JwtResponse;
import com.wzy.common.result.Result;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
@RestController
@Log4j2
public class AuthController {
@Autowired
private AuthService authService;
@Autowired
private HttpServletRequest request;
@PostMapping("/login")
public Result<JwtResponse> login(@RequestBody LoginRequest loginRequest){
log.info("功能:登录,请求UIR:{},请求方式:{},请求参数:{}",request.getRequestURI(),
request.getMethod(),loginRequest);
Result<JwtResponse> result = authService.login(loginRequest);
log.info("功能:登录,请求UIR:{},请求方式:{},响应结果:{}",request.getRequestURI(),
request.getMethod(), JSONObject.toJSONString(result));
return result;
}
@GetMapping("/user/info")
public Result<User> userInfo(){
User user = authService.userInfo();
return Result.success(user);
}
@PostMapping("/logout")
public Result logout(){
authService.logout();
return Result.success();
}
}

View File

@ -0,0 +1,13 @@
package com.wzy.auth.feign;
import com.wzy.common.domain.User;
import com.wzy.common.result.Result;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
@FeignClient("wzy-user")
public interface UserFeignService {
@PostMapping("/login/{username}")
Result<User> login(@PathVariable String username);
}

View File

@ -0,0 +1,14 @@
package com.wzy.auth.service;
import com.wzy.common.domain.User;
import com.wzy.common.domain.request.LoginRequest;
import com.wzy.common.domain.response.JwtResponse;
import com.wzy.common.result.Result;
public interface AuthService {
Result<JwtResponse> login(LoginRequest loginRequest);
User userInfo();
void logout();
}

View File

@ -0,0 +1,72 @@
package com.wzy.auth.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.wzy.auth.feign.UserFeignService;
import com.wzy.auth.service.AuthService;
import com.wzy.common.constants.JwtConstants;
import com.wzy.common.constants.TokenConstants;
import com.wzy.common.domain.User;
import com.wzy.common.domain.request.LoginRequest;
import com.wzy.common.domain.response.JwtResponse;
import com.wzy.common.result.Result;
import com.wzy.common.utils.JwtUtils;
import com.wzy.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
@Service
public class AuthServiceImpl implements AuthService {
@Autowired
private UserFeignService userFeignService;
@Autowired
private RedisTemplate<String,String> redisTemplate;
@Autowired
private HttpServletRequest request;
@Override
public Result<JwtResponse> login(LoginRequest loginRequest) {
Result<User> byName = userFeignService.login(loginRequest.getUsername());
User data = byName.getData();
if (null == data) {
return Result.error("用户不存在!");
}
if (!loginRequest.getPassword().equals(data.getPassword())) {
return Result.error("密码错误!");
}
if (StringUtils.isAllBlank(loginRequest.getUsername(),loginRequest.getPassword())) {
return Result.error("用户或密码不能为空!");
}
String userKey = UUID.randomUUID().toString().replaceAll("-", "");
HashMap<String, Object> map = new HashMap<>();
map.put(JwtConstants.USER_KEY,userKey);
String token = JwtUtils.createToken(map);
redisTemplate.opsForValue().set(TokenConstants.LOGIN_TOKEN_KEY+userKey, JSONObject.toJSONString(data),30, TimeUnit.MINUTES);
JwtResponse jwtResponse = new JwtResponse();
jwtResponse.setExpireTime("30MIN");
jwtResponse.setToken(token);
return Result.success(jwtResponse);
}
@Override
public User userInfo() {
String token = request.getHeader(TokenConstants.TOKEN);
String userKey = JwtUtils.getUserKey(token);
String s = redisTemplate.opsForValue().get(TokenConstants.LOGIN_TOKEN_KEY + userKey);
return JSONObject.parseObject(s,User.class);
}
@Override
public void logout() {
String token = request.getHeader(TokenConstants.TOKEN);
String userKey = JwtUtils.getUserKey(token);
redisTemplate.delete(TokenConstants.LOGIN_TOKEN_KEY+userKey);
}
}

View File

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

38
wzy-common/.gitignore vendored 100644
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

116
wzy-common/pom.xml 100644
View File

@ -0,0 +1,116 @@
<?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.wzy</groupId>
<artifactId>wzy-11.7yk</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>wzy-common</artifactId>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- bootstrap 启动器 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
<!-- SpringCloud Alibaba Nacos -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<!-- SpringCloud Alibaba Nacos Config -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
<!-- SpringCloud Alibaba Sentinel -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
<!-- 负载均衡-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
</dependency>
<!-- SpringCloud Openfeign -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<!-- JWT -->
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.9.1</version>
</dependency>
<!-- Alibaba Fastjson -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.80</version>
</dependency>
<!-- SpringBoot Boot Redis -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<!-- Hibernate Validator -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<!-- Apache Lang3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<!-- lombok依赖 -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<!-- hutool -->
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.8.3</version>
</dependency>
<!-- 阿里大鱼 -->
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>dysmsapi20170525</artifactId>
<version>2.0.1</version>
</dependency>
<!-- oss 图片上传 -->
<dependency>
<groupId>com.aliyun.oss</groupId>
<artifactId>aliyun-sdk-oss</artifactId>
<version>3.12.0</version>
</dependency>
<!-- rabbitMQ -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
<!-- &lt;!&ndash;mq 依赖&ndash;&gt;
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>-->
<dependency>
<groupId>com.github.tobato</groupId>
<artifactId>fastdfs-client</artifactId>
<version>1.26.5</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,40 @@
package com.wzy.common.config;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
@Configuration
public class RedisConfig {
@Bean
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) {
RedisTemplate<String, Object> template = new RedisTemplate<>();
template.setConnectionFactory(factory);
Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new
Jackson2JsonRedisSerializer(Object.class);
ObjectMapper om = new ObjectMapper();
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
jackson2JsonRedisSerializer.setObjectMapper(om);
StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
// key采用String的序列化方式
template.setKeySerializer(stringRedisSerializer);
// hash的key也采用String的序列化方式
template.setHashKeySerializer(stringRedisSerializer);
// value序列化方式采用jackson
template.setValueSerializer(jackson2JsonRedisSerializer);
// hash的value序列化方式采用jackson
template.setHashValueSerializer(jackson2JsonRedisSerializer);
template.afterPropertiesSet();
return template;
}
}

View File

@ -0,0 +1,18 @@
package com.wzy.common.constants;
/**
* @description:
* @author DongZl
*/
public class Constants {
/**
*
*/
public static final Integer SUCCESS = 200;
public static final String SUCCESS_MSG = "操作成功";
/**
*
*/
public static final Integer ERROR = 500;
public static final String ERROR_MSG = "操作异常";
}

View File

@ -0,0 +1,29 @@
package com.wzy.common.constants;
/**
* @author DongZl
* @description: Jwt
*/
public class JwtConstants {
/**
* ID
*/
public static final String DETAILS_USER_ID = "user_id";
/**
*
*/
public static final String DETAILS_USERNAME = "username";
/**
*
*/
public static final String USER_KEY = "user_key";
/**
*
*/
public final static String SECRET = "abcdefghijklmnopqrstuvwxyz";
}

View File

@ -0,0 +1,24 @@
package com.wzy.common.constants;
/**
* @author DongZl
* @description:
*/
public class TokenConstants {
/**
* 720
*/
public final static long EXPIRATION = 720;
/**
* 120
*/
public final static long REFRESH_TIME = 120;
/**
*
*/
public final static String LOGIN_TOKEN_KEY = "login_tokens:";
/**
* token
*/
public static final String TOKEN = "token";
}

View File

@ -0,0 +1,18 @@
package com.wzy.common.domain;
import lombok.Data;
import java.util.Date;
@Data
public class Check {
private Integer checkId;
private Date checkDate;
private Double bargainPrice;
private Integer userId;
private String username;
private Integer productId;
private String productName;
}

View File

@ -0,0 +1,29 @@
package com.wzy.common.domain;
import lombok.Data;
import java.util.Date;
@Data
public class Product {
private String productId;
private String productName;
private String productType;
private String productPic;
private String productDesc;
private Double productPrice;
private Integer bargainNum;
private Double bargainPrice;
private Date bargainDate;
private Integer joinNum;
private Integer successNum;
private Integer beBeingNum;
private Integer status;
private Integer userId;
private Integer number;
private Integer ruleId;
private String ruleName;
private Integer ruleStatus;
}

View File

@ -0,0 +1,16 @@
package com.wzy.common.domain;
import lombok.Data;
@Data
public class Rule {
private Integer ruleId;
private Integer startNum;
private Integer endNum;
private Double startRange;
private Double sendRange;
private Integer typeId;
private String typeName;
private String ruleName;
private Integer ruleStatus;
}

View File

@ -0,0 +1,9 @@
package com.wzy.common.domain;
import lombok.Data;
@Data
public class Type {
private Integer typeId;
private String typeName;
}

View File

@ -0,0 +1,11 @@
package com.wzy.common.domain;
import lombok.Data;
@Data
public class User {
private Integer userId;
private String username;
private String password;
private Integer number;
}

View File

@ -0,0 +1,9 @@
package com.wzy.common.domain.request;
import lombok.Data;
@Data
public class LoginRequest {
private String username;
private String password;
}

View File

@ -0,0 +1,11 @@
package com.wzy.common.domain.request;
import lombok.Data;
@Data
public class Req {
private Integer pageNum=1;
private Integer pageSize=5;
private String productName;
private String productType;
}

View File

@ -0,0 +1,9 @@
package com.wzy.common.domain.response;
import lombok.Data;
@Data
public class JwtResponse {
private String token;
private String expireTime;
}

View File

@ -0,0 +1,34 @@
package com.wzy.common.result;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
/**
* @author DongZl
* @description:
*/
@Data
public class PageResult<T> implements Serializable {
/**
*
*/
private long total;
/**
*
*/
private List<T> list;
public PageResult() {
}
public PageResult(long total, List<T> list) {
this.total = total;
this.list = list;
}
public static <T> PageResult<T> toPageResult(long total, List<T> list){
return new PageResult(total , list);
}
public static <T> Result<PageResult<T>> toResult(long total, List<T> list){
return Result.success(PageResult.toPageResult(total,list));
}
}

View File

@ -0,0 +1,76 @@
package com.wzy.common.result;
import com.wzy.common.constants.Constants;
import lombok.Data;
import java.io.Serializable;
/**
* @author DongZl
* @description:
*/
@Data
public class Result<T> implements Serializable {
private static final long serialVersionUID = 1L;
/**
*
*/
public static final int SUCCESS = Constants.SUCCESS;
/**
*
*/
public static final int FAIL = Constants.ERROR;
/**
*
*/
private int code;
/**
*
*/
private String msg;
/**
*
*/
private T data;
public static <T> Result<T> success() {
return restResult(null, SUCCESS, Constants.SUCCESS_MSG);
}
public static <T> Result<T> success(T data) {
return restResult(data, SUCCESS, Constants.SUCCESS_MSG);
}
public static <T> Result<T> success(T data, String msg) {
return restResult(data, SUCCESS, msg);
}
public static <T> Result<T> error() {
return restResult(null, FAIL, Constants.ERROR_MSG);
}
public static <T> Result<T> error(String msg) {
return restResult(null, FAIL, msg);
}
public static <T> Result<T> error(T data) {
return restResult(data, FAIL, Constants.ERROR_MSG);
}
public static <T> Result<T> error(T data, String msg) {
return restResult(data, FAIL, msg);
}
public static <T> Result<T> error(int code, String msg) {
return restResult(null, code, msg);
}
private static <T> Result<T> restResult(T data, int code, String msg) {
Result<T> apiResult = new Result<>();
apiResult.setCode(code);
apiResult.setData(data);
apiResult.setMsg(msg);
return apiResult;
}
}

View File

@ -0,0 +1,55 @@
package com.wzy.common.utils;
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,109 @@
package com.wzy.common.utils;
import com.wzy.common.constants.JwtConstants;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import java.util.Map;
/**
* @description: Jwt
* @author DongZl
*/
public class JwtUtils {
/**
*
*/
public static String secret = JwtConstants.SECRET;
/**
*
*
* @param claims
* @return
*/
public static String createToken(Map<String, Object> claims){
String token = Jwts.builder().setClaims(claims).signWith(SignatureAlgorithm.HS512, secret).compact();
return token;
}
/**
*
*
* @param token
* @return
*/
public static Claims parseToken(String token) {
return Jwts.parser().setSigningKey(secret).parseClaimsJws(token).getBody();
}
/**
*
*
* @param token
* @return ID
*/
public static String getUserKey(String token){
Claims claims = parseToken(token);
return getValue(claims, JwtConstants.USER_KEY);
}
/**
*
*
* @param claims
* @return ID
*/
public static String getUserKey(Claims claims){
return getValue(claims, JwtConstants.USER_KEY);
}
/**
* ID
*
* @param token
* @return ID
*/
public static String getUserId(String token){
Claims claims = parseToken(token);
return getValue(claims, JwtConstants.DETAILS_USER_ID);
}
/**
* ID
*
* @param claims
* @return ID
*/
public static String getUserId(Claims claims){
return getValue(claims, JwtConstants.DETAILS_USER_ID);
}
/**
*
*
* @param token
* @return
*/
public static String getUserName(String token){
Claims claims = parseToken(token);
return getValue(claims, JwtConstants.DETAILS_USERNAME);
}
/**
*
*
* @param claims
* @return
*/
public static String getUserName(Claims claims){
return getValue(claims, JwtConstants.DETAILS_USERNAME);
}
/**
*
*
* @param claims
* @param key
* @return
*/
public static String getValue(Claims claims, String key){
Object obj = claims.get(key);
return obj == null ? "" : obj.toString();
}
}

View File

@ -0,0 +1,68 @@
package com.wzy.common.utils;
import org.springframework.util.AntPathMatcher;
import java.util.Collection;
import java.util.List;
/**
* @author DongZl
* @description:
*/
public class StringUtils extends org.apache.commons.lang3.StringUtils {
/**
* *
*
* @param object Object
* @return true false
*/
public static boolean isNull(Object object) {
return object == null;
}
/**
* * Collection ListSetQueue
*
* @param coll Collection
* @return true false
*/
public static boolean isEmpty(Collection<?> coll) {
return isNull(coll) || coll.isEmpty();
}
/**
*
*
* @param str
* @param strs
* @return
*/
public static boolean matches(String str, List<String> strs) {
if (isEmpty(str) || isEmpty(strs)) {
return false;
}
for (String pattern : strs) {
if (isMatch(pattern, str))
{
return true;
}
}
return false;
}
/**
* url:
* ? ;
* * ;
* ** ;
*
* @param pattern
* @param url url
* @return
*/
public static boolean isMatch(String pattern, String url) {
AntPathMatcher matcher = new AntPathMatcher();
return matcher.match(pattern, url);
}
}

View File

@ -0,0 +1,87 @@
package com.wzy.common.utils;
import com.alibaba.fastjson.JSONObject;
import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
import com.aliyun.teaopenapi.models.Config;
import lombok.extern.log4j.Log4j2;
import java.util.Map;
/**
*
*/
@Log4j2
public class TelSmsUtils {
/**
* AccessKeyaccessKeySecretAPI访
*/
private static String accessKeyId = "LTAIEVXszCmcd1T5";
private static String accessKeySecret = "2zHwciQXln8wExSEnkIYtRTSwLeRNd";
/**
* 访
*/
private static String endpoint = "dysmsapi.aliyuncs.com";
/**
*
*/
private static String signName = "登录验证";
/**
*
*/
private static Client client;
static {
log.info("初始化短信服务开始");
long startTime = System.currentTimeMillis();
try {
client = initClient();
log.info("初始化短信成功:{}",signName);
} catch (Exception e) {
e.printStackTrace();
}
log.info("初始化短信服务结束:耗时:{}MS",(System.currentTimeMillis()-startTime));
}
/**
*
* @return
* @throws Exception
*/
private static Client initClient() throws Exception{
Config config = new Config()
// 您的AccessKey ID
.setAccessKeyId(accessKeyId)
// 您的AccessKey Secret
.setAccessKeySecret(accessKeySecret);
// 访问的域名
config.endpoint = endpoint;
return new Client(config);
}
/**
*
* @param tel
* @param templateCode SMS_153991546
* @param sendDataMap
*/
public static String sendSms(String tel , String templateCode , Map<String,String> sendDataMap){
SendSmsRequest sendSmsRequest = new SendSmsRequest()
.setPhoneNumbers(tel)
.setSignName(signName)
.setTemplateCode(templateCode)
.setTemplateParam(JSONObject.toJSONString(sendDataMap));
SendSmsResponse sendSmsResponse = null;
try {
log.info("发送短信验证码:消息内容是:【{}】", JSONObject.toJSONString(sendDataMap));
sendSmsResponse = client.sendSms(sendSmsRequest);
} catch (Exception e) {
log.error("短信发送异常,手机号:【{}】,短信内容:【{}】,异常信息:【{}】", tel, sendDataMap, e);
}
return JSONObject.toJSONString(sendSmsResponse.getBody());
}
}

View File

@ -0,0 +1,3 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration = \
com.wzy.common.config.RedisConfig,\
com.wzy.common.utils.FastUtil

38
wzy-gateway/.gitignore vendored 100644
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,42 @@
<?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.wzy</groupId>
<artifactId>wzy-11.7yk</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>wzy-gateway</artifactId>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- 公共模块 -->
<dependency>
<groupId>com.wzy</groupId>
<artifactId>wzy-common</artifactId>
</dependency>
<!-- 网关依赖 -->
<!-- SpringCloud Gateway -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<!-- SpringCloud Alibaba Sentinel Gateway -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-sentinel-gateway</artifactId>
</dependency>
<!-- 引入阿里巴巴sentinel限流 依赖-->
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-spring-cloud-gateway-adapter</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,11 @@
package com.wzy.gateway;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class GatewayApplication {
public static void main(String[] args) {
SpringApplication.run(GatewayApplication.class);
}
}

View File

@ -0,0 +1,32 @@
package com.wzy.gateway.config;
import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import lombok.extern.log4j.Log4j2;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Configuration;
import java.util.ArrayList;
import java.util.List;
/**
* @description:
* @author DongZl
*/
@Configuration
@RefreshScope
@ConfigurationProperties(prefix = "ignore")
@Data
@Log4j2
public class IgnoreWhiteConfig {
/**
*
*/
private List<String> whites = new ArrayList<>();
public void setWhites(List<String> whites) {
log.info("加载网关路径白名单:{}", JSONObject.toJSONString(whites));
this.whites = whites;
}
}

View File

@ -0,0 +1,58 @@
package com.wzy.gateway.filters;
import com.wzy.common.constants.TokenConstants;
import com.wzy.common.utils.JwtUtils;
import com.wzy.common.utils.StringUtils;
import com.wzy.gateway.config.IgnoreWhiteConfig;
import com.wzy.gateway.utils.GatewayUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;
import java.util.List;
@Component
public class AuthFilter implements GlobalFilter, Ordered {
@Autowired
private IgnoreWhiteConfig ignoreWhiteConfig;
@Autowired
private RedisTemplate<String,String> redisTemplate;
@Override
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
List<String> whites = ignoreWhiteConfig.getWhites();
ServerHttpRequest request = exchange.getRequest();
String path = request.getURI().getPath();
if (StringUtils.matches(path,whites)) {
return chain.filter(exchange);
}
String token = request.getHeaders().getFirst(TokenConstants.TOKEN);
if (StringUtils.isEmpty(token)) {
return GatewayUtils.errorResponse(exchange,"token不能为空!");
}
try {
JwtUtils.parseToken(token);
} catch (Exception e) {
return GatewayUtils.errorResponse(exchange,"token不合法!");
}
String userKey = JwtUtils.getUserKey(token);
Boolean hasKey = redisTemplate.hasKey(TokenConstants.LOGIN_TOKEN_KEY + userKey);
if (Boolean.FALSE.equals(hasKey)) {
return GatewayUtils.errorResponse(exchange,"token失效!");
}
return chain.filter(exchange);
}
@Override
public int getOrder() {
return 0;
}
}

View File

@ -0,0 +1,98 @@
package com.wzy.gateway.utils;
import com.alibaba.fastjson.JSONObject;
import com.wzy.common.result.Result;
import com.wzy.common.utils.StringUtils;
import lombok.extern.log4j.Log4j2;
import org.springframework.core.io.buffer.DataBuffer;
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.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;
/**
* @author DongZl
* @description:
*/
@Log4j2
public class GatewayUtils {
/**
*
* @param mutate
* @param key
* @param value
*/
public static void addHeader(ServerHttpRequest.Builder mutate, String key, Object value) {
if (StringUtils.isEmpty(key)){
log.warn("添加请求头参数键不可以为空");
return;
}
if (value == null) {
log.warn("添加请求头参数:[{}]值为空",key);
return;
}
String valueStr = value.toString();
mutate.header(key, valueStr);
log.info("添加请求头参数成功 - 键:[{}] , 值:[{}]", key , value);
}
/**
*
* @param mutate
* @param key
*/
public static void removeHeader(ServerHttpRequest.Builder mutate, String key) {
if (StringUtils.isEmpty(key)){
log.warn("删除请求头参数键不可以为空");
return;
}
mutate.headers(httpHeaders -> httpHeaders.remove(key)).build();
log.info("删除请求头参数 - 键:[{}]",key);
}
/**
*
* @param exchange
* @param msg
* @return
*/
public static Mono<Void> errorResponse(ServerWebExchange exchange, String msg, HttpStatus httpStatus) {
ServerHttpResponse response = exchange.getResponse();
//设置HTTP响应头状态
response.setStatusCode(httpStatus);
//设置HTTP响应头文本格式
response.getHeaders().add(HttpHeaders.CONTENT_TYPE, "application/json");
//定义响应内容
Result<?> result = Result.error(msg);
String resultJson = JSONObject.toJSONString(result);
log.error("[鉴权异常处理]请求路径:[{}],异常信息:[{}],响应结果:[{}]", exchange.getRequest().getPath(), msg, resultJson);
DataBuffer dataBuffer = response.bufferFactory().wrap(resultJson.getBytes());
//进行响应
return response.writeWith(Mono.just(dataBuffer));
}
/**
*
* @param exchange
* @param msg
* @return
*/
public static Mono<Void> errorResponse(ServerWebExchange exchange, String msg) {
ServerHttpResponse response = exchange.getResponse();
//设置HTTP响应头状态
response.setStatusCode(HttpStatus.OK);
//设置HTTP响应头文本格式
response.getHeaders().add(HttpHeaders.CONTENT_TYPE, "application/json");
//定义响应内容
Result<?> result = Result.error(msg);
String resultJson = JSONObject.toJSONString(result);
log.error("[鉴权异常处理]请求路径:[{}],异常信息:[{}],响应结果:[{}]", exchange.getRequest().getPath(), msg, resultJson);
DataBuffer dataBuffer = response.bufferFactory().wrap(resultJson.getBytes());
//进行响应
return response.writeWith(Mono.just(dataBuffer));
}
}

View File

@ -0,0 +1,29 @@
# Tomcat
server:
port: 18080
# Spring
spring:
application:
# 应用名称
name: wzy-gateway
profiles:
# 环境配置
active: dev
main:
# 允许使用循环引用
allow-circular-references: true
# 允许定义相同的bean对象 去覆盖原有的
allow-bean-definition-overriding: true
cloud:
nacos:
discovery:
# 服务注册地址
server-addr: 165.154.161.166:8848
config:
# 配置中心地址
server-addr: 165.154.161.166:8848
# 配置文件格式
file-extension: yml
# 共享配置
shared-configs:
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}

38
wzy-models/.gitignore vendored 100644
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

20
wzy-models/pom.xml 100644
View File

@ -0,0 +1,20 @@
<?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.wzy</groupId>
<artifactId>wzy-11.7yk</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>wzy-models</artifactId>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>

38
wzy-models/wzy-es/.gitignore vendored 100644
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,38 @@
<?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.wzy</groupId>
<artifactId>wzy-11.7yk</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>wzy-es</artifactId>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.wzy</groupId>
<artifactId>wzy-common</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,15 @@
package com.wzy.es;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.scheduling.annotation.EnableScheduling;
@SpringBootApplication
@EnableFeignClients
@EnableScheduling
public class EsApplication {
public static void main(String[] args) {
SpringApplication.run(EsApplication.class);
}
}

View File

@ -0,0 +1,25 @@
package com.wzy.es.config;
import lombok.Data;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
@ConfigurationProperties(prefix = "es")
@Data
public class InitEsRes {
private String host;
private int port;
private String scheme;
@Bean
public RestHighLevelClient restHighLevelClient(){
return new RestHighLevelClient(
RestClient.builder(new HttpHost(host,port,scheme))
);
}
}

View File

@ -0,0 +1,34 @@
package com.wzy.es.controller;
import com.alibaba.fastjson.JSONObject;
import com.wzy.common.domain.request.Req;
import com.wzy.common.result.Result;
import com.wzy.es.service.EsService;
import lombok.extern.log4j.Log4j2;
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.RestController;
import javax.servlet.http.HttpServletRequest;
@RestController
@Log4j2
public class EsController {
@Autowired
private EsService esService;
@Autowired
private HttpServletRequest request;
@PostMapping("/list")
public Result list(@RequestBody Req req){
log.info("功能:ES列表,请求UIR:{},请求方式:{},请求参数:{}",request.getRequestURI(),
request.getMethod(),req);
Result result = esService.list(req);
log.info("功能:ES列表,请求UIR:{},请求方式:{},响应结果:{}",request.getRequestURI(),
request.getMethod(), JSONObject.toJSONString(result));
return result;
}
}

View File

@ -0,0 +1,14 @@
package com.wzy.es.feign;
import com.wzy.common.domain.Product;
import com.wzy.common.result.Result;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import java.util.List;
@FeignClient("wzy-product")
public interface ProductFeignService {
@GetMapping("/findProductList")
Result<List<Product>> findProductList();
}

View File

@ -0,0 +1,8 @@
package com.wzy.es.service;
import com.wzy.common.domain.request.Req;
import com.wzy.common.result.Result;
public interface EsService {
Result list(Req req);
}

View File

@ -0,0 +1,83 @@
package com.wzy.es.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.wzy.common.domain.Product;
import com.wzy.common.domain.request.Req;
import com.wzy.common.result.PageResult;
import com.wzy.common.result.Result;
import com.wzy.common.utils.StringUtils;
import com.wzy.es.service.EsService;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.text.Text;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.SearchHits;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder;
import org.elasticsearch.search.fetch.subphase.highlight.HighlightField;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Map;
@Service
public class EsServiceImpl implements EsService {
@Autowired
private RestHighLevelClient restHighLevelClient;
private static final String INDEX_NAME = "product";
@Override
public Result list(Req req) {
long total = 0;
ArrayList<Product> list = new ArrayList<>();
try {
SearchRequest searchRequest = new SearchRequest(INDEX_NAME);
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
if (StringUtils.isNotEmpty(req.getProductName())) {
boolQueryBuilder.must(QueryBuilders.matchQuery("productName",req.getProductName()));
}
if (StringUtils.isNotEmpty(req.getProductType())) {
boolQueryBuilder.must(QueryBuilders.matchQuery("productType",req.getProductType()));
}
searchSourceBuilder.query(boolQueryBuilder);
HighlightBuilder highlightBuilder = new HighlightBuilder();
highlightBuilder.field("goodsName").preTags("<font colour=red>").postTags("</font>");
searchSourceBuilder.highlighter(highlightBuilder);
searchRequest.source(searchSourceBuilder);
SearchResponse search = restHighLevelClient.search(searchRequest, RequestOptions.DEFAULT);
SearchHits hits = search.getHits();
total = hits.getTotalHits().value;
for (SearchHit hit : hits.getHits()) {
String sourceAsString = hit.getSourceAsString();
Product product = JSONObject.parseObject(sourceAsString, Product.class);
product.setProductId(hit.getId());
Map<String, HighlightField> highlightFields = hit.getHighlightFields();
if (null != highlightFields) {
HighlightField highlightField = highlightFields.get("productName");
if (null != highlightField) {
String str = "";
for (Text fragment : highlightField.fragments()) {
str += fragment;
}
product.setProductName(str);
}
}
list.add(product);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
return PageResult.toResult(total,list);
}
}

View File

@ -0,0 +1,69 @@
package com.wzy.es.sync;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SimplePropertyPreFilter;
import com.wzy.common.domain.Product;
import com.wzy.common.result.Result;
import com.wzy.es.feign.ProductFeignService;
import lombok.extern.log4j.Log4j2;
import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest;
import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheResponse;
import org.elasticsearch.action.bulk.BulkRequest;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.xcontent.XContentType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Component
@Log4j2
public class EsSync {
@Autowired
private ProductFeignService productFeignService;
@Autowired
private RestHighLevelClient restHighLevelClient;
private static final String INDEX_NAME = "product";
@Scheduled(cron = "0 * * * * *")
public void runEs() throws IOException {
Result<List<Product>> productList = productFeignService.findProductList();
List<Product> data = productList.getData();
long l = System.currentTimeMillis();
if (!CollectionUtils.isEmpty(data)) {
BulkRequest bulkRequest = new BulkRequest();
data.forEach(item -> {
SimplePropertyPreFilter filter = new SimplePropertyPreFilter();
filter.getExcludes().addAll(new ArrayList<String>(){{
add("productId");
}});
bulkRequest.add(
new IndexRequest(INDEX_NAME)
.source(JSON.toJSONString(item,filter), XContentType.JSON)
.id(item.getProductId())
);
});
restHighLevelClient.bulk(bulkRequest, RequestOptions.DEFAULT);
log.info("功能:同步ES消耗:{}毫秒",(System.currentTimeMillis())-l);
ClearIndicesCacheRequest cacheRequest = new ClearIndicesCacheRequest();
cacheRequest.indices(INDEX_NAME);
cacheRequest.fieldDataCache(true);
cacheRequest.queryCache(true);
ClearIndicesCacheResponse cacheResponse = restHighLevelClient.indices().clearCache(cacheRequest, RequestOptions.DEFAULT);
log.info("清除ES索引缓存成功"+cacheResponse);
Date date = new Date();
log.info("当前时间:"+date);
}
}
}

View File

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

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,55 @@
<?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.wzy</groupId>
<artifactId>wzy-11.7yk</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>wzy-product</artifactId>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- 系统公共 依赖 -->
<dependency>
<groupId>com.wzy</groupId>
<artifactId>wzy-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>
</dependencies>
</project>

View File

@ -0,0 +1,13 @@
package com.wzy.product;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;
@SpringBootApplication
@EnableScheduling
public class ProductApplication {
public static void main(String[] args) {
SpringApplication.run(ProductApplication.class);
}
}

View File

@ -0,0 +1,115 @@
package com.wzy.product.controller;
import com.alibaba.fastjson.JSONObject;
import com.wzy.common.domain.Check;
import com.wzy.common.domain.Product;
import com.wzy.common.domain.Rule;
import com.wzy.common.domain.User;
import com.wzy.common.result.Result;
import com.wzy.product.service.ProductService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
@RestController
@Log4j2
public class ProductController {
@Autowired
private ProductService productService;
@Autowired
private HttpServletRequest request;
@GetMapping("/findProductList")
public Result<List<Product>> findProductList(){
List<Product> findProductList = productService.findProductList();
return Result.success(findProductList);
}
@GetMapping("/ruleList")
@Scheduled(cron = "0 * * * * *")
public Result<List<Rule>> ruleList(){
List<Rule> ruleList = productService.ruleList();
return Result.success(ruleList);
}
@PostMapping("/ruleSave")
public Result<String> ruleSave(@RequestBody Rule rule){
log.info("功能:新增规则,请求URI:{},请求方式:{},请求参数:{}",request.getRequestURI(),
request.getMethod(),rule);
Result result = productService.ruleSave(rule);
log.info("功能:新增规则,请求URI:{},请求方式:{},响应结果:{}",request.getRequestURI(),
request.getMethod(), JSONObject.toJSONString(result));
return result;
}
@GetMapping("/choiceProduct")
public Result<List<Product>> choiceProduct(){
List<Product> choiceProduct = productService.choiceProduct();
return Result.success(choiceProduct);
}
@PostMapping("/productSave")
public Result<String> productSave(@RequestBody Product product){
log.info("功能:新增商品,请求URI:{},请求方式:{},请求参数:{}",request.getRequestURI(),
request.getMethod(),product);
Result result = productService.productSave(product);
log.info("功能:新增商品,请求URI:{},请求方式:{},响应结果:{}",request.getRequestURI(),
request.getMethod(), JSONObject.toJSONString(result));
return result;
}
@PostMapping("/startUp/{productId}")
public Result<String> startUp(@PathVariable Integer productId){
Result result = productService.startUp(productId);
return result;
}
@PostMapping("/stopUp/{productId}")
public Result<String> stopUp(@PathVariable Integer productId){
Result result = productService.stopUp(productId);
return result;
}
@PostMapping("/upload")
public Result upload(@RequestParam("file")MultipartFile multipartFile){
Result result = productService.upload(multipartFile);
return result;
}
@PostMapping("/updateProduct")
public Result<String> updateProduct(@RequestBody Product product){
Result result = productService.updateProduct(product);
return result;
}
@PostMapping("/updateUser")
public Result<String> updateUser(@RequestBody User user){
Result result = productService.updateUser(user);
return result;
}
@PostMapping("/checkAdd")
public Result<String> checkAdd(@RequestBody Check check){
Result result = productService.checkAdd(check);
return result;
}
@GetMapping("/checkList")
public Result<List<Check>> checkList(){
List<Check> checkList = productService.checkList();
return Result.success(checkList);
}
@PostMapping("/updateUser1")
public Result<String> updateUser1(@RequestBody User user){
Result result = productService.updateUser1(user);
return result;
}
}

View File

@ -0,0 +1,36 @@
package com.wzy.product.mapper;
import com.wzy.common.domain.Check;
import com.wzy.common.domain.Product;
import com.wzy.common.domain.Rule;
import com.wzy.common.domain.User;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface ProductMapper {
List<Product> findProductList();
List<Rule> ruleList();
int ruleSave(Rule rule);
List<Product> choiceProduct();
int productSave(Product product);
int startUp(Integer productId);
int stopUp(Integer productId);
int updateProduct(Product product);
int updateUser(User user);
int checkAdd(Check check);
List<Check> checkList();
int updateUser1(User user);
}

View File

@ -0,0 +1,38 @@
package com.wzy.product.service;
import com.wzy.common.domain.Check;
import com.wzy.common.domain.Product;
import com.wzy.common.domain.Rule;
import com.wzy.common.domain.User;
import com.wzy.common.result.Result;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
public interface ProductService {
List<Product> findProductList();
List<Rule> ruleList();
Result ruleSave(Rule rule);
List<Product> choiceProduct();
Result productSave(Product product);
Result startUp(Integer productId);
Result stopUp(Integer productId);
Result upload(MultipartFile multipartFile);
Result updateProduct(Product product);
Result updateUser(User user);
Result checkAdd(Check check);
List<Check> checkList();
Result updateUser1(User user);
}

View File

@ -0,0 +1,158 @@
package com.wzy.product.service.impl;
import cn.hutool.core.util.RandomUtil;
import com.wzy.common.domain.Check;
import com.wzy.common.domain.Product;
import com.wzy.common.domain.Rule;
import com.wzy.common.domain.User;
import com.wzy.common.result.Result;
import com.wzy.common.utils.FastUtil;
import com.wzy.common.utils.StringUtils;
import com.wzy.product.mapper.ProductMapper;
import com.wzy.product.service.ProductService;
import org.apache.commons.lang3.RandomUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
import java.util.concurrent.TimeUnit;
@Service
public class ProductServiceImpl implements ProductService {
@Autowired
private ProductMapper productMapper;
@Autowired
private RedisTemplate<String,String> redisTemplate;
@Autowired
private FastUtil fastUtil;
@Override
public List<Product> findProductList() {
return productMapper.findProductList();
}
@Override
public List<Rule> ruleList() {
return productMapper.ruleList();
}
@Override
public Result ruleSave(Rule rule) {
int code = RandomUtils.nextInt(10, 30);
redisTemplate.opsForValue().set("code", String.valueOf(code),1,TimeUnit.MINUTES);
rule.setStartNum(code);
if (StringUtils.isEmpty(rule.getRuleName())) {
return Result.error("规则名称不能为空!");
}
if (rule.getStartNum() > rule.getEndNum()) {
return Result.error("截止次数不可小于起始次数!");
}
int i = productMapper.ruleSave(rule);
if (i > 0) {
return Result.success(i,"规则新增成功!");
} else {
return Result.error("请求失败");
}
}
@Override
public List<Product> choiceProduct() {
return productMapper.choiceProduct();
}
@Override
public Result productSave(Product product) {
int i = productMapper.productSave(product);
if (i > 0) {
return Result.success(i,"新增成功");
} else {
return Result.error("请求失败");
}
}
@Override
public Result startUp(Integer productId) {
int i = productMapper.startUp(productId);
if (i > 0) {
return Result.success(i,"开启砍价模式");
} else {
return Result.error("请求失败");
}
}
@Override
public Result stopUp(Integer productId) {
int i = productMapper.stopUp(productId);
if (i > 0) {
return Result.success(i,"关闭砍价模式");
} else {
return Result.error("请求失败");
}
}
@Override
public Result upload(MultipartFile multipartFile) {
String upload = null;
try {
upload = fastUtil.upload(multipartFile);
if (null == upload) {
return Result.error("上传失败");
}
} catch (Exception e) {
throw new RuntimeException(e);
}
return Result.success("http://165.154.161.166:8888/" + upload,"上传成功");
}
@Override
public Result updateProduct(Product product) {
double v = RandomUtils.nextDouble(0.1, 1);
product.setBargainPrice(v);
int i = productMapper.updateProduct(product);
if (i > 0) {
return Result.success(i,"砍价成功");
} else {
return Result.error("请求失败");
}
}
@Override
public Result updateUser(User user) {
int i = productMapper.updateUser(user);
if (i > 0) {
return Result.success(i,"砍价次数更新成功");
} else {
return Result.error("请求失败");
}
}
@Override
public Result checkAdd(Check check) {
double v = RandomUtils.nextDouble(0.1, 1);
check.setBargainPrice(v);
int i = productMapper.checkAdd(check);
if (i > 0) {
return Result.success(i,"砍价记录添加成功");
} else {
return Result.error("请求失败");
}
}
@Override
public List<Check> checkList() {
return productMapper.checkList();
}
@Override
public Result updateUser1(User user) {
int i = productMapper.updateUser1(user);
if (i > 0) {
return Result.success(i,"砍价次数更新成功");
} else {
return Result.error("请求失败");
}
}
}

View File

@ -0,0 +1,42 @@
# 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: wzy-product
profiles:
# 环境配置
active: dev
cloud:
nacos:
discovery:
# 服务注册地址
server-addr: 165.154.161.166:8848
config:
# 配置中心地址
server-addr: 165.154.161.166:8848
# 配置文件格式
file-extension: yml
# 共享配置
shared-configs:
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
fdfs:
so-timeout: 1500 # socket 连接时长
connect-timeout: 600 # 连接 tracker 服务器超时时长
# 这两个是你服务器的 IP 地址,注意 23000 端口也要打开阿里云服务器记得配置安全组。tracker 要和 stroage 服务进行交流
tracker-list: 165.154.161.166:22122
web-server-url: 165.154.161.166:8888
pool:
jmx-enabled: false
# 生成缩略图
thumb-image:
height: 500
width: 500

View File

@ -0,0 +1,79 @@
<?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.wzy.product.mapper.ProductMapper">
<insert id="ruleSave">
insert into t_rule (start_num, end_num, start_range, send_range, type_id, rule_name)
values (
#{startNum},
#{endNum},
#{startRange},
#{sendRange},
#{typeId},
#{ruleName}
)
</insert>
<insert id="productSave">
insert into t_product (product_name, product_type, product_pic, product_desc, product_price,
bargain_num, bargain_price, bargain_date, join_num, success_num, be_being_num, status,
user_id, rule_id)
values (
#{productName},
#{productType},
#{productPic},
#{productDesc},
#{productPrice},
#{bargainNum},
#{bargainPrice},
now(),
5000,
300,
2000,
2,
1,
#{ruleId}
)
</insert>
<insert id="checkAdd">
insert into t_check (check_date, user_id, bargain_price, product_id)
values (
#{checkDate},
#{userId},
#{bargainPrice},
#{productId}
)
</insert>
<update id="startUp">
update t_product set status=1 where product_id=#{productId}
</update>
<update id="stopUp">
update t_product set status=2 where product_id=#{productId}
</update>
<update id="updateProduct">
update t_product set bargain_num=bargain_num+1,bargain_price=bargain_price-#{bargainPrice} where product_id=#{productId}
</update>
<update id="updateUser">
update t_user set number=number-1 where user_id=#{userId}
</update>
<update id="updateUser1">
update t_user set number=number+1 where user_id=#{userId}
</update>
<select id="findProductList" resultType="com.wzy.common.domain.Product">
select p.*,u.number,r.rule_name
from t_product p left join t_user u on p.user_id = u.user_id
left join t_rule r on p.rule_id = r.rule_id
</select>
<select id="ruleList" resultType="com.wzy.common.domain.Rule">
select r.*,t.type_name
from t_rule r left join t_type t on r.type_id = t.type_id
</select>
<select id="choiceProduct" resultType="com.wzy.common.domain.Product">
select p.*,u.number
from t_product p left join t_user u on p.user_id = u.user_id where p.status=1
</select>
<select id="checkList" resultType="com.wzy.common.domain.Check">
select c.*,u.username,p.product_name
from t_check c left join t_user u on c.user_id = u.user_id
left join t_product p on c.product_id = p.product_id
</select>
</mapper>

38
wzy-models/wzy-user/.gitignore vendored 100644
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,55 @@
<?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.wzy</groupId>
<artifactId>wzy-11.7yk</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>wzy-user</artifactId>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- 系统公共 依赖 -->
<dependency>
<groupId>com.wzy</groupId>
<artifactId>wzy-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>
</dependencies>
</project>

View File

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

View File

@ -0,0 +1,35 @@
package com.wzy.user.controller;
import com.alibaba.fastjson.JSONObject;
import com.wzy.common.domain.User;
import com.wzy.common.result.Result;
import com.wzy.user.service.UserService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
@RestController
@Log4j2
public class UserController {
@Autowired
private UserService userService;
@Autowired
private HttpServletRequest request;
@PostMapping("/login/{username}")
public Result<User> login(@PathVariable String username){
log.info("功能:登录,请求UIR:{},请求方式:{},请求参数:{}",request.getRequestURI(),
request.getMethod(),username);
User user = userService.login(username);
Result<User> result = Result.success(user);
log.info("功能:登录,请求UIR:{},请求方式:{},响应结果:{}",request.getRequestURI(),
request.getMethod(), JSONObject.toJSONString(result));
return result;
}
}

View File

@ -0,0 +1,9 @@
package com.wzy.user.mapper;
import com.wzy.common.domain.User;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface UserMapper {
User login(String username);
}

View File

@ -0,0 +1,7 @@
package com.wzy.user.service;
import com.wzy.common.domain.User;
public interface UserService {
User login(String username);
}

View File

@ -0,0 +1,18 @@
package com.wzy.user.service.impl;
import com.wzy.common.domain.User;
import com.wzy.user.mapper.UserMapper;
import com.wzy.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class UserServiceImpl implements UserService {
@Autowired
private UserMapper userMapper;
@Override
public User login(String username) {
return userMapper.login(username);
}
}

View File

@ -0,0 +1,42 @@
# Tomcat
server:
port: 9004
# Spring
spring:
main:
allow-circular-references: true
jackson:
date-format: yyyy-MM-dd HH:mm:ss
time-zone: GMT+8
application:
# 应用名称
name: wzy-user
profiles:
# 环境配置
active: dev
cloud:
nacos:
discovery:
# 服务注册地址
server-addr: 165.154.161.166:8848
config:
# 配置中心地址
server-addr: 165.154.161.166:8848
# 配置文件格式
file-extension: yml
# 共享配置
shared-configs:
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
fdfs:
so-timeout: 1500 # socket 连接时长
connect-timeout: 600 # 连接 tracker 服务器超时时长
# 这两个是你服务器的 IP 地址,注意 23000 端口也要打开阿里云服务器记得配置安全组。tracker 要和 stroage 服务进行交流
tracker-list: 165.154.161.166:22122
web-server-url: 165.154.161.166:8888
pool:
jmx-enabled: false
# 生成缩略图
thumb-image:
height: 500
width: 500

View File

@ -0,0 +1,9 @@
<?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.wzy.user.mapper.UserMapper">
<select id="login" resultType="com.wzy.common.domain.User">
select *
from t_user where username=#{username}
</select>
</mapper>