田源
2024-12-03 e973fb747f0d1a382fb9e4cdb20383a0a546ef67
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
<?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="${mapperPackage}.${className}Mapper">
    #set($jin="#{")
    #set($dao ="${")
    #set($newline="
")
    <resultMap id="BaseResultMap" type="${doPackage}.${className}DO">
        <id column="OID" jdbcType="VARCHAR" property="oid" />
#foreach($attr in $attributes)
#if($attr.id != "oid")
        <result column="$attr.idUpper" property="$attr.id"  jdbcType="$attr.jdbcType"/>
#end
#end
    </resultMap>
    <resultMap id="BaseResultMapHasRefer" type="${doPackage}.${className}DO" extends="BaseResultMap">
#foreach($attr in $referAttributes)
        <result column="$attr.idUpper" property="$attr.id"  jdbcType="$attr.jdbcType"/>
#end
    </resultMap>
    <sql id="base_query_column">
#foreach($attr in $attributes)
        $attr.idUpper #if($foreach.hasNext),#end #if($velocityCount%5==0) $newline #end
#end
    </sql>
    <sql id="tableName">
        ${tableName}
    </sql>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.String" >
        delete from <include refid="tableName"/>
        where OID = $jin oid,jdbcType=VARCHAR}
    </delete>
    <insert id="insert" parameterType="${doPackage}.${className}DO" >
        insert into <include refid="tableName"/> (
#foreach($attr in $attributes) $attr.idUpper #if($foreach.hasNext),#end #if($velocityCount%5==0) $newline #end
#end    )
        values (
#foreach($attr in $attributes)
        $jin $attr.id,jdbcType=$attr.jdbcType}#if($foreach.hasNext),#end #if($velocityCount%5==0) $newline #end
#end )
    </insert>
    <insert id="batchInsert" useGeneratedKeys="false" >
        insert into <include refid="tableName"/> (
        #foreach($attr in $attributes) $attr.idUpper #if($foreach.hasNext),#end #if($velocityCount%5==0) $newline #end
        #end    )
        <foreach collection="records" item="item" separator="union all" >
        (select
        #foreach($attr in $attributes)
            $jin item.$attr.id,jdbcType=$attr.jdbcType}#if($foreach.hasNext),#end #if($velocityCount%5==0) $newline #end
        #end
        FROM DUAL)
        </foreach>
    </insert>
    <update id="updateByPrimaryKey" parameterType="${doPackage}.${className}DO" >
    update  <include refid="tableName"/> set
#foreach($attr in $attributes)
#if($attr.id !="oid")
    $attr.idUpper = $jin $attr.id,jdbcType=$attr.jdbcType}#if($foreach.hasNext),#end #if($velocityCount%5==0) $newline #end
#end
#end
    where OID = $jin oid,jdbcType=VARCHAR}
    </update>
    <update id="batchUpdate" parameterType="java.util.Collection">
        <foreach collection="records" item="item" index="index" open="begin" close=";end;" separator=";">
        update  <include refid="tableName"/> set
        #foreach($attr in $attributes)
            #if($attr.id !="oid")
                $attr.idUpper = $jin item.$attr.id,jdbcType=$attr.jdbcType}#if($foreach.hasNext),#end #if($velocityCount%5==0) $newline #end
            #end
        #end
        where OID = $jin item.oid,jdbcType=VARCHAR}
        </foreach>
    </update>
    <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String" >
        select <include refid="base_query_column"/>
        from <include refid="tableName"/>
        where OID = $jin oid,jdbcType=VARCHAR}
    </select>
    <select id="selectByPrimaryKeys" resultMap="BaseResultMap">
        select <include refid="base_query_column" />
        from <include refid="tableName" />
        where OID in ( $dao oids,jdbcType=VARCHAR})
    </select>
    <select id="selectByPrimaryKeyCollection" resultMap="BaseResultMap">
        select <include refid="base_query_column" />
        from <include refid="tableName" />
        <where>
            <foreach collection="oids" item="item" index="arrayindex" open=" OID in ( " close=")" >
                $jin item,jdbcType=VARCHAR}
                <if test="(arrayindex != oids.size() -1)">
                    ,
                </if>
            </foreach>
        </where>
    </select>
    <select id="selectAll" resultMap="BaseResultMap" >
        select <include refid="base_query_column"/>
        from <include refid="tableName"/>
    </select>
    <select id="selectByWrapper" resultMap="BaseResultMap">
        $dao wrapper.selectFieldSql} from <include refid="tableName"/> $dao wrapper.tableNick} $dao wrapper.linkTableSql}
        <where>
            $dao wrapper.whereSql}
        </where>
    </select>
    <select id="countByWrapper" resultType="java.lang.Long">
        select count(*) from ( $dao wrapper.selectFieldSql} from <include refid="tableName"/> $dao wrapper.tableNick} $dao wrapper.linkTableSql}
        <where>
            $dao wrapper.whereSql}
        </where> )
    </select>
    <select id="selectNameByOid" resultType="java.lang.String">
        select NAME from <include refid="tableName" />
        where OID = $jin oid,jdbcType=VARCHAR}
    </select>
    <delete id="batchDeleteByOids" >
        delete from <include refid="tableName" />
        <where>
            <foreach collection="oids" item="item" index="arrayindex" open=" oid in ( " close=")" >
                $jin item,jdbcType=VARCHAR}
                <if test="(arrayindex != oids.size() -1)">
                    ,
                </if>
            </foreach>
        </where>
    </delete>
#if(${hasEnable})
    <update id="batchUpdateLcStatus" >
        update <include refid="tableName"/>
        set lcstatus = $jin lcStatus,jdbcType=VARCHAR}, ts=sysdate
        where
        <foreach collection="oids" item="item" index="arrayindex" open=" oid in ( " close=")" >
            $jin item,jdbcType=VARCHAR}
            <if test="(arrayindex != oids.size() -1)">
                ,
            </if>
        </foreach>
    </update>
    <update id="updateLcStatus">
        update <include refid="tableName"/>
        set lcstatus = $jin lcStatus,jdbcType=VARCHAR}, ts=sysdate
        where oid =$jin oid,jdbcType=VARCHAR}
    </update>
#end
#if(${hasParentField})
    <select id="selectAllLevelChild" parameterType="java.lang.String" resultMap="BaseResultMap">
        select <include refid="base_query_column"/> FROM <include refid="tableName"/>
        START WITH ${parentFieldName} = $jin oid,jdbcType=VARCHAR} CONNECT BY PRIOR OID=${parentFieldName}
    </select>
    <select id="selectAllLevelChildOid" parameterType="java.lang.String" resultType="java.lang.String">
        select OID FROM <include refid="tableName"/>
        START WITH ${parentFieldName} = $jin oid,jdbcType=VARCHAR} CONNECT BY PRIOR OID=${parentFieldName}
    </select>
    <select id="countAllLevelChildOid" resultType="java.lang.Long">
        select count(OID) FROM <include refid="tableName"/>
        START WITH ${parentFieldName} = $jin oid,jdbcType=VARCHAR} CONNECT BY PRIOR OID=${parentFieldName}
    </select>
#end
</mapper>