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
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
<?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.admin.mapper.centen.master.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 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  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(
                #{paramMap.defineCode}
                , #{paramMap.eleCode}
                , #{paramMap.masterCode}
                , #{paramMap.eleValue}
          )
    </select>
 
    <update id="updateStart">
        update epc_master_value
        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
          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(
                #{mast.defineCode}, 
                #{mast.inMeCode}, 
                #{mast.outMeCode} , 
                #{mast.mvCode}    
            );
    </select>
 
    <select id="selectCode" resultMap="MasterElementMap">
        SELECT
            CODE,
            ALIAS
        FROM
            epc_master_element
        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
        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 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 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 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  T1
        RIGHT JOIN (
            SELECT
                mse.DEFINE_CODE,
                mse.CODE,
                mse.ALIAS
            FROM
                epc_master_element  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 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 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
        <foreach collection="list" item="ele" separator=",">
            ${ele.tableField} as #{ele.meCode}
        </foreach>
        from ${name}_{rule}
        where data_start = 0
    </select>
 
 
    <delete id="deleteAll">
          delete from epc_master_value
          
    </delete>
 
    <select id="selectValueSeache" resultMap="ValueResultMap">
        SELECT
        DISTINCT
        ELE_VALUE,ROW_NO
        FROM
        epc_master_value T1
        RIGHT JOIN (
        SELECT
        mse.DEFINE_CODE,
        mse.CODE,
        mse.ALIAS
        FROM
        epc_master_element 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 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 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 a
        WHERE
            a.DEFINE_CODE = #{master.defineCode}
        AND a.ELE_CODE = (
            SELECT
                CODE
            FROM
                epc_master_element b
            WHERE
                b.DEFINE_CODE = #{master.defineCode}
            AND b.alias = 'code'
        )
        AND a.ROW_NO = (
            SELECT
                ROW_NO
            FROM
                epc_master_value c
            WHERE
                c.DEFINE_CODE = #{master.defineCode} and
                c.ELE_VALUE = #{master.eleValue}
        )
    </select>
 
    <delete id="deleteByDefineCode">
        delete from
            ${tableName}
        where
            define_code=#{code}
    </delete>
 
    <update id="createValueTable" parameterType="java.lang.String">
      CREATE TABLE
        ${tableName} (
          `ID` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增ID',
          `DEFINE_CODE` varchar(10) NOT NULL COMMENT '主数据定义代码',
 
          <foreach collection="list" item="val">
              ${val} varchar(100) DEFAULT '',
          </foreach>
          `ROW_NO` int(11) DEFAULT NULL COMMENT '相同行号的数据,横向组成一行主数据值 记录',
          `DEF1` varchar(100) DEFAULT '' COMMENT '备用字段1',
          `DEF2` varchar(100) DEFAULT '' COMMENT '备用字段2',
          `DEF3` varchar(100) DEFAULT '' COMMENT '备用字段3',
          `DEF4` varchar(100) DEFAULT '' COMMENT '备用字段4',
          `DEF5` varchar(100) DEFAULT '' COMMENT '备用字段5',
          `DEL_FLAG` int(4) DEFAULT 0 COMMENT '删除标记',
          `INS_P` varchar(20) DEFAULT NULL COMMENT '创建人',
          `INS_T` datetime DEFAULT NULL COMMENT '创建时间',
          `UPD_P` varchar(20) DEFAULT NULL COMMENT '修改人',
          `UPD_T` datetime DEFAULT NULL COMMENT '修改时间',
          `TENANT_ID` char(20) DEFAULT NULL COMMENT '租户ID',
          `DATA_START` int(4) DEFAULT 0,
          PRIMARY KEY (`ID`),
          KEY `IDX_VALUE_DEFINE_CODE` (`DEFINE_CODE`),
          KEY `IDX_VALUE_ROW_NO` (`ROW_NO`)
)
     ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='主数据赋值表';
    </update>
 
    <insert id="insertOtherValue" >
          insert into
            ${tableName}(
                DEL_FLAG,
                DATA_START,
              <foreach collection="valueListMap" index="o" separator="," >
                    ${o}
              </foreach>
        ) values(
                0,
                0,
            <foreach collection="valueListMap"  index="o" item="val" separator=",">
                #{val}
            </foreach>
        )
    </insert>
 
    <insert id="insert" parameterType="com.changhong.epc.bean.tenant.master.extend.GeneralMasterValue">
        INSERT INTO `epc_center`.`epc_master_value`
        ( `DEFINE_CODE`, `ELE_CODE`,
        `ELE_VALUE`, `ROW_NO`,
        `DEF1`, `DEF2`, `DEF3`,
        `DEF4`, `DEF5`, `DEL_FLAG`,
        `INS_P`, `INS_T`, `UPD_P`,
        `UPD_T`, `DATA_START`)
         VALUES
         (#{val.defineCode}, #{val.eleCode},
          #{val.eleValue}, #{val.rowNo},
          #{val.def1},  #{val.def2}, #{val.def3},
          #{val.def4}, #{val.def5},0,
          #{val.insP},#{val.insT},#{val.updP},
          #{val.updT},#{val.dataStart}
          );
 
    </insert>
 
    <update id="addTabelColumns">
         alter table ${tableName} add  ${code} varchar(100) default ""
    </update>
 
    <update id="updateMasterVal">
    UPDATE epc_master_value
    SET ELE_VALUE = #{mv.eleValue}
    WHERE
        DEFINE_CODE = #{mv.defineCode}
    AND ELE_CODE = #{mv.eleCode}
    AND ROW_NO = #{mv.rowNo}
 
    </update>
 
    <delete id="delMasterValue">
        DELETE
    FROM
        epc_master_value
    WHERE
        define_code = #{mv.defineCode}
    and
        row_no = #{mv.rowNo}
    </delete>
 
    <update id="updateOtherValue">
        update
          ${tableName}
        set
          <foreach collection="mv" item="val" index="key" separator=",">
              ${key}=#{val}
          </foreach>
        where
          define_code=#{defineCode} and row_no=#{rowNo}
    </update>
 
    <delete id="deleteOtherValue">
        delete from ${tableName}
        where define_code=#{defineCode} and row_no=#{rowNo}
    </delete>
 
    <select id="selectByRowNo" resultType="java.lang.Integer">
        select count(*) from
        epc_master_value
        where define_Code = #{defineCode}
        and row_no=#{no}
        and ele_code = #{eleCode}
    </select>
 
    <select id="selectTwoByRowNo" resultType="java.util.Map">
        select * from ${tableName} where row_no=#{no}
    </select>
 
    <select id="selectMasterValueList" parameterType="com.changhong.epc.bean.tenant.master.MasterValue" resultType="com.changhong.epc.bean.tenant.master.MasterValue">
        select
          ID id,
          DEFINE_CODE defineCode,
          ELE_CODE eleCode,
          ELE_VALUE eleValue,
          ROW_NO rowNo
        from epc_master_value
        where DEFINE_CODE = #{defineCode}
        and DEL_FLAG = 0
        ORDER BY ROW_NO
    </select>
 
    <select id="selectMaster2" resultType="java.util.Map">
        select
        <foreach collection="field" item="val" separator=",">
          ${val.tableField}
        </foreach>
        from ${name}
    </select>
 
 
    <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="value!=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>