<?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.thhy.staff.modules.biz.group.mapper.GroupMapper">
|
|
<!-- 通用查询结果列 -->
|
<sql id="Base_Column_List">
|
t.group_id as groupId,
|
t.depart_id as departId,
|
t.group_name as groupName,
|
t.create_time as createTime,
|
t.create_user as createUser,
|
t.update_time as updateTime,
|
t.update_user as updateUser
|
</sql>
|
|
<sql id="condition_query">
|
<where>
|
<trim suffixOverrides=" AND ">
|
<if test="departId!=null and departId!=''">
|
t.depart_id = #{departId} AND
|
</if>
|
<if test="groupName!=null and groupName!=''">
|
t.group_name = #{groupName} AND
|
</if>
|
<if test="createTime!=null">
|
t.create_time = #{createTime} AND
|
</if>
|
<if test="createUser!=null and createUser!=''">
|
t.create_user = #{createUser} AND
|
</if>
|
<if test="updateTime!=null">
|
t.update_time = #{updateTime} AND
|
</if>
|
<if test="updateUser!=null and updateUser!=''">
|
t.update_user = #{updateUser} AND
|
</if>
|
</trim>
|
</where>
|
</sql>
|
|
<select id="queryById" resultType="com.thhy.staff.modules.biz.group.entity.Group">
|
select <include refid="Base_Column_List" />
|
from sys_group t
|
where t.group_id=#{groupId}
|
</select>
|
|
<select id="queryVersionById" resultType="integer">
|
select version from sys_group
|
where group_id=#{groupId}
|
</select>
|
|
<!--查询列表-->
|
<select id="findList" resultType="com.thhy.staff.modules.biz.group.entity.GroupListVo">
|
select b.*,spu.real_name as groupAdminName,sd.depart_name as departName from (
|
select a.*,(select user_id from sys_group_user where group_id = a.groupId and is_admin = 1) as groupAdmin,
|
(select count(sgu.group_id)
|
from sys_group_user sgu
|
left join sys_plat_user spu on spu.user_id = sgu.user_id
|
left join sys_group sg on sg.group_id = sgu.group_id
|
where sgu.group_id = a.groupId and sgu.is_use = 1 and sg.is_use = 1 and spu.is_use = 1 ) as groupUserCount
|
|
from
|
(SELECT
|
t.group_id as groupId,
|
t.depart_id as departId,
|
t.group_name as groupName
|
from sys_group t
|
left join sys_com_depart scd on scd.depart_id = t.depart_id
|
where t.is_use=1 and scd.company_id = #{companyId}
|
<if test="groupName != null and groupName !=''">
|
AND t.group_name LIKE concat('%',#{groupName},'%')
|
</if>
|
) a) b
|
left join sys_plat_user spu on spu.user_id = b.groupAdmin
|
left join sys_depart sd on sd.depart_id = b.departId
|
</select>
|
|
<!--查询列表-->
|
<select id="queryGroupInfo" resultType="com.thhy.staff.modules.biz.group.entity.GroupListVo">
|
select b.*,spu.real_name as groupAdminName,sd.depart_name as departName from (
|
select a.*,(select user_id from sys_group_user where group_id = a.groupId and is_admin = 1) as groupAdmin,
|
(select count(group_id) from sys_group_user where group_id = a.groupId and is_use = 1) as groupUserCount
|
|
from
|
(SELECT
|
t.group_id as groupId,
|
t.depart_id as departId,
|
t.group_name as groupName
|
from sys_group t
|
where t.is_use=1 and t.group_id = #{groupId}) a) b
|
left join sys_plat_user spu on spu.user_id = b.groupAdmin
|
left join sys_depart sd on sd.depart_id = b.departId
|
</select>
|
|
<select id="queryGroupUserList" resultType="com.thhy.staff.modules.biz.group.entity.GroupPlatUserVo">
|
select spu.user_id as userId,spu.sex,spu.real_name as realName,spu.phone,sgu.is_admin as isAdmin
|
from sys_group_user sgu
|
left join sys_plat_user spu on sgu.user_id = spu.user_id
|
where sgu.is_use = 1 and sgu.group_id = #{groupId}
|
<if test="realName !=null and realName !=''">
|
and spu.real_name LIKE concat('%',#{realName},'%')
|
</if>
|
</select>
|
|
<!--查询列表-->
|
<select id="findAll" resultType="com.thhy.staff.modules.biz.group.entity.Group">
|
SELECT
|
<include refid="Base_Column_List" />
|
from sys_group t
|
</select>
|
|
<select id="findPullByDepartId" resultType="com.thhy.staff.modules.biz.depart.entity.GroupPullDownVo">
|
SELECT
|
t.group_id as groupId,
|
t.group_name as groupName
|
from sys_group t where t.is_use = 1 and t.depart_id = #{departId}
|
</select>
|
|
<!--插入操作-->
|
<insert id="insert">
|
insert into sys_group
|
<trim prefix="(" suffix=")" suffixOverrides="," >
|
<if test="groupId != null">
|
group_id,
|
</if>
|
<if test="departId != null">
|
depart_id,
|
</if>
|
<if test="groupName != null">
|
group_name,
|
</if>
|
<if test="createTime != null">
|
create_time,
|
</if>
|
<if test="createUser != null">
|
create_user,
|
</if>
|
<if test="updateTime != null">
|
update_time,
|
</if>
|
<if test="updateUser != null">
|
update_user,
|
</if>
|
</trim>
|
|
<trim prefix="values (" suffix=")" suffixOverrides="," >
|
<if test="groupId != null">
|
#{groupId},
|
</if>
|
<if test="departId != null">
|
#{departId},
|
</if>
|
<if test="groupName != null">
|
#{groupName},
|
</if>
|
<if test="createTime != null">
|
#{createTime},
|
</if>
|
<if test="createUser != null">
|
#{createUser},
|
</if>
|
<if test="updateTime != null">
|
#{updateTime},
|
</if>
|
<if test="updateUser != null">
|
#{updateUser},
|
</if>
|
</trim>
|
</insert>
|
|
|
<!--更新操作-->
|
<update id="update">
|
update sys_group
|
<set>
|
<if test="departId != null">
|
depart_id=#{departId},
|
</if>
|
<if test="groupName != null">
|
group_name=#{groupName},
|
</if>
|
<if test="createTime != null">
|
create_time=#{createTime},
|
</if>
|
<if test="createUser != null">
|
create_user=#{createUser},
|
</if>
|
<if test="updateTime != null">
|
update_time=#{updateTime},
|
</if>
|
<if test="updateUser != null">
|
update_user=#{updateUser},
|
</if>
|
</set>
|
where group_id=#{groupId}
|
</update>
|
|
<!--逻辑删除-->
|
<update id="deletelogic">
|
update sys_group
|
SET is_use = 0
|
where group_id=#{groupId}
|
</update>
|
|
<!--根据ID删除-->
|
<delete id="deleteById">
|
delete from sys_group
|
where group_id=#{groupId}
|
</delete>
|
|
<select id="queryGroupPull" resultType="hashmap">
|
select group_id as groupId,group_name as groupName
|
from sys_group sg
|
left join sys_com_depart scd on scd.depart_id = sg.depart_id
|
where sg.is_use = 1 and scd.company_id = #{companyId}
|
order by sg.create_time desc
|
</select>
|
|
</mapper>
|