| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.time.LocalDateTime; |
| | | import java.util.ArrayList; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | import java.util.*; |
| | | |
| | | |
| | | @Slf4j |
| | |
| | | @Autowired |
| | | private UmsAdminRoleRelationService umsAdminRoleRelationService; |
| | | |
| | | //@Scheduled(cron = "0 50 14 * * ?") |
| | | @Scheduled(cron = "40 50 16 * * ?") |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void run() { |
| | | log.info("开始同步任务"); |
| | |
| | | /** |
| | | // * 根据组织code 查询 通讯录人员信息 |
| | | // */ |
| | | Set<DingUserInfo> dingList = dingCommon.getPersonInfoByOrgCode(); |
| | | //查询所有用户 |
| | | List<UmsAdmin> userList = umsAdminService.list(); |
| | | //查询用户组织关联表 |
| | | List<UmsDepartManage> empOrgList = departManageService.list(); |
| | | Iterator<DingUserInfo> iterator = dingList.iterator(); |
| | | //查询所有用户 |
| | | Set<DingUserInfo> dingList = dingCommon.getPersonInfoByOrgCode(); |
| | | Set<DingUserInfo> dingUsers = new HashSet<>(dingList); |
| | | log.info("dinglistStart----->{}",dingList); |
| | | List<UmsAdmin> userList = umsAdminService.list(); |
| | | Iterator<DingUserInfo> iterator = dingUsers.iterator(); |
| | | while (iterator.hasNext()) { |
| | | DingUserInfo dingUserInfo = iterator.next(); |
| | | //判断用户是否存在,输出新用户 |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | log.info("dinglistEnd----->{}",dingUsers); |
| | | ArrayList<UmsAdminRoleRelation> relations = new ArrayList<>(); |
| | | // log.info(TAG + " elapsed time:" + timer.interval()); |
| | | for (DingUserInfo dingUserInfo : dingList) { |
| | | for (DingUserInfo dingUserInfo : dingUsers) { |
| | | //1.添加用户 |
| | | UmsAdmin user = new UmsAdmin(); |
| | | //账号 |
| | |
| | | user.setNickName(dingUserInfo.getEmployeeName()); |
| | | } |
| | | //code |
| | | //accountId |
| | | log.info("员工账户id{}",dingUserInfo.getAccountId()); |
| | | user.setAccountId(dingUserInfo.getAccountId()); |
| | | //头像 |
| | | user.setIcon(dingUserInfo.getGovEmpAvatar()); |
| | | //姓名 |
| | |
| | | //状态为停用(不可用状态)点击登录后才能使用 |
| | | user.setStatus(1); |
| | | umsAdminService.save(user); |
| | | //员工信息,关联组织 |
| | | UmsDepartManage departManage = new UmsDepartManage(); |
| | | departManage.setDepartId(dingUserInfo.getOrgId()); |
| | | departManage.setIsLeader(0); |
| | | departManage.setUserId(dingUserInfo.getUserId()); |
| | | departManageService.saveOrUpdate(departManage); |
| | | //角色信息 |
| | | List<String> roleCode = dingUserInfo.getRoleCodeList(); |
| | | if (CollectionUtils.isNotEmpty(roleCode)) { |
| | | List<UmsRole> roleList = roleService.getRoleListByCodes(roleCode); |
| | | roleList.forEach(item -> { |
| | | UmsAdminRoleRelation relation = new UmsAdminRoleRelation(); |
| | | relation.setAdminId(dingUserInfo.getUserId()); |
| | | relation.setRoleId(item.getId()); |
| | | relations.add(relation); |
| | | }); |
| | | } |
| | | } |
| | | if (CollUtil.isNotEmpty(relations)) { |
| | | umsAdminRoleRelationService.saveBatch(relations, IService.DEFAULT_BATCH_SIZE); |
| | | // //员工信息,关联组织 |
| | | // UmsDepartManage departManage = new UmsDepartManage(); |
| | | // departManage.setDepartId(dingUserInfo.getOrgId()); |
| | | // departManage.setIsLeader(0); |
| | | // departManage.setUserId(dingUserInfo.getUserId()); |
| | | // departManageService.saveOrUpdate(departManage); |
| | | // //角色信息 |
| | | // List<String> roleCode = dingUserInfo.getRoleCodeList(); |
| | | // if (CollectionUtils.isNotEmpty(roleCode)) { |
| | | // List<UmsRole> roleList = roleService.getRoleListByCodes(roleCode); |
| | | // roleList.forEach(item -> { |
| | | // UmsAdminRoleRelation relation = new UmsAdminRoleRelation(); |
| | | // relation.setAdminId(dingUserInfo.getUserId()); |
| | | // relation.setRoleId(item.getId()); |
| | | // relations.add(relation); |
| | | // }); |
| | | // } |
| | | // } |
| | | // if (CollUtil.isNotEmpty(relations)) { |
| | | // umsAdminRoleRelationService.saveBatch(relations, IService.DEFAULT_BATCH_SIZE); |
| | | } |
| | | log.info("同步任务结束"); |
| | | // log.info(TAG + "update user size " + dingList.size()); |