package cn.fw.valhalla.service.bus.listener; import cn.fw.valhalla.domain.db.follow.ClueTask; import cn.fw.valhalla.domain.enums.FollowTypeEnum; import cn.fw.valhalla.domain.vo.setting.SettingVO; import cn.fw.valhalla.service.bus.follow.FollowBizService; import cn.fw.valhalla.service.bus.follow.strategy.impl.PubFollowStrategy; import cn.fw.valhalla.service.bus.setting.SettingBizService; import cn.fw.valhalla.service.event.PublicPoolEvent; import cn.fw.valhalla.service.event.SettingChangeEvent; import cn.fw.valhalla.service.event.StopTaskEvent; import cn.fw.valhalla.service.event.TaskCancelEvent; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.event.EventListener; import org.springframework.stereotype.Component; import java.util.List; import java.util.Objects; import java.util.Optional; /** * @author : kurisu * @className : CustomEventListener * @description : 事件监听器 * @date: 2020-08-18 16:28 */ @Component @Slf4j public class CustomEventListener { private final SettingBizService settingBizService; private final FollowBizService followBizService; private final PubFollowStrategy pubFollowStrategy; @Autowired public CustomEventListener(final SettingBizService settingBizService, final FollowBizService followBizService, final PubFollowStrategy pubFollowStrategy) { this.settingBizService = settingBizService; this.followBizService = followBizService; this.pubFollowStrategy = pubFollowStrategy; } /** * 监听跟进任务取消事件 * * @param event */ @EventListener(TaskCancelEvent.class) public void onDataCancel(final TaskCancelEvent event) { followBizService.onDataCancel(event); } /** * 当设置发生改变时 * * @param event */ @EventListener(SettingChangeEvent.class) public void onSettingChange(final SettingChangeEvent event) { final FollowTypeEnum type = event.getType(); if (Objects.isNull(type) || FollowTypeEnum.OT.equals(type)) { return; } Optional> listOptional = Optional.ofNullable(settingBizService.querySettingByCat(type.getValue(), event.getGroupId(), event.getBrandId())); listOptional.ifPresent(settingList -> followBizService.synFollowTask(settingList, type, event.getGroupId())); } /** * 档案进入公共池 * * @param event */ @EventListener(PublicPoolEvent.class) public void stopTaskAndAddPublic(final PublicPoolEvent event) { String vin = event.getVin(); Long groupId = event.getGroupId(); boolean fromTask = event.isFromTask(); followBizService.stopClue(vin, groupId, fromTask); pubFollowStrategy.clueConvertFailedFromFlow(vin, groupId); } /** * 审批终止 续保/事故车 任务 * * @param event */ @EventListener(StopTaskEvent.class) public void stopTask(final StopTaskEvent event) { ClueTask task = event.getTask(); followBizService.stopTask(task); } }