| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207 |
- <?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.ylx.system.mapper.SysDeptMapper">
- <resultMap type="SysDept" id="SysDeptResult">
- <id property="deptId" column="dept_id" />
- <result property="parentId" column="parent_id" />
- <result property="ancestors" column="ancestors" />
- <result property="provinceCode" column="province_code" />
- <result property="provinceName" column="province_name" />
- <result property="deptName" column="dept_name" />
- <result property="cityCode" column="city_code" />
- <result property="cityName" column="city_name" />
- <result property="districtCode" column="district_code" />
- <result property="districtName" column="district_name" />
- <result property="orderNum" column="order_num" />
- <result property="leader" column="leader" />
- <result property="phone" column="phone" />
- <result property="email" column="email" />
- <result property="status" column="status" />
- <result property="isDelete" column="is_delete" />
- <result property="parentName" column="parent_name" />
- <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>
- <sql id="selectDeptVo">
- select d.dept_id, d.parent_id, d.ancestors, d.province_code, d.province_name, d.dept_name,
- d.city_code, d.city_name, d.district_code, d.district_name, d.order_num, d.leader,
- d.phone, d.email, d.status, d.is_delete, d.create_by, d.create_time
- from sys_dept d
- </sql>
- <!-- 查询部门列表 -->
- <select id="selectDeptList" parameterType="SysDept" resultMap="SysDeptResult">
- <include refid="selectDeptVo"/>
- where d.is_delete = 0
- <if test="deptId != null and deptId != 0">
- AND dept_id = #{deptId}
- </if>
- <if test="parentId != null and parentId != 0">
- AND parent_id = #{parentId}
- </if>
- <if test="deptName != null and deptName != ''">
- AND dept_name like concat('%', #{deptName}, '%')
- </if>
- <if test="status != null and status != ''">
- AND status = #{status}
- </if>
- <!-- 数据范围过滤
- ${params.dataScope}-->
- order by d.parent_id, d.order_num
- </select>
- <!-- 分页查询部门列表 -->
- <select id="selectDeptPage" resultMap="SysDeptResult">
- <include refid="selectDeptVo"/>
- where d.is_delete = 0
- <if test="dto.deptId != null and dto.deptId != 0">
- AND dept_id = #{dto.deptId}
- </if>
- <if test="dto.deptName != null and dto.deptName != ''">
- AND dept_name like concat('%', #{dto.deptName}, '%')
- </if>
- <if test="dto.status != null and dto.status != ''">
- AND status = #{dto.status}
- </if>
- <if test="dto.startTime != null and dto.startTime != ''">
- AND d.create_time >= #{dto.startTime}
- </if>
- <if test="dto.endTime != null and dto.endTime != ''">
- AND d.create_time <= #{dto.endTime}
- </if>
- order by d.parent_id, d.order_num
- </select>
- <!-- 按省市查询部门平铺列表,包含顶级部门 -->
- <select id="selectDeptFlatListByRegion" resultMap="SysDeptResult">
- <include refid="selectDeptVo"/>
- <where>
- d.is_delete = 0
- AND (
- d.parent_id = 0
- <if test="(dept.provinceCode != null and dept.provinceCode != '')
- or (dept.provinceName != null and dept.provinceName != '')
- or (dept.cityCode != null and dept.cityCode != '')
- or (dept.cityName != null and dept.cityName != '')">
- OR (
- 1 = 1
- <if test="dept.provinceCode != null and dept.provinceCode != ''">
- AND d.province_code = #{dept.provinceCode}
- </if>
- <if test="dept.provinceName != null and dept.provinceName != ''">
- AND d.province_name = #{dept.provinceName}
- </if>
- <if test="dept.cityCode != null and dept.cityCode != ''">
- AND d.city_code = #{dept.cityCode}
- </if>
- <if test="dept.cityName != null and dept.cityName != ''">
- AND d.city_name = #{dept.cityName}
- </if>
- )
- </if>
- )
- </where>
- order by d.parent_id, d.order_num, d.dept_id
- </select>
- <!-- 查询城市列表 -->
- <select id="selectCityList" resultType="com.ylx.system.domain.vo.SysDeptCityVo">
- select distinct
- d.city_code as cityCode,
- d.city_name as cityName
- from sys_dept d
- where d.is_delete = 0
- and d.status = '0'
- and d.city_code is not null
- and d.city_code != ''
- and d.city_name is not null
- and d.city_name != ''
- order by d.city_code, d.city_name
- </select>
- <select id="selectDeptListByRoleId" resultType="Long">
- select d.dept_id
- from sys_dept d
- left join sys_role_dept rd on d.dept_id = rd.dept_id
- where rd.role_id = #{roleId}
- <if test="deptCheckStrictly">
- and d.dept_id not in (select d.parent_id from sys_dept d inner join sys_role_dept rd on d.dept_id = rd.dept_id and rd.role_id = #{roleId})
- </if>
- order by d.parent_id, d.order_num
- </select>
- <select id="selectDeptById" parameterType="Long" resultMap="SysDeptResult">
- select d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.phone, d.email, d.status,
- (select dept_name from sys_dept where dept_id = d.parent_id) parent_name
- from sys_dept d
- where d.dept_id = #{deptId}
- </select>
- <select id="checkDeptExistUser" parameterType="Long" resultType="int">
- select count(1) from sys_user where dept_id = #{deptId} and del_flag = '0'
- </select>
- <!-- 查询部门是否存在下级部门 -->
- <select id="hasChildByDeptId" parameterType="Long" resultType="int">
- select count(1) from sys_dept
- where is_delete = 0 and parent_id = #{deptId} limit 1
- </select>
- <select id="selectChildrenDeptById" parameterType="Long" resultMap="SysDeptResult">
- select * from sys_dept where find_in_set(#{deptId}, ancestors)
- </select>
- <select id="selectNormalChildrenDeptById" parameterType="Long" resultType="int">
- select count(*) from sys_dept where status = 0 and is_delete = 0 and find_in_set(#{deptId}, ancestors)
- </select>
- <!-- 校验部门名称是否唯一 -->
- <select id="checkDeptNameUnique" resultMap="SysDeptResult">
- <include refid="selectDeptVo"/>
- where dept_name=#{deptName} and parent_id = #{parentId} and is_delete = 0 limit 1
- </select>
- <update id="updateDept" parameterType="SysDept">
- update sys_dept
- <set>
- <if test="parentId != null and parentId != 0">parent_id = #{parentId},</if>
- <if test="deptName != null and deptName != ''">dept_name = #{deptName},</if>
- <if test="ancestors != null and ancestors != ''">ancestors = #{ancestors},</if>
- <if test="orderNum != null">order_num = #{orderNum},</if>
- <if test="leader != null">leader = #{leader},</if>
- <if test="phone != null">phone = #{phone},</if>
- <if test="email != null">email = #{email},</if>
- <if test="status != null and status != ''">status = #{status},</if>
- <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
- update_time = sysdate()
- </set>
- where dept_id = #{deptId}
- </update>
- <update id="updateDeptChildren" parameterType="java.util.List">
- update sys_dept set ancestors =
- <foreach collection="depts" item="item" index="index"
- separator=" " open="case dept_id" close="end">
- when #{item.deptId} then #{item.ancestors}
- </foreach>
- where dept_id in
- <foreach collection="depts" item="item" index="index"
- separator="," open="(" close=")">
- #{item.deptId}
- </foreach>
- </update>
- <update id="updateDeptStatusNormal" parameterType="Long">
- update sys_dept set status = '0' where dept_id in
- <foreach collection="array" item="deptId" open="(" separator="," close=")">
- #{deptId}
- </foreach>
- </update>
- </mapper>
|