|
@@ -1,24 +1,25 @@
|
|
/*
|
|
/*
|
|
* Copyright [2021] [MaxKey of copyright http://www.maxkey.top]
|
|
* Copyright [2021] [MaxKey of copyright http://www.maxkey.top]
|
|
- *
|
|
|
|
|
|
+ *
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
* You may obtain a copy of the License at
|
|
- *
|
|
|
|
|
|
+ *
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
- *
|
|
|
|
|
|
+ *
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
* limitations under the License.
|
|
*/
|
|
*/
|
|
-
|
|
|
|
|
|
+
|
|
|
|
|
|
package org.maxkey.synchronizer.dingding;
|
|
package org.maxkey.synchronizer.dingding;
|
|
|
|
|
|
import org.joda.time.DateTime;
|
|
import org.joda.time.DateTime;
|
|
import org.joda.time.format.DateTimeFormat;
|
|
import org.joda.time.format.DateTimeFormat;
|
|
|
|
+import org.maxkey.constants.ConstantsPasswordSetType;
|
|
import org.maxkey.entity.Synchronizers;
|
|
import org.maxkey.entity.Synchronizers;
|
|
import org.maxkey.entity.UserInfo;
|
|
import org.maxkey.entity.UserInfo;
|
|
import org.maxkey.persistence.service.UserInfoService;
|
|
import org.maxkey.persistence.service.UserInfoService;
|
|
@@ -36,100 +37,128 @@ import com.dingtalk.api.response.OapiV2DepartmentListsubResponse.DeptBaseRespons
|
|
import com.dingtalk.api.response.OapiV2UserListResponse.ListUserResponse;
|
|
import com.dingtalk.api.response.OapiV2UserListResponse.ListUserResponse;
|
|
|
|
|
|
@Service
|
|
@Service
|
|
-public class DingdingUsersService implements ISynchronizerService{
|
|
|
|
- final static Logger _logger = LoggerFactory.getLogger(DingdingUsersService.class);
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- DingdingOrganizationService organizationService;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- UserInfoService userInfoService;
|
|
|
|
-
|
|
|
|
- String access_token;
|
|
|
|
-
|
|
|
|
- public void sync() {
|
|
|
|
- _logger.info("Sync Users...");
|
|
|
|
- try {
|
|
|
|
-
|
|
|
|
- OapiV2DepartmentListsubResponse rspDepts = organizationService.getRspDepts();
|
|
|
|
- for(DeptBaseResponse dept : rspDepts.getResult()) {
|
|
|
|
- DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/user/list");
|
|
|
|
- OapiV2UserListRequest req = new OapiV2UserListRequest();
|
|
|
|
- req.setDeptId(dept.getDeptId());
|
|
|
|
- req.setCursor(0L);
|
|
|
|
- req.setSize(100L);
|
|
|
|
- req.setOrderField("modify_desc");
|
|
|
|
- req.setContainAccessLimit(true);
|
|
|
|
- req.setLanguage("zh_CN");
|
|
|
|
- OapiV2UserListResponse rsp = client.execute(req, access_token);
|
|
|
|
- _logger.info("response : " + rsp.getBody());
|
|
|
|
-
|
|
|
|
- if(rsp.getErrcode()==0) {
|
|
|
|
- for(ListUserResponse user :rsp.getResult().getList()) {
|
|
|
|
- _logger.info("name : " + user.getName()+" , "+user.getLoginId()+" , "+user.getUserid());
|
|
|
|
- UserInfo userInfo = buildUserInfo(user);
|
|
|
|
- _logger.info("userInfo " + userInfo);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- e.printStackTrace();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public void postSync(UserInfo userInfo) {
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public UserInfo buildUserInfo(ListUserResponse user) {
|
|
|
|
- UserInfo userInfo = new UserInfo();
|
|
|
|
-
|
|
|
|
- userInfo.setUsername(user.getUserid());//鐧诲綍鍚�
|
|
|
|
- userInfo.setNickName(user.getName());//鐢ㄦ埛鍚�
|
|
|
|
- userInfo.setDisplayName(user.getName());//鐢ㄦ埛鍚�
|
|
|
|
- userInfo.setFormattedName(user.getName());//鐢ㄦ埛鍚�
|
|
|
|
-
|
|
|
|
- userInfo.setEmail(user.getEmail());
|
|
|
|
- userInfo.setEntryDate(new DateTime(user.getHiredDate()).toString(DateTimeFormat.forPattern("yyyy-MM-dd")));
|
|
|
|
- userInfo.setMobile(user.getMobile());//鎵嬫満
|
|
|
|
- userInfo.setDepartmentId(user.getDeptIdList().get(0)+"");
|
|
|
|
- userInfo.setJobTitle(user.getTitle());//鑱屽姟
|
|
|
|
- userInfo.setWorkEmail(user.getOrgEmail());//宸ヤ綔閭欢
|
|
|
|
- userInfo.setWorkPhoneNumber(user.getTelephone());//鍏徃鐢佃瘽
|
|
|
|
- userInfo.setWorkOfficeName(user.getWorkPlace());//鍔炲叕瀹�
|
|
|
|
- userInfo.setDescription(user.getRemark());//澶囨敞
|
|
|
|
-
|
|
|
|
- return userInfo;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public void setOrganizationService(DingdingOrganizationService organizationService) {
|
|
|
|
- this.organizationService = organizationService;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public void setAccess_token(String access_token) {
|
|
|
|
- this.access_token = access_token;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public UserInfoService getUserInfoService() {
|
|
|
|
- return userInfoService;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public void setUserInfoService(UserInfoService userInfoService) {
|
|
|
|
- this.userInfoService = userInfoService;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public DingdingOrganizationService getOrganizationService() {
|
|
|
|
- return organizationService;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public void setSynchronizer(Synchronizers Synchronizer) {
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+public class DingdingUsersService implements ISynchronizerService
|
|
|
|
+{
|
|
|
|
+ final static Logger _logger = LoggerFactory.getLogger(DingdingUsersService.class);
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ DingdingOrganizationService organizationService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ UserInfoService userInfoService;
|
|
|
|
+
|
|
|
|
+ String access_token;
|
|
|
|
+
|
|
|
|
+ public void sync()
|
|
|
|
+ {
|
|
|
|
+ _logger.info("Sync Users...");
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+
|
|
|
|
+ OapiV2DepartmentListsubResponse rspDepts = organizationService.getRspDepts();
|
|
|
|
+ for (DeptBaseResponse dept : rspDepts.getResult())
|
|
|
|
+ {
|
|
|
|
+ DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/user/list");
|
|
|
|
+ OapiV2UserListRequest req = new OapiV2UserListRequest();
|
|
|
|
+ req.setDeptId(dept.getDeptId());
|
|
|
|
+ req.setCursor(0L);
|
|
|
|
+ req.setSize(100L);
|
|
|
|
+ req.setOrderField("modify_desc");
|
|
|
|
+ req.setContainAccessLimit(true);
|
|
|
|
+ req.setLanguage("zh_CN");
|
|
|
|
+ OapiV2UserListResponse rsp = client.execute(req, access_token);
|
|
|
|
+ _logger.info("response : " + rsp.getBody());
|
|
|
|
+
|
|
|
|
+ if (rsp.getErrcode() == 0)
|
|
|
|
+ {
|
|
|
|
+ for (ListUserResponse user : rsp.getResult().getList())
|
|
|
|
+ {
|
|
|
|
+ _logger.info("name : " + user.getName() + " , " + user.getLoginId() + " , " + user.getUserid());
|
|
|
|
+ UserInfo userInfo = buildUserInfo(user);
|
|
|
|
+ // 同步人员
|
|
|
|
+ userInfo.setPassword("123456");
|
|
|
|
+ userInfo.setPasswordSetType(ConstantsPasswordSetType.PASSWORD_NORMAL);
|
|
|
|
+ userInfo.setStatus(1);
|
|
|
|
+ userInfo.setDepartmentId(dept.getDeptId().toString());
|
|
|
|
+ userInfo.setDepartment(dept.getName());
|
|
|
|
+ UserInfo loadUser = userInfoService.loadByUsername(userInfo.getUsername());
|
|
|
|
+ if (loadUser != null)
|
|
|
|
+ {
|
|
|
|
+ userInfoService.update(userInfo);
|
|
|
|
+ } else
|
|
|
|
+ {
|
|
|
|
+ userInfoService.insert(userInfo);
|
|
|
|
+ }
|
|
|
|
+ _logger.info("userInfo " + userInfo);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ } catch (Exception e)
|
|
|
|
+ {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void postSync(UserInfo userInfo)
|
|
|
|
+ {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public UserInfo buildUserInfo(ListUserResponse user)
|
|
|
|
+ {
|
|
|
|
+ UserInfo userInfo = new UserInfo();
|
|
|
|
+
|
|
|
|
+ userInfo.setUsername(user.getUserid());//鐧诲綍鍚�
|
|
|
|
+ userInfo.setNickName(user.getName());//鐢ㄦ埛鍚�
|
|
|
|
+ userInfo.setDisplayName(user.getName());//鐢ㄦ埛鍚�
|
|
|
|
+ userInfo.setFormattedName(user.getName());//鐢ㄦ埛鍚�
|
|
|
|
+
|
|
|
|
+ userInfo.setEmail(user.getEmail());
|
|
|
|
+ userInfo.setEntryDate(new DateTime(user.getHiredDate()).toString(DateTimeFormat.forPattern("yyyy-MM-dd")));
|
|
|
|
+ userInfo.setMobile(user.getMobile());//鎵嬫満
|
|
|
|
+ userInfo.setDepartmentId(user.getDeptIdList().get(0) + "");
|
|
|
|
+ userInfo.setJobTitle(user.getTitle());//鑱屽姟
|
|
|
|
+ userInfo.setWorkEmail(user.getOrgEmail());//宸ヤ綔閭欢
|
|
|
|
+ userInfo.setWorkPhoneNumber(user.getTelephone());//鍏徃鐢佃瘽
|
|
|
|
+ userInfo.setWorkOfficeName(user.getWorkPlace());//鍔炲叕瀹�
|
|
|
|
+ userInfo.setDescription(user.getRemark());//澶囨敞
|
|
|
|
+
|
|
|
|
+ return userInfo;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void setOrganizationService(DingdingOrganizationService organizationService)
|
|
|
|
+ {
|
|
|
|
+ this.organizationService = organizationService;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void setAccess_token(String access_token)
|
|
|
|
+ {
|
|
|
|
+ this.access_token = access_token;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public UserInfoService getUserInfoService()
|
|
|
|
+ {
|
|
|
|
+ return userInfoService;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void setUserInfoService(UserInfoService userInfoService)
|
|
|
|
+ {
|
|
|
|
+ this.userInfoService = userInfoService;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public DingdingOrganizationService getOrganizationService()
|
|
|
|
+ {
|
|
|
|
+ return organizationService;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void setSynchronizer(Synchronizers Synchronizer)
|
|
|
|
+ {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|