liujie
2026-09-21 20051550f01227ecebbe0bf064e188dd242f58f2
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
165
166
167
168
169
170
171
172
173
174
175
176
<?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.ruoyi.system.mapper.SysCardMapper">
 
    <resultMap type="SysCard" id="SysCardResult">
        <id property="cardId" column="card_id" />
        <result property="cardNo" column="card_no" />
        <result property="employeeId" column="employee_id" />
        <result property="delFlag" column="del_flag" />
        <result property="createBy" column="create_by" />
        <result property="createTime" column="create_time" />
        <result property="updateBy" column="update_by" />
        <result property="updateTime" column="update_time" />
    </resultMap>
 
    <resultMap type="SysCardVO" id="SysCardVOResult">
        <id property="cardId" column="card_id" />
        <result property="cardNo" column="card_no" />
        <result property="employeeId" column="employee_id" />
        <result property="employeeName" column="employee_name" />
        <result property="contactPhone" column="contact_phone_cipher" />
        <result property="deptId" column="dept_id" />
        <result property="deptName" column="dept_name" />
        <result property="bindTime" column="bind_time" />
        <result property="bound" column="bound" />
    </resultMap>
 
    <sql id="selectCardVo">
        select c.card_id,
               c.card_no,
               c.employee_id,
               e.employee_name,
               e.contact_phone_cipher,
               e.dept_id,
               d.dept_name,
               c.bind_time,
               case when c.employee_id is not null then 1 else 0 end as bound
        from t_card c
        left join t_employee e on e.employee_id = c.employee_id and e.del_flag = '0'
        left join sys_dept d on d.dept_id = e.dept_id and d.del_flag = '0'
    </sql>
 
    <select id="pageList" resultMap="SysCardVOResult">
        <include refid="selectCardVo" />
        <where>
            c.del_flag = '0'
            <if test="query.cardNo != null and query.cardNo != ''">
                and c.card_no like concat('%', #{query.cardNo}, '%')
            </if>
            <if test="query.employeeName != null and query.employeeName != ''">
                and e.employee_name like concat('%', #{query.employeeName}, '%')
            </if>
            <if test="query.bound != null and query.bound">
                and c.employee_id is not null
            </if>
            <if test="query.bound != null and !query.bound">
                and c.employee_id is null
            </if>
        </where>
        order by c.bind_time desc, c.card_id desc
    </select>
 
    <select id="selectList" resultMap="SysCardVOResult">
        <include refid="selectCardVo" />
        <where>
            c.del_flag = '0'
            <if test="query.cardNo != null and query.cardNo != ''">
                and c.card_no like concat('%', #{query.cardNo}, '%')
            </if>
            <if test="query.employeeName != null and query.employeeName != ''">
                and e.employee_name like concat('%', #{query.employeeName}, '%')
            </if>
            <if test="query.bound != null and query.bound">
                and c.employee_id is not null
            </if>
            <if test="query.bound != null and !query.bound">
                and c.employee_id is null
            </if>
        </where>
        order by c.bind_time desc, c.card_id desc
    </select>
 
    <select id="selectVoById" parameterType="Long" resultMap="SysCardVOResult">
        <include refid="selectCardVo" />
        where c.card_id = #{cardId}
          and c.del_flag = '0'
    </select>
 
    <select id="selectById" parameterType="Long" resultMap="SysCardResult">
        select card_id, card_no, employee_id, del_flag, create_by, create_time, update_by, update_time
        from t_card
        where card_id = #{cardId}
          and del_flag = '0'
    </select>
 
    <select id="selectByCardNo" resultMap="SysCardResult">
        select card_id, card_no, employee_id, del_flag, create_by, create_time, update_by, update_time
        from t_card
        where card_no = #{cardNo}
          and del_flag = '0'
        limit 1
    </select>
 
    <select id="selectByEmployeeId" resultMap="SysCardResult">
        select card_id, card_no, employee_id, del_flag, create_by, create_time, update_by, update_time
        from t_card
        where employee_id = #{employeeId}
          and del_flag = '0'
        limit 1
    </select>
 
    <insert id="insertCard" parameterType="SysCard" useGeneratedKeys="true" keyProperty="cardId">
        insert into t_card (card_no, employee_id, bind_time, create_by, create_time)
        values (#{cardNo}, #{employeeId},
                <choose>
                    <when test="employeeId != null">sysdate()</when>
                    <otherwise>null</otherwise>
                </choose>,
                #{createBy}, sysdate())
    </insert>
 
    <update id="updateCard" parameterType="SysCard">
        update t_card
        set card_no = #{cardNo},
            update_by = #{updateBy},
            update_time = sysdate()
        where card_id = #{cardId}
          and del_flag = '0'
    </update>
 
    <update id="bindCard">
        update t_card
        set employee_id = #{employeeId},
            bind_time = sysdate(),
            update_by = #{updateBy},
            update_time = sysdate()
        where card_id = #{cardId}
          and del_flag = '0'
    </update>
 
    <update id="unbindByEmployeeId">
        update t_card
        set employee_id = null,
            bind_time = null,
            update_by = #{updateBy},
            update_time = sysdate()
        where employee_id = #{employeeId}
          and del_flag = '0'
    </update>
 
    <update id="unbindByCardNo">
        update t_card
        set employee_id = null,
            bind_time = null,
            update_by = #{updateBy},
            update_time = sysdate()
        where card_no = #{cardNo}
          and del_flag = '0'
    </update>
 
    <update id="deleteByIds">
        update t_card
        set employee_id = null,
            bind_time = null,
            del_flag = '1',
            update_by = #{updateBy},
            update_time = sysdate()
        where del_flag = '0'
          and card_id in
        <foreach collection="cardIds" item="cardId" open="(" separator="," close=")">
            #{cardId}
        </foreach>
    </update>
</mapper>