如何将subscribeMeeting和updateWrapper的操作放到同一个事务中
时间: 2024-02-24 12:59:13 浏览: 49
可以使用@Transactional注解来开启事务,将subscribeMeeting和updateWrapper的操作放到同一个事务中,以保证在两个表中的数据操作是原子性的,一旦出现异常,事务就会回滚,保证数据一致性和完整性。优化后的代码如下:
```
@ApiOperation("编辑会议报名信息")
@Transactional
@PostMapping("/updateMeetingRegistration")
public AjaxResult updateMeetingRegistration(@RequestBody MeetingUpdateInfo meeting){
String subscribeId = meeting.getSubscribeId();
if (StringUtils.isBlank(subscribeId)) {
return AjaxResult.error("预约id不能为空!");
}
//更新subscribe_meeting表
SubscribeMeeting subscribeMeeting = SubscribeMeeting.builder()
.subscribeId(subscribeId)
.customName(meeting.getCustomName())
.customIdNumber(meeting.getCustomIdNumber())
.regionName(meeting.getRegionName())
.shopName(meeting.getShopName())
.ticket(meeting.getTicket())
.meetingRemark(meeting.getMeetingRemark())
.build();
subscribeMeetingService.updateById(subscribeMeeting);
//更新subscribe_detail表
UpdateWrapper<SubscribeDetail> updateWrapper = new UpdateWrapper<>();
updateWrapper.lambda()
.set(SubscribeDetail::getCustomPhone, meeting.getCustomPhone())
.set(SubscribeDetail::getCustomType, meeting.getCustomType())
.set(SubscribeDetail::getLeaderName, meeting.getLeaderName())
.eq(SubscribeDetail::getSubscribeId, subscribeId);
subscribeDetailService.update(updateWrapper);
return AjaxResult.success();
}
```
阅读全文