提交 910bf3ab 编写于 作者: zhouweidong's avatar zhouweidong

补充数据查询忽略空值配置

上级 04b7cd48
......@@ -175,14 +175,25 @@ TARGET=PSDATAENTITY
<#if singleQuery.getAllPSDEDataQueryCodes()??>
<#list singleQuery.getAllPSDEDataQueryCodes() as dedqcode>
<#assign dbtype=dedqcode.getDBType()?lower_case?replace("mysql5","mysql")>
<#assign hasIgnoreNullValueCond=checkIgnoreNullvalueCond(dedqcode)>
<!--数据查询[${singleQuery.getCodeName()}]-->
<sql id="${singleQuery.getCodeName()}" databaseId="${dbtype}">
<#comment>判断是否存在忽略空值条件</#comment>
<#if hasIgnoreNullValueCond>
<![CDATA[ ${contextParamConvert(srfjavasqlcode(dedqcode.getQueryCode()))} ]]>
<#if dedqcode.getPSDEDataQueryCodeConds()??>
<#list dedqcode.getPSDEDataQueryCodeConds() as dedqfieldcond>
<#if (dedqfieldcond_index==0)> WHERE </#if> <#if (dedqfieldcond_index>0)> AND </#if>${checkNullContextParamConvert(srfjavasqlcode(dedqfieldcond.getCustomCond()))}
</#list>
</#if>
<#else>
<![CDATA[ ${contextParamConvert(srfjavasqlcode(dedqcode.getQueryCode()))}
<#if dedqcode.getPSDEDataQueryCodeConds()??>
<#list dedqcode.getPSDEDataQueryCodeConds() as dedqfieldcond>
<#if (dedqfieldcond_index==0)> WHERE </#if> <#if (dedqfieldcond_index>0)> AND </#if>${contextParamConvert(srfjavasqlcode(dedqfieldcond.getCustomCond()))}
</#list>
</#if>]]>
</#if>
</sql>
</#list>
</#if>
......@@ -191,19 +202,16 @@ TARGET=PSDATAENTITY
</mapper>
</#if>
<#comment>上下文参数转换 原字符串:${srfdatacontext('field','{"defname":"PORGNAME","dename":"IBZORG"}')})</#comment>
<#comment>第一次替换:#{srf.datacontext.field','{"defname":"PORGNAME","dename":"IBZORG"}')})</#comment>
<#comment>第二次替换:#{srf.datacontext.field}</#comment>
<#comment>第三次替换: #{srf.datacontext.ORGID} --> #{srf.datacontext.orgid} </#comment>
<#comment>数据查询context条件转换</#comment>
<#function contextParamConvert contextParam>
<#comment>平台配置格式替换${srfdatacontext('cityid','{"defname":"CITYID","dename":"CITY"}')} --> #{srf.srfdatacontext.cityid} </#comment>
<#assign resultParam=contextParam?replace("\\$\\{srf(datacontext|sessioncontext|webcontext)\\('(\\w+)','(.*?)'\\)}","#\{srf.$1.$2}","r")>
<#comment>用户配置格式替换${srfdatacontext('cityid')} --> #{srf.srfdatacontext.cityid} </#comment>
<#assign resultParam=resultParam?replace("\\$\\{srf(datacontext|sessioncontext|webcontext)\\('(\\w+)'\\)}","#\{srf.$1.$2}","r")>
<#comment>将上下文参数转小写 #{srf.srfdatacontext.SRFORGID} --> #{srf.srfdatacontext.srforgid}</#comment>
<#assign params=resultParam?matches('#\\{srf.(\\w+).(\\w+)}')>
<#assign params=resultParam?matches('srf.(datacontext|sessioncontext|webcontext).(\\w+)')>
<#list params as param>
<#assign resultParam=resultParam?replace(param,param?lower_case)>
<#assign resultParam=resultParam?replace(param,param?lower_case,'i')>
</#list>
<#--<#assign resultParam="">-->
<#--<#assign resultParam=contextParam?replace('$\{srfdatacontext(\'','#\{srf.datacontext.')?replace("','\\{[\\S]*}'\\)}","\\}","r")><#comment>数据上下文</#comment>-->
......@@ -215,3 +223,26 @@ TARGET=PSDATAENTITY
<#--</#list>-->
<#return resultParam>
</#function>
<#comment>数据查询忽略空值条件转换</#comment>
<#function checkNullContextParamConvert contextParam>
<#comment>获取数据查询中的条件,并对条件进行转义 <![CDATA[ age <='20' ]]></#comment>
<#assign resultParam=contextParam?replace("(\\s+[\\w|\\.|\\`]+\\s*?)(<>|<=|<|>=|>)(\\s*[\\w|\\'|$\{}()'\",:\\\\]+\\s+?)"," <![CDATA[ $1$2$3 ]]> ","r")>
<#comment>获取模型中的空值条件,在条件外层补充mybatis判断条件 <choose><when test="srf.datacontext.name != null"> <![CDATA[ t1.`NAME` <= #{srf.datacontext.name} ]]> </when><otherwise>1=1</otherwise></choose> </#comment>
<#assign resultParam=resultParam?replace("<#assign _value=srf(datacontext|sessioncontext|webcontext)\\('(\\w+)','(.*?)'\\)><#if _value\\?length gt 0>(.*?)=(.*?)<#else>1=1</#if>","<choose><when test=\"srf.$1.$2 != null\"> <![CDATA[ $4= #\{srf.$1.$2} ]]> </when><otherwise>1=1</otherwise></choose>","r")>
<#comment>对数据查询中的其余条件的context进行解析</#comment>
<#assign resultParam=contextParamConvert(resultParam)>
<#return resultParam>
</#function>
<#comment>计算当前数据查询中是否包含空值忽略的条件</#comment>
<#function checkIgnoreNullvalueCond dataQueryCode>
<#if dataQueryCode.getPSDEDataQueryCodeConds()??>
<#list dataQueryCode.getPSDEDataQueryCodeConds() as dedqfieldcond>
<#if srfjavasqlcode(dedqfieldcond.getCustomCond())?matches("(.*?)srfdatacontext(.*?)\\\\\"ignoreempty\\\\\":true(.*?)")>
<#return true>
</#if>
</#list>
</#if>
<#return false>
</#function>
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册