CommGatewayApiLogMapper.xml 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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.fs.comm.mapper.CommGatewayApiLogMapper">
  4. <resultMap id="CommGatewayApiLogResult" type="com.fs.comm.domain.CommGatewayApiLog">
  5. <result property="logId" column="log_id"/>
  6. <result property="tenantId" column="tenant_id"/>
  7. <result property="companyId" column="company_id"/>
  8. <result property="companyUserId" column="company_user_id"/>
  9. <result property="callerAccount" column="caller_account"/>
  10. <result property="apiType" column="api_type"/>
  11. <result property="apiPath" column="api_path"/>
  12. <result property="requestBody" column="request_body"/>
  13. <result property="responseBody" column="response_body"/>
  14. <result property="resultCode" column="result_code"/>
  15. <result property="resultMsg" column="result_msg"/>
  16. <result property="success" column="success"/>
  17. <result property="limitHit" column="limit_hit"/>
  18. <result property="limitReason" column="limit_reason"/>
  19. <result property="calleePhone" column="callee_phone"/>
  20. <result property="callerPhone" column="caller_phone"/>
  21. <result property="gatewayId" column="gateway_id"/>
  22. <result property="billingAmount" column="billing_amount"/>
  23. <result property="costPrice" column="cost_price"/>
  24. <result property="calcPrice" column="calc_price"/>
  25. <result property="billingQuantity" column="billing_quantity"/>
  26. <result property="billingUnit" column="billing_unit"/>
  27. <result property="clientIp" column="client_ip"/>
  28. <result property="authScope" column="auth_scope"/>
  29. <result property="durationMs" column="duration_ms"/>
  30. <result property="createTime" column="create_time"/>
  31. <result property="companyName" column="company_name"/>
  32. </resultMap>
  33. <sql id="selectCommGatewayApiLogVo">
  34. select l.log_id, l.tenant_id, l.company_id, l.company_user_id, l.caller_account,
  35. l.api_type, l.api_path, l.request_body, l.response_body, l.result_code, l.result_msg,
  36. l.success, l.limit_hit, l.limit_reason, l.callee_phone, l.caller_phone, l.gateway_id,
  37. l.billing_amount, l.cost_price, l.calc_price, l.billing_quantity, l.billing_unit,
  38. l.client_ip, l.auth_scope, l.duration_ms, l.create_time,
  39. c.company_name
  40. from comm_gateway_api_log l
  41. left join company c on c.company_id = l.company_id
  42. </sql>
  43. <select id="selectCommGatewayApiLogList" resultMap="CommGatewayApiLogResult">
  44. <include refid="selectCommGatewayApiLogVo"/>
  45. <where>
  46. <if test="tenantId != null">and l.tenant_id = #{tenantId}</if>
  47. <if test="companyId != null">and l.company_id = #{companyId}</if>
  48. <if test="apiType != null and apiType != ''">and l.api_type = #{apiType}</if>
  49. <if test="success != null">and l.success = #{success}</if>
  50. <if test="limitHit != null">and l.limit_hit = #{limitHit}</if>
  51. <if test="calleePhone != null and calleePhone != ''">and l.callee_phone like concat('%', #{calleePhone}, '%')</if>
  52. <if test="callerAccount != null and callerAccount != ''">and l.caller_account like concat('%', #{callerAccount}, '%')</if>
  53. <if test="params.beginTime != null and params.beginTime != ''">
  54. and l.create_time &gt;= #{params.beginTime}
  55. </if>
  56. <if test="params.endTime != null and params.endTime != ''">
  57. and l.create_time &lt;= #{params.endTime}
  58. </if>
  59. </where>
  60. order by l.log_id desc
  61. </select>
  62. <select id="selectCommGatewayApiLogById" resultMap="CommGatewayApiLogResult">
  63. <include refid="selectCommGatewayApiLogVo"/>
  64. where l.log_id = #{logId}
  65. </select>
  66. <insert id="insertCommGatewayApiLog" useGeneratedKeys="true" keyProperty="logId">
  67. insert into comm_gateway_api_log
  68. (tenant_id, company_id, company_user_id, caller_account, api_type, api_path,
  69. request_body, response_body, result_code, result_msg, success, limit_hit, limit_reason,
  70. callee_phone, caller_phone, gateway_id, billing_amount, cost_price, calc_price, billing_quantity,
  71. billing_unit, client_ip, auth_scope, duration_ms, create_time)
  72. values
  73. (#{tenantId}, #{companyId}, #{companyUserId}, #{callerAccount}, #{apiType}, #{apiPath},
  74. #{requestBody}, #{responseBody}, #{resultCode}, #{resultMsg}, #{success}, #{limitHit}, #{limitReason},
  75. #{calleePhone}, #{callerPhone}, #{gatewayId}, #{billingAmount}, #{costPrice}, #{calcPrice}, #{billingQuantity},
  76. #{billingUnit}, #{clientIp}, #{authScope}, #{durationMs}, #{createTime})
  77. </insert>
  78. <select id="countByCalleePhone" resultType="java.lang.Integer">
  79. select count(1) from comm_gateway_api_log
  80. where company_id = #{companyId}
  81. and callee_phone = #{calleePhone}
  82. and limit_hit = 0
  83. <if test="type != null and type == 1">and timestampdiff(MINUTE, create_time, now()) &lt; 1</if>
  84. <if test="type != null and type == 2">and timestampdiff(HOUR, create_time, now()) &lt; 1</if>
  85. <if test="type != null and type == 3">and timestampdiff(DAY, create_time, now()) &lt; 1</if>
  86. <if test="type != null and type == 4">and timestampdiff(WEEK, create_time, now()) &lt; 1</if>
  87. <if test="type != null and type == 5">and timestampdiff(MONTH, create_time, now()) &lt; 1</if>
  88. </select>
  89. <select id="countByCallerPhone" resultType="java.lang.Integer">
  90. select count(1) from comm_gateway_api_log
  91. where company_id = #{companyId}
  92. and caller_phone = #{callerPhone}
  93. and limit_hit = 0
  94. <if test="type != null and type == 1">and timestampdiff(MINUTE, create_time, now()) &lt; 1</if>
  95. <if test="type != null and type == 2">and timestampdiff(HOUR, create_time, now()) &lt; 1</if>
  96. <if test="type != null and type == 3">and timestampdiff(DAY, create_time, now()) &lt; 1</if>
  97. <if test="type != null and type == 4">and timestampdiff(WEEK, create_time, now()) &lt; 1</if>
  98. <if test="type != null and type == 5">and timestampdiff(MONTH, create_time, now()) &lt; 1</if>
  99. </select>
  100. <select id="countByCompanyCall" resultType="java.lang.Integer">
  101. select count(1) from comm_gateway_api_log
  102. where company_id = #{companyId}
  103. and api_type = #{apiType}
  104. and limit_hit = 0
  105. <if test="type != null and type == 1">and timestampdiff(MINUTE, create_time, now()) &lt; 1</if>
  106. <if test="type != null and type == 2">and timestampdiff(HOUR, create_time, now()) &lt; 1</if>
  107. <if test="type != null and type == 3">and timestampdiff(DAY, create_time, now()) &lt; 1</if>
  108. <if test="type != null and type == 4">and timestampdiff(WEEK, create_time, now()) &lt; 1</if>
  109. <if test="type != null and type == 5">and timestampdiff(MONTH, create_time, now()) &lt; 1</if>
  110. </select>
  111. </mapper>