Search in sources :

Example 16 with JeecgEntityExcelView

use of org.jeecgframework.poi.excel.view.JeecgEntityExcelView in project kykms by mahonelau.

the class SysUserAgentController method exportXls.

/**
 * 导出excel
 *
 * @param sysUserAgent
 * @param request
 */
@RequestMapping(value = "/exportXls")
public ModelAndView exportXls(SysUserAgent sysUserAgent, HttpServletRequest request) {
    // Step.1 组装查询条件
    QueryWrapper<SysUserAgent> queryWrapper = QueryGenerator.initQueryWrapper(sysUserAgent, request.getParameterMap());
    // Step.2 AutoPoi 导出Excel
    ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
    List<SysUserAgent> pageList = sysUserAgentService.list(queryWrapper);
    // 导出文件名称
    mv.addObject(NormalExcelConstants.FILE_NAME, "用户代理人设置列表");
    mv.addObject(NormalExcelConstants.CLASS, SysUserAgent.class);
    LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
    ExportParams exportParams = new ExportParams("用户代理人设置列表数据", "导出人:" + user.getRealname(), "导出信息");
    exportParams.setImageBasePath(upLoadPath);
    mv.addObject(NormalExcelConstants.PARAMS, exportParams);
    mv.addObject(NormalExcelConstants.DATA_LIST, pageList);
    return mv;
}
Also used : ExportParams(org.jeecgframework.poi.excel.entity.ExportParams) JeecgEntityExcelView(org.jeecgframework.poi.excel.view.JeecgEntityExcelView) ModelAndView(org.springframework.web.servlet.ModelAndView) SysUserAgent(org.jeecg.modules.system.entity.SysUserAgent) LoginUser(org.jeecg.common.system.vo.LoginUser) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 17 with JeecgEntityExcelView

use of org.jeecgframework.poi.excel.view.JeecgEntityExcelView in project kykms by mahonelau.

the class SysCategoryController method exportXls.

/**
 * 导出excel
 *
 * @param request
 */
@RequestMapping(value = "/exportXls")
public ModelAndView exportXls(HttpServletRequest request, SysCategory sysCategory) {
    // Step.1 组装查询条件查询数据
    QueryWrapper<SysCategory> queryWrapper = QueryGenerator.initQueryWrapper(sysCategory, request.getParameterMap());
    List<SysCategory> pageList = sysCategoryService.list(queryWrapper);
    // Step.2 AutoPoi 导出Excel
    ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
    // 过滤选中数据
    String selections = request.getParameter("selections");
    if (oConvertUtils.isEmpty(selections)) {
        mv.addObject(NormalExcelConstants.DATA_LIST, pageList);
    } else {
        List<String> selectionList = Arrays.asList(selections.split(","));
        List<SysCategory> exportList = pageList.stream().filter(item -> selectionList.contains(item.getId())).collect(Collectors.toList());
        mv.addObject(NormalExcelConstants.DATA_LIST, exportList);
    }
    // 导出文件名称
    mv.addObject(NormalExcelConstants.FILE_NAME, "分类字典列表");
    mv.addObject(NormalExcelConstants.CLASS, SysCategory.class);
    LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
    mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("分类字典列表数据", "导出人:" + user.getRealname(), "导出信息"));
    return mv;
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) java.util(java.util) ImportParams(org.jeecgframework.poi.excel.entity.ImportParams) ExportParams(org.jeecgframework.poi.excel.entity.ExportParams) MultipartHttpServletRequest(org.springframework.web.multipart.MultipartHttpServletRequest) DictModel(org.jeecg.common.system.vo.DictModel) Autowired(org.springframework.beans.factory.annotation.Autowired) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) HttpServletRequest(javax.servlet.http.HttpServletRequest) LoginUser(org.jeecg.common.system.vo.LoginUser) org.jeecg.common.util.oConvertUtils(org.jeecg.common.util.oConvertUtils) SysCategory(org.jeecg.modules.system.entity.SysCategory) ISysCategoryService(org.jeecg.modules.system.service.ISysCategoryService) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) QueryGenerator(org.jeecg.common.system.query.QueryGenerator) Result(org.jeecg.common.api.vo.Result) JeecgEntityExcelView(org.jeecgframework.poi.excel.view.JeecgEntityExcelView) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) TreeSelectModel(org.jeecg.modules.system.model.TreeSelectModel) NormalExcelConstants(org.jeecgframework.poi.excel.def.NormalExcelConstants) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) ModelAndView(org.springframework.web.servlet.ModelAndView) Slf4j(lombok.extern.slf4j.Slf4j) JSON(com.alibaba.fastjson.JSON) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) MultipartFile(org.springframework.web.multipart.MultipartFile) ExcelImportUtil(org.jeecgframework.poi.excel.ExcelImportUtil) IPage(com.baomidou.mybatisplus.core.metadata.IPage) SecurityUtils(org.apache.shiro.SecurityUtils) ExportParams(org.jeecgframework.poi.excel.entity.ExportParams) JeecgEntityExcelView(org.jeecgframework.poi.excel.view.JeecgEntityExcelView) ModelAndView(org.springframework.web.servlet.ModelAndView) SysCategory(org.jeecg.modules.system.entity.SysCategory) LoginUser(org.jeecg.common.system.vo.LoginUser)

Example 18 with JeecgEntityExcelView

use of org.jeecgframework.poi.excel.view.JeecgEntityExcelView in project kykms by mahonelau.

the class QuartzJobController method exportXls.

/**
 * 导出excel
 *
 * @param request
 * @param quartzJob
 */
@RequestMapping(value = "/exportXls")
public ModelAndView exportXls(HttpServletRequest request, QuartzJob quartzJob) {
    // Step.1 组装查询条件
    QueryWrapper<QuartzJob> queryWrapper = QueryGenerator.initQueryWrapper(quartzJob, request.getParameterMap());
    // Step.2 AutoPoi 导出Excel
    ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
    List<QuartzJob> pageList = quartzJobService.list(queryWrapper);
    // 导出文件名称
    mv.addObject(NormalExcelConstants.FILE_NAME, "定时任务列表");
    mv.addObject(NormalExcelConstants.CLASS, QuartzJob.class);
    mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("定时任务列表数据", "导出人:Jeecg", "导出信息"));
    mv.addObject(NormalExcelConstants.DATA_LIST, pageList);
    return mv;
}
Also used : ExportParams(org.jeecgframework.poi.excel.entity.ExportParams) QuartzJob(org.jeecg.modules.quartz.entity.QuartzJob) JeecgEntityExcelView(org.jeecgframework.poi.excel.view.JeecgEntityExcelView) ModelAndView(org.springframework.web.servlet.ModelAndView)

Example 19 with JeecgEntityExcelView

use of org.jeecgframework.poi.excel.view.JeecgEntityExcelView in project kykms by mahonelau.

the class JeecgController method exportXlsSheet.

/**
 * 根据每页sheet数量导出多sheet
 *
 * @param request
 * @param object 实体类
 * @param clazz 实体类class
 * @param title 标题
 * @param exportFields 导出字段自定义
 * @param pageNum 每个sheet的数据条数
 * @param request
 */
protected ModelAndView exportXlsSheet(HttpServletRequest request, T object, Class<T> clazz, String title, String exportFields, Integer pageNum) {
    // Step.1 组装查询条件
    QueryWrapper<T> queryWrapper = QueryGenerator.initQueryWrapper(object, request.getParameterMap());
    LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
    // Step.2 计算分页sheet数据
    double total = service.count();
    int count = (int) Math.ceil(total / pageNum);
    // Step.3 多sheet处理
    List<Map<String, Object>> listMap = new ArrayList<Map<String, Object>>();
    for (int i = 1; i <= count; i++) {
        Page<T> page = new Page<T>(i, pageNum);
        IPage<T> pageList = service.page(page, queryWrapper);
        List<T> records = pageList.getRecords();
        List<T> exportList = null;
        // 过滤选中数据
        String selections = request.getParameter("selections");
        if (oConvertUtils.isNotEmpty(selections)) {
            List<String> selectionList = Arrays.asList(selections.split(","));
            exportList = records.stream().filter(item -> selectionList.contains(getId(item))).collect(Collectors.toList());
        } else {
            exportList = records;
        }
        Map<String, Object> map = new HashMap<String, Object>();
        ExportParams exportParams = new ExportParams(title + "报表", "导出人:" + sysUser.getRealname(), title + i, upLoadPath);
        exportParams.setType(ExcelType.XSSF);
        // map.put("title",exportParams);//表格Title
        // 表格Title
        map.put(NormalExcelConstants.PARAMS, exportParams);
        // 表格对应实体
        map.put(NormalExcelConstants.CLASS, clazz);
        // 数据集合
        map.put(NormalExcelConstants.DATA_LIST, exportList);
        listMap.add(map);
    }
    // Step.4 AutoPoi 导出Excel
    ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
    // 此处设置的filename无效 ,前端会重更新设置一下
    mv.addObject(NormalExcelConstants.FILE_NAME, title);
    mv.addObject(NormalExcelConstants.MAP_LIST, listMap);
    return mv;
}
Also used : JeecgEntityExcelView(org.jeecgframework.poi.excel.view.JeecgEntityExcelView) ModelAndView(org.springframework.web.servlet.ModelAndView) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) IPage(com.baomidou.mybatisplus.core.metadata.IPage) LoginUser(org.jeecg.common.system.vo.LoginUser) ExportParams(org.jeecgframework.poi.excel.entity.ExportParams)

Example 20 with JeecgEntityExcelView

use of org.jeecgframework.poi.excel.view.JeecgEntityExcelView in project kms by mahonelau.

the class JeecgController method exportXlsSheet.

/**
 * 根据每页sheet数量导出多sheet
 *
 * @param request
 * @param object 实体类
 * @param clazz 实体类class
 * @param title 标题
 * @param exportFields 导出字段自定义
 * @param pageNum 每个sheet的数据条数
 * @param request
 */
protected ModelAndView exportXlsSheet(HttpServletRequest request, T object, Class<T> clazz, String title, String exportFields, Integer pageNum) {
    // Step.1 组装查询条件
    QueryWrapper<T> queryWrapper = QueryGenerator.initQueryWrapper(object, request.getParameterMap());
    LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
    // Step.2 计算分页sheet数据
    double total = service.count();
    int count = (int) Math.ceil(total / pageNum);
    // Step.3 多sheet处理
    List<Map<String, Object>> listMap = new ArrayList<Map<String, Object>>();
    for (int i = 1; i <= count; i++) {
        Page<T> page = new Page<T>(i, pageNum);
        IPage<T> pageList = service.page(page, queryWrapper);
        List<T> records = pageList.getRecords();
        List<T> exportList = null;
        // 过滤选中数据
        String selections = request.getParameter("selections");
        if (oConvertUtils.isNotEmpty(selections)) {
            List<String> selectionList = Arrays.asList(selections.split(","));
            exportList = records.stream().filter(item -> selectionList.contains(getId(item))).collect(Collectors.toList());
        } else {
            exportList = records;
        }
        Map<String, Object> map = new HashMap<String, Object>();
        ExportParams exportParams = new ExportParams(title + "报表", "导出人:" + sysUser.getRealname(), title + i, upLoadPath);
        exportParams.setType(ExcelType.XSSF);
        // map.put("title",exportParams);//表格Title
        // 表格Title
        map.put(NormalExcelConstants.PARAMS, exportParams);
        // 表格对应实体
        map.put(NormalExcelConstants.CLASS, clazz);
        // 数据集合
        map.put(NormalExcelConstants.DATA_LIST, exportList);
        listMap.add(map);
    }
    // Step.4 AutoPoi 导出Excel
    ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
    // 此处设置的filename无效 ,前端会重更新设置一下
    mv.addObject(NormalExcelConstants.FILE_NAME, title);
    mv.addObject(NormalExcelConstants.MAP_LIST, listMap);
    return mv;
}
Also used : JeecgEntityExcelView(org.jeecgframework.poi.excel.view.JeecgEntityExcelView) ModelAndView(org.springframework.web.servlet.ModelAndView) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) IPage(com.baomidou.mybatisplus.core.metadata.IPage) LoginUser(org.jeecg.common.system.vo.LoginUser) ExportParams(org.jeecgframework.poi.excel.entity.ExportParams)

Aggregations

ExportParams (org.jeecgframework.poi.excel.entity.ExportParams)33 JeecgEntityExcelView (org.jeecgframework.poi.excel.view.JeecgEntityExcelView)33 ModelAndView (org.springframework.web.servlet.ModelAndView)33 LoginUser (org.jeecg.common.system.vo.LoginUser)28 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)6 IPage (com.baomidou.mybatisplus.core.metadata.IPage)6 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)6 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 JSON (com.alibaba.fastjson.JSON)3 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)3 IOException (java.io.IOException)3 java.util (java.util)3 Collectors (java.util.stream.Collectors)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)3 Slf4j (lombok.extern.slf4j.Slf4j)3 StringUtils (org.apache.commons.lang.StringUtils)3 SecurityUtils (org.apache.shiro.SecurityUtils)3 Result (org.jeecg.common.api.vo.Result)3