EntmicroDepartmentPathMapper.xml
4.17 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
<?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.com.glsx.entmicro.mapper.EntmicroDepartmentPathMapper">
<resultMap id="BaseResultMap" type="cn.com.glsx.entmicro.entity.EntmicroDepartmentPath">
<!--
WARNING - @mbg.generated
-->
<id column="id" jdbcType="INTEGER" property="id"/>
<result column="created_by" jdbcType="INTEGER" property="createdBy"/>
<result column="created_time" jdbcType="TIMESTAMP" property="createdTime"/>
<result column="updated_by" jdbcType="INTEGER" property="updatedBy"/>
<result column="updated_time" jdbcType="TIMESTAMP" property="updatedTime"/>
<result column="del_flag" jdbcType="TINYINT" property="delFlag"/>
<result column="superior_id" jdbcType="INTEGER" property="superiorId"/>
<result column="sub_id" jdbcType="INTEGER" property="subId"/>
<result column="depth" jdbcType="INTEGER" property="depth"/>
</resultMap>
<sql id="Base_Column_List">
<!--
WARNING - @mbg.generated
-->
id, created_by, created_time, updated_by, updated_time, del_flag, superior_id, sub_id,
`depth`
</sql>
<insert id="saveEntmicroDepartmentPath"
parameterType="cn.com.glsx.entmicro.entity.EntmicroDepartmentPath">
INSERT INTO entmicro_department_path(superior_id,sub_id,depth)
SELECT t.superior_id,#{entmicroDepartmentPath.subId},t.depth+1
FROM entmicro_department_path AS t
WHERE t.sub_id = #{entmicroDepartmentPath.superiorId}
UNION ALL
SELECT #{entmicroDepartmentPath.subId},#{entmicroDepartmentPath.subId},0
</insert>
<select id="selectDepartmentTree"
parameterType="cn.com.glsx.entmicro.model.request.EntmicroDepartmentRequest"
resultType="cn.com.glsx.entmicro.model.response.DepartmentPathResponse">
select t.superior_id as superiorId,
t.sub_id as subId,
t1.department_name as subName,
t1.relevance_merchant as relevanceMerchant,
t1.merchantId as merchantId
from
(select superior_id,sub_id
from entmicro_department_path
where superior_id in
(select sub_id from entmicro_department_path
where superior_id=#{entmicroDepartmentRequest.id}) and depth=1 and del_flag = 0
UNION ALL
select null,#{entmicroDepartmentRequest.id})t
left join entmicro_department t1 on t.sub_id=t1.id
where t1.del_flag = 0
</select>
<select id="findSubordinateDep" resultMap="BaseResultMap">
select * from entmicro_department_path where superior_id = #{parentId}
</select>
<select id="findByParentId" resultType="java.lang.Integer">
select sub_id from entmicro_department_path where superior_id = #{parentId}
</select>
<update id="updateDepartmentPath" parameterType="cn.com.glsx.entmicro.entity.EntmicroDepartmentPath">
UPDATE entmicro_department_path
set del_flag = #{entmicroDepartmentPath.delFlag}
where
sub_id in (select * from(select sub_id from entmicro_department_path where superior_id = #{entmicroDepartmentPath.subId}) as t1)
and
superior_id in (select * from(select superior_id from entmicro_department_path where sub_id = #{entmicroDepartmentPath.subId} and superior_id != sub_id) as t2)
</update>
<insert id="saveNewDepartmentPath" parameterType="cn.com.glsx.entmicro.entity.EntmicroDepartmentPath">
INSERT INTO entmicro_department_path(superior_id,sub_id,depth)
select super.superior_id,
sub.sub_id ,
super.depth + sub.depth + 1
from
entmicro_department_path super
cross join
entmicro_department_path sub
where super.sub_id = #{entmicroDepartmentPath.superiorId}
and sub.superior_id = #{entmicroDepartmentPath.subId}
</insert>
<update id="deleteDepartmentPath" parameterType="cn.com.glsx.entmicro.entity.EntmicroDepartmentPath">
update entmicro_department_path
set del_flag = -1
where sub_id = #{entmicroDepartmentPath.subId}
</update>
</mapper>