1
0
mirror of https://github.com/FatttSnake/Pinnacle-OA.git synced 2026-04-06 07:21:24 +08:00
Files
Pinnacle-OA/Pinnacle/src/main/resources/mapper/DepartmentMapper.xml
2023-06-04 19:30:02 +08:00

86 lines
3.6 KiB
XML

<?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.cfive.pinnacle.mapper.DepartmentMapper">
<select id="getAllDepartment" resultType="department">
select id, name, tel, address, deleted, version
from t_department where deleted = 0
<if test="searchInput != null and searchInput != ''">
<choose>
<when test="searchType == 0">
<if test="searchRegex == 1">
and (
name regexp #{searchInput}
or tel regexp #{searchInput}
or address regexp #{searchInput}
)
</if>
<if test="searchRegex != 1">
and (
instr(name, #{searchInput}) > 0
or instr(tel, #{searchInput}) > 0
or instr(address, #{searchInput}) > 0
)
</if>
</when>
<when test="searchType == 1">
<if test="searchRegex == 1">
and name regexp #{searchInput}
</if>
<if test="searchRegex != 1">
and instr(name, #{searchInput}) > 0
</if>
</when>
<when test="searchType == 2">
<if test="searchRegex == 1">
and tel regexp #{searchInput}
</if>
<if test="searchRegex != 1">
and instr(tel, #{searchInput}) > 0
</if>
</when>
<when test="searchType == 3">
<if test="searchRegex == 1">
and address regexp #{searchInput}
</if>
<if test="searchRegex != 1">
and instr(address, #{searchInput}) > 0
</if>
</when>
</choose>
</if>
</select>
<select id="getDepartmentWithUser" resultMap="departmentWithUserMap">
select td.id as department_id, td.name as department_name
from (select * from t_department where deleted = 0) as td
</select>
<select id="getUserInDepartment" resultMap="userInDepartmentMap">
select tu.id as user_id,
tu.username as user_username,
ts.id as staff_id,
ts.first_name as staff_first_name,
ts.last_name as staff_last_name
from (select * from t_user where deleted = 0) as tu
left join (select * from t_staff where deleted = 0) as ts on ts.user_id = tu.id
where tu.department_id = #{department_id}
</select>
<resultMap id="departmentWithUserMap" type="department">
<id property="id" column="department_id"/>
<result property="name" column="department_name"/>
<collection property="userList" ofType="user" column="department_id" select="getUserInDepartment"/>
</resultMap>
<resultMap id="userInDepartmentMap" type="user">
<id property="id" column="user_id"/>
<result property="username" column="user_username"/>
<association property="staff" javaType="staff">
<id property="id" column="staff_id"/>
<result property="firstName" column="staff_first_name"/>
<result property="lastName" column="staff_last_name"/>
</association>
</resultMap>
</mapper>