123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- <?xml version="1.0" encoding="utf-8" ?>
- <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
- <mapper namespace="com.backendsys.modules.material.dao.MaterialDao">
- <sql id="includeMaterial">
- m.id,
- m.id material_id,
- m.user_id,
- m.category_id,
- COALESCE(mc.category_name, '') category_name,
- COALESCE(m.tag_ids, '') tag_ids,
- m.material_name,
- COALESCE(m.image_thumb_url, '') image_thumb_url,
- m.is_copyright,
- m.create_time,
- m.update_time
- </sql>
- <sql id="includeMaterialDetail">
- m.id,
- m.id material_id,
- m.user_id,
- m.category_id,
- COALESCE(mc.category_name, '') category_name,
- COALESCE(m.tag_ids, '') tag_ids,
- m.material_name,
- COALESCE(m.image_thumb_url, '') image_thumb_url,
- COALESCE(m.image_url, '') image_url,
- COALESCE(m.file_url, '') file_url,
- m.is_copyright,
- m.create_time,
- m.update_time
- </sql>
- <resultMap id="resultMapMaterial" type="java.util.LinkedHashMap">
- <id property="id" column="id" jdbcType="BIGINT" />
- <result property="material_id" column="id" javaType="java.lang.Long" />
- <result property="user_id" column="user_id" javaType="java.lang.Long" />
- <result property="user_nickname" column="user_nickname" />
- <result property="category_id" column="category_id" javaType="java.lang.Long" />
- <result property="category_name" column="category_name" />
- <result property="tag_ids" column="tag_ids" />
- <result property="material_name" column="material_name" />
- <result property="image_thumb_url" column="image_thumb_url" />
- <result property="is_copyright" column="is_copyright" javaType="java.lang.Integer" />
- <result property="create_time" column="create_time"
- typeHandler="com.backendsys.config.Mybatis.handler.timezone.LocalDateTimeHandler" />
- <result property="update_time" column="update_time"
- typeHandler="com.backendsys.config.Mybatis.handler.timezone.LocalDateTimeHandler" />
- </resultMap>
- <resultMap id="resultMapMaterialDetail" type="com.backendsys.modules.material.entity.Material">
- <id property="id" column="id" jdbcType="BIGINT" />
- <result property="material_id" column="id" javaType="java.lang.Long" />
- <result property="user_id" column="user_id" javaType="java.lang.Long" />
- <result property="user_nickname" column="user_nickname" />
- <result property="category_id" column="category_id" javaType="java.lang.Long" />
- <result property="category_name" column="category_name" />
- <result property="tag_ids" column="tag_ids" />
- <result property="material_name" column="material_name" />
- <result property="image_thumb_url" column="image_thumb_url" />
- <result property="image_url" column="image_url" />
- <result property="file_url" column="file_url" />
- <result property="is_copyright" column="is_copyright" javaType="java.lang.Integer" />
- <result property="create_time" column="create_time"
- typeHandler="com.backendsys.config.Mybatis.handler.timezone.LocalDateTimeHandler" />
- <result property="update_time" column="update_time"
- typeHandler="com.backendsys.config.Mybatis.handler.timezone.LocalDateTimeHandler" />
- </resultMap>
- <!-- 查 -->
- <select id="selectMaterialList" resultMap="resultMapMaterial">
- SELECT
- <include refid="includeMaterial" />
- FROM ai_material m
- LEFT JOIN ai_material_category mc ON m.category_id = mc.id
- <where>
- <if test="category_id != null and category_id != ''">
- AND m.category_id = #{category_id}
- </if>
- <if test="tag_id != null and tag_id != ''">
- AND FIND_IN_SET(#{tag_id}, m.tag_ids) > 0
- </if>
- <if test="material_name != null and material_name != ''">
- AND m.material_name like concat('%', #{material_name}, '%')
- </if>
- <if test="is_copyright != null and is_copyright != ''">
- AND m.is_copyright = #{is_copyright}
- </if>
- </where>
- ORDER BY m.create_time DESC
- </select>
- <select id="selectMaterialDetail" resultMap="resultMapMaterialDetail">
- SELECT
- <include refid="includeMaterialDetail" />, uf.nickname AS user_nickname
- FROM ai_material m
- LEFT JOIN ai_material_category mc ON m.category_id = mc.id
- LEFT JOIN sys_user_info uf ON m.user_id = uf.user_id
- WHERE m.id = #{material_id}
- </select>
- <!-- 增 -->
- <insert id="insertMaterial" parameterType="com.backendsys.modules.material.entity.Material"
- useGeneratedKeys="true" keyProperty="material_id">
- INSERT INTO ai_material (
- user_id, category_id, material_name
- <if test="tag_ids != null and tag_ids != ''">, tag_ids</if>
- <if test="image_thumb_url != null and image_thumb_url != ''">, image_thumb_url</if>
- <if test="image_url != null and image_url != ''">, image_url</if>
- <if test="file_url != null and file_url != ''">, file_url</if>
- <if test="is_copyright != null and is_copyright != ''">, is_copyright</if>
- )
- VALUES (
- #{user_id}, #{category_id}, #{material_name}
- <if test="tag_ids != null and tag_ids != ''">, #{tag_ids}</if>
- <if test="image_thumb_url != null and image_thumb_url != ''">, #{image_thumb_url}</if>
- <if test="image_url != null and image_url != ''">, #{image_url}</if>
- <if test="file_url != null and file_url != ''">, #{file_url}</if>
- <if test="is_copyright != null and is_copyright != ''">, #{is_copyright}</if>
- )
- </insert>
- <!-- 改 -->
- <update id="updateMaterial" parameterType="com.backendsys.modules.material.entity.Material"
- useGeneratedKeys="true" keyProperty="material_id">
- UPDATE ai_material SET
- user_id = #{user_id}
- <if test="category_id != null and category_id != ''">, category_id = #{category_id}</if>
- <if test="material_name != null and material_name != ''">, material_name = #{material_name}</if>
- <if test="tag_ids != null and tag_ids != ''">, tag_ids = #{tag_ids}</if>
- <if test="image_thumb_url != null and image_thumb_url != ''">, image_thumb_url = #{image_thumb_url}</if>
- <if test="image_url != null and image_url != ''">, image_url = #{image_url}</if>
- <if test="file_url != null and file_url != ''">, file_url = #{file_url}</if>
- <if test="is_copyright != null and is_copyright != ''">, is_copyright = #{is_copyright}</if>
- WHERE id = #{material_id}
- </update>
- <delete id="deleteMaterial">
- DELETE FROM ai_material WHERE id = #{material_id}
- </delete>
- </mapper>
|