把监听事件改成工厂模式
This commit is contained in:
parent
5b52ffdcdc
commit
925268f83a
|
@ -0,0 +1,27 @@
|
|||
package com.snow.dingtalk.listener;
|
||||
|
||||
import com.snow.dingtalk.model.DepartmentCreateRequest;
|
||||
import com.snow.dingtalk.service.DepartmentService;
|
||||
import com.snow.system.domain.SysDept;
|
||||
import com.snow.system.event.SyncEvent;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
* @author qimingjin
|
||||
* @Title: 创建部门数据同步
|
||||
* @Description:
|
||||
* @date 2020/9/28 9:33
|
||||
*/
|
||||
public class DepartmentCreateEventService implements ISyncDingTalkInfo {
|
||||
|
||||
@Autowired
|
||||
private DepartmentService departmentService;
|
||||
|
||||
@Override
|
||||
public void syncDingTalkInfoEvent(SyncEvent syncEvent) {
|
||||
SysDept sysDept=(SysDept)syncEvent.getT();
|
||||
DepartmentCreateRequest departmentDTO = DepartmentCreateRequest.builder().name(sysDept.getDeptName()).order(sysDept.getOrderNum())
|
||||
.parentid(sysDept.getParentName()).build();
|
||||
departmentService.createDepartment(departmentDTO);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package com.snow.dingtalk.listener;
|
||||
|
||||
import com.snow.system.event.SyncEvent;
|
||||
|
||||
/**
|
||||
* @author qimingjin
|
||||
* @Title:
|
||||
* @Description:
|
||||
* @date 2020/9/28 9:31
|
||||
*/
|
||||
public interface ISyncDingTalkInfo {
|
||||
/**
|
||||
* 同步钉钉事件
|
||||
* @param syncEvent
|
||||
*/
|
||||
void syncDingTalkInfoEvent(SyncEvent syncEvent);
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package com.snow.dingtalk.listener;
|
||||
|
||||
import com.snow.common.enums.DingTalkListenerType;
|
||||
import com.snow.system.event.SyncEvent;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* @author qimingjin
|
||||
* @Title: 创建同步钉钉数据工厂类
|
||||
* @Description:
|
||||
* @date 2020/9/28 9:43
|
||||
*/
|
||||
@Slf4j
|
||||
public class SyncDingTalkInfoFactory {
|
||||
|
||||
public ISyncDingTalkInfo getSyncDingTalkService(SyncEvent syncEvent){
|
||||
|
||||
Integer eventType = syncEvent.getEventType();
|
||||
if(eventType.equals(DingTalkListenerType.DEPARTMENT_CREATE.getCode())){
|
||||
return new DepartmentCreateEventService();
|
||||
}
|
||||
else if(eventType.equals(DingTalkListenerType.USER_CREATED.getCode())){
|
||||
return new UserCreateEventService();
|
||||
}else {
|
||||
throw new RuntimeException("不存在的监听类型");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -1,19 +1,14 @@
|
|||
package com.snow.dingtalk.listener;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.snow.common.enums.DingTalkListenerType;
|
||||
import com.snow.dingtalk.model.DepartmentCreateRequest;
|
||||
import com.snow.dingtalk.service.DepartmentService;
|
||||
import com.snow.system.domain.SysDept;
|
||||
import com.snow.system.event.SyncEvent;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author qimingjin
|
||||
* @Title: 同步事件监听器
|
||||
* @Title: 同步事件监听器工厂
|
||||
* @Description:
|
||||
* @date 2020/9/17 17:40
|
||||
*/
|
||||
|
@ -21,23 +16,13 @@ import org.springframework.stereotype.Component;
|
|||
@Slf4j
|
||||
public class SyncEventListener implements ApplicationListener<SyncEvent> {
|
||||
|
||||
@Autowired
|
||||
private DepartmentService departmentService;
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(SyncEvent syncEvent) {
|
||||
log.info("进入监听器.....");
|
||||
Integer eventType = syncEvent.getEventType();
|
||||
if(eventType==DingTalkListenerType.DEPARTMENT_CREATE.getCode()){
|
||||
SysDept sysDept=(SysDept)syncEvent.getT();
|
||||
DepartmentCreateRequest departmentDTO = DepartmentCreateRequest.builder().name(sysDept.getDeptName()).order(sysDept.getOrderNum())
|
||||
.parentid(sysDept.getParentName()).build();
|
||||
departmentService.createDepartment(departmentDTO);
|
||||
}
|
||||
else if(eventType == DingTalkListenerType.USER_CREATED.getCode()){
|
||||
|
||||
}
|
||||
|
||||
log.info("监听到的事件类型:"+eventType+JSON.toJSONString(syncEvent));
|
||||
SyncDingTalkInfoFactory syncEventListenerFactory = new SyncDingTalkInfoFactory();
|
||||
syncEventListenerFactory.getSyncDingTalkService(syncEvent);
|
||||
log.info("监听到的事件类型:"+JSON.toJSONString(syncEvent));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package com.snow.dingtalk.listener;
|
||||
|
||||
import com.snow.system.event.SyncEvent;
|
||||
|
||||
/**
|
||||
* @author qimingjin
|
||||
* @Title: 创建用户
|
||||
* @Description:
|
||||
* @date 2020/9/28 9:34
|
||||
*/
|
||||
public class UserCreateEventService implements ISyncDingTalkInfo {
|
||||
@Override
|
||||
public void syncDingTalkInfoEvent(SyncEvent syncEvent) {
|
||||
|
||||
}
|
||||
}
|
|
@ -4,9 +4,7 @@ import com.alibaba.fastjson.JSON;
|
|||
import com.dingtalk.api.DefaultDingTalkClient;
|
||||
import com.dingtalk.api.DingTalkClient;
|
||||
import com.dingtalk.api.request.OapiUserCreateRequest;
|
||||
import com.dingtalk.api.request.OapiWorkrecordAddRequest;
|
||||
import com.dingtalk.api.response.OapiUserCreateResponse;
|
||||
import com.dingtalk.api.response.OapiWorkrecordAddResponse;
|
||||
import com.snow.dingtalk.common.BaseConstantUrl;
|
||||
import com.snow.dingtalk.common.BaseService;
|
||||
import com.snow.dingtalk.model.WorkrecordAddRequest;
|
||||
|
|
Loading…
Reference in New Issue