| | |
| | | package com.vincent.rsf.server.common.utils; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.TableInfo; |
| | | import com.baomidou.mybatisplus.core.metadata.TableInfoHelper; |
| | | import com.vincent.rsf.framework.common.Cools; |
| | | import com.vincent.rsf.framework.common.SpringUtils; |
| | | import com.vincent.rsf.framework.exception.CoolException; |
| | | import com.vincent.rsf.server.common.domain.BaseParam; |
| | | import com.vincent.rsf.server.common.domain.PageParam; |
| | | import com.vincent.rsf.server.system.entity.Fields; |
| | | import com.vincent.rsf.server.system.entity.FieldsItem; |
| | | import com.vincent.rsf.server.system.service.FieldsItemService; |
| | |
| | | saveFields(params, params.get("index").toString()); |
| | | } |
| | | } |
| | | |
| | | public static <T> QueryWrapper<T> setFieldsFilters(QueryWrapper<T> queryWrapper, PageParam<T, BaseParam> pageParam, Class<T> entityClass) { |
| | | // 动态获取表名 |
| | | TableInfo tableInfo = TableInfoHelper.getTableInfo(entityClass); |
| | | String tableName = tableInfo.getTableName(); |
| | | |
| | | FieldsService fieldsService = SpringUtils.getBean(FieldsService.class); |
| | | Map<String, Object> map = pageParam.getWhere().getFields(); |
| | | |
| | | for (String key : map.keySet()) { |
| | | Object val = map.get(key); |
| | | Fields fields = fieldsService.getOne(new LambdaQueryWrapper<Fields>().eq(Fields::getFields, key)); |
| | | if (!Cools.isEmpty(fields)) { |
| | | String applySql = String.format( |
| | | "EXISTS (SELECT 1 FROM sys_fields_item fie " + |
| | | "WHERE %s.fields_index IS NOT NULL " + |
| | | "AND fie.uuid = %s.fields_index " + |
| | | "AND fie.fields_id = '%s' " + |
| | | "AND fie.value = '%s')", |
| | | tableName, tableName, fields.getId(), val |
| | | ); |
| | | queryWrapper.apply(applySql); |
| | | } |
| | | } |
| | | return queryWrapper; |
| | | } |
| | | } |