Merge branch 'feature/resource' of https://gitea.qinmian.online/CY/mcwl-ai into preview
commit
3785ce626c
|
@ -23,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>
|
||||
|
|
|
@ -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,26 @@
|
|||
<?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>
|
Loading…
Reference in New Issue