feat: There is no way the,

This commit is contained in:
Superman_Main
2021-11-27 19:50:56 +08:00
parent 90f15e4401
commit 5c4f8108d7
9 changed files with 756 additions and 7 deletions
@@ -21,6 +21,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import sun.misc.BASE64Encoder;
@@ -30,6 +31,8 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotNull;
import java.io.*;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.nio.file.Files;
import java.text.SimpleDateFormat;
@@ -56,6 +59,9 @@ public class AttFileEOController {
@Value("${file.path}")
private String filePath;//文件存储路径
@Value("${stand.edit.file.path}")
private String standEditFilePath;
// @Autowired
// private RoleEOService roleEOService;
//
@@ -66,6 +72,89 @@ public class AttFileEOController {
private String uploadFileWhiteLists; //上传文件白名单
@ApiOperation(value = "|获取企标文件")
@GetMapping("/getBusStandFileByAttId")
public ResponseMessage<AttFileEO> getBusStandFileByAttId(String attId){
AttFileEO attFileEO = attFileEOService.saveOrGetBusFileInfo(attId);
return Result.success(attFileEO);
}
@ApiOperation(value = "|onlyOffice接收文件")
@PostMapping("/recieveFile")
public void recieveFile(HttpServletRequest request, HttpServletResponse response, String fileNm,String standNo){
logger.info("**********进入onlyoffice接收文档接口************");
try {
PrintWriter writer = response.getWriter();
String body = "";
try {
Scanner scanner = new Scanner(request.getInputStream());
scanner.useDelimiter("\\A");
body = scanner.hasNext() ? scanner.next() : "";
scanner.close();
} catch (Exception ex) {
writer.write("get request.getInputStream error:" + ex.getMessage());
return;
}
if (body.isEmpty()) {
writer.write("empty request.getInputStream");
return;
}
net.sf.json.JSONObject jsonObj = net.sf.json.JSONObject.fromObject(body);
logger.info("**********onlyoffice接收文档接口获得结果body************" + body);
int status = (Integer) jsonObj.get("status");
int saved = 0;
if (status == 2 || status == 3)//MustSave, Corrupted
{
String downloadUri = (String) jsonObj.get("url");
try {
logger.info("**********onlyoffice接收文档接口获得downloadUri************" + downloadUri);
if (StringUtils.isNotEmpty(downloadUri)) {
File file = new File(standEditFilePath + standNo + "\\" + fileNm);
downloadNetFile(downloadUri, file);
}
} catch (Exception ex) {
saved = 1;
logger.info("**********onlyoffice接收文档接口异常************" + ex.getMessage());
logger.error(ex.getMessage(),ex);
}
} else if (status == 4) {
logger.info("**********onlyoffice接收文档接口开始修改文件状态状态4************");
logger.info("**********onlyoffice接收文档接口修改文件状态成功状态4************");
}
logger.info("onlyoffice编辑完成--------------");
writer.write("{\"error\":" + saved + "}");
} catch (IOException e) {
logger.info("**********onlyoffice接收文档接口异常************" + e.getMessage());
logger.error(e.getMessage(),e);
return;
}
}
public void downloadNetFile(String downloadUrl, File file) {
try {
FileOutputStream fileOutputStream = new FileOutputStream(file);
URL url = new URL(downloadUrl);
URLConnection connection = url.openConnection();
InputStream inputStream = connection.getInputStream();
int length = 0;
byte[] bytes = new byte[1024];
while ((length = inputStream.read(bytes)) != -1) {
fileOutputStream.write(bytes, 0, length);
}
fileOutputStream.close();
inputStream.close();
} catch (IOException e) {
logger.error("download error ! url :{}, exception:{}", downloadUrl, e);
}
}
@ApiOperation(value="|File|上传文件")
@PostMapping(value="/upload",consumes="multipart/*",headers="content-type=multipart/form-data" )
@CrossOrigin(origins = "*", maxAge = 3600)
@@ -104,6 +193,8 @@ public class AttFileEOController {
String standName = oriFileName.replace(standNumber,"");
fileInfo.setStandName(standName);
}
// 上传转换文件
fileToConvert();
return Result.success("true", "上传成功", fileInfo);
} else {
return Result.error("文件上传失败");
@@ -116,6 +207,12 @@ public class AttFileEOController {
}
}
@Async
void fileToConvert(){
}
@ApiOperation(value="|File|上传文件")
@PostMapping(value="/uploadFiles",consumes="multipart/*",headers="content-type=multipart/form-data" )
@CrossOrigin(origins = "*", maxAge = 3600)
@@ -10,6 +10,8 @@ import java.util.List;
public interface IAttFileEOService extends IService<AttFileEO> {
AttFileEO saveOrGetBusFileInfo(String attId);
public AttFileVo saveFileInfo(File file);
public AttFileVo saveFileInfo(MultipartFile file);
@@ -11,6 +11,8 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
@@ -28,10 +30,77 @@ import java.util.List;
@Slf4j
public class AttFileEOServiceImpl extends ServiceImpl<AttFileEODao, AttFileEO> implements IAttFileEOService {
private static final Logger logger = LoggerFactory.getLogger(AttFileEOServiceImpl.class);
@Value("${file.path}")
private String filePath;//文件存储路径
/**
* 文件下载路径
*/
@Value("${file.downloadUrl}")
private String downloadUrl;
public AttFileEO saveOrGetBusFileInfo(String attId){
AttFileEO attFileEO=new AttFileEO();
if(StringUtils.isNotBlank(attId)){
attFileEO = this.getFileInfo(attId);
//2020年10月25日 此处补充文件的下载地址
StringBuffer downloadFileUrl = new StringBuffer();
downloadFileUrl.append(downloadUrl).append(attFileEO.getFilePath()).append(attFileEO.getFileName());
attFileEO.setDownLoadUrl(downloadFileUrl.toString());
}else{
String fileId = UUIDUtils.randomUUID20();
try {
String uuidPath = UUIDUtils.getUUIDPath(fileId);
String FileSavePath = filePath + uuidPath;
File dir = new File(FileSavePath);
if (!dir.exists()) {
dir.mkdirs();
}
File defaultBusFile =new File(filePath+"/modal/newStandFile.docx");
if(!defaultBusFile.exists()){
logger.error("默认标准文件不存在");
}
String fileName = "标准正文.docx";
String fileSuffix = ".docx";
String newFileName = fileId + fileSuffix;
File saveFile = new File(FileSavePath + newFileName);
// FileUtil.copyInputStreamToFile(file.get, saveFile);
FileUtils.copyFile(defaultBusFile,saveFile);
//开始存储文件信息
String tableName = UUIDUtils.getAttTable();
int existTable = this.baseMapper.existTable(tableName);
if (existTable == 0) {
this.baseMapper.creatTableInfo(tableName);
}
fileId = tableName + "_" + fileId;
attFileEO.setTableName(tableName);
attFileEO.setId(fileId);
attFileEO.setOldFileName(fileName);
attFileEO.setFileSuffix(fileSuffix);
attFileEO.setFilePath(uuidPath);
attFileEO.setFileName(newFileName);
attFileEO.setValidFlag(ValidFlagEnum.VALID_TRUE.getValue());
attFileEO.setCreationTime(new Date());
attFileEO.setModifyTime(new Date());
this.baseMapper.insert(attFileEO);
//2020年10月25日 此处补充文件的下载地址
StringBuffer downloadFileUrl=new StringBuffer();
downloadFileUrl.append(filePath).append(uuidPath).append(newFileName);
attFileEO.setDownLoadUrl(downloadFileUrl.toString());
} catch (IOException e) {
logger.error(e.getMessage(),e);
} catch (Exception e) {
logger.error(e.getMessage(),e);
}
}
return attFileEO;
}
/**
* 保存文件并返回文件ID