Просмотр исходного кода

修改企业微信通讯录同步

yurk 2 лет назад
Родитель
Сommit
7eb2dcd9af

+ 3 - 3
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/controller/CompanyController.java

@@ -83,7 +83,7 @@ public class CompanyController {
             HttpRespMsg msg = new HttpRespMsg();
             String token = request.getHeader("TOKEN");
             User user = userMapper.selectById(token);
-            //判断时间
+            /*//判断时间
             long now = System.currentTimeMillis();
             if (syncLog.get(token) == null) {
                 syncLog.put(token, now);
@@ -110,7 +110,7 @@ public class CompanyController {
                         }
                     }
                 }
-            }
+            }*/
 
             Company company = companyMapper.selectOne(new QueryWrapper<Company>().eq("id", user.getCompanyId()));
             Integer employeeCnt = userMapper.selectCount(new QueryWrapper<User>().eq("company_id", company.getId()).eq("is_active",1));
@@ -123,7 +123,7 @@ public class CompanyController {
             if (companyDingding != null) {
                 System.out.println("===========同步钉钉===========");
                 String rest = dingDingService.syncCorpMembs(companyDingding.getCorpid());
-                syncLog.remove(user.getCompanyId()+"_status");
+                /*syncLog.remove(user.getCompanyId()+"_status");*/
                 if (rest.startsWith("调用失败")) {
                     msg.setError(rest);
                 } else {

+ 34 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/DingDingServiceImpl.java

@@ -29,6 +29,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
 import java.text.DecimalFormat;
 import java.text.SimpleDateFormat;
 import java.time.LocalDate;
@@ -72,6 +73,8 @@ public class DingDingServiceImpl implements DingDingService {
     @Resource
     private SysRoleMapper sysRoleMapper;
     @Resource
+    private HttpServletRequest request;
+    @Resource
     private SysModuleMapper sysModuleMapper;
     @Resource
     private LeaveQuotaNumService leaveQuotaNumService;
@@ -135,6 +138,8 @@ public class DingDingServiceImpl implements DingDingService {
     @Value("${configEnv.isDev}")
     private boolean isDev;//是否是本地开发环境
 
+    public static final HashMap<String, Long> syncLog = new HashMap();
+
     @Override
     public synchronized HttpRespMsg initSystem(String corpid) throws ApiException {
         System.out.println("========接收到initSystem请求===corpid="+corpid);
@@ -351,6 +356,34 @@ public class DingDingServiceImpl implements DingDingService {
     public String syncCorpMembs(String corpid) throws ApiException {
         CompanyDingding dingding = companyDingdingMapper.selectById(corpid);
         String accessToken = null;
+        String token = request.getHeader("TOKEN");
+        User user = userMapper.selectById(token);
+        //判断时间
+        long now = System.currentTimeMillis();
+        if (syncLog.get(token) == null) {
+            syncLog.put(token, now);
+            syncLog.put(user.getCompanyId()+"_status", 1L);
+        } else {
+            if (now - syncLog.get(token) < 30*1000) {
+                //msg.setError("调用过于频繁,请稍后再试");
+                return MessageUtils.message("Company.callError");
+            } else {
+                //检查是否当前公司有同步的正在进行
+                if (syncLog.get(user.getCompanyId()+"_status") == null) {
+                    //没有进行中的任务,更新最近同步的时间
+                    syncLog.put(token, now);
+                    syncLog.put(user.getCompanyId()+"_status", 1L);
+                } else {
+                    if (now - syncLog.get(token) > 0.5*3600*1000) {
+                        //更新最近同步的时间
+                        syncLog.put(token, now);
+                    } else {
+                        //msg.setError("同步正在进行中,请稍后再试");
+                        return MessageUtils.message("Company.synError");
+                    }
+                }
+            }
+        }
         if (dingding == null) {
             System.out.println("corpid不存在=="+corpid);
             return "调用失败:corpid不存在==";
@@ -388,6 +421,7 @@ public class DingDingServiceImpl implements DingDingService {
             System.out.println("syncCorpMembs 开始获取部门, accessToken="+accessToken);
             //获取授权的部门
             getAuthedDeptsAndUsers(dingding, accessToken);
+            syncLog.remove(user.getCompanyId()+"_status");
             return "调用成功";
         }
     }