| | |
| | | */ |
| | | public abstract class AbstractBaseController { |
| | | |
| | | public <T> List exportSupport(List<T> list, List<String> fields){ |
| | | if (Cools.isEmpty(list)){ |
| | | public <T> List exportSupport(List<T> list, List<String> fields) { |
| | | if (Cools.isEmpty(list)) { |
| | | throw new CoolException(BaseRes.EMPTY); |
| | | } |
| | | try { |
| | | List<List<Object>> result = new ArrayList<>(); |
| | | Method[] methods = list.get(0).getClass().getMethods(); |
| | | for (T t : list){ |
| | | for (T t : list) { |
| | | List<Object> node = new ArrayList<>(); |
| | | for (String field : fields){ |
| | | for (String field : fields) { |
| | | for (Method method : methods) { |
| | | if (("get" + field).toLowerCase().equals(method.getName().toLowerCase())) { |
| | | Object val = method.invoke(t); |
| | |
| | | result.add(node); |
| | | } |
| | | return result; |
| | | } catch (Exception e){ |
| | | } catch (Exception e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | |
| | | } |
| | | |
| | | public static Map<String, Object> excludeTrash(Map<String, Object> map){ |
| | | if (Cools.isEmpty(map)){ |
| | | public static Map<String, Object> excludeTrash(Map<String, Object> map) { |
| | | if (Cools.isEmpty(map)) { |
| | | return new HashMap<>(); |
| | | } |
| | | map.entrySet().removeIf(next -> next.getKey().equals("curr") |
| | | || next.getKey().equals("limit") |
| | | || next.getKey().equals("orderByField") |
| | | || next.getKey().equals("orderByType") |
| | | || next.getKey().equals("condition") |
| | | || Cools.isEmpty(next.getValue())); |
| | | map.entrySet().removeIf(next -> next.getKey().equals("curr") || next.getKey().equals("limit") || next.getKey().equals("orderByField") || next.getKey().equals("orderByType") || next.getKey().equals("condition") || Cools.isEmpty(next.getValue())); |
| | | return map; |
| | | } |
| | | |