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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<?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_app_stander_def_{rule} -->
<mapper namespace="com.changhong.epc.tenant.mapper.tenant.norm.MasterDefineMapper">
    
    <resultMap id="BaseResultMap" type="com.changhong.epc.bean.tenant.master.extend.MasterDefineExtend" >
        <id column="id" property="Id" jdbcType="INTEGER" />
        <result column="CODE" property="code" jdbcType="VARCHAR" />
           <result column="Name" property="name" jdbcType="VARCHAR" />
        <result column="DESCRIPTION" property="description" jdbcType="VARCHAR" />
        <result column="TYPE" property="type" jdbcType="VARCHAR" />
        <result column="ELECODE" property="eleCode" jdbcType="VARCHAR" />
        <result column="ELEVALUE" property="eleValue" jdbcType="VARCHAR" />
        <result column="DEL_FLAG" property="delFlag" jdbcType="INTEGER" />
        <result column="Def1" property="def1" jdbcType="VARCHAR" />
        <result column="Def2" property="def2" jdbcType="VARCHAR" />
        <result column="Def3" property="def3" jdbcType="VARCHAR" />
        <result column="Def4" property="def4" jdbcType="VARCHAR" />
        <result column="Def5" property="def5" jdbcType="VARCHAR" />
        <result column="ins_p" property="insP" jdbcType="INTEGER" />
        <result column="ins_t" property="insT" jdbcType="TIMESTAMP" />
        <result column="upd_p" property="updP" jdbcType="INTEGER" />
        <result column="upd_t" property="updT" jdbcType="TIMESTAMP" />
      </resultMap>
      
      <resultMap id="MasterEleResult" type="com.changhong.epc.bean.tenant.master.extend.MasterDefinesExtend" >
          <id property="id" column="id"/>
          <result property="code" column="CODE"/>
          <result property="name" column="NAME"/>
          <collection property="eleList" ofType="com.changhong.epc.bean.tenant.master.MasterElement" javaType="list">
              <id property="id" column="bId"/>
              <result property="defineCode" column="define_code"/>
              <result property="code" column="bCode"/>
              <result property="name" column="bName"/>
              <result property="alias" column="alias"/>
          </collection>
      </resultMap>
      
    <select id="selectIdByCode" resultType="java.lang.Integer" parameterType="java.lang.String" >
      
        select 
            id
        from epc_master_define_{rule}
        where code = #{code}
     
        and data_start = 0
  </select>
    
      <select id="selectByQuery" resultMap="BaseResultMap" >
        select 
        distinct
        code , name, DESCRIPTION, type
         ,(select meCode.code from epc_master_element_{rule}  meCode where meCode.define_code = md.code and meCode.DEL_FLAG = 1 and meCode.ALIAS = 'code') ELECODE
         ,(select meCode.code from epc_master_element_{rule}  meCode where meCode.define_code = md.code and meCode.DEL_FLAG = 1 and meCode.ALIAS = 'value') ELEVALUE
        from epc_master_define_{rule}  md
        <where>
        <if test="type != null">
            and type = #{type}
        </if>
        and del_flag = 0
        </where>
      </select>
      
      <sql id="selectField">
          ID,CODE,NAME,DESCRIPTION,TYPE,DEL_FLAG,INS_P,INS_T,UPD_P,UPD_T,TENANT_ID,DATA_START
      </sql>
      
      
      <select id="selectEle" resultMap="MasterEleResult" parameterType="com.changhong.epc.bean.tenant.master.MasterDefine">
              SELECT
                  a.id ,
                a. CODE ,
                a. NAME ,
                b.define_code ,
                b.id bId,
                b. CODE bCode,
                b. NAME bName,
                b.ALIAS alias
            FROM
                epc_master_define_{rule}  a
            LEFT JOIN epc_master_element_{rule}  b ON a. CODE = b.define_code
            <trim prefix="WHERE" prefixOverrides="AND | OR">
                <if test="name != null">
                    a.NAME = #{name} 
                </if>
                <if test="id != null">
                    and a.id = #{id}
                </if>
                <if test="code != null">
                    and a.CODE = #{code}
                </if>
                
        </trim>
            
      </select>
      
      <select id="selectName" resultMap="MasterEleResult" >
              SELECT
                a.id,
                a. CODE ,
                a. NAME ,
                b.define_code,
                b.id bId,
                b. CODE bCode,
                b. NAME bName
            FROM
                epc_master_define_{rule}  a
            LEFT JOIN epc_master_element_{rule}  b ON a. CODE = b.define_code
            <trim prefix="WHERE" >
                <if test="master.name != null">
                    a.NAME = #{master.name} 
                </if>
        </trim>
      </select>
      
      <delete id="deleteAll">
          delete from epc_master_define_{rule}
          
      </delete>
 
    <select id="queryMaster" resultType="java.lang.Integer">
          SELECT
                COUNT(*)
            FROM
                epc_master_define_{rule}
            WHERE
                DEL_FLAG = 0
            AND CODE = #{code}
    </select>
 
    <insert id="addMasterValue">
        insert into ${tableName}
        <foreach collection="map" index="key" item="val" separator="," open="(" close=")">
            ${key}
        </foreach>
            values
        <foreach collection="map" index="key" item="val" separator="," open="(" close=")">
            #{val}
        </foreach>
    </insert>
 
    <resultMap id="selectDefAndMapResultMap" type="com.changhong.epc.bean.tenant.master.extend.MasterDefinesExtend">
        <id column="mdCode" property="code"/>
        <result column="mdName" property="name"/>
        <result column="type" property="defType"/>
        <result column="table_name" property="defMapTableName"/>
        <result column="mapType" property="defMapType"/>
        <collection property="eleList" ofType="com.changhong.epc.bean.tenant.master.MasterElement">
            <id column="meCode" property="code"/>
            <result column="meName" property="name"/>
            <result column="mdCode" property="defineCode"/>
            <result column="meAlias" property="alias"/>
            <result column="table_field" property="defMapTalbeField"/>
        </collection>
    </resultMap>
 
    <select id="selectDefAndMap" parameterType="com.changhong.epc.bean.tenant.master.MasterDefine" resultMap="selectDefAndMapResultMap">
        select
            td.code mdCode
            , td.name mdName
            , 0 type
            , tdm.table_name
            , tdm.type mapType
            , te.`CODE` meCode
            , te.`NAME` meName
            , te.ALIAS  meAlias
            , tem.table_field
        from epc_master_define_{rule} td
        left join epc_center.epc_master_default_mapping tdm on td.`CODE` = tdm.md_code
        left join epc_master_element_{rule} te on td.`CODE` = te.DEFINE_CODE
        left join epc_center.epc_master_element_mapping tem on tdm.id = tem.m_id and te.code = tem.me_code
        <where>
            <if test="code != null">
                td.code = #{code}
            </if>
        </where>
        UNION ALL
        select
            td.code mdCode
            , td.name mdName
            , 1 type
            , tdm.table_name
            , tdm.type mapType
            , te.`CODE` meCode
            , te.`NAME` meName
            , te.ALIAS  meAlias
            , tem.table_field
        from epc_center.epc_master_define td
        left join epc_center.epc_master_default_mapping tdm on td.`CODE` = tdm.md_code
        left join epc_center.epc_master_element te on td.`CODE` = te.DEFINE_CODE
        left join epc_center.epc_master_element_mapping tem on tdm.id = tem.m_id and te.code = tem.me_code
        <where>
            <if test="code != null">
                td.code = #{code}
            </if>
        </where>
    </select>
 
</mapper>