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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?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.ycl.platform.mapper.DynamicColumnMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.ycl.platform.domain.vo.DynamicColumnVO">
        <result column="ref_id" property="refId"/>
        <result column="prop_name" property="propName"/>
        <result column="label_value" property="labelValue"/>
        <result column="field_value" property="fieldValue"/>
    </resultMap>
 
    <select id="getById" resultMap="BaseResultMap">
        SELECT TDC.ref_id,
               TDC.prop_name,
               TDC.label_value,
               TDC.field_value,
               TDC.id
        FROM t_dynamic_column TDC
        WHERE TDC.id = #{id}
          AND TDC.deleted = 0
    </select>
 
    <select id="getHeader" resultType="java.lang.String">
        SELECT TDC.label_value
        FROM t_dynamic_column TDC
        WHERE TDC.table_name =#{tableName}
    </select>
    <select id="getData" resultType="com.ycl.platform.domain.vo.DynamicColumnVO">
        SELECT
        TDC.id,
        TDCV.ref_id,
        TDC.prop_name,
        TDC.label_value,
        TDCV.column_value,
        TDCV.id as value_id
        FROM
        t_dynamic_column TDC
        LEFT JOIN t_dynamic_column_value TDCV ON TDC.id =TDCV.dynamic_column_id
        <where>
            TDC.table_name  = 't_yw_point'
<!--            <if test="ids !=null and ids.size > 0">-->
<!--                AND TDCV.ref_id in-->
<!--                <foreach collection="ids" open="(" separator="," close=")" item="id">-->
<!--                    #{id}-->
<!--                </foreach>-->
<!--            </if>-->
        </where>
    </select>
 
 
    <select id="getPage" resultMap="BaseResultMap">
        SELECT TDC.ref_id,
               TDC.prop_name,
               TDC.label_value,
               TDC.field_value,
               TDC.id
        FROM t_dynamic_column TDC
        WHERE TDC.deleted = 0
    </select>
 
    <insert id="saveBatch">
        insert into t_dynamic_column_value (dynamic_column_id,column_value,ref_id,ref_string_id) values
        <foreach collection="insertList" item="item" separator=",">
            (#{item.dynamicColumnId},#{item.columnValue},#{item.refId},#{item.refStringId})
        </foreach>
    </insert>
    <update id="updateBatch">
        <foreach collection="updateList" separator=";" item="item">
            UPDATE t_dynamic_column_value
            SET column_value = #{item.columnValue}
            WHERE id = #{item.id}
        </foreach>
    </update>
    <delete id="deleteBatch">
        delete from t_dynamic_column_value where id in
        <foreach collection="deleteList" open="(" close=")" separator="," item="id">
            #{id}
        </foreach>
    </delete>
 
    <select id="getDynamicsByIds" resultType="com.ycl.platform.domain.vo.DynamicColumnVO">
        SELECT
        *
        FROM
        t_dynamic_column_value dcv
        INNER JOIN t_dynamic_column dc ON dc.id = dcv.dynamic_column_id AND dc.table_name = #{tableName}
        WHERE
        dcv.ref_id in
        <foreach collection="ids" item="id" separator="," open="(" close=")">
            #{id}
        </foreach>
    </select>
 
    <resultMap id="dynamicColumnMap" type="com.ycl.platform.domain.vo.DynamicColumnVO">
        <result column="prop_name" property="propName"/>
        <result column="label_value" property="labelValue"/>
        <result column="column_value" property="columnValue"/>
        <result column="ref_string_id" property="refStringId"/>
        <result column="value_id" property="valueId"/>
        <result column="label_id" property="labelId"/>
    </resultMap>
 
    <select id="getDynamicColumnByTable" resultMap="dynamicColumnMap">
        SELECT
        *,
        dcv.id as value_id
        FROM
        t_dynamic_column dc
        LEFT JOIN t_dynamic_column_value dcv ON dc.id = dcv.dynamic_column_id and dcv.ref_string_id = #{id} WHERE dc.table_name = #{tableName}
 
    </select>
 
    <select id="getDynamicColumnByTableName" resultMap="dynamicColumnMap">
        select *,
               dc.prop_name,
               dc.label_value,
               dcv.column_value,
               dcv.ref_string_id,
               dcv.dynamic_column_id as label_id
        from  t_dynamic_column_value dcv
        left join t_dynamic_column dc
        on dc.id = dcv.dynamic_column_id
        where dc.table_name =#{tableName}
    </select>
</mapper>