123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- <?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.jiayue.system.mapper.SysUnitMapper">
- <resultMap type="SysUnit" id="SysUnitResult">
- <id property="unitId" column="unit_id"/>
- <result property="parentId" column="parent_id"/>
- <result property="ancestors" column="ancestors"/>
- <result property="unitNo" column="unit_no"/>
- <result property="unitName" column="unit_name"/>
- <result property="unitCategory" column="unit_category"/>
- <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="delFlag" column="del_flag"/>
- <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"/>
- <result property="remark" column="remark"/>
- </resultMap>
- <sql id="selectUnitVo">
- select d.unit_id, d.parent_id, d.ancestors, d.unit_no, d.unit_name, d.unit_category, d.order_num, d.leader, d.phone, d.email, d.status, d.del_flag, d.create_by, d.create_time, d.update_by, d.update_time, d.remark
- from sys_unit d
- </sql>
- <select id="selectUnitList" parameterType="SysUnit" resultMap="SysUnitResult">
- <include refid="selectUnitVo"/>
- where d.del_flag = '0'
- <if test="unitId != null and unitId != 0">
- AND unit_id = #{unitId}
- </if>
- <if test="parentId != null and parentId != 0">
- AND parent_id = #{parentId}
- </if>
- <if test="unitNo != null and unitNo != ''">
- AND unit_no = #{unitNo}
- </if>
- <if test="unitName != null and unitName != ''">
- AND unit_name like concat('%', #{unitName}, '%')
- </if>
- <if test="unitCategory != null and unitCategory != ''">
- AND unit_category = #{unitCategory}
- </if>
- <if test="status != null and status != ''">
- AND status = #{status}
- </if>
- <!-- 数据范围过滤 -->
- ${params.dataScope}
- order by d.parent_id, d.order_num
- </select>
- <select id="selectUnitListByRoleId" resultType="Long">
- select d.unit_id
- from sys_unit d
- left join sys_role_unit rd on d.unit_id = rd.unit_id
- where rd.role_id = #{roleId}
- <if test="unitCheckStrictly">
- and d.unit_id not in (select d.parent_id from sys_unit d inner join sys_role_unit rd on
- d.unit_id = rd.unit_id and rd.role_id = #{roleId})
- </if>
- order by d.parent_id, d.order_num
- </select>
- <select id="selectUnitById" parameterType="Long" resultMap="SysUnitResult">
- <include refid="selectUnitVo"/>
- where unit_id = #{unitId}
- </select>
- <select id="checkUnitExistUser" parameterType="Long" resultType="int">
- select count(1) from sys_user where unit_id = #{unitId} and del_flag = '0'
- </select>
- <select id="hasChildByUnitId" parameterType="Long" resultType="int">
- select count(1) from sys_unit
- where del_flag = '0' and parent_id = #{unitId} limit 1
- </select>
- <select id="selectChildrenUnitById" parameterType="Long" resultMap="SysUnitResult">
- select * from sys_unit where find_in_set(#{unitId}, ancestors)
- </select>
- <select id="selectNormalChildrenUnitById" parameterType="Long" resultType="int">
- select count(*) from sys_unit where status = 0 and del_flag = '0' and find_in_set(#{unitId}, ancestors)
- </select>
- <select id="checkUnitNameUnique" resultMap="SysUnitResult">
- <include refid="selectUnitVo"/>
- where unit_name = #{unitName} and parent_id = #{parentId} limit 1
- </select>
- <insert id="insertUnit" parameterType="SysUnit">
- insert into sys_unit(
- <if test="unitId != null and unitId != 0">unit_id,</if>
- <if test="parentId != null and parentId != 0">parent_id,</if>
- <if test="unitNo != null and unitNo != ''">unit_no,</if>
- <if test="unitName != null and unitName != ''">unit_name,</if>
- <if test="unitCategory != null and unitCategory != ''">unit_category,</if>
- <if test="ancestors != null and ancestors != ''">ancestors,</if>
- <if test="orderNum != null">order_num,</if>
- <if test="leader != null and leader != ''">leader,</if>
- <if test="phone != null and phone != ''">phone,</if>
- <if test="email != null and email != ''">email,</if>
- <if test="status != null">status,</if>
- <if test="delFlag != null">del_flag,</if>
- <if test="createBy != null and createBy != ''">create_by,</if>
- <if test="updateBy != null and updateBy != ''">update_by,</if>
- <if test="remark != null and remark != ''">remark,</if>
- create_time,
- update_time
- )values(
- <if test="unitId != null and unitId != 0">#{unitId},</if>
- <if test="parentId != null and parentId != 0">#{parentId},</if>
- <if test="unitNo != null and unitNo != ''">#{unitNo},</if>
- <if test="unitName != null and unitName != ''">#{unitName},</if>
- <if test="unitCategory != null and unitCategory != ''">#{unitCategory},</if>
- <if test="ancestors != null and ancestors != ''">#{ancestors},</if>
- <if test="orderNum != null">#{orderNum},</if>
- <if test="leader != null and leader != ''">#{leader},</if>
- <if test="phone != null and phone != ''">#{phone},</if>
- <if test="email != null and email != ''">#{email},</if>
- <if test="status != null">#{status},</if>
- <if test="delFlag != null">#{delFlag},</if>
- <if test="createBy != null and createBy != ''">#{createBy},</if>
- <if test="updateBy != null and updateBy != ''">#{updateBy},</if>
- <if test="remark != null and remark != ''">#{remark},</if>
- sysdate(),
- sysdate()
- )
- </insert>
- <update id="updateUnit" parameterType="SysUnit">
- update sys_unit
- <set>
- <if test="parentId != null and parentId != 0">parent_id = #{parentId},</if>
- <if test="unitNo != null and unitNo != ''">unit_no = #{unitNo},</if>
- <if test="unitName != null and unitName != ''">unit_name = #{unitName},</if>
- <if test="unitCategory != null and unitCategory != ''">
- unit_category = #{unitCategory},
- </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="delFlag != null and delFlag != ''">del_flag = #{delFlag},</if>
- <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
- <if test="remark != null">remark = #{remark},</if>
- update_time = sysdate()
- </set>
- where unit_id = #{unitId}
- </update>
- <update id="updateUnitChildren" parameterType="java.util.List">
- update sys_unit set ancestors =
- <foreach collection="units" item="item" index="index"
- separator=" " open="case unit_id" close="end">
- when #{item.unitId} then #{item.ancestors}
- </foreach>
- where unit_id in
- <foreach collection="units" item="item" index="index"
- separator="," open="(" close=")">
- #{item.unitId}
- </foreach>
- </update>
- <update id="updateUnitStatusNormal" parameterType="Long">
- update sys_unit set status = '0' where unit_id in
- <foreach collection="array" item="unitId" open="(" separator="," close=")">
- #{unitId}
- </foreach>
- </update>
- <delete id="deleteUnitById" parameterType="Long">
- update sys_unit set del_flag = '2' where unit_id = #{unitId}
- </delete>
- <select id="selectUnitListByNo" parameterType="java.util.List" resultMap="SysUnitResult">
- <include refid="selectUnitVo"/>
- where d.unit_no IN
- <foreach collection="unitNoList" index="index" item="unitNo" open="(" separator=","
- close=")">
- #{unitNo}
- </foreach>
- </select>
- </mapper>
|