实现了拯救内存的二分查找(待强力测试);
parent
22d2763360
commit
72e23ad0f0
|
@ -136,12 +136,12 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
|
|||
@NotNull
|
||||
private void addResultProjectProcess(List<StaffProcessDTO> resList, String projectType) {
|
||||
Boolean typeExist = false;
|
||||
for(StaffProcessDTO staffProcessDTO: resList) {
|
||||
if(Objects.equals(staffProcessDTO.getTaskType(), projectType)) {
|
||||
for (StaffProcessDTO staffProcessDTO : resList) {
|
||||
if (Objects.equals(staffProcessDTO.getTaskType(), projectType)) {
|
||||
typeExist = true;
|
||||
}
|
||||
}
|
||||
if(!typeExist) {
|
||||
if (!typeExist) {
|
||||
StaffProcessDTO staffProcessDTO = new StaffProcessDTO();
|
||||
staffProcessDTO.setTaskType(projectType);
|
||||
staffProcessDTO.setCompleteNum(0L);
|
||||
|
@ -186,16 +186,56 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
|
|||
return getHolderLevel(staffId, staffGlobalLevel, taskId);
|
||||
}
|
||||
|
||||
private int lowerBound(List<Task> data, long x) {
|
||||
int l = 0, r = data.size() - 1;
|
||||
while (l < r) {
|
||||
int mid = (l + r) / 2;
|
||||
if (data.get(mid).getTaskFatherId() >= x) r = mid;
|
||||
else l = mid + 1;
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
private int upperBound(List<Task> data, long x) {
|
||||
int l = 0, r = data.size() - 1;
|
||||
while (l < r) {
|
||||
int mid = (l + r) / 2;
|
||||
if (data.get(mid).getTaskFatherId() <= x) l = mid + 1;
|
||||
else r = mid;
|
||||
}
|
||||
return l - 1;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<Task> listMyTasks(String token, Integer projectId) throws BadRequestException {
|
||||
if (projectGroupService.getProjectAccessLevel(token, projectId) == 0) {
|
||||
throw new BadRequestException(IProjectGroupService.UNABLE_TO_ACCESS_PROJECT);
|
||||
}
|
||||
Integer staffId = TokenUtils.getStaffId(token);
|
||||
return baseMapper.selectList(Wrappers.<Task>lambdaQuery()
|
||||
.eq(Task::getTaskHolderId, staffId)
|
||||
.eq(Task::getTaskProjectId, projectId)
|
||||
);
|
||||
List<Task> resList = baseMapper.selectList(Wrappers.<Task>lambdaQuery().select(Task::getTaskId, Task::getTaskFatherId, Task::getTaskHolderId)
|
||||
.eq(Task::getTaskProjectId, projectId).orderByAsc(Task::getTaskFatherId));
|
||||
List<Long> results = new ArrayList<>();
|
||||
ArrayList<Long> vec = new ArrayList<>();
|
||||
ArrayList<Boolean> isTarget = new ArrayList<>();
|
||||
vec.add(0L);
|
||||
isTarget.add(false);
|
||||
int id = 0;
|
||||
while (id != vec.size()) {
|
||||
Long pos = vec.get(id);
|
||||
Boolean flag = isTarget.get(id);
|
||||
id++;
|
||||
if (flag) {
|
||||
results.add(pos);
|
||||
continue;
|
||||
}
|
||||
int l = lowerBound(resList, pos);
|
||||
int r = upperBound(resList, pos);
|
||||
if (l > r)
|
||||
continue;
|
||||
for (int i = l; i <= r; i++) {
|
||||
vec.add(resList.get(i).getTaskId());
|
||||
isTarget.add(resList.get(i).getTaskHolderId().equals(staffId));
|
||||
}
|
||||
}
|
||||
return baseMapper.selectList(Wrappers.<Task>lambdaQuery().in(Task::getTaskId, results));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue