SysOrgSmapper.xml
5.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?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.zteits.sys.mapper.smapper.SysOrgSmapper">
<resultMap id="BaseResultMap" type="com.zteits.sys.domain.SysOrg">
<id column="id" property="id" jdbcType="BIGINT"/>
<result column="org_code" property="orgCode" jdbcType="VARCHAR"/>
<result column="org_name" property="orgName" jdbcType="VARCHAR"/>
<result column="short_name" property="shortName" jdbcType="VARCHAR"/>
<result column="sort_num" property="sortNum" jdbcType="INTEGER"/>
<result column="org_level" property="orgLevel" jdbcType="INTEGER"/>
<result column="parent_org_id" property="parentOrgId" jdbcType="BIGINT"/>
<result column="org_desc" property="orgDesc" jdbcType="VARCHAR"/>
<result column="org_leader_id" property="orgLeaderId" jdbcType="BIGINT"/>
<result column="org_icon" property="orgIcon" jdbcType="VARCHAR"/>
<result column="sys_code" property="sysCode" jdbcType="VARCHAR"/>
<result column="data_state" property="dataState" jdbcType="INTEGER"/>
<result column="create_empid" property="createEmpid" jdbcType="VARCHAR"/>
<result column="create_date" property="createDate" jdbcType="TIMESTAMP"/>
<result column="modfiy_empid" property="modfiyEmpid" jdbcType="VARCHAR"/>
<result column="modfiy_date" property="modfiyDate" jdbcType="TIMESTAMP"/>
</resultMap>
<sql id="Base_Column_List">
id, org_code, org_name, short_name, sort_num, org_level, parent_org_id, org_desc,
org_leader_id, org_icon, sys_code, data_state, create_empid, create_date, modfiy_empid,
modfiy_date
</sql>
<!--通过组织等级查询组织信息-->
<select id="queryOrgByOrgLevel" resultMap="BaseResultMap"
parameterType="com.zteits.clouds.api.dto.sys.param.OrgByOrgLevelRequest">
SELECT
<include refid="Base_Column_List"/>
FROM
sys_org a
WHERE a.data_state=1
and a.sys_code = #{sysCode,jdbcType=VARCHAR}
<if test="orgLevel != null">
and (org_level=#{orgLevel,jdbcType=INTEGER} or a.org_level=1)
</if>
</select>
<!-- 通过操作员id查询组织ID -->
<select id="querySysOrgBySysOpId" resultType="java.lang.Long">
select b.id
from sys_op_org a,sys_org b
where a.sys_org_id = b.id
and a.sys_op_id =#{sysOpId,jdbcType=BIGINT}
<if test="sysCode != null">
and b.sys_code = #{sysCode,jdbcType=VARCHAR}
</if>
and b.data_state =1
</select>
<!-- 查询组织 langlw 2017-08-14 -->
<select id="queryPageSysOrgForList" resultMap="BaseResultMap" parameterType="com.zteits.sys.domain.SysOrg">
select
<include refid="Base_Column_List"/>
from sys_org
<where>
<if test="id != null">
and id= #{id,jdbcType=BIGINT}
</if>
<if test="parentOrgId != null">
and parent_org_id= #{parentOrgId,jdbcType=BIGINT}
</if>
<if test="sysCode != null">
and sys_code = #{sysCode,jdbcType=VARCHAR}
</if>
<choose>
<when test="dataState != null">
and data_state = #{dataState,jdbcType=INTEGER}
</when>
<otherwise>
and data_state = 1
</otherwise>
</choose>
</where>
order by sort_num asc
</select>
<!-- 批量查询组织 -->
<select id="queryBatchSysOrgById" resultType="com.zteits.sys.domain.SysOrg">
SELECT
<include refid="Base_Column_List"/>
from sys_org
<where>
<if test="sysCode != null">
and sys_code = #{sysCode,jdbcType=VARCHAR}
</if>
AND id IN
<foreach collection="ids" item="id" index="index" open="(" close=")" separator=",">
#{id}
</foreach>
<choose>
<when test="dataState != null">
and data_state = #{dataState,jdbcType=INTEGER}
</when>
<otherwise>
and data_state = 1
</otherwise>
</choose>
</where>
</select>
<!-- 通过主键批量删除组织 逻辑删除 langlw 2017-08-14 -->
<update id="deleteBatchForLogicByPrimaryKey">
update sys_org set data_state = 0
where id IN
<foreach collection="ids" item="id" separator="," open="(" close=")" index="index">
#{id,jdbcType=BIGINT}
</foreach>
</update>
<!-- 更新排序 langlw 2017-08-17 -->
<update id="updateSysOrgSortNumOfSaveOrUpdate">
update sys_org
SET sort_num = sort_num
<if test="sortNum > oldSortNum">
-1
</if>
<if test="sortNum < oldSortNum">
+1
</if>
<where>
<if test="sortNum > oldSortNum">
sort_num <= #{sortNum} AND sort_num > #{oldSortNum}
</if>
<if test="sortNum < oldSortNum">
sort_num >= #{sortNum} AND sort_num < #{oldSortNum}
</if>
AND id != #{id,jdbcType=BIGINT}
AND parent_org_id = #{parentOrgId}
</where>
</update>
<!-- 更新排序 langlw 2017-08-17 -->
<update id="updateSysOrgSortNumOfDelete">
UPDATE sys_org
SET sort_num = sort_num - 1
WHERE sort_num > (SELECT a.sort_num FROM (SELECT sort_num FROM sys_org WHERE id = #{id}) a)
AND parent_org_id = (SELECT b.parent_org_id FROM (SELECT parent_org_id FROM sys_org WHERE id = #{id}) b)
</update>
<select id="querySysOrgByParentId" parameterType="java.lang.Long" resultMap="BaseResultMap">
SELECT
<include refid="Base_Column_List"/>
FROM sys_org WHERE data_state = 1 AND parent_org_id = #{parentId}
</select>
</mapper>