This commit is contained in:
parent
479e08dda0
commit
3d1bc1194a
|
|
@ -10,7 +10,12 @@ import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.web.context.request.RequestContextHolder;
|
||||||
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
@Api(tags = "代办事项")
|
@Api(tags = "代办事项")
|
||||||
@RestController
|
@RestController
|
||||||
|
|
@ -38,4 +43,15 @@ public class ToDoController extends BaseController {
|
||||||
return toDoService.getTaskType(bean);
|
return toDoService.getTaskType(bean);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户手册下载
|
||||||
|
*/
|
||||||
|
@ApiOperation(value = "用户手册下载")
|
||||||
|
@PostMapping("/downLoadUserManual")
|
||||||
|
public void downLoadUserManual(){
|
||||||
|
HttpServletResponse resp = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getResponse();
|
||||||
|
toDoService.downLoadTemplate(resp);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@ package com.bonus.material.basic.service;
|
||||||
|
|
||||||
import com.bonus.common.core.web.domain.AjaxResult;
|
import com.bonus.common.core.web.domain.AjaxResult;
|
||||||
import com.bonus.material.basic.domain.ToDoBean;
|
import com.bonus.material.basic.domain.ToDoBean;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -20,4 +22,8 @@ public interface ToDoService {
|
||||||
*/
|
*/
|
||||||
AjaxResult getTaskType(ToDoBean bean);
|
AjaxResult getTaskType(ToDoBean bean);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户手册下载
|
||||||
|
*/
|
||||||
|
void downLoadTemplate(HttpServletResponse resp);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,11 @@ import com.bonus.system.api.RemoteUserService;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
@ -41,4 +46,35 @@ public class ToDoServiceImpl implements ToDoService {
|
||||||
return AjaxResult.success(list);
|
return AjaxResult.success(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void downLoadTemplate(HttpServletResponse response) {
|
||||||
|
// 模板名称
|
||||||
|
String templateName = "机械化施工装备管理(共享)平台操作手册V1.0.pdf";
|
||||||
|
try (
|
||||||
|
InputStream input = this.getClass().getClassLoader().getResourceAsStream("template/机械化施工装备管理(共享)平台操作手册V1.0.pdf");
|
||||||
|
OutputStream out = response.getOutputStream()
|
||||||
|
) {
|
||||||
|
if (input == null) {
|
||||||
|
throw new FileNotFoundException("文件不存在: " + templateName);
|
||||||
|
}
|
||||||
|
// 设置响应头
|
||||||
|
response.setCharacterEncoding("UTF-8");
|
||||||
|
response.setContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
|
||||||
|
response.setHeader(
|
||||||
|
"Content-Disposition",
|
||||||
|
"attachment;filename=" + new String(templateName.getBytes("UTF-8"), "ISO-8859-1")
|
||||||
|
);
|
||||||
|
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
|
||||||
|
// 缓冲区传输
|
||||||
|
byte[] buffer = new byte[1024];
|
||||||
|
int bytesToRead;
|
||||||
|
while ((bytesToRead = input.read(buffer)) != -1) {
|
||||||
|
out.write(buffer, 0, bytesToRead);
|
||||||
|
}
|
||||||
|
out.flush();
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error("下载失败: {}", e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Binary file not shown.
Loading…
Reference in New Issue