|
@@ -1,9 +1,15 @@
|
|
|
package org.fouram.service;
|
|
|
|
|
|
import java.util.List;
|
|
|
+import java.util.concurrent.ExecutorService;
|
|
|
+import java.util.concurrent.Executors;
|
|
|
|
|
|
+import org.fouram.constants.WebConstants;
|
|
|
import org.fouram.core.base.service.BaseService;
|
|
|
import org.fouram.core.plugin.weixin.cp.util.WXCpMessageUtil;
|
|
|
+import org.fouram.core.util.DateUtil;
|
|
|
+import org.fouram.core.util.LoggerUtil;
|
|
|
+import org.fouram.dto.output.SyncWeixinUserOutput;
|
|
|
import org.fouram.entity.SapUser;
|
|
|
import org.fouram.enums.DelFlagEnum;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -19,9 +25,31 @@ public class SyncSapUserToWxService extends BaseService {
|
|
|
private SapUserService sapUserService;
|
|
|
@Autowired
|
|
|
private WxDepartService wxDepartService;
|
|
|
-
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ public SyncWeixinUserOutput syncWeixinUser() throws Exception {
|
|
|
+ if (WebConstants.CACHE.containsKey(WebConstants.CACHE_SYNC_SAP)) {
|
|
|
+ return SyncWeixinUserOutput.builder().state("同步中")
|
|
|
+ .time(WebConstants.CACHE.get(WebConstants.CACHE_SYNC_SAP)).build();
|
|
|
+ }
|
|
|
+ ExecutorService threadPool = Executors.newSingleThreadExecutor();
|
|
|
+ threadPool.execute(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ try {
|
|
|
+ taskBiz();
|
|
|
+ } catch (Exception e) {
|
|
|
+ LoggerUtil.error(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ threadPool.shutdown();// 任务执行完毕,关闭线程池
|
|
|
+ return SyncWeixinUserOutput.builder().state("正在同步,请稍等").build();
|
|
|
+ }
|
|
|
+
|
|
|
@Transactional
|
|
|
public void taskBiz() throws Exception {
|
|
|
+ WebConstants.CACHE.put(WebConstants.CACHE_SYNC_SAP, DateUtil.getTime());
|
|
|
// 更新微信部门
|
|
|
wxDepartService.saveWxDeparts();
|
|
|
// 更新微信用户
|
|
@@ -38,6 +66,7 @@ public class SyncSapUserToWxService extends BaseService {
|
|
|
sapUserService.updateAllNormalSyncWxResult();
|
|
|
// 发送禁用企业微信账号信息
|
|
|
this.sendQuitUserMsg();
|
|
|
+ WebConstants.CACHE.remove(WebConstants.CACHE_SYNC_SAP);
|
|
|
}
|
|
|
|
|
|
// 发送禁用企业微信账号信息
|