<?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>
|