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;
}
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("文件导入失败!");
}
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;
}
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;
}
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("文件导入失败!");
}
Aggregations