Commit eece8e37 by 丁伟峰

修改了返回的字段要素,并改用了strem方式简化逻辑

1 parent 09dbc25a
......@@ -24,9 +24,10 @@ public class CapacityStatQueryRespDTO {
private Date updateTime;
private String date;
private long engineerNum;
private String groupName;
private String levelType;
private String levelValue;
private String layer;
private String teamName;
private String showName;
}
}
......
......@@ -21,6 +21,7 @@ import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.TextStyle;
import java.util.*;
import java.util.stream.Collectors;
@Service
@Slf4j
......@@ -78,21 +79,32 @@ public class CapacityQueryServiceImpl implements CapacityQueryService {
// 根据大区/分部/分站查询,分别返回分部/分站/工作队的容量
Page<?> stats = null;
Pageable pageable = PageRequest.of(reqDTO.getPage() - 1, reqDTO.getSize());
if ("cluster".equals(reqDTO.getLevelType())) {
List<String> branchIds = getBranchIdsByClusterId(reqDTO.getLevelValue());
log.info("levelType: {} ==> branchIds: {}", reqDTO.getLevelType(), branchIds);
Map<String, String> names = null;
String levelType = reqDTO.getLevelType();
String levelValue = reqDTO.getLevelValue();
if ("cluster".equals(levelType)) {
names = orgBranchDao.findAllByClusterId(levelValue).stream()
.collect(Collectors.toMap(OrgBranchEntity::getBranchId, OrgBranchEntity::getBranchName));
;
List<String> branchIds = new ArrayList<>(names.keySet());
log.info("levelType: {} ==> branchIds: {}", levelType, branchIds);
stats = capacityOrgStatDao.findByBranchIdsAndWorkdayBetween(branchIds, reqDTO.getStartDate(), reqDTO.getEndDate(), pageable);
} else if ("branch".equals(reqDTO.getLevelType())) {
List<String> groupIds = getGroupIdsByBranchId(reqDTO.getLevelValue());
log.info("levelType: {} ==> groupIds: {}", reqDTO.getLevelType(), groupIds);
names = orgGroupDao.findAllByBranchId(levelValue).stream()
.collect(Collectors.toMap(OrgGroupEntity::getGroupId, OrgGroupEntity::getGroupName));
List<String> groupIds = new ArrayList<>(names.keySet());
log.info("levelType: {} ==> groupIds: {}", levelType, groupIds);
stats = capacityOrgStatDao.findByGroupIdsAndWorkdayBetween(groupIds, reqDTO.getStartDate(), reqDTO.getEndDate(), pageable);
} else {
List<String> teamIds = getTeamIdsByGroupId(reqDTO.getLevelValue());
log.info("levelType: {} ==> teamIds: {}", reqDTO.getLevelType(), teamIds);
names = orgTeamDao.findAllByGroupId(levelValue).stream()
.collect(Collectors.toMap(OrgTeamEntity::getTeamId, OrgTeamEntity::getTeamName));
List<String> teamIds = new ArrayList<>(names.keySet());
log.info("levelType: {} ==> teamIds: {}", levelType, teamIds);
stats = capacityTeamStatDao.findByTeamIdsAndWorkdayBetween(teamIds, reqDTO.getStartDate(), reqDTO.getEndDate(), pageable);
}
CapacityStatQueryRespDTO data = new CapacityStatQueryRespDTO();
data.setLevelType(reqDTO.getLevelType());
data.setLevelType(levelType);
data.setTotal(stats.getTotalElements()).setPages(stats.getTotalPages()).setPageSize(pageable.getPageSize()).setPageCurrent(stats.getNumber());
List<CapacityStatQueryRespDTO.Content> contents = new ArrayList<>();
......@@ -101,10 +113,8 @@ public class CapacityQueryServiceImpl implements CapacityQueryService {
if (item instanceof CapacityOrgStatEntity) {
// cluster/branch查询,都是capacity_org_stat
CapacityOrgStatEntity e = (CapacityOrgStatEntity) item;
if ("group".equals(e.getType())) {
OrgGroupEntity g = orgGroupDao.getByGroupId(e.getOrgId());
content.setGroupName(g.getGroupName());
}
content.setLevelType(e.getType()).setLevelValue(e.getOrgId());
content.setShowName(names.get(e.getOrgId()));
content.setDate(e.getWorkday()).setLayer(e.getLayer())
.setCapTotal(e.getCapTotal()).setCapUsed(e.getCapUsedTotal())
.setEngineerNum(e.getEngineerCount()).setUpdateTime(e.getUpdateTime());
......@@ -112,7 +122,9 @@ public class CapacityQueryServiceImpl implements CapacityQueryService {
// group查询,是capacity_team_stat
CapacityTeamStatEntity e = (CapacityTeamStatEntity) item;
// capacity_team_stat表中的team_id,直接就是字符串
content.setDate(e.getWorkday()).setLayer(e.getLayer()).setTeamName(e.getTeamId())
content.setLevelType("team").setLevelValue(e.getTeamId());
content.setShowName(names.get(e.getTeamId()));
content.setDate(e.getWorkday()).setLayer(e.getLayer()).setShowName(e.getTeamId())
.setCapTotal(e.getCapTotal()).setCapUsed(e.getCapUsed()).setCapAdjust(e.getCapAdjust())
.setEngineerNum(e.getEngineerCount()).setUpdateTime(e.getUpdateTime());
}
......@@ -123,30 +135,6 @@ public class CapacityQueryServiceImpl implements CapacityQueryService {
return Result.success(data);
}
private List<String> getTeamIdsByGroupId(String groupId) {
List<String> teamIds = new ArrayList<>();
for (OrgTeamEntity e : orgTeamDao.findAllByGroupId(groupId)) {
teamIds.add(e.getTeamId());
}
return teamIds;
}
private List<String> getBranchIdsByClusterId(String clusterId) {
List<String> branchIds = new ArrayList<>();
for (OrgBranchEntity e : orgBranchDao.findAllByClusterId(clusterId)) {
branchIds.add(e.getBranchId());
}
return branchIds;
}
private List<String> getGroupIdsByBranchId(String branchId) {
List<String> groupIds = new ArrayList<>();
for (OrgGroupEntity e : orgGroupDao.findAllByBranchId(branchId)) {
groupIds.add(e.getGroupId());
}
return groupIds;
}
private int getSpanType(int capLeft, int capTotal) {
float ratio = (float) capLeft / capTotal;
if (ratio < 0.3) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!