Files
klp-oa/klp-wms/src/main/resources/mapper/klp/WmsDeliveryPlanMapper.xml

96 lines
3.7 KiB
XML
Raw Normal View History

<?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.klp.mapper.WmsDeliveryPlanMapper">
<resultMap type="com.klp.domain.WmsDeliveryPlan" id="WmsDeliveryPlanResult">
<result property="planId" column="plan_id"/>
<result property="planName" column="plan_name"/>
<result property="planDate" column="plan_date"/>
<result property="remark" column="remark"/>
<result property="delFlag" column="del_flag"/>
<result property="createTime" column="create_time"/>
<result property="createBy" column="create_by"/>
<result property="updateTime" column="update_time"/>
<result property="updateBy" column="update_by"/>
</resultMap>
<select id="selectDeliveryPlanStatistics" resultType="com.klp.domain.vo.WmsDeliveryPlanStatisticsVo">
SELECT
dp.plan_id as planId,
dp.plan_name as planName,
COUNT(DISTINCT dw.waybill_id) as waybillCount,
COALESCE(SUM(completed_waybills.completed_count), 0) as completedWaybillCount,
COALESCE(SUM(detail_stats.total_coil_count), 0) as totalCoilCount,
COALESCE(SUM(detail_stats.total_weight), 0) as totalWeight,
CASE
WHEN COUNT(DISTINCT dw.waybill_id) > 0 THEN
ROUND((COALESCE(SUM(completed_waybills.completed_count), 0) * 100.0) / COUNT(DISTINCT dw.waybill_id), 2)
ELSE 0
END as completionRate
FROM wms_delivery_plan dp
LEFT JOIN wms_delivery_waybill dw ON dp.plan_id = dw.plan_id AND dw.del_flag = 0
LEFT JOIN (
SELECT
waybill_id,
COUNT(*) as total_coil_count,
SUM(weight) as total_weight
FROM wms_delivery_waybill_detail
WHERE del_flag = 0
GROUP BY waybill_id
) detail_stats ON dw.waybill_id = detail_stats.waybill_id
LEFT JOIN (
SELECT
plan_id,
COUNT(*) as completed_count
FROM wms_delivery_waybill
WHERE status = 2 AND del_flag = 0
GROUP BY plan_id
) completed_waybills ON dp.plan_id = completed_waybills.plan_id
WHERE dp.del_flag = 0
<if test="planId != null">
AND dp.plan_id = #{planId}
</if>
GROUP BY dp.plan_id, dp.plan_name
ORDER BY dp.create_time DESC
</select>
<select id="selectDeliveryReport" resultType="com.klp.domain.vo.WmsDeliveryReportVo">
SELECT
dwd.product_name as productName,
COUNT(DISTINCT dw.waybill_id) as waybillCount,
SUM(dwd.quantity) as coilCount,
SUM(dwd.weight) as totalWeight,
CASE
WHEN #{startTime} IS NOT NULL AND #{endTime} IS NOT NULL THEN
ROUND(COUNT(DISTINCT dw.waybill_id) / (DATEDIFF(#{endTime}, #{startTime}) + 1), 2)
ELSE 0
END as dailyWaybillCount,
CASE
WHEN #{startTime} IS NOT NULL AND #{endTime} IS NOT NULL THEN
ROUND(SUM(dwd.quantity) / (DATEDIFF(#{endTime}, #{startTime}) + 1), 2)
ELSE 0
END as dailyCoilCount,
CASE
WHEN #{startTime} IS NOT NULL AND #{endTime} IS NOT NULL THEN
ROUND(SUM(dwd.weight) / (DATEDIFF(#{endTime}, #{startTime}) + 1), 2)
ELSE 0
END as dailyWeight
FROM wms_delivery_waybill_detail dwd
LEFT JOIN wms_delivery_waybill dw ON dwd.waybill_id = dw.waybill_id AND dw.del_flag = 0
WHERE dwd.del_flag = 0
<if test="startTime != null">
AND dw.create_time >= #{startTime}
</if>
<if test="endTime != null">
AND dw.create_time &lt;= #{endTime}
</if>
GROUP BY dwd.product_name
ORDER BY totalWeight DESC
</select>
</mapper>