mirror of https://github.com/jeecgboot/jeecg-boot
pull/5605/head
parent
04c55fa3ba
commit
8dcc5bdf8a
|
@ -37,7 +37,9 @@ import java.util.*;
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class JeecgController<T, S extends IService<T>> {
|
public class JeecgController<T, S extends IService<T>> {
|
||||||
/**issues/2933 JeecgController注入service时改用protected修饰,能避免重复引用service*/
|
/**
|
||||||
|
* issues/2933 JeecgController注入service时改用protected修饰,能避免重复引用service
|
||||||
|
*/
|
||||||
@Autowired
|
@Autowired
|
||||||
protected S service;
|
protected S service;
|
||||||
@Resource
|
@Resource
|
||||||
|
@ -57,7 +59,7 @@ public class JeecgController<T, S extends IService<T>> {
|
||||||
String selections = request.getParameter("selections");
|
String selections = request.getParameter("selections");
|
||||||
if (oConvertUtils.isNotEmpty(selections)) {
|
if (oConvertUtils.isNotEmpty(selections)) {
|
||||||
List<String> selectionList = Arrays.asList(selections.split(","));
|
List<String> selectionList = Arrays.asList(selections.split(","));
|
||||||
queryWrapper.in("id",selectionList);
|
queryWrapper.in("id", selectionList);
|
||||||
}
|
}
|
||||||
// Step.2 获取导出数据
|
// Step.2 获取导出数据
|
||||||
List<T> exportList = service.list(queryWrapper);
|
List<T> exportList = service.list(queryWrapper);
|
||||||
|
@ -68,53 +70,54 @@ public class JeecgController<T, S extends IService<T>> {
|
||||||
mv.addObject(NormalExcelConstants.FILE_NAME, title);
|
mv.addObject(NormalExcelConstants.FILE_NAME, title);
|
||||||
mv.addObject(NormalExcelConstants.CLASS, clazz);
|
mv.addObject(NormalExcelConstants.CLASS, clazz);
|
||||||
//update-begin--Author:liusq Date:20210126 for:图片导出报错,ImageBasePath未设置--------------------
|
//update-begin--Author:liusq Date:20210126 for:图片导出报错,ImageBasePath未设置--------------------
|
||||||
ExportParams exportParams=new ExportParams(title + "报表", "导出人:" + sysUser.getRealname(), title);
|
ExportParams exportParams = new ExportParams(title + "报表", "导出人:" + sysUser.getRealname(), title);
|
||||||
exportParams.setImageBasePath(jeecgBaseConfig.getPath().getUpload());
|
exportParams.setImageBasePath(jeecgBaseConfig.getPath().getUpload());
|
||||||
//update-end--Author:liusq Date:20210126 for:图片导出报错,ImageBasePath未设置----------------------
|
//update-end--Author:liusq Date:20210126 for:图片导出报错,ImageBasePath未设置----------------------
|
||||||
mv.addObject(NormalExcelConstants.PARAMS,exportParams);
|
mv.addObject(NormalExcelConstants.PARAMS, exportParams);
|
||||||
mv.addObject(NormalExcelConstants.DATA_LIST, exportList);
|
mv.addObject(NormalExcelConstants.DATA_LIST, exportList);
|
||||||
return mv;
|
return mv;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据每页sheet数量导出多sheet
|
* 根据每页sheet数量导出多sheet
|
||||||
*
|
*
|
||||||
* @param request
|
* @param request
|
||||||
* @param object 实体类
|
* @param object 实体类
|
||||||
* @param clazz 实体类class
|
* @param clazz 实体类class
|
||||||
* @param title 标题
|
* @param title 标题
|
||||||
* @param exportFields 导出字段自定义
|
* @param exportFields 导出字段自定义
|
||||||
* @param pageNum 每个sheet的数据条数
|
* @param pageNum 每个sheet的数据条数
|
||||||
* @param request
|
* @param request
|
||||||
*/
|
*/
|
||||||
protected ModelAndView exportXlsSheet(HttpServletRequest request, T object, Class<T> clazz, String title,String exportFields,Integer pageNum) {
|
protected ModelAndView exportXlsSheet(HttpServletRequest request, T object, Class<T> clazz, String title, String exportFields, Integer pageNum) {
|
||||||
// Step.1 组装查询条件
|
// Step.1 组装查询条件
|
||||||
QueryWrapper<T> queryWrapper = QueryGenerator.initQueryWrapper(object, request.getParameterMap());
|
QueryWrapper<T> queryWrapper = QueryGenerator.initQueryWrapper(object, request.getParameterMap());
|
||||||
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
||||||
// Step.2 计算分页sheet数据
|
// Step.2 计算分页sheet数据
|
||||||
double total = service.count();
|
double total = service.count();
|
||||||
int count = (int)Math.ceil(total/pageNum);
|
int count = (int) Math.ceil(total / pageNum);
|
||||||
//update-begin-author:liusq---date:20220629--for: 多sheet导出根据选择导出写法调整 ---
|
//update-begin-author:liusq---date:20220629--for: 多sheet导出根据选择导出写法调整 ---
|
||||||
// Step.3 过滤选中数据
|
// Step.3 过滤选中数据
|
||||||
String selections = request.getParameter("selections");
|
String selections = request.getParameter("selections");
|
||||||
if (oConvertUtils.isNotEmpty(selections)) {
|
if (oConvertUtils.isNotEmpty(selections)) {
|
||||||
List<String> selectionList = Arrays.asList(selections.split(","));
|
List<String> selectionList = Arrays.asList(selections.split(","));
|
||||||
queryWrapper.in("id",selectionList);
|
queryWrapper.in("id", selectionList);
|
||||||
}
|
}
|
||||||
//update-end-author:liusq---date:20220629--for: 多sheet导出根据选择导出写法调整 ---
|
//update-end-author:liusq---date:20220629--for: 多sheet导出根据选择导出写法调整 ---
|
||||||
// Step.4 多sheet处理
|
// Step.4 多sheet处理
|
||||||
List<Map<String, Object>> listMap = new ArrayList<Map<String, Object>>();
|
List<Map<String, Object>> listMap = new ArrayList<Map<String, Object>>();
|
||||||
for (int i = 1; i <=count ; i++) {
|
for (int i = 1; i <= count; i++) {
|
||||||
Page<T> page = new Page<T>(i, pageNum);
|
Page<T> page = new Page<T>(i, pageNum);
|
||||||
IPage<T> pageList = service.page(page, queryWrapper);
|
IPage<T> pageList = service.page(page, queryWrapper);
|
||||||
List<T> exportList = pageList.getRecords();
|
List<T> exportList = pageList.getRecords();
|
||||||
Map<String, Object> map = new HashMap<>(5);
|
Map<String, Object> map = new HashMap<>(5);
|
||||||
ExportParams exportParams=new ExportParams(title + "报表", "导出人:" + sysUser.getRealname(), title+i,jeecgBaseConfig.getPath().getUpload());
|
ExportParams exportParams = new ExportParams(title + "报表", "导出人:" + sysUser.getRealname(), title + i, jeecgBaseConfig.getPath().getUpload());
|
||||||
exportParams.setType(ExcelType.XSSF);
|
exportParams.setType(ExcelType.XSSF);
|
||||||
//map.put("title",exportParams);
|
//map.put("title",exportParams);
|
||||||
//表格Title
|
//表格Title
|
||||||
map.put(NormalExcelConstants.PARAMS,exportParams);
|
map.put(NormalExcelConstants.PARAMS, exportParams);
|
||||||
//表格对应实体
|
//表格对应实体
|
||||||
map.put(NormalExcelConstants.CLASS,clazz);
|
map.put(NormalExcelConstants.CLASS, clazz);
|
||||||
//数据集合
|
//数据集合
|
||||||
map.put(NormalExcelConstants.DATA_LIST, exportList);
|
map.put(NormalExcelConstants.DATA_LIST, exportList);
|
||||||
listMap.add(map);
|
listMap.add(map);
|
||||||
|
@ -133,9 +136,9 @@ public class JeecgController<T, S extends IService<T>> {
|
||||||
*
|
*
|
||||||
* @param request
|
* @param request
|
||||||
*/
|
*/
|
||||||
protected ModelAndView exportXls(HttpServletRequest request, T object, Class<T> clazz, String title,String exportFields) {
|
protected ModelAndView exportXls(HttpServletRequest request, T object, Class<T> clazz, String title, String exportFields) {
|
||||||
ModelAndView mv = this.exportXls(request,object,clazz,title);
|
ModelAndView mv = this.exportXls(request, object, clazz, title);
|
||||||
mv.addObject(NormalExcelConstants.EXPORT_FIELDS,exportFields);
|
mv.addObject(NormalExcelConstants.EXPORT_FIELDS, exportFields);
|
||||||
return mv;
|
return mv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,9 +187,9 @@ public class JeecgController<T, S extends IService<T>> {
|
||||||
//update-begin-author:taoyan date:20211124 for: 导入数据重复增加提示
|
//update-begin-author:taoyan date:20211124 for: 导入数据重复增加提示
|
||||||
String msg = e.getMessage();
|
String msg = e.getMessage();
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
if(msg!=null && msg.indexOf("Duplicate entry")>=0){
|
if (msg != null && msg.indexOf("Duplicate entry") >= 0) {
|
||||||
return Result.error("文件导入失败:有重复数据!");
|
return Result.error("文件导入失败:有重复数据!");
|
||||||
}else{
|
} else {
|
||||||
return Result.error("文件导入失败:" + e.getMessage());
|
return Result.error("文件导入失败:" + e.getMessage());
|
||||||
}
|
}
|
||||||
//update-end-author:taoyan date:20211124 for: 导入数据重复增加提示
|
//update-end-author:taoyan date:20211124 for: 导入数据重复增加提示
|
||||||
|
|
|
@ -36,6 +36,9 @@ public class JeecgSentinelApplication {
|
||||||
triggerSentinelInit();
|
triggerSentinelInit();
|
||||||
ConfigurableApplicationContext application = SpringApplication.run(JeecgSentinelApplication.class, args);
|
ConfigurableApplicationContext application = SpringApplication.run(JeecgSentinelApplication.class, args);
|
||||||
Environment env = application.getEnvironment();
|
Environment env = application.getEnvironment();
|
||||||
|
// 目前jeecg-sentinel 1.8.3 版本存在alibaba-sentinel 1.8.3版本 启动nacos数据源导致配置不生效的问题,以下为临时处理办法
|
||||||
|
System.getProperties().setProperty("sentinel.dashboard.auth.username", env.getProperty("sentinel.dashboard.auth.username"));
|
||||||
|
System.getProperties().setProperty("sentinel.dashboard.auth.password", env.getProperty("sentinel.dashboard.auth.password"));
|
||||||
String port = env.getProperty("server.port");
|
String port = env.getProperty("server.port");
|
||||||
log.info("\n----------------------------------------------------------\n\t" +
|
log.info("\n----------------------------------------------------------\n\t" +
|
||||||
"Application SentinelDashboard is running! Access URLs:\n\t" +
|
"Application SentinelDashboard is running! Access URLs:\n\t" +
|
||||||
|
|
|
@ -18,8 +18,6 @@ auth:
|
||||||
filter:
|
filter:
|
||||||
exclude-url-suffixes: htm,html,js,css,map,ico,ttf,woff,png
|
exclude-url-suffixes: htm,html,js,css,map,ico,ttf,woff,png
|
||||||
exclude-urls: /,/auth/login,/auth/logout,/registry/machine,/version
|
exclude-urls: /,/auth/login,/auth/logout,/registry/machine,/version
|
||||||
password: sentinel
|
|
||||||
username: sentinel
|
|
||||||
logging:
|
logging:
|
||||||
level:
|
level:
|
||||||
org:
|
org:
|
||||||
|
@ -35,3 +33,6 @@ nacos:
|
||||||
sentinel:
|
sentinel:
|
||||||
dashboard:
|
dashboard:
|
||||||
version: 1.8.2
|
version: 1.8.2
|
||||||
|
auth:
|
||||||
|
username: sentinel
|
||||||
|
password: sentinel
|
Loading…
Reference in New Issue