Files
nanguangszwlback/mhd_wms/src/main/resources/mapper/outboundRank/OutboundRankMapper.xml
T
rcx bf96f5f005 feat(wms,oms):库存管理新增入库排名统计(按仓单+货品汇总,件数降序,与出库排名tab配对);还原出库排名第一版源码
入库排名统计(新增):WMS /inboundRankApi、OMS /executionInboundRankApi 的 queryMaterialRankList 分页+合计、exportMaterialRank 导出;口径:仅已入库(status=5),明细仅level=1主行,日期区间按入仓日期warehouse_date筛选(必填);一行=仓单内某货品合计(GROUP BY 仓单+货品 ORDER BY 件数DESC);字段:入仓日期/仓单编号/客户编号/存货人/货名/件数/毛重(吨=KG/1000)/投保总额(货品档案保额,组内MAX防重复累加)/体积(CBM)+货号/规格/单位;合计行:totalPieceCount/totalGrossWeightTon/totalInsureAmount/totalVolume/totalOrderCount;登录上下文:日期必填校验+topOrganizationId租户隔离,WMS另注入关联仓库warehouseId。出库排名统计(还原第一版):/outboundRankApi、/executionOutboundRankApi,按货品/线路汇总排名
2026-08-31 17:47:09 +08:00

127 lines
6.0 KiB
XML

<?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.mhd.wms.domain.outboundRank.repository.mapper.OutboundRankMapper">
<!--
出库排名统计公共查询条件
数据源:出库明细 out_material_detail(a,仅 level=1 主行防重复) join 出库单 stock_out_order(b)
口径:b.status in (9已出库,12已复核,13已交接),排除已取消(10)/已关闭(11);
日期按出库单创建时间 b.create_time(与出库单列表日期筛选一致)
-->
<sql id="outboundRankConditions">
a.del_flag = 1
and a.level = 1
and b.status in (9, 12, 13)
<if test="topOrganizationId != null">
and b.top_organization_id = #{topOrganizationId}
</if>
<if test="warehouseId != null">
and b.warehouse_id = #{warehouseId}
</if>
<if test="warehouseName != null and warehouseName != ''">
and b.warehouse_name like concat('%', #{warehouseName}, '%')
</if>
<if test="customerName != null and customerName != ''">
and b.customer_name like concat('%', #{customerName}, '%')
</if>
<if test="shipperName != null and shipperName != ''">
and b.shipper_name like concat('%', #{shipperName}, '%')
</if>
<if test="lineCode != null and lineCode != ''">
and b.line_code like concat('%', #{lineCode}, '%')
</if>
<if test="lineName != null and lineName != ''">
and b.line_name like concat('%', #{lineName}, '%')
</if>
<if test="createTimeStart != null and createTimeStart != ''">
and date_format(b.create_time,'%Y-%m-%d') &gt;= #{createTimeStart}
</if>
<if test="createTimeEnd != null and createTimeEnd != ''">
and date_format(b.create_time,'%Y-%m-%d') &lt;= #{createTimeEnd}
</if>
</sql>
<sql id="outboundRankFrom">
from out_material_detail a
join stock_out_order b on a.out_order_number = b.out_order_number and b.del_flag = 1
</sql>
<!-- 商品出库排名列表 -->
<select id="queryMaterialRankList" parameterType="com.mhd.wms.domain.outboundRank.repository.todo.OutboundRankDO"
resultType="com.mhd.wms.domain.outboundRank.repository.po.OutboundMaterialRankPO">
select
a.material_code AS materialCode,
MAX(a.material_name) AS materialName,
MAX(a.SPECIFICATION_MODEL) AS specificationModel,
MAX(a.unit_name) AS unitName,
IFNULL(SUM(a.outbound_quantity), 0) AS salesQuantity,
COUNT(DISTINCT a.out_order_number) AS tradeCount,
IFNULL(SUM(IFNULL(a.TOTAL_AMOUNT, 0)), 0) AS amount
<include refid="outboundRankFrom"/>
<where>
<include refid="outboundRankConditions"/>
<if test="materialCode != null and materialCode != ''">
and a.material_code like concat('%', #{materialCode}, '%')
</if>
<if test="materialName != null and materialName != ''">
and a.material_name like concat('%', #{materialName}, '%')
</if>
</where>
GROUP BY a.material_code
order by salesQuantity desc
</select>
<!-- 线路出库排名列表(线路为空的历史单不参与线路排名) -->
<select id="queryLineRankList" parameterType="com.mhd.wms.domain.outboundRank.repository.todo.OutboundRankDO"
resultType="com.mhd.wms.domain.outboundRank.repository.po.OutboundLineRankPO">
select
b.line_code AS lineCode,
MAX(b.line_name) AS lineName,
IFNULL(SUM(a.outbound_quantity), 0) AS salesQuantity,
COUNT(DISTINCT b.out_order_number) AS tradeCount,
IFNULL(SUM(IFNULL(a.TOTAL_AMOUNT, 0)), 0) AS amount
<include refid="outboundRankFrom"/>
<where>
<include refid="outboundRankConditions"/>
and b.line_code is not null and b.line_code != ''
</where>
GROUP BY b.line_code
order by salesQuantity desc
</select>
<!-- 商品出库排名合计(当前筛选条件全量) -->
<select id="queryMaterialRankTotal" parameterType="com.mhd.wms.domain.outboundRank.repository.todo.OutboundRankDO"
resultType="com.mhd.wms.domain.outboundRank.repository.po.OutboundRankTotalPO">
select
IFNULL(SUM(a.outbound_quantity), 0) AS totalSalesQuantity,
COUNT(DISTINCT a.out_order_number) AS totalTradeCount,
IFNULL(SUM(IFNULL(a.TOTAL_AMOUNT, 0)), 0) AS totalAmount
<include refid="outboundRankFrom"/>
<where>
<include refid="outboundRankConditions"/>
<if test="materialCode != null and materialCode != ''">
and a.material_code like concat('%', #{materialCode}, '%')
</if>
<if test="materialName != null and materialName != ''">
and a.material_name like concat('%', #{materialName}, '%')
</if>
</where>
</select>
<!-- 线路出库排名合计(当前筛选条件全量) -->
<select id="queryLineRankTotal" parameterType="com.mhd.wms.domain.outboundRank.repository.todo.OutboundRankDO"
resultType="com.mhd.wms.domain.outboundRank.repository.po.OutboundRankTotalPO">
select
IFNULL(SUM(a.outbound_quantity), 0) AS totalSalesQuantity,
COUNT(DISTINCT b.out_order_number) AS totalTradeCount,
IFNULL(SUM(IFNULL(a.TOTAL_AMOUNT, 0)), 0) AS totalAmount
<include refid="outboundRankFrom"/>
<where>
<include refid="outboundRankConditions"/>
and b.line_code is not null and b.line_code != ''
</where>
</select>
</mapper>