feat(wms): 优化钢卷库区操作记录吞吐报表统计功能
- 后端新增 statistics 接口聚合图表数据,避免前端遍历计算 - 新增 WmsCoilWarehouseOperationLogStatisticsVo 数据传输对象 - 实现按操作人汇总、按日趋势、汇总指标三个维度的数据查询 - 前端 record 页面集成统计卡片、趋势图、饼图、柱状图展示 - 优化分页逻辑,移除前端全量数据存储和分页计算 - 添加完整的 SQL 统计查询语句支持多维度数据聚合
This commit is contained in:
@@ -23,6 +23,7 @@ import com.klp.common.enums.BusinessType;
|
||||
import com.klp.common.utils.poi.ExcelUtil;
|
||||
import com.klp.domain.vo.WmsCoilWarehouseOperationLogVo;
|
||||
import com.klp.domain.vo.WmsCoilWarehouseOperationLogExportVo;
|
||||
import com.klp.domain.vo.WmsCoilWarehouseOperationLogStatisticsVo;
|
||||
import com.klp.domain.bo.WmsCoilWarehouseOperationLogBo;
|
||||
import com.klp.service.IWmsCoilWarehouseOperationLogService;
|
||||
import com.klp.common.core.page.TableDataInfo;
|
||||
@@ -178,5 +179,13 @@ public class WmsCoilWarehouseOperationLogController extends BaseController {
|
||||
ExcelUtil.exportExcel(list, "钢卷库区操作记录导出", WmsCoilWarehouseOperationLogExportVo.class, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 吞吐报表统计 —— 后端聚合图表数据,前端仅负责渲染
|
||||
*/
|
||||
@GetMapping("/statistics")
|
||||
public R<WmsCoilWarehouseOperationLogStatisticsVo> statistics(WmsCoilWarehouseOperationLogBo bo) {
|
||||
return R.ok(iWmsCoilWarehouseOperationLogService.statistics(bo));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.klp.domain.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 吞吐报表统计结果 VO —— 后端聚合所有图表数据,前端不再遍历全量 rows
|
||||
*
|
||||
* @author klp
|
||||
* @date 2026-06-22
|
||||
*/
|
||||
@Data
|
||||
public class WmsCoilWarehouseOperationLogStatisticsVo {
|
||||
|
||||
/** 操作记录总数 */
|
||||
private long totalCount;
|
||||
|
||||
/** 总重量(kg),所有关联钢卷净重之和 */
|
||||
private BigDecimal totalWeight;
|
||||
|
||||
/** 涉及库位数量(去重) */
|
||||
private long warehouseCount;
|
||||
|
||||
/** 操作人汇总(用于左侧表格 + 饼图 + 柱状图) */
|
||||
private List<UserSummary> userSummary;
|
||||
|
||||
/** 按日趋势数据(用于折线图) */
|
||||
private List<TrendItem> trendData;
|
||||
|
||||
// ---------- inner types ----------
|
||||
|
||||
@Data
|
||||
public static class UserSummary {
|
||||
/** 操作人 */
|
||||
private String createBy;
|
||||
/** 操作卷数 */
|
||||
private long coilCount;
|
||||
/** 总重量(kg) */
|
||||
private BigDecimal totalWeight;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class TrendItem {
|
||||
/** 日期,格式 yyyy-MM-dd */
|
||||
private String date;
|
||||
/** 当天操作笔数 */
|
||||
private long count;
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package com.klp.mapper;
|
||||
|
||||
import com.klp.domain.WmsCoilWarehouseOperationLog;
|
||||
import com.klp.domain.vo.WmsCoilWarehouseOperationLogVo;
|
||||
import com.klp.domain.vo.WmsCoilWarehouseOperationLogStatisticsVo;
|
||||
import com.klp.common.core.mapper.BaseMapperPlus;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
@@ -21,4 +22,34 @@ public interface WmsCoilWarehouseOperationLogMapper extends BaseMapperPlus<WmsCo
|
||||
@Param("inOutType") Integer inOutType,
|
||||
@Param("startTime") Date startTime,
|
||||
@Param("endTime") Date endTime);
|
||||
|
||||
/**
|
||||
* 吞吐报表统计 —— 汇总指标(总数、总重量、涉及库位数)
|
||||
*/
|
||||
WmsCoilWarehouseOperationLogStatisticsVo selectStatisticsSummary(@Param("actualWarehouseId") Long actualWarehouseId,
|
||||
@Param("operationType") Integer operationType,
|
||||
@Param("inOutType") Integer inOutType,
|
||||
@Param("createBy") String createBy,
|
||||
@Param("startTime") Date startTime,
|
||||
@Param("endTime") Date endTime);
|
||||
|
||||
/**
|
||||
* 吞吐报表统计 —— 按操作人汇总
|
||||
*/
|
||||
List<WmsCoilWarehouseOperationLogStatisticsVo.UserSummary> selectUserSummary(@Param("actualWarehouseId") Long actualWarehouseId,
|
||||
@Param("operationType") Integer operationType,
|
||||
@Param("inOutType") Integer inOutType,
|
||||
@Param("createBy") String createBy,
|
||||
@Param("startTime") Date startTime,
|
||||
@Param("endTime") Date endTime);
|
||||
|
||||
/**
|
||||
* 吞吐报表统计 —— 按日趋势
|
||||
*/
|
||||
List<WmsCoilWarehouseOperationLogStatisticsVo.TrendItem> selectTrendData(@Param("actualWarehouseId") Long actualWarehouseId,
|
||||
@Param("operationType") Integer operationType,
|
||||
@Param("inOutType") Integer inOutType,
|
||||
@Param("createBy") String createBy,
|
||||
@Param("startTime") Date startTime,
|
||||
@Param("endTime") Date endTime);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.klp.common.core.domain.PageQuery;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.Collection;
|
||||
import com.klp.domain.vo.WmsCoilWarehouseOperationLogExportVo;
|
||||
import com.klp.domain.vo.WmsCoilWarehouseOperationLogStatisticsVo;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@@ -85,4 +86,12 @@ public interface IWmsCoilWarehouseOperationLogService {
|
||||
* @return 导出数据列表
|
||||
*/
|
||||
List<WmsCoilWarehouseOperationLogExportVo> exportBySecondWarehouseIdAndTimeRange(Long secondWarehouseId, Integer operationType, Integer inOutType, Date startTime, Date endTime);
|
||||
|
||||
/**
|
||||
* 吞吐报表统计 —— 后端聚合,返回图表所需全部数据
|
||||
*
|
||||
* @param bo 查询条件(与 /list 共用同一套 BO)
|
||||
* @return 统计结果(汇总卡片 + 操作人排名 + 按日趋势)
|
||||
*/
|
||||
WmsCoilWarehouseOperationLogStatisticsVo statistics(WmsCoilWarehouseOperationLogBo bo);
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import org.springframework.stereotype.Service;
|
||||
import com.klp.domain.bo.WmsCoilWarehouseOperationLogBo;
|
||||
import com.klp.domain.vo.WmsCoilWarehouseOperationLogVo;
|
||||
import com.klp.domain.vo.WmsCoilWarehouseOperationLogExportVo;
|
||||
import com.klp.domain.vo.WmsCoilWarehouseOperationLogStatisticsVo;
|
||||
import java.math.BigDecimal;
|
||||
import com.klp.domain.vo.WmsMaterialCoilVo;
|
||||
import com.klp.domain.WmsCoilWarehouseOperationLog;
|
||||
@@ -352,4 +353,34 @@ public class WmsCoilWarehouseOperationLogServiceImpl implements IWmsCoilWarehous
|
||||
default: return String.valueOf(inOutType);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public WmsCoilWarehouseOperationLogStatisticsVo statistics(WmsCoilWarehouseOperationLogBo bo) {
|
||||
Long actualWarehouseId = bo.getActualWarehouseId();
|
||||
Integer operationType = bo.getOperationType();
|
||||
Integer inOutType = bo.getInOutType();
|
||||
String createBy = bo.getCreateBy();
|
||||
Date startTime = bo.getCreateStartTime();
|
||||
Date endTime = bo.getCreateEndTime();
|
||||
|
||||
// 一次 RPC 内三次轻量 GROUP BY 查询,远比拉取全量 rows 再聚合快
|
||||
WmsCoilWarehouseOperationLogStatisticsVo summary =
|
||||
baseMapper.selectStatisticsSummary(actualWarehouseId, operationType, inOutType, createBy, startTime, endTime);
|
||||
|
||||
List<WmsCoilWarehouseOperationLogStatisticsVo.UserSummary> userSummary =
|
||||
baseMapper.selectUserSummary(actualWarehouseId, operationType, inOutType, createBy, startTime, endTime);
|
||||
|
||||
List<WmsCoilWarehouseOperationLogStatisticsVo.TrendItem> trendData =
|
||||
baseMapper.selectTrendData(actualWarehouseId, operationType, inOutType, createBy, startTime, endTime);
|
||||
|
||||
if (summary == null) {
|
||||
summary = new WmsCoilWarehouseOperationLogStatisticsVo();
|
||||
summary.setTotalCount(0);
|
||||
summary.setTotalWeight(BigDecimal.ZERO);
|
||||
summary.setWarehouseCount(0);
|
||||
}
|
||||
summary.setUserSummary(userSummary);
|
||||
summary.setTrendData(trendData);
|
||||
return summary;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,4 +129,66 @@
|
||||
ORDER BY log.create_time DESC
|
||||
</select>
|
||||
|
||||
<!-- ==================== 吞吐报表统计 SQL ==================== -->
|
||||
|
||||
<!-- 公共过滤条件片段 -->
|
||||
<sql id="statisticsWhere">
|
||||
<where>
|
||||
log.del_flag = 0
|
||||
<if test="actualWarehouseId != null">
|
||||
AND log.actual_warehouse_id = #{actualWarehouseId}
|
||||
</if>
|
||||
<if test="operationType != null">
|
||||
AND log.operation_type = #{operationType}
|
||||
</if>
|
||||
<if test="inOutType != null">
|
||||
AND log.in_out_type = #{inOutType}
|
||||
</if>
|
||||
<if test="createBy != null and createBy != ''">
|
||||
AND log.create_by = #{createBy}
|
||||
</if>
|
||||
<if test="startTime != null">
|
||||
AND log.create_time >= #{startTime}
|
||||
</if>
|
||||
<if test="endTime != null">
|
||||
AND log.create_time <= #{endTime}
|
||||
</if>
|
||||
</where>
|
||||
</sql>
|
||||
|
||||
<!-- 汇总指标:总数、总重量、涉及库位数 -->
|
||||
<select id="selectStatisticsSummary" resultType="com.klp.domain.vo.WmsCoilWarehouseOperationLogStatisticsVo">
|
||||
SELECT
|
||||
COUNT(*) AS totalCount,
|
||||
COALESCE(SUM(mc.net_weight), 0) AS totalWeight,
|
||||
COUNT(DISTINCT log.actual_warehouse_id) AS warehouseCount
|
||||
FROM wms_coil_warehouse_operation_log log
|
||||
LEFT JOIN wms_material_coil mc ON log.coil_id = mc.coil_id AND mc.del_flag = 0
|
||||
<include refid="statisticsWhere"/>
|
||||
</select>
|
||||
|
||||
<!-- 按操作人汇总 -->
|
||||
<select id="selectUserSummary" resultType="com.klp.domain.vo.WmsCoilWarehouseOperationLogStatisticsVo$UserSummary">
|
||||
SELECT
|
||||
log.create_by AS createBy,
|
||||
COUNT(*) AS coilCount,
|
||||
COALESCE(SUM(mc.net_weight), 0) AS totalWeight
|
||||
FROM wms_coil_warehouse_operation_log log
|
||||
LEFT JOIN wms_material_coil mc ON log.coil_id = mc.coil_id AND mc.del_flag = 0
|
||||
<include refid="statisticsWhere"/>
|
||||
GROUP BY log.create_by
|
||||
ORDER BY coilCount DESC
|
||||
</select>
|
||||
|
||||
<!-- 按日趋势 -->
|
||||
<select id="selectTrendData" resultType="com.klp.domain.vo.WmsCoilWarehouseOperationLogStatisticsVo$TrendItem">
|
||||
SELECT
|
||||
DATE_FORMAT(log.create_time, '%Y-%m-%d') AS date,
|
||||
COUNT(*) AS count
|
||||
FROM wms_coil_warehouse_operation_log log
|
||||
<include refid="statisticsWhere"/>
|
||||
GROUP BY DATE_FORMAT(log.create_time, '%Y-%m-%d')
|
||||
ORDER BY date ASC
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
||||
Reference in New Issue
Block a user