许鹏程
2023-06-06 b119f3a31de2a459b56e7fde5dbd02d58a148f72
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package com.product.face.service;
 
import com.alibaba.fastjson.JSON;
import com.product.common.lang.StringUtils;
import com.product.core.cache.util.RedisUtil;
import com.product.core.exception.BaseException;
import com.product.core.service.support.AbstractBaseService;
import com.product.face.config.FaceConst;
import com.product.face.entity.FaceListEntity;
import org.springframework.stereotype.Component;
 
import java.util.List;
import java.util.Map;
 
/**
 * @Author cheng
 * @Date 2023/5/23 17:41
 * @Desc 表单列表搜索
 */
@Component
public class FaceListSearchService extends AbstractBaseService {
 
    public String getFaceListSearchFilter(Map<String, List<String>> aliasTable, Map<String, List<String>> aliasField, String faceUuid, String faceNumber, String val) throws BaseException {
        if (StringUtils.isEmpty(val)) {
            return "";
        }
        FaceListEntity face = null;
        if (!StringUtils.isEmpty(faceNumber)) {
            face = (FaceListEntity) RedisUtil.get(FaceConst.FACE_LIST_KEY + ":face-number" + faceNumber);
        } else if (!StringUtils.isEmpty(faceUuid)) {
            face = JSON.parseObject(JSON.toJSONString(RedisUtil.get(FaceConst.FACE_LIST_KEY + faceUuid)), FaceListEntity.class);
        }
        if (face != null) {
            String tableAlias = null;
            String tableName = face.getTableName();
            List<String> t = aliasTable.get(tableName);
            if (t != null && t.size() > 0) {
                tableAlias = t.get(0);
            }
            Map<String, List<String>> params = face.getFilters(tableAlias, aliasField);
            List<String> fieldNames = params.get("fields");
            List<String> filters = params.get("filter");
            String filter = "";
            for (int i = 0; i < fieldNames.size(); i++) {
                if (i > 0) {
                    filter += " or ";
                }
                filter += " " + fieldNames.get(i) + " LIKE BINARY concat('%','" + val + "','%')";
            }
            for (int i = 0; i < filters.size(); i++) {
                if (!"".equals(filter)) {
                    filter += " or ";
                }
                filter += filters.get(i).replace("~val~", val);
            }
            return "".equals(filter) ? "" : "( " + filter + " )";
        }
        return "";
    }
}