|  |  |  | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  | import com.vincent.rsf.server.system.service.FieldsService; | 
|---|
|  |  |  | import lombok.Synchronized; | 
|---|
|  |  |  | import org.apache.commons.lang3.StringUtils; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | * @time 2025/4/7 15:28 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Synchronized | 
|---|
|  |  |  | @Transactional(rollbackFor = Exception.class) | 
|---|
|  |  |  | public static synchronized  void updateFieldsValue(Map<String, Object> params) throws Exception { | 
|---|
|  |  |  | public static void updateFieldsValue(Map<String, Object> params) throws Exception { | 
|---|
|  |  |  | List<Fields> fields = getFieldsSta(); | 
|---|
|  |  |  | if (fields.isEmpty()) { return; } | 
|---|
|  |  |  | Object fieldsIndex = params.get("fieldsIndex"); | 
|---|
|  |  |  | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|