|
|
@@ -0,0 +1,88 @@
|
|
|
+package com.usoftchina.uas.office.qywx.listener;
|
|
|
+
|
|
|
+import com.usoftchina.qywx.sdk.MessageSdk;
|
|
|
+import com.usoftchina.qywx.sdk.dto.SendMessageReq;
|
|
|
+import com.usoftchina.qywx.sdk.util.UrlUtils;
|
|
|
+import com.usoftchina.uas.office.context.MasterHolder;
|
|
|
+import com.usoftchina.uas.office.dto.UasEvent;
|
|
|
+import com.usoftchina.uas.office.entity.DataCenter;
|
|
|
+import com.usoftchina.uas.office.jdbc.DataSourceHolder;
|
|
|
+import com.usoftchina.uas.office.listener.UasEventListener;
|
|
|
+import com.usoftchina.uas.office.qywx.entity.Employee;
|
|
|
+import com.usoftchina.uas.office.qywx.entity.JProcandOrProcess;
|
|
|
+import com.usoftchina.uas.office.qywx.entity.JProcess;
|
|
|
+import com.usoftchina.uas.office.qywx.manage.entity.QywxAgent;
|
|
|
+import com.usoftchina.uas.office.qywx.manage.service.QywxAgentService;
|
|
|
+import com.usoftchina.uas.office.qywx.service.UasEmployeeService;
|
|
|
+import com.usoftchina.uas.office.qywx.service.UasJProcessService;
|
|
|
+import com.usoftchina.uas.office.util.Try;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.net.URLEncoder;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author yingp
|
|
|
+ * @date 2020/2/16
|
|
|
+ */
|
|
|
+@Component
|
|
|
+public class UasUrlMsgListener {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MessageSdk messageSdk;
|
|
|
+
|
|
|
+ private final Logger logger = LoggerFactory.getLogger(UasUrlMsgListener.class);
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private QywxAgentService agentService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * uas催办任务,发送消息到企业微信
|
|
|
+ *
|
|
|
+ * @param event
|
|
|
+ */
|
|
|
+ @UasEventListener(caller = "TEXTCARD", operation = "BASEURLMSG")
|
|
|
+ public void baseUrlMsg(UasEvent event) {
|
|
|
+ if (!messageSdk.isAgentEnabled("Uas")) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (event.getKey() instanceof List) {
|
|
|
+ List<Map<String,Object>> msgList = (List<Map<String,Object>>) event.getKey();
|
|
|
+ msgList.forEach(msg -> {
|
|
|
+ sendProcessMessage(event, msg);
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ sendProcessMessage(event, (Map<String,Object>) event.getKey());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ private void sendProcessMessage(UasEvent event, Map<String,Object> msg) {
|
|
|
+ try {
|
|
|
+ DataCenter dataCenter = DataCenter.INSTANCE;
|
|
|
+ String title = msg.get("title").toString();
|
|
|
+ String url = msg.get("redirectUrl").toString();
|
|
|
+ String description = msg.get("description").toString();
|
|
|
+ String userCode = msg.get("userCode").toString();
|
|
|
+ // 根据UAS配置的外部地址发送 开通U审批用U审批推送 没开通用UAS应用推送
|
|
|
+ QywxAgent agent = getUasAgent();
|
|
|
+ String msgUrl = UrlUtils.generateOAuthUrl(messageSdk.getCorpId(), event.getMaster(), "Uas", agent.getOuterUrl(),
|
|
|
+ dataCenter.getOuterUrl() + "api/authorize", url);
|
|
|
+ messageSdk.send("Uas", new SendMessageReq()
|
|
|
+ .textCard(title, description, msgUrl, "查看详情")
|
|
|
+ .toUser(userCode));
|
|
|
+ }catch (Exception e){
|
|
|
+ logger.error("send urge message error", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ public QywxAgent getUasAgent() {
|
|
|
+ try {
|
|
|
+ DataSourceHolder.set(DataCenter.INSTANCE);
|
|
|
+ return agentService.findByCode("Uas");
|
|
|
+ } finally {
|
|
|
+ DataSourceHolder.set(MasterHolder.get());
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|