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 "";
|
}
|
}
|