添加了新的交接接口,完善了Task的childrenCount,修复了更新staffPositions失败的问题

master
ArgonarioD 2022-07-12 00:30:42 +08:00
parent 13e9825f75
commit 8cc1111489
5 changed files with 52 additions and 7 deletions

View File

@ -96,7 +96,7 @@ public class ProjectGroupController {
@PathVariable Integer staffId, @PathVariable Integer staffId,
@Parameter(description = "在body中只传projectStaffPosition") @RequestBody GroupPositionVO groupPosition @Parameter(description = "在body中只传projectStaffPosition") @RequestBody GroupPositionVO groupPosition
) { ) {
if (projectGroupService.updateStaffPositions(token, staffId, projectId, groupPosition.getProjectStaffPosition())) { if (projectGroupService.updateStaffPositions(token, projectId, staffId, groupPosition.getProjectStaffPosition())) {
return ResponseMap.ofSuccess(); return ResponseMap.ofSuccess();
} }
throw new BadRequestException(BadRequestException.OPERATE_FAILED); throw new BadRequestException(BadRequestException.OPERATE_FAILED);
@ -139,4 +139,20 @@ public class ProjectGroupController {
} }
throw new BadRequestException(BadRequestException.OPERATE_FAILED); throw new BadRequestException(BadRequestException.OPERATE_FAILED);
} }
//TODO: TEST
@Operation(description = "将staffId的所有工作项转移至targetStaffId")
@SneakyThrows
@PutMapping("/{staffId}/transfer/{targetStaffId}")
public ResponseMap transferTasksToSingleStaff(
@RequestHeader(TokenUtils.HEADER_TOKEN) String token,
@PathVariable Integer projectId,
@PathVariable Integer staffId,
@PathVariable Integer targetStaffId
) {
if (taskService.transferTasksToSingleStaff(token, projectId, staffId, targetStaffId)) {
return ResponseMap.ofSuccess();
}
throw new BadRequestException(BadRequestException.OPERATE_FAILED);
}
} }

View File

@ -133,6 +133,8 @@ public class Task {
return false; return false;
if (!Objects.equals(rawTask.getTaskCreatedTime(), this.getTaskCreatedTime())) if (!Objects.equals(rawTask.getTaskCreatedTime(), this.getTaskCreatedTime()))
return false; return false;
if (!Objects.equals(rawTask.getChildrenCount(), this.getChildrenCount()))
return false;
return Objects.equals(rawTask.getTaskClosedTime(), this.getTaskClosedTime()); return Objects.equals(rawTask.getTaskClosedTime(), this.getTaskClosedTime());
} }
} }

View File

@ -33,6 +33,7 @@ public interface ITaskService extends IService<Task> {
/** /**
* /访1 * /访1
*
* @return 1:all rights 2:father holder 3:current holder 0:no right * @return 1:all rights 2:father holder 3:current holder 0:no right
*/ */
Integer getHolderLevel(String token, Long taskId); Integer getHolderLevel(String token, Long taskId);
@ -49,4 +50,5 @@ public interface ITaskService extends IService<Task> {
Boolean transferStaffTasks(String token, Integer projectId, Integer transferredStaffId, Map<Long, Integer> transferMap) throws ForbiddenException, BadRequestException; Boolean transferStaffTasks(String token, Integer projectId, Integer transferredStaffId, Map<Long, Integer> transferMap) throws ForbiddenException, BadRequestException;
Boolean transferTasksToSingleStaff(String token, Integer projectId, Integer transferredStaffId, Integer targetStaffId) throws ForbiddenException, BadRequestException;
} }

View File

@ -96,11 +96,11 @@ public class ProjectGroupServiceImpl extends ServiceImpl<ProjectGroupMapper, Pro
} }
return baseMapper.update( return baseMapper.update(
ProjectGroup.builder() null,
.projectId(projectId) Wrappers.<ProjectGroup>lambdaUpdate()
.staffId(targetId) .eq(ProjectGroup::getProjectId, projectId)
.build(), .eq(ProjectGroup::getStaffId, targetId)
Wrappers.<ProjectGroup>lambdaUpdate().set(ProjectGroup::getProjectStaffPosition, positions) .set(ProjectGroup::getProjectStaffPosition, positions)
) == 1; ) == 1;
} }

View File

@ -81,6 +81,7 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
.in(Task::getTaskFatherId, res)); .in(Task::getTaskFatherId, res));
baseMapper.update(null, Wrappers.<Task>lambdaUpdate().in(Task::getTaskId, res).set(Task::getChildrenCount, 0)); baseMapper.update(null, Wrappers.<Task>lambdaUpdate().in(Task::getTaskId, res).set(Task::getChildrenCount, 0));
baseMapper.delete(Wrappers.<Task>lambdaQuery().in(Task::getTaskId, res)); baseMapper.delete(Wrappers.<Task>lambdaQuery().in(Task::getTaskId, res));
if (list == null || list.isEmpty()) break; if (list == null || list.isEmpty()) break;
res = list.stream().map(Task::getTaskId).collect(Collectors.toList()); res = list.stream().map(Task::getTaskId).collect(Collectors.toList());
} }
@ -283,10 +284,12 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
} }
task.setTaskCreatedTime(null); task.setTaskCreatedTime(null);
task.setTaskStatus(Task.STATUS_WAITING); task.setTaskStatus(Task.STATUS_WAITING);
task.setChildrenCount(0);
task.setTaskClosedTime(null); task.setTaskClosedTime(null);
if (baseMapper.insert(task) == 0) { if (baseMapper.insert(task) == 0) {
throw new BadRequestException(BadRequestException.OPERATE_FAILED); throw new BadRequestException(BadRequestException.OPERATE_FAILED);
} }
baseMapper.update(null, Wrappers.<Task>lambdaUpdate().setSql("children_count = children_count + 1"));
} catch (Exception e) { } catch (Exception e) {
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
throw new BadRequestException(BadRequestException.OPERATE_FAILED); throw new BadRequestException(BadRequestException.OPERATE_FAILED);
@ -429,7 +432,7 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
return taskTrendDTO; return taskTrendDTO;
} }
//不需要定义为事务因为updateBatch已经定义为事务 @Transactional(isolation = Isolation.SERIALIZABLE, rollbackFor = Exception.class)
@Override @Override
public Boolean transferStaffTasks(String token, Integer projectId, Integer transferredStaffId, Map<Long, Integer> transferMap) throws ForbiddenException, BadRequestException { public Boolean transferStaffTasks(String token, Integer projectId, Integer transferredStaffId, Map<Long, Integer> transferMap) throws ForbiddenException, BadRequestException {
if (projectGroupService.getProjectAccessLevel(token, projectId) == 0 if (projectGroupService.getProjectAccessLevel(token, projectId) == 0
@ -482,4 +485,26 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
); );
} }
@Transactional(isolation = Isolation.SERIALIZABLE, rollbackFor = Exception.class)
@Override
public Boolean transferTasksToSingleStaff(String token, Integer projectId, Integer transferredStaffId, Integer targetStaffId) throws ForbiddenException, BadRequestException {
if (projectGroupService.getProjectAccessLevel(token, projectId) == 0
|| projectGroupService.getProjectAccessLevelIgnoreGlobalLevel(transferredStaffId, projectId) == 0
|| projectGroupService.getProjectAccessLevelIgnoreGlobalLevel(targetStaffId, projectId) == 0) {
throw new ForbiddenException(IProjectGroupService.UNABLE_TO_ACCESS_PROJECT);
}
if (projectGroupService.compareProjectAccessLevel(projectId, token, transferredStaffId) < 0) {
throw new ForbiddenException(ForbiddenException.UNABLE_TO_OPERATE);
}
Long transferredTaskCount = baseMapper.selectCount(Wrappers.<Task>lambdaQuery().eq(Task::getTaskHolderId, transferredStaffId));
int updatedTaskCount = baseMapper.update(
null,
Wrappers.<Task>lambdaUpdate()
.eq(Task::getTaskHolderId, transferredStaffId)
.set(Task::getTaskHolderId, targetStaffId)
);
return transferredTaskCount.intValue() == updatedTaskCount;
}
} }