WorkDeptMapper.xml 3.17 KB
Newer Older
cq990612's avatar
cq990612 committed
1 2 3 4 5 6 7 8
<?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="cn.wisenergy.mapper.WorkDeptMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="cn.wisenergy.model.app.WorkDept">
        <id column="id" property="id" />
        <result column="dept_name" property="deptName" />
nie'hong's avatar
nie'hong committed
9
        <result column="oa_dept_id" property="oaDeptId"/>
nie'hong's avatar
nie'hong committed
10 11
        <result column="centre_id" property="centreId"/>
        <result column="dept_manager_id" property="deptManagerId"/>
cq990612's avatar
cq990612 committed
12 13 14 15
        <result column="create_time" property="createTime" />
        <result column="modify_time" property="modifyTime" />
    </resultMap>

cq990612's avatar
cq990612 committed
16 17 18 19 20 21 22 23 24 25

    <resultMap id="CentreDeptMap" type="cn.wisenergy.model.dto.OrganizationStructureDto">
        <id column="centre_id" property="centreId" />
        <result column="centre_name" property="centreName"/>
        <collection property="deptUserDtos" ofType="cn.wisenergy.model.dto.DeptUserDto">
            <id column="dept_id" property="deptId"/>
            <result column="dept_name" property="deptName"/>
        </collection>
    </resultMap>

nie'hong's avatar
nie'hong committed
26 27 28 29 30 31 32 33 34
    <sql id="table">
        work_dept
    </sql>
    
    <sql id="cols_all">
        id, <include refid="cols_exclude_id"/>
    </sql>
    
    <sql id="cols_exclude_id">
nie'hong's avatar
nie'hong committed
35
        dept_name,oa_dept_id,dept_manager_id,centre_id, create_time, modify_time
nie'hong's avatar
nie'hong committed
36
    </sql>
nie'hong's avatar
nie'hong committed
37

nie'hong's avatar
nie'hong committed
38
    <sql id="criteria">
nie'hong's avatar
nie'hong committed
39
        <if test="id != null">AND id = #{id}</if>
nie'hong's avatar
nie'hong committed
40
        <if test="deptName != null">AND dept_name = #{deptName}</if>
nie'hong's avatar
nie'hong committed
41
        <if test="oaDeptId != null">AND oa_dept_id = #{oaDeptId}</if>
nie'hong's avatar
nie'hong committed
42
        <if test="centreId != null">AND centre_id = #{centreId}</if>
nie'hong's avatar
nie'hong committed
43
        <if test="deptManagerId != null">AND dept_manager_id = #{deptManagerId}</if>
nie'hong's avatar
nie'hong committed
44 45 46 47
        <if test="createTime != null">AND create_time = #{createTime}</if>
        <if test="modifyTime != null">AND modify_time = #{modifyTime}</if>
    </sql>

nie'hong's avatar
nie'hong committed
48
    <!-- 通用查询结果列 -->
cq990612's avatar
cq990612 committed
49
    <sql id="Base_Column_List">
nie'hong's avatar
nie'hong committed
50
        id,dept_name, oa_dept_id,centre_id, dept_name, create_time, modify_time
cq990612's avatar
cq990612 committed
51
    </sql>
cq990612's avatar
cq990612 committed
52 53 54 55 56
    <update id="updateManagerIdISNullById">
        UPDATE <include refid="table"/>
        SET dept_manager_id = NULL
        WHERE id = #{id}
    </update>
cq990612's avatar
cq990612 committed
57

nie'hong's avatar
nie'hong committed
58
    <select id="getDeptByCondition" resultMap="BaseResultMap" parameterType="integer">
59 60
        select <include refid="cols_all"/>
        from <include refid="table"/>
nie'hong's avatar
nie'hong committed
61 62 63
       <where>
           <include refid="criteria"/>
       </where>
nie'hong's avatar
nie'hong committed
64
       order by sort
65 66
    </select>

cq990612's avatar
cq990612 committed
67 68 69 70 71 72
    <select id="getAllDeptByAllCentre" resultMap="CentreDeptMap">
select c.id as 'centre_id',c.centre_name as 'centre_name',d.id as 'dept_id',d.dept_name as 'dept_name'
from work_centre c LEFT JOIN work_dept d ON c.id = d.centre_id
ORDER BY c.id,d.id

    </select>
nie'hong's avatar
nie'hong committed
73 74 75 76 77 78
    <select id="getById" resultMap="BaseResultMap">
        select <include refid="cols_all"/>
        from <include refid="table"/>
        where id =#{deptId}

    </select>
cq990612's avatar
cq990612 committed
79

nie'hong's avatar
nie'hong committed
80 81 82
    <select id="getDeptByManagerId" resultType="cn.wisenergy.model.app.WorkDept">
        select <include refid="cols_all"/>
        from <include refid="table"/>
cq990612's avatar
cq990612 committed
83
        where dept_manager_id = #{userId}
nie'hong's avatar
nie'hong committed
84 85
    </select>

cq990612's avatar
cq990612 committed
86
</mapper>