2151adf1 by 夏齐

首次提交

1 parent aa72ced8
package com.pashanhoo.common;
import com.alibaba.fastjson.JSONObject;
import com.pashanhoo.qys.service.SysFileService;
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.mock.web.MockMultipartFile;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
import java.io.*;
import java.net.HttpURLConnection;
......@@ -27,6 +31,8 @@ public class EciHttpUtil {
@Value("${app.eciPath}")
private String eciPath;
@Autowired
private SysFileService sysFileService;
......@@ -143,11 +149,13 @@ public class EciHttpUtil {
* @param documentId 合同文档ID
* @return
*/
public String download(String documentId,String bh,String htlx,String areacode) {
public String[] download(String documentId,String bh,String htlx,String areacode) {
String url = hostUrl + "/document/download" + "?documentId=" + documentId;
InputStream in = null;
String absolutePath = "";
String localPath = "";
String minioPath="";
OutputStream out = null;
String backUrl[]=new String[2];
try{
URL url1=new URL(url);
HttpURLConnection conn= (HttpURLConnection) url1.openConnection();
......@@ -173,7 +181,7 @@ public class EciHttpUtil {
in =conn.getInputStream();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy");
String dateDir = simpleDateFormat.format(new Date());
File savePath = new File(eciPath+"ECI\\"+areacode+"\\"+ htlx+dateDir+bh);
File savePath = new File(eciPath+"ECI\\"+areacode+"\\"+ htlx+dateDir+bh);
if (!savePath.exists()) {
savePath.mkdirs();
}
......@@ -181,15 +189,26 @@ public class EciHttpUtil {
if (!filePath.exists()){
filePath.createNewFile();
}
byte[] bytes = cloneInputStream(in);
InputStream fileInputStream = new ByteArrayInputStream(bytes);
out = new FileOutputStream(filePath);
byte[] buffer = new byte[4096];
int readLength = 0;
while ((readLength = in.read(buffer)) != -1) {
while ((readLength = fileInputStream.read(buffer)) != -1) {
out.write(buffer, 0, readLength);
}
absolutePath = filePath.getAbsolutePath();
out.flush();
localPath = filePath.getAbsolutePath();
backUrl[0]=localPath;
InputStream newInputStream = new ByteArrayInputStream(bytes);
MultipartFile multipartFile = new MockMultipartFile(
"File", documentId+".ofd",
"text/plain",
newInputStream);
String miniofilePath=areacode+"/"+ htlx+dateDir+bh+"/"+documentId+".ofd";
minioPath=sysFileService.uploadFileMinio(multipartFile,miniofilePath);
backUrl[1]=minioPath;
}catch (Exception ex){
logger.info("发送 POST 请求出现异常!" + ex);
ex.printStackTrace();
......@@ -205,7 +224,30 @@ public class EciHttpUtil {
ex.printStackTrace();
}
}
return absolutePath;
return backUrl;
}
/**
* 将流存在缓存流中,这样可以重复使用
* @param input
* @return
*/
private static byte[] cloneInputStream(InputStream input) {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len;
while ((len = input.read(buffer)) > -1) {
baos.write(buffer, 0, len);
}
baos.flush();
baos.close();
input.close();
return baos.toByteArray();
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
......
......@@ -155,5 +155,17 @@ public class ElecLicenseInfoDo {
@TableField("ZJH")
private String zjh;
/**
* ofd在minion服务器上的地址
*/
@TableField("MINIO_OFD_URL")
private String minio_ofd_url;
/**
* jpg在minion服务器上的地址
*/
@TableField("MINIO_JPG_URL")
private String minio_jpg_url;
}
......
......@@ -2,13 +2,11 @@ package com.pashanhoo.qys.service;
import org.springframework.web.multipart.MultipartFile;
/**
* @author CAIYONGSONG
* @commpany www.pashanhoo.com
* @date 2022/7/20
*/
public interface SysFileService {
public String uploadFileMinio(MultipartFile file);
public String uploadFileMinio(MultipartFile[] file);
public String uploadFileMinio(MultipartFile file,String filePath);
}
......
package com.pashanhoo.qys.service.impl;
import cn.hutool.core.util.ArrayUtil;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.zxing.EncodeHintType;
......@@ -8,6 +9,7 @@ import com.pashanhoo.common.Result;
import com.pashanhoo.qys.entity.ElecLicenseInfoDo;
import com.pashanhoo.qys.mapper.ElecLicenseInfoMapper;
import com.pashanhoo.qys.service.EciService;
import com.pashanhoo.qys.service.SysFileService;
import com.pashanhoo.zhj.mapper.RegBusBdcqzsdjxxMapper;
import net.glxn.qrgen.core.image.ImageType;
import net.glxn.qrgen.javase.QRCode;
......@@ -19,13 +21,13 @@ 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.mock.web.MockMultipartFile;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.*;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.nio.file.Path;
......@@ -58,6 +60,8 @@ public class EciServiceImpl extends ServiceImpl<ElecLicenseInfoMapper, ElecLicen
private ElecLicenseInfoMapper elecLicenseInfoMapper;
@Autowired
private EciHttpUtil eciHttpUtil;
@Autowired
private SysFileService sysFileService;
......@@ -403,12 +407,17 @@ public class EciServiceImpl extends ServiceImpl<ElecLicenseInfoMapper, ElecLicen
String documentId = waitForDownload.getDocumentId();
String bh=waitForDownload.getZsbh();
String htlx=waitForDownload.getHtlx();
String ofdPath = eciHttpUtil.download(documentId,bh,htlx,areacode);
if (StringUtils.isNotBlank(ofdPath)) {
String backUrl[] = eciHttpUtil.download(documentId,bh,htlx,areacode);
if (ArrayUtil.isNotEmpty(backUrl)) {
//入库ofd文件地址
waitForDownload.setSfxz("1");
waitForDownload.setOfdWjdz(ofdPath);
waitForDownload.setOfdWjdz(backUrl[0]);
if(backUrl.length>1){
waitForDownload.setMinio_ofd_url(backUrl[1]);
}
waitForDownload.setErr_state("0");
}else{
waitForDownload.setErr_state("3");
}
......@@ -432,6 +441,14 @@ public class EciServiceImpl extends ServiceImpl<ElecLicenseInfoMapper, ElecLicen
String dateDir = simpleDateFormat.format(new Date());
String url=ofdToImg(ofdPath,eciPath+"ECI\\"+areacode+"\\"+ htlx+dateDir+bh+"\\",id);
if(StringUtils.isNotBlank(url)){
InputStream imageStream=new FileInputStream(new File(url));
MultipartFile multipartFile = new MockMultipartFile(
"File", id+ImageType.JPG,
"text/plain",
imageStream);
String miniofilePath=areacode+"/"+ htlx+dateDir+bh+"/"+id+".jpg";
String minioPath=sysFileService.uploadFileMinio(multipartFile,miniofilePath);
waitForConvert.setMinio_jpg_url(minioPath);
waitForConvert.setSfzh("1");
waitForConvert.setJpgWjdz(url);
waitForConvert.setErr_state("0");
......
......@@ -60,6 +60,34 @@ public class SysFileServiceImpl implements SysFileService {
}
@Override
public String uploadFileMinio(MultipartFile file, String filePath) {
Long st = System.currentTimeMillis();
if (file.isEmpty()) {
throw new RuntimeException("文件不存在!");
}
log.info("开始上传单个文件,文件大小:" + (file.getSize()/1024) + "KB");
// 判断存储桶是否存在
if (!minioUtil.bucketExists(minioConfig.getBucketName())) {
minioUtil.makeBucket(minioConfig.getBucketName());
}
// 生成文件名 按照要求-带文件夹路径的文件的全路径
String fineName = filePath;
try {
// 上传文件
minioUtil.upload(file, fineName, minioConfig.getBucketName());
} catch (Exception e) {
System.out.println("上传minio服务器期出错了 " + e.getMessage());
e.printStackTrace();
return null;
}
String url = minioConfig.getMinioUrl() + "/" + minioConfig.getBucketName() + "/" + fineName;
log.info("上传文件结束,总耗时:"+(System.currentTimeMillis() - st) +"ms, 文件路径:" + url );
return url;
}
@Override
public String uploadFileMinio(MultipartFile file) {
Long st = System.currentTimeMillis();
if (file.isEmpty()) {
......
......@@ -80,7 +80,7 @@ minio:
# 密码
secretKey: minioadmin
# MinIO桶名字
bucketName: ecibucket
bucketName: eci
swagger2:
enable: true
......