shicf
2 天以前 b8dbd91e4a1552a1e11cd5fe4eef09f296cf656b
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
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 {
    
    /**
     * 不用
     * 列表关键字搜索
     * @param aliasTable
     * @param aliasField
     * @param faceUuid
     * @param faceNumber
     * @param val
     * @return
     * @throws BaseException
     */
    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 "";
    }
    /**
     * 列表关键字搜索
     * @param aliasTable  {"product_sys_staffs":["a"],"product_sys_users":["b"],"product_sys_job_posts":["e"],"product_sys_org_levels":["c","d"]}
     * @param aliasField
     * @param faceUuid
     * @param faceNumber
     * @param val
     * @param tableOfField  表对应字段 如:table_relate_fields = {
        "product_sys_staffs": ["uuid", "staff_status", "staff_avatar", "show_name", "mobile_phone", "staff_status_save_value", "status_save_value"],
        "product_sys_users": ["uuid1", "user_name", "user_id", "user_account", "status"],
        "product_sys_job_posts": ["job_post_uuid"],
        "product_sys_org_levels": ["uuid2", "uuid3", "org_level_uuid", "dept_uuid"]
    }
     * @return
     * @throws BaseException
     */
    public String getFaceListSearchFilter(Map<String, List<String>> aliasTable, Map<String, List<String>> aliasField, String faceUuid, String faceNumber, String val, Map<String, List<String>> tableOfField) 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(aliasTable, aliasField,tableOfField);
            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 "";
    }
}