Files
OpenPark/op-mapper/src/main/resources/mapper/generator/TableMapper.xml
王鹏 48822a3444 init
2025-08-14 14:32:37 +08:00

198 lines
5.6 KiB
XML

<?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="cn.feast.coding.mapper.generator.TableMapper">
<!-- Result Map -->
<resultMap id="baseResultMap" type="cn.feast.coding.model.generator.Table">
<result column="id" property="id"/>
<result column="table_name" property="tableName"/>
<result column="class_name" property="className"/>
<result column="show_name" property="showName"/>
<result column="show_style" property="showStyle"/>
<result column="project_id" property="projectId"/>
</resultMap>
<resultMap id="queryResultMap" type="cn.feast.coding.model.generator.Table">
<result column="id" property="id"/>
<result column="table_name" property="tableName"/>
<result column="class_name" property="className"/>
<result column="show_name" property="showName"/>
<result column="show_style" property="showStyle"/>
<result column="project_id" property="projectId"/>
</resultMap>
<!-- table name -->
<sql id="table_name">
t_table
</sql>
<!-- property table all fields -->
<sql id="base_column_list">
id,
table_name,
class_name,
show_name,
show_style,
project_id
</sql>
<sql id="update_clause">
<trim suffixOverrides=",">
<if test="tableName != null and tableName !=''">
table_name=#{tableName},
</if>
<if test="className != null and className !=''">
class_name=#{className},
</if>
<if test="showName != null and showName !=''">
show_name=#{showName},
</if>
<if test="showStyle != null">
show_style=#{showStyle},
</if>
<if test="projectId != null">
project_id=#{projectId},
</if>
</trim>
</sql>
<sql id="query_where_clause">
where 1=1
<trim suffixOverrides=",">
<if test="id != null">
and id=#{id}
</if>
<if test="tableName != null and tableName !=''">
and table_name=#{tableName}
</if>
<if test="className != null and className !=''">
and class_name=#{className}
</if>
<if test="showName != null and showName !=''">
and show_name=#{showName}
</if>
<if test="showStyle != null">
and show_style=#{showStyle}
</if>
<if test="projectId != null">
and project_id=#{projectId}
</if>
</trim>
</sql>
<insert id="save" parameterType="Object">
<selectKey resultType="java.lang.Integer" order="AFTER" keyProperty="id">
SELECT LAST_INSERT_ID() AS id
</selectKey>
insert into
<include refid="table_name"/>
(
table_name,
class_name,
show_name,
show_style,
project_id
)
values
(
#{tableName},
#{className},
#{showName},
#{showStyle},
#{projectId}
)
</insert>
<insert id="saveByBatch" parameterType="Object">
insert into
<include refid="table_name"/>
(
table_name,
class_name,
show_name,
show_style,
project_id
)
values
<foreach collection="list" item="t" separator=",">
(
#{t.tableName},
#{t.className},
#{t.showName},
#{t.showStyle},
#{t.projectId}
)
</foreach>
</insert>
<select id="queryById" resultMap="baseResultMap" parameterType="Object">
select
<include refid="base_column_list"/>
from
<include refid="table_name"/>
where id = #{id}
</select>
<select id="queryByProject" resultMap="baseResultMap" parameterType="Object">
select
<include refid="base_column_list"/>
from
<include refid="table_name"/>
where project_id = #{projectId}
</select>
<select id="queryByCount" resultType="java.lang.Integer" parameterType="Object">
select count(1) from
<include refid="table_name"/>
<include refid="query_where_clause"/>
</select>
<select id="queryByList" resultMap="baseResultMap" parameterType="Object">
select
<include refid="base_column_list"/>
from
<include refid="table_name"/>
<include refid="query_where_clause"/>
${pageQueryCondition}
</select>
<select id="queryByTable" resultMap="queryResultMap" parameterType="Object">
select
*
from
t_table t, t_project p
<include refid="query_where_clause"/>
and t.project_id = p.id
</select>
<update id="update" parameterType="Object">
update
<include refid="table_name"/>
set
<include refid="update_clause"/>
where id = #{id}
</update>
<update id="updateResult" parameterType="Object">
update
<include refid="table_name"/>
set
<include refid="update_clause"/>
where id = #{id}
</update>
<delete id="deleteById" parameterType="Object">
delete from
<include refid="table_name"/>
where id = #{id}
</delete>
<delete id="deleteProjectRelatedData" parameterType="Object">
delete
tt
from
t_table as tt, t_project as tp
where
tt.project_id = tp.id
and tp.id = #{projectId}
</delete>
</mapper>