|
|
@ -1,18 +1,20 @@ |
|
|
|
package org.dromara.platform.controller; |
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
import java.io.*; |
|
|
|
import java.net.URLEncoder; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import com.alibaba.excel.EasyExcel; |
|
|
|
import jakarta.mail.internet.MimeUtility; |
|
|
|
import jakarta.servlet.ServletOutputStream; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import jakarta.servlet.http.HttpServletResponse; |
|
|
|
import jakarta.validation.constraints.*; |
|
|
|
import cn.dev33.satoken.annotation.SaCheckPermission; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.dromara.platform.domain.AgreementInfo; |
|
|
|
import org.dromara.platform.domain.ProjectManager; |
|
|
|
import org.dromara.platform.listener.AgreementInfoListener; |
|
|
|
import org.dromara.platform.listener.ProjectManagerListener; |
|
|
|
import org.springframework.core.io.ClassPathResource; |
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
import org.springframework.validation.annotation.Validated; |
|
|
|
import org.dromara.common.idempotent.annotation.RepeatSubmit; |
|
|
@ -125,4 +127,49 @@ public class AgreementInfoController extends BaseController { |
|
|
|
log.info("导入协议信息表数据成功! 共用时:{}ms",(t2-t1)); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@GetMapping("downLoadTemplate") |
|
|
|
public void downLoadTemplate(HttpServletResponse httpServletResponse) { |
|
|
|
InputStream inputStream = null; |
|
|
|
try (ServletOutputStream outputStream = httpServletResponse.getOutputStream()) { |
|
|
|
//设置响应头信息,包括下载后的文件名和编码等
|
|
|
|
String fileName = "服务内容导入模版.xlsx"; |
|
|
|
String encodedFileName = MimeUtility.encodeText(fileName, "UTF-8", "B"); // 使用 MIME 编码
|
|
|
|
httpServletResponse.addHeader("Content-Disposition", "attachment; filename=\"" + encodedFileName + "\"; filename*=utf-8''" + URLEncoder.encode(fileName, "UTF-8")); |
|
|
|
httpServletResponse.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); |
|
|
|
httpServletResponse.setCharacterEncoding("UTF-8"); |
|
|
|
//在文件夹里获取到文件并转为流
|
|
|
|
inputStream = new ClassPathResource("/服务内容导入模版.xlsx").getInputStream(); |
|
|
|
byte[] b = streamToByteArray(inputStream); |
|
|
|
httpServletResponse.getOutputStream().write(b); |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} finally { |
|
|
|
if (inputStream != null) { |
|
|
|
try { |
|
|
|
inputStream.close(); |
|
|
|
} catch (IOException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//文件流转字节方法
|
|
|
|
public static byte[] streamToByteArray(InputStream in) throws Exception { |
|
|
|
ByteArrayOutputStream output = new ByteArrayOutputStream(); |
|
|
|
byte[] buffer = new byte[4096]; |
|
|
|
int n; |
|
|
|
while (-1 != (n = in.read(buffer))) { |
|
|
|
output.write(buffer, 0, n); |
|
|
|
} |
|
|
|
return output.toByteArray(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|