MerchantPathMapper.xml
7.2 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
<?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.merchants.mapper.MerchantPathMapper">
<resultMap id="BaseResultMap" type="cn.com.glsx.merchants.entity.MerchantPath">
<!--
WARNING - @mbg.generated
-->
<id column="id" jdbcType="INTEGER" property="id"/>
<result column="superior_id" jdbcType="INTEGER" property="superiorId"/>
<result column="sub_id" jdbcType="INTEGER" property="subId"/>
<result column="depth" jdbcType="INTEGER" property="depth"/>
<result column="del_flag" jdbcType="TINYINT" property="delFlag"/>
<result column="created_date" jdbcType="TIMESTAMP" property="createdDate"/>
<result column="created_by" jdbcType="INTEGER" property="createdBy"/>
<result column="updated_date" jdbcType="TIMESTAMP" property="updatedDate"/>
<result column="updated_by" jdbcType="INTEGER" property="updatedBy"/>
<result column="subName" jdbcType="VARCHAR" property="subName"/>
<result column="status" jdbcType="VARCHAR" property="status"/>
<result column="entmicro_name" jdbcType="VARCHAR" property="entmicroName"/>
<result column="merchant_account_level" jdbcType="INTEGER" property="merchantAccountLevel"/>
</resultMap>
<sql id="Base_Column_List">
<!--
WARNING - @mbg.generated
-->
id, superior_id, sub_id, `depth`, del_flag, created_date, created_by, updated_date,
updated_by
</sql>
<insert id="insertPath" parameterType="cn.com.glsx.merchants.entity.MerchantPath">
INSERT INTO platform_merchant_path(superior_id,sub_id,depth)
SELECT t.superior_id,#{merchantPath.subId},t.depth+1
FROM platform_merchant_path AS t
WHERE t.sub_id = #{merchantPath.superiorId}
UNION ALL
SELECT #{merchantPath.subId},#{merchantPath.subId},0
</insert>
<insert id="insertPathByMerchantPathRequest" parameterType="cn.com.glsx.merchants.model.request.MerchantPathRequest">
INSERT INTO platform_merchant_path(superior_id,sub_id,depth,created_date)
select super.superior_id,
sub.sub_id ,
super.depth + sub.depth + 1,
NOW()
from
platform_merchant_path super
cross join
platform_merchant_path sub
where super.sub_id = #{request.targetId}
and sub.superior_id = #{request.sourceId}
</insert>
<update id="updatePathDelFlagByMerchantPathRequest" parameterType="cn.com.glsx.merchants.model.request.MerchantPathRequest">
UPDATE platform_merchant_path
SET del_flag = -1
WHERE
sub_id IN (SELECT * FROM(SELECT sub_id FROM platform_merchant_path WHERE superior_id = #{request.sourceId}) AS t1)
AND
superior_id IN (SELECT * FROM(SELECT superior_id FROM platform_merchant_path WHERE sub_id = #{request.sourceId} AND superior_id != #{request.sourceId}) AS t2);
</update>
<delete id="deletePathByMerchantPathRequest" parameterType="cn.com.glsx.merchants.model.request.MerchantPathRequest">
DELETE from platform_merchant_path
where
sub_id in (select * from (select sub_id from platform_merchant_path where superior_id = #{request.sourceId}) as t1)
and
superior_id in (select * from (select superior_id from platform_merchant_path where sub_id = #{request.sourceId} and superior_id != #{request.sourceId}) as t2)
and del_flag = -1;
</delete>
<select id="findMerchantTree" resultType="cn.com.glsx.merchants.entity.MerchantPath"
parameterType="cn.com.glsx.merchants.model.request.MerchantRequest">
select t.superior_id as superiorId,t.sub_id as subId,t1.merchant_name as subName,t1.merchantNo as merchantNo,t1.merchant_account_level as merchantAccountLevel,t1.entmicro_name as entmicroName from (select superior_id,sub_id from platform_merchant_path where superior_id in (select sub_id from platform_merchant_path where superior_id=#{merchantRequest.id}) and depth=1
UNION ALL select null,#{merchantRequest.id})t left join platform_merchant t1 on t.sub_id=t1.id where t1.status=2
</select>
<select id="findAllMerchantTree" resultType="cn.com.glsx.merchants.entity.MerchantPath"
parameterType="cn.com.glsx.merchants.model.request.MerchantRequest">
select t.superior_id as superiorId,t.sub_id as subId,t1.status as status,t1.merchant_name as subName,t1.merchantNo as merchantNo,t1.merchant_account_level as merchantAccountLevel,t1.entmicro_name as entmicroName from (select superior_id,sub_id from platform_merchant_path where superior_id in (select sub_id from platform_merchant_path where superior_id=#{merchantRequest.id}) and depth=1
UNION ALL select null,#{merchantRequest.id})t left join platform_merchant t1 on t.sub_id=t1.id
</select>
<select id="findMerchantAllTree" resultType="cn.com.glsx.merchants.entity.MerchantPath"
parameterType="cn.com.glsx.merchants.model.request.MerchantRequest">
SELECT
t.superior_id AS superiorId,
t.sub_id AS subId,
t1.merchant_name AS subName,
t1.merchantNo AS merchantNo,
t1.merchant_account_level AS merchantAccountLevel,
t1.entmicro_name AS entmicroName
FROM
(
SELECT
superior_id,
sub_id
FROM
platform_merchant_path
WHERE
superior_id IN ( SELECT sub_id FROM platform_merchant_path WHERE superior_id IN (SELECT t1.id FROM platform_merchant t1 WHERE t1.merchant_account_level = 1)
)AND depth =1
union all
select null,t2.id
FROM platform_merchant t2 WHERE t2.merchant_account_level = 1
)t
left join platform_merchant t1 on t.sub_id=t1.id
</select>
<select id="findSubordinateMerchant" resultMap="BaseResultMap"
parameterType="java.lang.Integer">
select pp.*,pm.status,pm.merchant_account_level from platform_merchant_path pp
left join platform_merchant pm on pp.sub_id=pm.id
where pp.del_flag=0 and superior_id=#{merchantId}
</select>
<select id="findDirectSubordinateMerchant" resultMap="BaseResultMap"
parameterType="java.lang.Integer">
select pp.* from platform_merchant_path pp
left join platform_merchant t1 on pp.sub_id=t1.id
where pp.del_flag=0 and pp.superior_id=#{merchantId}
and (pp.depth=0
or (t1.merchant_account_level=4 and pp.depth=1))
</select>
<select id="findMerchantByIds" resultMap="BaseResultMap"
>
select pp.*,t1.merchant_name as subName from platform_merchant_path pp
left join platform_merchant t1 on pp.sub_id=t1.id
WHERE pp.depth=1 and pp.sub_id in
<foreach collection="list" index="index" item="item"
open="(" close=")" separator=",">
#{item}
</foreach>
</select>
<select id="findMerchantTreeToIds" resultType="java.lang.Integer">
select t.sub_id from (select superior_id,sub_id from platform_merchant_path where superior_id in (select sub_id from platform_merchant_path where superior_id=#{id}) and depth=1
UNION ALL select null,#{id})t left join platform_merchant t1 on t.sub_id=t1.id
</select>
<delete id="deleteSuperiorId">
DELETE FROM platform_merchant_path WHERE depth != 0 AND sub_id = (SELECT id FROM platform_merchant WHERE merchantNo= #{merchantNo})
</delete>
</mapper>