2 Commits 00cc019591 ... 3c98aca051

Auteur SHA1 Bericht Datum
  zhouy 3c98aca051 Merge remote-tracking branch 'origin/branch_qywx_v2' into branch_qywx_v2 2 maanden geleden
  zhouy c80ca75378 增加按手机号同步刷新接口 2 maanden geleden

+ 19 - 0
uas-office-qywx/src/main/java/com/usoftchina/uas/office/qywx/manage/controller/QywxAddrBookController.java

@@ -124,4 +124,23 @@ public class QywxAddrBookController {
         }
 
     }
+
+    @GetMapping(path = "/addrbook/syncUserOpenIdByMobile")
+    public Result getUserOpenIdByMobile(String mobile) {
+        DataCenter dataCenter = DataCenter.INSTANCE;
+        if (null == dataCenter) {
+            return Result.error("数据中心未设置");
+        }
+        if (!addrBookSdk.enabled()) {
+            return Result.error("通讯录API未设置");
+        }
+        try {
+            DataSourceHolder.set(dataCenter);
+            employeeService.syncEmployee(mobile);
+            return Result.success();
+        } finally {
+            DataSourceHolder.clear();
+        }
+
+    }
 }

+ 27 - 21
uas-office-qywx/src/main/java/com/usoftchina/uas/office/qywx/service/UasEmployeeService.java

@@ -529,7 +529,32 @@ public class UasEmployeeService extends AbstractService {
      * 当前方法仅适用于企业微信端已提前建立好人员资料
      * */
     public void syncAll_UpGrade(){
-        List<Employee> employeeList = queryForBeanList("select * from employee where em_statuscode='AUDITED' and em_mobile is not null", Employee.class);
+        syncEmployee(null);
+    }
+    public Object convert_openUserId(){
+        List<Employee> employeeList = queryForBeanList("select * from employee where em_statuscode='AUDITED' and em_plainqywx is not null and em_qywx is null", Employee.class);
+        //通过手机号查找userID信息
+        if(!employeeList.isEmpty()) {
+            GetUserOpenIDListResp getUserOpenIDListResp = addrBookSdk.convert_openUserId(employeeList.stream().map(Employee::getEm_plainqywx).collect(Collectors.toList()));
+            List<GetUserOpenIDListResp.OpenUser> userList = getUserOpenIDListResp.getOpen_userid_list();
+            for (GetUserOpenIDListResp.OpenUser openUser : userList) {
+                Employee employee = employeeList.stream().filter(emp->StringUtils.hasText(emp.getEm_plainqywx())&&emp.getEm_plainqywx().equals(openUser.getUserid())).findFirst().orElse(null);
+                if(employee!= null){
+                    employee.setEm_qywx(openUser.getOpen_userid());
+                    setQywxWithPlain(employee);
+                }
+            }
+            return getUserOpenIDListResp;
+        }
+        return null;
+    }
+    public void syncEmployee(String mobile){
+        List<Employee> employeeList = null;
+        if(StringUtils.hasText(mobile)){
+            employeeList = queryForBeanList("select * from employee where em_statuscode='AUDITED' and em_mobile=?", Employee.class,mobile);
+        }else {
+            employeeList = queryForBeanList("select * from employee", Employee.class);
+        }
         //通过手机号查找userID信息
         for (Employee employee : employeeList) {
             try {
@@ -544,24 +569,7 @@ public class UasEmployeeService extends AbstractService {
             }
         }
         if(!employeeList.isEmpty()) {
-          List<GetUserOpenIDListResp.OpenUser> userList = addrBookSdk.convert_openUserId(employeeList.stream().filter(emp->StringUtils.hasText(emp.getEm_plainqywx())).map(Employee::getEm_plainqywx).collect(Collectors.toList())).getOpen_userid_list();
-          for (GetUserOpenIDListResp.OpenUser openUser : userList) {
-              Employee employee = employeeList.stream().filter(emp->StringUtils.hasText(emp.getEm_plainqywx())&&emp.getEm_plainqywx().equals(openUser.getUserid())).findFirst().orElse(null);
-              if(employee!= null){
-                  employee.setEm_qywx(openUser.getOpen_userid());
-                  setQywxWithPlain(employee);
-              }
-          }
-        }
-
-
-    }
-    public Object convert_openUserId(){
-        List<Employee> employeeList = queryForBeanList("select * from employee where em_statuscode='AUDITED' and em_plainqywx is not null and em_qywx is null", Employee.class);
-        //通过手机号查找userID信息
-        if(!employeeList.isEmpty()) {
-            GetUserOpenIDListResp getUserOpenIDListResp = addrBookSdk.convert_openUserId(employeeList.stream().map(Employee::getEm_plainqywx).collect(Collectors.toList()));
-            List<GetUserOpenIDListResp.OpenUser> userList = getUserOpenIDListResp.getOpen_userid_list();
+            List<GetUserOpenIDListResp.OpenUser> userList = addrBookSdk.convert_openUserId(employeeList.stream().filter(emp->StringUtils.hasText(emp.getEm_plainqywx())).map(Employee::getEm_plainqywx).collect(Collectors.toList())).getOpen_userid_list();
             for (GetUserOpenIDListResp.OpenUser openUser : userList) {
                 Employee employee = employeeList.stream().filter(emp->StringUtils.hasText(emp.getEm_plainqywx())&&emp.getEm_plainqywx().equals(openUser.getUserid())).findFirst().orElse(null);
                 if(employee!= null){
@@ -569,8 +577,6 @@ public class UasEmployeeService extends AbstractService {
                     setQywxWithPlain(employee);
                 }
             }
-            return getUserOpenIDListResp;
         }
-        return null;
     }
 }