|
@@ -40,17 +40,13 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.jms.core.JmsMessagingTemplate;
|
|
import org.springframework.jms.core.JmsMessagingTemplate;
|
|
-import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
-import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
+import javax.servlet.ServletOutputStream;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.validation.Valid;
|
|
import javax.validation.Valid;
|
|
-import java.io.BufferedInputStream;
|
|
|
|
import java.io.File;
|
|
import java.io.File;
|
|
import java.io.FileInputStream;
|
|
import java.io.FileInputStream;
|
|
-import java.io.OutputStream;
|
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
@@ -69,6 +65,7 @@ import java.util.stream.Collectors;
|
|
@RestController
|
|
@RestController
|
|
@AllArgsConstructor
|
|
@AllArgsConstructor
|
|
@RequestMapping("/emergency/emergency-repair")
|
|
@RequestMapping("/emergency/emergency-repair")
|
|
|
|
+@SuppressWarnings("all")
|
|
public class EmergencyRepairController {
|
|
public class EmergencyRepairController {
|
|
|
|
|
|
private EmergencyRepairService emergencyRepairService;
|
|
private EmergencyRepairService emergencyRepairService;
|
|
@@ -888,8 +885,13 @@ public class EmergencyRepairController {
|
|
|
|
|
|
@PostMapping("export")
|
|
@PostMapping("export")
|
|
@Validation(fields = {"ids"})
|
|
@Validation(fields = {"ids"})
|
|
- public void export(@Val @RequestBody RepairRequest request, HttpServletResponse response) {
|
|
|
|
- log.info("headerAlias: {}", headerAlias);
|
|
|
|
|
|
+ public void export(
|
|
|
|
+ @Val @RequestBody RepairRequest request,
|
|
|
|
+ HttpServletResponse response) {
|
|
|
|
+
|
|
|
|
+ if (request.getIds().size() > 10) {
|
|
|
|
+ throw Validate.validateException("批量导出急修单最大个数为10!");
|
|
|
|
+ }
|
|
List<RepairResponse> repairs = emergencyRepairService.listByIdList(request);
|
|
List<RepairResponse> repairs = emergencyRepairService.listByIdList(request);
|
|
Validate.notNull(repairs, ValuePool.EMERGENCY_NOT_EXIST);
|
|
Validate.notNull(repairs, ValuePool.EMERGENCY_NOT_EXIST);
|
|
|
|
|
|
@@ -986,34 +988,24 @@ public class EmergencyRepairController {
|
|
//压缩文件夹
|
|
//压缩文件夹
|
|
log.info("生成zipfile: {}", zip);
|
|
log.info("生成zipfile: {}", zip);
|
|
ZipUtil.zip(dir, zip);
|
|
ZipUtil.zip(dir, zip);
|
|
|
|
+
|
|
|
|
+ response.setContentType("application/zip");
|
|
|
|
+ ServletOutputStream out = response.getOutputStream();
|
|
|
|
+ FileInputStream in = new FileInputStream(new File(zip));
|
|
|
|
+ byte[] buffer = new byte[1024];
|
|
|
|
+ int len;
|
|
|
|
+ while ((len = in.read(buffer)) != -1) {
|
|
|
|
+ out.write(buffer, 0, len);
|
|
|
|
+ }
|
|
|
|
+ out.flush();
|
|
|
|
+ in.close();
|
|
|
|
+ out.close();
|
|
|
|
+
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
FileUtil.del(zipFile);
|
|
FileUtil.del(zipFile);
|
|
FileUtil.del(baseDir);
|
|
FileUtil.del(baseDir);
|
|
log.error("生成急修文件失败", e);
|
|
log.error("生成急修文件失败", e);
|
|
throw Validate.validateException("生成急修文件失败");
|
|
throw Validate.validateException("生成急修文件失败");
|
|
}
|
|
}
|
|
- //下载压缩文件
|
|
|
|
- if (FileUtil.exist(zipFile)) {
|
|
|
|
- // 设置强制下载不打开, ZIP的application/x-zip-compressed
|
|
|
|
- response.setContentType("application/force-download");
|
|
|
|
- // 设置文件名
|
|
|
|
- response.addHeader("Content-Disposition", "attachment;fileName=" + zipFile.getName());
|
|
|
|
- byte[] buffer = new byte[1024];
|
|
|
|
- try (FileInputStream fis = new FileInputStream(zipFile);
|
|
|
|
- BufferedInputStream bis = new BufferedInputStream(fis)) {
|
|
|
|
- OutputStream os = response.getOutputStream();
|
|
|
|
- int i;
|
|
|
|
- while ((i = bis.read(buffer)) != -1) {
|
|
|
|
- os.write(buffer, 0, i);
|
|
|
|
- }
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- log.error("下载急修文件失败", e);
|
|
|
|
- throw Validate.validateException("下载急修文件失败");
|
|
|
|
- } finally {
|
|
|
|
- //删除临时根目录和zip文件
|
|
|
|
- FileUtil.del(zipFile);
|
|
|
|
- FileUtil.del(baseDir);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|