Search in sources :

Example 1 with SysDict

use of org.jeecg.modules.system.entity.SysDict 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 SysDict

use of org.jeecg.modules.system.entity.SysDict 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 SysDict

use of org.jeecg.modules.system.entity.SysDict in project kms by mahonelau.

the class SysDictController method treeList.

/**
 * @功能:获取树形字典数据
 * @param sysDict
 * @param pageNo
 * @param pageSize
 * @param req
 * @return
 */
@SuppressWarnings("unchecked")
@RequestMapping(value = "/treeList", method = RequestMethod.GET)
public Result<List<SysDictTree>> treeList(SysDict sysDict, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest req) {
    Result<List<SysDictTree>> result = new Result<>();
    LambdaQueryWrapper<SysDict> query = new LambdaQueryWrapper<>();
    // 构造查询条件
    String dictName = sysDict.getDictName();
    if (oConvertUtils.isNotEmpty(dictName)) {
        query.like(true, SysDict::getDictName, dictName);
    }
    query.orderByDesc(true, SysDict::getCreateTime);
    List<SysDict> list = sysDictService.list(query);
    List<SysDictTree> treeList = new ArrayList<>();
    for (SysDict node : list) {
        treeList.add(new SysDictTree(node));
    }
    result.setSuccess(true);
    result.setResult(treeList);
    return result;
}
Also used : SysDictTree(org.jeecg.modules.system.model.SysDictTree) SysDict(org.jeecg.modules.system.entity.SysDict) Result(org.jeecg.common.api.vo.Result) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)

Example 4 with SysDict

use of org.jeecg.modules.system.entity.SysDict 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 5 with SysDict

use of org.jeecg.modules.system.entity.SysDict 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)

Aggregations

SysDict (org.jeecg.modules.system.entity.SysDict)15 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)6 Result (org.jeecg.common.api.vo.Result)6 SysDictItem (org.jeecg.modules.system.entity.SysDictItem)6 SysDictPage (org.jeecg.modules.system.vo.SysDictPage)6 IPage (com.baomidou.mybatisplus.core.metadata.IPage)3 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)3 ServiceImpl (com.baomidou.mybatisplus.extension.service.impl.ServiceImpl)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 Collectors (java.util.stream.Collectors)3 Slf4j (lombok.extern.slf4j.Slf4j)3 CacheConstant (org.jeecg.common.constant.CacheConstant)3 CommonConstant (org.jeecg.common.constant.CommonConstant)3 DictModel (org.jeecg.common.system.vo.DictModel)3 DictQuery (org.jeecg.common.system.vo.DictQuery)3 LoginUser (org.jeecg.common.system.vo.LoginUser)3 SqlInjectionUtil (org.jeecg.common.util.SqlInjectionUtil)3