添加上传文件服务器功能
This commit is contained in:
150
src/main/java/com/xkrs/service/impl/FileServerServiceImpl.java
Normal file
150
src/main/java/com/xkrs/service/impl/FileServerServiceImpl.java
Normal file
@ -0,0 +1,150 @@
|
||||
package com.xkrs.service.impl;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.xkrs.model.vo.FileServerResultVo;
|
||||
import com.xkrs.model.vo.FileServiceResDetailVo;
|
||||
import com.xkrs.service.FileServerService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.xkrs.util.FileServerTool.postFileManage;
|
||||
import static com.xkrs.util.RequestUtil.postFile;
|
||||
|
||||
/**
|
||||
* 文件服务器接口
|
||||
* @author tajochen
|
||||
*/
|
||||
@Service
|
||||
public class FileServerServiceImpl implements FileServerService {
|
||||
|
||||
Logger logger = LoggerFactory.getLogger(FileServerServiceImpl.class);
|
||||
|
||||
@Value("${my.FileServerAdminAdress}")
|
||||
private String fileServerAdminAdress;
|
||||
|
||||
@Value("${my.FileServerAdress}")
|
||||
private String fileServerAdress;
|
||||
|
||||
/**
|
||||
* 上传文件
|
||||
* @param theFile 本地文件
|
||||
* @param path 文件服务器路径 项目名/功能模块名/具体分类名根据业务定
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public FileServiceResDetailVo uploadFile(File theFile, String path){
|
||||
Map<String,String> postParam = new HashMap<>(16);
|
||||
postParam.put("output","json");
|
||||
postParam.put("path",path);
|
||||
postParam.put("scene","");
|
||||
String resFileServer = postFile(theFile, fileServerAdress+"/group1/upload", postParam);
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
FileServiceResDetailVo result = null;
|
||||
try {
|
||||
result = objectMapper.readValue(resFileServer,FileServiceResDetailVo.class);
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件统计信息
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public FileServerResultVo getFileStat(){
|
||||
String requestUrl = fileServerAdminAdress + "/group1/stat";
|
||||
Map<String,String> map = new HashMap<>(16);
|
||||
return postFileManage(requestUrl,map);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文件
|
||||
* @param md5 信息摘要
|
||||
* @param path 路径
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public FileServerResultVo deleteFile(String md5,String path){
|
||||
String requestUrl = fileServerAdminAdress + "/group1/delete";
|
||||
Map<String,String> map = new HashMap<>(16);
|
||||
if(md5 != null && !md5.isEmpty()){
|
||||
map.put("md5",md5);
|
||||
}
|
||||
if(path != null && !path.isEmpty()){
|
||||
map.put("path",path);
|
||||
}
|
||||
return postFileManage(requestUrl,map);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件信息
|
||||
* @param md5 信息摘要
|
||||
* @param path 路径
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public FileServerResultVo getFileInfo(String md5,String path){
|
||||
String requestUrl = fileServerAdminAdress + "/group1/get_file_info";
|
||||
Map<String,String> map = new HashMap<>(16);
|
||||
if(md5 != null && !md5.isEmpty()){
|
||||
map.put("md5",md5);
|
||||
}
|
||||
if(path != null && !path.isEmpty()){
|
||||
map.put("path",path);
|
||||
}
|
||||
return postFileManage(requestUrl,map);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件列表
|
||||
* @param dir 目录名
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public FileServerResultVo getFileList(String dir){
|
||||
String requestUrl = fileServerAdminAdress + "/group1/list_dir";
|
||||
Map<String,String> map = new HashMap<>(16);
|
||||
map.put("dir",dir);
|
||||
return postFileManage(requestUrl,map);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修复统计信息
|
||||
* @param date 要修复的日期,格式如:20190725
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public FileServerResultVo getFileRepairStat(String date){
|
||||
String requestUrl = fileServerAdminAdress + "/group1/repair_stat";
|
||||
Map<String,String> map = new HashMap<>(16);
|
||||
map.put("date",date);
|
||||
return postFileManage(requestUrl,map);
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步失败修复
|
||||
* @param force 是否强行修复(0|1)
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public FileServerResultVo getFileRepair(String force){
|
||||
String requestUrl = fileServerAdminAdress + "/group1/repair";
|
||||
Map<String,String> map = new HashMap<>(16);
|
||||
map.put("force",force);
|
||||
return postFileManage(requestUrl,map);
|
||||
}
|
||||
|
||||
public static void main(){
|
||||
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user