xiaoyong931011
2020-11-25 adf7a921b6a0e3007ff15158252a085ff220c795
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
<?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.xcong.excoin.modules.login.dao.WtWalletDao">
    <!-- 定义WtWallet 的复杂关联map -->
    <resultMap type="com.xcong.excoin.modules.login.entity.WtWallet" id="WtWalletMap">
            <result property="privateKey" column="private_key" />
            <result property="mnemonicWords" column="mnemonic_words" />
            <result property="password" column="password" />
            <result property="walletName" column="wallet_name" />
            <result property="terminalId" column="terminal_Id" />
    </resultMap>
 
    
    <!-- 字段sql -->
    <sql id="columns">
            address,
            private_key,
            mnemonic_words,
            password,
            wallet_name,
            terminal_Id
    </sql>
    <sql id="simpleColumns">
            address,
            wallet_name
    </sql>
    
    <!-- 属性sql -->
    <sql id="propertys">
            #{item.address},
            #{item.privateKey},
            #{item.mnemonicWords},
            #{item.password},
            #{item.walletName},
            #{item.terminalId}
    </sql>
    
 
    
    <!--  插入方法   -->
    <insert id="insert" parameterType="com.xcong.excoin.modules.login.entity.WtWallet"
        useGeneratedKeys="true" keyProperty="item.address">
        INSERT INTO wt_wallet (
             <include refid="columns"></include>
        )
        VALUES (
         <include refid="propertys"></include>
    )
    </insert>
    
    
    
    <!--  批量插入   -->
    <insert id="batchInsert" parameterType="java.util.List">
        INSERT INTO wt_wallet (
        <include refid="columns"></include>    
        )
    VALUES 
    <foreach collection="list" item="item" index="index" separator=",">(
        <include refid="propertys"></include>    
    )</foreach>
    </insert>
    
    
    
    
    
 
    
    
    <!--  根据对象更新 部分更新   -->
    <update id="updateByModel" parameterType="String">
        UPDATE wt_wallet
        <set>
            <if test="record.password != null and record.password != '' ">
                password  = #{record.password}, 
            </if>
            <if test="record.walletName != null and record.walletName != '' ">
                wallet_name  = #{record.walletName}, 
            </if>
            <if test="record.terminalId != null and record.terminalId != '' ">
                terminal_Id  = #{record.terminalId}, 
            </if>
        </set>
        WHERE address=#{record.address} 
    </update>
    
    <!-- 批量删除 -->
    <delete id="deleteByIds" parameterType="java.util.List">
        delete from wt_wallet where  address in
        <foreach collection="list" index="index" item="item" open="("
            separator="," close=")">
            #{item}
        </foreach>
    </delete>
        
    <!-- 根据id删除-->
    <delete id="deleteById" parameterType="String">
        DELETE FROM wt_wallet
        where  address=#{address} 
    </delete>
    
 
    <!-- 根据id查询-->
    <select id="selectById" resultMap="WtWalletMap">
        select 
        <include refid="columns" ></include>
        from wt_wallet
        where  address=#{address} 
    </select>
    <select id="selectSimpleById" resultMap="WtWalletMap">
        select
        <include refid="simpleColumns" ></include>
        from wt_wallet
        where  address=#{address}
    </select>
 
    <select id="selectSimpleByTerminalId" resultMap="WtWalletMap">
        select
        <include refid="simpleColumns" ></include>
        from wt_wallet
        where  terminal_Id=#{terminalId}
        limit 1
    </select>
 
    <select id="selectByMnemonicWords" resultMap="WtWalletMap">
        select
            address,
            mnemonic_words,
            wallet_name,
            password,
            terminal_Id
        from wt_wallet
        where  mnemonic_words=#{mnemonic_words}
    </select>
 
    <update id="clearTerminalId" parameterType="string">
        update wt_wallet set   terminal_id = null where address = #{address}
    </update>
 
    <update id="deleteTerminal" parameterType="string">
        update wt_wallet set   terminal_Id = null where terminal_id = #{terminalId}
    </update>
 
</mapper>