首次提交
Showing
6 changed files
with
116 additions
and
19 deletions
| 1 | package com.pashanhoo.common; | 1 | package com.pashanhoo.common; | 
| 2 | 2 | ||
| 3 | import com.alibaba.fastjson.JSONObject; | 3 | import com.alibaba.fastjson.JSONObject; | 
| 4 | import com.pashanhoo.qys.service.SysFileService; | ||
| 4 | import org.slf4j.Logger; | 5 | import org.slf4j.Logger; | 
| 5 | import org.slf4j.LoggerFactory; | 6 | import org.slf4j.LoggerFactory; | 
| 7 | import org.springframework.beans.factory.annotation.Autowired; | ||
| 6 | import org.springframework.beans.factory.annotation.Value; | 8 | import org.springframework.beans.factory.annotation.Value; | 
| 9 | import org.springframework.mock.web.MockMultipartFile; | ||
| 7 | import org.springframework.stereotype.Component; | 10 | import org.springframework.stereotype.Component; | 
| 11 | import org.springframework.web.multipart.MultipartFile; | ||
| 8 | 12 | ||
| 9 | import java.io.*; | 13 | import java.io.*; | 
| 10 | import java.net.HttpURLConnection; | 14 | import java.net.HttpURLConnection; | 
| ... | @@ -27,6 +31,8 @@ public class EciHttpUtil { | ... | @@ -27,6 +31,8 @@ public class EciHttpUtil { | 
| 27 | 31 | ||
| 28 | @Value("${app.eciPath}") | 32 | @Value("${app.eciPath}") | 
| 29 | private String eciPath; | 33 | private String eciPath; | 
| 34 | @Autowired | ||
| 35 | private SysFileService sysFileService; | ||
| 30 | 36 | ||
| 31 | 37 | ||
| 32 | 38 | ||
| ... | @@ -143,11 +149,13 @@ public class EciHttpUtil { | ... | @@ -143,11 +149,13 @@ public class EciHttpUtil { | 
| 143 | * @param documentId 合同文档ID | 149 | * @param documentId 合同文档ID | 
| 144 | * @return | 150 | * @return | 
| 145 | */ | 151 | */ | 
| 146 | public String download(String documentId,String bh,String htlx,String areacode) { | 152 | public String[] download(String documentId,String bh,String htlx,String areacode) { | 
| 147 | String url = hostUrl + "/document/download" + "?documentId=" + documentId; | 153 | String url = hostUrl + "/document/download" + "?documentId=" + documentId; | 
| 148 | InputStream in = null; | 154 | InputStream in = null; | 
| 149 | String absolutePath = ""; | 155 | String localPath = ""; | 
| 156 | String minioPath=""; | ||
| 150 | OutputStream out = null; | 157 | OutputStream out = null; | 
| 158 | String backUrl[]=new String[2]; | ||
| 151 | try{ | 159 | try{ | 
| 152 | URL url1=new URL(url); | 160 | URL url1=new URL(url); | 
| 153 | HttpURLConnection conn= (HttpURLConnection) url1.openConnection(); | 161 | HttpURLConnection conn= (HttpURLConnection) url1.openConnection(); | 
| ... | @@ -173,7 +181,7 @@ public class EciHttpUtil { | ... | @@ -173,7 +181,7 @@ public class EciHttpUtil { | 
| 173 | in =conn.getInputStream(); | 181 | in =conn.getInputStream(); | 
| 174 | SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy"); | 182 | SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy"); | 
| 175 | String dateDir = simpleDateFormat.format(new Date()); | 183 | String dateDir = simpleDateFormat.format(new Date()); | 
| 176 | File savePath = new File(eciPath+"ECI\\"+areacode+"\\"+ htlx+dateDir+bh); | 184 | File savePath = new File(eciPath+"ECI\\"+areacode+"\\"+ htlx+dateDir+bh); | 
| 177 | if (!savePath.exists()) { | 185 | if (!savePath.exists()) { | 
| 178 | savePath.mkdirs(); | 186 | savePath.mkdirs(); | 
| 179 | } | 187 | } | 
| ... | @@ -181,15 +189,26 @@ public class EciHttpUtil { | ... | @@ -181,15 +189,26 @@ public class EciHttpUtil { | 
| 181 | if (!filePath.exists()){ | 189 | if (!filePath.exists()){ | 
| 182 | filePath.createNewFile(); | 190 | filePath.createNewFile(); | 
| 183 | } | 191 | } | 
| 192 | byte[] bytes = cloneInputStream(in); | ||
| 193 | InputStream fileInputStream = new ByteArrayInputStream(bytes); | ||
| 184 | out = new FileOutputStream(filePath); | 194 | out = new FileOutputStream(filePath); | 
| 185 | byte[] buffer = new byte[4096]; | 195 | byte[] buffer = new byte[4096]; | 
| 186 | int readLength = 0; | 196 | int readLength = 0; | 
| 187 | 197 | while ((readLength = fileInputStream.read(buffer)) != -1) { | |
| 188 | while ((readLength = in.read(buffer)) != -1) { | ||
| 189 | out.write(buffer, 0, readLength); | 198 | out.write(buffer, 0, readLength); | 
| 190 | } | 199 | } | 
| 191 | absolutePath = filePath.getAbsolutePath(); | ||
| 192 | out.flush(); | 200 | out.flush(); | 
| 201 | localPath = filePath.getAbsolutePath(); | ||
| 202 | backUrl[0]=localPath; | ||
| 203 | |||
| 204 | InputStream newInputStream = new ByteArrayInputStream(bytes); | ||
| 205 | MultipartFile multipartFile = new MockMultipartFile( | ||
| 206 | "File", documentId+".ofd", | ||
| 207 | "text/plain", | ||
| 208 | newInputStream); | ||
| 209 | String miniofilePath=areacode+"/"+ htlx+dateDir+bh+"/"+documentId+".ofd"; | ||
| 210 | minioPath=sysFileService.uploadFileMinio(multipartFile,miniofilePath); | ||
| 211 | backUrl[1]=minioPath; | ||
| 193 | }catch (Exception ex){ | 212 | }catch (Exception ex){ | 
| 194 | logger.info("发送 POST 请求出现异常!" + ex); | 213 | logger.info("发送 POST 请求出现异常!" + ex); | 
| 195 | ex.printStackTrace(); | 214 | ex.printStackTrace(); | 
| ... | @@ -205,7 +224,30 @@ public class EciHttpUtil { | ... | @@ -205,7 +224,30 @@ public class EciHttpUtil { | 
| 205 | ex.printStackTrace(); | 224 | ex.printStackTrace(); | 
| 206 | } | 225 | } | 
| 207 | } | 226 | } | 
| 208 | return absolutePath; | 227 | return backUrl; | 
| 228 | } | ||
| 229 | |||
| 230 | /** | ||
| 231 | * 将流存在缓存流中,这样可以重复使用 | ||
| 232 | * @param input | ||
| 233 | * @return | ||
| 234 | */ | ||
| 235 | private static byte[] cloneInputStream(InputStream input) { | ||
| 236 | try { | ||
| 237 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); | ||
| 238 | byte[] buffer = new byte[1024]; | ||
| 239 | int len; | ||
| 240 | while ((len = input.read(buffer)) > -1) { | ||
| 241 | baos.write(buffer, 0, len); | ||
| 242 | } | ||
| 243 | baos.flush(); | ||
| 244 | baos.close(); | ||
| 245 | input.close(); | ||
| 246 | return baos.toByteArray(); | ||
| 247 | } catch (IOException e) { | ||
| 248 | e.printStackTrace(); | ||
| 249 | return null; | ||
| 250 | } | ||
| 209 | } | 251 | } | 
| 210 | 252 | ||
| 211 | 253 | ... | ... | 
| ... | @@ -155,5 +155,17 @@ public class ElecLicenseInfoDo { | ... | @@ -155,5 +155,17 @@ public class ElecLicenseInfoDo { | 
| 155 | @TableField("ZJH") | 155 | @TableField("ZJH") | 
| 156 | private String zjh; | 156 | private String zjh; | 
| 157 | 157 | ||
| 158 | /** | ||
| 159 | * ofd在minion服务器上的地址 | ||
| 160 | */ | ||
| 161 | @TableField("MINIO_OFD_URL") | ||
| 162 | private String minio_ofd_url; | ||
| 163 | |||
| 164 | /** | ||
| 165 | * jpg在minion服务器上的地址 | ||
| 166 | */ | ||
| 167 | @TableField("MINIO_JPG_URL") | ||
| 168 | private String minio_jpg_url; | ||
| 169 | |||
| 158 | 170 | ||
| 159 | } | 171 | } | ... | ... | 
| ... | @@ -2,13 +2,11 @@ package com.pashanhoo.qys.service; | ... | @@ -2,13 +2,11 @@ package com.pashanhoo.qys.service; | 
| 2 | 2 | ||
| 3 | import org.springframework.web.multipart.MultipartFile; | 3 | import org.springframework.web.multipart.MultipartFile; | 
| 4 | 4 | ||
| 5 | /** | 5 | |
| 6 | * @author CAIYONGSONG | 6 | |
| 7 | * @commpany www.pashanhoo.com | ||
| 8 | * @date 2022/7/20 | ||
| 9 | */ | ||
| 10 | public interface SysFileService { | 7 | public interface SysFileService { | 
| 11 | 8 | ||
| 12 | public String uploadFileMinio(MultipartFile file); | 9 | public String uploadFileMinio(MultipartFile file); | 
| 13 | public String uploadFileMinio(MultipartFile[] file); | 10 | public String uploadFileMinio(MultipartFile[] file); | 
| 11 | public String uploadFileMinio(MultipartFile file,String filePath); | ||
| 14 | } | 12 | } | ... | ... | 
| 1 | package com.pashanhoo.qys.service.impl; | 1 | package com.pashanhoo.qys.service.impl; | 
| 2 | 2 | ||
| 3 | import cn.hutool.core.util.ArrayUtil; | ||
| 3 | import com.alibaba.fastjson.JSON; | 4 | import com.alibaba.fastjson.JSON; | 
| 4 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | 5 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | 
| 5 | import com.google.zxing.EncodeHintType; | 6 | import com.google.zxing.EncodeHintType; | 
| ... | @@ -8,6 +9,7 @@ import com.pashanhoo.common.Result; | ... | @@ -8,6 +9,7 @@ import com.pashanhoo.common.Result; | 
| 8 | import com.pashanhoo.qys.entity.ElecLicenseInfoDo; | 9 | import com.pashanhoo.qys.entity.ElecLicenseInfoDo; | 
| 9 | import com.pashanhoo.qys.mapper.ElecLicenseInfoMapper; | 10 | import com.pashanhoo.qys.mapper.ElecLicenseInfoMapper; | 
| 10 | import com.pashanhoo.qys.service.EciService; | 11 | import com.pashanhoo.qys.service.EciService; | 
| 12 | import com.pashanhoo.qys.service.SysFileService; | ||
| 11 | import com.pashanhoo.zhj.mapper.RegBusBdcqzsdjxxMapper; | 13 | import com.pashanhoo.zhj.mapper.RegBusBdcqzsdjxxMapper; | 
| 12 | import net.glxn.qrgen.core.image.ImageType; | 14 | import net.glxn.qrgen.core.image.ImageType; | 
| 13 | import net.glxn.qrgen.javase.QRCode; | 15 | import net.glxn.qrgen.javase.QRCode; | 
| ... | @@ -19,13 +21,13 @@ import org.slf4j.Logger; | ... | @@ -19,13 +21,13 @@ import org.slf4j.Logger; | 
| 19 | import org.slf4j.LoggerFactory; | 21 | import org.slf4j.LoggerFactory; | 
| 20 | import org.springframework.beans.factory.annotation.Autowired; | 22 | import org.springframework.beans.factory.annotation.Autowired; | 
| 21 | import org.springframework.beans.factory.annotation.Value; | 23 | import org.springframework.beans.factory.annotation.Value; | 
| 24 | import org.springframework.mock.web.MockMultipartFile; | ||
| 22 | import org.springframework.stereotype.Service; | 25 | import org.springframework.stereotype.Service; | 
| 26 | import org.springframework.web.multipart.MultipartFile; | ||
| 23 | 27 | ||
| 24 | import javax.imageio.ImageIO; | 28 | import javax.imageio.ImageIO; | 
| 25 | import java.awt.image.BufferedImage; | 29 | import java.awt.image.BufferedImage; | 
| 26 | import java.io.ByteArrayOutputStream; | 30 | import java.io.*; | 
| 27 | import java.io.File; | ||
| 28 | import java.io.IOException; | ||
| 29 | import java.math.BigDecimal; | 31 | import java.math.BigDecimal; | 
| 30 | import java.net.URLEncoder; | 32 | import java.net.URLEncoder; | 
| 31 | import java.nio.file.Path; | 33 | import java.nio.file.Path; | 
| ... | @@ -58,6 +60,8 @@ public class EciServiceImpl extends ServiceImpl<ElecLicenseInfoMapper, ElecLicen | ... | @@ -58,6 +60,8 @@ public class EciServiceImpl extends ServiceImpl<ElecLicenseInfoMapper, ElecLicen | 
| 58 | private ElecLicenseInfoMapper elecLicenseInfoMapper; | 60 | private ElecLicenseInfoMapper elecLicenseInfoMapper; | 
| 59 | @Autowired | 61 | @Autowired | 
| 60 | private EciHttpUtil eciHttpUtil; | 62 | private EciHttpUtil eciHttpUtil; | 
| 63 | @Autowired | ||
| 64 | private SysFileService sysFileService; | ||
| 61 | 65 | ||
| 62 | 66 | ||
| 63 | 67 | ||
| ... | @@ -403,12 +407,17 @@ public class EciServiceImpl extends ServiceImpl<ElecLicenseInfoMapper, ElecLicen | ... | @@ -403,12 +407,17 @@ public class EciServiceImpl extends ServiceImpl<ElecLicenseInfoMapper, ElecLicen | 
| 403 | String documentId = waitForDownload.getDocumentId(); | 407 | String documentId = waitForDownload.getDocumentId(); | 
| 404 | String bh=waitForDownload.getZsbh(); | 408 | String bh=waitForDownload.getZsbh(); | 
| 405 | String htlx=waitForDownload.getHtlx(); | 409 | String htlx=waitForDownload.getHtlx(); | 
| 406 | String ofdPath = eciHttpUtil.download(documentId,bh,htlx,areacode); | 410 | String backUrl[] = eciHttpUtil.download(documentId,bh,htlx,areacode); | 
| 407 | if (StringUtils.isNotBlank(ofdPath)) { | 411 | |
| 412 | if (ArrayUtil.isNotEmpty(backUrl)) { | ||
| 408 | //入库ofd文件地址 | 413 | //入库ofd文件地址 | 
| 409 | waitForDownload.setSfxz("1"); | 414 | waitForDownload.setSfxz("1"); | 
| 410 | waitForDownload.setOfdWjdz(ofdPath); | 415 | waitForDownload.setOfdWjdz(backUrl[0]); | 
| 416 | if(backUrl.length>1){ | ||
| 417 | waitForDownload.setMinio_ofd_url(backUrl[1]); | ||
| 418 | } | ||
| 411 | waitForDownload.setErr_state("0"); | 419 | waitForDownload.setErr_state("0"); | 
| 420 | |||
| 412 | }else{ | 421 | }else{ | 
| 413 | waitForDownload.setErr_state("3"); | 422 | waitForDownload.setErr_state("3"); | 
| 414 | } | 423 | } | 
| ... | @@ -432,6 +441,14 @@ public class EciServiceImpl extends ServiceImpl<ElecLicenseInfoMapper, ElecLicen | ... | @@ -432,6 +441,14 @@ public class EciServiceImpl extends ServiceImpl<ElecLicenseInfoMapper, ElecLicen | 
| 432 | String dateDir = simpleDateFormat.format(new Date()); | 441 | String dateDir = simpleDateFormat.format(new Date()); | 
| 433 | String url=ofdToImg(ofdPath,eciPath+"ECI\\"+areacode+"\\"+ htlx+dateDir+bh+"\\",id); | 442 | String url=ofdToImg(ofdPath,eciPath+"ECI\\"+areacode+"\\"+ htlx+dateDir+bh+"\\",id); | 
| 434 | if(StringUtils.isNotBlank(url)){ | 443 | if(StringUtils.isNotBlank(url)){ | 
| 444 | InputStream imageStream=new FileInputStream(new File(url)); | ||
| 445 | MultipartFile multipartFile = new MockMultipartFile( | ||
| 446 | "File", id+ImageType.JPG, | ||
| 447 | "text/plain", | ||
| 448 | imageStream); | ||
| 449 | String miniofilePath=areacode+"/"+ htlx+dateDir+bh+"/"+id+".jpg"; | ||
| 450 | String minioPath=sysFileService.uploadFileMinio(multipartFile,miniofilePath); | ||
| 451 | waitForConvert.setMinio_jpg_url(minioPath); | ||
| 435 | waitForConvert.setSfzh("1"); | 452 | waitForConvert.setSfzh("1"); | 
| 436 | waitForConvert.setJpgWjdz(url); | 453 | waitForConvert.setJpgWjdz(url); | 
| 437 | waitForConvert.setErr_state("0"); | 454 | waitForConvert.setErr_state("0"); | ... | ... | 
| ... | @@ -60,6 +60,34 @@ public class SysFileServiceImpl implements SysFileService { | ... | @@ -60,6 +60,34 @@ public class SysFileServiceImpl implements SysFileService { | 
| 60 | } | 60 | } | 
| 61 | 61 | ||
| 62 | @Override | 62 | @Override | 
| 63 | public String uploadFileMinio(MultipartFile file, String filePath) { | ||
| 64 | Long st = System.currentTimeMillis(); | ||
| 65 | if (file.isEmpty()) { | ||
| 66 | throw new RuntimeException("文件不存在!"); | ||
| 67 | } | ||
| 68 | log.info("开始上传单个文件,文件大小:" + (file.getSize()/1024) + "KB"); | ||
| 69 | // 判断存储桶是否存在 | ||
| 70 | if (!minioUtil.bucketExists(minioConfig.getBucketName())) { | ||
| 71 | minioUtil.makeBucket(minioConfig.getBucketName()); | ||
| 72 | } | ||
| 73 | // 生成文件名 按照要求-带文件夹路径的文件的全路径 | ||
| 74 | String fineName = filePath; | ||
| 75 | try { | ||
| 76 | // 上传文件 | ||
| 77 | minioUtil.upload(file, fineName, minioConfig.getBucketName()); | ||
| 78 | } catch (Exception e) { | ||
| 79 | System.out.println("上传minio服务器期出错了 " + e.getMessage()); | ||
| 80 | e.printStackTrace(); | ||
| 81 | return null; | ||
| 82 | } | ||
| 83 | |||
| 84 | String url = minioConfig.getMinioUrl() + "/" + minioConfig.getBucketName() + "/" + fineName; | ||
| 85 | |||
| 86 | log.info("上传文件结束,总耗时:"+(System.currentTimeMillis() - st) +"ms, 文件路径:" + url ); | ||
| 87 | return url; | ||
| 88 | } | ||
| 89 | |||
| 90 | @Override | ||
| 63 | public String uploadFileMinio(MultipartFile file) { | 91 | public String uploadFileMinio(MultipartFile file) { | 
| 64 | Long st = System.currentTimeMillis(); | 92 | Long st = System.currentTimeMillis(); | 
| 65 | if (file.isEmpty()) { | 93 | if (file.isEmpty()) { | ... | ... | 
- 
Please register or sign in to post a comment