<?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.matrix.system.common.dao.CustomerDataDictionaryDao">
|
<!-- 定义DataDictionary 的复杂关联map -->
|
<resultMap type="com.matrix.system.common.bean.CustomerDataDictionary"
|
id="CustomerDataDictionaryMap">
|
<id property="id" column="id" />
|
<result property="createBy" column="create_by" />
|
<result property="createTime" column="create_time" />
|
<result property="updateBy" column="update_by" />
|
<result property="updateTime" column="update_time" />
|
<result property="typeName" column="type_name" />
|
<result property="typeCode" column="type_code" />
|
<result property="value" column="value" />
|
<result property="parentId" column="parent_id" />
|
<result property="sort" column="sort" />
|
<result property="extValue" column="ext_value" />
|
<result property="companyId" column="company_id" />
|
<association property="parentTypeName" column="{id=parent_id}" select="selectNameById"></association>
|
</resultMap>
|
|
<select id="selectNameById" resultType="java.lang.String">
|
select type_name
|
from customer_data_dictionary
|
where id = #{id}
|
</select>
|
|
|
<!-- 字段sql -->
|
<sql id="columns">
|
create_by,
|
create_time,
|
update_by,
|
update_time,
|
id,
|
type_name,
|
type_code,
|
value,
|
parent_id,
|
sort,
|
ext_value,
|
company_id
|
</sql>
|
|
<!-- 属性sql -->
|
<sql id="propertys">
|
#{item.createBy},
|
now(),
|
#{item.updateBy},
|
now(),
|
#{item.id},
|
#{item.typeName},
|
#{item.typeCode},
|
#{item.value},
|
#{item.parentId},
|
#{item.sort},
|
#{item.extValue},
|
#{item.companyId}
|
</sql>
|
|
<!-- where sql -->
|
<sql id="where_sql">
|
|
<if test="record!=null">
|
<if
|
test="(record.id!=null and record.id!='') or (record.id!='' and record.id==0) ">
|
and id = #{record.id}
|
</if>
|
<if
|
test="(record.typeName!=null and record.typeName!='') or (record.typeName!='' and record.typeName==0) ">
|
and type_name like concat('%',#{record.typeName},'%')
|
</if>
|
<if
|
test="(record.typeCode!=null and record.typeCode!='') or (record.typeCode!='' and record.typeCode==0) ">
|
and type_code = #{record.typeCode}
|
</if>
|
<if
|
test="(record.value!=null and record.value!='') or (record.value!='' and record.value==0) ">
|
and value like concat('%',#{record.value},'%')
|
</if>
|
<if
|
test="(record.parentId!=null and record.parentId!='') or (record.parentId!='' and record.parentId==0) ">
|
and parent_id = #{record.parentId}
|
</if>
|
<if
|
test="(record.sort!=null and record.sort!='') or (record.sort!='' and record.sort==0) ">
|
and sort = #{record.sort}
|
</if>
|
<if
|
test="(record.extValue!=null and record.extValue!='') or (record.extValue!='' and record.extValue==0) ">
|
and ext_value = #{record.extValue}
|
</if>
|
<if
|
test="(record.companyId!=null and record.companyId!='') or (record.companyId!='' and record.companyId==0) ">
|
and company_id = #{record.companyId}
|
</if>
|
</if>
|
|
</sql>
|
|
<!-- 插入方法 -->
|
<insert id="insert"
|
parameterType="com.matrix.system.common.bean.CustomerDataDictionary"
|
useGeneratedKeys="true" keyProperty="item.id">
|
INSERT INTO customer_data_dictionary (
|
<include refid="columns"></include>
|
)
|
VALUES (
|
<include refid="propertys"></include>
|
)
|
</insert>
|
|
|
|
<!-- 批量插入 -->
|
<insert id="batchInsert" parameterType="java.util.List">
|
INSERT INTO customer_data_dictionary (
|
<include refid="columns"></include>
|
)
|
VALUES
|
<foreach collection="list" item="item" index="index"
|
separator=",">
|
(
|
<include refid="propertys"></include>
|
)
|
</foreach>
|
</insert>
|
|
|
|
|
|
<!-- 根据Map更新 部分更新 -->
|
<update id="updateByMap" parameterType="java.util.HashMap">
|
UPDATE customer_data_dictionary
|
<set>
|
<if test="_parameter.containsKey('typeName')">
|
type_name = #{typeName},
|
</if>
|
<if test="_parameter.containsKey('typeCode')">
|
type_code = #{typeCode},
|
</if>
|
<if test="_parameter.containsKey('value')">
|
value = #{value},
|
</if>
|
<if test="_parameter.containsKey('parentId')">
|
parent_id = #{parentId},
|
</if>
|
<if test="_parameter.containsKey('sort')">
|
sort = #{sort},
|
</if>
|
<if test="_parameter.containsKey('extValue')">
|
ext_value = #{extValue},
|
</if>
|
<if test="_parameter.containsKey('companyId')">
|
company_id = #{companyId},
|
</if>
|
</set>
|
WHERE id=#{id}
|
</update>
|
|
|
<!-- 根据对象更新 部分更新 -->
|
<update id="updateByModel" parameterType="String">
|
UPDATE customer_data_dictionary
|
<set>
|
<if test="record.typeName != null and record.typeName != '' ">
|
type_name = #{record.typeName},
|
</if>
|
<if test="record.typeCode != null and record.typeCode != '' ">
|
type_code = #{record.typeCode},
|
</if>
|
value = #{record.value},
|
<if test="record.parentId != null and record.parentId != '' ">
|
parent_id = #{record.parentId},
|
</if>
|
<if test="record.sort != null ">
|
sort = #{record.sort},
|
</if>
|
ext_value = #{record.extValue},
|
<if test="record.companyId != null and record.companyId != '' ">
|
company_id = #{record.companyId},
|
</if>
|
</set>
|
WHERE id=#{record.id}
|
</update>
|
|
<!-- 批量删除 -->
|
<delete id="deleteByIds" parameterType="java.util.List">
|
delete from customer_data_dictionary where id in
|
<foreach collection="list" index="index" item="item" open="("
|
separator="," close=")">
|
#{item}
|
</foreach>
|
</delete>
|
|
<!-- 根据id删除 -->
|
<delete id="deleteById" parameterType="String">
|
DELETE FROM
|
customer_data_dictionary
|
where id=#{id}
|
</delete>
|
|
<!-- 根据对象删除 -->
|
<delete id="deleteByModel"
|
parameterType="com.matrix.system.common.bean.CustomerDataDictionary">
|
DELETE FROM customer_data_dictionary
|
<where>
|
<include refid="where_sql"></include>
|
</where>
|
</delete>
|
|
|
|
<!-- 分页查询 -->
|
<select id="selectInPage" resultMap="CustomerDataDictionaryMap">
|
select
|
<include refid="columns"></include>
|
from customer_data_dictionary
|
<where>
|
<include refid="where_sql"></include>
|
</where>
|
<if test="pageVo !=null"><!-- 判断pageVo对象是否为空 -->
|
<if test="pageVo.sort !=null and pageVo.order !=null">
|
order by
|
${pageVo.sort} ${pageVo.order}
|
</if>
|
<if test="pageVo.offset >=0 and pageVo.limit >0">
|
limit
|
#{pageVo.offset},#{pageVo.limit}
|
</if>
|
</if>
|
</select>
|
|
<!-- 查询总条数 -->
|
<select id="selectTotalRecord" parameterType="long"
|
resultType="java.lang.Integer">
|
select count(*)
|
from customer_data_dictionary
|
<where>
|
<include refid="where_sql"></include>
|
</where>
|
</select>
|
|
<!-- 根据id查询 -->
|
<select id="selectById" resultMap="CustomerDataDictionaryMap">
|
select
|
<include refid="columns"></include>
|
from customer_data_dictionary
|
where id=#{id}
|
</select>
|
|
|
<!-- 根据id 锁表查询 -->
|
<select id="selectForUpdate" resultMap="CustomerDataDictionaryMap">
|
select
|
<include refid="columns"></include>
|
from customer_data_dictionary
|
where id=#{id}
|
for update
|
</select>
|
|
|
|
<!-- 根据对象查询 -->
|
<select id="selectByModel" resultMap="CustomerDataDictionaryMap">
|
select
|
<include refid="columns"></include>
|
from customer_data_dictionary
|
<where>
|
<include refid="where_sql"></include>
|
</where>
|
</select>
|
|
<!--查询发票内容接口 -->
|
<select id="selectByInvoiceContent" resultMap="CustomerDataDictionaryMap">
|
SELECT
|
<include refid="columns"></include>
|
FROM
|
customer_data_dictionary
|
WHERE
|
parent_id IN ( SELECT id FROM customer_data_dictionary WHERE type_code = 'invoice_content' )
|
ORDER BY sort ASC
|
</select>
|
|
<select id="selectByParentCode" resultMap="CustomerDataDictionaryMap">
|
select dd.* from
|
customer_data_dictionary dd, customer_data_dictionary pat
|
where dd.parent_id = pat.id and pat.type_code = #{parentCode} and dd.company_id=#{companyId}
|
order by dd.sort
|
</select>
|
|
<select id="selectByTypeCode" resultMap="CustomerDataDictionaryMap">
|
select
|
<include refid="columns"></include>
|
from customer_data_dictionary
|
where type_code=#{TypeCode}
|
</select>
|
</mapper>
|