feat(wms): 新增发货计划统计功能

- 在 IWmsDeliveryPlanService 接口中新增 getDeliveryPlanStatistics 方法
- 在 WmsDeliveryPlanController 中添加 /statistics 接口用于获取统计信息
- 在 WmsDeliveryPlanMapper 中新增 selectDeliveryPlanStatistics 查询方法
- 在 WmsDeliveryPlanMapper.xml 中编写对应的 SQL 查询语句
- 在 WmsDeliveryPlanServiceImpl 中实现统计方法调用 Mapper 层
- 新增 WmsDeliveryPlanStatisticsVo 类用于封装统计结果数据
- 引入相关类导入依赖以支持新功能开发
This commit is contained in:
2025-11-25 16:58:47 +08:00
parent 21a662d7d8
commit 5591d702d7
6 changed files with 119 additions and 0 deletions

View File

@@ -3,6 +3,7 @@ package com.klp.controller;
import java.util.List;
import java.util.Arrays;
import com.klp.domain.vo.WmsDeliveryPlanStatisticsVo;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
@@ -96,4 +97,15 @@ public class WmsDeliveryPlanController extends BaseController {
@PathVariable Long[] planIds) {
return toAjax(iWmsDeliveryPlanService.deleteWithValidByIds(Arrays.asList(planIds), true));
}
/**
* 获取发货计划统计信息
*
* @param planId 计划ID可选
*/
@GetMapping("/statistics")
public R<List<WmsDeliveryPlanStatisticsVo>> getStatistics(@RequestParam(required = false) Long planId) {
List<WmsDeliveryPlanStatisticsVo> statistics = iWmsDeliveryPlanService.getDeliveryPlanStatistics(planId);
return R.ok(statistics);
}
}

View File

@@ -0,0 +1,46 @@
package com.klp.domain.vo;
import lombok.Data;
import java.math.BigDecimal;
/**
* 发货计划统计信息VO
*/
@Data
public class WmsDeliveryPlanStatisticsVo {
/**
* 计划ID
*/
private Long planId;
/**
* 计划名称
*/
private String planName;
/**
* 发货单数量
*/
private Integer waybillCount = 0;
/**
* 总卷数
*/
private Integer totalCoilCount = 0;
/**
* 总吨数(吨)
*/
private BigDecimal totalWeight = BigDecimal.ZERO;
/**
* 完成进度(百分比)
*/
private BigDecimal completionRate = BigDecimal.ZERO;
/**
* 已完成发货单数量
*/
private Integer completedWaybillCount = 0;
}

View File

@@ -1,9 +1,12 @@
package com.klp.mapper;
import com.klp.domain.WmsDeliveryPlan;
import com.klp.domain.vo.WmsDeliveryPlanStatisticsVo;
import com.klp.domain.vo.WmsDeliveryPlanVo;
import com.klp.common.core.mapper.BaseMapperPlus;
import java.util.List;
/**
* 发货计划Mapper接口
*
@@ -12,4 +15,5 @@ import com.klp.common.core.mapper.BaseMapperPlus;
*/
public interface WmsDeliveryPlanMapper extends BaseMapperPlus<WmsDeliveryPlanMapper, WmsDeliveryPlan, WmsDeliveryPlanVo> {
List<WmsDeliveryPlanStatisticsVo> selectDeliveryPlanStatistics(Long planId);
}

View File

@@ -1,6 +1,7 @@
package com.klp.service;
import com.klp.domain.WmsDeliveryPlan;
import com.klp.domain.vo.WmsDeliveryPlanStatisticsVo;
import com.klp.domain.vo.WmsDeliveryPlanVo;
import com.klp.domain.bo.WmsDeliveryPlanBo;
import com.klp.common.core.page.TableDataInfo;
@@ -46,4 +47,6 @@ public interface IWmsDeliveryPlanService {
* 校验并批量删除发货计划信息
*/
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
List<WmsDeliveryPlanStatisticsVo> getDeliveryPlanStatistics(Long planId);
}

View File

@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.klp.common.utils.StringUtils;
import com.klp.domain.vo.WmsDeliveryPlanStatisticsVo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import com.klp.domain.bo.WmsDeliveryPlanBo;
@@ -15,6 +16,7 @@ import com.klp.domain.WmsDeliveryPlan;
import com.klp.mapper.WmsDeliveryPlanMapper;
import com.klp.service.IWmsDeliveryPlanService;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Collection;
@@ -107,4 +109,15 @@ public class WmsDeliveryPlanServiceImpl implements IWmsDeliveryPlanService {
}
return baseMapper.deleteBatchIds(ids) > 0;
}
/**
* 获取发货计划统计信息
*
* @param planId 计划ID可选
* @return 统计信息列表
*/
public List<WmsDeliveryPlanStatisticsVo> getDeliveryPlanStatistics(Long planId) {
return baseMapper.selectDeliveryPlanStatistics(planId);
}
}

View File

@@ -16,5 +16,46 @@
<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/1000.0) 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>
</mapper>