思路:先逐个导出Word文件到服务器,再压缩,再返回给用户下载。
(导出Word用的是freemarker模板导出形式,这里不再赘述)
直接贴代码:
Controller文件:
@ApiOperation("同时导出多个Word文件")
@GetMapping("/exportZip")
public void exportZip(String instrumentIds, HttpServletRequest request, HttpServletResponse response) throws Exception {
Map<String, Object> replaceMap = new HashMap<String, Object>();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
if (!StringUtils.isEmpty(instrumentIds)) {
String[] split = instrumentIds.split(",");
List<String> files = new ArrayList<>();
for (int i = 0; i < split.length; i++) {
Instrument instrument = instrumentService.getById(split[i]);
if (instrument != null) {
replaceMap.put("instrument_name", instrument.getName());
DevicePlace devicePlace = devicePlaceService.getById(instrument.getPlaceId());
if (devicePlace != null) {
replaceMap.put("place_name", devicePlace.getName());
}
replaceMap.put("new_sn", instrument.getNewSn());
SysDepart sysDepart = sysDepartService.getById(instrument.getDeptId());
if (sysDepart != null) {
replaceMap.put("depart_name", sysDepart.getDepartName());
}
QueryWrapper<InstrumentUseRecord> instrumentUseRecordQueryWrapper = new QueryWrapper<>();
instrumentUseRecordQueryWrapper.eq("instrument_id", split[i]);
List<InstrumentUseRecor