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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
<?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.changhong.epc.tenant.mapper.tenant.norm.MasterValueMapper">
    
    <resultMap type="com.changhong.epc.bean.tenant.master.MasterValue" id="ValueResultMap">
        <result property="eleValue" column="ELE_VALUE"/>
        <result property="rowNo" column="ROW_NO"/>
    </resultMap>
 
    <resultMap type="com.changhong.epc.bean.tenant.master.MasterValue" id="ValueResultMap1">
        <result property="eleCode" column="ELE_CODE"/>
        <result property="eleValue" column="ELE_VALUE"/>
        <result property="rowNo" column="ROW_NO"/>
    </resultMap>
    
    <resultMap id="MasterElementMap" type="com.changhong.epc.bean.tenant.master.extend.MasterElementExtend" >
           <result column="CODE" property="code"/>
           <result column="ALIAS" property="alias"/>
   </resultMap>
      
    <resultMap type="com.changhong.epc.bean.tenant.master.extend.MasterValueListExtend" id="masterValueMap">
        <id column="DEFINE_CODE" property="mdCode"/>
           <collection property="values" ofType="java.util.Map" javaType="com.changhong.epc.bean.tenant.master.MasterValueList">
               <id column="ID" property="id"/>
               <result column="ELE_CODE" property="eleCode"/>
               <result column="ELE_VALUE" property="eleValue"/>                
               <result column="ROW_NO" property="rowNo"/>
        </collection>
      </resultMap>
 
 
    <select id="isEmpty" resultType="java.lang.Integer">
    
        select count(0) from epc_master_value_{rule}  b where
            
            b.DEFINE_CODE = #{mdCode}
            AND b.ELE_CODE = #{eleCode}
            AND b.TENANT_ID = #{tenantId}
            AND DATA_START = 0
            AND b.ROW_NO = #{rowNo}
    
    </select>
        
    <select id="getMasterValString" resultType="java.lang.String">
          select getVal_{rule}(
                #{paramMap.defineCode}
                , #{paramMap.eleCode}
                , #{paramMap.masterCode}
                , #{paramMap.eleValue}
          )
    </select>
    
      <update id="updateStart" >
          update epc_master_value_{rule}
          set 
              data_start = 99
            ,upd_p = -1
            ,upd_t = now()
          where 
        define_code = #{mdCode}
        and row_no 
        <foreach collection="list" item="data" open="IN (" close=")" separator=",">
            #{data.rowNum}
    </foreach>
  </update>
    
     <delete id="deleteValue">
          delete from epc_master_value_{rule}
          where define_code = #{config.masDataDefCode}
        and row_no = #{config.rowNum}
      </delete>
        
    <select id="getVal" resultType="Object" parameterType="com.changhong.epc.bean.tenant.master.MasterEleValue">
        SELECT
            getVal_{rule} (
                #{mast.defineCode}, 
                #{mast.inMeCode}, 
                #{mast.outMeCode} , 
                #{mast.mvCode}    
            );
    </select>
 
 
    
    <select id="selectCode" resultMap="MasterElementMap" >
        SELECT
            CODE,
            ALIAS
        FROM
            epc_master_element_{rule}
        WHERE
            DEFINE_code = #{code}
        AND ALIAS IN ('code', 'value')
    </select>
    
    <select id="selectMasterValueListExtend" resultMap="masterValueMap">
        select 
            ID,
            DEFINE_CODE,
            <choose>
            
                <when test="params != null">
                (    
                    CASE
                    <foreach collection="params" item="item" index="index">
                        WHEN ELE_CODE = #{item.code}
                            THEN #{item.alias}
                    </foreach>
                    END
                ) ELE_CODE,
                
                </when>
                <otherwise>
                 ELE_CODE,
                </otherwise>
            </choose>
            ELE_VALUE,
            ROW_NO
         from epc_master_value_{rule}
         where DEFINE_CODE = #{defineCode} 
         and ELE_CODE in
         
         <foreach collection="params" item="item" index="index" open="(" close=")" separator=",">
             #{item.code}
         </foreach>
         
         and DEL_FLAG = 0 
         <if test="list != null">
         and    ROW_NO in(select ROW_NO from epc_master_value_{rule} where DEFINE_CODE = #{defineCode} and ELE_VALUE in
             <foreach collection="list" item="item" index="index" open="(" close=")" separator=",">
             #{item} 
         </foreach>
         ) 
         </if>
         <if test="value != null and list ==null">
             and ROW_NO in(select ROW_NO from epc_master_value_{rule} where DEFINE_CODE = #{defineCode}
             and ELE_CODE in
             <foreach collection="params" item="item" index="index" open="(" close=")" separator=",">
                 #{item.code}
             </foreach>
             and ELE_VALUE LIKE CONCAT('%',#{value},'%'))
         </if>
         <if test="value != null and list !=null">
             or ROW_NO in(select ROW_NO from epc_master_value_{rule} where DEFINE_CODE = #{defineCode}
             and ELE_CODE in
             <foreach collection="params" item="item" index="index" open="(" close=")" separator=",">
                 #{item.code}
             </foreach>
             and ELE_VALUE LIKE CONCAT('%',#{value},'%'))
         </if>
         ORDER BY ROW_NO 
         <if test="isAll!=null">
             limit 200
         </if>
    </select>
    
    <select id="selectValue" resultMap="ValueResultMap">
        SELECT
            DISTINCT
            ELE_VALUE,ROW_NO
        FROM
            epc_master_value_{rule}  T1
        RIGHT JOIN (
            SELECT
                mse.DEFINE_CODE,
                mse.CODE,
                mse.ALIAS
            FROM
                epc_master_element_{rule}  mse
            WHERE
                mse.DEFINE_CODE = #{code}
            AND mse.ALIAS IN ('code', 'value')
        ) T2 
        ON T2.DEFINE_CODE = T1.DEFINE_CODE
        AND T2.CODE = T1.ELE_CODE
        ORDER BY ROW_NO,ALIAS
    </select>
    
    <select id="getValString" resultType="java.lang.String">
        SELECT
            (
                select T3.ELE_VALUE FROM epc_master_value_{rule}  T3
                WHERE
                    T3.DEFINE_CODE = T2.DEFINE_CODE
                and T3.ROW_NO = T2.ROW_NO
                and T3.ELE_CODE  = #{meCode}
                and T3.DEL_FLAG = 0
                limit 1
            ) result
        FROM
            (
                select
                    DISTINCT
                    T1.DEFINE_CODE,
                    T1.ELE_CODE,
                    T1.ELE_VALUE,
                    T1.ROW_NO
                from epc_master_value_{rule}  T1
                WHERE T1.DEFINE_CODE = #{mdCode}
                AND T1.DEL_FLAG = 0
                ORDER BY
                    T1.ROW_NO
            )T2
        <where>
            <foreach collection="params" item="item" open="(" close=")" separator="or">
                    (T2.ELE_CODE, T2.ELE_VALUE) = (#{item.leftMeCode},#{item.meValue})
            </foreach>
        </where>
        GROUP BY T2.ROW_NO
        HAVING count(ROW_NO) = ${params.size()}
        LIMIT 1
    </select>
 
 
    <select id="selectValues" resultType="java.util.Map" >
        select
        id,
        <foreach collection="list" item="ele" separator=",">
            ${ele.tableField} as #{ele.meCode}
        </foreach>
        from ${name}
        where data_start = 0 and isBlock = '0'
    </select>
    
    
    <delete id="deleteAll">
          delete from epc_master_value_{rule}
          
    </delete>
    
       <select id="selectValueSeache" resultMap="ValueResultMap">
        SELECT
            DISTINCT
            ELE_VALUE,ROW_NO
        FROM
            epc_master_value_{rule} T1
        RIGHT JOIN (
            SELECT
                mse.DEFINE_CODE,
                mse.CODE,
                mse.ALIAS
            FROM
                epc_master_element_{rule} mse
            WHERE
                mse.DEFINE_CODE = #{code}
            AND mse.ALIAS IN ('code', 'value')
        ) T2 
        ON T2.DEFINE_CODE = T1.DEFINE_CODE
        AND T2.CODE = T1.ELE_CODE
        <if test="value !=null">
        and ROW_NO in(select ROW_NO from epc_master_value_{rule} where DEFINE_CODE = #{code} and ELE_VALUE LIKE CONCAT('%',#{value},'%'))
        </if>
        <if test="list !=null">
            and    ROW_NO in(select ROW_NO from epc_master_value_{rule} where DEFINE_CODE = #{code} and ELE_VALUE in
             <foreach collection="list" item="item" index="index" open="(" close=")" separator=",">
             #{item} 
         </foreach>
         )
        </if>
        ORDER BY ROW_NO,ALIAS
        LIMIT 200
    </select>
 
    <select id="getMasterCode" resultType="java.lang.String">
        SELECT
            a.ELE_VALUE
        FROM
            epc_master_value_{rule} a
        WHERE
            a.DEFINE_CODE = #{master.defineCode}
        AND a.ELE_CODE = (
            SELECT
                CODE
            FROM
                epc_master_element_{rule} b
            WHERE
                b.DEFINE_CODE = #{master.defineCode}
            AND b.alias = 'code'
            limit 1
        )
        AND a.ROW_NO = (
            SELECT
                ROW_NO
            FROM
                epc_master_value_{rule} c
            WHERE
                c.DEFINE_CODE = #{master.defineCode} and
                c.ELE_VALUE = #{master.eleValue}
            limit 1
        )
        limit 1
    </select>
 
 
    <select id="selectValue1" resultMap="ValueResultMap1">
        SELECT
            ELE_CODE,
            ELE_VALUE,ROW_NO
        FROM
            epc_master_value_{rule}  T1
            where DEFINE_CODE = #{code}
        ORDER BY ROW_NO
    </select>
 
    <insert id="addConfigMaster">
        insert into ${tableName}
        <foreach collection="data" index="key" item="vaj" separator="," open="(" close=")">
            ${key}
        </foreach>
        values
        <foreach collection="data" index="key" item="val" separator="," open="(" close=")">
            #{val}
        </foreach>
    </insert>
    
    <delete id="deleteConfigMaster">
        delete from ${tableName}
            where id = #{id}
    </delete>
    
    <update id="updateConfigMaster">
        update ${tableName} set
            <foreach collection="data" index="key" item="val" separator="," >
                ${key}=#{val}
            </foreach>
            ,company_code = #{companyCode}
            ,company_name = #{companyName}
        where id = #{id}
    </update>
 
    <select id="getValTwoDimensional" resultType="java.lang.String">
        select
            ${resField}
        from ${tableName}
        <where>
            <if test="params != null">
                <foreach collection="params" item="param" separator=" AND ">
                    ${param.fieldName} = #{param.meValue}
                </foreach>
            </if>
        </where>
        limit 1
    </select>
    
    <select id="twoCodeValue" resultType="java.lang.String">
    
        select ${field}
        from ${tableName}
        where ${conditionField} = #{conditionValue}
        LIMIT 1
    </select>
 
    <select id="seacherValues" resultType="java.util.Map">
        SELECT
            ${code} `code`,
            ${value} `value`
        FROM
            ${tableName}
        <trim prefix="where" prefixOverrides="AND | OR">
            <if test="eleValue != null">
            and ${value} LIKE CONCAT('%', #{eleValue}, '%')
            </if>
            <if test="list!=null">
                and ${code} in
                <foreach collection="list" item="item" index="index" open="(" close=")" separator=",">
                    #{item}
                </foreach>
            </if>
        </trim>
    </select>
 
</mapper>