|
@@ -93,6 +93,29 @@
|
|
|
WHERE row_num = 1;
|
|
WHERE row_num = 1;
|
|
|
</select>
|
|
</select>
|
|
|
|
|
|
|
|
|
|
+ <select id="getRelatedCompanyById" resultType="com.wx.blink.common.vo.BlinkCustomerVO">
|
|
|
|
|
+ WITH RECURSIVE full_tree AS (
|
|
|
|
|
+ /* 向上查询部分*/
|
|
|
|
|
+ SELECT *, 0 AS level, 'current_start' AS relation
|
|
|
|
|
+ FROM blink_customer
|
|
|
|
|
+ WHERE id = #{id} /* 起始节点ID*/
|
|
|
|
|
+ UNION ALL
|
|
|
|
|
+ /* 向上查找父节点(上级)*/
|
|
|
|
|
+ SELECT c.*, ft.level + 1, 'ancestor' AS relation
|
|
|
|
|
+ FROM blink_customer c
|
|
|
|
|
+ JOIN full_tree ft ON c.id = ft.group_customer_id
|
|
|
|
|
+ WHERE ft.relation IN ('current_start', 'ancestor') AND ft.level < 10/*向上最大找寻10次*/
|
|
|
|
|
+ UNION ALL
|
|
|
|
|
+ /* 向下查找子节点(下级)*/
|
|
|
|
|
+ SELECT c.*, ft.level + 1, 'descendant' AS relation
|
|
|
|
|
+ FROM blink_customer c
|
|
|
|
|
+ JOIN full_tree ft ON c.group_customer_id = ft.id
|
|
|
|
|
+ WHERE ft.relation IN ('current_start', 'descendant') AND ft.level < 10/*向下最大找寻10次*/
|
|
|
|
|
+ )
|
|
|
|
|
+ SELECT * FROM full_tree
|
|
|
|
|
+ ORDER BY relation, ABS(level);
|
|
|
|
|
+ </select>
|
|
|
|
|
+
|
|
|
<update id="customerTransfer">
|
|
<update id="customerTransfer">
|
|
|
update blink_customer set belong_region=#{vo.belongRegion},market_staff=#{vo.marketStaff} where id = #{vo.cusid}
|
|
update blink_customer set belong_region=#{vo.belongRegion},market_staff=#{vo.marketStaff} where id = #{vo.cusid}
|
|
|
</update>
|
|
</update>
|