分页调整获取where条件,针对时间类型以及包含空格的搜索条件做了调整,加入了alias一列用来当作表的别名

This commit is contained in:
wangxin
2018-03-09 20:59:13 +08:00
parent f1114d209f
commit fd6425772c
6 changed files with 585 additions and 153 deletions

View File

@@ -61,7 +61,7 @@ public class IpCfgController extends BaseController{
if(!StringUtils.isBlank(tableName)){
logger.info("table name is "+tableName);
ipCfg.setTableName(tableName);
Page<BaseIpCfg> page = ipCfgService.findPage(new Page<BaseIpCfg>(request,response), ipCfg);
Page<BaseIpCfg> page = ipCfgService.findPage(new Page<BaseIpCfg>(request,response,"r"), ipCfg);
model.addAttribute("page", page);
model.addAttribute("action", ipCfg.getAction());
model.addAttribute("tableName", tableName);

View File

@@ -92,13 +92,33 @@
SERVICE_ID,REQUEST_ID,COMPILE_ID,IS_AREA_EFFECTIVE,CLASSIFY,
ATTRIBUTE,LABLE,AREA_EFFECTIVE_IDS
</sql>
<sql id="BaseIpCfg_Column_List_with_id_alias" >
<!-- <sql id="BaseIpCfg_Column_List_with_id_alias" >
r.CFG_ID as cfgId, r.CFG_DESC as cfgDesc, r.IP_TYPE as ipType, r.SRC_IP as srcIp, r.SRC_IP_MASK as srcIpMask, r.SRC_PORT as srcPort,
r.SRC_PORT_MASK as srcPortMask ,r.DST_IP as dstIp,r.DST_IP_MASK as dstIpMask, r.DST_PORT as dstPort, r.DST_PORT_MASK as dstPortMask,
r.DIRECTION as direction,r.PROTOCOL as protocol,r.PROTOCOL_ID as protocolId,r.ACTION as action,r.IS_VALID as isValid,r.IS_AUDIT as isAudit,
r.CREATOR_ID as creatorId,r.CREATE_TIME AS createTime,r.EDITOR_ID as editorId,r.EDIT_TIME AS editTime,r.AUDITOR_ID as auditorId,r.AUDIT_TIME AS auditTime,
r.SERVICE_ID as serviceId,r.REQUEST_ID AS requestId,r.COMPILE_ID AS compileId,r.IS_AREA_EFFECTIVE as isAreaEffective,r.classify,
r.ATTRIBUTE AS attribute,r.LABLE AS lable,r.AREA_EFFECTIVE_IDS AS areaEffectiveIds
</sql> -->
<sql id="BaseIpCfg_Column_List_with_id_alias" >
<choose>
<when test="page !=null and page.alias != null and page.alias != ''">
${page.alias}.CFG_ID as cfgId, ${page.alias}.CFG_DESC as cfgDesc, ${page.alias}.IP_TYPE as ipType, ${page.alias}.SRC_IP as srcIp, ${page.alias}.SRC_IP_MASK as srcIpMask, ${page.alias}.SRC_PORT as srcPort,
${page.alias}.SRC_PORT_MASK as srcPortMask ,${page.alias}.DST_IP as dstIp,${page.alias}.DST_IP_MASK as dstIpMask, ${page.alias}.DST_PORT as dstPort, ${page.alias}.DST_PORT_MASK as dstPortMask,
${page.alias}.DIRECTION as direction,${page.alias}.PROTOCOL as protocol,${page.alias}.PROTOCOL_ID as protocolId,${page.alias}.ACTION as action,${page.alias}.IS_VALID as isValid,${page.alias}.IS_AUDIT as isAudit,
${page.alias}.CREATOR_ID as creatorId,${page.alias}.CREATE_TIME AS createTime,${page.alias}.EDITOR_ID as editorId,${page.alias}.EDIT_TIME AS editTime,${page.alias}.AUDITOR_ID as auditorId,${page.alias}.AUDIT_TIME AS auditTime,
${page.alias}.SERVICE_ID as serviceId,${page.alias}.REQUEST_ID AS requestId,${page.alias}.COMPILE_ID AS compileId,${page.alias}.IS_AREA_EFFECTIVE as isAreaEffective,${page.alias}.classify,
${page.alias}.ATTRIBUTE AS attribute,${page.alias}.LABLE AS lable,${page.alias}.AREA_EFFECTIVE_IDS AS areaEffectiveIds
</when>
<otherwise>
r.CFG_ID as cfgId, r.CFG_DESC as cfgDesc, r.IP_TYPE as ipType, r.SRC_IP as srcIp, r.SRC_IP_MASK as srcIpMask, r.SRC_PORT as srcPort,
r.SRC_PORT_MASK as srcPortMask ,r.DST_IP as dstIp,r.DST_IP_MASK as dstIpMask, r.DST_PORT as dstPort, r.DST_PORT_MASK as dstPortMask,
r.DIRECTION as direction,r.PROTOCOL as protocol,r.PROTOCOL_ID as protocolId,r.ACTION as action,r.IS_VALID as isValid,r.IS_AUDIT as isAudit,
r.CREATOR_ID as creatorId,r.CREATE_TIME AS createTime,r.EDITOR_ID as editorId,r.EDIT_TIME AS editTime,r.AUDITOR_ID as auditorId,r.AUDIT_TIME AS auditTime,
r.SERVICE_ID as serviceId,r.REQUEST_ID AS requestId,r.COMPILE_ID AS compileId,r.IS_AREA_EFFECTIVE as isAreaEffective,r.classify,
r.ATTRIBUTE AS attribute,r.LABLE AS lable,r.AREA_EFFECTIVE_IDS AS areaEffectiveIds
</otherwise>
</choose>
</sql>
<sql id="BaseIpCfg_Column_List" >
CFG_DESC, IP_TYPE, SRC_IP, SRC_IP_MASK, SRC_PORT,
@@ -241,7 +261,13 @@
, s.name as creator_name,e.name as editor_name,u.name as auditor_name
,ri.request_title as requestName
</trim>
from ${tableName} r
from ${tableName}
<choose>
<when test="page !=null and page.alias != null and page.alias != ''">
${page.alias}
</when>
<otherwise> r</otherwise>
</choose>
left join sys_user s on r.creator_id=s.id
left join sys_user e on r.editor_id=e.id
left join sys_user u on r.auditor_id=u.id
@@ -254,109 +280,212 @@
<if test="page !=null and page.where != null and page.where != ''">
AND ${page.where}
</if>
<if test="cfgId != null">
AND r.CFG_ID=#{cfgId,jdbcType=BIGINT}
</if>
<if test="cfgDesc != null">
AND r.CFG_DESC like concat(concat('%',#{cfgDesc,jdbcType=VARCHAR}),'%')
</if>
<if test="ipType != null">
AND r.IP_TYPE=#{ipType,jdbcType=INTEGER}
</if>
<if test="srcIp != null">
AND r.SRC_IP=#{srcIp,jdbcType=VARCHAR}
</if>
<if test="srcIpMask != null">
AND r.SRC_IP_MASK=#{srcIpMask,jdbcType=VARCHAR}
</if>
<if test="srcPort != null">
AND r.SRC_PORT=#{srcPort,jdbcType=VARCHAR}
</if>
<if test="srcPortMask != null">
AND r.SRC_PORT_MASK=#{srcPortMask,jdbcType=VARCHAR}
</if>
<if test="dstIp != null">
AND r.DST_IP=#{dstIp,jdbcType=VARCHAR}
</if>
<if test="dstIpMask != null">
AND r.DST_IP_MASK=#{dstIpMask,jdbcType=VARCHAR}
</if>
<if test="dstPort != null">
AND r.DST_PORT=#{dstPort,jdbcType=VARCHAR}
</if>
<if test="dstPortMask != null">
AND r.DST_PORT_MASK=#{dstPortMask,jdbcType=VARCHAR}
</if>
<if test="direction != null">
AND r.DIRECTION=#{direction,jdbcType=INTEGER}
</if>
<if test="protocol != null">
AND r.PROTOCOL=#{protocol,jdbcType=INTEGER}
</if>
<if test="protocolId != null">
AND r.PROTOCOL_ID=#{protocolId,jdbcType=INTEGER}
</if>
<if test="action != null">
AND r.ACTION=#{action,jdbcType=INTEGER}
</if>
<if test="isValid != null">
AND r.IS_VALID=#{isValid,jdbcType=INTEGER}
</if>
<if test="isValid == null">
AND r.IS_VALID != -1
</if>
<if test="isAudit != null">
AND r.IS_AUDIT=#{isAudit,jdbcType=INTEGER}
</if>
<if test="creatorName != null">
AND CREATOR_NAME like concat(concat('%',#{creatorName,jdbcType=VARCHAR}),'%')
</if>
<if test="createTime != null">
AND r.CREATE_TIME=#{createTime,jdbcType=TIMESTAMP}
</if>
<if test="editorName != null">
AND EDITOR_NAME like concat(concat('%',#{editorName,jdbcType=VARCHAR}),'%')
</if>
<if test="editTime != null">
AND r.EDIT_TIME=#{editTime,jdbcType=TIMESTAMP}
</if>
<if test="auditorName != null">
AND AUDITOR_NAME like concat(concat('%',#{auditorName,jdbcType=VARCHAR}),'%')
</if>
<if test="auditTime != null">
AND r.AUDIT_TIME=#{auditTime,jdbcType=TIMESTAMP}
</if>
<if test="serviceId != null">
AND r.SERVICE_ID=#{serviceId,jdbcType=INTEGER}
</if>
<if test="requestId != null">
AND r.REQUEST_ID=#{requestId,jdbcType=INTEGER}
</if>
<if test="compileId != null">
AND r.COMPILE_ID=#{compileId,jdbcType=INTEGER}
</if>
<if test="isAreaEffective != null">
AND r.IS_AREA_EFFECTIVE=#{isAreaEffective,jdbcType=INTEGER}
</if>
<if test="classify != null">
AND r.classify like concat(concat('%',#{classify,jdbcType=VARCHAR}),'%')
</if>
<if test="attribute != null">
AND r.attribute like concat(concat('%',#{attribute,jdbcType=VARCHAR}),'%')
</if>
<if test="lable != null">
AND r.lable like concat(concat('%',#{lable,jdbcType=VARCHAR}),'%')
</if>
<if test="areaEffectiveIds != null">
AND r.AREA_EFFECTIVE_IDS like concat(concat('%',#{areaEffectiveIds,jdbcType=VARCHAR}),'%')
</if>
<choose>
<when test="page !=null and page.alias != null and page.alias != ''">
<if test="cfgId != null and cfgId != ''">
AND ${page.alias}.CFG_ID=#{cfgId,jdbcType=BIGINT}
</if>
<if test="cfgDesc != null and cfgDesc != ''">
AND ${page.alias}.CFG_DESC like concat(concat('%',#{cfgDesc,jdbcType=VARCHAR}),'%')
</if>
<if test="ipType != null and ipType != ''">
AND ${page.alias}.IP_TYPE=#{ipType,jdbcType=INTEGER}
</if>
<if test="srcIp != null and srcIp != ''">
AND ${page.alias}.SRC_IP=#{srcIp,jdbcType=VARCHAR}
</if>
<if test="srcIpMask != null and srcIpMask != ''">
AND ${page.alias}.SRC_IP_MASK=#{srcIpMask,jdbcType=VARCHAR}
</if>
<if test="srcPort != null and srcPort !=''">
AND ${page.alias}.SRC_PORT=#{srcPort,jdbcType=VARCHAR}
</if>
<if test="srcPortMask != null and srcPortMask !=''">
AND ${page.alias}.SRC_PORT_MASK=#{srcPortMask,jdbcType=VARCHAR}
</if>
<if test="dstIp != null and dstIp !=''">
AND ${page.alias}.DST_IP=#{dstIp,jdbcType=VARCHAR}
</if>
<if test="dstIpMask != null and dstIpMask !=''">
AND ${page.alias}.DST_IP_MASK=#{dstIpMask,jdbcType=VARCHAR}
</if>
<if test="dstPort != null and dstPort !=''">
AND ${page.alias}.DST_PORT=#{dstPort,jdbcType=VARCHAR}
</if>
<if test="dstPortMask != null and dstPortMask !=''">
AND ${page.alias}.DST_PORT_MASK=#{dstPortMask,jdbcType=VARCHAR}
</if>
<if test="direction != null and direction!= ''">
AND ${page.alias}.DIRECTION=#{direction,jdbcType=INTEGER}
</if>
<if test="protocol != null and protocol!=''">
AND ${page.alias}.PROTOCOL=#{protocol,jdbcType=INTEGER}
</if>
<if test="protocolId != null and protocolId !=''">
AND ${page.alias}.PROTOCOL_ID=#{protocolId,jdbcType=INTEGER}
</if>
<if test="action != null and action !=''">
AND ${page.alias}.ACTION=#{action,jdbcType=INTEGER}
</if>
<if test="isValid != null and isValid !=''">
AND ${page.alias}.IS_VALID=#{isValid,jdbcType=INTEGER}
</if>
<if test="isValid == null and isValid !=''">
AND ${page.alias}.IS_VALID != -1
</if>
<if test="isAudit != null and isAudit !=''">
AND ${page.alias}.IS_AUDIT=#{isAudit,jdbcType=INTEGER}
</if>
<if test="creatorName != null and creatorName !=''">
AND CREATOR_NAME like concat(concat('%',#{creatorName,jdbcType=VARCHAR}),'%')
</if>
<if test="createTime != null and createTime !=''">
AND ${page.alias}.CREATE_TIME=#{createTime,jdbcType=TIMESTAMP}
</if>
<if test="editorName != null and editorName !=''">
AND EDITOR_NAME like concat(concat('%',#{editorName,jdbcType=VARCHAR}),'%')
</if>
<if test="editTime != null and editTime !='' ">
AND ${page.alias}.EDIT_TIME=#{editTime,jdbcType=TIMESTAMP}
</if>
<if test="auditorName != null and auditorName !=''">
AND AUDITOR_NAME like concat(concat('%',#{auditorName,jdbcType=VARCHAR}),'%')
</if>
<if test="auditTime != null and auditTime !=''">
AND ${page.alias}.AUDIT_TIME=#{auditTime,jdbcType=TIMESTAMP}
</if>
<if test="serviceId != null and serviceId !=''">
AND ${page.alias}.SERVICE_ID=#{serviceId,jdbcType=INTEGER}
</if>
<if test="requestId != null and requestId !=''">
AND ${page.alias}.REQUEST_ID=#{requestId,jdbcType=INTEGER}
</if>
<if test="compileId != null and compileId !=''">
AND ${page.alias}.COMPILE_ID=#{compileId,jdbcType=INTEGER}
</if>
<if test="isAreaEffective != null and isAreaEffective !=''">
AND ${page.alias}.IS_AREA_EFFECTIVE=#{isAreaEffective,jdbcType=INTEGER}
</if>
<if test="classify != null and classify !=''">
AND ${page.alias}.classify like concat(concat('%',#{classify,jdbcType=VARCHAR}),'%')
</if>
<if test="attribute != null and attribute !=''">
AND ${page.alias}.attribute like concat(concat('%',#{attribute,jdbcType=VARCHAR}),'%')
</if>
<if test="lable != null and lable !=''">
AND ${page.alias}.lable like concat(concat('%',#{lable,jdbcType=VARCHAR}),'%')
</if>
<if test="areaEffectiveIds != null and areaEffectiveIds !=''">
AND ${page.alias}.AREA_EFFECTIVE_IDS like concat(concat('%',#{areaEffectiveIds,jdbcType=VARCHAR}),'%')
</if>
</when>
<otherwise>
<if test="cfgId != null and cfgId != ''">
AND r.CFG_ID=#{cfgId,jdbcType=BIGINT}
</if>
<if test="cfgDesc != null and cfgDesc != ''">
AND r.CFG_DESC like concat(concat('%',#{cfgDesc,jdbcType=VARCHAR}),'%')
</if>
<if test="ipType != null and ipType != ''">
AND r.IP_TYPE=#{ipType,jdbcType=INTEGER}
</if>
<if test="srcIp != null and srcIp != ''">
AND r.SRC_IP=#{srcIp,jdbcType=VARCHAR}
</if>
<if test="srcIpMask != null and srcIpMask != ''">
AND r.SRC_IP_MASK=#{srcIpMask,jdbcType=VARCHAR}
</if>
<if test="srcPort != null and srcPort !=''">
AND r.SRC_PORT=#{srcPort,jdbcType=VARCHAR}
</if>
<if test="srcPortMask != null and srcPortMask !=''">
AND r.SRC_PORT_MASK=#{srcPortMask,jdbcType=VARCHAR}
</if>
<if test="dstIp != null and dstIp !=''">
AND r.DST_IP=#{dstIp,jdbcType=VARCHAR}
</if>
<if test="dstIpMask != null and dstIpMask !=''">
AND r.DST_IP_MASK=#{dstIpMask,jdbcType=VARCHAR}
</if>
<if test="dstPort != null and dstPort !=''">
AND r.DST_PORT=#{dstPort,jdbcType=VARCHAR}
</if>
<if test="dstPortMask != null and dstPortMask !=''">
AND r.DST_PORT_MASK=#{dstPortMask,jdbcType=VARCHAR}
</if>
<if test="direction != null and direction!= ''">
AND r.DIRECTION=#{direction,jdbcType=INTEGER}
</if>
<if test="protocol != null and protocol!=''">
AND r.PROTOCOL=#{protocol,jdbcType=INTEGER}
</if>
<if test="protocolId != null and protocolId !=''">
AND r.PROTOCOL_ID=#{protocolId,jdbcType=INTEGER}
</if>
<if test="action != null and action !=''">
AND r.ACTION=#{action,jdbcType=INTEGER}
</if>
<if test="isValid != null and isValid !=''">
AND r.IS_VALID=#{isValid,jdbcType=INTEGER}
</if>
<if test="isValid == null and isValid !=''">
AND r.IS_VALID != -1
</if>
<if test="isAudit != null and isAudit !=''">
AND r.IS_AUDIT=#{isAudit,jdbcType=INTEGER}
</if>
<if test="creatorName != null and creatorName !=''">
AND CREATOR_NAME like concat(concat('%',#{creatorName,jdbcType=VARCHAR}),'%')
</if>
<if test="createTime != null and createTime !=''">
AND r.CREATE_TIME=#{createTime,jdbcType=TIMESTAMP}
</if>
<if test="editorName != null and editorName !=''">
AND EDITOR_NAME like concat(concat('%',#{editorName,jdbcType=VARCHAR}),'%')
</if>
<if test="editTime != null and editTime !='' ">
AND r.EDIT_TIME=#{editTime,jdbcType=TIMESTAMP}
</if>
<if test="auditorName != null and auditorName !=''">
AND AUDITOR_NAME like concat(concat('%',#{auditorName,jdbcType=VARCHAR}),'%')
</if>
<if test="auditTime != null and auditTime !=''">
AND r.AUDIT_TIME=#{auditTime,jdbcType=TIMESTAMP}
</if>
<if test="serviceId != null and serviceId !=''">
AND r.SERVICE_ID=#{serviceId,jdbcType=INTEGER}
</if>
<if test="requestId != null and requestId !=''">
AND r.REQUEST_ID=#{requestId,jdbcType=INTEGER}
</if>
<if test="compileId != null and compileId !=''">
AND r.COMPILE_ID=#{compileId,jdbcType=INTEGER}
</if>
<if test="isAreaEffective != null and isAreaEffective !=''">
AND r.IS_AREA_EFFECTIVE=#{isAreaEffective,jdbcType=INTEGER}
</if>
<if test="classify != null and classify !=''">
AND r.classify like concat(concat('%',#{classify,jdbcType=VARCHAR}),'%')
</if>
<if test="attribute != null and attribute !=''">
AND r.attribute like concat(concat('%',#{attribute,jdbcType=VARCHAR}),'%')
</if>
<if test="lable != null and lable !=''">
AND r.lable like concat(concat('%',#{lable,jdbcType=VARCHAR}),'%')
</if>
<if test="areaEffectiveIds != null and areaEffectiveIds !=''">
AND r.AREA_EFFECTIVE_IDS like concat(concat('%',#{areaEffectiveIds,jdbcType=VARCHAR}),'%')
</if>
</otherwise>
</choose>
</trim>
<choose>
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
ORDER BY ${page.orderBy}
</when>
<otherwise>
ORDER BY CFG_ID desc
ORDER BY r.CFG_ID desc
</otherwise>
</choose>
</select>