| | |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper; |
| | | import com.ycl.jxkg.domain.entity.Exam; |
| | | import com.ycl.jxkg.domain.entity.Meet; |
| | | import com.ycl.jxkg.enums.general.ExamStatusEnum; |
| | | import com.ycl.jxkg.mapper.ExamMapper; |
| | | import com.ycl.jxkg.mapper.MeetMapper; |
| | | import com.ycl.jxkg.rabbitmq.msg.ExamStatusMsg; |
| | | import com.ycl.jxkg.rabbitmq.msg.MeetStatusMsg; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.amqp.core.Message; |
| | | import org.springframework.amqp.rabbit.annotation.*; |
| | |
| | | public class Consumer { |
| | | |
| | | private final ExamMapper examMapper; |
| | | |
| | | private final MeetMapper meetMapper; |
| | | /** |
| | | * 考试状态更新的消费者 |
| | | * |
| | |
| | | */ |
| | | @RabbitListener(queues = "meetDlxQueue") |
| | | public void meetConsumer(Message message){ |
| | | System.out.println(message); |
| | | MeetStatusMsg meetStatusMsg = JSON.parseObject(message.getBody(), MeetStatusMsg.class); |
| | | Meet meet = meetMapper.selectById(meetStatusMsg.getMeetId()); |
| | | if (Objects.nonNull(meet) && meetStatusMsg.getVersion().equals(meet.getUpdateVersion())) { |
| | | // 不使用updateById这种方式,避免乐观锁加一。 |
| | | new LambdaUpdateChainWrapper<>(meetMapper) |
| | | .eq(Meet::getId, meet.getId()) |
| | | .set(Meet::getStatus, meetStatusMsg.getMeetStatus()) |
| | | .update(); |
| | | } |
| | | } |
| | | } |