Search in sources :

Example 1 with SysDictPage

use of org.jeecg.modules.system.vo.SysDictPage in project jeecg-boot by jeecgboot.

the class SysDictController method exportXls.

/**
 * 导出excel
 *
 * @param request
 */
@RequestMapping(value = "/exportXls")
public ModelAndView exportXls(SysDict sysDict, HttpServletRequest request) {
    // Step.1 组装查询条件
    QueryWrapper<SysDict> queryWrapper = QueryGenerator.initQueryWrapper(sysDict, request.getParameterMap());
    // Step.2 AutoPoi 导出Excel
    ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
    List<SysDictPage> pageList = new ArrayList<SysDictPage>();
    List<SysDict> sysDictList = sysDictService.list(queryWrapper);
    for (SysDict dictMain : sysDictList) {
        SysDictPage vo = new SysDictPage();
        BeanUtils.copyProperties(dictMain, vo);
        // 查询机票
        List<SysDictItem> sysDictItemList = sysDictItemService.selectItemsByMainId(dictMain.getId());
        vo.setSysDictItemList(sysDictItemList);
        pageList.add(vo);
    }
    // 导出文件名称
    mv.addObject(NormalExcelConstants.FILE_NAME, "数据字典");
    // 注解对象Class
    mv.addObject(NormalExcelConstants.CLASS, SysDictPage.class);
    // 自定义表格参数
    LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
    mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("数据字典列表", "导出人:" + user.getRealname(), "数据字典"));
    // 导出数据列表
    mv.addObject(NormalExcelConstants.DATA_LIST, pageList);
    return mv;
}
Also used : ExportParams(org.jeecgframework.poi.excel.entity.ExportParams) SysDictPage(org.jeecg.modules.system.vo.SysDictPage) JeecgEntityExcelView(org.jeecgframework.poi.excel.view.JeecgEntityExcelView) SysDict(org.jeecg.modules.system.entity.SysDict) ModelAndView(org.springframework.web.servlet.ModelAndView) SysDictItem(org.jeecg.modules.system.entity.SysDictItem) LoginUser(org.jeecg.common.system.vo.LoginUser)

Example 2 with SysDictPage

use of org.jeecg.modules.system.vo.SysDictPage in project kms by mahonelau.

the class SysDictController method importExcel.

/**
 * 通过excel导入数据
 *
 * @param request
 * @param
 * @return
 */
// @RequiresRoles({"admin"})
@RequestMapping(value = "/importExcel", method = RequestMethod.POST)
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
    MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
    Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
    for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
        // 获取上传文件对象
        MultipartFile file = entity.getValue();
        ImportParams params = new ImportParams();
        params.setTitleRows(2);
        params.setHeadRows(2);
        params.setNeedSave(true);
        try {
            // 导入Excel格式校验,看匹配的字段文本概率
            Boolean t = ExcelImportCheckUtil.check(file.getInputStream(), SysDictPage.class, params);
            if (!t) {
                throw new RuntimeException("导入Excel校验失败 !");
            }
            List<SysDictPage> list = ExcelImportUtil.importExcel(file.getInputStream(), SysDictPage.class, params);
            // 错误信息
            List<String> errorMessage = new ArrayList<>();
            int successLines = 0, errorLines = 0;
            for (int i = 0; i < list.size(); i++) {
                SysDict po = new SysDict();
                BeanUtils.copyProperties(list.get(i), po);
                po.setDelFlag(CommonConstant.DEL_FLAG_0);
                try {
                    Integer integer = sysDictService.saveMain(po, list.get(i).getSysDictItemList());
                    if (integer > 0) {
                        successLines++;
                    } else {
                        errorLines++;
                        int lineNumber = i + 1;
                        errorMessage.add("第 " + lineNumber + " 行:字典编码已经存在,忽略导入。");
                    }
                } catch (Exception e) {
                    errorLines++;
                    int lineNumber = i + 1;
                    errorMessage.add("第 " + lineNumber + " 行:字典编码已经存在,忽略导入。");
                }
            }
            return ImportExcelUtil.imporReturnRes(errorLines, successLines, errorMessage);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return Result.error("文件导入失败:" + e.getMessage());
        } finally {
            try {
                file.getInputStream().close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    return Result.error("文件导入失败!");
}
Also used : SysDictPage(org.jeecg.modules.system.vo.SysDictPage) MultipartFile(org.springframework.web.multipart.MultipartFile) ImportParams(org.jeecgframework.poi.excel.entity.ImportParams) SysDict(org.jeecg.modules.system.entity.SysDict) MultipartHttpServletRequest(org.springframework.web.multipart.MultipartHttpServletRequest)

Example 3 with SysDictPage

use of org.jeecg.modules.system.vo.SysDictPage in project kykms by mahonelau.

the class SysDictController method exportXls.

/**
 * 导出excel
 *
 * @param request
 */
@RequestMapping(value = "/exportXls")
public ModelAndView exportXls(SysDict sysDict, HttpServletRequest request) {
    // Step.1 组装查询条件
    QueryWrapper<SysDict> queryWrapper = QueryGenerator.initQueryWrapper(sysDict, request.getParameterMap());
    // Step.2 AutoPoi 导出Excel
    ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
    List<SysDictPage> pageList = new ArrayList<SysDictPage>();
    List<SysDict> sysDictList = sysDictService.list(queryWrapper);
    for (SysDict dictMain : sysDictList) {
        SysDictPage vo = new SysDictPage();
        BeanUtils.copyProperties(dictMain, vo);
        // 查询机票
        List<SysDictItem> sysDictItemList = sysDictItemService.selectItemsByMainId(dictMain.getId());
        vo.setSysDictItemList(sysDictItemList);
        pageList.add(vo);
    }
    // 导出文件名称
    mv.addObject(NormalExcelConstants.FILE_NAME, "数据字典");
    // 注解对象Class
    mv.addObject(NormalExcelConstants.CLASS, SysDictPage.class);
    // 自定义表格参数
    LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
    mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("数据字典列表", "导出人:" + user.getRealname(), "数据字典"));
    // 导出数据列表
    mv.addObject(NormalExcelConstants.DATA_LIST, pageList);
    return mv;
}
Also used : ExportParams(org.jeecgframework.poi.excel.entity.ExportParams) SysDictPage(org.jeecg.modules.system.vo.SysDictPage) JeecgEntityExcelView(org.jeecgframework.poi.excel.view.JeecgEntityExcelView) SysDict(org.jeecg.modules.system.entity.SysDict) ModelAndView(org.springframework.web.servlet.ModelAndView) SysDictItem(org.jeecg.modules.system.entity.SysDictItem) LoginUser(org.jeecg.common.system.vo.LoginUser)

Example 4 with SysDictPage

use of org.jeecg.modules.system.vo.SysDictPage in project kykms by mahonelau.

the class SysDictController method importExcel.

/**
 * 通过excel导入数据
 *
 * @param request
 * @param
 * @return
 */
// @RequiresRoles({"admin"})
@RequestMapping(value = "/importExcel", method = RequestMethod.POST)
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
    MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
    Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
    for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
        // 获取上传文件对象
        MultipartFile file = entity.getValue();
        ImportParams params = new ImportParams();
        params.setTitleRows(2);
        params.setHeadRows(2);
        params.setNeedSave(true);
        try {
            // 导入Excel格式校验,看匹配的字段文本概率
            Boolean t = ExcelImportCheckUtil.check(file.getInputStream(), SysDictPage.class, params);
            if (!t) {
                throw new RuntimeException("导入Excel校验失败 !");
            }
            List<SysDictPage> list = ExcelImportUtil.importExcel(file.getInputStream(), SysDictPage.class, params);
            // 错误信息
            List<String> errorMessage = new ArrayList<>();
            int successLines = 0, errorLines = 0;
            for (int i = 0; i < list.size(); i++) {
                SysDict po = new SysDict();
                BeanUtils.copyProperties(list.get(i), po);
                po.setDelFlag(CommonConstant.DEL_FLAG_0);
                try {
                    Integer integer = sysDictService.saveMain(po, list.get(i).getSysDictItemList());
                    if (integer > 0) {
                        successLines++;
                    } else {
                        errorLines++;
                        int lineNumber = i + 1;
                        errorMessage.add("第 " + lineNumber + " 行:字典编码已经存在,忽略导入。");
                    }
                } catch (Exception e) {
                    errorLines++;
                    int lineNumber = i + 1;
                    errorMessage.add("第 " + lineNumber + " 行:字典编码已经存在,忽略导入。");
                }
            }
            return ImportExcelUtil.imporReturnRes(errorLines, successLines, errorMessage);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return Result.error("文件导入失败:" + e.getMessage());
        } finally {
            try {
                file.getInputStream().close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    return Result.error("文件导入失败!");
}
Also used : SysDictPage(org.jeecg.modules.system.vo.SysDictPage) MultipartFile(org.springframework.web.multipart.MultipartFile) ImportParams(org.jeecgframework.poi.excel.entity.ImportParams) SysDict(org.jeecg.modules.system.entity.SysDict) MultipartHttpServletRequest(org.springframework.web.multipart.MultipartHttpServletRequest)

Example 5 with SysDictPage

use of org.jeecg.modules.system.vo.SysDictPage in project kms by mahonelau.

the class SysDictController method exportXls.

/**
 * 导出excel
 *
 * @param request
 */
@RequestMapping(value = "/exportXls")
public ModelAndView exportXls(SysDict sysDict, HttpServletRequest request) {
    // Step.1 组装查询条件
    QueryWrapper<SysDict> queryWrapper = QueryGenerator.initQueryWrapper(sysDict, request.getParameterMap());
    // Step.2 AutoPoi 导出Excel
    ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
    List<SysDictPage> pageList = new ArrayList<SysDictPage>();
    List<SysDict> sysDictList = sysDictService.list(queryWrapper);
    for (SysDict dictMain : sysDictList) {
        SysDictPage vo = new SysDictPage();
        BeanUtils.copyProperties(dictMain, vo);
        // 查询机票
        List<SysDictItem> sysDictItemList = sysDictItemService.selectItemsByMainId(dictMain.getId());
        vo.setSysDictItemList(sysDictItemList);
        pageList.add(vo);
    }
    // 导出文件名称
    mv.addObject(NormalExcelConstants.FILE_NAME, "数据字典");
    // 注解对象Class
    mv.addObject(NormalExcelConstants.CLASS, SysDictPage.class);
    // 自定义表格参数
    LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
    mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("数据字典列表", "导出人:" + user.getRealname(), "数据字典"));
    // 导出数据列表
    mv.addObject(NormalExcelConstants.DATA_LIST, pageList);
    return mv;
}
Also used : ExportParams(org.jeecgframework.poi.excel.entity.ExportParams) SysDictPage(org.jeecg.modules.system.vo.SysDictPage) JeecgEntityExcelView(org.jeecgframework.poi.excel.view.JeecgEntityExcelView) SysDict(org.jeecg.modules.system.entity.SysDict) ModelAndView(org.springframework.web.servlet.ModelAndView) SysDictItem(org.jeecg.modules.system.entity.SysDictItem) LoginUser(org.jeecg.common.system.vo.LoginUser)

Aggregations

SysDict (org.jeecg.modules.system.entity.SysDict)6 SysDictPage (org.jeecg.modules.system.vo.SysDictPage)6 LoginUser (org.jeecg.common.system.vo.LoginUser)3 SysDictItem (org.jeecg.modules.system.entity.SysDictItem)3 ExportParams (org.jeecgframework.poi.excel.entity.ExportParams)3 ImportParams (org.jeecgframework.poi.excel.entity.ImportParams)3 JeecgEntityExcelView (org.jeecgframework.poi.excel.view.JeecgEntityExcelView)3 MultipartFile (org.springframework.web.multipart.MultipartFile)3 MultipartHttpServletRequest (org.springframework.web.multipart.MultipartHttpServletRequest)3 ModelAndView (org.springframework.web.servlet.ModelAndView)3