Commit f0d99869 by 翁国栋 Committed by 284718418@qq.com

禅道id--

395、在合同证照当中添加一个导出合同证照的功能
parent 87abdea7
package cn.timer.api.controller.htzz; package cn.timer.api.controller.htzz;
import java.util.ArrayList; import java.io.*;
import java.util.Date; import java.nio.charset.StandardCharsets;
import java.util.List; import java.util.*;
import cn.timer.api.utils.aliyun.OSSUtil;
import com.google.common.base.Strings;
import com.google.common.collect.Maps;
import io.swagger.models.auth.In;
import org.bouncycastle.util.encoders.UrlBase64Encoder;
import org.eclipse.jetty.util.UrlEncoded;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
...@@ -26,7 +32,6 @@ import com.google.common.collect.Lists; ...@@ -26,7 +32,6 @@ import com.google.common.collect.Lists;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.hutool.cron.CronUtil; import cn.hutool.cron.CronUtil;
import cn.hutool.cron.task.Task; import cn.hutool.cron.task.Task;
import cn.timer.api.bean.admin.AdminAssoTxjlb;
import cn.timer.api.bean.htzz.HtzzAdminZzda; import cn.timer.api.bean.htzz.HtzzAdminZzda;
import cn.timer.api.bean.htzz.HtzzAssoHtgx; import cn.timer.api.bean.htzz.HtzzAssoHtgx;
import cn.timer.api.bean.htzz.HtzzAssoZztx; import cn.timer.api.bean.htzz.HtzzAssoZztx;
...@@ -37,20 +42,28 @@ import cn.timer.api.config.annotation.UserBean; ...@@ -37,20 +42,28 @@ import cn.timer.api.config.annotation.UserBean;
import cn.timer.api.dao.htzz.HtzzAdminZzdaMapper; import cn.timer.api.dao.htzz.HtzzAdminZzdaMapper;
import cn.timer.api.dto.htzz.HtzzQueryDto; import cn.timer.api.dto.htzz.HtzzQueryDto;
import cn.timer.api.dto.htzz.NotifyPersonDto; import cn.timer.api.dto.htzz.NotifyPersonDto;
import cn.timer.api.dto.htzz.QueryNoReadingDto;
import cn.timer.api.utils.Result; import cn.timer.api.utils.Result;
import cn.timer.api.utils.ResultUtil; import cn.timer.api.utils.ResultUtil;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@Api(tags = "7.0合同证照") @Api(tags = "7.0合同证照")
@RestController @RestController
@Transactional @Transactional
@RequestMapping(value = "/htzz", produces = { "application/json" }) @RequestMapping(value = "/htzz", produces = {"application/json"})
public class HtzzController { public class HtzzController {
@Autowired @Autowired
private HtzzAdminZzdaMapper htzzAdminZzdaMapper; private HtzzAdminZzdaMapper htzzAdminZzdaMapper;
@Autowired
private OSSUtil oss;
@Value("${config-8timer.Aliyun.project_package}")
private String project_package;
@Value("${zip.path}")
private String zipPath;
/** /**
...@@ -79,7 +92,7 @@ public class HtzzController { ...@@ -79,7 +92,7 @@ public class HtzzController {
} }
if (date != null && date.getTime() <= new Date().getTime()) { if (date != null && date.getTime() <= new Date().getTime()) {
Logoutput("企业 " + orgCode + " :短信套餐已过期"); Logoutput("企业 " + orgCode + " :短信套餐已过期");
return ResultUtil.error("短信套餐已到期!"); // return ResultUtil.error("短信套餐已到期!");
} }
if (zzda.getId() == null) { if (zzda.getId() == null) {
zzda.setTxkgType(1);//默认开启提醒 zzda.setTxkgType(1);//默认开启提醒
...@@ -128,7 +141,7 @@ public class HtzzController { ...@@ -128,7 +141,7 @@ public class HtzzController {
List<NotifyPersonDto> tzids = new ArrayList<NotifyPersonDto>(); List<NotifyPersonDto> tzids = new ArrayList<NotifyPersonDto>();
List<HtzzAssoHtgx> httxs = HtzzAssoHtgx.builder().build().selectList(new QueryWrapper<HtzzAssoHtgx>().lambda().eq(HtzzAssoHtgx::getHtid, id)); List<HtzzAssoHtgx> httxs = HtzzAssoHtgx.builder().build().selectList(new QueryWrapper<HtzzAssoHtgx>().lambda().eq(HtzzAssoHtgx::getHtid, id));
for(HtzzAssoHtgx gx : httxs) { for (HtzzAssoHtgx gx : httxs) {
NotifyPersonDto predto = NotifyPersonDto.builder().build(); NotifyPersonDto predto = NotifyPersonDto.builder().build();
predto.setEmpName(gx.getName()); predto.setEmpName(gx.getName());
predto.setEmpNum(gx.getTzrid()); predto.setEmpNum(gx.getTzrid());
...@@ -273,12 +286,77 @@ public class HtzzController { ...@@ -273,12 +286,77 @@ public class HtzzController {
public void Logoutput(String science) { public void Logoutput(String science) {
if(!("pro").equals(environmental_science)) { if (!("pro").equals(environmental_science)) {
System.out.println(science); System.out.println(science);
}else { } else {
System.out.println(""); System.out.println("");
} }
}
/**
* @Author wgd
* @Description 导出勾选的合同
* @Date 2021/12/2 17:05
**/
@PostMapping(value = "/exportContract")
public Result<Object> exportContract(@CurrentUser UserBean userBean, @RequestBody List<Integer> ids, HttpServletRequest request, HttpServletResponse resp) {
if (ids.size() <= 0) {
return ResultUtil.error("操作失败");
}
Map<String, String> url = Maps.newHashMap();
ids.forEach(i -> {
HtzzAdminZzda htzzAdminZzda = HtzzAdminZzda.builder().id(i).build().selectById();
/*格式化获取文字*/
String urla =UrlEncoded.decodeString(htzzAdminZzda.getZjfj());
int index = urla.indexOf(project_package);
url.put(htzzAdminZzda.getId() +"_"+ htzzAdminZzda.getZjmc(), urla.substring(index));
});
String zipUrl = null;
try {
zipUrl = oss.createZip(url);
return ResultUtil.data(zipUrl);
} catch (Exception e) {
e.printStackTrace();
}
return ResultUtil.error("操作失败");
}
@GetMapping(value = "/exportContract")
public void exportContract(@CurrentUser UserBean userBean, @RequestParam("url") String url, HttpServletRequest request, HttpServletResponse resp) {
FileInputStream fis = null;
BufferedInputStream bis = null;
OutputStream os;
File filePath = null;
try {
resp.setContentType("application/octet-stream");
resp.setHeader("content-disposition", "attachment; filename=" + new String(url.getBytes("UTF8"), "ISO-8859-1"));
resp.setCharacterEncoding("UTF-8");
filePath = new File(zipPath + url);
byte[] buffer = new byte[1024];
fis = new FileInputStream(filePath);
bis = new BufferedInputStream(fis);
os = resp.getOutputStream();
int i = bis.read(buffer);
while (i != -1) {
os.write(buffer, 0, i);
i = bis.read(buffer);
}
os.flush();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
bis.close();
} catch (IOException e) {
e.printStackTrace();
}
try {
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
filePath.delete();
}
} }
} }
package cn.timer.api.utils.aliyun; package cn.timer.api.utils.aliyun;
import java.io.BufferedReader; import java.io.*;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.text.DateFormat;
import java.util.Date; import java.text.SimpleDateFormat;
import java.util.Iterator; import java.util.*;
import java.util.List; import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.bouncycastle.jce.exception.ExtIOException;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
...@@ -38,11 +40,12 @@ import cn.hutool.core.util.StrUtil; ...@@ -38,11 +40,12 @@ import cn.hutool.core.util.StrUtil;
import cn.timer.api.utils.Result; import cn.timer.api.utils.Result;
import cn.timer.api.utils.ResultUtil; import cn.timer.api.utils.ResultUtil;
import javax.servlet.http.HttpServletResponse;
/** /**
* OSS接口操作示例 1.创建空间 2.上传文件 3.下载文件 * OSS接口操作示例 1.创建空间 2.上传文件 3.下载文件
* *
* @author dsc * @author dsc
*
*/ */
@Component @Component
public class OSSUtil { public class OSSUtil {
...@@ -71,6 +74,9 @@ public class OSSUtil { ...@@ -71,6 +74,9 @@ public class OSSUtil {
@Value("${config-8timer.Aliyun.expirationTime_pri}") @Value("${config-8timer.Aliyun.expirationTime_pri}")
private String expirationTime_pri; private String expirationTime_pri;
@Value("${zip.path}")
private String zipPath;
/** /**
* 1.创建储存空间 sout控制台輸出 储存空间名 * 1.创建储存空间 sout控制台輸出 储存空间名
* *
...@@ -135,7 +141,7 @@ public class OSSUtil { ...@@ -135,7 +141,7 @@ public class OSSUtil {
// 关闭OSSClient。 // 关闭OSSClient。
ossClient.shutdown(); ossClient.shutdown();
// 返回上传成功的文件名 // 返回上传成功的文件名
return url.toString().substring(0,url.toString().lastIndexOf("?")); return url.toString().substring(0, url.toString().lastIndexOf("?"));
} }
/** /**
...@@ -564,12 +570,71 @@ public class OSSUtil { ...@@ -564,12 +570,71 @@ public class OSSUtil {
public void Logoutput(String science) { public void Logoutput(String science) {
if(!("pro").equals(environmental_science)) { if (!("pro").equals(environmental_science)) {
System.out.println(science); System.out.println(science);
}else { } else {
System.out.println(""); System.out.println("");
} }
} }
/**
* @Author wgd
* @Description 创建zip
* @Date 2021/12/2 18:06
**/
public String createZip(Map<String, String> urlMap) throws Exception {
DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
String fileName = dateFormat.format(new Date()) + ".zip";
FileOutputStream fos = null;
ZipOutputStream zos = null;
BufferedInputStream inputStream;
OSSObject ossObject;
String Suffix;
try {
fos = new FileOutputStream(zipPath+fileName);
zos = new ZipOutputStream(fos);
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
for (String m : urlMap.keySet()) {
Suffix = urlMap.get(m).substring(urlMap.get(m).lastIndexOf("."));
ossObject = ossClient.getObject(bucketName, urlMap.get(m));
inputStream = new BufferedInputStream(ossObject.getObjectContent());
ZipEntry entry = new ZipEntry(m + Suffix);
try {
zos.putNextEntry(entry);
int nNumber;
byte[] buffer = new byte[4096];
while ((nNumber = inputStream.read(buffer)) > 0) {
zos.write(buffer, 0, nNumber);
}
} catch (IOException e) {
throw new Exception("写入失败");//TODO 应作为自定义异常
} finally {
try {
inputStream.close();
} catch (IOException e) {
throw new Exception("关闭失败");//TODO 应作为自定义异常
}
}
}
ossClient.shutdown();
} catch (FileNotFoundException e) {
e.printStackTrace();
} finally {
// 关闭创建的流对象
try {
if (zos != null) {
zos.closeEntry();
zos.close();
}
if (fos != null) {
fos.close();
}
} catch (IOException e) {
throw new Exception("关闭失败");//TODO 应作为自定义异常
}
}
return fileName;
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment