EntmicroDepartmentMapper.xml
9.76 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<?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.EntmicroDepartmentMapper">
<resultMap id="BaseResultMap" type="cn.com.glsx.entmicro.entity.EntmicroDepartment">
<!--
WARNING - @mbg.generated
-->
<id column="id" jdbcType="INTEGER" property="id"/>
<result column="department_name" jdbcType="VARCHAR" property="departmentName"/>
<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="merchantId" jdbcType="VARCHAR" property="merchantid"/>
</resultMap>
<resultMap id="resultMap" type="cn.com.glsx.entmicro.model.response.EntmicroDepartmentResponse">
<!--
WARNING - @mbg.generated
-->
<id column="id" jdbcType="INTEGER" property="id"/>
<result column="department_name" jdbcType="VARCHAR" property="departmentName"/>
<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="merchantId" jdbcType="VARCHAR" property="merchantId"/>
<result column="department_Id" jdbcType="VARCHAR" property="departmentId"/>
<result column="entmicro_parent_id" jdbcType="INTEGER" property="entmicroParentId"/>
<result column="relevance_merchant" jdbcType="INTEGER" property="relevanceMerchant"/>
<result column="childrenNum" jdbcType="INTEGER" property="childrenNum"/>
</resultMap>
<sql id="Base_Column_List">
<!--
WARNING - @mbg.generated
-->
id, department_name, created_by, created_time, updated_by, updated_time, del_flag,
merchantId, department_Id, entmicro_parent_id, relevance_merchant
</sql>
<update id="updateEntmicroDepartment"
parameterType="cn.com.glsx.entmicro.model.request.EntmicroDepartmentRequest">
update entmicro_department
set
<if test="entmicroDepartmentRequest.departmentName != null and entmicroDepartmentRequest.departmentName != null">
department_name = #{entmicroDepartmentRequest.departmentName},
</if>
updated_time = #{entmicroDepartmentRequest.updatedTime},
<if test="entmicroDepartmentRequest.entmicroParentId != null">
entmicro_parent_id = #{entmicroDepartmentRequest.entmicroParentId},
</if>
updated_by = #{entmicroDepartmentRequest.updatedBy}
where id=#{entmicroDepartmentRequest.id}
</update>
<update id="deleteEntmicroDepartment"
parameterType="cn.com.glsx.entmicro.model.request.EntmicroDepartmentRequest">
update entmicro_department
set del_flag = #{entmicroDepartmentRequest.delFlag}
where department_id = #{entmicroDepartmentRequest.departmentId}
and merchantId = #{entmicroDepartmentRequest.merchantId}
</update>
<update id="updateMerchantBind">
update entmicro_department
set
merchantId = #{merchantNo},
relevance_merchant = #{merchantNo}
where id in
<foreach collection="list" open="(" separator="," close=")" item="id">
#{id}
</foreach>
</update>
<select id="selectByDepartmentId"
resultMap="resultMap">
SELECT * from entmicro_department where id in (select sub_id from entmicro_department_path where superior_id =(SELECT min(id) from entmicro_department where relevance_merchant =#{merchantId} and del_flag = 0)) and del_flag = 0
</select>
<select id="selectByEntmicroDepartmentId" resultMap="resultMap">
select
<include refid="Base_Column_List"/>
from entmicro_department
where department_id = #{departmentId}
<if test="merchantId != null">
and merchantId in
(SELECT merchantId from entmicro_department where id in(select sub_id from entmicro_department_path where
superior_id=(select min(superior_id) from entmicro_department_path where sub_id =(SELECT min(id) from
entmicro_department where relevance_merchant =#{merchantId} and del_flag = 0))))
</if>
and del_flag = 0
</select>
<select id="selectSubDepartmentById" resultMap="resultMap">
select
<include refid="Base_Column_List"/>
from entmicro_department
where relevance_merchant = #{merchantId}
and del_flag = 0
</select>
<select id="findSupMerchantNo" resultType="java.lang.Integer">
select merchantId from entmicro_department where id=(select min(superior_id) from entmicro_department_path where sub_id =(SELECT min(id) from entmicro_department where relevance_merchant =#{merchantId} and del_flag = 0))
</select>
<select id="findAuthorizeMerchantNo" resultType="java.lang.Integer">
select relevance_merchant from entmicro_department where id in (select sub_id from entmicro_department_path where superior_id =(SELECT min(id) from entmicro_department where relevance_merchant =#{merchantId} and del_flag = 0))
and relevance_merchant is not null group by relevance_merchant
</select>
<select id="findAuthorizeDepartment" resultMap="resultMap">
select department_Id,relevance_merchant from entmicro_department where id in (select sub_id from entmicro_department_path where superior_id =(SELECT min(id) from entmicro_department where relevance_merchant =#{merchantId} and del_flag = 0))
and relevance_merchant is not null group by relevance_merchant
</select>
<select id="getDepartmentNameByStaffId" resultType="cn.com.glsx.entmicro.model.response.EntmicroStaffResponse">
SELECT d.staff_id AS staffId,
es.staff_name AS staffName,
p.department_name AS departmentName,
es.`thumb_avatar` AS thumbAvatar
FROM entmicro_staff_depart_relation d
LEFT JOIN entmicro_department p ON d.department_id = p.id
LEFT JOIN entmicro_staff es ON es.id = d.staff_id
WHERE d.del_flag = 0
AND d.staff_id IN
<foreach collection="staffIds" open="(" separator="," close=")" item="id">
#{id}
</foreach>
AND d.relevance_merchant = #{merchantId}
GROUP BY d.staff_id
</select>
<select id="findSubChildDepartment" resultMap="resultMap">
SELECT
<include refid="Base_Column_List"/>
from entmicro_department
where entmicro_parent_id = #{entmicroParentId}
and department_name = #{departmentName}
and del_flag=0
and merchantId in
(SELECT merchantId from entmicro_department where id in(select sub_id from entmicro_department_path where
superior_id=(select min(superior_id) from entmicro_department_path where sub_id =(SELECT min(id) from
entmicro_department where relevance_merchant = #{merchantId} and del_flag = 0))))
</select>
<select id="findIdByDepartmentId" resultType="java.lang.Integer">
select id from entmicro_department where department_id=#{departmentId} and created_by=#{merchantId} and del_flag=0 limit 1
</select>
<!--查询当前关联商户的最小部门-->
<select id="findMinDepartment" resultType="integer">
SELECT MIN(id) FROM entmicro_department WHERE relevance_merchant = #{merchantId} AND del_flag = 0
</select>
<select id="findSubDepartmentBySupId"
resultMap="resultMap">
SELECT
ed.*,count(edp.sub_id) as childrenNum
FROM
entmicro_department ed LEFT JOIN entmicro_department_path edp ON edp.superior_id = ed.id AND edp.superior_id != edp.sub_id AND edp.del_flag = 0
WHERE
ed.id IN (
SELECT
sub_id
FROM
entmicro_department_path
WHERE
del_flag = 0
<choose>
<when test="departmentId != null">
and superior_id =#{departmentId}
</when>
<when test="departmentId ==null || departmentId == ''">
and superior_id =
( SELECT min( id ) FROM entmicro_department WHERE merchantId = #{merchantId} AND del_flag = 0 )
</when>
</choose>
AND depth =1
)
AND ed.del_flag = 0
GROUP BY ed.id
</select>
<select id="findDepartmentListByPage"
resultMap="resultMap">
SELECT
dep.*,
dep1.department_name as entmicroParentName,
dep1.department_id as entmicroParentId
FROM
entmicro_department dep
LEFT JOIN entmicro_department dep1 ON dep.entmicro_parent_id = dep1.department_id
AND dep1.id IN (SELECT sub_id FROM entmicro_department_path WHERE superior_id = ( SELECT MIN( id ) FROM entmicro_department WHERE merchantId = #{condition.merchantId} AND del_flag = 0 ))
WHERE
dep.del_flag = 0
AND dep.id IN (SELECT sub_id FROM entmicro_department_path WHERE superior_id = ( SELECT MIN( id ) FROM entmicro_department WHERE merchantId = #{condition.merchantId} AND del_flag = 0 ))
AND ISNULL(dep.relevance_merchant)
<if test="condition.departmentName != null and condition.departmentName != ''">
AND dep.department_name LIKE concat('%',#{condition.departmentName},'%')
</if>
</select>
</mapper>