MaterialDao.xml 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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.modules.material.dao.MaterialDao">
  4. <sql id="includeMaterial">
  5. m.id,
  6. m.id material_id,
  7. m.user_id,
  8. m.category_id,
  9. COALESCE(mc.category_name, '') category_name,
  10. COALESCE(m.tag_ids, '') tag_ids,
  11. m.material_name,
  12. COALESCE(m.image_thumb_url, '') image_thumb_url,
  13. m.is_copyright,
  14. m.create_time,
  15. m.update_time
  16. </sql>
  17. <sql id="includeMaterialDetail">
  18. m.id,
  19. m.id material_id,
  20. m.user_id,
  21. m.category_id,
  22. COALESCE(mc.category_name, '') category_name,
  23. COALESCE(m.tag_ids, '') tag_ids,
  24. m.material_name,
  25. COALESCE(m.image_thumb_url, '') image_thumb_url,
  26. COALESCE(m.image_url, '') image_url,
  27. COALESCE(m.file_url, '') file_url,
  28. m.is_copyright,
  29. m.create_time,
  30. m.update_time
  31. </sql>
  32. <resultMap id="resultMapMaterial" type="java.util.LinkedHashMap">
  33. <id property="id" column="id" jdbcType="BIGINT" />
  34. <result property="material_id" column="id" javaType="java.lang.Long" />
  35. <result property="user_id" column="user_id" javaType="java.lang.Long" />
  36. <result property="user_nickname" column="user_nickname" />
  37. <result property="category_id" column="category_id" javaType="java.lang.Long" />
  38. <result property="category_name" column="category_name" />
  39. <result property="tag_ids" column="tag_ids" />
  40. <result property="material_name" column="material_name" />
  41. <result property="image_thumb_url" column="image_thumb_url" />
  42. <result property="is_copyright" column="is_copyright" javaType="java.lang.Integer" />
  43. <result property="create_time" column="create_time"
  44. typeHandler="com.backendsys.config.Mybatis.handler.timezone.LocalDateTimeHandler" />
  45. <result property="update_time" column="update_time"
  46. typeHandler="com.backendsys.config.Mybatis.handler.timezone.LocalDateTimeHandler" />
  47. </resultMap>
  48. <resultMap id="resultMapMaterialDetail" type="com.backendsys.modules.material.entity.Material">
  49. <id property="id" column="id" jdbcType="BIGINT" />
  50. <result property="material_id" column="id" javaType="java.lang.Long" />
  51. <result property="user_id" column="user_id" javaType="java.lang.Long" />
  52. <result property="user_nickname" column="user_nickname" />
  53. <result property="category_id" column="category_id" javaType="java.lang.Long" />
  54. <result property="category_name" column="category_name" />
  55. <result property="tag_ids" column="tag_ids" />
  56. <result property="material_name" column="material_name" />
  57. <result property="image_thumb_url" column="image_thumb_url" />
  58. <result property="image_url" column="image_url" />
  59. <result property="file_url" column="file_url" />
  60. <result property="is_copyright" column="is_copyright" javaType="java.lang.Integer" />
  61. <result property="create_time" column="create_time"
  62. typeHandler="com.backendsys.config.Mybatis.handler.timezone.LocalDateTimeHandler" />
  63. <result property="update_time" column="update_time"
  64. typeHandler="com.backendsys.config.Mybatis.handler.timezone.LocalDateTimeHandler" />
  65. </resultMap>
  66. <!-- 查 -->
  67. <select id="selectMaterialList" resultMap="resultMapMaterial">
  68. SELECT
  69. <include refid="includeMaterial" />
  70. FROM ai_material m
  71. LEFT JOIN ai_material_category mc ON m.category_id = mc.id
  72. <where>
  73. <if test="category_id != null and category_id != ''">
  74. AND m.category_id = #{category_id}
  75. </if>
  76. <if test="tag_id != null and tag_id != ''">
  77. AND FIND_IN_SET(#{tag_id}, m.tag_ids) > 0
  78. </if>
  79. <if test="material_name != null and material_name != ''">
  80. AND m.material_name like concat('%', #{material_name}, '%')
  81. </if>
  82. <if test="is_copyright != null and is_copyright != ''">
  83. AND m.is_copyright = #{is_copyright}
  84. </if>
  85. </where>
  86. ORDER BY m.create_time DESC
  87. </select>
  88. <select id="selectMaterialDetail" resultMap="resultMapMaterialDetail">
  89. SELECT
  90. <include refid="includeMaterialDetail" />, uf.nickname AS user_nickname
  91. FROM ai_material m
  92. LEFT JOIN ai_material_category mc ON m.category_id = mc.id
  93. LEFT JOIN sys_user_info uf ON m.user_id = uf.user_id
  94. WHERE m.id = #{material_id}
  95. </select>
  96. <!-- 增 -->
  97. <insert id="insertMaterial" parameterType="com.backendsys.modules.material.entity.Material"
  98. useGeneratedKeys="true" keyProperty="material_id">
  99. INSERT INTO ai_material (
  100. user_id, category_id, material_name
  101. <if test="tag_ids != null and tag_ids != ''">, tag_ids</if>
  102. <if test="image_thumb_url != null and image_thumb_url != ''">, image_thumb_url</if>
  103. <if test="image_url != null and image_url != ''">, image_url</if>
  104. <if test="file_url != null and file_url != ''">, file_url</if>
  105. <if test="is_copyright != null and is_copyright != ''">, is_copyright</if>
  106. )
  107. VALUES (
  108. #{user_id}, #{category_id}, #{material_name}
  109. <if test="tag_ids != null and tag_ids != ''">, #{tag_ids}</if>
  110. <if test="image_thumb_url != null and image_thumb_url != ''">, #{image_thumb_url}</if>
  111. <if test="image_url != null and image_url != ''">, #{image_url}</if>
  112. <if test="file_url != null and file_url != ''">, #{file_url}</if>
  113. <if test="is_copyright != null and is_copyright != ''">, #{is_copyright}</if>
  114. )
  115. </insert>
  116. <!-- 改 -->
  117. <update id="updateMaterial" parameterType="com.backendsys.modules.material.entity.Material"
  118. useGeneratedKeys="true" keyProperty="material_id">
  119. UPDATE ai_material SET
  120. user_id = #{user_id}
  121. <if test="category_id != null and category_id != ''">, category_id = #{category_id}</if>
  122. <if test="material_name != null and material_name != ''">, material_name = #{material_name}</if>
  123. <if test="tag_ids != null and tag_ids != ''">, tag_ids = #{tag_ids}</if>
  124. <if test="image_thumb_url != null and image_thumb_url != ''">, image_thumb_url = #{image_thumb_url}</if>
  125. <if test="image_url != null and image_url != ''">, image_url = #{image_url}</if>
  126. <if test="file_url != null and file_url != ''">, file_url = #{file_url}</if>
  127. <if test="is_copyright != null and is_copyright != ''">, is_copyright = #{is_copyright}</if>
  128. WHERE id = #{material_id}
  129. </update>
  130. <delete id="deleteMaterial">
  131. DELETE FROM ai_material WHERE id = #{material_id}
  132. </delete>
  133. </mapper>