|
@@ -137,6 +137,10 @@ public class TimingTask {
|
|
|
private TaskExecutorMapper taskExecutorMapper;
|
|
|
@Resource
|
|
|
private TimeTypeService timeTypeService;
|
|
|
+ @Resource
|
|
|
+ private SysRoleMapper sysRoleMapper;
|
|
|
+ @Resource
|
|
|
+ private UserService userService;
|
|
|
|
|
|
private static final List<Integer> VALID_TOKEN_CHARS = new ArrayList<>();
|
|
|
static {
|
|
@@ -592,6 +596,112 @@ public class TimingTask {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ @Scheduled(cron = "0 10 1 ? * *")
|
|
|
+ private void synAd() throws Exception {
|
|
|
+ if (isDev) return;
|
|
|
+ if(!isPrivateDeploy) return;
|
|
|
+ List<TimeType> timeTypeList = timeTypeMapper.selectList(new QueryWrapper<TimeType>().eq("sync_ad", 1));
|
|
|
+ List<Integer> compIds = timeTypeList.stream().map(TimeType::getCompanyId).collect(Collectors.toList());
|
|
|
+ if(compIds.isEmpty()){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ for (Integer compId : compIds) {
|
|
|
+ SysRole role = sysRoleMapper.selectOne(new QueryWrapper<SysRole>().eq("company_id",compId).eq("rolename","普通员工"));
|
|
|
+ List<Department> departmentList = departmentMapper.selectList(new QueryWrapper<Department>().eq("company_id", compId));
|
|
|
+ List<User> userList = userMapper.selectList(new QueryWrapper<User>().eq("company_id", compId));
|
|
|
+// List<JSONObject> deptArrays = userService.ldapGetOU();
|
|
|
+// for (JSONObject dept : deptArrays) {
|
|
|
+// Department department=new Department();
|
|
|
+// department.setDepartmentName(dept.getString("name"))
|
|
|
+// .setCompanyId(companyId);
|
|
|
+// departmentMapper.insert(department);
|
|
|
+// }
|
|
|
+// List<Department> departmentList = departmentMapper.selectList(new QueryWrapper<Department>().eq("company_id",companyId));
|
|
|
+// for (JSONObject deptArray : deptArrays) {
|
|
|
+// String canonicalName = deptArray.getString("canonicalName");
|
|
|
+// Optional<Department> first = departmentList.stream().filter(dl -> dl.getDepartmentName().equals(deptArray.getString("name"))).findFirst();
|
|
|
+// if(first.isPresent()){
|
|
|
+// String[] split = canonicalName.split("/");
|
|
|
+// if(split.length>2){
|
|
|
+// String s = split[split.length - 2];
|
|
|
+// Department one = departmentMapper.selectOne(new QueryWrapper<Department>().eq("department_name", s).eq("company_id",companyId));
|
|
|
+// if(one!=null&&Optional.of(one).isPresent()){
|
|
|
+// first.get().setSuperiorId(one.getDepartmentId());
|
|
|
+// }
|
|
|
+// }
|
|
|
+// departmentMapper.updateById(first.get());
|
|
|
+// }
|
|
|
+// }
|
|
|
+ List<JSONObject> userArrays = userService.getUser();
|
|
|
+ Integer[] ints = {514, 546, 66050, 66080, 66082};
|
|
|
+ List<Integer> disable = Arrays.asList(ints);
|
|
|
+ for (JSONObject user : userArrays) {
|
|
|
+ if(disable.contains(user.getIntValue("userAccountControl"))){
|
|
|
+ List<User> users = userList.stream().filter(ul -> ul.getPhone() != null).collect(Collectors.toList());
|
|
|
+ Optional<User> optional = users.stream().filter(ul -> ul.getPhone() != null && ul.getPhone().equals(user.getString("userPrincipalName"))).findFirst();
|
|
|
+ if(optional.isPresent()){
|
|
|
+ userMapper.deleteById(optional.get().getId());
|
|
|
+ }
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if(!user.containsKey("userPrincipalName")){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ User u=new User();
|
|
|
+ u.setId(SnowFlake.nextId()+"")
|
|
|
+ .setName(user.getString("name"))
|
|
|
+ .setPhone(user.getString("userPrincipalName"))
|
|
|
+ .setId(SnowFlake.nextId()+"")
|
|
|
+ .setRoleId(role.getId())//默认普通员工
|
|
|
+ .setRoleName(role.getRolename())
|
|
|
+ .setCompanyId(compId)
|
|
|
+ .setColor(ColorUtil.randomColor())
|
|
|
+ .setPassword(MD5Util.getPassword("000000"));
|
|
|
+ String distinguishedName = user.getString("distinguishedName");
|
|
|
+ String[] split = distinguishedName.split(",");
|
|
|
+ List<String> list = Arrays.asList(split);
|
|
|
+ List<String> collect = list.stream().filter(l -> l.contains("OU=")).collect(Collectors.toList());
|
|
|
+ if(collect.size()>0){
|
|
|
+ String s = collect.get(0).replaceAll("OU=", "");
|
|
|
+ Department one = departmentMapper.selectOne(new QueryWrapper<Department>().eq("department_name", s).eq("company_id",compId));
|
|
|
+ if(one!=null){
|
|
|
+ u.setDepartmentId(one.getDepartmentId()).setDepartmentName(one.getDepartmentName()).setDepartmentCascade(convertDepartmentIdToCascade(one.getDepartmentId(),departmentList));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<User> users = userList.stream().filter(ul -> ul.getPhone() != null).collect(Collectors.toList());
|
|
|
+ if(!users.stream().anyMatch(ul->ul.getPhone()!=null&&ul.getPhone().equals(u.getPhone()))){
|
|
|
+ userMapper.insert(u);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ OperationRecord operationRecord=new OperationRecord();
|
|
|
+ operationRecord.setCompanyId(compId)
|
|
|
+ .setContent("同步来自LDAP的AD域控组织架构")
|
|
|
+ .setOperationTime(LocalDateTime.now());
|
|
|
+ operationRecordService.save(operationRecord);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //将部门id转换为部门层级
|
|
|
+ private String convertDepartmentIdToCascade(Integer id, List<Department> allDeptList) {
|
|
|
+ StringBuilder cascade = new StringBuilder();
|
|
|
+ if (id == 0) {
|
|
|
+ cascade.append("0");
|
|
|
+ } else {
|
|
|
+ cascade.append(id);
|
|
|
+ id = findById(id, allDeptList).getSuperiorId();
|
|
|
+ while (id != null) {
|
|
|
+ cascade.append(",").append(id);
|
|
|
+ id = findById(id, allDeptList).getSuperiorId();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return cascade.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ private Department findById(int id, List<Department> allList) {
|
|
|
+ return allList.stream().filter(all->all.getDepartmentId().intValue() == id).findFirst().get();
|
|
|
+ }
|
|
|
+
|
|
|
private List<LocalDateTime> getDays(LocalDateTime start, LocalDateTime end) {
|
|
|
List<LocalDateTime> result = new ArrayList();
|
|
|
while (start.isBefore(end)) {
|