From db0cee24e18b03deec662e7eb87bd1fb071d2169 Mon Sep 17 00:00:00 2001 From: ChenYan <3139166962@qq.com> Date: Mon, 30 Dec 2024 11:28:25 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mcwl-common/pom.xml | 11 ++ .../mcwl/common/config/BloomFilterUtil.java | 84 +++++++++++++++ .../com/mcwl/common/config/FastConfig.java | 20 ++++ .../java/com/mcwl/common/config/FastUtil.java | 53 ++++++++++ mcwl-resource/pom.xml | 100 ++++++++++++++++++ .../com/mcwl/McWlResourceApplication.java | 30 ++++++ pom.xml | 1 + 7 files changed, 299 insertions(+) create mode 100644 mcwl-common/src/main/java/com/mcwl/common/config/BloomFilterUtil.java create mode 100644 mcwl-common/src/main/java/com/mcwl/common/config/FastConfig.java create mode 100644 mcwl-common/src/main/java/com/mcwl/common/config/FastUtil.java create mode 100644 mcwl-resource/pom.xml create mode 100644 mcwl-resource/src/main/java/com/mcwl/McWlResourceApplication.java diff --git a/mcwl-common/pom.xml b/mcwl-common/pom.xml index dcf7212..e7b8731 100644 --- a/mcwl-common/pom.xml +++ b/mcwl-common/pom.xml @@ -23,6 +23,17 @@ org.springframework spring-context-support + + com.github.tobato + fastdfs-client + 1.26.5 + + + + + org.springframework.boot + spring-boot-starter-quartz + diff --git a/mcwl-common/src/main/java/com/mcwl/common/config/BloomFilterUtil.java b/mcwl-common/src/main/java/com/mcwl/common/config/BloomFilterUtil.java new file mode 100644 index 0000000..c9afee5 --- /dev/null +++ b/mcwl-common/src/main/java/com/mcwl/common/config/BloomFilterUtil.java @@ -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; + } + } + + +} diff --git a/mcwl-common/src/main/java/com/mcwl/common/config/FastConfig.java b/mcwl-common/src/main/java/com/mcwl/common/config/FastConfig.java new file mode 100644 index 0000000..0c7e862 --- /dev/null +++ b/mcwl-common/src/main/java/com/mcwl/common/config/FastConfig.java @@ -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 { + +} diff --git a/mcwl-common/src/main/java/com/mcwl/common/config/FastUtil.java b/mcwl-common/src/main/java/com/mcwl/common/config/FastUtil.java new file mode 100644 index 0000000..58e4155 --- /dev/null +++ b/mcwl-common/src/main/java/com/mcwl/common/config/FastUtil.java @@ -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 "删除成功"; + } + +} diff --git a/mcwl-resource/pom.xml b/mcwl-resource/pom.xml new file mode 100644 index 0000000..2f15a70 --- /dev/null +++ b/mcwl-resource/pom.xml @@ -0,0 +1,100 @@ + + + 4.0.0 + + com.mcwl + mcwl + 3.8.8 + + + mcwl-resource + + + resource资源中心模块 + + + + + + com.mcwl + mcwl-common + + + + + org.springframework.boot + spring-boot-devtools + true + + + + + io.springfox + springfox-boot-starter + + + + + io.swagger + swagger-models + 1.6.2 + + + + + mysql + mysql-connector-java + + + + + com.mcwl + mcwl-framework + + + + + com.mcwl + mcwl-quartz + + + + + com.mcwl + mcwl-generator + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + 2.5.15 + + true + + + + + repackage + + + + + + org.apache.maven.plugins + maven-war-plugin + 3.1.0 + + false + ${project.artifactId} + + + + ${project.artifactId} + + diff --git a/mcwl-resource/src/main/java/com/mcwl/McWlResourceApplication.java b/mcwl-resource/src/main/java/com/mcwl/McWlResourceApplication.java new file mode 100644 index 0000000..ca863af --- /dev/null +++ b/mcwl-resource/src/main/java/com/mcwl/McWlResourceApplication.java @@ -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" + + " ''-' `'-' `-..-' "); + } +} diff --git a/pom.xml b/pom.xml index 38cb07c..aa2fb2f 100644 --- a/pom.xml +++ b/pom.xml @@ -228,6 +228,7 @@ mcwl-quartz mcwl-generator mcwl-common + mcwl-resource pom