zm
2020-05-18 a18bfacbf56b401f6e0fdae8710fbca4df8cff77
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
127
128
129
130
131
132
133
134
135
136
137
138
139
<?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" >
<!-- Table:epc_master_default_mapping -->
<mapper namespace="com.changhong.epc.admin.mapper.centen.site.MasterDefaultMappingMapper">
 
    <resultMap type="com.changhong.epc.bean.admin.MasterDefaultMapping" id="resultMap">
 
        <id property="id" column="id"/>
        <result property="mdCode" column="md_code"/>
        <result property="tableName" column="table_name"/>
        <result property="type" column="type"/>
    </resultMap>
    <sql id="masterDefaultMappingSql">
        md_code, table_name
    </sql>
 
    <select id="selectMaster" resultMap="resultMap">
        
         SELECT
            id,md_code,table_name,type
        FROM
            epc_master_default_mapping
        WHERE
            md_code = #{code}
    
    </select>
 
    <select id="selectMasterById" resultMap="resultMap">
 
         SELECT
            id,md_code,table_name,type
        FROM
            epc_master_default_mapping
        WHERE
            id = #{id}
    </select>
 
    <select id="selectValue" resultType="java.util.Map">
        select
        <if test="tableName == 'epc_nationwide_site'">
            DISTINCT
        </if>
        <foreach collection="list" item="ele" separator=",">
            ${ele.tableField} as #{ele.meCode}
        </foreach>
        from ${tableName}
        where data_start = 0
        and DEL_FLAG = 0
        <if test="listParam != null and code != null">
            and ${code} in
            <foreach collection="listParam" item="item" index="index" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="value != null and listParam ==null">
            and ${value} LIKE CONCAT('%',#{value},'%')
        </if>
        <if test="value != null and listParam !=null">
            or ${value} LIKE CONCAT('%',#{value},'%')
        </if>
        order by ROW_NO asc
        <if test="isAll!=null">
            limit 100
        </if>
    </select>
 
    <select id="CodeConValue" resultType="java.lang.String">
        SELECT
            ${con.valueFlied}
        FROM
            ${con.tableName}
        WHERE
        ${con.codeFlied} = #{con.code}
    LIMIT 1;
    </select>
 
    <select id="ValueConCode" resultType="java.lang.String">
        SELECT
            ${con.codeFlied}
        FROM
            ${con.tableName}
        WHERE
        ${con.valueFlied} = #{con.value}
        LIMIT 1;
    </select>
 
    <update id="updateMasterDefaultMapping" parameterType="com.changhong.epc.bean.admin.MasterDefaultMapping">
        update  epc_master_default_mapping
        <trim prefix="set" suffix=" where id = #{id} " suffixOverrides=",">
            <if test="mdCode!=null and mdCode.length()>0">
                md_code=#{mdCode},
            </if>
            <if test="tableName != null and tableName.length()>0">
                table_name=#{tableName},
            </if>
            <if test="type != null and type.length()>0">
                type=#{type},
            </if>
           <!-- <if test="updT != null">
                upd_t=#{updT},
            </if>
            <if test="updP != null and updP.length()>0">
                upd_p=#{updP},
            </if>-->
        </trim>
 
    </update>
 
    <insert id="insertDefaultMappingToId" parameterType="com.changhong.epc.bean.admin.MasterDefaultMapping"
            useGeneratedKeys="true"  keyProperty="mdm.id">
        insert into epc_master_default_mapping(md_code,table_name,ins_p,ins_t,upd_p,upd_t,data_start,type)
        values(#{mdm.mdCode},#{mdm.tableName},#{mdm.insP},#{mdm.insT},#{mdm.updP},#{mdm.updT},#{mdm.dataStart},#{mdm.type})
    </insert>
 
    <resultMap id="selectAllDefAndEleMap" type="com.changhong.epc.bean.admin.MasterDefaultMapping">
        <id column="id" property="id"/>
        <result column="md_code" property="mdCode"/>
        <result column="table_name" property="tableName"/>
        <result column="type" property="type"/>
        <collection property="masterElementMappings" ofType="com.changhong.epc.bean.admin.MasterElementMapping" >
            <id column="me_code" property="meCode"/>
            <result column="table_field" property="tableField"/>
        </collection>
    </resultMap>
 
    <select id="selectAllDefAndEle" resultMap="selectAllDefAndEleMap">
        SELECT
            def.id,
            def.md_code,
            def.table_name,
            def.type,
            ele.me_code,
            ele.table_field
        FROM
            epc_master_default_mapping def
        left join epc_master_element_mapping ele on ele.m_id = def.id
    </select>
 
</mapper>