SpApilogMapper.xml 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.pj.project4sp.apilog.SpApilogMapper">
  4. <!-- 保存入库 -->
  5. <insert id="saveObj">
  6. insert into
  7. sp_apilog (
  8. id, req_ip, req_api, req_parame, req_type, req_token, req_header, user_id, admin_id, start_time,
  9. res_code, res_msg, res_string, end_time, cost_time)
  10. values (
  11. #{id}, #{reqIp}, #{reqApi}, #{reqParame}, #{reqType}, #{reqToken}, #{reqHeader}, #{userId}, #{adminId}, #{startTime},
  12. #{resCode}, #{resMsg}, #{resString}, #{endTime}, #{costTime})
  13. </insert>
  14. <!-- 增 -->
  15. <insert id="add">
  16. insert into
  17. sp_apilog (id, req_ip, req_api, req_parame, req_token, user_id, admin_id, start_time)
  18. values (#{id}, #{reqIp}, #{reqApi}, #{reqParame}, #{reqToken}, #{userId}, #{adminId}, now(3))
  19. </insert>
  20. <!-- 删 -->
  21. <delete id="delete">
  22. delete from sp_apilog
  23. where id = #{id}
  24. </delete>
  25. <!-- 删 -->
  26. <delete id="deleteByStartEnd">
  27. delete from sp_apilog
  28. where start_time BETWEEN #{startTime} AND #{endTime}
  29. </delete>
  30. <!-- 改 -->
  31. <update id="update">
  32. update sp_apilog set
  33. res_code = #{resCode},
  34. res_msg = #{resMsg},
  35. res_string = #{resString},
  36. end_time = now(3),
  37. cost_time = #{costTime}
  38. where id = #{id}
  39. </update>
  40. <!-- ================================== 查询相关 ================================== -->
  41. <!-- 通用映射 -->
  42. <resultMap id="model" type="com.pj.project4sp.apilog.SpApilog">
  43. <result property="id" column="id" />
  44. <result property="reqIp" column="req_ip" />
  45. <result property="reqApi" column="req_api" />
  46. <result property="reqParame" column="req_parame" />
  47. <result property="reqType" column="req_type" />
  48. <result property="reqToken" column="req_token" />
  49. <result property="reqHeader" column="req_header" />
  50. <result property="resCode" column="res_code" />
  51. <result property="resMsg" column="res_msg" />
  52. <result property="resString" column="res_string" />
  53. <result property="userId" column="user_id" />
  54. <result property="adminId" column="admin_id" />
  55. <result property="startTime" column="start_time" />
  56. <result property="endTime" column="end_time" />
  57. <result property="costTime" column="cost_time" />
  58. </resultMap>
  59. <!-- 公共查询sql片段 -->
  60. <sql id="select_sql">
  61. select * from sp_apilog
  62. </sql>
  63. <!-- 查询,根据条件(参数为null或0时默认忽略此条件) -->
  64. <select id="getList" resultMap="model" >
  65. <include refid="select_sql"></include>
  66. where 1 = 1
  67. <if test=' this.has("id") '>and id = #{id} </if>
  68. <if test=' this.has("reqToken") '>and req_token = #{reqToken} </if>
  69. <if test=' this.has("reqIp") '> and req_ip = #{reqIp} </if>
  70. <if test=' this.has("reqApi") '>and req_api = #{reqApi} </if>
  71. <if test=' this.has("resCode") '>and res_code = #{resCode} </if>
  72. <if test=' this.has("userId") '>and user_id = #{userId} </if>
  73. <if test=' this.has("adminId") '>and admin_id = #{adminId} </if>
  74. <if test=' this.has("sTime") '>and start_time &gt;= #{sTime} </if>
  75. <if test=' this.has("eTime") '>and start_time &lt;= #{eTime} </if>
  76. order by
  77. <choose>
  78. <when test='sortType == "id" '>id desc</when>
  79. <when test='sortType == "start_time" '>start_time desc, id desc</when>
  80. <when test='sortType == "cost_time" '>cost_time desc, id desc</when>
  81. <otherwise>id desc</otherwise>
  82. </choose>
  83. </select>
  84. <!-- 统计 -->
  85. <select id="staBy" resultType="somap">
  86. select sum(cost_time) as cost_time_count from sp_apilog
  87. where 1 = 1
  88. <if test=' this.has("id") '>and id = #{id} </if>
  89. <if test=' this.has("reqToken") '>and req_token = #{reqToken} </if>
  90. <if test=' this.has("reqIp") '> and req_ip = #{reqIp} </if>
  91. <if test=' this.has("reqApi") '>and req_api = #{reqApi} </if>
  92. <if test=' this.has("resCode") '>and res_code = #{resCode} </if>
  93. <if test=' this.has("userId") '>and user_id = #{userId} </if>
  94. <if test=' this.has("adminId") '>and admin_id = #{adminId} </if>
  95. <if test=' this.has("sTime") '>and start_time &gt;= #{sTime} </if>
  96. <if test=' this.has("eTime") '>and start_time &lt;= #{eTime} </if>
  97. </select>
  98. </mapper>