<?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="com.ruoyi.warehouse.mapper.WarehouseMapper">
|
|
<!-- <!– 定义 WarehouseDto 的 resultMap(优化后) –>-->
|
<!-- <resultMap id="WarehouseDtoResultMap" type="com.ruoyi.warehouse.dto.WarehouseDto">-->
|
<!-- <!– 映射 Warehouse 父类的字段(仓库主表信息) –>-->
|
<!-- <id property="id" column="w_id"/> <!– 明确别名,避免与子表id冲突 –>-->
|
<!-- <result property="warehouseName" column="warehouse_name"/>-->
|
<!-- <!– 其他父类字段按需添加,建议统一加表别名前缀 –>-->
|
|
<!-- <!– 移除 WarehouseDto 中的 goodsShelvesName 字段映射-->
|
<!-- 原因:该字段属于子表 warehouse_goods_shelves,应通过嵌套集合获取,避免数据歧义 –>-->
|
|
<!-- <!– 映射 WarehouseDto 自身的分类字段(若业务需要关联文档分类) –>-->
|
<!-- <result property="category" column="category"/>-->
|
|
<!-- <!– 映射嵌套集合:仓库-货架(一对多) –>-->
|
<!-- <collection property="warehouseGoodsShelvesList" ofType="com.ruoyi.warehouse.dto.WarehouseGoodsShelvesDto">-->
|
<!-- <id property="id" column="wgs_id"/> <!– 货架表主键,唯一标识 –>-->
|
<!-- <result property="goodsShelvesName" column="goods_shelves_name"/>-->
|
<!-- <result property="warehouseId" column="w_id"/> <!– 关联仓库的外键,便于反向追溯 –>-->
|
<!-- <!– 其他货架字段按需添加(如创建时间、状态等) –>-->
|
|
<!-- <!– 映射嵌套集合:货架-行列(一对多) –>-->
|
<!-- <collection property="warehouseGoodsShelvesRowcolList" ofType="com.ruoyi.warehouse.dto.WarehouseGoodsShelvesRowcolDto">-->
|
<!-- <id property="id" column="wgsr_id"/> <!– 行列表自身主键,修正原外键别名导致的歧义 –>-->
|
<!-- <result property="storey" column="storey"/>-->
|
<!-- <result property="arrange" column="arrange"/>-->
|
<!-- <result property="warehouseGoodsShelvesId" column="wgs_id"/> <!– 关联货架的外键 –>-->
|
<!-- <!– 其他行列字段按需添加(如容量、状态等) –>-->
|
<!-- </collection>-->
|
<!-- </collection>-->
|
<!-- </resultMap>-->
|
|
<!-- <select id="findList" resultMap="WarehouseDtoResultMap">-->
|
<!-- SELECT-->
|
<!-- w.id AS w_id, -- 仓库表id加别名,避免与子表id冲突-->
|
<!-- w.warehouse_name,-->
|
<!-- wgs.id AS wgs_id, -- 货架表id加别名-->
|
<!-- wgs.goods_shelves_name,-->
|
<!-- wgsr.id AS wgsr_id, -- 行列表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-->
|
<!-- -- 关联文档表和分类表时,若无需文档详情,建议用 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>-->
|
<!-- <!– 移除 1=1,MyBatis的where标签会自动处理首个AND –>-->
|
<!-- <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>-->
|
<!-- -- 分组去重:避免因多表连接导致的重复数据(核心优化点)-->
|
<!-- GROUP BY w.id, wgs.id, wgsr.id-->
|
<!-- </select>-->
|
|
<select id="findList" resultType="com.ruoyi.warehouse.dto.WarehouseDto">
|
SELECT
|
wgsr.*,
|
w.warehouse_name,
|
wgs.goods_shelves_name,
|
doc.doc_name,
|
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
|
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>
|
1=1
|
<if test="warehouse.warehouseName != null">
|
and w.warehouse_name like concat('%',#{warehouse.warehouseName},'%')
|
</if>
|
<if test="warehouse.id != null">
|
and w.id = #{warehouse.id}
|
</if>
|
</where>
|
</select>
|
<select id="listAll" resultType="com.ruoyi.warehouse.pojo.Warehouse">
|
select * from warehouse
|
<where>
|
1=1
|
<if test="warehouse.warehouseName != null">
|
and warehouse_name like concat('%',#{warehouse.warehouseName},'%')
|
</if>
|
</where>
|
</select>
|
</mapper>
|