| | |
| | | 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 com.zy.asrs.wcs.utils.CommonUtils; |
| | | |
| | | 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 |
| | |
| | | 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 != list) { |
| | | key = key.replaceAll("Range", ""); |
| | | if (this.isToUnderlineCase) { |
| | | key = Utils.toSymbolCase(key, '_'); |
| | | key = CommonUtils.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, '_'); |
| | | key = CommonUtils.toSymbolCase(key, '_'); |
| | | } |
| | | if (like) { |
| | | queryWrapper.like(key, val); |
| | |
| | | } |
| | | } |
| | | |
| | | if (!Cools.isEmpty(where.getCondition()) && !Cools.isEmpty(cls)) { |
| | | if (null != consumer) { |
| | | consumer.accept(queryWrapper); |
| | | } |
| | | |
| | | Field[] fields = null; |
| | | if (!Cools.isEmpty(cls)) { |
| | | fields = Cools.getAllFields(cls); |
| | | for (Field field : fields) { |
| | | if ("createTime".equals(field.getName())) { |
| | | queryWrapper.orderByDesc(CommonUtils.toSymbolCase(field.getName(), '_')); |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (!Cools.isEmpty(where.getCondition()) && !Cools.isEmpty(fields)) { |
| | | List<String> columns = new ArrayList<>(); |
| | | for (Field field :Cools.getAllFields(cls)){ |
| | | for (Field field : fields){ |
| | | if (Modifier.isFinal(field.getModifiers()) |
| | | || Modifier.isStatic(field.getModifiers()) |
| | | || Modifier.isTransient(field.getModifiers())){ |
| | | continue; |
| | | } |
| | | |
| | | String column = Utils.toSymbolCase(field.getName(), '_'); |
| | | if (field.isAnnotationPresent(TableField.class)){ |
| | | TableField annotation = field.getAnnotation(TableField.class); |
| | | if (!annotation.exist()) { |
| | | continue; |
| | | } |
| | | } |
| | | |
| | | String column = CommonUtils.toSymbolCase(field.getName(), '_'); |
| | | columns.add(column); |
| | | } |
| | | if (!columns.isEmpty()) { |
| | |
| | | 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; |
| | | } |
| | | |
| | | } |