public SysDept getEastTaskDept(String taskId) { EastTask eastTaskById = this.getEastTaskById(taskId); if (null != eastTaskById) { Long taskDeptId = eastTaskById.getTaskDeptId(); return sysDeptMapper.selectByPrimaryKey(taskDeptId); } return null; }
时间: 2024-04-20 18:26:17 浏览: 87
这段代码是一个方法,用于根据 taskId 获取对应的 EastTask 对象,并返回其关联的 SysDept 对象。
首先,它调用了之前提到的 getEastTaskById 方法,通过 taskId 获取对应的 EastTask 对象。
接下来,它判断获取到的 EastTask 对象是否为 null。如果不为 null,则获取其 taskDeptId 属性,并调用 sysDeptMapper 的 selectByPrimaryKey 方法,通过 taskDeptId 查询对应的 SysDept 对象。
最后,它返回查询到的 SysDept 对象。如果 EastTask 对象为 null,则返回 null。
相关问题
@Data @TableName("bis_task") public class BisTask { private static final long serialVersionUID = 1L; @TableId(value="id" , type = IdType.AUTO) private Integer id; @TableField("task_name") private String taskName; @TableField("create_time") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") private Date createTime; @TableField("task_status") private Integer taskStatus; @TableField("expect_task_start_date") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") private Date expectTaskStartDate; @TableField("actual_task_start_date") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") private Date actualTaskStartDate; @TableField("expect_task_end_date") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") private Date expectTaskEndDate; @TableField("actual_task_end_date") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") private Date actualTaskEndDate; @TableField("fly_place") private String flyPlace; } 帮我写一个根据id修改,但是projectName是BisProject类的, BisTask类的id关联BisTaskTower类的taskId, BisTower类的id关联BisTaskTower类的Id, BisTower类的projectId关联BisProject类的id, 用mybtais-plus修改,不要写mapper和sql
好的,以下是根据id修改BisTask类的方法,同时修改BisTask关联的其他类的相关信息:
```java
@Service
public class BisTaskService extends ServiceImpl<BisTaskMapper, BisTask> {
@Autowired
private BisTaskTowerMapper bisTaskTowerMapper;
@Autowired
private BisTowerMapper bisTowerMapper;
@Autowired
private BisProjectMapper bisProjectMapper;
/**
* 根据id修改BisTask类的相关信息
* BisTask类的id关联BisTaskTower类的taskId,
* BisTower类的id关联BisTaskTower类的towerId,
* BisTower类的projectId关联BisProject类的id
*
* @param id BisTask的id
* @param projectName BisProject的projectName
* @param bisTask BisTask对象,修改的其他属性值
* @return 是否修改成功
*/
public boolean updateBisTaskAndRelatedInfoById(Integer id, String projectName, BisTask bisTask) {
// 根据id查询BisTask
BisTask oldTask = getById(id);
if (oldTask == null) {
return false;
}
// 更新BisTask的属性值
oldTask.setTaskName(bisTask.getTaskName());
oldTask.setCreateTime(bisTask.getCreateTime());
oldTask.setTaskStatus(bisTask.getTaskStatus());
oldTask.setExpectTaskStartDate(bisTask.getExpectTaskStartDate());
oldTask.setActualTaskStartDate(bisTask.getActualTaskStartDate());
oldTask.setExpectTaskEndDate(bisTask.getExpectTaskEndDate());
oldTask.setActualTaskEndDate(bisTask.getActualTaskEndDate());
oldTask.setFlyPlace(bisTask.getFlyPlace());
// 更新BisTaskTower的属性值
QueryWrapper<BisTaskTower> bisTaskTowerQueryWrapper = new QueryWrapper<>();
bisTaskTowerQueryWrapper.eq("task_id", id);
List<BisTaskTower> bisTaskTowerList = bisTaskTowerMapper.selectList(bisTaskTowerQueryWrapper);
for (BisTaskTower bisTaskTower : bisTaskTowerList) {
bisTaskTower.setTaskId(oldTask.getId());
bisTaskTowerMapper.updateById(bisTaskTower);
}
// 更新BisTower的属性值
QueryWrapper<BisTower> bisTowerQueryWrapper = new QueryWrapper<>();
bisTowerQueryWrapper.in("id", bisTaskTowerList.stream().map(BisTaskTower::getTowerId).collect(Collectors.toList()));
List<BisTower> bisTowerList = bisTowerMapper.selectList(bisTowerQueryWrapper);
for (BisTower bisTower : bisTowerList) {
bisTower.setProjectId(bisProjectMapper.selectOne(new QueryWrapper<BisProject>().eq("project_name", projectName)).getId());
bisTowerMapper.updateById(bisTower);
}
// 更新BisTask
return updateById(oldTask);
}
}
```
需要注意的是,这里传入的BisTask对象只需要包含需要修改的属性值,其他属性值会从数据库中查询出来并更新。另外,需要注意更新BisTower时需要先根据BisTaskTower的towerId查询出BisTower对象,再根据BisTower的projectId查询出BisProject的id,最后更新BisTower的projectId。
阅读全文