|  |  |  | 
|---|
|  |  |  | package com.zy.asrs.wcs.common.domain; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.annotation.TableField; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 
|---|
|  |  |  | import com.zy.asrs.framework.common.Cools; | 
|---|
|  |  |  | import com.zy.asrs.framework.common.DateUtils; | 
|---|
|  |  |  | import com.zy.asrs.wcs.utils.Utils; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.lang.reflect.Field; | 
|---|
|  |  |  | import java.lang.reflect.Modifier; | 
|---|
|  |  |  | import java.util.ArrayList; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  | import java.util.function.Consumer; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * Created by vincent on 2/13/2024 | 
|---|
|  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private final boolean isToUnderlineCase; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private final Class<T> cls; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public PageParam() { | 
|---|
|  |  |  | this(null); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | this(where, true); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public PageParam(U where, Class<T> cls) { | 
|---|
|  |  |  | this(where, true, cls); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public PageParam(U where, boolean isToUnderlineCase) { | 
|---|
|  |  |  | this(where, isToUnderlineCase, null); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public PageParam(U where, boolean isToUnderlineCase, Class<T> cls) { | 
|---|
|  |  |  | super(); | 
|---|
|  |  |  | this.where = where; | 
|---|
|  |  |  | this.isToUnderlineCase = isToUnderlineCase; | 
|---|
|  |  |  | this.cls = cls; | 
|---|
|  |  |  | if (where != null) { | 
|---|
|  |  |  | if (where.getCurrent() != null) { | 
|---|
|  |  |  | setCurrent(where.getCurrent()); | 
|---|
|  |  |  | 
|---|
|  |  |  | return this.buildWrapper(false); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @SuppressWarnings("all") | 
|---|
|  |  |  | public QueryWrapper<T> buildWrapper(Consumer<QueryWrapper<T>> consumer) { | 
|---|
|  |  |  | return this.buildWrapper(false, consumer); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public QueryWrapper<T> buildWrapper(boolean like) { | 
|---|
|  |  |  | return this.buildWrapper(like, null); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @SuppressWarnings("all") | 
|---|
|  |  |  | public QueryWrapper<T> buildWrapper(boolean like, Consumer<QueryWrapper<T>> consumer) { | 
|---|
|  |  |  | QueryWrapper<T> queryWrapper = new QueryWrapper<>(); | 
|---|
|  |  |  | Map<String, Object> map = where.getMap(); | 
|---|
|  |  |  | for (String key : map.keySet()) { | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (null != consumer) { | 
|---|
|  |  |  | consumer.accept(queryWrapper); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //            switch (queryType) { | 
|---|
|  |  |  | //                case EQ: | 
|---|
|  |  |  | //                    queryWrapper.eq(fieldName, fieldValue); | 
|---|
|  |  |  | //                    break; | 
|---|
|  |  |  | //                case NE: | 
|---|
|  |  |  | //                    queryWrapper.ne(fieldName, fieldValue); | 
|---|
|  |  |  | //                    break; | 
|---|
|  |  |  | //                case GT: | 
|---|
|  |  |  | //                    queryWrapper.gt(fieldName, fieldValue); | 
|---|
|  |  |  | //                    break; | 
|---|
|  |  |  | //                case GE: | 
|---|
|  |  |  | //                    queryWrapper.ge(fieldName, fieldValue); | 
|---|
|  |  |  | //                    break; | 
|---|
|  |  |  | //                case LT: | 
|---|
|  |  |  | //                    queryWrapper.lt(fieldName, fieldValue); | 
|---|
|  |  |  | //                    break; | 
|---|
|  |  |  | //                case LE: | 
|---|
|  |  |  | //                    queryWrapper.le(fieldName, fieldValue); | 
|---|
|  |  |  | //                    break; | 
|---|
|  |  |  | //                case LIKE: | 
|---|
|  |  |  | //                    queryWrapper.like(fieldName, fieldValue); | 
|---|
|  |  |  | //                    break; | 
|---|
|  |  |  | //                case NOT_LIKE: | 
|---|
|  |  |  | //                    queryWrapper.notLike(fieldName, fieldValue); | 
|---|
|  |  |  | //                    break; | 
|---|
|  |  |  | //                case LIKE_LEFT: | 
|---|
|  |  |  | //                    queryWrapper.likeLeft(fieldName, fieldValue); | 
|---|
|  |  |  | //                    break; | 
|---|
|  |  |  | //                case LIKE_RIGHT: | 
|---|
|  |  |  | //                    queryWrapper.likeRight(fieldName, fieldValue); | 
|---|
|  |  |  | //                    break; | 
|---|
|  |  |  | //                case IS_NULL: | 
|---|
|  |  |  | //                    queryWrapper.isNull(fieldName); | 
|---|
|  |  |  | //                    break; | 
|---|
|  |  |  | //                case IS_NOT_NULL: | 
|---|
|  |  |  | //                    queryWrapper.isNotNull(fieldName); | 
|---|
|  |  |  | //                    break; | 
|---|
|  |  |  | //                case IN: | 
|---|
|  |  |  | //                    queryWrapper.in(fieldName, fieldValue); | 
|---|
|  |  |  | //                    break; | 
|---|
|  |  |  | //                case NOT_IN: | 
|---|
|  |  |  | //                    queryWrapper.notIn(fieldName, fieldValue); | 
|---|
|  |  |  | //                    break; | 
|---|
|  |  |  | //                case IN_STR: | 
|---|
|  |  |  | //                    if (fieldValue instanceof String) { | 
|---|
|  |  |  | //                        queryWrapper.in(fieldName, Arrays.asList(((String) fieldValue).split(","))); | 
|---|
|  |  |  | //                    } | 
|---|
|  |  |  | //                    break; | 
|---|
|  |  |  | //                case NOT_IN_STR: | 
|---|
|  |  |  | //                    if (fieldValue instanceof String) { | 
|---|
|  |  |  | //                        queryWrapper.notIn(fieldName, Arrays.asList(((String) fieldValue).split(","))); | 
|---|
|  |  |  | //                    } | 
|---|
|  |  |  | //                    break; | 
|---|
|  |  |  | //            } | 
|---|
|  |  |  | Field[] fields = null; | 
|---|
|  |  |  | if (!Cools.isEmpty(cls)) { | 
|---|
|  |  |  | fields = Cools.getAllFields(cls); | 
|---|
|  |  |  | for (Field field : fields) { | 
|---|
|  |  |  | if ("createTime".equals(field.getName())) { | 
|---|
|  |  |  | queryWrapper.orderByDesc(Utils.toSymbolCase(field.getName(), '_')); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!Cools.isEmpty(where.getCondition()) && !Cools.isEmpty(fields)) { | 
|---|
|  |  |  | List<String> columns = new ArrayList<>(); | 
|---|
|  |  |  | for (Field field : fields){ | 
|---|
|  |  |  | 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(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (i == 0) { | 
|---|
|  |  |  | queryWrapper.and(wrapper -> wrapper.like(column, condition)); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | queryWrapper.or().like(column, condition); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return queryWrapper; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public Map<String, Object> pickOutMap() { | 
|---|
|  |  |  | return pickOutMap(false); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public Map<String, Object> pickOutMap(boolean mergeCondition) { | 
|---|
|  |  |  | Map<String, Object> map = where.getMap(); | 
|---|
|  |  |  | if (mergeCondition) { | 
|---|
|  |  |  | if (!Cools.isEmpty(where.getCondition())) { | 
|---|
|  |  |  | map.put("condition", where.getCondition()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return map; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|