|
@@ -1,9 +1,13 @@
|
|
|
package com.rongwei.bscommon.sys.service.impl;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.io.FileUtil;
|
|
|
+import cn.hutool.core.util.IdUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
+import cn.hutool.core.util.ZipUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.rongwei.bscommon.sys.feign.SysNotifyFeginService;
|
|
|
import com.rongwei.bscommon.sys.service.*;
|
|
@@ -24,13 +28,21 @@ import com.rongwei.rwcommon.utils.SecurityUtil;
|
|
|
import com.rongwei.rwcommon.utils.StringUtils;
|
|
|
import com.rongwei.rwcommon.vo.MailDo;
|
|
|
import com.rongwei.rwcommon.vo.generalsql.MasterSlaveUpdateVo;
|
|
|
+import com.rongwei.rwcommonentity.commonservers.domain.SysFileItemDo;
|
|
|
import com.rongwei.rwcommonentity.commonservers.vo.SysSerialVo;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Isolation;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
-
|
|
|
+import org.springframework.util.ResourceUtils;
|
|
|
+
|
|
|
+import javax.servlet.ServletOutputStream;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.*;
|
|
|
+import java.net.URL;
|
|
|
+import java.net.URLEncoder;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
@@ -66,6 +78,9 @@ public class ZhcxOutsideInspectionItpServiceImpl extends ServiceImpl<ZhcxOutside
|
|
|
@Autowired
|
|
|
private SysGeneralCRUDService sysGeneralCRUDService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private SysFileItemService sysFileItemService;
|
|
|
+
|
|
|
@Autowired
|
|
|
private SysNotifyFeginService notifyFeginService;
|
|
|
|
|
@@ -479,6 +494,125 @@ public class ZhcxOutsideInspectionItpServiceImpl extends ServiceImpl<ZhcxOutside
|
|
|
return notifyDto;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public int downloadFile(Map<String, Object> map, HttpServletResponse response) throws FileNotFoundException {
|
|
|
+ Object itpid = map.get("itpid");
|
|
|
+ if(ObjectUtil.isEmpty(itpid)){
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ String itpId = (String) itpid;
|
|
|
+ ZhcxOutsideInspectionItpDo inspectionItpDo = getById(itpId);
|
|
|
+ LambdaQueryWrapper<ZhcxOutsideInspectionItpSupervisionDispatchDo> wrapper = Wrappers.lambdaQuery();
|
|
|
+ wrapper.eq(ZhcxOutsideInspectionItpSupervisionDispatchDo::getItpid,itpId);
|
|
|
+ ZhcxOutsideInspectionItpSupervisionDispatchDo dispatchDo = dispatchService.getOne(wrapper);
|
|
|
+ List<String> fileIds = new ArrayList<>();
|
|
|
+ if(dispatchDo != null){
|
|
|
+ String sfiles = dispatchDo.getSfiles();
|
|
|
+ String signature = dispatchDo.getSignature();
|
|
|
+ if(StringUtils.isNotBlank(signature)){
|
|
|
+ getIds(signature, fileIds);
|
|
|
+ }
|
|
|
+ if(StringUtils.isNotBlank(sfiles)){
|
|
|
+ getIds(sfiles, fileIds);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String files = inspectionItpDo.getFiles();
|
|
|
+ if(StringUtils.isNotBlank(files)){
|
|
|
+ getIds(files, fileIds);
|
|
|
+ }
|
|
|
+ if(fileIds.size() > 0){
|
|
|
+ QueryWrapper<SysFileItemDo> qw = new QueryWrapper();
|
|
|
+ qw.in("ID", fileIds);
|
|
|
+ List<SysFileItemDo> list = sysFileItemService.list(qw);
|
|
|
+ if(list.size() > 0){
|
|
|
+ // 获取类路径
|
|
|
+ String classPath = ResourceUtils.getURL("classpath:").getPath();
|
|
|
+ // 临时目录 以uuid+时间戳 为目录名称
|
|
|
+ String temp = classPath + IdUtil.simpleUUID() + System.currentTimeMillis();
|
|
|
+ // 临时目录如果存在则删除
|
|
|
+ File tempDir = new File(temp);
|
|
|
+ File zipFile = null;
|
|
|
+ try {
|
|
|
+
|
|
|
+ if (tempDir.exists()) {
|
|
|
+ FileUtil.del(tempDir);
|
|
|
+ }
|
|
|
+ // 创建临时目录
|
|
|
+ boolean mkdir = tempDir.mkdir();
|
|
|
+ if (mkdir) {
|
|
|
+
|
|
|
+ list.forEach(item->
|
|
|
+ FileUtil.copyFile(new File(item.getFullpath()),
|
|
|
+ new File(temp+File.separator+item.getFilename()))
|
|
|
+ );
|
|
|
+ // 设置响应的一些格式
|
|
|
+ String encodedFileName = URLEncoder.encode(inspectionItpDo.getInspectioncode()+".zip", "UTF-8").replaceAll("\\+", "%20");
|
|
|
+ response.setContentType("application/octet-stream");
|
|
|
+ response.setHeader("content-type", "application/octet-stream");
|
|
|
+ //response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
|
|
|
+ response.setHeader("Content-Disposition", String.format("attachment; filename=\"%s\"", encodedFileName));
|
|
|
+ //response.setHeader("Pragma", "no-cache");
|
|
|
+ //response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
|
|
|
+ //response.setHeader("Expires", "0");
|
|
|
+ // 将临时目录压缩成zip
|
|
|
+ zipFile = ZipUtil.zip(temp);
|
|
|
+ byte[] buffer = new byte[1024];
|
|
|
+ FileInputStream fis = null;
|
|
|
+ BufferedInputStream bis = null;
|
|
|
+ try{
|
|
|
+ fis = new FileInputStream(zipFile);
|
|
|
+ bis = new BufferedInputStream(fis);
|
|
|
+ OutputStream os = response.getOutputStream();
|
|
|
+ int i = bis.read(buffer);
|
|
|
+ while (i != -1) {
|
|
|
+ os.write(buffer, 0, i);
|
|
|
+ i = bis.read(buffer);
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }finally {
|
|
|
+ if (bis != null) {
|
|
|
+ try {
|
|
|
+ bis.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (fis != null) {
|
|
|
+ try {
|
|
|
+ fis.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ //throw new CustomException("下载附件失败");
|
|
|
+ return 1;
|
|
|
+ }finally {
|
|
|
+ // 删除临时目录和压缩后的文件
|
|
|
+ FileUtil.del(tempDir);
|
|
|
+ FileUtil.del(zipFile);
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ return 2;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void getIds(String files, List<String> fileIds) {
|
|
|
+ String[] split = files.split("\\^_\\^");
|
|
|
+ for(String fileItem : split){
|
|
|
+ String id = fileItem.split("-;-")[1];
|
|
|
+ fileIds.add(id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 保存
|
|
|
*
|