WorkDeptMapper.xml 4.56 KB
Newer Older
cq990612's avatar
cq990612 committed
1 2 3 4 5 6
<?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">
cq990612's avatar
cq990612 committed
7 8
        <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
        <result column="create_time" property="createTime"/>
        <result column="modify_time" property="modifyTime"/>
cq990612's avatar
cq990612 committed
14
        <result column="sort" property="sort"/>
cq990612's avatar
cq990612 committed
15 16
    </resultMap>

cq990612's avatar
cq990612 committed
17
    <resultMap id="CentreDeptMap" type="cn.wisenergy.model.dto.OrganizationStructureDto">
cq990612's avatar
cq990612 committed
18
        <id column="centre_id" property="centreId"/>
cq990612's avatar
cq990612 committed
19 20 21 22 23 24 25
        <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>

cq990612's avatar
cq990612 committed
26 27 28 29 30 31 32 33 34
    <resultMap id="ProjectAndOrderType" type="cn.wisenergy.model.dto.DeptOfProjectAndOrderType">
        <id column="dept_id" property="deptId"/>
        <result column="dept_name" property="deptName"/>
        <collection property="projectManagerDtos" ofType="cn.wisenergy.model.dto.ProjectManagerDto">
            <id column="project_id" property="id"/>
            <result column="project_name" property="projectName"/>
        </collection>
    </resultMap>

nie'hong's avatar
nie'hong committed
35 36 37
    <sql id="table">
        work_dept
    </sql>
cq990612's avatar
cq990612 committed
38

nie'hong's avatar
nie'hong committed
39
    <sql id="cols_all">
cq990612's avatar
cq990612 committed
40 41
        id,
        <include refid="cols_exclude_id"/>
nie'hong's avatar
nie'hong committed
42
    </sql>
cq990612's avatar
cq990612 committed
43

nie'hong's avatar
nie'hong committed
44
    <sql id="cols_exclude_id">
cq990612's avatar
cq990612 committed
45
        dept_name,oa_dept_id,dept_manager_id,centre_id, create_time, modify_time,sort
nie'hong's avatar
nie'hong committed
46
    </sql>
nie'hong's avatar
nie'hong committed
47

nie'hong's avatar
nie'hong committed
48
    <sql id="criteria">
nie'hong's avatar
nie'hong committed
49
        <if test="id != null">AND id = #{id}</if>
nie'hong's avatar
nie'hong committed
50
        <if test="deptName != null">AND dept_name = #{deptName}</if>
nie'hong's avatar
nie'hong committed
51
        <if test="oaDeptId != null">AND oa_dept_id = #{oaDeptId}</if>
nie'hong's avatar
nie'hong committed
52
        <if test="centreId != null">AND centre_id = #{centreId}</if>
nie'hong's avatar
nie'hong committed
53
        <if test="deptManagerId != null">AND dept_manager_id = #{deptManagerId}</if>
nie'hong's avatar
nie'hong committed
54 55 56 57
        <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
58
    <!-- 通用查询结果列 -->
cq990612's avatar
cq990612 committed
59
    <sql id="Base_Column_List">
cq990612's avatar
cq990612 committed
60
        id,dept_name, oa_dept_id,centre_id, dept_name, create_time, modify_time,sort
cq990612's avatar
cq990612 committed
61
    </sql>
cq990612's avatar
cq990612 committed
62
    <update id="updateManagerIdISNullById">
cq990612's avatar
cq990612 committed
63 64
        UPDATE
        <include refid="table"/>
cq990612's avatar
cq990612 committed
65 66 67
        SET dept_manager_id = NULL
        WHERE id = #{id}
    </update>
cq990612's avatar
cq990612 committed
68

nie'hong's avatar
nie'hong committed
69
    <select id="getDeptByCondition" resultMap="BaseResultMap" parameterType="integer">
cq990612's avatar
cq990612 committed
70 71 72 73 74 75 76 77
        select
        <include refid="cols_all"/>
        from
        <include refid="table"/>
        <where>
            <include refid="criteria"/>
        </where>
        order by sort
78 79
    </select>

cq990612's avatar
cq990612 committed
80 81 82
    <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
cq990612's avatar
cq990612 committed
83
ORDER BY c.id,d.sort
cq990612's avatar
cq990612 committed
84 85

    </select>
nie'hong's avatar
nie'hong committed
86
    <select id="getById" resultMap="BaseResultMap">
cq990612's avatar
cq990612 committed
87 88 89 90
        select
        <include refid="cols_all"/>
        from
        <include refid="table"/>
nie'hong's avatar
nie'hong committed
91 92 93
        where id =#{deptId}

    </select>
cq990612's avatar
cq990612 committed
94

nie'hong's avatar
nie'hong committed
95
    <select id="getDeptByManagerId" resultType="cn.wisenergy.model.app.WorkDept">
cq990612's avatar
cq990612 committed
96 97 98 99
        select
        <include refid="cols_all"/>
        from
        <include refid="table"/>
cq990612's avatar
cq990612 committed
100
        where dept_manager_id = #{userId}
nie'hong's avatar
nie'hong committed
101 102
    </select>

cq990612's avatar
cq990612 committed
103 104 105 106 107

    <select id="getDeptOfProjectAndOrderType" resultMap="ProjectAndOrderType">
select d.id 'dept_id',d.dept_name,p.id 'project_id',p.project_name
from work_dept d LEFT JOIN work_project p on d.id = p.dept_id
<where>
cq990612's avatar
cq990612 committed
108
        <if test="userId !=null">
cq990612's avatar
cq990612 committed
109
        AND   p.manager_id = #{userId}
cq990612's avatar
cq990612 committed
110 111 112 113
        </if>
        <if test="deptId !=null">
        OR p.dept_id = #{deptId}
        </if>
cq990612's avatar
cq990612 committed
114
</where>
cq990612's avatar
cq990612 committed
115
ORDER BY d.sort,p.id
cq990612's avatar
cq990612 committed
116 117 118

    </select>

nie'hong's avatar
nie'hong committed
119 120 121 122 123 124
    <select id="getOaDeptNoByUserId" resultMap="BaseResultMap">
    select d.id,<include refid="cols_exclude_id"/>
    from work_dept d join work_user_dept ud on d.id = ud.dept_id
    where ud.user_id = #{userId}
    </select>

nie'hong's avatar
nie'hong committed
125 126 127 128 129 130 131
    <select id="getAllDept" resultType="cn.wisenergy.model.app.WorkDept">
        select
        <include refid="cols_all"/>
        from
        <include refid="table"/>
    </select>

cq990612's avatar
cq990612 committed
132
</mapper>