Lius
2025-03-27 b0f56573ea27a8798764314c72cf39e9eb0651dc
lxzn-module-system/lxzn-system-biz/src/main/java/org/jeecg/modules/system/mapper/xml/MdcProductionMapper.xml
@@ -31,4 +31,97 @@
    <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>
</mapper>
    <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>
    <select id="findChildren" resultType="java.lang.String">
        WITH temp ( id ) AS (
            SELECT
                id
            FROM
                mdc_production
            WHERE
                id IN
            <foreach collection="mdcProductionIds" item = "id" index = "index" open = "(" close = ")" separator = ",">
                #{id}
            </foreach>
            AND mdc_flag = '1' UNION ALL
            SELECT
                a.id
            FROM
                mdc_production a
                    INNER JOIN temp ON a.parent_id = temp.id
            WHERE
                a.mdc_flag = '1'
        ) SELECT
            *
        FROM
            temp
    </select>
    <select id="loadProductionOptions" 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
        WHERE
            t2.user_id = #{userId} AND t1.mdc_flag = '1'
        <choose>
            <when test="productionId != null and productionId != ''">
                AND t1.org_type = '3' AND t1.parent_id = #{productionId}
            </when>
            <otherwise>
                AND t1.org_type = '2'
            </otherwise>
        </choose>
    </select>
    <select id="findTeamValue" resultType="java.lang.String">
        SELECT DISTINCT
            t1.team_code deamCode
        FROM
            mdc_equipment t1
            LEFT JOIN mdc_production_equipment t2 ON t1.id = t2.equipment_id
        WHERE t2.production_id IN
        <foreach collection="productionList" item = "productionId" index = "index" open = "(" close= ")" separator = ",">
            #{productionId}
        </foreach>
    </select>
</mapper>