|  |  |  | 
|---|
|  |  |  | import com.aliyun.dingtalkoauth2_1_0.Client; | 
|---|
|  |  |  | import com.aliyun.dingtalkoauth2_1_0.models.GetAccessTokenRequest; | 
|---|
|  |  |  | import com.aliyun.dingtalkoauth2_1_0.models.GetAccessTokenResponse; | 
|---|
|  |  |  | import com.aliyun.dingtalktodo_1_0.models.*; | 
|---|
|  |  |  | import com.aliyun.tea.TeaException; | 
|---|
|  |  |  | import com.aliyun.teautil.models.RuntimeOptions; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
|---|
|  |  |  | import com.dingtalk.api.DefaultDingTalkClient; | 
|---|
|  |  |  | import com.dingtalk.api.DingTalkClient; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.doumee.dao.business.dao.CompanyMapper; | 
|---|
|  |  |  | import com.doumee.dao.business.model.CarUseBook; | 
|---|
|  |  |  | import com.doumee.dao.business.model.Company; | 
|---|
|  |  |  | import com.doumee.dao.business.model.HiddenDanger; | 
|---|
|  |  |  | import com.doumee.dao.business.model.Visits; | 
|---|
|  |  |  | import com.doumee.dao.system.model.SystemDictData; | 
|---|
|  |  |  | import com.doumee.service.business.CompanyService; | 
|---|
|  |  |  | 
|---|
|  |  |  | private CompanyMapper companyMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 使用 Token 初始化账号Client | 
|---|
|  |  |  | * 使用 Token 初始化账号Client 数据同步类 | 
|---|
|  |  |  | * @return Client com.aliyun.dingtalkoauth2_1_0. | 
|---|
|  |  |  | * @throws Exception | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | 
|---|
|  |  |  | return new Client(config); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 待办通知类 链接池 | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | * @throws Exception | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public static com.aliyun.dingtalktodo_1_0.Client createV1Client() throws Exception { | 
|---|
|  |  |  | com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config(); | 
|---|
|  |  |  | config.protocol = "https"; | 
|---|
|  |  |  | config.regionId = "central"; | 
|---|
|  |  |  | return new com.aliyun.dingtalktodo_1_0.Client(config); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public void updTokenInfo() throws Exception { | 
|---|
|  |  |  | String appKey  =  systemDictDataBiz.queryByCode(Constants.DD_TALK,Constants.APP_KEY).getCode(); | 
|---|
|  |  |  | 
|---|
|  |  |  | getResponseList.add(deptGetResponse); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return getResponseList; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return thisLevelList; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 创建组织部门 暂不使用 | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static void main(String[] args) throws Exception { | 
|---|
|  |  |  | String appKey  = "dingkfglaktqmfd2dmo2";//systemDictDataBiz.queryByCode("","").getCode(); | 
|---|
|  |  |  | String appSecret  = "0e22TT2s794Yj49Exgvq8nU2ulpXmxlw9ThBh5s-vDv5Cfspv-f8HPmta4cg2evk";//systemDictDataBiz.queryByCode("","").getCode(); | 
|---|
|  |  |  | Client client = DingTalk.createClient(); | 
|---|
|  |  |  | GetAccessTokenRequest getAccessTokenRequest = new GetAccessTokenRequest() | 
|---|
|  |  |  | .setAppKey(appKey) | 
|---|
|  |  |  | .setAppSecret(appSecret); | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | GetAccessTokenResponse getAccessTokenResponse = client.getAccessToken(getAccessTokenRequest); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //更新Token信息 | 
|---|
|  |  |  | System.out.println(JSONObject.toJSONString(getAccessTokenResponse)); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } catch (TeaException err) { | 
|---|
|  |  |  | if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) { | 
|---|
|  |  |  | // err 中含有 code 和 message 属性,可帮助开发定位问题 | 
|---|
|  |  |  | log.error("更新钉钉Token失败:{}" + err.message); | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 发送 工作通知 | 
|---|
|  |  |  | * @param agentId | 
|---|
|  |  |  | * @param userIds | 
|---|
|  |  |  | * @param msg | 
|---|
|  |  |  | * api 地址 https://open.dingtalk.com/document/orgapp/asynchronous-sending-of-enterprise-session-messages | 
|---|
|  |  |  | * @throws ApiException | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public Boolean workInfoOANotice(Long agentId,String userIds,OapiMessageCorpconversationAsyncsendV2Request.Msg msg){ | 
|---|
|  |  |  | try{ | 
|---|
|  |  |  | if(CollectionUtils.isEmpty(msg)){ | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2"); | 
|---|
|  |  |  | OapiMessageCorpconversationAsyncsendV2Request request = new OapiMessageCorpconversationAsyncsendV2Request(); | 
|---|
|  |  |  | request.setAgentId(agentId); | 
|---|
|  |  |  | request.setUseridList(userIds); | 
|---|
|  |  |  | request.setToAllUser(false); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } catch (Exception _err) { | 
|---|
|  |  |  | TeaException err = new TeaException(_err.getMessage(), _err); | 
|---|
|  |  |  | if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) { | 
|---|
|  |  |  | // err 中含有 code 和 message 属性,可帮助开发定位问题 | 
|---|
|  |  |  | log.error("更新钉钉Token失败:{}" + err.message); | 
|---|
|  |  |  | request.setMsg(msg); | 
|---|
|  |  |  | OapiMessageCorpconversationAsyncsendV2Response rsp = client.execute(request, getToken()); | 
|---|
|  |  |  | if(rsp.getErrcode().equals(Constants.DD_ERR_CODE)){ | 
|---|
|  |  |  | return true; | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),rsp.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }catch (ApiException apiException){ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public void workInfoOANotice(Long agentId,String userIds,OapiMessageCorpconversationAsyncsendV2Request.Msg msg)throws ApiException { | 
|---|
|  |  |  | DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2"); | 
|---|
|  |  |  | OapiMessageCorpconversationAsyncsendV2Request request = new OapiMessageCorpconversationAsyncsendV2Request(); | 
|---|
|  |  |  | request.setAgentId(agentId); | 
|---|
|  |  |  | request.setUseridList(userIds); | 
|---|
|  |  |  | request.setToAllUser(false); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | request.setMsg(msg); | 
|---|
|  |  |  | OapiMessageCorpconversationAsyncsendV2Response rsp = client.execute(request, getToken()); | 
|---|
|  |  |  | if(rsp.getErrcode().equals(Constants.DD_ERR_CODE)){ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),rsp.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | List<OapiMessageCorpconversationAsyncsendV2Request.Form> formList = new ArrayList<>(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | OapiMessageCorpconversationAsyncsendV2Request.Form visitUser = new OapiMessageCorpconversationAsyncsendV2Request.Form(); | 
|---|
|  |  |  | visitUser.setKey("来访人"); | 
|---|
|  |  |  | visitUser.setKey("来访人:"); | 
|---|
|  |  |  | visitUser.setValue(visits.getName()); | 
|---|
|  |  |  | formList.add(visitUser); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | OapiMessageCorpconversationAsyncsendV2Request.Form inDate = new OapiMessageCorpconversationAsyncsendV2Request.Form(); | 
|---|
|  |  |  | inDate.setKey("入园时间"); | 
|---|
|  |  |  | inDate.setKey("入园时间:"); | 
|---|
|  |  |  | inDate.setValue(DateUtil.formatDate(visits.getStarttime(),"MM-dd HH:mm")); | 
|---|
|  |  |  | formList.add(inDate); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | OapiMessageCorpconversationAsyncsendV2Request.Form outDate = new OapiMessageCorpconversationAsyncsendV2Request.Form(); | 
|---|
|  |  |  | outDate.setKey("离园时间"); | 
|---|
|  |  |  | outDate.setKey("离园时间:"); | 
|---|
|  |  |  | outDate.setValue(DateUtil.formatDate(visits.getEndtime(),"MM-dd HH:mm")); | 
|---|
|  |  |  | formList.add(outDate); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | OapiMessageCorpconversationAsyncsendV2Request.Form inReason = new OapiMessageCorpconversationAsyncsendV2Request.Form(); | 
|---|
|  |  |  | inReason.setKey("来访事由"); | 
|---|
|  |  |  | inReason.setKey("来访事由:"); | 
|---|
|  |  |  | inReason.setValue(visits.getReason()); | 
|---|
|  |  |  | formList.add(inReason); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if(StringUtils.isNotBlank(visits.getCarNos())){ | 
|---|
|  |  |  | OapiMessageCorpconversationAsyncsendV2Request.Form carNos = new OapiMessageCorpconversationAsyncsendV2Request.Form(); | 
|---|
|  |  |  | carNos.setKey("随访车辆"); | 
|---|
|  |  |  | carNos.setKey("随访车辆:"); | 
|---|
|  |  |  | carNos.setValue(visits.getCarNos()); | 
|---|
|  |  |  | formList.add(visitUser); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | body.setForm(formList); | 
|---|
|  |  |  | oa.setBody(body); | 
|---|
|  |  |  | msg.setOa(oa); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return msg; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /* public OapiMessageCorpconversationAsyncsendV2Request.Msg getCarUseNoticeMsg(CarUseBook carUseBook,String title){ | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 用车信息 钉钉通知数据组合 | 
|---|
|  |  |  | * @param carUseBook | 
|---|
|  |  |  | * @param title | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public OapiMessageCorpconversationAsyncsendV2Request.Msg getCarUseNoticeMsg(CarUseBook carUseBook,String title){ | 
|---|
|  |  |  | OapiMessageCorpconversationAsyncsendV2Request.Msg msg = new OapiMessageCorpconversationAsyncsendV2Request.Msg(); | 
|---|
|  |  |  | msg.setMsgtype("oa"); | 
|---|
|  |  |  | OapiMessageCorpconversationAsyncsendV2Request.OA oa = new OapiMessageCorpconversationAsyncsendV2Request.OA(); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | OapiMessageCorpconversationAsyncsendV2Request.Form startDate = new OapiMessageCorpconversationAsyncsendV2Request.Form(); | 
|---|
|  |  |  | startDate.setKey("开始时间"); | 
|---|
|  |  |  | startDate.setKey("开始时间:"); | 
|---|
|  |  |  | startDate.setValue(DateUtil.formatDate(carUseBook.getStartTime(),"MM-dd HH:mm")); | 
|---|
|  |  |  | formList.add(startDate); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | OapiMessageCorpconversationAsyncsendV2Request.Form endDate = new OapiMessageCorpconversationAsyncsendV2Request.Form(); | 
|---|
|  |  |  | endDate.setKey("结束时间"); | 
|---|
|  |  |  | endDate.setKey("结束时间:"); | 
|---|
|  |  |  | endDate.setValue(DateUtil.formatDate(carUseBook.getEndTime(),"MM-dd HH:mm")); | 
|---|
|  |  |  | formList.add(endDate); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | OapiMessageCorpconversationAsyncsendV2Request.Form userNum = new OapiMessageCorpconversationAsyncsendV2Request.Form(); | 
|---|
|  |  |  | userNum.setKey("乘车人数"); | 
|---|
|  |  |  | userNum.setValue(DateUtil.formatDate(carUseBook.getEndTime(),"MM-dd HH:mm")); | 
|---|
|  |  |  | userNum.setKey("乘车人数:"); | 
|---|
|  |  |  | userNum.setValue(StringUtils.isBlank(carUseBook.getMemberNames())?"0人": (carUseBook.getMemberNames().split(",").length+"人")); | 
|---|
|  |  |  | formList.add(userNum); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | OapiMessageCorpconversationAsyncsendV2Request.Form inReason = new OapiMessageCorpconversationAsyncsendV2Request.Form(); | 
|---|
|  |  |  | inReason.setKey("来访事由"); | 
|---|
|  |  |  | inReason.setValue(visits.getReason()); | 
|---|
|  |  |  | inReason.setKey("用车地点:"); | 
|---|
|  |  |  | inReason.setValue(Constants.equalsInteger(carUseBook.getType(),Constants.ZERO)?"市内":"市外"); | 
|---|
|  |  |  | formList.add(inReason); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if(StringUtils.isNotBlank(visits.getCarNos())){ | 
|---|
|  |  |  | OapiMessageCorpconversationAsyncsendV2Request.Form carNos = new OapiMessageCorpconversationAsyncsendV2Request.Form(); | 
|---|
|  |  |  | carNos.setKey("随访车辆"); | 
|---|
|  |  |  | carNos.setValue(visits.getCarNos()); | 
|---|
|  |  |  | formList.add(visitUser); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | body.setForm(formList); | 
|---|
|  |  |  | oa.setBody(body); | 
|---|
|  |  |  | msg.setOa(oa); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return msg; | 
|---|
|  |  |  | }*/ | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 天气 markdown | 
|---|
|  |  |  | * @param title | 
|---|
|  |  |  | * @param text | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public OapiMessageCorpconversationAsyncsendV2Request.Msg getWeatherNoticeMsg(String title,String text){ | 
|---|
|  |  |  | OapiMessageCorpconversationAsyncsendV2Request.Msg msg = new OapiMessageCorpconversationAsyncsendV2Request.Msg(); | 
|---|
|  |  |  | msg.setMsgtype("markdown"); | 
|---|
|  |  |  | OapiMessageCorpconversationAsyncsendV2Request.Markdown markdown = new OapiMessageCorpconversationAsyncsendV2Request.Markdown(); | 
|---|
|  |  |  | markdown.setTitle(title); | 
|---|
|  |  |  | markdown.setText(text); | 
|---|
|  |  |  | msg.setMarkdown(markdown); | 
|---|
|  |  |  | return msg; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 安防/消防 markdown | 
|---|
|  |  |  | * @param hiddenDanger | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public OapiMessageCorpconversationAsyncsendV2Request.Msg getAlarmNoticeMsg(String areaName,String submitTime,String infoType){ | 
|---|
|  |  |  | OapiMessageCorpconversationAsyncsendV2Request.Msg msg = new OapiMessageCorpconversationAsyncsendV2Request.Msg(); | 
|---|
|  |  |  | msg.setMsgtype("markdown"); | 
|---|
|  |  |  | OapiMessageCorpconversationAsyncsendV2Request.Markdown markdown = new OapiMessageCorpconversationAsyncsendV2Request.Markdown(); | 
|---|
|  |  |  | markdown.setTitle("园区存在安防/消防隐患"); | 
|---|
|  |  |  | markdown.setText(areaName+"在"+submitTime+"发生"+infoType+",请及时前往安防中心/消防中心进行处理"); | 
|---|
|  |  |  | msg.setMarkdown(markdown); | 
|---|
|  |  |  | return msg; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 钉钉待办事件 | 
|---|
|  |  |  | * api地址 https://open.dingtalk.com/document/orgapp/add-dingtalk-to-do-task | 
|---|
|  |  |  | * unionId 通知所属用户 | 
|---|
|  |  |  | * title 标题 | 
|---|
|  |  |  | * unionIdList 待办通知人员集合 | 
|---|
|  |  |  | * @throws Exception | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public String toDoNotice(String title,List<String> unionIdList,List<CreateTodoTaskRequest.CreateTodoTaskRequestContentFieldList> fieldList,String url) { | 
|---|
|  |  |  | try{ | 
|---|
|  |  |  | if(CollectionUtils.isEmpty(fieldList)){ | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | com.aliyun.dingtalktodo_1_0.Client client = DingTalk.createV1Client(); | 
|---|
|  |  |  | CreateTodoTaskHeaders createTodoTaskHeaders = new CreateTodoTaskHeaders(); | 
|---|
|  |  |  | createTodoTaskHeaders.xAcsDingtalkAccessToken = getToken(); | 
|---|
|  |  |  | //待办截止前的提醒 | 
|---|
|  |  |  | CreateTodoTaskRequest.CreateTodoTaskRequestRemindNotifyConfigs remindNotifyConfigs = new CreateTodoTaskRequest.CreateTodoTaskRequestRemindNotifyConfigs() | 
|---|
|  |  |  | .setDingNotify("1") | 
|---|
|  |  |  | .setSendTodoApn("true"); | 
|---|
|  |  |  | //待办通知配置 | 
|---|
|  |  |  | CreateTodoTaskRequest.CreateTodoTaskRequestNotifyConfigs notifyConfigs = new CreateTodoTaskRequest.CreateTodoTaskRequestNotifyConfigs() | 
|---|
|  |  |  | .setDingNotify("1") | 
|---|
|  |  |  | .setSendTodoApn("true") | 
|---|
|  |  |  | .setSendAssistantChat("true"); | 
|---|
|  |  |  | //按钮事件 | 
|---|
|  |  |  | CreateTodoTaskRequest.CreateTodoTaskRequestActionListParam actionList0Param = new CreateTodoTaskRequest.CreateTodoTaskRequestActionListParam() | 
|---|
|  |  |  | .setBody(""); | 
|---|
|  |  |  | CreateTodoTaskRequest.CreateTodoTaskRequestActionList actionList0 = new CreateTodoTaskRequest.CreateTodoTaskRequestActionList() | 
|---|
|  |  |  | .setTitle("去处理") | 
|---|
|  |  |  | .setActionType(2) | 
|---|
|  |  |  | .setParam(actionList0Param) | 
|---|
|  |  |  | .setUrl(url) //TODO 详情地址 | 
|---|
|  |  |  | .setActionKey("ak-1-1"); | 
|---|
|  |  |  | //详情页url跳转地址 | 
|---|
|  |  |  | CreateTodoTaskRequest.CreateTodoTaskRequestDetailUrl detailUrl = new CreateTodoTaskRequest.CreateTodoTaskRequestDetailUrl() | 
|---|
|  |  |  | .setAppUrl("https://www.baidu.com") | 
|---|
|  |  |  | .setPcUrl("https://www.baidu.com"); | 
|---|
|  |  |  | CreateTodoTaskRequest createTodoTaskRequest = new CreateTodoTaskRequest() | 
|---|
|  |  |  | .setSubject(title) | 
|---|
|  |  |  | .setCreatorId(unionIdList.get(Constants.ZERO)) | 
|---|
|  |  |  | .setDescription(title) | 
|---|
|  |  |  | .setExecutorIds(unionIdList) | 
|---|
|  |  |  | .setDetailUrl(detailUrl) | 
|---|
|  |  |  | .setContentFieldList(fieldList) | 
|---|
|  |  |  | .setIsOnlyShowExecutor(true) | 
|---|
|  |  |  | .setPriority(20) | 
|---|
|  |  |  | .setNotifyConfigs(notifyConfigs) | 
|---|
|  |  |  | .setActionList(java.util.Arrays.asList(actionList0)) | 
|---|
|  |  |  | .setTodoType("TODO") | 
|---|
|  |  |  | .setRemindNotifyConfigs(remindNotifyConfigs); | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | CreateTodoTaskResponse response = client.createTodoTaskWithOptions(unionIdList.get(Constants.ZERO), createTodoTaskRequest, createTodoTaskHeaders, new com.aliyun.teautil.models.RuntimeOptions()); | 
|---|
|  |  |  | log.error("待办通知发送成功,发送内容:{}"+JSONObject.toJSONString(response)); | 
|---|
|  |  |  | return response.getBody().getId(); | 
|---|
|  |  |  | } catch (TeaException err) { | 
|---|
|  |  |  | if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) { | 
|---|
|  |  |  | log.error("待办通知发送失败,失败原因:{}"+err.message); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } catch (Exception _err) { | 
|---|
|  |  |  | TeaException err = new TeaException(_err.getMessage(), _err); | 
|---|
|  |  |  | if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) { | 
|---|
|  |  |  | // err 中含有 code 和 message 属性,可帮助开发定位问题 | 
|---|
|  |  |  | log.error("待办通知发送失败,失败原因:{}"+err.message); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | }catch (Exception e){ | 
|---|
|  |  |  | throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"钉钉待办任务通知发送失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 处理全部人的待办信息 (流程审批完成、本级审批完成 使用) | 
|---|
|  |  |  | * @param unionId | 
|---|
|  |  |  | * @param taskId | 
|---|
|  |  |  | * api地址 https://open.dingtalk.com/document/orgapp/updates-dingtalk-to-do-tasks | 
|---|
|  |  |  | * @throws Exception | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public void updToDoNoticeInfoStatus(String unionId,String taskId){ | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | com.aliyun.dingtalktodo_1_0.Client client = DingTalk.createV1Client(); | 
|---|
|  |  |  | UpdateTodoTaskHeaders updateTodoTaskHeaders = new UpdateTodoTaskHeaders(); | 
|---|
|  |  |  | updateTodoTaskHeaders.xAcsDingtalkAccessToken = getToken(); | 
|---|
|  |  |  | UpdateTodoTaskRequest updateTodoTaskRequest = new UpdateTodoTaskRequest() | 
|---|
|  |  |  | .setOperatorId(unionId) | 
|---|
|  |  |  | .setDone(true); | 
|---|
|  |  |  | UpdateTodoTaskResponse response = client.updateTodoTaskWithOptions(unionId, taskId, updateTodoTaskRequest, updateTodoTaskHeaders, new RuntimeOptions()); | 
|---|
|  |  |  | log.error("待办通知发送成功,发送内容:{}"+JSONObject.toJSONString(response)); | 
|---|
|  |  |  | } catch (TeaException err) { | 
|---|
|  |  |  | if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) { | 
|---|
|  |  |  | // err 中含有 code 和 message 属性,可帮助开发定位问题 | 
|---|
|  |  |  | log.error("待办通知发送失败,失败原因:{}"+err.message); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } catch (Exception _err) { | 
|---|
|  |  |  | TeaException err = new TeaException(_err.getMessage(), _err); | 
|---|
|  |  |  | if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) { | 
|---|
|  |  |  | // err 中含有 code 和 message 属性,可帮助开发定位问题 | 
|---|
|  |  |  | log.error("待办通知发送失败,失败原因:{}"+err.message); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 处理对应人员的待办信息 | 
|---|
|  |  |  | * @param unionId 创建人unionId | 
|---|
|  |  |  | * @param taskId  钉钉任务主键 | 
|---|
|  |  |  | * @param dealUnionId | 
|---|
|  |  |  | * api 地址 https://open.dingtalk.com/document/orgapp/update-dingtalk-to-do-status | 
|---|
|  |  |  | * @throws Exception | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public void updUserToDoNoticeInfoStatus(String unionId,String taskId,String dealUnionId){ | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | com.aliyun.dingtalktodo_1_0.Client client = DingTalk.createV1Client(); | 
|---|
|  |  |  | UpdateTodoTaskExecutorStatusHeaders updateTodoTaskExecutorStatusHeaders = new UpdateTodoTaskExecutorStatusHeaders(); | 
|---|
|  |  |  | updateTodoTaskExecutorStatusHeaders.xAcsDingtalkAccessToken = getToken(); | 
|---|
|  |  |  | UpdateTodoTaskExecutorStatusRequest.UpdateTodoTaskExecutorStatusRequestExecutorStatusList executorStatusList0 = new UpdateTodoTaskExecutorStatusRequest.UpdateTodoTaskExecutorStatusRequestExecutorStatusList() | 
|---|
|  |  |  | .setId(dealUnionId) | 
|---|
|  |  |  | .setIsDone(true); | 
|---|
|  |  |  | UpdateTodoTaskExecutorStatusRequest updateTodoTaskExecutorStatusRequest = new UpdateTodoTaskExecutorStatusRequest() | 
|---|
|  |  |  | .setExecutorStatusList(java.util.Arrays.asList( | 
|---|
|  |  |  | executorStatusList0 | 
|---|
|  |  |  | )); | 
|---|
|  |  |  | UpdateTodoTaskExecutorStatusResponse response = client.updateTodoTaskExecutorStatusWithOptions(unionId, taskId, updateTodoTaskExecutorStatusRequest, updateTodoTaskExecutorStatusHeaders, new RuntimeOptions()); | 
|---|
|  |  |  | log.error("待办通知发送成功,发送内容:{}"+JSONObject.toJSONString(response)); | 
|---|
|  |  |  | } catch (TeaException err) { | 
|---|
|  |  |  | if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) { | 
|---|
|  |  |  | // err 中含有 code 和 message 属性,可帮助开发定位问题 | 
|---|
|  |  |  | log.error("待办通知发送失败,失败原因:{}"+err.message); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } catch (Exception _err) { | 
|---|
|  |  |  | TeaException err = new TeaException(_err.getMessage(), _err); | 
|---|
|  |  |  | if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) { | 
|---|
|  |  |  | // err 中含有 code 和 message 属性,可帮助开发定位问题 | 
|---|
|  |  |  | log.error("待办通知发送失败,失败原因:{}"+err.message); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 访客报备与访客申请 钉钉待办 | 
|---|
|  |  |  | * @param visits | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public List<CreateTodoTaskRequest.CreateTodoTaskRequestContentFieldList> getToDoVisitFiledInfo(Visits visits){ | 
|---|
|  |  |  | List<CreateTodoTaskRequest.CreateTodoTaskRequestContentFieldList> list = new ArrayList<>(); | 
|---|
|  |  |  | CreateTodoTaskRequest.CreateTodoTaskRequestContentFieldList contentFieldList0 = new CreateTodoTaskRequest.CreateTodoTaskRequestContentFieldList() | 
|---|
|  |  |  | .setFieldKey("来访人") | 
|---|
|  |  |  | .setFieldValue(visits.getName()); | 
|---|
|  |  |  | list.add(contentFieldList0); | 
|---|
|  |  |  | CreateTodoTaskRequest.CreateTodoTaskRequestContentFieldList contentFieldList1 = new CreateTodoTaskRequest.CreateTodoTaskRequestContentFieldList() | 
|---|
|  |  |  | .setFieldKey("入园时间") | 
|---|
|  |  |  | .setFieldValue(DateUtil.getFomartDate(visits.getStarttime(),"MM-dd HH:mm")); | 
|---|
|  |  |  | list.add(contentFieldList1); | 
|---|
|  |  |  | CreateTodoTaskRequest.CreateTodoTaskRequestContentFieldList contentFieldList2 = new CreateTodoTaskRequest.CreateTodoTaskRequestContentFieldList() | 
|---|
|  |  |  | .setFieldKey("离园时间") | 
|---|
|  |  |  | .setFieldValue(DateUtil.getFomartDate(visits.getEndtime(),"MM-dd HH:mm")); | 
|---|
|  |  |  | list.add(contentFieldList2); | 
|---|
|  |  |  | CreateTodoTaskRequest.CreateTodoTaskRequestContentFieldList contentFieldList3 = new CreateTodoTaskRequest.CreateTodoTaskRequestContentFieldList() | 
|---|
|  |  |  | .setFieldKey("来访事由") | 
|---|
|  |  |  | .setFieldValue(visits.getReason()); | 
|---|
|  |  |  | list.add(contentFieldList3); | 
|---|
|  |  |  | if(StringUtils.isNotBlank(visits.getCarNos())){ | 
|---|
|  |  |  | CreateTodoTaskRequest.CreateTodoTaskRequestContentFieldList contentFieldList4 = new CreateTodoTaskRequest.CreateTodoTaskRequestContentFieldList() | 
|---|
|  |  |  | .setFieldKey("随访车辆") | 
|---|
|  |  |  | .setFieldValue(visits.getCarNos()); | 
|---|
|  |  |  | list.add(contentFieldList4); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return list; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 用车申请的 钉钉待办 | 
|---|
|  |  |  | * @param carUseBook | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public List<CreateTodoTaskRequest.CreateTodoTaskRequestContentFieldList> getToDoCarUseBookFiledInfo(CarUseBook carUseBook){ | 
|---|
|  |  |  | List<CreateTodoTaskRequest.CreateTodoTaskRequestContentFieldList> list = new ArrayList<>(); | 
|---|
|  |  |  | CreateTodoTaskRequest.CreateTodoTaskRequestContentFieldList contentFieldList1 = new CreateTodoTaskRequest.CreateTodoTaskRequestContentFieldList() | 
|---|
|  |  |  | .setFieldKey("开始时间") | 
|---|
|  |  |  | .setFieldValue(DateUtil.getFomartDate(carUseBook.getStartTime(),"MM-dd HH:mm")); | 
|---|
|  |  |  | list.add(contentFieldList1); | 
|---|
|  |  |  | CreateTodoTaskRequest.CreateTodoTaskRequestContentFieldList contentFieldList2 = new CreateTodoTaskRequest.CreateTodoTaskRequestContentFieldList() | 
|---|
|  |  |  | .setFieldKey("结束时间") | 
|---|
|  |  |  | .setFieldValue(DateUtil.getFomartDate(carUseBook.getEndTime(),"MM-dd HH:mm")); | 
|---|
|  |  |  | list.add(contentFieldList2); | 
|---|
|  |  |  | CreateTodoTaskRequest.CreateTodoTaskRequestContentFieldList contentFieldList3 = new CreateTodoTaskRequest.CreateTodoTaskRequestContentFieldList() | 
|---|
|  |  |  | .setFieldKey("乘车人数") | 
|---|
|  |  |  | .setFieldValue(StringUtils.isBlank(carUseBook.getMemberNames())?"0人": (carUseBook.getMemberNames().split(",").length+"人")); | 
|---|
|  |  |  | list.add(contentFieldList3); | 
|---|
|  |  |  | CreateTodoTaskRequest.CreateTodoTaskRequestContentFieldList contentFieldList4 = new CreateTodoTaskRequest.CreateTodoTaskRequestContentFieldList() | 
|---|
|  |  |  | .setFieldKey("用车地点") | 
|---|
|  |  |  | .setFieldValue(Constants.equalsInteger(carUseBook.getType(),Constants.ZERO)?"市内":"市外"); | 
|---|
|  |  |  | list.add(contentFieldList4); | 
|---|
|  |  |  | return list; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static void main(String[] args) throws Exception { | 
|---|
|  |  |  | DingTalk dingTalk = new DingTalk(); | 
|---|
|  |  |  | //        Visits visits = new Visits(); | 
|---|
|  |  |  | //        visits.setName("小豆丁"); | 
|---|
|  |  |  | //        visits.setStarttime(new Date()); | 
|---|
|  |  |  | //        visits.setEndtime(new Date()); | 
|---|
|  |  |  | //        visits.setReason("参观"); | 
|---|
|  |  |  | //        visits.setCarNos("皖A00001"); | 
|---|
|  |  |  | //        dingTalk.toDoNotice("visit_01","小豆丁的访客申请",java.util.Arrays.asList("iPsP86axviPHiSP4nm5YgQNCQiEiE") ,dingTalk.getToDoVisitFiledInfo(visits)); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | CarUseBook carUseBook = new CarUseBook(); | 
|---|
|  |  |  | carUseBook.setStartTime(new Date()); | 
|---|
|  |  |  | carUseBook.setEndTime(new Date()); | 
|---|
|  |  |  | carUseBook.setMemberNames("张三,李四,王五"); | 
|---|
|  |  |  | carUseBook.setType(Constants.ZERO); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //        dingTalk.workInfoOANotice(4015267031L,"1568490244651036",dingTalk.getCarUseNoticeMsg(carUseBook,"用车申请")); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | dingTalk.toDoNotice("小豆丁提交的公务车用车",java.util.Arrays.asList("iPsP86axviPHiSP4nm5YgQNCQiEiE","XiPYJKRAv9eCoO4UPM20HQQiEiE","eWbHiSp3uRtrMtiiOX5LXamgiEiE") ,dingTalk.getToDoCarUseBookFiledInfo(carUseBook),""); | 
|---|
|  |  |  | // | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //        dingTalk.updUserToDoNoticeInfoStatus("iPsP86axviPHiSP4nm5YgQNCQiEiE", | 
|---|
|  |  |  | //                "taska2d004da1f8e84847c895d14e8695102", | 
|---|
|  |  |  | //                "XiPYJKRAv9eCoO4UPM20HQQiEiE"); | 
|---|
|  |  |  | ; | 
|---|
|  |  |  | //        String appKey  = "dingkfglaktqmfd2dmo2";//systemDictDataBiz.queryByCode("","").getCode(); | 
|---|
|  |  |  | //        String appSecret  = "0e22TT2s794Yj49Exgvq8nU2ulpXmxlw9ThBh5s-vDv5Cfspv-f8HPmta4cg2evk";//systemDictDataBiz.queryByCode("","").getCode(); | 
|---|
|  |  |  | //        Client client = DingTalk.createClient(); | 
|---|
|  |  |  | //        GetAccessTokenRequest getAccessTokenRequest = new GetAccessTokenRequest() | 
|---|
|  |  |  | //                .setAppKey(appKey) | 
|---|
|  |  |  | //                .setAppSecret(appSecret); | 
|---|
|  |  |  | //        try { | 
|---|
|  |  |  | //            GetAccessTokenResponse getAccessTokenResponse = client.getAccessToken(getAccessTokenRequest); | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //            //更新Token信息 | 
|---|
|  |  |  | //            System.out.println(JSONObject.toJSONString(getAccessTokenResponse)); | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //        } catch (TeaException err) { | 
|---|
|  |  |  | //            if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) { | 
|---|
|  |  |  | //                // err 中含有 code 和 message 属性,可帮助开发定位问题 | 
|---|
|  |  |  | //                log.error("更新钉钉Token失败:{}" + err.message); | 
|---|
|  |  |  | //            } | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //        } catch (Exception _err) { | 
|---|
|  |  |  | //            TeaException err = new TeaException(_err.getMessage(), _err); | 
|---|
|  |  |  | //            if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) { | 
|---|
|  |  |  | //                // err 中含有 code 和 message 属性,可帮助开发定位问题 | 
|---|
|  |  |  | //                log.error("更新钉钉Token失败:{}" + err.message); | 
|---|
|  |  |  | //            } | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|