<?xml version="1.0" encoding="UTF-8" ?>
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
<mapper namespace="com.terra.proxy.mapper.LogMapper">
|
|
<select id="querylog" parameterType="map"
|
resultType="map">
|
select t.*,p."SERVERNAME" from "VISITLOG" t left join "SERVERRG" p ON t."RESOURCEID"=p."RESOURCEID" where 1=1
|
<if test="ip!=null and ip!=''">
|
and t."REQUESTIP"=#{ip}
|
</if>
|
<if test="id!=null and id!=''">
|
and t."ID"=#{id}
|
</if>
|
<if test="result!=null and result!='' ">
|
and t."RESULT"=#{result}
|
</if>
|
<if test="servername!=null and servername!=''">
|
and p."SERVERNAME"=#{servername}
|
</if>
|
<if test="serverurl!=null and serverurl!='' ">
|
and t."SERVERURL"=#{serverurl}
|
</if>
|
<if test="fromsys!=null and fromsys!='' ">
|
and t."VISITFROMSYS"=#{fromsys}
|
</if>
|
<if test="starttime!=null and starttime!='' and endtime!=null and endtime!='' ">
|
and t."TIMESTAMP" BETWEEN #{starttime} AND #{endtime}
|
</if>
|
limit #{limit} offset #{offSet};
|
</select>
|
|
|
<select id="queryTotalLog" parameterType="map"
|
resultType="Integer">
|
select count(*) as count from "VISITLOG" t left join "SERVERRG" p ON t."RESOURCEID"=p."RESOURCEID" where 1=1
|
<if test="ip!=null and ip!=''">
|
and t."REQUESTIP"=#{ip}
|
</if>
|
<if test="id!=null and id!=''">
|
and t."ID"=#{id}
|
</if>
|
<if test="result!=null and result!='' ">
|
and t."RESULT"=#{result}
|
</if>
|
<if test="servername!=null and servername!=''">
|
and p."SERVERNAME"=#{servername}
|
</if>
|
<if test="serverurl!=null and serverurl!='' ">
|
and p."SERVERURL"=#{serverurl}
|
</if>
|
<if test="fromsys!=null and fromsys!='' ">
|
and t."VISITFROMSYS"=#{fromsys}
|
</if>
|
<if test="starttime!=null and starttime!='' and endtime!=null and endtime!='' ">and t."TIMESTAMP" BETWEEN
|
#{starttime} AND #{endtime}
|
</if>
|
</select>
|
|
<select id="querylogCountAndIp" parameterType="map"
|
resultType="map">
|
select count(*) as count,t."REQUESTIP" as requestip from "VISITLOG" t where 1=1
|
<if test="starttime!=null and starttime!='' and endtime!=null and endtime!='' ">and t."TIMESTAMP" BETWEEN
|
#{starttime} AND #{endtime}
|
</if>
|
group by t."REQUESTIP" ORDER BY count desc
|
</select>
|
|
|
<select id="getTotalCountPerHour" parameterType="map"
|
resultType="map">
|
select sum(s.count),caltime from ( select count(*) as count,t."REQUESTIP" as requestip,to_char(t."TIMESTAMP",'yyyy-mm-dd HH:00:00')as caltime from "VISITLOG" t where 1=1
|
group by t."REQUESTIP",caltime ORDER BY count desc) s where 1=1 GROUP BY s."caltime" order by s.caltime asc;
|
</select>
|
|
<select id="getVisitInfoPerHourByip" parameterType="map"
|
resultType="map">
|
select count(*) as count,t."REQUESTIP" as requestip ,to_char(t."TIMESTAMP",'yyyy-mm-dd HH:00:00')as caltime from "VISITLOG" t where 1=1
|
group by t."REQUESTIP",caltime ORDER BY caltime asc;
|
</select>
|
|
<insert id="savelog" parameterType="map">
|
INSERT INTO "VISITLOG"(
|
"REQUESTIP",
|
"SERVERURL",
|
"RESULT",
|
"RESOURCEID"
|
"VISITFROMSYS"
|
"TIMESTAMP")
|
values
|
(
|
#{requestip,jdbcType=VARCHAR},
|
#{serverurl,jdbcType=VARCHAR},
|
#{result,jdbcType=VARCHAR},
|
#{RESOURCEID,jdbcType=INTEGER},
|
#{visitfromsys,jdbcType=VARCHAR},
|
#{timestamp}
|
)
|
</insert>
|
|
|
<insert id="batchsavelog" parameterType="java.util.List">
|
INSERT INTO "VISITLOG"(
|
"REQUESTIP",
|
"SERVERURL",
|
"RESULT",
|
"TIMESTAMP",
|
"VISITFROMSYS",
|
"RESOURCEID"
|
)
|
values
|
<foreach collection="list" item="item" index="index" separator=",">
|
(
|
#{item.requestip,jdbcType=VARCHAR},
|
#{item.serverurl,jdbcType=VARCHAR},
|
#{item.result,jdbcType=VARCHAR},
|
#{item.timestamp},
|
#{item.visitfromsys},
|
#{item.resourceid}
|
)
|
</foreach>
|
</insert>
|
|
|
<insert id="batchsaveResRecord" parameterType="java.util.List">
|
INSERT INTO "RES_ACTION_RECORD"(
|
"RESOURCEID",
|
"USERID",
|
"APPID",
|
"ACTIONTIME",
|
"ACTIONTYPE",
|
"IP",
|
"REQUESTURL",
|
"TOKEN"
|
)
|
values
|
<foreach collection="list" item="item" index="index" separator=",">
|
(
|
#{item.resourceid},
|
#{item.userid},
|
#{item.appid},
|
#{item.actiontime},
|
'调用',
|
#{item.ip},
|
#{item.requesturl},
|
#{item.token}
|
)
|
</foreach>
|
</insert>
|
|
<insert id="saveResRecord" parameterType="com.terra.proxy.bean.ResActionRecord">
|
INSERT INTO "RES_ACTION_RECORD"(
|
"RESOURCEID",
|
"USERID",
|
"APPID",
|
"ACTIONTIME",
|
"ACTIONTYPE",
|
"IP",
|
"REQUESTURL",
|
"TOKEN"
|
)
|
values
|
(
|
#{resourceid},
|
#{userid},
|
#{appid},
|
#{actiontime},
|
'调用',
|
#{ip},
|
#{requesturl},
|
#{token}
|
)
|
|
</insert>
|
|
|
<insert id="saveTokenRecord" parameterType="com.terra.proxy.bean.TokenRecord">
|
INSERT INTO "TOKENRECORD"(
|
"TOKEN",
|
"APPLYTIME",
|
"IDENTYINFO",
|
"EXPIRATION",
|
"TOKENAPPLYER",
|
"TOKENINFO",
|
"RESOURCEID"
|
)
|
values
|
(
|
#{token},
|
#{applytime},
|
#{identyinfo},
|
#{expiration},
|
#{tokenapplyer},
|
#{tokeninfo},
|
#{resourceid}
|
)
|
|
</insert>
|
|
<select id="selectTokenRecord" parameterType="map" resultType="map">
|
SELECT t.*, p.*,
|
<![CDATA[(case (now()<t."APPLYTIME"+ (t."EXPIRATION"||' sec')::INTERVAL) when 't' then 0 else 1 end) as "TOKENSTATUS" ]]>
|
FROM "TOKENRECORD" t LEFT JOIN "SERVERRG" p on t."RESOURCEID"=p."RESOURCEID" WHERE 1=1
|
<if test="token!=null and token!=''">and t."TOKEN"=#{token}</if>
|
<if test="resourceId!=null">and t."RESOURCEID"=#{resourceId}</if>
|
<if test="identyinfo!=null and identyinfo!=''">and t."IDENTYINFO" like #{identyinfo}</if>
|
<if test="tokenstatus==1">
|
<![CDATA[ and now() > (t."APPLYTIME"+ (t."EXPIRATION"||' sec')::INTERVAL ) and 1=#{tokenstatus} ]]> </if>
|
<if test="tokenstatus==0">
|
<![CDATA[ and now() < (t."APPLYTIME"+ (t."EXPIRATION"||' sec')::INTERVAL ) and 0=#{tokenstatus} ]]> </if>
|
order by t."APPLYTIME" desc
|
<if test="limit!=null and limit!=''">
|
limit #{limit} offset #{page}
|
</if>
|
</select>
|
|
<select id="getTotalTokenRecord" parameterType="map" resultType="java.lang.Integer">
|
SELECT count(*) FROM "TOKENRECORD" t WHERE 1=1
|
<if test="token!=null and token!=''">and t."TOKEN"=#{token}</if>
|
<if test="identyinfo!=null and identyinfo!=''">and t."IDENTYINFO" like #{identyinfo}</if>
|
<if test="tokenstatus==1">
|
<![CDATA[ and now() > (t."APPLYTIME"+ (t."EXPIRATION"||' sec')::INTERVAL ) and 1=#{tokenstatus} ]]> </if>
|
<if test="tokenstatus==0">
|
<![CDATA[ and now() < (t."APPLYTIME"+ (t."EXPIRATION"||' sec')::INTERVAL ) and 0=#{tokenstatus} ]]> </if>
|
</select>
|
|
<update id="updateTokenRecord" parameterType="map">
|
update "TOKENRECORD"
|
<set>
|
<if test="expiration != null and expiration != '' ">
|
"EXPIRATION"=#{expiration},
|
</if>
|
<if test="applytime != null ">
|
"APPLYTIME"=#{applytime},
|
</if>
|
</set>
|
where "TOKEN"=#{token}
|
</update>
|
|
<select id="queryBlackLists" resultType="com.terra.proxy.bean.VistorBean">
|
select
|
V."REQUESTIP",
|
V."SERVERURL",
|
V."RESULT",
|
V."TIMESTAMP" AS date,
|
V."VISITFROMSYS",
|
V."RESOURCEID",
|
V."ID",
|
V."STATUS",
|
S."SERVERNAME" as serverName,
|
S."FROMSYS" AS fromSys
|
from "VISITLOG" V
|
left join "SERVERRG" S
|
ON V."SERVERURL"=S."SERVERURL"
|
and V."RESOURCEID"=S."RESOURCEID"
|
<where>
|
<if test="ip !=null and ip!='' "> and V."REQUESTIP"=#{ip} </if>
|
<if test="status ==null">and V."STATUS" IN ('1','2')</if>
|
<if test="status !=null ">and V."STATUS"=#{status}</if>
|
<if test="limit!=null and limit!=''">
|
limit #{limit} offset #{page}
|
</if>
|
</where>
|
</select>
|
|
|
<insert id="saveBlackLog" parameterType="com.terra.proxy.bean.VistorBean">
|
insert into "VISITLOG"
|
("REQUESTIP",
|
"SERVERURL",
|
"RESULT",
|
"TIMESTAMP",
|
"VISITFROMSYS",
|
"RESOURCEID",
|
"STATUS")
|
values
|
( #{requestip,jdbcType=VARCHAR},
|
#{serverurl,jdbcType=VARCHAR},
|
#{result,jdbcType=VARCHAR},
|
current_timeStamp,
|
#{visitfromsys},
|
#{resourceid},
|
'1')
|
</insert>
|
|
<update id="delBlackById" parameterType="com.terra.proxy.bean.VistorBean">
|
update "VISITLOG" set
|
"STATUS"=#{status}
|
<where>
|
<if test="requestip !=null and requestip!='' "> and "REQUESTIP"=#{requestip} </if>
|
<if test="id !=null"> and "ID"=#{id}</if>
|
</where>
|
</update>
|
|
<select id="selectBlackRule" resultType="com.terra.proxy.bean.BlackRule">
|
select * from "BLACKRULE"
|
order by "ID" desc limit 1
|
</select>
|
|
<update id="updateRules" parameterType="com.terra.proxy.bean.BlackRule">
|
update "BLACKRULE" SET
|
<if test="count != null and count != '' ">
|
"COUNT"=#{count},
|
</if>
|
<if test="time != null ">
|
"TIME"=#{time},
|
</if>
|
<if test="seltime != null ">
|
"SELTIME"=#{seltime}
|
</if>
|
</update>
|
|
<select id="getTotalBlackList" parameterType="map"
|
resultType="java.lang.Integer">
|
SELECT count(*) FROM "VISITLOG"
|
<where>
|
<if test="ip !=null and ip!='' ">"REQUESTIP"=#{ip} and</if>
|
<if test="status ==null ">"STATUS" IN ('1','2')</if>
|
<if test="status !=null">"STATUS"=#{status}</if>
|
</where>
|
</select>
|
|
<select id="queryWhite" parameterType="com.terra.proxy.bean.VistorBean" resultType="com.terra.proxy.bean.VistorBean">
|
select distinct * from "VISITLOG"
|
<where>
|
<if test="requestip !=null and requestip!='' "> and "REQUESTIP"=#{requestip} </if>
|
<if test="status !=null"> and "STATUS"=#{status}</if>
|
</where>
|
</select>
|
|
<select id="selectWhiteList" parameterType="map" resultType="com.terra.proxy.bean.VistorBean">
|
select
|
V."REQUESTIP",
|
V."SERVERURL",
|
V."RESULT",
|
V."TIMESTAMP" AS date,
|
V."VISITFROMSYS",
|
V."RESOURCEID",
|
V."ID",
|
V."STATUS"
|
from "VISITLOG" V
|
<where>
|
<if test="requestip !=null and requestip!='' "> and V."REQUESTIP"=#{requestip} </if>
|
<if test="status ==null"> and V."STATUS" IN ('3','4')</if>
|
<if test="status !=null "> and V."STATUS"=#{status}</if>
|
<if test="limit!=null and limit!=''">
|
limit #{limit} offset #{page}
|
</if>
|
</where>
|
</select>
|
|
<select id="getTotalWhiteList" parameterType="map" resultType="java.lang.Integer">
|
SELECT count(*) FROM "VISITLOG"
|
<where>
|
<if test="ip !=null and ip!='' ">and "REQUESTIP"=#{ip} </if>
|
<if test="status ==null ">and "STATUS" IN ('3','4')</if>
|
<if test="status !=null">and "STATUS"=#{status}</if>
|
</where>
|
</select>
|
|
<select id="queryToken" parameterType="map" resultType="java.lang.String">
|
<bind name="likeToken" value="userid+'%'"/>
|
select "TOKEN" from "TOKENRECORD"
|
where "RESOURCEID"=#{resourceid} and "TOKENINFO"
|
like #{likeToken}
|
order by "APPLYTIME" desc LIMIT 1
|
</select>
|
|
</mapper>
|