fix:分页Bug

feat:模板文件
This commit is contained in:
nieziyan 2023-09-08 11:32:18 +08:00
parent 609852532a
commit c9ccba3a7e
10 changed files with 50 additions and 6 deletions

View File

@ -1,16 +1,22 @@
package org.jeecg.common.util;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import org.apache.poi.ss.usermodel.Workbook;
import org.jeecgframework.poi.excel.ExcelExportUtil;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.TemplateExportParams;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@ -72,9 +78,17 @@ public class ExportUtil {
}
public static TemplateExportParams excelTemplate(String name){
String templatePath = "D:\\excelTemplate\\";
templatePath += name;
return new TemplateExportParams(templatePath);
try {
String pathPrefix = "classpath:excelTemplate/";
ResourceLoader loader = new DefaultResourceLoader();
String templatePath = pathPrefix + name;
Resource resource = loader.getResource(templatePath);
String path = resource.getFile().getAbsolutePath();
return new TemplateExportParams(path);
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
public static void exportXls(HttpServletResponse response, String template,

View File

@ -0,0 +1,26 @@
package org.jeecg.common.util;
import cn.hutool.core.collection.CollUtil;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
public class PageUtil {
public static <T> List<T> page(int pageNo, int pageSize, List<T> data) {
if (CollUtil.isEmpty(data))
return Collections.emptyList();
if (pageNo <= 0 || pageSize < 0)
return Collections.emptyList();
// 计算偏移量
int offset = (pageNo - 1) * pageSize;
// 总记录数
int totalSize = data.size();
if (offset >= totalSize)
return Collections.emptyList();
// 分页结果数据
return data.stream().skip(offset).limit(pageSize)
.collect(Collectors.toList());
}
}

View File

@ -14,6 +14,7 @@ import org.jeecg.common.constant.DateConstant;
import org.jeecg.common.constant.DictConstant;
import org.jeecg.common.constant.SymbolConstant;
import org.jeecg.common.system.vo.DictModel;
import org.jeecg.common.util.PageUtil;
import org.jeecg.modules.base.dto.AnalysisLogDto;
import org.jeecg.modules.base.dto.NuclideInfo;
import org.jeecg.modules.base.dto.TypeDto;
@ -107,7 +108,7 @@ public class AlarmAnalysisLogServiceImpl extends ServiceImpl<AlarmAnalysisLogMap
Integer pageNo = analysisLogVo.getPageNo();
Integer pageSize = analysisLogVo.getPageSize();
int total = result.size();
List<AnalysisLogDto> records = ListUtil.page(pageNo, pageSize, result);
List<AnalysisLogDto> records = PageUtil.page(pageNo, pageSize, result);
Page<AnalysisLogDto> page = new Page<>(pageNo,pageSize,total);
page.setRecords(records);
return Result.OK(page);

View File

@ -11,6 +11,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.*;
import org.jeecg.common.system.vo.DictModel;
import org.jeecg.common.util.PageUtil;
import org.jeecg.common.util.RedisUtil;
import org.jeecg.modules.base.dto.AlarmAnalysisRuleDto;
import org.jeecg.modules.base.dto.AlarmAnalysisRuleInfo;
@ -125,7 +126,7 @@ public class AlarmAnalysisRuleServiceImpl extends ServiceImpl<AlarmAnalysisRuleM
}
// 封装分页
int total = dtos.size();
List<AlarmAnalysisRuleDto> records = ListUtil.page(pageNo, pageSize, dtos);
List<AlarmAnalysisRuleDto> records = PageUtil.page(pageNo, pageSize, dtos);
Page<AlarmAnalysisRuleDto> page = new Page<>(pageNo,pageSize,total);
page.setRecords(records);
return Result.OK(page);

View File

@ -15,6 +15,7 @@ import org.jeecg.common.constant.enums.FileTypeEnum;
import org.jeecg.common.properties.SpectrumPathProperties;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.FTPUtil;
import org.jeecg.common.util.PageUtil;
import org.jeecg.modules.base.comparator.FileComparator;
import org.jeecg.modules.base.dto.FileDto;
import org.jeecg.modules.base.bizVo.FileVo;
@ -146,7 +147,7 @@ public class SpectrumFileServiceImpl implements ISpectrumFileService {
String field = fileVo.getField();
String order = fileVo.getOrder();
fileDtos.sort(new FileComparator(field, order));
List<FileDto> records = ListUtil.page(pageNo, pageSize, fileDtos);
List<FileDto> records = PageUtil.page(pageNo, pageSize, fileDtos);
page.setRecords(records).setTotal(fileDtos.size());
return Result.OK(page);
} catch (IOException e) {

View File

@ -416,6 +416,7 @@
<nonFilteredFileExtension>eot</nonFilteredFileExtension>
<nonFilteredFileExtension>ttf</nonFilteredFileExtension>
<nonFilteredFileExtension>svg</nonFilteredFileExtension>
<nonFilteredFileExtension>xls</nonFilteredFileExtension>
</nonFilteredFileExtensions>
</configuration>
</plugin>