AiChatMapper.xml 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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.backendsys.mapper.Ai.AiChatMapper">
  4. <sql id="includeAiChat">
  5. id id,
  6. id chat_id,
  7. history_code,
  8. user_id,
  9. COALESCE(user_nickname, '') user_nickname,
  10. COALESCE(user_avatar, '') user_avatar,
  11. COALESCE(robot_code, '') robot_code,
  12. role,
  13. content,
  14. create_time,
  15. update_time
  16. </sql>
  17. <resultMap id="resultMapAiChat" type="java.util.LinkedHashMap">
  18. <id property="id" column="id" jdbcType="BIGINT" />
  19. <result property="chat_id" column="chat_id" javaType="java.lang.Long"/>
  20. <result property="history_code" column="history_code" />
  21. <result property="user_id" column="user_id" javaType="java.lang.Long"/>
  22. <result property="user_nickname" column="user_nickname" />
  23. <result property="user_avatar" column="user_avatar" />
  24. <result property="robot_code" column="robot_code" />
  25. <result property="role" column="role" />
  26. <result property="content" column="content" />
  27. <result property="create_time" column="create_time" />
  28. <result property="update_time" column="update_time" />
  29. </resultMap>
  30. <select id="queryAiChatList" resultMap="resultMapAiChat">
  31. SELECT
  32. <include refid="includeAiChat" />
  33. FROM ai_chat
  34. <where>
  35. <if test="history_code != null and history_code != ''">
  36. AND history_code = #{history_code}
  37. </if>
  38. <if test="user_id != null and user_id != ''">
  39. AND user_id = #{user_id}
  40. </if>
  41. <if test="robot_code != null and robot_code != ''">
  42. AND robot_code = #{robot_code}
  43. </if>
  44. <if test="role != null and role != ''">
  45. AND role = #{role}
  46. </if>
  47. </where>
  48. ORDER BY update_time ASC
  49. </select>
  50. <insert id="insertAiChat" parameterType="com.backendsys.entity.Ai.AiChatDTO">
  51. INSERT INTO ai_chat (history_code, content
  52. <if test="user_id != null and user_id != ''">, user_id</if>
  53. <if test="user_nickname != null and user_nickname != ''">, user_nickname</if>
  54. <if test="user_avatar != null and user_avatar != ''">, user_avatar</if>
  55. <if test="robot_code != null and robot_code != ''">, robot_code</if>
  56. <if test="role != null and role != ''">, role</if>
  57. )
  58. VALUES (#{history_code}, #{content}
  59. <if test="user_id != null and user_id != ''">, #{user_id}</if>
  60. <if test="user_nickname != null and user_nickname != ''">, #{user_nickname}</if>
  61. <if test="user_avatar != null and user_avatar != ''">, #{user_avatar}</if>
  62. <if test="robot_code != null and robot_code != ''">, #{robot_code}</if>
  63. <if test="role != null and role != ''">, #{role}</if>
  64. )
  65. </insert>
  66. <!-- <update id="updateAiChat" parameterType="com.backendsys.entity.Ai.AiChatDTO"
  67. useGeneratedKeys="true" keyProperty="history_code">
  68. UPDATE ai_chat
  69. SET content = #{content}
  70. <if test="user_nickname != null and user_nickname != ''">, user_nickname = #{user_nickname}</if>
  71. <if test="user_avatar != null and user_avatar != ''">, user_avatar = #{user_avatar}</if>
  72. WHERE history_code = #{history_code}
  73. </update> -->
  74. <delete id="deleteAiChat">
  75. DELETE FROM ai_chat WHERE history_code = #{history_code}
  76. </delete>
  77. </mapper>