From db5f57946476d9c41d2942fab3300e2dab05c9fd Mon Sep 17 00:00:00 2001 From: Hermes Agent Date: Mon, 22 Jun 2026 13:53:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81data=5Ffilter=E6=98=BE?= =?UTF-8?q?=E5=BC=8F=E5=A3=B0=E6=98=8Eop(LIKE)=EF=BC=8C=E4=B8=8D=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E5=AF=B9=E6=89=80=E6=9C=89=E5=AD=97=E7=AC=A6=E4=B8=B2?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E6=A8=A1=E7=B3=8A=E5=8C=B9=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- xls2ddl/tmpls.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/xls2ddl/tmpls.py b/xls2ddl/tmpls.py index 4824cb5..b4dfabd 100644 --- a/xls2ddl/tmpls.py +++ b/xls2ddl/tmpls.py @@ -171,17 +171,21 @@ ori_fields = json.loads(fields_str) if not filterjson: fields = [ f['name'] for f in ori_fields ] filterjson = default_filterjson(fields, ns) - # 字符串字段使用LIKE模糊匹配 - str_fields = {f['name'] for f in ori_fields if f.get('type') in ('str', 'text')} - if filterjson and str_fields: - if not isinstance(filterjson, dict) or 'AND' not in filterjson: - filterjson = {'AND': [filterjson] if filterjson else []} - for fj in filterjson['AND']: - if fj.get('field') in str_fields and fj.get('op') == '=': - var = fj.get('var') - if var and var in ns and ns[var]: - ns[var] = f'%{ns[var]}%' - fj['op'] = 'LIKE' +{% if data_filter and data_filter.fields %} +# 应用 data_filter 中显式声明的 op(如 LIKE) +__df_fields = {{json.dumps(data_filter.fields, ensure_ascii=False)}} +__df_ops = {f['field']: f.get('op') for f in __df_fields if f.get('op')} +if filterjson and __df_ops: + if not isinstance(filterjson, dict) or 'AND' not in filterjson: + filterjson = {'AND': [filterjson] if filterjson else []} + for fj in filterjson['AND']: + if fj.get('field') in __df_ops: + fj['op'] = __df_ops[fj['field']] + if fj['op'] == 'LIKE': + var = fj.get('var') + if var and var in ns and ns[var]: + ns[var] = f'%{ns[var]}%' +{% endif %} {% if logined_userorgid or logined_userid %} # 确保 logined 过滤条件始终生效 if filterjson: