添加了新的交接接口,完善了Task的childrenCount,修复了更新staffPositions失败的问题
parent
13e9825f75
commit
8cc1111489
|
@ -96,7 +96,7 @@ public class ProjectGroupController {
|
|||
@PathVariable Integer staffId,
|
||||
@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();
|
||||
}
|
||||
throw new BadRequestException(BadRequestException.OPERATE_FAILED);
|
||||
|
@ -139,4 +139,20 @@ public class ProjectGroupController {
|
|||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -133,6 +133,8 @@ public class Task {
|
|||
return false;
|
||||
if (!Objects.equals(rawTask.getTaskCreatedTime(), this.getTaskCreatedTime()))
|
||||
return false;
|
||||
if (!Objects.equals(rawTask.getChildrenCount(), this.getChildrenCount()))
|
||||
return false;
|
||||
return Objects.equals(rawTask.getTaskClosedTime(), this.getTaskClosedTime());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ public interface ITaskService extends IService<Task> {
|
|||
|
||||
/**
|
||||
* 对拥有项目一级/二级访问权限的员工,直接返回1
|
||||
*
|
||||
* @return 1:all rights 2:father holder 3:current holder 0:no right
|
||||
*/
|
||||
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 transferTasksToSingleStaff(String token, Integer projectId, Integer transferredStaffId, Integer targetStaffId) throws ForbiddenException, BadRequestException;
|
||||
}
|
||||
|
|
|
@ -96,11 +96,11 @@ public class ProjectGroupServiceImpl extends ServiceImpl<ProjectGroupMapper, Pro
|
|||
}
|
||||
|
||||
return baseMapper.update(
|
||||
ProjectGroup.builder()
|
||||
.projectId(projectId)
|
||||
.staffId(targetId)
|
||||
.build(),
|
||||
Wrappers.<ProjectGroup>lambdaUpdate().set(ProjectGroup::getProjectStaffPosition, positions)
|
||||
null,
|
||||
Wrappers.<ProjectGroup>lambdaUpdate()
|
||||
.eq(ProjectGroup::getProjectId, projectId)
|
||||
.eq(ProjectGroup::getStaffId, targetId)
|
||||
.set(ProjectGroup::getProjectStaffPosition, positions)
|
||||
) == 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -81,6 +81,7 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
|
|||
.in(Task::getTaskFatherId, res));
|
||||
baseMapper.update(null, Wrappers.<Task>lambdaUpdate().in(Task::getTaskId, res).set(Task::getChildrenCount, 0));
|
||||
baseMapper.delete(Wrappers.<Task>lambdaQuery().in(Task::getTaskId, res));
|
||||
|
||||
if (list == null || list.isEmpty()) break;
|
||||
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.setTaskStatus(Task.STATUS_WAITING);
|
||||
task.setChildrenCount(0);
|
||||
task.setTaskClosedTime(null);
|
||||
if (baseMapper.insert(task) == 0) {
|
||||
throw new BadRequestException(BadRequestException.OPERATE_FAILED);
|
||||
}
|
||||
baseMapper.update(null, Wrappers.<Task>lambdaUpdate().setSql("children_count = children_count + 1"));
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
throw new BadRequestException(BadRequestException.OPERATE_FAILED);
|
||||
|
@ -429,7 +432,7 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements IT
|
|||
return taskTrendDTO;
|
||||
}
|
||||
|
||||
//不需要定义为事务,因为updateBatch已经定义为事务
|
||||
@Transactional(isolation = Isolation.SERIALIZABLE, rollbackFor = Exception.class)
|
||||
@Override
|
||||
public Boolean transferStaffTasks(String token, Integer projectId, Integer transferredStaffId, Map<Long, Integer> transferMap) throws ForbiddenException, BadRequestException {
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue