LocationStatisticsServiceImpl.java
4.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package com.huaheng.api.digitalTwins.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.huaheng.api.digitalTwins.domain.CskInfoOverviewDto;
import com.huaheng.api.digitalTwins.domain.LkInfoOverviewDto;
import com.huaheng.api.digitalTwins.domain.LocationInfoOverviewDto;
import com.huaheng.api.digitalTwins.domain.WarehouseInfoOverviewDto;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.pc.config.location.domain.Location;
import com.huaheng.pc.config.location.service.LocationService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;
import java.util.stream.Collectors;
/**
* 库位统计相关业务接口实现类
*/
@Service
@RequiredArgsConstructor
public class LocationStatisticsServiceImpl implements LocationStatisticsService {
private final LocationService locationService;
@Override
public void getLocationInfoOverview(WarehouseInfoOverviewDto warehouseInfoOverviewDto) {
// 获取所有库位信息
LambdaQueryWrapper<Location> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.select(Location::getCode, Location::getContainerCode, Location::getZoneCode);
List<Location> locationList = locationService.list(queryWrapper);
// TODO: L、C魔法值
// 过滤出立库库位
List<Location> lkLocationList = locationList.stream()
.filter(x -> "L".equals(x.getZoneCode()))
.collect(Collectors.toList());
// 封装立库信息
LkInfoOverviewDto lkInfoOverviewDto = new LkInfoOverviewDto();
lkInfoOverviewDto.setLength(BigDecimal.ONE);
lkInfoOverviewDto.setWidth(BigDecimal.ONE);
lkInfoOverviewDto.setHeight(BigDecimal.ONE);
lkInfoOverviewDto.setVolume(BigDecimal.ONE);
if (StringUtils.isNotEmpty(lkLocationList)) {
lkInfoOverviewDto.setLocationCount(lkLocationList.size());
// 集合类型转换 实体->Dto
List<LocationInfoOverviewDto> locationInfoOverviewDtoList = lkLocationList.stream()
.map(location -> {
LocationInfoOverviewDto locationInfoOverviewDto = new LocationInfoOverviewDto();
BeanUtils.copyProperties(location, locationInfoOverviewDto);
return locationInfoOverviewDto;
})
.collect(Collectors.toList());
lkInfoOverviewDto.setLocations(locationInfoOverviewDtoList);
}
// 过滤出穿梭库库位
List<Location> cskLocationList = locationList.stream()
.filter(x -> "C".equals(x.getZoneCode()))
.collect(Collectors.toList());
// 封装穿梭库信息
CskInfoOverviewDto cskInfoOverviewDto = new CskInfoOverviewDto();
cskInfoOverviewDto.setLength(BigDecimal.valueOf(2));
cskInfoOverviewDto.setWidth(BigDecimal.valueOf(2));
cskInfoOverviewDto.setHeight(BigDecimal.valueOf(2));
cskInfoOverviewDto.setVolume(BigDecimal.valueOf(8));
if (StringUtils.isNotEmpty(cskLocationList)){
cskInfoOverviewDto.setLocationCount(cskLocationList.size());
// 集合类型转换 实体->Dto
List<LocationInfoOverviewDto> locationInfoOverviewDtoList = cskLocationList.stream()
.map(location -> {
LocationInfoOverviewDto locationInfoOverviewDto = new LocationInfoOverviewDto();
BeanUtils.copyProperties(location, locationInfoOverviewDto);
return locationInfoOverviewDto;
})
.collect(Collectors.toList());
cskInfoOverviewDto.setLocations(locationInfoOverviewDtoList);
}
// 封装仓库概况信息
warehouseInfoOverviewDto.setLk(lkInfoOverviewDto);
warehouseInfoOverviewDto.setCsk(cskInfoOverviewDto);
}
@Override
public BigDecimal getLocationUtilizationRate() {
// 获取所有库位
List<Location> allLocationList = locationService.list();
// 过滤出已使用(与托盘有关联)的库位
List<Location> usedLocationList = allLocationList.stream()
.filter(x -> StringUtils.isNotEmpty(x.getContainerCode()))
.collect(Collectors.toList());
// 库容使用率=仓库使用/仓库容积
if (StringUtils.isEmpty(usedLocationList)) {
return BigDecimal.valueOf(1);
} else {
return BigDecimal.valueOf((double) usedLocationList.size() / (double) allLocationList.size()).setScale(3, RoundingMode.UP);
}
}
}