From 0cb3f66d6ea29da00a5fe8982d8b32926b399f72 Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期三, 06 三月 2024 17:00:04 +0800 Subject: [PATCH] 反射查询方法 --- src/main/java/com/lf/server/service/sys/ReportService.java | 48 ++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 38 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/lf/server/service/sys/ReportService.java b/src/main/java/com/lf/server/service/sys/ReportService.java index 6d5e919..c2f2a5f 100644 --- a/src/main/java/com/lf/server/service/sys/ReportService.java +++ b/src/main/java/com/lf/server/service/sys/ReportService.java @@ -20,6 +20,7 @@ import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; import java.io.File; +import java.lang.reflect.Method; import java.util.*; /** @@ -313,7 +314,7 @@ * 鐢熸垚Excel */ private void createExcel(String source, String target, ReportEntity re) { - List<CountEntity> list = countExplorationPoints(); + List<CountEntity> list = selectListByMethodName(re); if (null == list || list.isEmpty()) { return; } @@ -321,15 +322,6 @@ int rows = 1, allCount = 0; Double allSize = 0d, allArea = 0d; for (CountEntity ce : list) { - if (null == ce.getCount()) { - ce.setCount(0L); - } - if (null == ce.getSizes()) { - ce.setSizes(0d); - } - if (null == ce.getArea()) { - ce.setArea(0d); - } ce.setNo(rows++); ce.setM2(FileHelper.getSizes(ce.getSizes())); ce.setM3(FileHelper.getSquareMeter(ce.getArea())); @@ -354,6 +346,42 @@ } /** + * 鏍规嵁鏂规硶鍚嶇О鏌ヨ鏁版嵁鍒楄〃 + * + * @param re + * @return + */ + private List<CountEntity> selectListByMethodName(ReportEntity re) { + List<CountEntity> list = null; + try { + Method method = ReportService.class.getDeclaredMethod(re.getCode(), ReportService.class); + Object obj = method.invoke(this); + if (obj instanceof List<?>) { + list = (List<CountEntity>) obj; + } + } catch (Exception ex) { + log.error(ex.getMessage(), ex); + } + + if (null == list || list.isEmpty()) { + return list; + } + for (CountEntity ce : list) { + if (null == ce.getCount()) { + ce.setCount(0L); + } + if (null == ce.getSizes()) { + ce.setSizes(0d); + } + if (null == ce.getArea()) { + ce.setArea(0d); + } + } + + return list; + } + + /** * 鑾峰彇涓嬭浇瀹炰綋绫� */ private DownloadEntity getDownloadEntity(UserEntity ue, String file) { -- Gitblit v1.9.3