chore: 工具

feature/comment
ChenYan 2024-12-30 11:28:25 +08:00
parent 3f69d8466b
commit db0cee24e1
7 changed files with 299 additions and 0 deletions

View File

@ -23,6 +23,17 @@
<groupId>org.springframework</groupId> <groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId> <artifactId>spring-context-support</artifactId>
</dependency> </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模块 --> <!-- SpringWeb模块 -->
<dependency> <dependency>

View File

@ -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;
}
}
}

View File

@ -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 {
}

View File

@ -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 "删除成功";
}
}

View File

@ -0,0 +1,100 @@
<?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>
<!-- spring-boot-devtools -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional> <!-- 表示依赖不会传递 -->
</dependency>
<!-- swagger3-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
</dependency>
<!-- 防止进入swagger页面报类型转换错误排除3.0.0中的引用手动增加1.6.2版本 -->
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-models</artifactId>
<version>1.6.2</version>
</dependency>
<!-- Mysql驱动包 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!-- 核心模块-->
<dependency>
<groupId>com.mcwl</groupId>
<artifactId>mcwl-framework</artifactId>
</dependency>
<!-- 定时任务-->
<dependency>
<groupId>com.mcwl</groupId>
<artifactId>mcwl-quartz</artifactId>
</dependency>
<!-- 代码生成-->
<dependency>
<groupId>com.mcwl</groupId>
<artifactId>mcwl-generator</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.5.15</version>
<configuration>
<fork>true</fork> <!-- 如果没有该配置devtools不会生效 -->
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<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>
</plugins>
<finalName>${project.artifactId}</finalName>
</build>
</project>

View File

@ -0,0 +1,30 @@
package com.mcwl;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
/**
*
*
* @author mcwl
*/
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })
public class McWlResourceApplication
{
public static void main(String[] args)
{
// System.setProperty("spring.devtools.restart.enabled", "false");
SpringApplication.run(McWlResourceApplication.class, args);
System.out.println("(♥◠‿◠)ノ゙ 资源中心启动成功 ლ(´ڡ`ლ)゙ \n" +
" .-------. ____ __ \n" +
" | _ _ \\ \\ \\ / / \n" +
" | ( ' ) | \\ _. / ' \n" +
" |(_ o _) / _( )_ .' \n" +
" | (_,_).' __ ___(_ o _)' \n" +
" | |\\ \\ | || |(_,_)' \n" +
" | | \\ `' /| `-' / \n" +
" | | \\ / \\ / \n" +
" ''-' `'-' `-..-' ");
}
}

View File

@ -228,6 +228,7 @@
<module>mcwl-quartz</module> <module>mcwl-quartz</module>
<module>mcwl-generator</module> <module>mcwl-generator</module>
<module>mcwl-common</module> <module>mcwl-common</module>
<module>mcwl-resource</module>
</modules> </modules>
<packaging>pom</packaging> <packaging>pom</packaging>