1.初始化
commit
44201dc84e
|
@ -0,0 +1,35 @@
|
|||
target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
!**/src/main/**/target/
|
||||
!**/src/test/**/target/
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
*.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
|
|
@ -0,0 +1,160 @@
|
|||
<?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.muyu</groupId>
|
||||
<artifactId>h6-exam19</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>cloud-common</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>
|
||||
<!-- 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>
|
||||
<!-- Alibaba Fastjson2 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.fastjson2</groupId>
|
||||
<artifactId>fastjson2</artifactId>
|
||||
<version>2.0.50</version>
|
||||
</dependency>
|
||||
<!-- SpringBoot Boot Redis -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||
</dependency>
|
||||
<!-- Druid -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-spring-boot-starter</artifactId>
|
||||
<version>1.2.8</version>
|
||||
</dependency>
|
||||
<!-- Mysql Connector -->
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</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>
|
||||
<!-- 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>
|
||||
<!-- 阿里大鱼 -->
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>dysmsapi20170525</artifactId>
|
||||
<version>2.0.1</version>
|
||||
</dependency>
|
||||
<!-- rabbitMQ依赖-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-amqp</artifactId>
|
||||
<version>3.2.6</version>
|
||||
</dependency>
|
||||
<!--fdfs上传图片-->
|
||||
<dependency>
|
||||
<groupId>com.github.tobato</groupId>
|
||||
<artifactId>fastdfs-client</artifactId>
|
||||
<version>1.26.5</version>
|
||||
</dependency>
|
||||
<!-- oss -->
|
||||
<dependency>
|
||||
<groupId>com.aliyun.oss</groupId>
|
||||
<artifactId>aliyun-sdk-oss</artifactId>
|
||||
<version>3.12.0</version>
|
||||
</dependency>
|
||||
<!-- swagger3 -->
|
||||
<dependency>
|
||||
<groupId>io.swagger.core.v3</groupId>
|
||||
<artifactId>swagger-annotations-jakarta</artifactId>
|
||||
<version>2.2.8</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
<!--锁依赖-->
|
||||
<dependency>
|
||||
<groupId>redis.clients</groupId>
|
||||
<artifactId>jedis</artifactId>
|
||||
<version>3.7.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.redisson</groupId>
|
||||
<artifactId>redisson</artifactId>
|
||||
<version>3.16.0</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
</project>
|
|
@ -0,0 +1,22 @@
|
|||
package com.muyu.common.config;
|
||||
|
||||
import com.muyu.common.result.Result;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
|
||||
/**
|
||||
* @Author: xe ya ru
|
||||
* @Description: 异常处理器
|
||||
* @Data 2024/7/10
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Log4j2
|
||||
@RestControllerAdvice
|
||||
public class ExceptionHandler {
|
||||
|
||||
@org.springframework.web.bind.annotation.ExceptionHandler(value = RuntimeException.class)
|
||||
public Result<String> runtimeExceptionHandler(RuntimeException e) {
|
||||
log.error("程序请求异常:[{}]",e.getMessage(), e);
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package com.muyu.common.constant;
|
||||
|
||||
/**
|
||||
* @description: 系统常量
|
||||
* @author xie ya ru
|
||||
* @Data 2024/7/10
|
||||
*/
|
||||
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 = "操作异常";
|
||||
|
||||
/**
|
||||
* 自动识别json对象白名单配置(仅允许解析的包名,范围越小越安全)
|
||||
*/
|
||||
public static final String[] JSON_WHITELIST_STR = {"org.springframework", "com.muyu"};
|
||||
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package com.muyu.common.constant;
|
||||
|
||||
/**
|
||||
* @author xie ya ru
|
||||
* @description: Jwt常量
|
||||
* @Data 2024/7/10
|
||||
*/
|
||||
public class JwtConstants {
|
||||
/**
|
||||
* 用户ID字段
|
||||
*/
|
||||
public static final String DETAILS_USER_ID = "user_id";
|
||||
|
||||
/**
|
||||
* 用户名字段
|
||||
*/
|
||||
public static final String DETAILS_USERNAME = "username";
|
||||
|
||||
/*
|
||||
用户手机号
|
||||
*/
|
||||
public static final String DETAILS_USERPHONE ="userPhone";
|
||||
|
||||
/**
|
||||
* 用户标识
|
||||
*/
|
||||
public static final String USER_KEY = "user_key";
|
||||
|
||||
/**
|
||||
* 令牌秘钥
|
||||
*/
|
||||
public final static String SECRET = "abcdefghijklmnopqrstuvwxyz";
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package com.muyu.common.constant;
|
||||
|
||||
/**
|
||||
* @ClassName:
|
||||
* @Description: 消息队列名称常量
|
||||
* @Data 2024/7/10
|
||||
* @Author: xie ya ru
|
||||
*/
|
||||
public class MQQueueNameConstants {
|
||||
|
||||
/**
|
||||
* 短信队列名称
|
||||
*/
|
||||
public static final String SMS_QUEUE_NAME = "SEND_SMS_QUEUE";
|
||||
public static final String SMS_PHONE_NAME = "SEND_SMS_QUEUE";
|
||||
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package com.muyu.common.constant;
|
||||
|
||||
/**
|
||||
* @Author: xie ya ru
|
||||
* @Description: 服务名称常量
|
||||
* @Data 2024/7/10
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public class ServerNameConstants {
|
||||
|
||||
/**
|
||||
* 系统服务服务名称
|
||||
*/
|
||||
public final static String SYSTEM_NAME = "system-server";
|
||||
public final static String GOODS_NAME = "system-goods";
|
||||
|
||||
/**
|
||||
* 系统API远程调用前缀
|
||||
*/
|
||||
public static interface SystemApi {
|
||||
// 用户远程前缀
|
||||
String USER_INFO_API = "/user";
|
||||
String GOODS_INFO_API ="/goods";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package com.muyu.common.constant;
|
||||
|
||||
/**
|
||||
* @author xie ya ru
|
||||
* @description: 令牌常量
|
||||
* @Data 2024/7/10
|
||||
*/
|
||||
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";
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.muyu.common.domain;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author xie ya ru
|
||||
* @Date 2024/8/8 8:45
|
||||
* @注释
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class Student {
|
||||
private Long id;
|
||||
private String studentName;
|
||||
private String studentCourse;
|
||||
private Double studentScore;
|
||||
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
package com.muyu.common.redis.configure;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONReader;
|
||||
import com.alibaba.fastjson2.JSONWriter;
|
||||
import com.alibaba.fastjson2.filter.Filter;
|
||||
|
||||
import com.muyu.common.constant.Constants;
|
||||
import org.springframework.data.redis.serializer.RedisSerializer;
|
||||
import org.springframework.data.redis.serializer.SerializationException;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/**
|
||||
* Redis使用FastJson序列化
|
||||
* @author xie ya ru
|
||||
* @Data 2024/7/10
|
||||
*/
|
||||
public class FastJson2JsonRedisSerializer<T> implements RedisSerializer<T> {
|
||||
|
||||
public static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8;
|
||||
|
||||
static final Filter AUTO_TYPE_FILTER = JSONReader.autoTypeFilter(Constants.JSON_WHITELIST_STR);
|
||||
|
||||
private Class<T> clazz;
|
||||
|
||||
public FastJson2JsonRedisSerializer (Class<T> clazz) {
|
||||
super();
|
||||
this.clazz = clazz;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] serialize (T t) throws SerializationException {
|
||||
if (t == null) {
|
||||
return new byte[0];
|
||||
}
|
||||
return JSON.toJSONString(t, JSONWriter.Feature.WriteClassName).getBytes(DEFAULT_CHARSET);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T deserialize (byte[] bytes) throws SerializationException {
|
||||
if (bytes == null || bytes.length <= 0) {
|
||||
return null;
|
||||
}
|
||||
String str = new String(bytes, DEFAULT_CHARSET);
|
||||
|
||||
return JSON.parseObject(str, clazz, AUTO_TYPE_FILTER);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package com.muyu.common.redis.configure;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
|
||||
import org.springframework.cache.annotation.CachingConfigurerSupport;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
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.StringRedisSerializer;
|
||||
|
||||
/**
|
||||
* redis配置
|
||||
*
|
||||
* @author xie ya ru
|
||||
*/
|
||||
@Configuration
|
||||
@EnableCaching
|
||||
@AutoConfigureBefore(RedisAutoConfiguration.class)
|
||||
public class RedisConfig extends CachingConfigurerSupport {
|
||||
@Bean
|
||||
@SuppressWarnings(value = {"unchecked", "rawtypes"})
|
||||
public RedisTemplate<Object, Object> redisTemplate (RedisConnectionFactory connectionFactory) {
|
||||
RedisTemplate<Object, Object> template = new RedisTemplate<>();
|
||||
template.setConnectionFactory(connectionFactory);
|
||||
|
||||
FastJson2JsonRedisSerializer serializer = new FastJson2JsonRedisSerializer(Object.class);
|
||||
|
||||
// 使用StringRedisSerializer来序列化和反序列化redis的key值
|
||||
template.setKeySerializer(new StringRedisSerializer());
|
||||
template.setValueSerializer(serializer);
|
||||
|
||||
// Hash的key也采用StringRedisSerializer的序列化方式
|
||||
template.setHashKeySerializer(new StringRedisSerializer());
|
||||
template.setHashValueSerializer(serializer);
|
||||
|
||||
template.afterPropertiesSet();
|
||||
return template;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package com.muyu.common.redis.configure;
|
||||
|
||||
import org.redisson.Redisson;
|
||||
import org.redisson.api.RedissonClient;
|
||||
import org.redisson.config.Config;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @BelongsPackage: com.bw.config
|
||||
* @Author: xie ya ru
|
||||
* @Data: 2021/7/10
|
||||
*/
|
||||
|
||||
@Configuration
|
||||
public class RedissonConfig {
|
||||
|
||||
@Bean(destroyMethod="shutdown") // 服务停止后调用 shutdown 方法。
|
||||
public RedissonClient redisson() throws IOException {
|
||||
System.out.println("配置类初始加载......");
|
||||
// 1.创建配置
|
||||
Config config = new Config();
|
||||
// 集群模式
|
||||
// config.useClusterServers().addNodeAddress("127.0.0.1:6379", "127.0.0.1:6378");
|
||||
// 2.根据 Config 创建出 RedissonClient 实例。
|
||||
config.useSingleServer().setAddress("redis://43.142.14.107:6379");
|
||||
return Redisson.create(config);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,268 @@
|
|||
package com.muyu.common.redis.service;
|
||||
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.BoundSetOperations;
|
||||
import org.springframework.data.redis.core.HashOperations;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.core.ValueOperations;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* spring redis 工具类
|
||||
*
|
||||
* @author xie ya ru
|
||||
**/
|
||||
@SuppressWarnings(value = {"unchecked", "rawtypes"})
|
||||
@Log4j2
|
||||
@Component
|
||||
public class RedisService {
|
||||
|
||||
@Scheduled(cron = "0/5 * * * * ?")
|
||||
public void scheduled() {
|
||||
this.setCacheObject("skip", System.currentTimeMillis());
|
||||
log.info("Redis心跳成功");
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public RedisTemplate redisTemplate;
|
||||
|
||||
/**
|
||||
* 缓存基本的对象,Integer、String、实体类等
|
||||
*
|
||||
* @param key 缓存的键值
|
||||
* @param value 缓存的值
|
||||
*/
|
||||
public <T> void setCacheObject (final String key, final T value) {
|
||||
redisTemplate.opsForValue().set(key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 缓存基本的对象,Integer、String、实体类等
|
||||
*
|
||||
* @param key 缓存的键值
|
||||
* @param value 缓存的值
|
||||
* @param timeout 时间
|
||||
* @param timeUnit 时间颗粒度
|
||||
*/
|
||||
public <T> void setCacheObject (final String key, final T value, final Long timeout, final TimeUnit timeUnit) {
|
||||
redisTemplate.opsForValue().set(key, value, timeout, timeUnit);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置有效时间
|
||||
*
|
||||
* @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 Redis键
|
||||
*
|
||||
* @return 有效时间
|
||||
*/
|
||||
public long getExpire (final String key) {
|
||||
return redisTemplate.getExpire(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断 key是否存在
|
||||
*
|
||||
* @param key 键
|
||||
*
|
||||
* @return true 存在 false不存在
|
||||
*/
|
||||
public Boolean hasKey (String key) {
|
||||
return redisTemplate.hasKey(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得缓存的基本对象。
|
||||
*
|
||||
* @param key 缓存键值
|
||||
*
|
||||
* @return 缓存键值对应的数据
|
||||
*/
|
||||
public <T> T getCacheObject (final String key) {
|
||||
ValueOperations<String, T> operation = redisTemplate.opsForValue();
|
||||
return operation.get(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除单个对象
|
||||
*
|
||||
* @param key
|
||||
*/
|
||||
public boolean deleteObject (final String key) {
|
||||
return redisTemplate.delete(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除集合对象
|
||||
*
|
||||
* @param collection 多个对象
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean deleteObject (final Collection collection) {
|
||||
return redisTemplate.delete(collection) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 缓存List数据
|
||||
*
|
||||
* @param key 缓存的键值
|
||||
* @param dataList 待缓存的List数据
|
||||
*
|
||||
* @return 缓存的对象
|
||||
*/
|
||||
public <T> long setCacheList (final String key, final List<T> dataList) {
|
||||
Long count = redisTemplate.opsForList().rightPushAll(key, dataList);
|
||||
return count == null ? 0 : count;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得缓存的list对象
|
||||
*
|
||||
* @param key 缓存的键值
|
||||
*
|
||||
* @return 缓存键值对应的数据
|
||||
*/
|
||||
public <T> List<T> getCacheList (final String key) {
|
||||
return redisTemplate.opsForList().range(key, 0, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 缓存Set
|
||||
*
|
||||
* @param key 缓存键值
|
||||
* @param dataSet 缓存的数据
|
||||
*
|
||||
* @return 缓存数据的对象
|
||||
*/
|
||||
public <T> BoundSetOperations<String, T> setCacheSet (final String key, final Set<T> dataSet) {
|
||||
BoundSetOperations<String, T> setOperation = redisTemplate.boundSetOps(key);
|
||||
Iterator<T> it = dataSet.iterator();
|
||||
while (it.hasNext()) {
|
||||
setOperation.add(it.next());
|
||||
}
|
||||
return setOperation;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得缓存的set
|
||||
*
|
||||
* @param key
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public <T> Set<T> getCacheSet (final String key) {
|
||||
return redisTemplate.opsForSet().members(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 缓存Map
|
||||
*
|
||||
* @param key
|
||||
* @param dataMap
|
||||
*/
|
||||
public <T> void setCacheMap (final String key, final Map<String, T> dataMap) {
|
||||
if (dataMap != null) {
|
||||
redisTemplate.opsForHash().putAll(key, dataMap);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得缓存的Map
|
||||
*
|
||||
* @param key
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public <T> Map<String, T> getCacheMap (final String key) {
|
||||
return redisTemplate.opsForHash().entries(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 往Hash中存入数据
|
||||
*
|
||||
* @param key Redis键
|
||||
* @param hKey Hash键
|
||||
* @param value 值
|
||||
*/
|
||||
public <T> 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> T getCacheMapValue (final String key, final String hKey) {
|
||||
HashOperations<String, String, T> opsForHash = redisTemplate.opsForHash();
|
||||
return opsForHash.get(key, hKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取多个Hash中的数据
|
||||
*
|
||||
* @param key Redis键
|
||||
* @param hKeys Hash键集合
|
||||
*
|
||||
* @return Hash对象集合
|
||||
*/
|
||||
public <T> List<T> getMultiCacheMapValue (final String key, final Collection<Object> hKeys) {
|
||||
return redisTemplate.opsForHash().multiGet(key, hKeys);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除Hash中的某条数据
|
||||
*
|
||||
* @param key Redis键
|
||||
* @param hKey Hash键
|
||||
*
|
||||
* @return 是否成功
|
||||
*/
|
||||
public boolean deleteCacheMapValue (final String key, final String hKey) {
|
||||
return redisTemplate.opsForHash().delete(key, hKey) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得缓存的基本对象列表
|
||||
*
|
||||
* @param pattern 字符串前缀
|
||||
*
|
||||
* @return 对象列表
|
||||
*/
|
||||
public Collection<String> keys (final String pattern) {
|
||||
return redisTemplate.keys(pattern);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package com.muyu.common.result;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author xie ya ru
|
||||
* @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));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package com.muyu.common.result;
|
||||
|
||||
import com.muyu.common.constant.Constants;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @description: 响应信息主体
|
||||
* @author xie ya ru
|
||||
*/
|
||||
@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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,104 @@
|
|||
package com.muyu.common.utils;
|
||||
|
||||
import com.muyu.common.constant.JwtConstants;
|
||||
import io.jsonwebtoken.Claims;
|
||||
import io.jsonwebtoken.Jwts;
|
||||
import io.jsonwebtoken.SignatureAlgorithm;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @description: Jwt工具类
|
||||
* @author xie ya ru
|
||||
*/
|
||||
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();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,162 @@
|
|||
package com.muyu.common.utils;
|
||||
|
||||
import com.aliyun.oss.OSS;
|
||||
import com.aliyun.oss.OSSClientBuilder;
|
||||
import com.aliyun.oss.model.GetObjectRequest;
|
||||
import com.aliyun.oss.model.PutObjectRequest;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @Author: xie ya ru
|
||||
* @Description TODO Oss工具
|
||||
*/
|
||||
@Log4j2
|
||||
public class OssUtil {
|
||||
|
||||
/**
|
||||
* Endpoint 存储对象概述 阿里云主账号AccessKey,accessKeySecret拥有所有API的访问权限 访问路径前缀 存储对象概述
|
||||
*/
|
||||
private static String endPoint = "oss-cn-shanghai.aliyuncs.com";
|
||||
private static String accessKeyId = "LTAI5tDbRqXkC5i3SMrCSDcX";
|
||||
private static String accessKeySecret = "XUzMZoHPLsjNLafHsdQnMElBWZATsu";
|
||||
private static String accessPre = "https://mall-bw.oss-cn-shanghai.aliyuncs.com/";
|
||||
|
||||
/**
|
||||
* bucket名称
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private static String bucketName = "mall-bw";
|
||||
|
||||
private static OSS ossClient;
|
||||
|
||||
static {
|
||||
ossClient = new OSSClientBuilder().build(
|
||||
endPoint,
|
||||
accessKeyId,
|
||||
accessKeySecret);
|
||||
log.info("oss服务连接成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 默认路径上传本地文件
|
||||
*
|
||||
* @param filePath
|
||||
*/
|
||||
public static String uploadFile(String filePath) {
|
||||
return uploadFileForBucket(bucketName, getOssFilePath(filePath), filePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* 默认路径上传multipartFile文件
|
||||
*
|
||||
* @param multipartFile
|
||||
*/
|
||||
public static String uploadMultipartFile(MultipartFile multipartFile) {
|
||||
return uploadMultipartFile(bucketName, getOssFilePath(multipartFile.getOriginalFilename()), multipartFile);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传 multipartFile 类型文件
|
||||
*
|
||||
* @param bucketName
|
||||
* @param ossPath
|
||||
* @param multipartFile
|
||||
*/
|
||||
public static String uploadMultipartFile(String bucketName, String ossPath, MultipartFile multipartFile) {
|
||||
InputStream inputStream = null;
|
||||
try {
|
||||
inputStream = multipartFile.getInputStream();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
uploadFileInputStreamForBucket(bucketName, ossPath, inputStream);
|
||||
return accessPre + ossPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用File上传PutObject上传文件 ** 程序默认使用次方法上传
|
||||
*
|
||||
* @param bucketName 实例名称
|
||||
* @param ossPath oss存储路径
|
||||
* @param filePath 本地文件路径
|
||||
*/
|
||||
public static String uploadFileForBucket(String bucketName, String ossPath, String filePath) {
|
||||
// 创建PutObjectRequest对象。
|
||||
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, ossPath, new File(filePath));
|
||||
// 上传
|
||||
ossClient.putObject(putObjectRequest);
|
||||
return accessPre + ossPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用文件流上传到指定的bucket实例
|
||||
*
|
||||
* @param bucketName 实例名称
|
||||
* @param ossPath oss存储路径
|
||||
* @param filePath 本地文件路径
|
||||
*/
|
||||
public static String uploadFileInputStreamForBucket(String bucketName, String ossPath, String filePath) {
|
||||
|
||||
// 填写本地文件的完整路径。如果未指定本地路径,则默认从示例程序所属项目对应本地路径中上传文件流。
|
||||
InputStream inputStream = null;
|
||||
try {
|
||||
inputStream = new FileInputStream(filePath);
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// 填写Bucket名称和Object完整路径。Object完整路径中不能包含Bucket名称。
|
||||
uploadFileInputStreamForBucket(bucketName, ossPath, inputStream);
|
||||
return accessPre + ossPath;
|
||||
}
|
||||
|
||||
public static void uploadFileInputStreamForBucket(String bucketName, String ossPath, InputStream inputStream) {
|
||||
ossClient.putObject(bucketName, ossPath, inputStream);
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载
|
||||
*
|
||||
* @param ossFilePath
|
||||
* @param filePath
|
||||
*/
|
||||
public static void downloadFile(String ossFilePath, String filePath) {
|
||||
downloadFileForBucket(bucketName, ossFilePath, filePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载
|
||||
*
|
||||
* @param bucketName 实例名称
|
||||
* @param ossFilePath oss存储路径
|
||||
* @param filePath 本地文件路径
|
||||
*/
|
||||
public static void downloadFileForBucket(String bucketName, String ossFilePath, String filePath) {
|
||||
ossClient.getObject(new GetObjectRequest(bucketName, ossFilePath), new File(filePath));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public static String getOssDefaultPath() {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
String url =
|
||||
now.getYear() + "/" +
|
||||
now.getMonth() + "/" +
|
||||
now.getDayOfMonth() + "/" +
|
||||
now.getHour() + "/" +
|
||||
now.getMinute() + "/";
|
||||
return url;
|
||||
}
|
||||
|
||||
public static String getOssFilePath(String filePath) {
|
||||
String fileSuf = filePath.substring(filePath.indexOf(".") + 1);
|
||||
return getOssDefaultPath() + UUID.randomUUID().toString() + "." + fileSuf;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
package com.muyu.common.utils;
|
||||
|
||||
import org.springframework.util.AntPathMatcher;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author xie ya ru
|
||||
* 工具类
|
||||
*/
|
||||
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是否为空, 包含List,Set,Queue
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,125 @@
|
|||
package com.muyu.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.dysmsapi20170525.models.SendSmsResponseBody;
|
||||
import com.aliyun.teaopenapi.models.Config;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* 短信工具类
|
||||
*/
|
||||
@Log4j2
|
||||
public class TelSmsUtils {
|
||||
|
||||
/**
|
||||
* 阿里云主账号AccessKey,accessKeySecret拥有所有API的访问权限
|
||||
* <p>
|
||||
* LTAI5tN9vdDeBioiVbGG3UG3
|
||||
* gzhfYLb0UX0zH35DOki9yi1Q35ndgS
|
||||
*/
|
||||
private static final String accessKeyId = "LTAI5tN9vdDeBioiVbGG3UG3";
|
||||
|
||||
private static final String accessKeySecret = "gzhfYLb0UX0zH35DOki9yi1Q35ndgS";
|
||||
|
||||
/**
|
||||
* 短信访问域名
|
||||
*/
|
||||
private static final String endpoint = "dysmsapi.aliyuncs.com";
|
||||
|
||||
/**
|
||||
* 短信签名
|
||||
*/
|
||||
private static final String signName = "登录验证";
|
||||
|
||||
/**
|
||||
* 模板编号
|
||||
*/
|
||||
private static final String templateCode = "SMS_467560395";
|
||||
|
||||
/**
|
||||
* 实例化短信对象
|
||||
*/
|
||||
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 sendDataMap 验证码对象
|
||||
*/
|
||||
public static SendSmsResponseBody sendSms(String tel, 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 sendSmsResponse.getBody();
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送手机验证码
|
||||
* @param tel 手机号
|
||||
* @param code 验证码
|
||||
*/
|
||||
public static SendSmsResponseBody sendSms(String tel, String code) {
|
||||
|
||||
Map<String, String> map = new HashMap<>();
|
||||
|
||||
map.put("code",code);
|
||||
|
||||
return sendSms(tel, map);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
int code = new Random().nextInt(900000) + 100000;
|
||||
map.put("code", String.valueOf(code));
|
||||
sendSms("15335893491", map);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
com.muyu.common.redis.configure.RedisConfig
|
||||
com.muyu.common.redis.service.RedisService
|
||||
com.muyu.common.config.ExceptionHandler
|
||||
com.muyu.common.redis.configure.RedissonConfig
|
|
@ -0,0 +1,78 @@
|
|||
<?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.muyu</groupId>
|
||||
<artifactId>h6-exam19</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<modules>
|
||||
<module>cloud-common</module>
|
||||
<module>system-server</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.7.15</version>
|
||||
<relativePath/>
|
||||
</parent>
|
||||
|
||||
<!-- 依赖声明 -->
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<!-- SpringCloud 微服务 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-dependencies</artifactId>
|
||||
<version>2021.0.8</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<!-- SpringCloud Alibaba 微服务 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
|
||||
<version>2021.0.5.0</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.muyu</groupId>
|
||||
<artifactId>cloud-common</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 系统服务公共依赖 -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>system-common</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
<!-- 系统服务远程调用依赖 -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>system-remote</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,44 @@
|
|||
<?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.muyu</groupId>
|
||||
<artifactId>h6-exam19</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>system-server</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.muyu</groupId>
|
||||
<artifactId>cloud-common</artifactId>
|
||||
</dependency>
|
||||
<!-- SpringBoot Web-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>16</source>
|
||||
<target>16</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
|
@ -0,0 +1,20 @@
|
|||
package com.muyu.cloud.system;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
/**
|
||||
* @Author: xie ya ru
|
||||
* @date: 2024/7/10
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@EnableScheduling
|
||||
public class CloudSystemApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(CloudSystemApplication.class, args);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package com.muyu.cloud.system.controller;
|
||||
|
||||
import com.muyu.cloud.system.service.StudentService;
|
||||
import com.muyu.common.domain.Student;
|
||||
import com.muyu.common.result.Result;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author xie ya ru
|
||||
* @Date 2024/8/8 8:51
|
||||
* @注释
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/student")
|
||||
public class StudentController {
|
||||
@Resource
|
||||
private StudentService studentService;
|
||||
|
||||
@GetMapping("/showStudent")
|
||||
public Result<List<Student>> showStudent(){
|
||||
List<Student> studentList = studentService.showStudent();
|
||||
return Result.success(studentList);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package com.muyu.cloud.system.mapper;
|
||||
|
||||
import com.muyu.common.domain.Student;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author xie ya ru
|
||||
* @Date 2024/8/8 8:46
|
||||
* @注释
|
||||
*/
|
||||
@Mapper
|
||||
public interface StudentMapper {
|
||||
|
||||
List<Student> showStudent();
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package com.muyu.cloud.system.service;
|
||||
|
||||
import com.muyu.common.domain.Student;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author xie ya ru
|
||||
* @Date 2024/8/8 8:47
|
||||
* @注释
|
||||
*/
|
||||
public interface StudentService {
|
||||
List<Student> showStudent();
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package com.muyu.cloud.system.service.impl;
|
||||
|
||||
import com.muyu.cloud.system.mapper.StudentMapper;
|
||||
import com.muyu.cloud.system.service.StudentService;
|
||||
import com.muyu.common.domain.Student;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author xie ya ru
|
||||
* @Date 2024/8/8 8:47
|
||||
* @注释
|
||||
*/
|
||||
@Service
|
||||
public class StudentServiceImpl implements StudentService {
|
||||
@Resource
|
||||
private StudentMapper studentMapper;
|
||||
|
||||
|
||||
@Override
|
||||
public List<Student> showStudent() {
|
||||
List<Student> studentList = studentMapper.showStudent();
|
||||
|
||||
for (Student student : studentList) {
|
||||
String str = student.getStudentName()+" "+student.getStudentCourse()+" "+student.getStudentScore();
|
||||
HashMap<Long, String> longStudentHashMap = new HashMap<>();
|
||||
longStudentHashMap.put(student.getId(),str);
|
||||
longStudentHashMap.forEach((aLong, strinf) -> {
|
||||
System.out.println(longStudentHashMap.get(aLong));
|
||||
});
|
||||
}
|
||||
studentList.stream().filter(student -> student.getId() != null)
|
||||
.map(student -> {
|
||||
student.getStudentName();
|
||||
return student;
|
||||
}).toList();
|
||||
return studentList;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
# Tomcat
|
||||
server:
|
||||
port: 9201
|
||||
|
||||
# 配置nacos的地址
|
||||
nacos:
|
||||
server-addr: 1.94.37.42:8848
|
||||
|
||||
# Spring
|
||||
spring:
|
||||
main:
|
||||
allow-circular-references: true
|
||||
jackson:
|
||||
date-format: yyyy-MM-dd HH:mm:ss
|
||||
time-zone: GMT+8
|
||||
application:
|
||||
# 应用名称
|
||||
name: system-server
|
||||
profiles:
|
||||
# 环境配置
|
||||
active: dev
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
# 服务注册地址
|
||||
server-addr: ${nacos.server-addr}
|
||||
config:
|
||||
# 配置中心地址
|
||||
server-addr: ${nacos.server-addr}
|
||||
# 配置文件格式
|
||||
file-extension: yml
|
||||
# 共享配置
|
||||
shared-configs:
|
||||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||
# 程序Redis公共配置文件
|
||||
- redis-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||
# 程序MySQL公共配置文件
|
||||
- mysql-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||
|
||||
- system-server-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||
|
||||
fdfs:
|
||||
so-timeout: 1500 # socket 连接时长
|
||||
connect-timeout: 600 # 连接 tracker 服务器超时时长
|
||||
# 这两个是你服务器的 IP 地址,注意 23000 端口也要打开,阿里云服务器记得配置安全组。tracker 要和 stroage 服务进行交流
|
||||
tracker-list: 1.94.37.42:22122
|
||||
web-server-url: 1.94.37.42:8888
|
||||
pool:
|
||||
jmx-enabled: false
|
||||
# 生成缩略图
|
||||
thumb-image:
|
||||
height: 500
|
||||
width: 500
|
|
@ -0,0 +1,12 @@
|
|||
<?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.muyu.cloud.system.mapper.StudentMapper">
|
||||
<!-- 添加 -->
|
||||
|
||||
|
||||
<select id="showStudent" resultType="com.muyu.common.domain.Student">
|
||||
select * from t_student
|
||||
</select>
|
||||
</mapper>
|
Loading…
Reference in New Issue