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
161
162
163
164
<?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.wisenergy.mapper.UsersMapper">
<resultMap id="userMap" type="cn.wisenergy.model.app.User">
<id column="id" property="id"/>
<result column="user_name" property="userName"/>
<result column="password" property="password"/>
<result column="phone" property="phone"/>
<result column="head_image" property="headImage"/>
<result column="sex" property="sex"/>
<result column="school" property="school"/>
<result column="exam_type" property="examType"/>
<result column="source" property="source"/>
<result column="is_delete" property="isDelete"/>
<result column="create_time" property="createTime"/>
<result column="update_time" property="updateTime"/>
</resultMap>
<sql id="table">
user
</sql>
<sql id="cols_all">
id,
<include refid="cols_exclude_id"/>
</sql>
<sql id="cols_exclude_id">
user_name,password, phone,head_image,sex,school, exam_type,source,is_delete,create_time,update_time
</sql>
<sql id="vals">
#{userName},#{password},#{phone},#{headImage},#{sex},#{school},#{examType}, #{source},
#{isDelete},now(),now()
</sql>
<sql id="updateCondition">
<if test="userName != null">user_name = #{userName},</if>
<if test="password != null">password =#{password},</if>
<if test="phone != null">phone =#{phone},</if>
<if test="headImage != null">head_image =#{headImage},</if>
<if test="sex != null">sex =#{sex},</if>
<if test="school != null">school =#{school},</if>
<if test="examType != null">exam_type = #{examType},</if>
<if test="source != null">source = #{source},</if>
<if test="isDelete != null">is_delete = #{isDelete},</if>
update_time =now()
</sql>
<sql id="criteria">
<if test="id != null">id = #{id}</if>
<if test="userName != null">and user_name = #{userName}</if>
<if test="password != null">and password =#{password}</if>
<if test="phone != null">and phone =#{phone}</if>
<if test="headImage != null">and head_image =#{headImage}</if>
<if test="sex != null">and sex =#{sex}</if>
<if test="school != null">and school =#{school}</if>
<if test="examType != null">and exam_type = #{examType}</if>
<if test="source != null">and source = #{source}</if>
<if test="isDelete != null">and is_delete = #{isDelete}</if>
<if test="createTime != null">and create_time >= #{createTime}</if>
<if test="updateTime != null">and #{updateTime} >= update_time</if>
</sql>
<insert id="add" parameterType="cn.wisenergy.model.app.User" keyProperty="id" useGeneratedKeys="true">
insert into
<include refid="table"/>
(<include refid="cols_exclude_id"/>)
value(
<include refid="vals"/>
)
</insert>
<update id="edit" parameterType="cn.wisenergy.model.app.User">
UPDATE
<include refid="table"/>
<set>
<include refid="updateCondition"/>
</set>
<where>
id = #{id}
</where>
</update>
<delete id="delById" parameterType="java.lang.Integer">
delete from
<include refid="table"/>
where id = #{id}
</delete>
<select id="countByPhoneAnsUserId" resultType="java.lang.Integer">
SELECT COUNT(1)
FROM
<include refid="table"/>
WHERE phone=#{phone} and id !=#{userId} and is_delete=0
</select>
<select id="getList" resultMap="userMap" parameterType="map">
select
<include refid="cols_all"/>
from
<include refid="table"/>
<where>
is_delete=0
<if test="startTime != null">
and create_time
between #{startTime}
</if>
<if test="endTime != null">and #{endTime}</if>
<if test="userName != null">and user_name like ('%' #{userName} '%')</if>
<if test="phone != null">and phone like ('%' #{phone} '%')</if>
order by create_time desc
limit #{pageNo},#{pageSize}
</where>
</select>
<select id="getUserNumbers" resultType="java.lang.Integer">
SELECT COUNT(id)
FROM
<include refid="table"/>
<where>
is_delete=0
<if test="startTime != null">
and create_time
between #{startTime}
</if>
<if test="endTime != null">and #{endTime}</if>
<if test="userName != null">and user_name like ('%' #{userName} '%')</if>
<if test="phone != null">and phone like ('%' #{phone} '%')</if>
</where>
</select>
<select id="getByPhone" resultType="cn.wisenergy.model.app.User">
SELECT
<include refid="cols_all"/>
FROM
<include refid="table"/>
where is_delete=0 and phone=#{phone}
</select>
<select id="test" resultType="cn.wisenergy.model.app.User">
select
<include refid="cols_all"/>
from
<include refid="table"/>
<where>
<if test="list != null">
<foreach collection="list" index="index" item="id" separator="or" open="(" close=")">
user_name LIKE CONCAT('%',#{id},'%')
</foreach>
</if>
</where>
</select>
</mapper>