@Data @ApiModel(value = "飞行任务管理-后端列表页vo") public class BisTaskVO extends PageReqVO implements Serializable { @ApiModelProperty(value = "id") private Integer id; @ApiModelProperty(value = "项目名称") private String projectName; @ApiModelProperty(value = "任务名称") private String taskName; @ApiModelProperty(value = "期望飞行开始时间") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") private Date expectTaskStartDate; @ApiModelProperty(value = "实际飞行开始时间") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") private Date actualTaskStartDate; @ApiModelProperty(value = "期望飞行结束时间") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") private Date expectTaskEndDate; @ApiModelProperty(value = "实际飞行结束时间") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") private Date actualTaskEndDate; @ApiModelProperty(value = "飞行地点") private String flyPlace; @ApiModelProperty(value = "任务创建时间") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") private Date createTime; @ApiModelProperty(value = "任务修改时间") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") private Date updateTime; @ApiModelProperty(value = "任务状态 1 待指派 2已指派 3已完成 4待飞行 5待上传 6已上传 7驳回 8审核通过") private Integer taskStatus; } 帮我写一个根据id修改,但是projectName是BisProject类的, BisTask类的id关联BisTaskTower类的taskId, BisTower类的id关联BisTaskTower类的Id, BisTower类的projectId关联BisProject类的id, 用mybtais-plus修改,不要写mapper和sql
时间: 2023-12-10 15:38:34 浏览: 90
Class属性Extends和Implements的区别示例介绍
5星 · 资源好评率100%
好的,这里是根据id修改BisTaskVO的代码:
```java
@Service
public class BisTaskService extends ServiceImpl<BisTaskMapper, BisTask> {
@Autowired
private BisTaskTowerMapper bisTaskTowerMapper;
@Autowired
private BisTowerMapper bisTowerMapper;
@Autowired
private BisProjectMapper bisProjectMapper;
public boolean updateBisTaskVOById(BisTaskVO bisTaskVO) {
// 根据id查询BisTask
BisTask bisTask = getById(bisTaskVO.getId());
if (bisTask == null) {
return false;
}
// 更新BisTask
BeanUtils.copyProperties(bisTaskVO, bisTask);
updateById(bisTask);
// 更新BisProject
BisProject bisProject = bisProjectMapper.selectOne(new QueryWrapper<BisProject>()
.eq("id", bisTaskVO.getProjectId()));
if (bisProject != null) {
bisProject.setProjectName(bisTaskVO.getProjectName());
bisProjectMapper.updateById(bisProject);
}
// 更新BisTower
BisTaskTower bisTaskTower = bisTaskTowerMapper.selectOne(new QueryWrapper<BisTaskTower>()
.eq("task_id", bisTaskVO.getId()));
if (bisTaskTower != null) {
BisTower bisTower = bisTowerMapper.selectOne(new QueryWrapper<BisTower>()
.eq("id", bisTaskTower.getTowerId()));
if (bisTower != null) {
bisTower.setProjectId(bisTaskVO.getProjectId());
bisTowerMapper.updateById(bisTower);
}
}
return true;
}
}
```
这里假设你已经定义好了`BisTaskMapper`和`BisTask`,以及其他相关的Mapper和实体类。在`updateBisTaskVOById`方法中,我们首先根据id查询到要修改的`BisTask`对象,然后将`BisTaskVO`中的属性复制到`BisTask`中,并更新到数据库。接着,我们根据`BisTask`的id查询到对应的`BisTaskTower`对象,从而得到`BisTower`对象,并将其`projectId`属性更新为`BisTaskVO`中的`projectId`。最后,我们还需要根据`BisTaskVO`中的`projectId`更新对应的`BisProject`对象。这里使用了`BeanUtils.copyProperties`来实现对象属性的复制,避免了手动设置每个属性。
阅读全文