入库出库分析

This commit is contained in:
猫猫guowen
2025-12-08 13:58:49 +08:00
parent 6f392fef57
commit d51f8b879f

View File

@@ -53,7 +53,7 @@ public class KpiServiceImpl implements KpiService
Map<String, Integer> roadwayCount = new HashMap<>(); Map<String, Integer> roadwayCount = new HashMap<>();
for (MydoJob job : list) { for (MydoJob job : list) {
// 检查入库作业标识是否小于10 // 检查入库作业标识是否小于20
if (job.getInOrOut() == null || Integer.parseInt(job.getInOrOut()) >= 20) { if (job.getInOrOut() == null || Integer.parseInt(job.getInOrOut()) >= 20) {
continue; continue;
} }
@@ -528,36 +528,79 @@ public class KpiServiceImpl implements KpiService
mydoJobParam.setCreateLeftTime(startTime); mydoJobParam.setCreateLeftTime(startTime);
mydoJobParam.setCreateRightTime(endTime); mydoJobParam.setCreateRightTime(endTime);
mydoJobParam.setInOut(inOut); mydoJobParam.setInOut(inOut);
List<DateTime> datesBetween = DateUtil.rangeToList(DateUtil.parseDate(startTime), DateUtil.parseDate(endTime), DateField.DAY_OF_MONTH);
List<MydoJob> list = mydoJobFinishMapper.selectMydoJobFinishListByMydoJob(mydoJobParam); List<MydoJob> list = mydoJobFinishMapper.selectMydoJobFinishListByMydoJob(mydoJobParam);
// 获取所有巷道ID(1和2) // 收集所有涉及的楼层
List<String> roadwayIds = Arrays.asList("1", "2"); Set<Long> floorSet = new HashSet<>();
Map<String, BasCargoSpace> cargoSpaceCache = new HashMap<>();
// 遍历作业记录,收集涉及的货位ID并查询对应楼层
for (MydoJob job : list) {
if (job.getCargoSpaceId() != null) {
// 检查缓存中是否有该货位信息
if (!cargoSpaceCache.containsKey(job.getCargoSpaceId())) {
// 使用现有的查询方法查询货位信息
BasCargoSpace queryParam = new BasCargoSpace();
queryParam.setCargoSpaceId(job.getCargoSpaceId());
List<BasCargoSpace> cargoSpaces = basCargoSpaceMapper.selectBasCargoSpaceList(queryParam);
if (!cargoSpaces.isEmpty()) {
BasCargoSpace cargoSpace = cargoSpaces.get(0);
cargoSpaceCache.put(job.getCargoSpaceId(), cargoSpace);
if (cargoSpace.getTheFloor() != null) {
floorSet.add(cargoSpace.getTheFloor());
}
}
} else {
BasCargoSpace cachedSpace = cargoSpaceCache.get(job.getCargoSpaceId());
if (cachedSpace.getTheFloor() != null) {
floorSet.add(cachedSpace.getTheFloor());
}
}
}
}
// 将楼层排序
List<Long> floors = new ArrayList<>(floorSet);
Collections.sort(floors);
// 生成日期范围
List<DateTime> datesBetween = DateUtil.rangeToList(DateUtil.parseDate(startTime), DateUtil.parseDate(endTime), DateField.DAY_OF_MONTH);
List<String> xAxis = new ArrayList<>(); List<String> xAxis = new ArrayList<>();
List<Map<String, Object>> series = new ArrayList<>(); List<Map<String, Object>> series = new ArrayList<>();
// 为每个巷道创建一个系列 // 为每个楼层创建一个系列
for (String roadwayId : roadwayIds) { for (Long floor : floors) {
Map<String, Object> seriesItem = new HashMap<>(); Map<String, Object> seriesItem = new HashMap<>();
seriesItem.put("name", roadwayId + "号巷道"); seriesItem.put("name", floor + "层");
seriesItem.put("type", "line"); seriesItem.put("type", "line");
List<Long> data = new ArrayList<>(); List<Long> data = new ArrayList<>();
seriesItem.put("data", data); seriesItem.put("data", data);
series.add(seriesItem); series.add(seriesItem);
} }
// 按日期统计每个巷道的数量 // 按日期统计每个楼层的数量
for (DateTime dateTime : datesBetween) { for (DateTime dateTime : datesBetween) {
xAxis.add(DateUtil.format(dateTime, "yyyy-MM-dd")); xAxis.add(DateUtil.format(dateTime, "yyyy-MM-dd"));
// 统计每个巷道在当天的数量 // 统计每个楼层在当天的数量
for (int i = 0; i < roadwayIds.size(); i++) { for (int i = 0; i < floors.size(); i++) {
String roadwayId = roadwayIds.get(i); Long floor = floors.get(i);
long count = list.stream() long count = 0;
.filter(mydoJob -> roadwayId.equals(mydoJob.getRoadwayId())
&& DateUtil.isIn(mydoJob.getCreateTime(), DateUtil.beginOfDay(dateTime), DateUtil.endOfDay(dateTime))) // 遍历作业记录,统计该楼层在当天的作业数量
.count(); for (MydoJob job : list) {
if (DateUtil.isIn(job.getCreateTime(), DateUtil.beginOfDay(dateTime), DateUtil.endOfDay(dateTime))) {
// 查找该作业对应的货位是否属于当前楼层
if (job.getCargoSpaceId() != null && cargoSpaceCache.containsKey(job.getCargoSpaceId())) {
BasCargoSpace space = cargoSpaceCache.get(job.getCargoSpaceId());
if (space.getTheFloor() != null && space.getTheFloor().equals(floor)) {
count++;
}
}
}
}
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
List<Long> data = (List<Long>) series.get(i).get("data"); List<Long> data = (List<Long>) series.get(i).get("data");
@@ -571,4 +614,6 @@ public class KpiServiceImpl implements KpiService
} }
} }