From 33390e4e83516425140d780f2928009df7051082 Mon Sep 17 00:00:00 2001 From: jinqiming <45981669@qq.com> Date: Fri, 6 Nov 2020 15:06:23 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=E7=9B=91=E5=90=AC=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6=E5=AF=B9=E8=B1=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/DingtalkCallBackController.java | 7 +- .../resources/templates/system/back/back.html | 1 + .../templates/system/back/detail.html | 74 +++++++++++++++++++ .../common/enums/DingTalkListenerType.java | 2 + .../dingtalk/listener/CallBackService.java | 15 ++-- .../listener/SyncDingTalkInfoFactory.java | 10 +-- .../dingtalk/service/CallBackService.java | 5 +- .../service/impl/CallBackServiceImpl.java | 19 +++-- 8 files changed, 114 insertions(+), 19 deletions(-) create mode 100644 snow-admin/src/main/resources/templates/system/back/detail.html diff --git a/snow-admin/src/main/java/com/snow/web/controller/system/DingtalkCallBackController.java b/snow-admin/src/main/java/com/snow/web/controller/system/DingtalkCallBackController.java index fa65b1a..6a26ab1 100644 --- a/snow-admin/src/main/java/com/snow/web/controller/system/DingtalkCallBackController.java +++ b/snow-admin/src/main/java/com/snow/web/controller/system/DingtalkCallBackController.java @@ -2,6 +2,8 @@ package com.snow.web.controller.system; import java.util.List; +import com.dingtalk.api.response.OapiCallBackGetCallBackFailedResultResponse; +import com.snow.dingtalk.service.impl.CallBackServiceImpl; import com.snow.framework.util.ShiroUtils; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; @@ -35,6 +37,8 @@ public class DingtalkCallBackController extends BaseController @Autowired private IDingtalkCallBackService dingtalkCallBackService; + @Autowired + private CallBackServiceImpl callBackServiceImpl; @RequiresPermissions("system:back:view") @GetMapping() @@ -132,7 +136,8 @@ public class DingtalkCallBackController extends BaseController @GetMapping("/detail/{id}") public String detail(@PathVariable("id") Long operId, ModelMap mmap) { - mmap.put("operLog", ""); + List callBackFailedResult = callBackServiceImpl.getCallBackFailedResult(); + mmap.put("operLog", callBackFailedResult); return prefix + "/detail"; } } diff --git a/snow-admin/src/main/resources/templates/system/back/back.html b/snow-admin/src/main/resources/templates/system/back/back.html index ff381c3..e2a1d66 100644 --- a/snow-admin/src/main/resources/templates/system/back/back.html +++ b/snow-admin/src/main/resources/templates/system/back/back.html @@ -46,6 +46,7 @@ + + \ No newline at end of file diff --git a/snow-common/src/main/java/com/snow/common/enums/DingTalkListenerType.java b/snow-common/src/main/java/com/snow/common/enums/DingTalkListenerType.java index c7e2ae0..7dcaa81 100644 --- a/snow-common/src/main/java/com/snow/common/enums/DingTalkListenerType.java +++ b/snow-common/src/main/java/com/snow/common/enums/DingTalkListenerType.java @@ -20,6 +20,8 @@ public enum DingTalkListenerType { CALL_BACK_UPDATE(21,10, "回调更新"), CALL_BACK_DELETE(22,10, "回调删除"), + + CALL_BACK_FAILED_RESULT(23,10, "获取回调失败结果"), ; diff --git a/snow-dingtalk/src/main/java/com/snow/dingtalk/listener/CallBackService.java b/snow-dingtalk/src/main/java/com/snow/dingtalk/listener/CallBackService.java index e8ffc9b..0f695f1 100644 --- a/snow-dingtalk/src/main/java/com/snow/dingtalk/listener/CallBackService.java +++ b/snow-dingtalk/src/main/java/com/snow/dingtalk/listener/CallBackService.java @@ -24,13 +24,18 @@ public class CallBackService implements ISyncDingTalkInfo { @Override public void syncDingTalkInfoEvent(SyncEvent syncEvent) { log.info("调用创建钉钉注册回调传入的原始参数:{}"+JSON.toJSONString(syncEvent)); - Enum eventType =(Enum) syncEvent.getT(); - if(eventType.equals(DingTalkListenerType.CALL_BACK_REGISTER.getCode())){ - callBackServiceImpl.registerCallBack((DingtalkCallBack) syncEvent.getT()); + DingTalkListenerType eventType =(DingTalkListenerType) syncEvent.getT(); + Integer code = eventType.getCode(); + if(code.equals(DingTalkListenerType.CALL_BACK_REGISTER.getCode())){ + callBackServiceImpl.registerCallBack((DingtalkCallBack) syncEvent.getSource()); } - else if( eventType.equals(DingTalkListenerType.CALL_BACK_UPDATE.getCode())){ - callBackServiceImpl.updateCallBack((DingtalkCallBack) syncEvent.getT()); + else if( code.equals(DingTalkListenerType.CALL_BACK_UPDATE.getCode())){ + callBackServiceImpl.updateCallBack((DingtalkCallBack) syncEvent.getSource()); } + else if(code.equals(DingTalkListenerType.CALL_BACK_DELETE.getCode())){ + callBackServiceImpl.deleteCallBack((DingtalkCallBack) syncEvent.getSource()); + } + } } diff --git a/snow-dingtalk/src/main/java/com/snow/dingtalk/listener/SyncDingTalkInfoFactory.java b/snow-dingtalk/src/main/java/com/snow/dingtalk/listener/SyncDingTalkInfoFactory.java index 7053489..7a499f9 100644 --- a/snow-dingtalk/src/main/java/com/snow/dingtalk/listener/SyncDingTalkInfoFactory.java +++ b/snow-dingtalk/src/main/java/com/snow/dingtalk/listener/SyncDingTalkInfoFactory.java @@ -17,15 +17,15 @@ public class SyncDingTalkInfoFactory { public ISyncDingTalkInfo getSyncDingTalkService(SyncEvent syncEvent){ - Enum dingTalkEnum = (Enum) syncEvent.getT(); - - if(dingTalkEnum.equals(DingTalkListenerType.DEPARTMENT_CREATE.getType())){ + DingTalkListenerType dingTalkEnum = (DingTalkListenerType) syncEvent.getT(); + Integer type = dingTalkEnum.getType(); + if(type.equals(DingTalkListenerType.DEPARTMENT_CREATE.getType())){ return new DepartmentCreateEventService(); } - else if(dingTalkEnum.equals(DingTalkListenerType.USER_CREATED.getType())){ + else if(type.equals(DingTalkListenerType.USER_CREATED.getType())){ return new UserCreateEventService(); } - else if(dingTalkEnum.equals(DingTalkListenerType.CALL_BACK_REGISTER.getType())){ + else if(type.equals(DingTalkListenerType.CALL_BACK_REGISTER.getType())){ return new CallBackService(); } diff --git a/snow-dingtalk/src/main/java/com/snow/dingtalk/service/CallBackService.java b/snow-dingtalk/src/main/java/com/snow/dingtalk/service/CallBackService.java index b0d3caa..3b6d47e 100644 --- a/snow-dingtalk/src/main/java/com/snow/dingtalk/service/CallBackService.java +++ b/snow-dingtalk/src/main/java/com/snow/dingtalk/service/CallBackService.java @@ -1,7 +1,10 @@ package com.snow.dingtalk.service; +import com.dingtalk.api.response.OapiCallBackGetCallBackFailedResultResponse; import com.snow.system.domain.DingtalkCallBack; +import java.util.List; + /** * @author qimingjin * @Title: @@ -29,5 +32,5 @@ public interface CallBackService { /** * 获取回调失败结果 */ - void getCallBackFailedResult(); + List getCallBackFailedResult(); } diff --git a/snow-dingtalk/src/main/java/com/snow/dingtalk/service/impl/CallBackServiceImpl.java b/snow-dingtalk/src/main/java/com/snow/dingtalk/service/impl/CallBackServiceImpl.java index d27017d..7325168 100644 --- a/snow-dingtalk/src/main/java/com/snow/dingtalk/service/impl/CallBackServiceImpl.java +++ b/snow-dingtalk/src/main/java/com/snow/dingtalk/service/impl/CallBackServiceImpl.java @@ -16,7 +16,8 @@ import com.snow.system.domain.DingtalkCallBack; import com.taobao.api.ApiException; import org.springframework.stereotype.Service; -import java.util.Arrays; +import java.util.List; + /** * @author qimingjin @@ -38,7 +39,7 @@ public class CallBackServiceImpl extends BaseService implements CallBackService request.setToken(dingtalkCallBack.getToken()); request.setCallBackTag(dingtalkCallBack.getEventNameList()); try { - OapiCallBackRegisterCallBackResponse response = client.execute(request,getCallBackDingTalkToken(dingtalkCallBack)); + OapiCallBackRegisterCallBackResponse response = client.execute(request,getDingTalkToken()); if(response.getErrcode()==0){ syncDingTalkErrorOperLog(BaseConstantUrl.REGISTER_CALL_BACK,response.getMessage(),"registerCallBack()", JSON.toJSONString(request)); }else { @@ -60,7 +61,7 @@ public class CallBackServiceImpl extends BaseService implements CallBackService request.setToken(dingtalkCallBack.getToken()); request.setCallBackTag(dingtalkCallBack.getEventNameList()); try { - OapiCallBackUpdateCallBackResponse response = client.execute(request,getCallBackDingTalkToken(dingtalkCallBack)); + OapiCallBackUpdateCallBackResponse response = client.execute(request,getDingTalkToken()); if(response.getErrcode()==0){ syncDingTalkErrorOperLog(BaseConstantUrl.UPDATE_CALL_BACK,response.getMessage(),"updateCallBack()", JSON.toJSONString(request)); }else { @@ -93,27 +94,31 @@ public class CallBackServiceImpl extends BaseService implements CallBackService } @Override - public void getCallBackFailedResult() { + public List getCallBackFailedResult() { DingTalkClient client = new DefaultDingTalkClient(BaseConstantUrl.CALL_BACK_FAILED_RESULT); OapiCallBackGetCallBackFailedResultRequest request = new OapiCallBackGetCallBackFailedResultRequest(); request.setHttpMethod("GET"); try { OapiCallBackGetCallBackFailedResultResponse response = client.execute(request, getDingTalkToken()); if(response.getErrcode()==0){ - syncDingTalkErrorOperLog(BaseConstantUrl.DELETE_CALL_BACK,response.getMessage(),"getCallBackFailedResult()", JSON.toJSONString(request)); + List failedList = response.getFailedList(); + syncDingTalkErrorOperLog(BaseConstantUrl.CALL_BACK_FAILED_RESULT,response.getMessage(),"getCallBackFailedResult()", JSON.toJSONString(request)); + return failedList; }else { //记录获取token失败日志 - syncDingTalkErrorOperLog(BaseConstantUrl.DELETE_CALL_BACK,response.getErrmsg(),"getCallBackFailedResult()", JSON.toJSONString(request)); + syncDingTalkErrorOperLog(BaseConstantUrl.CALL_BACK_FAILED_RESULT,response.getErrmsg(),"getCallBackFailedResult()", JSON.toJSONString(request)); } } catch (ApiException e) { - syncDingTalkErrorOperLog(BaseConstantUrl.DELETE_CALL_BACK,e.getMessage(),"getCallBackFailedResult()", JSON.toJSONString(request)); + syncDingTalkErrorOperLog(BaseConstantUrl.CALL_BACK_FAILED_RESULT,e.getMessage(),"getCallBackFailedResult()", JSON.toJSONString(request)); e.printStackTrace(); } + return null; } /** * 获取token * @return */ + @Deprecated public String getCallBackDingTalkToken(DingtalkCallBack dingtalkCallBack){ //创建缓存,缓存默认是7100S TimedCache timedCache = CacheUtil.newTimedCache(7100);