use of com.dtstack.taier.dao.domain.User in project Taier by DTStack.
the class UserController method switchTenant.
@PostMapping(value = "/switchTenant")
public R<String> switchTenant(@RequestParam(value = "tenantId") Long tenantId, HttpServletRequest request, HttpServletResponse response) {
String token = cookieService.token(request);
if (StringUtils.isBlank(token)) {
throw new RdosDefineException(ErrorCode.TOKEN_IS_NULL);
}
DTToken decryption = tokenService.decryption(token);
Long userId = decryption.getUserId();
User user = userService.getById(userId);
if (null == user) {
throw new RdosDefineException(ErrorCode.USER_IS_NULL);
}
Tenant tenant = tenantService.getTenantById(tenantId);
if (null == tenant) {
throw new RdosDefineException(ErrorCode.TENANT_IS_NULL);
}
DtUser dtUser = new DtUser();
dtUser.setUserId(user.getId());
dtUser.setUserName(user.getUserName());
dtUser.setEmail(user.getEmail());
dtUser.setPhone(user.getPhoneNumber());
dtUser.setTenantId(tenantId);
dtUser.setTenantName(tenant.getTenantName());
loginService.onAuthenticationSuccess(request, response, dtUser);
return R.ok(user.getUserName());
}
use of com.dtstack.taier.dao.domain.User in project Taier by DTStack.
the class UserService method getUserByDTO.
public UserDTO getUserByDTO(Long userId) {
if (userId == null) {
return null;
}
User one = getById(userId);
if (Objects.isNull(one)) {
return null;
}
UserDTO userDTO = new UserDTO();
BeanUtils.copyProperties(one, userDTO);
return userDTO;
}
use of com.dtstack.taier.dao.domain.User in project Taier by DTStack.
the class BatchTaskService method publishBatchTaskInfo.
/**
* 批量发布任务至engine
* @param publishTask 要发布的task集合
* @param tenantId 项目id
* @param userId 用户id
* @param publishDesc 发布描述
* @param isRoot 是否是管理员
* @param ignoreCheck 忽略检查
* @return 发布结果
*/
public TaskCheckResultVO publishBatchTaskInfo(BatchTask publishTask, Long tenantId, Long userId, String publishDesc, Boolean isRoot, Boolean ignoreCheck) {
// 判断任务责任人是否存在 如果任务责任人不存在或无权限 不允许提交
User user = userService.getById(publishTask.getCreateUserId());
if (user == null) {
throw new RdosDefineException(String.format("%s任务责任人在数栈中不存在", publishTask.getName()));
}
TaskCheckResultVO checkResultVO = new TaskCheckResultVO();
checkResultVO.setErrorSign(PublishTaskStatusEnum.NOMAL.getType());
// 检查任务是否可以发布并记录版本信息
TaskCheckResultVO resultVO = checkTaskAndSaveVersion(publishTask, tenantId, userId, publishDesc, isRoot, ignoreCheck);
if (!PublishTaskStatusEnum.NOMAL.getType().equals(resultVO.getErrorSign())) {
// 做一下优化 如果是工作流任务的话 把任务名称打印出来
if (publishTask.getFlowId() > 0) {
resultVO.setErrorMessage(String.format("任务:%s提交失败,原因是:%s", publishTask.getName(), resultVO.getErrorMessage()));
}
return resultVO;
}
// 发布任务中所有的依赖关系
List<Long> parentTaskIds = Lists.newArrayList();
ScheduleTaskShadeDTO scheduleTaskShadeDTO = buildScheduleTaskShadeDTO(publishTask, parentTaskIds);
// 提交任务参数信息并保存任务记录和更新任务状态
try {
BatchTask batchTask = getOneWithError(scheduleTaskShadeDTO.getTaskId());
String extraInfo = this.batchJobService.getExtraInfo(batchTask, userId, null);
scheduleTaskShadeDTO.setExtraInfo(extraInfo);
// 无异常保存一条任务记录并更新任务状态
saveRecordAndUpdateSubmitStatus(batchTask, tenantId, userId, TaskOperateType.COMMIT.getType(), ESubmitStatus.SUBMIT.getStatus());
} catch (Exception e) {
LOGGER.error("send task error {} ", scheduleTaskShadeDTO.getTaskId(), e);
throw new RdosDefineException(String.format("任务提交异常:%s", e.getMessage()), e);
}
SavaTaskDTO savaTaskDTO = new SavaTaskDTO();
savaTaskDTO.setScheduleTaskShadeDTO(scheduleTaskShadeDTO);
savaTaskDTO.setParentTaskIdList(parentTaskIds);
// 批量发布任务
this.taskService.saveTask(savaTaskDTO);
LOGGER.info("待发布任务参数提交完毕");
return checkResultVO;
}
use of com.dtstack.taier.dao.domain.User in project Taier by DTStack.
the class BatchTaskService method addOrUpdateTask.
/**
* 数据开发-新建/更新 任务
*
* @param param 任务
* @return
* @throws NoSuchFieldException
* @throws IllegalAccessException
* @author toutian
*/
@Transactional(rollbackFor = Exception.class)
public TaskCatalogueVO addOrUpdateTask(final TaskResourceParam param) {
// 检查密码回填操作
this.checkFillPassword(param);
// 数据预处理 主要是数据同步任务 生成sqlText
this.checkBeforeUpdateTask(param);
if (StringUtils.isNotBlank(param.getScheduleConf())) {
// 处理调度配置
JSONObject schduleConf = JSON.parseObject(param.getScheduleConf());
if (schduleConf.get("isExpire") != null && "false".equals(schduleConf.get("isExpire").toString())) {
schduleConf.replace("isLastInstance", true);
param.setScheduleConf(schduleConf.toString());
}
param.setPeriodType(schduleConf.getInteger("periodType"));
}
if (param.getId() > 0 && param.getTaskType().equals(EScheduleJobType.WORK_FLOW.getVal())) {
// 更新子任务间的依赖关系
final String sqlText = param.getSqlText();
if (StringUtils.isNotBlank(sqlText)) {
final Map<Long, List<Long>> relations = this.parseTaskRelationsFromSqlText(sqlText);
// 判断任务依赖是否成环
if (MapUtils.isNotEmpty(relations)) {
checkIsLoopByList(relations);
}
for (final Map.Entry<Long, List<Long>> entry : relations.entrySet()) {
List<BatchTask> dependencyTasks = getTaskByIds(entry.getValue());
dependencyTasks.stream().forEach(task -> {
task.setTenantId(param.getTenantId());
});
batchTaskTaskService.addOrUpdateTaskTask(entry.getKey(), dependencyTasks);
}
}
}
BatchTaskBatchVO task = PublicUtil.objectToObject(param, BatchTaskBatchVO.class);
task.setModifyUserId(param.getUserId());
task.setVersion(Objects.isNull(param.getVersion()) ? 0 : param.getVersion());
task.parsePeriodType();
task = this.updateTask(task, param.getEditBaseInfo());
TaskCatalogueVO taskCatalogueVO = new TaskCatalogueVO(task, task.getNodePid());
// 强行置为更新
taskCatalogueVO.getReadWriteLockVO().setResult(TaskLockStatus.TO_UPDATE.getVal());
// 更新 关联资源
if (param.getResourceIdList() != null) {
final Map<String, Object> params = Maps.newHashMap();
params.put("id", task.getId());
params.put("resources", param.getResourceIdList());
params.put("createUserId", task.getCreateUserId());
this.updateTaskResource(params);
}
if (param.getRefResourceIdList() != null) {
final Map<String, Object> params = Maps.newHashMap();
params.put("id", task.getId());
params.put("refResource", param.getRefResourceIdList());
params.put("createUserId", task.getCreateUserId());
this.updateTaskRefResource(params);
}
final User user = userService.getById(task.getModifyUserId());
if (user != null) {
taskCatalogueVO.setCreateUser(user.getUserName());
}
final List<BatchTask> dependencyTasks = param.getDependencyTasks();
if (dependencyTasks != null) {
this.batchTaskTaskService.addOrUpdateTaskTask(task.getId(), dependencyTasks);
taskCatalogueVO.setDependencyTasks(dependencyTasks);
}
String createUserName = userService.getUserName(task.getCreateUserId());
taskCatalogueVO.setCreateUser(createUserName);
taskCatalogueVO.setCatalogueType(CatalogueType.TASK_DEVELOP.getType());
return taskCatalogueVO;
}
use of com.dtstack.taier.dao.domain.User in project Taier by DTStack.
the class TaskService method queryTasks.
/**
* 查询任务列表
*
* @param dto 查询条件
* @return
*/
public PageResult<List<ReturnScheduleTaskVO>> queryTasks(QueryTaskListDTO dto) {
Page<ScheduleTaskShade> page = new Page<>(dto.getCurrentPage(), dto.getPageSize());
// 分页查询
Page<ScheduleTaskShade> resultPage = this.lambdaQuery().eq(ScheduleTaskShade::getFlowId, 0L).eq(ScheduleTaskShade::getIsDeleted, Deleted.NORMAL.getStatus()).like(StringUtils.isNotBlank(dto.getName()), ScheduleTaskShade::getName, dto.getName()).eq(dto.getOperatorId() != null, ScheduleTaskShade::getCreateUserId, dto.getOperatorId()).eq(dto.getTenantId() != null, ScheduleTaskShade::getTenantId, dto.getTenantId()).eq(dto.getScheduleStatus() != null, ScheduleTaskShade::getScheduleStatus, dto.getScheduleStatus()).between(dto.getStartModifiedTime() != null && dto.getEndModifiedTime() != null, ScheduleTaskShade::getGmtModified, null == dto.getStartModifiedTime() ? null : new Timestamp(dto.getStartModifiedTime()), null == dto.getEndModifiedTime() ? null : new Timestamp(dto.getEndModifiedTime())).in(CollectionUtils.isNotEmpty(dto.getTaskTypeList()), ScheduleTaskShade::getTaskType, dto.getTaskTypeList()).in(CollectionUtils.isNotEmpty(dto.getPeriodTypeList()), ScheduleTaskShade::getPeriodType, dto.getPeriodTypeList()).page(page);
List<ReturnScheduleTaskVO> scheduleTaskVOS = ScheduleTaskMapstructTransfer.INSTANCE.beanToTaskVO(resultPage.getRecords());
List<Long> userIds = resultPage.getRecords().stream().map(ScheduleTaskShade::getCreateUserId).collect(Collectors.toList());
Map<Long, User> userMap = userService.getUserMap(userIds);
scheduleTaskVOS.forEach(vo -> vo.setOperatorName(userMap.get(vo.getOperatorId()) != null ? userMap.get(vo.getOperatorId()).getUserName() : ""));
return new PageResult<>(dto.getCurrentPage(), dto.getPageSize(), resultPage.getTotal(), (int) resultPage.getPages(), scheduleTaskVOS);
}
Aggregations