yingp 5 years ago
parent
commit
afe619c9ef

+ 33 - 0
uas-office-core/src/main/java/com/usoftchina/uas/office/util/Try.java

@@ -0,0 +1,33 @@
+package com.usoftchina.uas.office.util;
+
+import java.util.concurrent.Callable;
+
+/**
+ * @author yingp
+ * @date 2020/2/18
+ */
+public class Try {
+    /**
+     * 多次尝试执行一段代码,直到拿到结果
+     *
+     * @param callable
+     * @param times
+     * @param <R>
+     * @return
+     * @throws Exception
+     */
+    public static <R> R call(Callable<R> callable, int times) {
+        for (int i = 0; i < times; i++) {
+            try {
+                R result = callable.call();
+                if (null != result) {
+                    return result;
+                }
+                Thread.sleep(500);
+            } catch (Exception e) {
+                return null;
+            }
+        }
+        return null;
+    }
+}

+ 2 - 3
uas-office-qywx/src/main/java/com/usoftchina/uas/office/qywx/listener/UasProcessListener.java

@@ -14,6 +14,7 @@ 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;
@@ -64,7 +65,7 @@ public class UasProcessListener {
     }
 
     private void sendProcessMessage(UasEvent event, Integer jpId) {
-        JProcess process = jProcessService.getById(jpId);
+        JProcess process = Try.call(() -> jProcessService.getById(jpId), 10);
         Employee employee = getDealMan(process);
         if (null == employee) {
             return;
@@ -88,9 +89,7 @@ public class UasProcessListener {
 
     public Employee getDealMan(JProcess process) {
         try {
-            logger.debug("null == process " + (null == process));
             DataSourceHolder.set(DataCenter.INSTANCE);
-            logger.debug("null == employeeService " + (null == employeeService));
             Employee employee = employeeService.getByCode(process.getJp_nodedealman());
             if (null == employee || null == employee.getEm_qywx()) {
                 return null;

+ 1 - 2
uas-office-qywx/src/main/java/com/usoftchina/uas/office/qywx/service/UasJProcessService.java

@@ -1,6 +1,5 @@
 package com.usoftchina.uas.office.qywx.service;
 
-import com.usoftchina.uas.office.context.MasterHolder;
 import com.usoftchina.uas.office.qywx.entity.JProcess;
 import com.usoftchina.uas.office.service.AbstractService;
 import org.springframework.stereotype.Service;
@@ -13,6 +12,6 @@ import org.springframework.stereotype.Service;
 public class UasJProcessService extends AbstractService {
 
     public JProcess getById(Integer id) {
-        return queryForBean("select * from " + MasterHolder.get().username() + ".JProcess where jp_id=?", JProcess.class, id);
+        return queryForBean("select * from JProcess where jp_id=?", JProcess.class, id);
     }
 }