yaowanxin
5 天以前 73e27a267afa5eb2c94b3c70aa3556aaef690cea
src/main/resources/mapper/warehouse/WarehouseMapper.xml
@@ -4,72 +4,13 @@
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.warehouse.mapper.WarehouseMapper">
<!--    &lt;!&ndash; 定义 WarehouseDto 的 resultMap(优化后) &ndash;&gt;-->
<!--    <resultMap id="WarehouseDtoResultMap" type="com.ruoyi.warehouse.dto.WarehouseDto">-->
<!--        &lt;!&ndash; 映射 Warehouse 父类的字段(仓库主表信息) &ndash;&gt;-->
<!--        <id property="id" column="w_id"/> &lt;!&ndash; 明确别名,避免与子表id冲突 &ndash;&gt;-->
<!--        <result property="warehouseName" column="warehouse_name"/>-->
<!--        &lt;!&ndash; 其他父类字段按需添加,建议统一加表别名前缀 &ndash;&gt;-->
<!--        &lt;!&ndash; 移除 WarehouseDto 中的 goodsShelvesName 字段映射-->
<!--             原因:该字段属于子表 warehouse_goods_shelves,应通过嵌套集合获取,避免数据歧义 &ndash;&gt;-->
<!--        &lt;!&ndash; 映射 WarehouseDto 自身的分类字段(若业务需要关联文档分类) &ndash;&gt;-->
<!--        <result property="category" column="category"/>-->
<!--        &lt;!&ndash; 映射嵌套集合:仓库-货架(一对多) &ndash;&gt;-->
<!--        <collection property="warehouseGoodsShelvesList" ofType="com.ruoyi.warehouse.dto.WarehouseGoodsShelvesDto">-->
<!--            <id property="id" column="wgs_id"/> &lt;!&ndash; 货架表主键,唯一标识 &ndash;&gt;-->
<!--            <result property="goodsShelvesName" column="goods_shelves_name"/>-->
<!--            <result property="warehouseId" column="w_id"/> &lt;!&ndash; 关联仓库的外键,便于反向追溯 &ndash;&gt;-->
<!--            &lt;!&ndash; 其他货架字段按需添加(如创建时间、状态等) &ndash;&gt;-->
<!--            &lt;!&ndash; 映射嵌套集合:货架-行列(一对多) &ndash;&gt;-->
<!--            <collection property="warehouseGoodsShelvesRowcolList" ofType="com.ruoyi.warehouse.dto.WarehouseGoodsShelvesRowcolDto">-->
<!--                <id property="id" column="wgsr_id"/> &lt;!&ndash; 行列表自身主键,修正原外键别名导致的歧义 &ndash;&gt;-->
<!--                <result property="storey" column="storey"/>-->
<!--                <result property="arrange" column="arrange"/>-->
<!--                <result property="warehouseGoodsShelvesId" column="wgs_id"/> &lt;!&ndash; 关联货架的外键 &ndash;&gt;-->
<!--                &lt;!&ndash; 其他行列字段按需添加(如容量、状态等) &ndash;&gt;-->
<!--            </collection>-->
<!--        </collection>-->
<!--    </resultMap>-->
<!--    <select id="findList" resultMap="WarehouseDtoResultMap">-->
<!--        SELECT-->
<!--        w.id AS w_id, &#45;&#45; 仓库表id加别名,避免与子表id冲突-->
<!--        w.warehouse_name,-->
<!--        wgs.id AS wgs_id, &#45;&#45; 货架表id加别名-->
<!--        wgs.goods_shelves_name,-->
<!--        wgsr.id AS wgsr_id, &#45;&#45; 行列表id加别名(修正原外键别名,明确为主键)-->
<!--        wgsr.storey,-->
<!--        wgsr.arrange,-->
<!--        dc.category-->
<!--        FROM warehouse_goods_shelves_rowcol wgsr-->
<!--        LEFT JOIN warehouse_goods_shelves wgs ON wgs.id = wgsr.warehouse_goods_shelves_id-->
<!--        LEFT JOIN warehouse w ON  w.id = wgs.warehouse_id-->
<!--        &#45;&#45; 关联文档表和分类表时,若无需文档详情,建议用 EXISTS 优化,避免重复数据-->
<!--        LEFT JOIN documentation doc ON doc.warehouse_goods_shelves_rowcol_id = wgsr.id-->
<!--        LEFT JOIN document_classification dc ON doc.document_classification_id = dc.id-->
<!--        <where>-->
<!--            &lt;!&ndash; 移除 1=1,MyBatis的where标签会自动处理首个AND &ndash;&gt;-->
<!--            <if test="warehouse.warehouseName != null and warehouse.warehouseName != ''">-->
<!--                AND w.warehouse_name LIKE CONCAT('%', #{warehouse.warehouseName}, '%')-->
<!--            </if>-->
<!--            <if test="warehouse.id != null">-->
<!--                AND w.id = #{warehouse.id}-->
<!--            </if>-->
<!--        </where>-->
<!--        &#45;&#45; 分组去重:避免因多表连接导致的重复数据(核心优化点)-->
<!--        GROUP BY w.id, wgs.id, wgsr.id-->
<!--    </select>-->
        <select id="findList" resultType="com.ruoyi.warehouse.dto.WarehouseDto">
    <select id="findList" resultType="com.ruoyi.warehouse.dto.WarehouseDto">
        SELECT
        wgsr.*,
        w.warehouse_name,
        wgs.goods_shelves_name,
        w.*,
        wgs.name,
        doc.doc_name,
        doc.doc_number,
        dc.category
        FROM warehouse_goods_shelves_rowcol wgsr
        LEFT JOIN warehouse_goods_shelves wgs ON wgs.id = wgsr.warehouse_goods_shelves_id
@@ -93,6 +34,9 @@
            <if test="warehouse.warehouseName != null">
                and warehouse_name like concat('%',#{warehouse.warehouseName},'%')
            </if>
            <if test="warehouse.id != null">
                and w.id = #{warehouse.id}
            </if>
        </where>
    </select>
</mapper>