parent
4d563a11cf
commit
18495e0f37
@ -0,0 +1,15 @@ |
||||
package cn.toesbieya.jxc.api; |
||||
|
||||
import java.util.List; |
||||
|
||||
public interface FileApi { |
||||
String getToken(); |
||||
|
||||
void delete(String key); |
||||
|
||||
void deleteBatch(String... key); |
||||
|
||||
default void deleteBatch(List<String> key) { |
||||
deleteBatch(key.toArray(new String[0])); |
||||
} |
||||
} |
||||
@ -1,4 +1,4 @@ |
||||
package cn.toesbieya.jxc.api.service; |
||||
package cn.toesbieya.jxc.api; |
||||
|
||||
import cn.toesbieya.jxc.common.model.entity.BizStock; |
||||
import cn.toesbieya.jxc.common.model.vo.StockOutboundVo; |
||||
@ -1,4 +1,4 @@ |
||||
package cn.toesbieya.jxc.api.service.system; |
||||
package cn.toesbieya.jxc.api.system; |
||||
|
||||
import cn.toesbieya.jxc.common.model.entity.SysUser; |
||||
import cn.toesbieya.jxc.common.model.vo.DepartmentVo; |
||||
@ -1,4 +1,4 @@ |
||||
package cn.toesbieya.jxc.api.service.system; |
||||
package cn.toesbieya.jxc.api.system; |
||||
|
||||
import cn.toesbieya.jxc.common.model.entity.SysRole; |
||||
import cn.toesbieya.jxc.common.model.vo.ResourceVo; |
||||
@ -1,4 +1,4 @@ |
||||
package cn.toesbieya.jxc.api.service.system; |
||||
package cn.toesbieya.jxc.api.system; |
||||
|
||||
import cn.toesbieya.jxc.common.model.entity.SysRole; |
||||
|
||||
@ -1,18 +0,0 @@ |
||||
package cn.toesbieya.jxc.api.vo; |
||||
|
||||
import cn.toesbieya.jxc.common.model.entity.RecAttachment; |
||||
import lombok.AllArgsConstructor; |
||||
import lombok.Data; |
||||
import lombok.NoArgsConstructor; |
||||
|
||||
import java.io.Serializable; |
||||
import java.util.List; |
||||
|
||||
@Data |
||||
@NoArgsConstructor |
||||
@AllArgsConstructor |
||||
public class AttachmentOperation implements Serializable { |
||||
private static final long serialVersionUID = 1L; |
||||
private List<RecAttachment> uploadImageList; |
||||
private List<String> deleteImageList; |
||||
} |
||||
@ -1,4 +1,4 @@ |
||||
package cn.toesbieya.jxc.common.utils; |
||||
package cn.toesbieya.jxc.common.util; |
||||
|
||||
import java.time.Instant; |
||||
import java.time.LocalDateTime; |
||||
@ -1,4 +1,4 @@ |
||||
package cn.toesbieya.jxc.common.utils; |
||||
package cn.toesbieya.jxc.common.util; |
||||
|
||||
import com.google.common.io.ByteStreams; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
@ -1,4 +1,4 @@ |
||||
package cn.toesbieya.jxc.common.utils; |
||||
package cn.toesbieya.jxc.common.util; |
||||
|
||||
import cn.toesbieya.jxc.common.model.entity.SysUser; |
||||
import cn.toesbieya.jxc.common.model.vo.UserVo; |
||||
@ -1,4 +1,4 @@ |
||||
package cn.toesbieya.jxc.common.utils; |
||||
package cn.toesbieya.jxc.common.util; |
||||
|
||||
import org.springframework.expression.EvaluationContext; |
||||
import org.springframework.expression.ExpressionParser; |
||||
@ -1,4 +1,4 @@ |
||||
package cn.toesbieya.jxc.common.utils; |
||||
package cn.toesbieya.jxc.common.util; |
||||
|
||||
import org.springframework.util.StringUtils; |
||||
|
||||
@ -1,4 +1,4 @@ |
||||
package cn.toesbieya.jxc.common.utils; |
||||
package cn.toesbieya.jxc.common.util; |
||||
|
||||
import cn.toesbieya.jxc.common.model.vo.SocketEventVo; |
||||
import cn.toesbieya.jxc.common.constant.SocketConstant; |
||||
@ -1,3 +1,6 @@ |
||||
server: |
||||
port: 8002 |
||||
|
||||
qiniu: |
||||
access-key: |
||||
secret-key: |
||||
@ -1,4 +1,4 @@ |
||||
server: |
||||
port: 8002 |
||||
port: 8003 |
||||
servlet: |
||||
context-path: /message |
||||
@ -1,2 +1,2 @@ |
||||
server: |
||||
port: 8003 |
||||
port: 8004 |
||||
@ -1,2 +1,2 @@ |
||||
server: |
||||
port: 8004 |
||||
port: 8005 |
||||
@ -1,2 +1,2 @@ |
||||
server: |
||||
port: 8005 |
||||
port: 8006 |
||||
@ -1,4 +1,4 @@ |
||||
server: |
||||
port: 8006 |
||||
port: 8007 |
||||
servlet: |
||||
context-path: /system |
||||
@ -0,0 +1,20 @@ |
||||
<?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"> |
||||
<parent> |
||||
<artifactId>web</artifactId> |
||||
<groupId>cn.toesbieya</groupId> |
||||
<version>0.0.1-SNAPSHOT</version> |
||||
</parent> |
||||
<modelVersion>4.0.0</modelVersion> |
||||
|
||||
<artifactId>file</artifactId> |
||||
|
||||
<dependencies> |
||||
<dependency> |
||||
<groupId>com.qiniu</groupId> |
||||
<artifactId>qiniu-java-sdk</artifactId> |
||||
</dependency> |
||||
</dependencies> |
||||
</project> |
||||
@ -0,0 +1,11 @@ |
||||
package cn.toesbieya.jxc.file; |
||||
|
||||
import org.springframework.boot.SpringApplication; |
||||
import org.springframework.boot.autoconfigure.SpringBootApplication; |
||||
|
||||
@SpringBootApplication(scanBasePackages = "cn.toesbieya.jxc") |
||||
public class FileApplication { |
||||
public static void main(String[] args) { |
||||
SpringApplication.run(FileApplication.class, args); |
||||
} |
||||
} |
||||
@ -0,0 +1,16 @@ |
||||
package cn.toesbieya.jxc.file.config; |
||||
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties; |
||||
import org.springframework.context.annotation.Bean; |
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.context.annotation.DependsOn; |
||||
|
||||
@Configuration |
||||
@EnableConfigurationProperties(QiniuProperty.class) |
||||
@DependsOn("redisUtil") |
||||
public class QiniuConfig { |
||||
@Bean |
||||
public QiniuTemplate qiniuTemplate(QiniuProperty property) { |
||||
return new QiniuTemplate(property); |
||||
} |
||||
} |
||||
@ -0,0 +1,45 @@ |
||||
package cn.toesbieya.jxc.file.config; |
||||
|
||||
import com.qiniu.storage.Region; |
||||
import lombok.Data; |
||||
import org.springframework.boot.context.properties.ConfigurationProperties; |
||||
import org.springframework.cloud.context.config.annotation.RefreshScope; |
||||
|
||||
@Data |
||||
@ConfigurationProperties("qiniu") |
||||
@RefreshScope |
||||
public class QiniuProperty { |
||||
private String accessKey; |
||||
|
||||
private String secretKey; |
||||
|
||||
private String bucket; |
||||
|
||||
//机房区域,默认为自动
|
||||
private QiniuRegion region = QiniuRegion.auto; |
||||
|
||||
//临时上传凭证的有效期,单位秒
|
||||
private Integer tokenExpire = 3600; |
||||
|
||||
//临时上传凭证的redis键名
|
||||
private String redisCacheKey = "qiniu-token"; |
||||
|
||||
enum QiniuRegion { |
||||
auto(Region.autoRegion()), |
||||
huadong(Region.huadong()), |
||||
huabei(Region.huabei()), |
||||
huanan(Region.huanan()), |
||||
beimei(Region.beimei()), |
||||
xinjiapo(Region.xinjiapo()); |
||||
|
||||
private final Region region; |
||||
|
||||
QiniuRegion(Region region) { |
||||
this.region = region; |
||||
} |
||||
|
||||
public Region getRegion() { |
||||
return this.region; |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,54 @@ |
||||
package cn.toesbieya.jxc.file.config; |
||||
|
||||
import cn.toesbieya.jxc.common.util.RedisUtil; |
||||
import com.qiniu.common.QiniuException; |
||||
import com.qiniu.storage.BucketManager; |
||||
import com.qiniu.storage.Configuration; |
||||
import com.qiniu.util.Auth; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
|
||||
@Slf4j |
||||
public class QiniuTemplate { |
||||
private final QiniuProperty property; |
||||
private final Auth auth; |
||||
private final BucketManager bucketManager; |
||||
|
||||
public QiniuTemplate(QiniuProperty property) { |
||||
this.property = property; |
||||
this.auth = Auth.create(property.getAccessKey(), property.getSecretKey()); |
||||
this.bucketManager = new BucketManager(this.auth, new Configuration(property.getRegion().getRegion())); |
||||
} |
||||
|
||||
public String getToken() { |
||||
String key = property.getRedisCacheKey(); |
||||
|
||||
String token = (String) RedisUtil.get(key); |
||||
|
||||
if (token == null) { |
||||
token = auth.uploadToken(property.getBucket()); |
||||
RedisUtil.set(key, token, property.getTokenExpire()); |
||||
} |
||||
|
||||
return token; |
||||
} |
||||
|
||||
public void delete(String key) { |
||||
try { |
||||
bucketManager.delete(property.getBucket(), key); |
||||
} |
||||
catch (QiniuException e) { |
||||
log.info("七牛云删除单个文件失败,{}", e.getMessage()); |
||||
} |
||||
} |
||||
|
||||
public void deleteBatch(String... key) { |
||||
BucketManager.BatchOperations batchOperations = new BucketManager.BatchOperations(); |
||||
batchOperations.addDeleteOp(property.getBucket(), key); |
||||
try { |
||||
bucketManager.batch(batchOperations); |
||||
} |
||||
catch (QiniuException e) { |
||||
log.info("七牛云批量删除文件失败,{}", e.getMessage()); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,33 @@ |
||||
package cn.toesbieya.jxc.file.controller; |
||||
|
||||
import cn.toesbieya.jxc.common.model.vo.Result; |
||||
import cn.toesbieya.jxc.file.service.FileService; |
||||
import org.springframework.stereotype.Controller; |
||||
import org.springframework.web.bind.annotation.GetMapping; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RequestParam; |
||||
import org.springframework.web.bind.annotation.ResponseBody; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.io.UnsupportedEncodingException; |
||||
import java.net.URLDecoder; |
||||
|
||||
@Controller |
||||
@RequestMapping("file") |
||||
public class FileController { |
||||
@Resource |
||||
private FileService service; |
||||
|
||||
@GetMapping("delete") |
||||
@ResponseBody |
||||
public Result delete(@RequestParam String url) throws UnsupportedEncodingException { |
||||
service.delete(URLDecoder.decode(url, "utf-8")); |
||||
return Result.success("删除成功"); |
||||
} |
||||
|
||||
@GetMapping("getToken") |
||||
@ResponseBody |
||||
public Result getToken() { |
||||
return Result.success(null, service.getToken()); |
||||
} |
||||
} |
||||
@ -0,0 +1,34 @@ |
||||
package cn.toesbieya.jxc.file.service; |
||||
|
||||
import cn.toesbieya.jxc.api.FileApi; |
||||
import cn.toesbieya.jxc.file.config.QiniuTemplate; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import javax.annotation.Resource; |
||||
|
||||
@Service |
||||
@org.apache.dubbo.config.annotation.Service |
||||
public class FileService implements FileApi { |
||||
@Resource |
||||
private QiniuTemplate template; |
||||
|
||||
@Override |
||||
public String getToken() { |
||||
return template.getToken(); |
||||
} |
||||
|
||||
@Override |
||||
public void delete(String key) { |
||||
template.delete(key); |
||||
} |
||||
|
||||
@Override |
||||
public void deleteBatch(String... key) { |
||||
template.deleteBatch(key); |
||||
} |
||||
|
||||
/*@Override |
||||
public void deleteBatch(List<String> key) { |
||||
deleteBatch(key.toArray(new String[0])); |
||||
}*/ |
||||
} |
||||
@ -0,0 +1,22 @@ |
||||
spring: |
||||
application: |
||||
name: jxc-web-file |
||||
|
||||
cloud: |
||||
nacos: |
||||
config: |
||||
server-addr: 127.0.0.1:8848 |
||||
file-extension: yml |
||||
shared-configs: |
||||
- data-id: jxc-common-redis.yml |
||||
discovery: |
||||
server-addr: 127.0.0.1:8848 |
||||
|
||||
dubbo: |
||||
protocol: |
||||
port: -1 |
||||
name: dubbo |
||||
scan: |
||||
base-packages: cn.toesbieya.jxc.file.service |
||||
registry: |
||||
address: nacos://127.0.0.1:8848 |
||||
@ -1,24 +0,0 @@ |
||||
package cn.toesbieya.jxc.web.common.config; |
||||
|
||||
import lombok.Data; |
||||
import org.springframework.boot.context.properties.ConfigurationProperties; |
||||
import org.springframework.cloud.context.config.annotation.RefreshScope; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
@Component |
||||
@ConfigurationProperties("qiniu") |
||||
@RefreshScope |
||||
@Data |
||||
public class QiniuConfig { |
||||
private String accessKey; |
||||
|
||||
private String secretKey; |
||||
|
||||
private String bucket; |
||||
|
||||
//临时上传凭证的有效期,单位秒
|
||||
private Integer tokenExpire = 3600; |
||||
|
||||
//临时上传凭证的redis键名
|
||||
private String redisCacheKey = "qiniu-token"; |
||||
} |
||||
@ -1,4 +1,4 @@ |
||||
package cn.toesbieya.jxc.web.common.utils; |
||||
package cn.toesbieya.jxc.web.common.util; |
||||
|
||||
import cn.toesbieya.jxc.common.model.vo.Result; |
||||
import com.alibaba.excel.EasyExcel; |
||||
@ -1,4 +1,4 @@ |
||||
package cn.toesbieya.jxc.web.common.utils; |
||||
package cn.toesbieya.jxc.web.common.util; |
||||
|
||||
import okhttp3.Call; |
||||
import okhttp3.OkHttpClient; |
||||
@ -1,6 +1,6 @@ |
||||
package cn.toesbieya.jxc.web.common.utils; |
||||
package cn.toesbieya.jxc.web.common.util; |
||||
|
||||
import cn.toesbieya.jxc.common.utils.RedisUtil; |
||||
import cn.toesbieya.jxc.common.util.RedisUtil; |
||||
import com.alibaba.fastjson.JSON; |
||||
import com.alibaba.fastjson.JSONArray; |
||||
import com.alibaba.fastjson.JSONObject; |
||||
@ -1,4 +1,4 @@ |
||||
package cn.toesbieya.jxc.web.common.utils; |
||||
package cn.toesbieya.jxc.web.common.util; |
||||
|
||||
import cn.toesbieya.jxc.common.model.vo.UserVo; |
||||
|
||||
@ -1,8 +1,8 @@ |
||||
package cn.toesbieya.jxc.web.common.utils; |
||||
package cn.toesbieya.jxc.web.common.util; |
||||
|
||||
import cn.toesbieya.jxc.common.model.vo.UserVo; |
||||
|
||||
public class SessionUtil extends cn.toesbieya.jxc.common.utils.SessionUtil { |
||||
public class SessionUtil extends cn.toesbieya.jxc.common.util.SessionUtil { |
||||
public static UserVo get() { |
||||
UserVo user = ThreadUtil.getUser(); |
||||
return user == null ? get(WebUtil.getRequest()) : user; |
||||
@ -1,8 +1,8 @@ |
||||
package cn.toesbieya.jxc.web.common.utils; |
||||
package cn.toesbieya.jxc.web.common.util; |
||||
|
||||
import cn.toesbieya.jxc.common.model.entity.RecUserAction; |
||||
import cn.toesbieya.jxc.common.model.vo.UserVo; |
||||
import cn.toesbieya.jxc.common.utils.SessionUtil; |
||||
import cn.toesbieya.jxc.common.util.SessionUtil; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
|
||||
@ -1,76 +0,0 @@ |
||||
package cn.toesbieya.jxc.web.common.utils; |
||||
|
||||
import cn.toesbieya.jxc.common.utils.RedisUtil; |
||||
import cn.toesbieya.jxc.web.common.config.QiniuConfig; |
||||
import com.qiniu.common.QiniuException; |
||||
import com.qiniu.storage.BucketManager; |
||||
import com.qiniu.storage.Configuration; |
||||
import com.qiniu.storage.Region; |
||||
import com.qiniu.util.Auth; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.context.annotation.DependsOn; |
||||
import org.springframework.stereotype.Component; |
||||
import org.springframework.util.StringUtils; |
||||
|
||||
import java.util.List; |
||||
|
||||
@Slf4j |
||||
@Component |
||||
@DependsOn("redisUtil") |
||||
public class QiniuUtil { |
||||
private final QiniuConfig config; |
||||
private final Auth auth; |
||||
private final BucketManager bucketManager; |
||||
|
||||
@Autowired |
||||
public QiniuUtil(QiniuConfig config) { |
||||
this.config = config; |
||||
|
||||
if (StringUtils.isEmpty(config.getAccessKey())) { |
||||
this.auth = null; |
||||
this.bucketManager = null; |
||||
return; |
||||
} |
||||
|
||||
this.auth = Auth.create(config.getAccessKey(), config.getSecretKey()); |
||||
this.bucketManager = new BucketManager(this.auth, new Configuration(Region.huadong())); |
||||
} |
||||
|
||||
public String getToken() { |
||||
String key = config.getRedisCacheKey(); |
||||
|
||||
String token = (String) RedisUtil.get(key); |
||||
|
||||
if (token == null) { |
||||
token = auth.uploadToken(config.getBucket()); |
||||
RedisUtil.set(key, token, config.getTokenExpire()); |
||||
} |
||||
|
||||
return token; |
||||
} |
||||
|
||||
public void delete(String key) { |
||||
try { |
||||
bucketManager.delete(config.getBucket(), key); |
||||
} |
||||
catch (QiniuException e) { |
||||
log.info("七牛云删除单个文件失败,{}", e.getMessage()); |
||||
} |
||||
} |
||||
|
||||
public void deleteBatch(String... key) { |
||||
BucketManager.BatchOperations batchOperations = new BucketManager.BatchOperations(); |
||||
batchOperations.addDeleteOp(config.getBucket(), key); |
||||
try { |
||||
bucketManager.batch(batchOperations); |
||||
} |
||||
catch (QiniuException e) { |
||||
log.info("七牛云批量删除文件失败,{}", e.getMessage()); |
||||
} |
||||
} |
||||
|
||||
public void deleteBatch(List<String> key) { |
||||
deleteBatch(key.toArray(new String[0])); |
||||
} |
||||
} |
||||
Loading…
Reference in new issue