<select id="entranceCardList" resultType="****************************************************************">
SELECT
g.id,
g.cardCode,
c.cardType,
c.status,
c.userType,
CONCAT(DATE_FORMAT(c.beginTime,'%Y-%m-%d %H:%i'),' 至 ',DATE_FORMAT(c.endTime,'%Y-%m-%d %H:%i')) AS authorizeTime,
CASE WHEN c.userType = '01' THEN u.employeeName
WHEN c.userType = '02' THEN v.visitorName
END as usePerson
FROM rece_guard_door as g LEFT JOIN rece_card_authorize as c ON g.id = c.cardIds
LEFT JOIN info_employee_user as u ON u.id = c.personId AND c.userType = '01'
LEFT JOIN info_visitor_record as v ON v.id = c.personId AND c.userType = '02'
<where>
c.`status` != '04'
<if test="userType != null and userType !=''">
and c.userType = #{userType}
</if>
<if test="cardCode != null and cardCode !=''">
and g.cardCode = #{cardCode}
</if>
<if test="keyWord != null and keyWord !=''">
and CONCAT(IFNULL(c.userType,''),IFNULL(u.employeeName,''),IFNULL(v.visitorName ,'')) LIKE CONCAT('%',#{keyWord},'%')
</if>
</where>
ORDER BY
<if test="orderStr != null and orderStr != ''">
${orderStr},
</if>
g.cardCode
limit #{start},#{limit}
</select>
sql 了解一下
猜你喜欢
转载自blog.csdn.net/xiaokai123_/article/details/88071789
今日推荐
周排行