Compare commits
12 Commits
200d7b8106
...
a0c6c39c03
Author | SHA1 | Date |
---|---|---|
|
a0c6c39c03 | |
|
8f80a6ea4f | |
|
c846cbcf50 | |
|
8e330577ee | |
|
cb923c32f8 | |
|
dee5eb0518 | |
|
3785ce626c | |
|
c1aa8aaeb1 | |
|
db0cee24e1 | |
|
4aa6c6250a | |
|
3f69d8466b | |
|
a998c414bd |
|
@ -55,6 +55,13 @@
|
|||
<artifactId>mcwl-quartz</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 我的邀请模块-->
|
||||
<dependency>
|
||||
<groupId>com.mcwl</groupId>
|
||||
<artifactId>mcwl-myInvitation</artifactId>
|
||||
<version>3.8.8</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 代码生成-->
|
||||
<dependency>
|
||||
<groupId>com.mcwl</groupId>
|
||||
|
@ -80,15 +87,15 @@
|
|||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<configuration>
|
||||
<failOnMissingWebXml>false</failOnMissingWebXml>
|
||||
<warName>${project.artifactId}</warName>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
</build>
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
package com.mcwl.web.controller.myInvitation;
|
||||
|
||||
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController("/consume")
|
||||
public class ConsumeController {
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
package com.mcwl.web.controller.myInvitation;
|
||||
|
||||
|
||||
import com.mcwl.common.annotation.Anonymous;
|
||||
import com.mcwl.common.core.domain.AjaxResult;
|
||||
import com.mcwl.common.utils.SecurityUtils;
|
||||
import com.mcwl.myInvitation.domain.Invitation;
|
||||
import com.mcwl.myInvitation.service.InvitationService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.mcwl.common.core.domain.AjaxResult.success;
|
||||
|
||||
@RestController("/invitation")
|
||||
@RequiredArgsConstructor
|
||||
|
||||
public class InvitationController {
|
||||
|
||||
private final InvitationService invitationService;
|
||||
|
||||
|
||||
@GetMapping("/getInvitationCode")
|
||||
@Anonymous
|
||||
public AjaxResult getInvitationCode() {
|
||||
// 获取当前用户
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
String invitationCode = invitationService.getInvitationCode(userId);
|
||||
return success("操作成功", invitationCode);
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
public AjaxResult list() {
|
||||
List<Invitation> list = invitationService.list();
|
||||
return success(list);
|
||||
}
|
||||
|
||||
@GetMapping("/getById")
|
||||
public AjaxResult getById(Long id) {
|
||||
Invitation invitation = invitationService.getById(id);
|
||||
return success(invitation);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
<artifactId>mcwl-common</artifactId>
|
||||
|
||||
|
||||
<description>
|
||||
common通用工具
|
||||
</description>
|
||||
|
@ -22,6 +23,17 @@
|
|||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context-support</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.tobato</groupId>
|
||||
<artifactId>fastdfs-client</artifactId>
|
||||
<version>1.26.5</version>
|
||||
</dependency>
|
||||
|
||||
<!-- quartz定时任务-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-quartz</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringWeb模块 -->
|
||||
<dependency>
|
||||
|
@ -46,13 +58,16 @@
|
|||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!--常用工具类 -->
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.qiniu</groupId>
|
||||
<artifactId>qiniu-java-sdk</artifactId>
|
||||
<version>7.4.0</version>
|
||||
</dependency>
|
||||
<!-- JSON工具类 -->
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
|
|
|
@ -0,0 +1,84 @@
|
|||
package com.mcwl.common.config;
|
||||
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.BitSet;
|
||||
|
||||
/***
|
||||
* 布隆过滤器
|
||||
*/
|
||||
|
||||
@Component
|
||||
public class BloomFilterUtil {
|
||||
private static final int DEFAULT_SIZE = 2 << 24; // 布隆过滤器的比特长度
|
||||
private static final int[] seeds = new int[] {7, 11, 13, 31,37, 61}; // 这里要选取质数,能很好的降低错误率
|
||||
|
||||
private BitSet bits = new BitSet(DEFAULT_SIZE);
|
||||
private SimpleHash[] func = new SimpleHash[seeds.length];
|
||||
|
||||
public static void main(String[] args) {
|
||||
String value = "crankzcool@gmail.com";
|
||||
BloomFilterUtil filter = new BloomFilterUtil();
|
||||
// System.out.println(filter.contains(value));
|
||||
// filter.add(value);
|
||||
// System.out.println(filter.contains(value));
|
||||
|
||||
filter.add("1");
|
||||
filter.add("2");
|
||||
filter.remove("1");
|
||||
System.out.println(filter.contains("1"));
|
||||
}
|
||||
|
||||
public void remove(String value) {
|
||||
if (value == null) {
|
||||
return;
|
||||
}
|
||||
for (SimpleHash f : func) {
|
||||
bits.set(f.hash(value), false);
|
||||
}
|
||||
}
|
||||
|
||||
public BloomFilterUtil() {
|
||||
for (int i = 0; i < seeds.length; i++) {
|
||||
func[i] = new SimpleHash(DEFAULT_SIZE, seeds[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public void add(String value) {
|
||||
for (SimpleHash f: func) {
|
||||
bits.set(f.hash(value), true);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean contains(String value) {
|
||||
if (value == null) {
|
||||
return false;
|
||||
}
|
||||
boolean ret = true;
|
||||
for (SimpleHash f : func) {
|
||||
ret = ret && bits.get(f.hash(value));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
public static class SimpleHash {
|
||||
private int cap;
|
||||
private int seed;
|
||||
|
||||
public SimpleHash(int cap, int seed) {
|
||||
this.cap = cap;
|
||||
this.seed = seed;
|
||||
}
|
||||
|
||||
public int hash(String value) {
|
||||
int result = 0;
|
||||
int len = value.length();
|
||||
for (int i = 0; i < len; i++) {
|
||||
result = seed * result + value.charAt(i);
|
||||
}
|
||||
return (cap - 1) & result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package com.mcwl.common.config;
|
||||
|
||||
import com.github.tobato.fastdfs.FdfsClientConfig;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.EnableMBeanExport;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.jmx.support.RegistrationPolicy;
|
||||
|
||||
/**
|
||||
* @BelongsProject: demo02
|
||||
* @BelongsPackage: com.bw.config
|
||||
* @Author: zhupengfei
|
||||
* @CreateTime: 2022-12-16 14:37
|
||||
*/
|
||||
@Configuration
|
||||
// 解决 jmx 重复注册 bean 的问题
|
||||
@EnableMBeanExport(registration = RegistrationPolicy.IGNORE_EXISTING)
|
||||
public class FastConfig {
|
||||
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package com.mcwl.common.config;
|
||||
|
||||
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.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
|
||||
*/
|
||||
@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 "删除成功";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package com.mcwl.common.config;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 七牛云配置
|
||||
*
|
||||
* @date 2024/5/5 下午5:01
|
||||
*/
|
||||
@Component
|
||||
@ConfigurationProperties(prefix = "oss.qiniu")
|
||||
@Data
|
||||
public class QiNiuConfig {
|
||||
|
||||
/**
|
||||
* AccessKey
|
||||
*/
|
||||
private String accessKey;
|
||||
/**
|
||||
* SecretKey
|
||||
*/
|
||||
private String secretKey;
|
||||
/**
|
||||
* 图片存储空间名
|
||||
*/
|
||||
private String bucketPictureName;
|
||||
/**
|
||||
* 图片外链
|
||||
*/
|
||||
private String domainPicture;
|
||||
/**
|
||||
* 文件存储空间名
|
||||
*/
|
||||
private String bucketFileName;
|
||||
/**
|
||||
* 文件外链
|
||||
*/
|
||||
private String domainFile;
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package com.mcwl.common.constant;
|
||||
|
||||
public class JwtConstants {
|
||||
/**
|
||||
* 用户ID字段
|
||||
*/
|
||||
public static final String DETAILS_USER_ID = "user_id";
|
||||
|
||||
/**
|
||||
* 用户名字段
|
||||
*/
|
||||
public static final String DETAILS_USERNAME = "user_name";
|
||||
|
||||
/**
|
||||
* 用户标识
|
||||
*/
|
||||
public static final String USER_KEY = "user_key";
|
||||
|
||||
/**
|
||||
* 令牌秘钥
|
||||
*/
|
||||
public final static String SECRET = "abcdefghijklmnopqrstuvwxyz";
|
||||
|
||||
/**
|
||||
* 手机
|
||||
*/
|
||||
public static final String USER_PHONE = "user_phone";
|
||||
|
||||
|
||||
/**
|
||||
* 用户token 的键的前缀
|
||||
*/
|
||||
public static final String LOGIN_TOKEN = "login_token:";
|
||||
|
||||
/**
|
||||
* token过期时间 1h = 60 * 60 * 1000L
|
||||
*/
|
||||
public static final Long EXPIRATION = 60 * 60 * 1000L;
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
|
||||
package com.mcwl.common.interfaces;
|
||||
/**
|
||||
* @author 苏三,该项目是知识星球:java突击队 的内部项目
|
||||
* @date 2024/6/11 下午4:12
|
||||
*/
|
||||
|
||||
|
||||
|
||||
import com.mcwl.common.valid.MaxMoneyConstraintValidator;
|
||||
|
||||
import javax.validation.Constraint;
|
||||
import javax.validation.Payload;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* 最大值约束.
|
||||
*
|
||||
* @author 苏三,该项目是知识星球:java突击队 的内部项目
|
||||
* @date 2024/6/11 下午4:13
|
||||
*/
|
||||
@Target({ElementType.METHOD, ElementType.FIELD})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Constraint(validatedBy = MaxMoneyConstraintValidator.class)
|
||||
public @interface MaxMoney {
|
||||
/**
|
||||
* message.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
String message() default "{minMoney.message.error}";
|
||||
|
||||
/**
|
||||
* max value.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
double value() default 0;
|
||||
|
||||
/**
|
||||
* group.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
Class<?>[] groups() default {};
|
||||
|
||||
/**
|
||||
* payload.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
Class<? extends Payload>[] payload() default {};
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
package com.mcwl.common.interfaces;
|
||||
|
||||
/**
|
||||
* @date 2024/6/11 下午4:12
|
||||
*/
|
||||
|
||||
|
||||
import com.mcwl.common.valid.MinMoneyConstraintValidator;
|
||||
|
||||
import javax.validation.Constraint;
|
||||
import javax.validation.Payload;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* 最小值约束.
|
||||
*
|
||||
|
||||
* @date 2024/6/11 下午4:13
|
||||
*/
|
||||
@Target({ElementType.METHOD, ElementType.FIELD})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Constraint(validatedBy = MinMoneyConstraintValidator.class)
|
||||
public @interface MinMoney {
|
||||
/**
|
||||
* message.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
String message() default "{minMoney.message.error}";
|
||||
|
||||
/**
|
||||
* min value.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
double value() default 0;
|
||||
|
||||
/**
|
||||
* group.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
Class<?>[] groups() default {};
|
||||
|
||||
/**
|
||||
* payload.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
Class<? extends Payload>[] payload() default {};
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package com.mcwl.common.interfaces;
|
||||
|
||||
import com.mcwl.common.valid.PhoneValidator;
|
||||
|
||||
import javax.validation.Constraint;
|
||||
import javax.validation.Payload;
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* @author 苏三
|
||||
* @date 2024/9/24 下午3:09
|
||||
*/
|
||||
@Documented
|
||||
@Constraint(validatedBy = {PhoneValidator.class})
|
||||
@Target({ElementType.METHOD, ElementType.FIELD, ElementType.ANNOTATION_TYPE, ElementType.CONSTRUCTOR, ElementType.PARAMETER})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface ValidPhone {
|
||||
/**
|
||||
* 返回信息
|
||||
*/
|
||||
String message() default "手机号码格式不正确";
|
||||
|
||||
/**
|
||||
* 分组
|
||||
* @return
|
||||
*/
|
||||
Class<?>[] groups() default {};
|
||||
|
||||
Class<? extends Payload>[] payload() default {};
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,114 @@
|
|||
package com.mcwl.common.utils;
|
||||
|
||||
import com.mcwl.common.constant.JwtConstants;
|
||||
import io.jsonwebtoken.Claims;
|
||||
import io.jsonwebtoken.Jwts;
|
||||
import io.jsonwebtoken.SignatureAlgorithm;
|
||||
|
||||
import java.util.Date;
|
||||
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()
|
||||
.addClaims(claims)
|
||||
.signWith(SignatureAlgorithm.HS512, secret)
|
||||
.setExpiration(new Date(System.currentTimeMillis() + JwtConstants.EXPIRATION))
|
||||
.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,45 @@
|
|||
package com.mcwl.common.utils;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* 订单编号生成工具
|
||||
*
|
||||
* @date 2024/5/30 下午6:02
|
||||
*/
|
||||
public class OrderCodeUtil {
|
||||
|
||||
public static final int ORDER_CODE_LENGTH = 24;
|
||||
private static final String ORDER_CODE_DATA_FORMAT = "yyyyMMddHHmmss";
|
||||
private static final int ORDER_CODE_RANDOM_NUMBER = 10;
|
||||
private static final int ORDER_CODE_RANDOM_LENGTH = 6;
|
||||
|
||||
|
||||
/**
|
||||
* 生成订单编号
|
||||
*
|
||||
* @return 订单编号
|
||||
*/
|
||||
public static String generateOrderCode() {
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat(ORDER_CODE_DATA_FORMAT);
|
||||
String random = getRandom(ORDER_CODE_RANDOM_LENGTH);
|
||||
Date date = new Date();
|
||||
String time = dateFormat.format(date);
|
||||
String code = "XS" + time + random;
|
||||
while (code.length() < ORDER_CODE_LENGTH) {
|
||||
code = code + 0;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
private static String getRandom(int len) {
|
||||
Random r = new Random();
|
||||
StringBuilder rs = new StringBuilder();
|
||||
for (int i = 0; i < len; i++) {
|
||||
rs.append(r.nextInt(ORDER_CODE_RANDOM_NUMBER));
|
||||
}
|
||||
return rs.toString();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
package com.mcwl.common.utils;
|
||||
|
||||
import com.qiniu.http.Response;
|
||||
import com.qiniu.storage.Configuration;
|
||||
import com.qiniu.storage.Region;
|
||||
import com.qiniu.storage.UploadManager;
|
||||
import com.qiniu.storage.model.DefaultPutRet;
|
||||
import com.qiniu.util.Auth;
|
||||
import com.google.gson.Gson;
|
||||
import com.mcwl.common.config.QiNiuConfig;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
|
||||
/**
|
||||
* 七牛云上传工具
|
||||
*
|
||||
* @date 2024/5/5 下午5:02
|
||||
*/
|
||||
@Component
|
||||
public class QiNiuUtil {
|
||||
public static final String IMAGE = "image";
|
||||
public static final String FILE = "file";
|
||||
|
||||
@Autowired
|
||||
private QiNiuConfig qiNiuConfig;
|
||||
|
||||
/**
|
||||
* 将图片上传到七牛云
|
||||
*/
|
||||
public String upload(InputStream file, String fileType, String fileContextType) throws Exception {
|
||||
Configuration cfg = new Configuration(Region.region2());
|
||||
UploadManager uploadManager = new UploadManager(cfg);
|
||||
Auth auth = Auth.create(qiNiuConfig.getAccessKey(), qiNiuConfig.getSecretKey());
|
||||
String upToken = null;
|
||||
String path = null;
|
||||
if (fileType.equals(IMAGE)) {
|
||||
upToken = auth.uploadToken(qiNiuConfig.getBucketPictureName());
|
||||
path = qiNiuConfig.getDomainFile();
|
||||
} else if (fileType.equals(FILE)) {
|
||||
upToken = auth.uploadToken(qiNiuConfig.getBucketFileName());
|
||||
path = qiNiuConfig.getDomainFile();
|
||||
}
|
||||
Response response = uploadManager.put(file, null, upToken, null, fileContextType);
|
||||
DefaultPutRet putRet = new Gson().fromJson(response.bodyString(), DefaultPutRet.class);
|
||||
return path + putRet.key;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package com.mcwl.common.valid;
|
||||
|
||||
|
||||
|
||||
import com.mcwl.common.interfaces.MaxMoney;
|
||||
|
||||
import javax.validation.ConstraintValidator;
|
||||
import javax.validation.ConstraintValidatorContext;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 最大金额校验
|
||||
* @date 2024/6/11 下午4:13
|
||||
*/
|
||||
public class MaxMoneyConstraintValidator implements ConstraintValidator<MaxMoney, BigDecimal> {
|
||||
|
||||
private MaxMoney constraint;
|
||||
|
||||
@Override
|
||||
public void initialize(MaxMoney constraint) {
|
||||
this.constraint = constraint;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(BigDecimal value, ConstraintValidatorContext context) {
|
||||
return value != null && value.doubleValue() < constraint.value();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package com.mcwl.common.valid;
|
||||
|
||||
|
||||
|
||||
import com.mcwl.common.interfaces.MinMoney;
|
||||
|
||||
import javax.validation.ConstraintValidator;
|
||||
import javax.validation.ConstraintValidatorContext;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 最小金额校验
|
||||
*
|
||||
* @date 2024/6/11 下午4:13
|
||||
*/
|
||||
public class MinMoneyConstraintValidator implements ConstraintValidator<MinMoney, BigDecimal> {
|
||||
|
||||
private MinMoney constraint;
|
||||
|
||||
@Override
|
||||
public void initialize(MinMoney constraint) {
|
||||
this.constraint = constraint;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(BigDecimal value, ConstraintValidatorContext context) {
|
||||
return value != null && value.doubleValue() >= constraint.value();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.mcwl.common.valid;
|
||||
|
||||
|
||||
|
||||
import com.mcwl.common.interfaces.ValidPhone;
|
||||
|
||||
import javax.validation.ConstraintValidator;
|
||||
import javax.validation.ConstraintValidatorContext;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* 手机号校验
|
||||
*
|
||||
* @author 苏三
|
||||
* @date 2024/9/24 下午3:12
|
||||
*/
|
||||
public class PhoneValidator implements ConstraintValidator<ValidPhone, String> {
|
||||
private static final String PHONE_REGEX = "^1([38][0-9]|4[5-9]|5[0-3,5-9]|6[6]|7[0-8]|9[89])[0-9]{8}$";
|
||||
private final Pattern pattern = Pattern.compile(PHONE_REGEX);
|
||||
|
||||
@Override
|
||||
public boolean isValid(String value, ConstraintValidatorContext context) {
|
||||
if (value == null) {
|
||||
return true;
|
||||
}
|
||||
return pattern.matcher(value).matches();
|
||||
}
|
||||
}
|
|
@ -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.mcwl</groupId>
|
||||
<artifactId>mcwl</artifactId>
|
||||
<version>3.8.8</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>mcwl-myInvitation</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<mybatis-plus.version>3.5.2</mybatis-plus.version>
|
||||
</properties>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<!-- 通用工具-->
|
||||
<dependency>
|
||||
<groupId>com.mcwl</groupId>
|
||||
<artifactId>mcwl-common</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
<version>${mybatis-plus.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,41 @@
|
|||
package com.mcwl.myInvitation.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.mcwl.common.core.domain.BaseEntity;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
// 提成表
|
||||
@Data
|
||||
@TableName("commissions")
|
||||
public class Commission extends BaseEntity {
|
||||
|
||||
@TableId
|
||||
private Long id;
|
||||
|
||||
// 用户id
|
||||
private Long userId;
|
||||
|
||||
// 消费id
|
||||
private Long consumeId;
|
||||
|
||||
// 提成金额
|
||||
private Double amount;
|
||||
|
||||
// 支付状态
|
||||
private Integer payStatus;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Commission that = (Commission) o;
|
||||
return Objects.equals(id, that.id) && Objects.equals(userId, that.userId) && Objects.equals(consumeId, that.consumeId) && Objects.equals(amount, that.amount) && Objects.equals(payStatus, that.payStatus);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id, userId, consumeId, amount, payStatus);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package com.mcwl.myInvitation.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.mcwl.common.core.domain.BaseEntity;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Objects;
|
||||
|
||||
// 消费表
|
||||
@Data
|
||||
@TableName("consumes")
|
||||
public class Consume extends BaseEntity {
|
||||
|
||||
@TableId
|
||||
private Long id;
|
||||
|
||||
// 用户id
|
||||
private Long userId;
|
||||
|
||||
// 消费金额
|
||||
private Double amount;
|
||||
|
||||
// 消费时间
|
||||
private Date consumeDate;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Consume consume = (Consume) o;
|
||||
return Objects.equals(id, consume.id) && Objects.equals(userId, consume.userId) && Objects.equals(amount, consume.amount) && Objects.equals(consumeDate, consume.consumeDate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id, userId, amount, consumeDate);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package com.mcwl.myInvitation.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.mcwl.common.core.domain.BaseEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
// 邀请表
|
||||
@Data
|
||||
@TableName("invitations")
|
||||
public class Invitation extends BaseEntity {
|
||||
|
||||
@TableId
|
||||
private Long id;
|
||||
|
||||
// 邀请者
|
||||
private Long userId;
|
||||
|
||||
// 被邀请者
|
||||
private Long userInviteId ;
|
||||
|
||||
// 邀请码
|
||||
private String invitationCode;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Invitation that = (Invitation) o;
|
||||
return Objects.equals(id, that.id) && Objects.equals(userId, that.userId) && Objects.equals(userInviteId, that.userInviteId) && Objects.equals(invitationCode, that.invitationCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id, userId, userInviteId, invitationCode);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package com.mcwl.myInvitation.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.mcwl.myInvitation.domain.Commission;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface CommissionMapper extends BaseMapper<Commission> {
|
||||
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package com.mcwl.myInvitation.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.mcwl.myInvitation.domain.Commission;
|
||||
import com.mcwl.myInvitation.domain.Consume;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface ConsumeMapper extends BaseMapper<Consume> {
|
||||
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package com.mcwl.myInvitation.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.mcwl.myInvitation.domain.Commission;
|
||||
import com.mcwl.myInvitation.domain.Invitation;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface InvitationMapper extends BaseMapper<Invitation> {
|
||||
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package com.mcwl.myInvitation.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.mcwl.myInvitation.domain.Commission;
|
||||
|
||||
public interface CommissionService extends IService<Commission> {
|
||||
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package com.mcwl.myInvitation.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.mcwl.myInvitation.domain.Consume;
|
||||
|
||||
public interface ConsumeService extends IService<Consume> {
|
||||
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package com.mcwl.myInvitation.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.mcwl.myInvitation.domain.Invitation;
|
||||
|
||||
public interface InvitationService extends IService<Invitation> {
|
||||
|
||||
/**
|
||||
* 获取邀请码
|
||||
* @param userId 用户id
|
||||
* @return 邀请码
|
||||
*/
|
||||
String getInvitationCode(Long userId);
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package com.mcwl.myInvitation.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.mcwl.myInvitation.domain.Commission;
|
||||
import com.mcwl.myInvitation.mapper.CommissionMapper;
|
||||
import com.mcwl.myInvitation.service.CommissionService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class CommissionServiceImpl extends ServiceImpl<CommissionMapper, Commission> implements CommissionService {
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package com.mcwl.myInvitation.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.mcwl.myInvitation.domain.Consume;
|
||||
import com.mcwl.myInvitation.mapper.ConsumeMapper;
|
||||
import com.mcwl.myInvitation.service.ConsumeService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class ConsumeServiceImpl extends ServiceImpl<ConsumeMapper, Consume> implements ConsumeService {
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.mcwl.myInvitation.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.mcwl.common.constant.JwtConstants;
|
||||
import com.mcwl.common.utils.JwtUtils;
|
||||
import com.mcwl.myInvitation.domain.Invitation;
|
||||
import com.mcwl.myInvitation.mapper.InvitationMapper;
|
||||
import com.mcwl.myInvitation.service.InvitationService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class InvitationServiceImpl extends ServiceImpl<InvitationMapper, Invitation> implements InvitationService {
|
||||
|
||||
|
||||
@Override
|
||||
public String getInvitationCode(Long userId) {
|
||||
// 生成邀请码
|
||||
Map<String, Object> claims = new HashMap<>() ;
|
||||
claims.put(JwtConstants.DETAILS_USER_ID, userId);
|
||||
String invitationCode = JwtUtils.createToken(claims);
|
||||
return invitationCode;
|
||||
}
|
||||
}
|
|
@ -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.mcwl.myInvitation.mapper.CommissionMapper">
|
||||
|
||||
|
||||
|
||||
</mapper>
|
|
@ -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.mcwl.myInvitation.mapper.ConsumeMapper">
|
||||
|
||||
|
||||
|
||||
</mapper>
|
|
@ -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.mcwl.myInvitation.mapper.InvitationMapper">
|
||||
|
||||
|
||||
|
||||
</mapper>
|
|
@ -0,0 +1,24 @@
|
|||
<?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.mcwl</groupId>
|
||||
<artifactId>mcwl</artifactId>
|
||||
<version>3.8.8</version>
|
||||
</parent>
|
||||
<artifactId>mcwl-resource</artifactId>
|
||||
<description>
|
||||
resource资源中心模块
|
||||
</description>
|
||||
|
||||
<dependencies>
|
||||
<!-- 通用工具-->
|
||||
<dependency>
|
||||
<groupId>com.mcwl</groupId>
|
||||
<artifactId>mcwl-common</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
2
pom.xml
2
pom.xml
|
@ -228,6 +228,8 @@
|
|||
<module>mcwl-quartz</module>
|
||||
<module>mcwl-generator</module>
|
||||
<module>mcwl-common</module>
|
||||
<module>mcwl-myInvitation</module>
|
||||
<module>mcwl-resource</module>
|
||||
</modules>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
-- ----------------------------
|
||||
-- 0、 xxx
|
||||
-- ----------------------------
|
||||
-- create table xxx
|
||||
-- (
|
||||
-- post_id bigint(20) not null auto_increment comment '岗位ID',
|
||||
-- post_code varchar(64) not null comment '岗位编码',
|
||||
-- primary key (post_id)
|
||||
-- ) engine=innodb comment = 'xxxx';
|
Loading…
Reference in New Issue