UsernameMapper.xml
4.14 KB
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
<?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.runsa.portal.base.dao.UsernameMapper" >
<resultMap id="BaseResultMap" type="cn.runsa.portal.base.entity.Username" >
<id column="usnId" property="id"></id>
<result column="usId" property="usid" jdbcType="INTEGER" />
<result column="usnName" property="name" jdbcType="VARCHAR" />
<result column="usnType" property="type" jdbcType="SMALLINT" />
<result column="emId" property="emid" jdbcType="INTEGER" />
<result column="usnValid" property="valid" jdbcType="BIT" />
</resultMap>
<insert id="insert" parameterType="cn.runsa.portal.base.entity.Username" >
insert into smUsername (usId, usnName, usnType,
emId, usnValid)
values (#{usid,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{type,jdbcType=SMALLINT},
#{emid,jdbcType=INTEGER}, #{valid,jdbcType=BIT})
</insert>
<insert id="insertSelective" parameterType="cn.runsa.portal.base.entity.Username" >
insert into smUsername
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="usid != null" >
usId,
</if>
<if test="name != null" >
usnName,
</if>
<if test="type != null" >
usnType,
</if>
<if test="emid != null" >
emId,
</if>
<if test="valid != null" >
usnValid,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="usid != null" >
#{usid,jdbcType=INTEGER},
</if>
<if test="name != null" >
#{name,jdbcType=VARCHAR},
</if>
<if test="type != null" >
#{type,jdbcType=SMALLINT},
</if>
<if test="emid != null" >
#{emid,jdbcType=INTEGER},
</if>
<if test="valid != null" >
#{valid,jdbcType=BIT},
</if>
</trim>
</insert>
<update id="updateValid" parameterType="cn.runsa.portal.base.entity.Username" >
update smUsername set usnValid = #{valid,jdbcType=BIT} where usnName = #{name,jdbcType=VARCHAR}
</update>
<select id="selectAll" parameterType="cn.runsa.portal.base.entity.Username" resultMap="BaseResultMap">
select * from smUsername
<where>
<if test="emid != null">
and emId = #{emid}
</if>
<if test="type != null">
and usnType = #{type}
</if>
<if test="name != null">
and usnName = #{name}
</if>
<if test="valid != null">
and usnValid = #{valid}
</if>
</where>
order by emId asc,usnType asc
</select>
<select id="selectAllByUsername" resultMap="BaseResultMap">
SELECT t1.* FROM smUsername t1
INNER JOIN smUsername t2 ON t1.emId=t2.emId and t2.usnName=#{username}
INNER JOIN mtEmployee t3 on t1.emId=t3.emId and now() between ifnull(t3.emEntryDate,now()) and ifnull(t3.emLeaveDate,now())
WHERE t1.usnValid=1 and exists(
SELECT 1 FROM smUsers
WHERE emId=t1.emId AND now() between ifnull(usStartDate,now()) and ifnull(usEndDate,now()) AND ptValid=1 AND usFrozen=0
)
<if test="null!=type">
AND t1.usnType=#{type}
</if>
ORDER BY usnType DESC
</select>
<select id="existsByName" resultType="java.lang.Integer" parameterType="cn.runsa.portal.base.entity.Username">
SELECT count(*) FROM smUsername usn
LEFT JOIN smUsers us ON us.emId = usn.emId
WHERE usn.usnType=#{type} AND usn.usnName =#{name,jdbcType=VARCHAR} AND usn.usnValid = #{valid,jdbcType=BIT}
</select>
<select id="selectById" parameterType="java.lang.Integer" resultMap="BaseResultMap">
SELECT t1.* FROM smUsername t1 where usnId=#{id}
</select>
<select id="selectPhoneOrEmailByUsername" resultMap="BaseResultMap">
SELECT t1.* FROM smUsername t1
INNER JOIN smUsername t2 ON t1.emId=t2.emId and t2.usnName=#{username}
INNER JOIN mtEmployee t3 on t1.emId=t3.emId and now() between ifnull(t3.emEntryDate,now()) and ifnull(t3.emLeaveDate,now())
WHERE t1.usnValid=1 and exists(
SELECT 1 FROM smUsers
WHERE emId=t1.emId AND now() between ifnull(usStartDate,now()) and ifnull(usEndDate,now()) AND ptValid=1 AND usFrozen=0
)
AND t1.usnType IN (2,3) and t1.usnName=#{username}
ORDER BY usnType DESC
</select>
</mapper>