|
@@ -5,6 +5,7 @@ import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
|
import java.io.OutputStream;
|
|
|
import java.net.URLEncoder;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
import java.util.List;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
@@ -13,6 +14,7 @@ import com.ruoyi.common.utils.uuid.UUID;
|
|
|
import com.ruoyi.powerdistribution.util.ImportExcelHelper;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
+import org.springframework.core.io.ClassPathResource;
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
@@ -26,6 +28,8 @@ import com.ruoyi.common.utils.poi.ExcelUtil;
|
|
|
import com.ruoyi.common.core.page.TableDataInfo;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import static javax.swing.text.DefaultStyledDocument.ElementSpec.ContentType;
|
|
|
+
|
|
|
/**
|
|
|
* 停电预算Controller
|
|
|
*
|
|
@@ -113,26 +117,27 @@ public class PdmStopTargeController extends BaseController
|
|
|
@ApiOperation(value = "停电预算下载模板")
|
|
|
public void downloadTemplate(HttpServletResponse response) {
|
|
|
String filePath = "excelTemplate/stopTarget.xlsx";//未完成
|
|
|
- byte[] buffer = new byte[1024];
|
|
|
InputStream fis = Thread.currentThread().getContextClassLoader().getResourceAsStream(filePath);
|
|
|
BufferedInputStream bis = null;
|
|
|
try {
|
|
|
response.setHeader("Content-Disposition", "attachment;filename*=UTF-8''" + URLEncoder.encode(UUID.fastUUID().toString(), "UTF-8"));
|
|
|
- response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
|
|
|
- response.setCharacterEncoding("UTF-8");
|
|
|
+ response.setCharacterEncoding(StandardCharsets.UTF_8.name()); // 字符集编码
|
|
|
+ response.setContentType("application/octet-stream");
|
|
|
+ response.reset();
|
|
|
bis = new BufferedInputStream(fis);
|
|
|
+ byte[] buffer = new byte[bis.available()];
|
|
|
OutputStream os = response.getOutputStream();
|
|
|
- int i = bis.read(buffer);
|
|
|
- while (i != -1) {
|
|
|
- os.write(buffer, 0, i);
|
|
|
- i = bis.read(buffer);
|
|
|
- }
|
|
|
+ bis.read(buffer);
|
|
|
+ os.write(buffer);
|
|
|
+ os.flush();
|
|
|
+ os.close();
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
} finally {
|
|
|
- try {
|
|
|
- bis.close();
|
|
|
- fis.close();
|
|
|
+ try {
|
|
|
+ if(fis!=null){
|
|
|
+ fis.close();
|
|
|
+ }
|
|
|
} catch (Exception e1) {
|
|
|
e1.printStackTrace();
|
|
|
}
|