Cui Zhi Feng
2024-08-29 f3e286d281e20f64f48d48309810d5a185bc7c68
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?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.mzl.flower.mapper.flower.FlowerParamMapper">
 
    <update id="createTable" parameterType="String">
        CREATE TABLE ${table.name} (
        <foreach collection="table.fields" item="field" open="" separator="," close="">
            ${field.column} ${field.type}
            <choose>
                <when test="field.primaryKey">
                    NOT NULL primary key
                </when>
                <otherwise>
                    DEFAULT NULL
                </otherwise>
            </choose>
            <if test="field.comment != null and field.comment != ''">
                COMMENT #{field.comment}
            </if>
        </foreach>
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT=#{table.label}
    </update>
 
    <select id="selectParamList" resultType="com.mzl.flower.dto.response.flower.FlowerParamListDTO">
        SELECT q.*
            , (SELECT GROUP_CONCAT(fc.name) FROM t_flower_category fc WHERE fc.param_id = q.id) categories
        FROM t_flower_param q
        WHERE q.deleted = 0
        <if test="condition.name != null and condition.name != ''">
            AND q.name LIKE concat('%', #{condition.name},'%')
        </if>
        <if test="condition.categoryId != null and condition.categoryId != ''">
            AND exists (
                select 1 from t_flower_category fc where fc.id = #{condition.categoryId} and fc.param_id = q.id
            )
        </if>
        ORDER BY q.sort_by, q.create_time Desc
    </select>
 
    <update id="insertTableData">
        insert into ${tableName}
        <foreach collection="columnList" item="column" open="(" separator="," close=")">
            ${column}
        </foreach>
        values
        <foreach collection="valueList" item="value" open="(" separator="," close=")">
            #{value}
        </foreach>
    </update>
 
    <update id="updateTableDataById">
        update ${tableName}
        SET
        <foreach collection="valueMapList" item="map" open="" separator="," close="">
            ${map.column} = #{map.value}
        </foreach>
        where ${idColumn} = #{idValue}
    </update>
 
    <select id="getTableDataById" resultType="java.util.Map">
        SELECT *
        FROM ${tableName}
        where id = #{id}
    </select>
</mapper>