cm-cloud/cloud-common-plugin-dynamic/src/main/resources/templates/codetemplate/default/mapper/mapper.ftl

116 lines
4.2 KiB
Plaintext
Raw Normal View History

<?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="${basePackage}.dao.${lowerTableName}.I${firstUpperTableName}Dao">
<resultMap id="${firstLowerTableName}DTO" type="${basePackage}.pojo.dtos.${lowerTableName}.${firstUpperTableName}DTO">
<id property="${firstLowerTableName}Id" column="${underLineTableName}_id"/>
<#list fieldList! as field>
<result property="${field.fieldName}" column="${field.underLineFieldName}"/>
</#list>
</resultMap>
<!-- 新增${tableExplain} -->
<insert id="save${firstUpperTableName}" parameterType="map">
INSERT INTO ${tablePrefix}${underLineTableName}(
${underLineTableName}_id,
<#list fieldList! as field>
${field.underLineFieldName},
</#list>
creator,
gmt_create,
modifier,
gmt_modified,
is_delete
) VALUES(
${r"#{"}${firstLowerTableName}Id${r"}"},
<#list fieldList! as field>
${r"#{"}${field.fieldName}${r"}"},
</#list>
${r"#{creator}"},
${r"#{gmtCreate}"},
${r"#{modifier}"},
${r"#{gmtModified}"},
${r"#{isDelete}"}
)
</insert>
<!-- 删除${tableExplain} -->
<update id="remove${firstUpperTableName}" parameterType="map">
UPDATE
${tablePrefix}${underLineTableName}
SET
is_delete = 1,
modifier = ${r"#{modifier}"},
gmt_modified = ${r"#{gmtModified}"}
WHERE
${underLineTableName}_id IN
<foreach collection="${firstLowerTableName}Ids" index="index" open="(" separator="," close=")">
${r"#{"}${firstLowerTableName}${r"Ids[${index}]}"}
</foreach>
</update>
<!-- 修改${tableExplain} -->
<update id="update${firstUpperTableName}" parameterType="map">
UPDATE
${tablePrefix}${underLineTableName}
SET
<#list fieldList! as field>
<#if field.fieldType == "number" || field.fieldType == "double">
<if test="${field.fieldName} != null">
${field.underLineFieldName} = ${r"#{"}${field.fieldName}${r"}"},
</if>
<#else>
<if test="${field.fieldName} != null ${field.fieldName} != ''">
${field.underLineFieldName} = ${r"#{"}${field.fieldName}${r"}"},
</if>
</#if>
</#list>
modifier = ${r"#{modifier}"},
gmt_modified = ${r"#{gmtModified}"}
WHERE
${underLineTableName}_id = ${r"#{"}${firstLowerTableName}${r"Id}"}
</update>
<!-- ${tableExplain}详情 -->
<select id="get${firstUpperTableName}" parameterType="map" resultMap="${firstLowerTableName}DTO">
SELECT
t1.*
FROM
${tablePrefix}${underLineTableName} t1
WHERE
t1.is_delete = 0
<if test="${firstLowerTableName}Id != null and ${firstLowerTableName}Id != ''">
AND
t1.${underLineTableName}_id = ${r"#{"}${firstLowerTableName}${r"Id}"}
</if>
</select>
<!-- ${tableExplain}列表 -->
<select id="list${firstUpperTableName}" parameterType="map" resultMap="${firstLowerTableName}DTO">
SELECT
t1.*
FROM
${tablePrefix}${underLineTableName} t1
WHERE
t1.is_delete = 0
<if test="keywords != null and keywords != ''">
<!-- 这里添加检索关键字 -->
</if>
<if test="startTime != null and startTime != ''">
AND
LEFT(t1.gmt_create, 10) <![CDATA[ >= ]]> ${r"#{startTime}"}
</if>
<if test="endTime != null and endTime != ''">
AND
LEFT(t1.gmt_create, 10) <![CDATA[ <= ]]> ${r"#{endTime}"}
</if>
<if test="${firstLowerTableName}Ids != null and ${firstLowerTableName}Ids.size > 0">
AND
t1.${underLineTableName}_id IN
<foreach collection="${firstLowerTableName}Ids" index="index" open="(" separator="," close=")">
${r"#{"}${firstLowerTableName}${r"Ids[${index}]}"}
</foreach>
</if>
</select>
</mapper>