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> aliasTable, Map> 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 t = aliasTable.get(tableName); if (t != null && t.size() > 0) { tableAlias = t.get(0); } Map> params = face.getFilters(tableAlias, aliasField); List fieldNames = params.get("fields"); List 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> aliasTable, Map> aliasField, String faceUuid, String faceNumber, String val, Map> 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 t = aliasTable.get(tableName); if (t != null && t.size() > 0) { tableAlias = t.get(0); } Map> params = face.getFilters(aliasTable, aliasField,tableOfField); List fieldNames = params.get("fields"); List 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 ""; } }