1
zhang
2 天以前 02e3fbfc96e08c9285daaa5a6ec53716c747a671
zy-acs-manager/src/main/java/com/zy/acs/manager/common/domain/PageParam.java
@@ -24,6 +24,11 @@
    private static final long serialVersionUID = 1L;
    public static final String ORDER_DESC_VALUE = "desc";
    public static final Integer DEFAULT_PAGESIZE = 100;
    public static final Integer DEFAULT_CURRENT = 1;
    private final U where;
    /**
@@ -45,6 +50,7 @@
        this(where, true, cls);
    }
    public PageParam(U where, boolean isToUnderlineCase) {
        this(where, isToUnderlineCase, null);
    }
@@ -63,6 +69,11 @@
            }
        }
    }
    public QueryWrapper<T> buildWrapperExcludeNull(boolean like) {
        return this.buildWrapperExcludeNull(like, null, "create_time");
    }
    public QueryWrapper<T> buildWrapper(boolean like) {
@@ -129,25 +140,116 @@
        if (!Cools.isEmpty(where.getCondition()) && !Cools.isEmpty(cls)) {
            List<String> columns = new ArrayList<>();
            for (Field field : Cools.getAllFields(cls)){
            for (Field field : Cools.getAllFields(cls)) {
                if (Modifier.isFinal(field.getModifiers())
                        || Modifier.isStatic(field.getModifiers())
                        || Modifier.isTransient(field.getModifiers())){
                        || Modifier.isTransient(field.getModifiers())) {
                    continue;
                }
                if (field.isAnnotationPresent(TableField.class)){
                if (field.isAnnotationPresent(TableField.class)) {
                    TableField annotation = field.getAnnotation(TableField.class);
                    if (!annotation.exist()) {
                        continue;
                    }
                }
                String column =  Utils.toSymbolCase(field.getName(), '_');
                String column = Utils.toSymbolCase(field.getName(), '_');
                columns.add(column);
            }
            if (!columns.isEmpty()) {
                for (int i=0;i<columns.size();i++){
                for (int i = 0; i < columns.size(); i++) {
                    String column = columns.get(i);
                    String condition = where.getCondition();
                    if (i == 0) {
                        queryWrapper.and(wrapper -> wrapper.like(column, condition));
                    } else {
                        queryWrapper.or().like(column, condition);
                    }
                }
            }
        }
        return queryWrapper;
    }
    @SuppressWarnings("all")
    public QueryWrapper<T> buildWrapperExcludeNull(boolean like, Consumer<QueryWrapper<T>> consumer, String timeField) {
        QueryWrapper<T> queryWrapper = new QueryWrapper<>();
        Map<String, Object> map = where.getMap();
        for (String key : map.keySet()) {
            Object val = map.get(key);
            if (val == null) {
                continue;
            }
            if (key.contains("Range")) {
                ArrayList<String> list = null;
                if (val instanceof ArrayList) {
                    list = (ArrayList<String>) val;
                }
                if (null != list) {
                    key = key.replaceAll("Range", "");
                    if (this.isToUnderlineCase) {
                        key = Utils.toSymbolCase(key, '_');
                    }
                    queryWrapper.ge(key, DateUtils.convert(list.get(0)));
                    queryWrapper.le(key, DateUtils.convert(list.get(1)));
                }
            } else {
                if (this.isToUnderlineCase) {
                    key = Utils.toSymbolCase(key, '_');
                }
                if (like) {
                    queryWrapper.like(key, val);
                } else {
                    queryWrapper.eq(key, val);
                }
            }
        }
        if (null != consumer) {
            consumer.accept(queryWrapper);
        }
        if (!Cools.isEmpty(where.getTimeStart())) {
            Date timeStart = DateUtils.convert(String.valueOf(where.getTimeStart()), DateUtils.yyyyMMdd_F);
            queryWrapper.ge(timeField, timeStart);
        }
        if (!Cools.isEmpty(where.getTimeEnd())) {
            Date timeStart = DateUtils.convert(String.valueOf(where.getTimeEnd()), DateUtils.yyyyMMdd_F);
            queryWrapper.le(timeField, timeStart);
        }
        if (!Cools.isEmpty(where.getOrderBy())) {
            if (sortIsSQL(where.getOrderBy())) {
                setOrders(parseOrderSQL(where.getOrderBy()));
            }
        } else {
//            queryWrapper.orderByDesc("create_time");
        }
        if (!Cools.isEmpty(where.getCondition()) && !Cools.isEmpty(cls)) {
            List<String> columns = new ArrayList<>();
            for (Field field : Cools.getAllFields(cls)) {
                if (Modifier.isFinal(field.getModifiers())
                        || Modifier.isStatic(field.getModifiers())
                        || Modifier.isTransient(field.getModifiers())) {
                    continue;
                }
                if (field.isAnnotationPresent(TableField.class)) {
                    TableField annotation = field.getAnnotation(TableField.class);
                    if (!annotation.exist()) {
                        continue;
                    }
                }
                String column = Utils.toSymbolCase(field.getName(), '_');
                columns.add(column);
            }
            if (!columns.isEmpty()) {
                for (int i = 0; i < columns.size(); i++) {
                    String column = columns.get(i);
                    String condition = where.getCondition();