| | |
| | | import com.ruoyi.project.domain.vo.DingTalkReqVo; |
| | | import com.ruoyi.project.service.DingTalkService; |
| | | import com.taobao.api.ApiException; |
| | | import lombok.Data; |
| | | import lombok.extern.log4j.Log4j; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | |
| | | |
| | | @Value("${dingAppSecret}") |
| | | private String dingAppSecret; |
| | | |
| | | @Value("${agentId}") |
| | | private Long agentId; |
| | | |
| | | @Override |
| | | public Boolean sendNotification(DingTalkReqVo dingTalkReqVo) { |
| | |
| | | DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2"); |
| | | OapiMessageCorpconversationAsyncsendV2Request request = new OapiMessageCorpconversationAsyncsendV2Request(); |
| | | request.setUseridList(urid); |
| | | request.setAgentId(1779052814L); |
| | | request.setAgentId(agentId); |
| | | request.setToAllUser(false); |
| | | |
| | | //发送内容处理 |
| | | List<ConcurrentHashMap<String, String>> contents = dingTalkReqVo.getContents(); |
| | | List<ConcurrentHashMap<String, Object>> contents = dingTalkReqVo.getContents(); |
| | | ArrayList<OapiMessageCorpconversationAsyncsendV2Request.Form> objects = new ArrayList<>(); |
| | | for (int i = 0; i < contents.size(); i++) { |
| | | ConcurrentHashMap<String, String> map = contents.get(i); |
| | | for (Map.Entry<String, String> entry : map.entrySet()) { |
| | | ConcurrentHashMap<String, Object> map = contents.get(i); |
| | | for (Map.Entry<String, Object> entry : map.entrySet()) { |
| | | OapiMessageCorpconversationAsyncsendV2Request.Form formSeverityDesc = new OapiMessageCorpconversationAsyncsendV2Request.Form(); |
| | | formSeverityDesc.setKey(entry.getKey()); |
| | | formSeverityDesc.setValue(entry.getValue()); |
| | | if (entry.getKey().contains("审批时间")) { |
| | | Date date = (Date) entry.getValue(); |
| | | SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); |
| | | String format = simpleDateFormat.format(date); |
| | | formSeverityDesc.setValue(format); |
| | | } else { |
| | | if (entry.getValue() != null) { |
| | | formSeverityDesc.setValue(entry.getValue().toString()); |
| | | } |
| | | } |
| | | objects.add(formSeverityDesc); |
| | | } |
| | | } |
| | |
| | | try { |
| | | response = client.execute(request, accessToken); |
| | | } catch (ApiException e) { |
| | | e.printStackTrace(); |
| | | e.getErrMsg(); |
| | | } |
| | | |
| | | // log.info("消息任务ID"+response.getTaskId()); |