|  |  |  | 
|---|
|  |  |  | import com.vincent.rsf.common.utils.Utils; | 
|---|
|  |  |  | import com.vincent.rsf.framework.common.Cools; | 
|---|
|  |  |  | import com.vincent.rsf.framework.common.DateUtils; | 
|---|
|  |  |  | import lombok.Getter; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.lang.reflect.Field; | 
|---|
|  |  |  | import java.lang.reflect.Modifier; | 
|---|
|  |  |  | 
|---|
|  |  |  | private static final long serialVersionUID = 1L; | 
|---|
|  |  |  | public static final String ORDER_DESC_VALUE = "desc"; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Getter | 
|---|
|  |  |  | private final U where; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public QueryWrapper<T> buildWrapper(boolean like, List<String> fields) { | 
|---|
|  |  |  | return this.buildWrapper(like, null,"create_time", fields); | 
|---|
|  |  |  | return this.buildWrapper(like, null, "create_time", fields); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @SuppressWarnings("all") | 
|---|
|  |  |  | 
|---|
|  |  |  | Map<String, Object> map = where.getMap(); | 
|---|
|  |  |  | for (String key : map.keySet()) { | 
|---|
|  |  |  | Object val = map.get(key); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (Cools.isEmpty(val)){ | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (key.contains("Range")) { | 
|---|
|  |  |  | ArrayList<String> list = null; | 
|---|
|  |  |  | if (val instanceof ArrayList) { | 
|---|
|  |  |  | 
|---|
|  |  |  | if (this.isToUnderlineCase) { | 
|---|
|  |  |  | key = Utils.toSymbolCase(key, '_'); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String finalKey = key; | 
|---|
|  |  |  | if (like && key.contains(timeField)) { | 
|---|
|  |  |  | queryWrapper.like("`" +  key + "`", val); | 
|---|
|  |  |  | queryWrapper.and(wrapper -> wrapper.like("`" + finalKey + "`", val)); | 
|---|
|  |  |  | //                    queryWrapper.like("`" +  key + "`", val); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | queryWrapper.eq("`" +  key + "`", val); | 
|---|
|  |  |  | queryWrapper.and(wrapper -> wrapper.eq("`" + finalKey + "`", val)); | 
|---|
|  |  |  | //                    queryWrapper.eq("`" +  key + "`", val); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 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++){ | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | queryWrapper.and(wrapper -> { | 
|---|
|  |  |  | for (int i = 0; i < columns.size(); i++) { | 
|---|
|  |  |  | String column = columns.get(i); | 
|---|
|  |  |  | String condition = where.getCondition(); | 
|---|
|  |  |  | if (i == 0) { | 
|---|
|  |  |  | wrapper.or().like("`" + column + "`", condition); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | wrapper.or().like("`" + column + "`", condition); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return queryWrapper; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @SuppressWarnings("all") | 
|---|
|  |  |  | public QueryWrapper<T> buildWrapper(boolean like, Consumer<QueryWrapper<T>> consumer,String timeField, List<String> fields) { | 
|---|
|  |  |  | public QueryWrapper<T> buildWrapper(boolean like, Consumer<QueryWrapper<T>> consumer, String timeField, List<String> fields) { | 
|---|
|  |  |  | QueryWrapper<T> queryWrapper = new QueryWrapper<>(); | 
|---|
|  |  |  | Map<String, Object> map = where.getMap(); | 
|---|
|  |  |  | for (String key : map.keySet()) { | 
|---|
|  |  |  | Object val = map.get(key); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (Cools.isEmpty(val)){ | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (key.contains("Range")) { | 
|---|
|  |  |  | ArrayList<String> list = null; | 
|---|
|  |  |  | if (val instanceof ArrayList) { | 
|---|
|  |  |  | 
|---|
|  |  |  | key = Utils.toSymbolCase(key, '_'); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (like && !fields.contains(key)) { | 
|---|
|  |  |  | queryWrapper.like("`" +  key + "`", val); | 
|---|
|  |  |  | queryWrapper.like("`" + key + "`", val); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | queryWrapper.eq("`" +  key + "`", val); | 
|---|
|  |  |  | queryWrapper.eq("`" + key + "`", val); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 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++){ | 
|---|
|  |  |  | //                    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); | 
|---|
|  |  |  | //                    } | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  | //            } | 
|---|
|  |  |  | if (!columns.isEmpty()) { | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | queryWrapper.and(wrapper -> { | 
|---|
|  |  |  | for (int i = 0; i < columns.size(); i++) { | 
|---|
|  |  |  | String column = columns.get(i); | 
|---|
|  |  |  | String condition = where.getCondition(); | 
|---|
|  |  |  | if (i == 0) { | 
|---|
|  |  |  | wrapper.or().like("`" + column + "`", condition); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | wrapper.or().like("`" + column + "`", condition); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return queryWrapper; | 
|---|