<?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.mindskip.xzs.repository.DepartmentMapper">
|
<resultMap id="BaseResultMap" type="com.mindskip.xzs.domain.Department">
|
<id column="id" jdbcType="INTEGER" property="id"/>
|
<result column="name" jdbcType="VARCHAR" property="name"/>
|
<result column="deleted" jdbcType="VARCHAR" property="deleted"/>
|
</resultMap>
|
|
<sql id="Base_Column_List">
|
id
|
, name,deleted
|
</sql>
|
|
<insert id="add" parameterType="com.mindskip.xzs.domain.Department" useGeneratedKeys="true" keyProperty="id">
|
insert into t_department (name, deleted)
|
values (#{name,jdbcType=VARCHAR}, #{deleted,jdbcType=VARCHAR})
|
</insert>
|
|
<update id="update" parameterType="com.mindskip.xzs.domain.Department">
|
update t_department
|
<set>
|
<if test="name != null">
|
name = #{name,jdbcType=VARCHAR},
|
</if>
|
<if test="adminId != null">
|
admin_id = #{adminId},
|
</if>
|
<if test="deleted != null">
|
deleted = #{deleted,jdbcType=VARCHAR},
|
</if>
|
</set>
|
where id = #{id,jdbcType=INTEGER}
|
</update>
|
|
<select id="gets" resultMap="BaseResultMap">
|
SELECT
|
td.id,
|
td.name
|
FROM
|
t_department td
|
WHERE
|
td.deleted = 0
|
<if test="deptId != null and deptId.size() > 0">
|
AND td.id in <foreach collection="deptId" item="item" index="index" open="(" separator="," close=")"> #{item} </foreach>
|
</if>
|
</select>
|
|
<select id="getById" resultMap="BaseResultMap">
|
SELECT
|
td.id,
|
td.name
|
FROM
|
t_department td
|
WHERE
|
td.id = #{id} AND td.deleted = 0
|
</select>
|
|
<resultMap id="pageResult" type="com.mindskip.xzs.viewmodel.admin.department.DepartmentResponseVM">
|
<id column="id" property="id"/>
|
<result column="name" property="name"/>
|
<collection column="id" property="adminIds" ofType="integer" select="selectUserIdsByDeptId"></collection>
|
<collection column="id" property="adminNames" ofType="integer" select="selectUserNamesByDeptId"></collection>
|
</resultMap>
|
|
<select id="selectUserIdsByDeptId" resultType="integer">
|
SELECT
|
tu.id
|
FROM
|
t_user_department tud
|
INNER JOIN t_user tu ON tud.user_id = tu.id AND tud.department_id = #{deptId} AND tu.status = 1 AND deleted = 0 AND tud.dept_admin = 1
|
</select>
|
|
<select id="selectUserNamesByDeptId" resultType="string">
|
SELECT
|
tu.real_name
|
FROM
|
t_user_department tud
|
INNER JOIN t_user tu ON tud.user_id = tu.id AND tud.department_id = #{deptId} AND tu.status = 1 AND deleted = 0 AND tud.dept_admin = 1
|
</select>
|
|
<select id="page" resultMap="pageResult"
|
parameterType="com.mindskip.xzs.viewmodel.admin.department.DepartmentResponseVM">
|
SELECT
|
td.id,
|
td.name
|
FROM
|
t_department td
|
<where>
|
AND td.deleted = 0
|
<if test="id != null ">
|
AND td.id= #{id}
|
</if>
|
<if test="name != null ">
|
AND td.name like concat('%',#{name},'%')
|
</if>
|
|
</where>
|
</select>
|
|
<select id="getName" resultMap="BaseResultMap">
|
SELECT
|
td.id,
|
td.name,
|
td.admin_id as adminId,
|
tu.real_name as adminName
|
FROM
|
t_department td
|
LEFT JOIN t_user tu ON td.admin_id = tu.id AND tu.deleted = 0
|
WHERE
|
td.name = #{name} AND td.deleted = 0
|
</select>
|
|
<select id="selectByAdminId" resultType="integer">
|
SELECT id FROM t_department WHERE admin_id = #{userId} AND deleted = 0
|
</select>
|
|
<select id="countByAdminId" resultType="integer">
|
SELECT count(*) FROM t_department WHERE admin_id = #{userId} AND deleted = 0 AND id != #{id}
|
</select>
|
|
</mapper>
|