Search in sources :

Example 1 with PostExcelDTO

use of com.hb0730.boot.admin.project.system.post.model.dto.PostExcelDTO in project boot-admin by hb0730.

the class PostController method export.

/**
 * 导出
 *
 * @param response 响应
 * @param params   请求参数,用于导出过滤
 * @throws ExportExceptions 导出异常
 */
@Override
@PostMapping("/export")
@Log(value = "导出", paramsName = { "params" }, businessType = BusinessTypeEnum.EXPORT)
@PreAuthorize("hasAnyAuthority('ROLE_ADMINISTRATOR','post:export')")
public void export(HttpServletResponse response, @RequestBody PostParams params) throws ExportExceptions {
    List<PostExcelDTO> export = service.export(params);
    HashMap<String, Object> map = Maps.newHashMap();
    try {
        map.put(ExcelConstant.FILE_NAME, "post_excel");
        map.put(ExcelConstant.DATA_LIST, export);
        ExcelUtils.writeWeb(response, map, ExcelTypeEnum.XLS, PostExcelDTO.class);
    } catch (Exception e) {
        e.printStackTrace();
        throw new ExportExceptions("岗位导出失败", e);
    }
}
Also used : PostExcelDTO(com.hb0730.boot.admin.project.system.post.model.dto.PostExcelDTO) ExportExceptions(com.hb0730.boot.admin.exceptions.ExportExceptions) IOException(java.io.IOException) PostMapping(org.springframework.web.bind.annotation.PostMapping) Log(com.hb0730.boot.admin.annotation.Log) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 2 with PostExcelDTO

use of com.hb0730.boot.admin.project.system.post.model.dto.PostExcelDTO in project boot-admin by hb0730.

the class ExcelUtilsTest method writeTest.

@Test
public void writeTest() throws IOException {
    ExcelProperties properties = new ExcelProperties("C:\\Users\\12780\\Downloads", "test", ExcelTypeEnum.XLS, PostExcelDTO.class);
    OutputStream outputStream = ExcelUtils.getOutputStream(properties);
    List<PostExcelDTO> data = Lists.newArrayList();
    data.add(new PostExcelDTO("S001", "全栈开发", 1, new Date()));
    data.add(new PostExcelDTO("S002", "全栈开发", 1, new Date()));
    data.add(new PostExcelDTO("S003", "全栈开发", 1, new Date()));
    data.add(new PostExcelDTO("S004", "全栈开发", 1, new Date()));
    ExcelUtils.write(outputStream, data, ExcelTypeEnum.XLS, PostExcelDTO.class);
}
Also used : PostExcelDTO(com.hb0730.boot.admin.project.system.post.model.dto.PostExcelDTO) OutputStream(java.io.OutputStream) Date(java.util.Date) Test(org.junit.Test)

Aggregations

PostExcelDTO (com.hb0730.boot.admin.project.system.post.model.dto.PostExcelDTO)2 Log (com.hb0730.boot.admin.annotation.Log)1 ExportExceptions (com.hb0730.boot.admin.exceptions.ExportExceptions)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 Date (java.util.Date)1 Test (org.junit.Test)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1