<?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="org.jeecg.modules.system.mapper.MdcProductionMapper">
|
|
<!--递归查询所有子节点-->
|
<select id="recursionChildren" resultType="java.lang.String">
|
WITH temp ( id ) AS (
|
SELECT
|
id
|
FROM
|
mdc_production
|
WHERE
|
id = #{ productionId } UNION ALL
|
SELECT
|
a.id
|
FROM
|
mdc_production a
|
INNER JOIN temp ON a.parent_id = temp.id
|
) SELECT
|
*
|
FROM
|
temp
|
</select>
|
|
<!--根据用户id和车间id获取用户拥有的车间id-->
|
<select id="findFirstProduction" resultType="java.lang.String">
|
SELECT TOP 1 t2.id FROM mdc_user_production t1 LEFT JOIN mdc_production t2 ON t1.pro_id = t2.id WHERE t1.user_id = #{ userId } AND t2.parent_id = #{productionId}
|
</select>
|
|
<!--根据用户id查询用户工段权限-->
|
<select id="findThreeProductionId" resultType="java.lang.String">
|
SELECT TOP 1 t2.id id FROM mdc_user_production t1 LEFT JOIN mdc_production t2 ON t1.pro_id = t2.id WHERE t1.user_id = #{userId} AND t2.org_type = '3'
|
</select>
|
<select id="findAllProductionId" resultType="org.jeecg.modules.system.entity.MdcProduction">
|
SELECT
|
t1.*
|
FROM
|
mdc_production t1
|
LEFT JOIN mdc_user_production t2 ON t1.id = t2.pro_id
|
LEFT JOIN sys_user t3 on t3.ID=t2.user_id
|
WHERE
|
t3.id = #{userId}
|
AND t1.org_type = '3'
|
</select>
|
<select id="recursionChildrenByList" resultType="java.lang.String">
|
WITH temp (id) AS (
|
-- 初始查询,获取指定 id 的记录
|
SELECT
|
id
|
FROM
|
mdc_production
|
WHERE
|
id IN
|
<foreach collection = "productionIds" item = "id" index = "index" open = "(" close = ")" separator = ",">
|
#{id}
|
</foreach>
|
UNION ALL
|
-- 递归查询,查找子节点
|
SELECT
|
a.id
|
FROM
|
mdc_production a
|
INNER JOIN temp ON a.parent_id = temp.id
|
)
|
-- 最终查询,使用 DISTINCT 去重
|
SELECT DISTINCT
|
id
|
FROM
|
temp;
|
</select>
|
</mapper>
|