FastgptEventLogTotalMapper.xml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.fs.fastGpt.mapper.FastgptEventLogTotalMapper">
  6. <resultMap type="FastgptEventLogTotal" id="FastgptEventLogTotalResult">
  7. <result property="id" column="id" />
  8. <result property="roleId" column="role_id" />
  9. <result property="count" column="count" />
  10. <result property="type" column="type" />
  11. <result property="companyId" column="company_id" />
  12. <result property="companyUserId" column="company_user_id" />
  13. <result property="qwUserId" column="qw_user_id" />
  14. <result property="statTime" column="stat_time" />
  15. </resultMap>
  16. <sql id="selectFastgptEventLogTotalVo">
  17. select id, role_id, `count`, `type`, company_id, company_user_id, qw_user_id, stat_time from fastgpt_event_log_total
  18. </sql>
  19. <select id="selectFastgptEventLogTotalList" parameterType="FastgptEventLogTotal" resultMap="FastgptEventLogTotalResult">
  20. <include refid="selectFastgptEventLogTotalVo"/>
  21. <where>
  22. <if test="roleId != null "> and role_id = #{roleId}</if>
  23. <if test="count != null "> and `count` = #{count}</if>
  24. <if test="type != null "> and `type` = #{type}</if>
  25. <if test="companyId != null "> and company_id = #{companyId}</if>
  26. <if test="companyUserId != null "> and company_user_id = #{companyUserId}</if>
  27. <if test="qwUserId != null "> and qw_user_id = #{qwUserId}</if>
  28. <if test="beginTime != null and endTime != null"> <![CDATA[and DATE_FORMAT(create_time, '%Y-%m-%d') >= #{beginTime}
  29. and DATE_FORMAT(create_time, '%Y-%m-%d') <= #{endTime} ]]></if>
  30. </where>
  31. </select>
  32. <select id="selectFastgptEventLogTotalById" parameterType="Long" resultMap="FastgptEventLogTotalResult">
  33. <include refid="selectFastgptEventLogTotalVo"/>
  34. where id = #{id}
  35. </select>
  36. <select id="selectFastgptEventLogTotalInfoList" resultType="com.fs.fastGpt.domain.FastgptEventLogTotal">
  37. SELECT role_id roleId,company_id companyId,company_user_id companyUserId,qw_user_id qwUserId,event_name eventName,`type`,
  38. DATE_FORMAT(create_time,'%Y-%m-%d') as statTime,sum(count) count,count(distinct sender_id) senderCount from fastgpt_event_log
  39. <where>
  40. <if test="roleId != null "> and role_id = #{roleId}</if>
  41. <if test="roleId == null "> and role_id is not null</if>
  42. <if test="createTime != null "> and DATE_FORMAT(create_time,'%Y-%m-%d') = DATE_FORMAT(#{createTime},'%Y-%m-%d')</if>
  43. <if test="beginTime != null and endTime != null"> <![CDATA[and DATE_FORMAT(create_time,'%Y-%m-%d') > DATE_FORMAT(#{beginTime},'%Y-%m-%d')
  44. and DATE_FORMAT(create_time,'%Y-%m-%d') <= DATE_FORMAT(#{endTime},'%Y-%m-%d') ]]></if>
  45. <if test="companyId != null "> and company_id = #{companyId}</if>
  46. <if test="companyUserId == null "> and company_user_id is not null</if>
  47. <if test="companyUserId != null "> and company_user_id = #{companyUserId}</if>
  48. <if test="qwUserId == null "> and qw_user_id is not null</if>
  49. <if test="qwUserId != null "> and qw_user_id = #{qwUserId}</if>
  50. </where>
  51. group by role_id,company_id,company_user_id,qw_user_id,event_name,`type`,DATE_FORMAT(create_time,'%Y-%m-%d')
  52. order by `type`
  53. </select>
  54. <select id="selectFastgptEventLogTotalVoInfoList" resultType="com.fs.fastGpt.domain.FastgptEventLogTotal">
  55. SELECT
  56. role_id roleId,type,
  57. sum(count) AS count,stat_time statTime
  58. FROM fastgpt_event_log_total
  59. <where>
  60. <if test="roleId != null "> and role_id = #{roleId}</if>
  61. <if test="count != null "> and `count` = #{count}</if>
  62. <if test="type != null "> and `type` = #{type}</if>
  63. <if test="companyId != null "> and company_id = #{companyId}</if>
  64. <if test="companyUserId != null "> and company_user_id = #{companyUserId}</if>
  65. <if test="qwUserIds != null">
  66. and qw_user_id in
  67. <foreach collection="qwUserIds.split(',')" item="qwUserId" open="(" close=")" separator=",">
  68. #{qwUserId}
  69. </foreach>
  70. </if>
  71. <if test="roleIds != null">
  72. and role_id in
  73. <foreach collection="roleIds" item="roleId" open="(" close=")" separator=",">
  74. #{roleId}
  75. </foreach>
  76. </if>
  77. <if test="beginTime != null and endTime != null"> <![CDATA[and DATE_FORMAT(stat_time, '%Y-%m-%d') >= #{beginTime}
  78. and DATE_FORMAT(stat_time, '%Y-%m-%d') <= #{endTime} ]]></if>
  79. </where>
  80. GROUP BY role_id,stat_time,type WITH ROLLUP
  81. HAVING role_id is not null and type is not null
  82. </select>
  83. <select id="selectFastgptEventTokenLogTotalList" resultType="com.fs.fastGpt.domain.FastGptEventTokenLog">
  84. SELECT role_id roleId,company_id companyId,company_user_id companyUserId,qw_user_id qwUserId,
  85. DATE_FORMAT(create_time, '%Y-%m-%d') as statTime,sum(token_count) tokenCount from fastgpt_event_token_log
  86. where token_type = 0
  87. <if test="roleId != null "> and role_id = #{roleId}</if>
  88. <if test="roleId == null "> and role_id is not null</if>
  89. <if test="createTime != null "> and DATE_FORMAT(create_time, '%Y-%m-%d') = DATE_FORMAT(#{createTime})</if>
  90. <if test="beginTime != null and endTime != null"> <![CDATA[and DATE_FORMAT(create_time, '%Y-%m-%d') > DATE_FORMAT(#{beginTime}, '%Y-%m-%d')
  91. and DATE_FORMAT(create_time, '%Y-%m-%d') <= DATE_FORMAT(#{endTime}, '%Y-%m-%d') ]]></if>
  92. <if test="companyId != null "> and company_id = #{companyId}</if>
  93. <if test="companyUserId != null "> and company_user_id = #{companyUserId}</if>
  94. <if test="companyUserId == null "> and company_user_id is not null</if>
  95. <if test="qwUserId == null "> and qw_user_id is not null</if>
  96. <if test="qwUserId != null "> and qw_user_id = #{qwUserId}</if>
  97. group by role_id,company_id,company_user_id,qw_user_id,DATE_FORMAT(create_time, '%Y-%m-%d')
  98. </select>
  99. <select id="selectFastgptEventTokenLogTotalByRoleIdAndType" resultMap="FastgptEventLogTotalResult">
  100. <include refid="selectFastgptEventLogTotalVo"/>
  101. where `type` = 11
  102. <if test="roleId != null "> and role_id = #{roleId}</if>
  103. <if test="companyId != null "> and company_id = #{companyId}</if>
  104. <if test="companyUserId != null "> and company_user_id = #{companyUserId}</if>
  105. <if test="qwUserId != null "> and qw_user_id = #{qwUserId}</if>
  106. <if test="statTime != null "> and stat_time = #{statTime}</if>
  107. </select>
  108. <select id="selectFastgptEventLogTotalByRoleIdAndType" resultMap="FastgptEventLogTotalResult">
  109. <include refid="selectFastgptEventLogTotalVo"/>
  110. <where>
  111. <if test="roleId != null "> and role_id = #{roleId}</if>
  112. <if test="type != null "> and `type` = #{type}</if>
  113. <if test="companyId != null "> and company_id = #{companyId}</if>
  114. <if test="companyUserId != null "> and company_user_id = #{companyUserId}</if>
  115. <if test="qwUserId != null "> and qw_user_id = #{qwUserId}</if>
  116. <if test="statTime != null "> and stat_time = #{statTime}</if>
  117. </where>
  118. </select>
  119. <select id="selectFastgptEventLogTotalListByStatTime"
  120. resultType="com.fs.fastGpt.vo.FastgptEventLogTotalVo">
  121. SELECT fe.stat_time statTime,c.company_id companyId,c.company_name companyName,sum(`count`) `count`
  122. FROM `fastgpt_event_log_total` fe left join company c on fe.company_id = c.company_id
  123. where fe.stat_time like concat(#{dateTime},'%')
  124. GROUP BY fe.company_id
  125. order by fe.company_id
  126. </select>
  127. <insert id="insertFastgptEventLogTotal" parameterType="FastgptEventLogTotal" useGeneratedKeys="true" keyProperty="id">
  128. insert into fastgpt_event_log_total
  129. <trim prefix="(" suffix=")" suffixOverrides=",">
  130. <if test="roleId != null">role_id,</if>
  131. <if test="count != null">`count`,</if>
  132. <if test="type != null">`type`,</if>
  133. <if test="companyId != null">company_id,</if>
  134. <if test="companyUserId != null">company_user_id,</if>
  135. <if test="qwUserId != null">qw_user_id,</if>
  136. <if test="statTime != null">stat_time,</if>
  137. </trim>
  138. <trim prefix="values (" suffix=")" suffixOverrides=",">
  139. <if test="roleId != null">#{roleId},</if>
  140. <if test="count != null">#{count},</if>
  141. <if test="type != null">#{type},</if>
  142. <if test="companyId != null">#{companyId},</if>
  143. <if test="companyUserId != null">#{companyUserId},</if>
  144. <if test="qwUserId != null">#{qwUserId},</if>
  145. <if test="statTime != null">#{statTime},</if>
  146. </trim>
  147. </insert>
  148. <insert id="insertFastgptEventLogTotalBatch" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id">
  149. INSERT INTO fastgpt_event_log_total
  150. (role_id, `count`, `type`, company_id, company_user_id, qw_user_id, stat_time)
  151. VALUES
  152. <foreach collection="list" item="item" separator=",">
  153. (
  154. #{item.roleId},
  155. #{item.count},
  156. #{item.type},
  157. #{item.companyId},
  158. #{item.companyUserId},
  159. #{item.qwUserId},
  160. #{item.statTime}
  161. )
  162. </foreach>
  163. </insert>
  164. <update id="updateFastgptEventLogTotal" parameterType="FastgptEventLogTotal">
  165. update fastgpt_event_log_total
  166. <trim prefix="SET" suffixOverrides=",">
  167. <if test="roleId != null">role_id = #{roleId},</if>
  168. <if test="count != null">`count` = #{count},</if>
  169. <if test="type != null">`type` = #{type},</if>
  170. <if test="companyId != null">company_id = #{companyId},</if>
  171. <if test="companyUserId != null">company_user_id = #{companyUserId},</if>
  172. <if test="qwUserId != null">qw_user_id = #{qwUserId},</if>
  173. <if test="statTime != null">stat_time = #{statTime},</if>
  174. </trim>
  175. where id = #{id}
  176. </update>
  177. <update id="updateFastgptEventLogTotalBatch" parameterType="java.util.List">
  178. <foreach collection="list" item="item" separator=";">
  179. UPDATE fastgpt_event_log_total
  180. <set>
  181. <if test="item.roleId != null">role_id = #{item.roleId},</if>
  182. <if test="item.count != null">`count` = #{item.count},</if>
  183. <if test="item.type != null">`type` = #{item.type},</if>
  184. <if test="item.companyId != null">company_id = #{item.companyId},</if>
  185. <if test="item.companyUserId != null">company_user_id = #{item.companyUserId},</if>
  186. <if test="item.qwUserId != null">qw_user_id = #{item.qwUserId},</if>
  187. <if test="item.statTime != null">stat_time = #{item.statTime},</if>
  188. </set>
  189. WHERE id = #{item.id}
  190. </foreach>
  191. </update>
  192. <delete id="deleteFastgptEventLogTotalById" parameterType="Long">
  193. delete from fastgpt_event_log_total where id = #{id}
  194. </delete>
  195. <delete id="deleteFastgptEventLogTotalByIds" parameterType="String">
  196. delete from fastgpt_event_log_total where id in
  197. <foreach item="id" collection="array" open="(" separator="," close=")">
  198. #{id}
  199. </foreach>
  200. </delete>
  201. </mapper>