|
|
@@ -0,0 +1,88 @@
|
|
|
+package com.usoftchina.uas.office.qywx.task;
|
|
|
+
|
|
|
+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.entity.DataCenter;
|
|
|
+import com.usoftchina.uas.office.jdbc.DataSourceHolder;
|
|
|
+import com.usoftchina.uas.office.qywx.entity.Employee;
|
|
|
+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.UasAnalysisService;
|
|
|
+import com.usoftchina.uas.office.qywx.service.UasEmployeeService;
|
|
|
+import com.usoftchina.uas.office.qywx.service.UasJProcessService;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.net.URLEncoder;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author wuyx
|
|
|
+ * @date 2020/3/12
|
|
|
+ */
|
|
|
+@Component
|
|
|
+public class QywxProcessTask {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MessageSdk messageSdk;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UasJProcessService uasJProcessService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UasEmployeeService uasEmployeeService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private QywxAgentService agentService;
|
|
|
+
|
|
|
+ private final Logger logger = LoggerFactory.getLogger(QywxProcessTask.class);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 每日审批提醒推送
|
|
|
+ */
|
|
|
+ @Scheduled(cron="0 0 23 * * ? ")
|
|
|
+ public void pullCheckinData() {
|
|
|
+ if (!messageSdk.isAgentEnabled("Uas")) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ DataCenter dataCenter = DataCenter.INSTANCE;
|
|
|
+ if (null != dataCenter.getUsername() && null != dataCenter.getPassword() && null != dataCenter.getUrl()) {
|
|
|
+ try {
|
|
|
+ DataSourceHolder.set(dataCenter);
|
|
|
+ //获取要推送人员列表
|
|
|
+ List<Employee> emList = uasEmployeeService.getAll();
|
|
|
+ for(Employee em : emList){
|
|
|
+ try {
|
|
|
+ QywxAgent agent = agentService.findByCode("Uas");
|
|
|
+ //获取待提醒流程列表
|
|
|
+ List<Map<String,Object>> remindList = uasJProcessService.getRemindList(em.getEm_code());
|
|
|
+ if(remindList.size() > 0 && "周袁#李剑辉#吴雨骁#李嘉#饶猛".contains(em.getEm_name())){
|
|
|
+ StringBuffer content = new StringBuffer();
|
|
|
+ content.append("**您有<font color=blue>"+remindList.get(0).get("COUNTS")+"</font>个审批单还未处理**\n" );
|
|
|
+ for (Map<String,Object> remind: remindList) {
|
|
|
+ String paramsStr = "{\"master\":\"" + remind.get("CURRENTMASTER") + "\",\"nodeId\":" + remind.get("JP_NODEID") + ",\"baseUrl\":\"" + URLEncoder.encode(agent.getOuterUrl(), "utf-8") + "\"}";
|
|
|
+ String msgUrl = UrlUtils.generateOAuthUrl(messageSdk.getCorpId(), dataCenter.getUsername(), "Uas", agent.getOuterUrl(),
|
|
|
+ dataCenter.getOuterUrl() + "api/authorize", "uas/approval/" + URLEncoder.encode(paramsStr, "utf-8"));
|
|
|
+ content.append("> 【停留").append(remind.get("PASSTIME")).append("天】\n ")
|
|
|
+ .append(remind.get("JP_LAUNCHERNAME")).append("的[").append(remind.get("JP_NAME")).append("]("+msgUrl+")\n");
|
|
|
+ }
|
|
|
+ String moreUrl = UrlUtils.generateOAuthUrl(messageSdk.getCorpId(), dataCenter.getUsername(), "Uas", agent.getOuterUrl(),
|
|
|
+ dataCenter.getOuterUrl() + "api/authorize", "uas/uasApproval/"+dataCenter.getUsername()+"/receive");
|
|
|
+ content.append("[更多...](").append(moreUrl).append(")");
|
|
|
+ messageSdk.send("UasAudit", new SendMessageReq().markdown(content.toString()).toUser(em.getEm_qywx()));
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("send process remind error", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } finally {
|
|
|
+ DataSourceHolder.clear();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|