parent
cdd4d074ec
commit
5e6d163357
|
|
@ -4,19 +4,14 @@ import com.bonus.canteen.core.common.export.dto.ExportRecordQueryDTO;
|
|||
import com.bonus.canteen.core.common.export.service.ExportRecordService;
|
||||
import com.bonus.common.core.web.domain.AjaxResult;
|
||||
import com.bonus.common.houqin.encrypt.RequiresGuest;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
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.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
@RestController
|
||||
@RequestMapping({"/api/v4/export"})
|
||||
|
|
@ -37,11 +32,4 @@ public class ExportRecordController {
|
|||
this.exportRecordService.stopAndDelete(dto);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "模版下载")
|
||||
@PostMapping("/downLoad")
|
||||
public void downLoadExcelFile(@RequestBody ExportRecordQueryDTO dto) {
|
||||
HttpServletResponse resp = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse();
|
||||
exportRecordService.downLoadTemplate(resp, dto.getFileName());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ import com.bonus.common.houqin.i18n.I18n;
|
|||
import com.bonus.common.houqin.utils.id.Id;
|
||||
import com.bonus.common.security.utils.SecurityUtils;
|
||||
import com.github.pagehelper.page.PageMethod;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.redisson.api.RLock;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
|
@ -26,10 +25,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
|
@ -191,29 +186,4 @@ public class ExportRecordService {
|
|||
.set(ExportRecord::getExportFileState, state)
|
||||
.eq(ExportRecord::getExportId, exportId));
|
||||
}
|
||||
|
||||
public void downLoadTemplate(HttpServletResponse response, String fileName) {
|
||||
OutputStream out = null;
|
||||
InputStream input = null;
|
||||
try {
|
||||
input = this.getClass().getClassLoader().getResourceAsStream("template/" + fileName);
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.setHeader("content-Type", "application/vnd.ms-excel");
|
||||
response.setHeader("Content-Disposition",
|
||||
"attachment;filename=" + new String((fileName).getBytes(), "iso-8859-1"));
|
||||
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
|
||||
out = response.getOutputStream();
|
||||
byte[] buffer = new byte[1024]; // 缓冲区
|
||||
int bytesToRead = -1;
|
||||
// 通过循环将读入内容输出到浏览器中
|
||||
while ((bytesToRead = input.read(buffer)) != -1) {
|
||||
out.write(buffer, 0, bytesToRead);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.error(e.getMessage());
|
||||
} finally {
|
||||
IOUtils.closeQuietly(input);
|
||||
IOUtils.closeQuietly(out);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Binary file not shown.
Loading…
Reference in New Issue