|
|
@@ -3,12 +3,18 @@ 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.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.service.DataCenterService;
|
|
|
+import com.usoftchina.uas.office.util.Try;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
@@ -27,14 +33,17 @@ public class UasProcessListener {
|
|
|
@Autowired
|
|
|
private MessageSdk messageSdk;
|
|
|
|
|
|
- @Autowired
|
|
|
- private DataCenterService dataCenterService;
|
|
|
-
|
|
|
@Autowired
|
|
|
private UasJProcessService jProcessService;
|
|
|
|
|
|
private final Logger logger = LoggerFactory.getLogger(UasProcessListener.class);
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private QywxAgentService agentService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UasEmployeeService employeeService;
|
|
|
+
|
|
|
/**
|
|
|
* uas保存审批任务,发送消息到企业微信
|
|
|
*
|
|
|
@@ -56,19 +65,51 @@ public class UasProcessListener {
|
|
|
}
|
|
|
|
|
|
private void sendProcessMessage(UasEvent event, Integer jpId) {
|
|
|
- JProcess process = jProcessService.getById(jpId);
|
|
|
- DataCenter dataCenter = dataCenterService.find();
|
|
|
+ JProcess process = Try.call(() -> jProcessService.getById(jpId), 10);
|
|
|
+ if (null == process) {
|
|
|
+ logger.warn("can not find process {}, {}", jpId, event);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Employee employee = getDealMan(process);
|
|
|
+ if (null == employee) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ DataCenter dataCenter = DataCenter.INSTANCE;
|
|
|
String title = process.getJp_launchername() + "的" + process.getJp_name();
|
|
|
String description = "单据编号:" + process.getJp_codevalue();
|
|
|
try {
|
|
|
- String paramsStr = "{\"master\":\"" + event.getMaster() + "\",\"nodeId\":" + process.getJp_nodeid() + ",\"baseUrl\":\"" + URLEncoder.encode(dataCenter.getErpOuterUrl(), "utf-8") + "\"}";
|
|
|
- String msgUrl = UrlUtils.generateOAuthUrl(messageSdk.getCorpId(), event.getMaster(), "Uas", dataCenter.getErpOuterUrl(),
|
|
|
- dataCenter.getOuterUrl() + "/api/authorize", "uas/approval/" + URLEncoder.encode(paramsStr, "utf-8"));
|
|
|
+ // 往uas应用发送
|
|
|
+ QywxAgent agent = getUasAgent();
|
|
|
+ String paramsStr = "{\"master\":\"" + event.getMaster() + "\",\"nodeId\":" + process.getJp_nodeid() + ",\"baseUrl\":\"" + URLEncoder.encode(agent.getOuterUrl(), "utf-8") + "\"}";
|
|
|
+ String msgUrl = UrlUtils.generateOAuthUrl(messageSdk.getCorpId(), event.getMaster(), "Uas", agent.getOuterUrl(),
|
|
|
+ dataCenter.getOuterUrl() + "api/authorize", "uas/approval/" + URLEncoder.encode(paramsStr, "utf-8"));
|
|
|
messageSdk.send("Uas", new SendMessageReq()
|
|
|
.textCard(title, description, msgUrl, "查看详情")
|
|
|
- .toUser(process.getEm_qywx()));
|
|
|
+ .toUser(employee.getEm_qywx()));
|
|
|
} catch (Exception e) {
|
|
|
logger.error("send process message error", e);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public Employee getDealMan(JProcess process) {
|
|
|
+ try {
|
|
|
+ DataSourceHolder.set(DataCenter.INSTANCE);
|
|
|
+ Employee employee = employeeService.getByCode(process.getJp_nodedealman());
|
|
|
+ if (null == employee || null == employee.getEm_qywx()) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return employee;
|
|
|
+ } finally {
|
|
|
+ DataSourceHolder.set(MasterHolder.get());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public QywxAgent getUasAgent() {
|
|
|
+ try {
|
|
|
+ DataSourceHolder.set(DataCenter.INSTANCE);
|
|
|
+ return agentService.findByCode("Uas");
|
|
|
+ } finally {
|
|
|
+ DataSourceHolder.set(MasterHolder.get());
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|