|
@@ -35,8 +35,6 @@ import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.http.*;
|
|
|
-import org.springframework.ldap.core.LdapTemplate;
|
|
|
-import org.springframework.ldap.filter.EqualsFilter;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
@@ -45,17 +43,6 @@ import org.springframework.web.servlet.ModelAndView;
|
|
|
import org.springframework.web.servlet.view.RedirectView;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import javax.naming.Context;
|
|
|
-import javax.naming.NamingEnumeration;
|
|
|
-import javax.naming.NamingException;
|
|
|
-import javax.naming.directory.Attribute;
|
|
|
-import javax.naming.directory.Attributes;
|
|
|
-import javax.naming.directory.SearchControls;
|
|
|
-import javax.naming.directory.SearchResult;
|
|
|
-import javax.naming.ldap.Control;
|
|
|
-import javax.naming.ldap.InitialLdapContext;
|
|
|
-import javax.naming.ldap.LdapContext;
|
|
|
-import javax.naming.ldap.SortControl;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import java.io.*;
|
|
|
import java.math.BigDecimal;
|
|
@@ -89,16 +76,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
private String corpId;
|
|
|
@Value("${providerSecret}")
|
|
|
private String providerSecret;
|
|
|
- @Value("${spring.ldap.urls}")
|
|
|
- private String ldapUrl;
|
|
|
- @Value("${spring.ldap.username}")
|
|
|
- private String userName;
|
|
|
- @Value("${spring.ldap.password}")
|
|
|
- private String passWord;
|
|
|
- @Value("${spring.ldap.base.dcFirst}")
|
|
|
- private String dcFirst;
|
|
|
- @Value("${spring.ldap.base.dcSecond}")
|
|
|
- private String dcSecond;
|
|
|
+
|
|
|
@Value("${configEnv.isPrivateDeploy}")
|
|
|
private boolean isPrivateDeploy;
|
|
|
|
|
@@ -107,8 +85,6 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
public SFTPAsyncUploader sftpAsyncUploader;
|
|
|
|
|
|
public static final String GET_TOKEN_URL = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=APPID&secret=SECRET&code=CODE&grant_type=authorization_code";
|
|
|
- public static final String GET_USERINFO_URL = "https://api.weixin.qq.com/sns/userinfo?access_token=accessToken&openid=openId&lang=zh_CN";
|
|
|
- public static final String[] MATCHING_FILED = {"corpwx_userid","phone","job_number"};
|
|
|
|
|
|
//用于控制线程锁
|
|
|
public static HashMap<String, CorpwxJobResult> corpwxJobCenter = new HashMap();
|
|
@@ -179,8 +155,6 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
private TaskGroupMapper taskGroupMapper;
|
|
|
@Resource
|
|
|
private WxCorpInfoMapper wxCorpInfoMapper;
|
|
|
-// @Resource
|
|
|
-// private CompanyDingdingService companyDingdingService;
|
|
|
@Resource
|
|
|
private WxCorpInfoService wxCorpInfoService;
|
|
|
@Resource
|
|
@@ -196,14 +170,10 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
@Resource
|
|
|
private ThirdPartyInterfaceMapper thirdPartyInterfaceMapper;
|
|
|
@Resource
|
|
|
- SysConfigMapper sysConfigMapper;
|
|
|
- @Resource
|
|
|
private ReportFormMapper reportFormMapper;
|
|
|
@Resource
|
|
|
private ProjectAuditorService projectAuditorService;
|
|
|
@Resource
|
|
|
- private TaskService taskService;
|
|
|
- @Resource
|
|
|
private TaskCommentMapper taskCommentMapper;
|
|
|
@Resource
|
|
|
private TaskCommentService taskCommentService;
|
|
@@ -219,21 +189,8 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
private SysFormService sysFormService;
|
|
|
@Resource
|
|
|
private StageService stageService;
|
|
|
-
|
|
|
- @Resource
|
|
|
- private CompanyDingdingMapper companyDingdingMapper;
|
|
|
-
|
|
|
- @Resource
|
|
|
- private LdapTemplate ldapTemplate;
|
|
|
-
|
|
|
- public static String provider_access_token = null;
|
|
|
- public static long providerTokenExpireTime = 0L;
|
|
|
- @Resource
|
|
|
- private SysDictMapper sysDictMapper;
|
|
|
-
|
|
|
@Resource
|
|
|
private SysDictService sysDictService;
|
|
|
-
|
|
|
@Resource
|
|
|
private SuperSonicConfig superSonicConfig;
|
|
|
|
|
@@ -3323,474 +3280,4 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
return httpRespMsg;
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public boolean ldapAuth(String username, String passWord) {
|
|
|
- EqualsFilter filter = new EqualsFilter("sAMAccountName",username);
|
|
|
- return ldapTemplate.authenticate("",filter.toString(),passWord);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<JSONObject> ldapGetOU() throws NamingException {
|
|
|
- LdapContext ldapContext = adLogin();
|
|
|
- HttpRespMsg httpRespMsg=new HttpRespMsg();
|
|
|
- //域部门节点
|
|
|
- String searchBase = "OU=my,DC="+dcFirst+",DC="+dcSecond;
|
|
|
- //String searchBase = "OU=my(组织架构名称),DC=test,DC=com";
|
|
|
- //搜索条件
|
|
|
- String searchFilter = "objectclass=organizationalUnit";
|
|
|
- //String searchFilter = "(&(objectclass=organizationalUnit)(|(name=名称1)(name=名称2)))"; //查询部门,并且部门名称等于名称1或者名称2
|
|
|
- // 创建搜索控制器
|
|
|
- SearchControls searchCtls = new SearchControls();
|
|
|
- String[] returnedAttrs={"ou", "name","canonicalName","distinguishedName","objectGUID", "objectCategory"};
|
|
|
- searchCtls.setReturningAttributes(returnedAttrs); //设置指定返回的字段,不设置则返回全部
|
|
|
- // 设置搜索范围 深度
|
|
|
- searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE);
|
|
|
- //查询结果
|
|
|
- NamingEnumeration answer = ldapContext.search(searchBase, searchFilter,searchCtls);
|
|
|
-
|
|
|
- List<JSONObject> jsonObjectList = new ArrayList<>();
|
|
|
-
|
|
|
- while (answer.hasMoreElements()){
|
|
|
- SearchResult searchResult = (SearchResult) answer.next();
|
|
|
- Attributes attributes = searchResult.getAttributes();
|
|
|
- if(attributes != null){
|
|
|
- JSONObject jsonObject = new JSONObject();
|
|
|
- for(NamingEnumeration ne = attributes.getAll(); ne.hasMore();){
|
|
|
- Attribute attribute = (Attribute) ne.next();
|
|
|
- for (NamingEnumeration e = attribute.getAll(); e.hasMore();) {
|
|
|
- if("objectGUID".equals(attribute.getID())){
|
|
|
- String guid =this.getObjectGUID((byte[]) e.next());
|
|
|
- jsonObject.put(attribute.getID(), guid);
|
|
|
- }else {
|
|
|
- jsonObject.put(attribute.getID(), e.next().toString());
|
|
|
- }
|
|
|
- if(!jsonObjectList.stream().anyMatch(jl->jl.getString("objectGUID").equals(jsonObject.getString("objectGUID")))){
|
|
|
- jsonObjectList.add(jsonObject);
|
|
|
- }
|
|
|
-// jsonObjectList.add(jsonObject);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- return jsonObjectList;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<JSONObject> getUser() throws Exception{
|
|
|
- HttpRespMsg httpRespMsg=new HttpRespMsg();
|
|
|
- LdapContext ldapContext = this.adLogin();
|
|
|
- String searchFilter = "objectclass=User";
|
|
|
- String searchBase = "DC="+dcFirst+",DC="+dcSecond;
|
|
|
- // 创建搜索控制器
|
|
|
- SearchControls searchCtls = new SearchControls();
|
|
|
- String[] returnedAttrs={"givenName","name","distinguishedName","userAccountControl","objectGUID", "objectCategory", "logonCount","sAMAccountName","userPrincipalName"};
|
|
|
- searchCtls.setReturningAttributes(returnedAttrs); //设置指定返回的字段,不设置则返回全部
|
|
|
- // 设置搜索范围 深度
|
|
|
- searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE);
|
|
|
- //查询结果
|
|
|
- NamingEnumeration answer = ldapContext.search(searchBase, searchFilter,searchCtls);
|
|
|
-
|
|
|
- List<JSONObject> jsonObjectList = new ArrayList<>();
|
|
|
-
|
|
|
- while (answer.hasMoreElements()){
|
|
|
- SearchResult searchResult = (SearchResult) answer.next();
|
|
|
- Attributes attributes = searchResult.getAttributes();
|
|
|
-
|
|
|
- if(attributes != null){
|
|
|
- JSONObject jsonObject = new JSONObject();
|
|
|
- for(NamingEnumeration ne = attributes.getAll(); ne.hasMore();){
|
|
|
- Attribute attribute = (Attribute) ne.next();
|
|
|
- for (NamingEnumeration e = attribute.getAll(); e.hasMore();) {
|
|
|
- if("objectGUID".equals(attribute.getID())){
|
|
|
- String guid =this.getObjectGUID((byte[]) e.next());
|
|
|
- jsonObject.put(attribute.getID(), guid);
|
|
|
- }else {
|
|
|
- jsonObject.put(attribute.getID(), e.next().toString());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if(!jsonObjectList.stream().anyMatch(jl->jl.getString("objectGUID").equals(jsonObject.getString("objectGUID")))){
|
|
|
- jsonObjectList.add(jsonObject);
|
|
|
- }
|
|
|
-// jsonObjectList.add(jsonObject);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- return jsonObjectList;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public HttpRespMsg initSystemForAd(String companyName) throws Exception {
|
|
|
- HttpRespMsg msg = new HttpRespMsg();
|
|
|
- Integer count = companyMapper.selectCount(new QueryWrapper<Company>().eq("company_name", companyName));
|
|
|
- if (count>0){
|
|
|
- msg.setError("当前公司名称已存在");
|
|
|
- return msg;
|
|
|
- }
|
|
|
- Company company = new Company().setCompanyName(companyName)
|
|
|
- .setExpirationDate(LocalDateTime.now().plusDays(36500));
|
|
|
- company.setPackageProject(0);
|
|
|
- companyMapper.insert(company);
|
|
|
- //生成工作时长
|
|
|
- TimeType timeType = new TimeType();
|
|
|
- timeType.setCompanyId(company.getId());
|
|
|
- timeType.setFinanceJobnumEnabled(1);//启用工号来导入财务匹配
|
|
|
- timeType.setProjectManDay(1);
|
|
|
- timeTypeMapper.insert(timeType);
|
|
|
- SysRole smanager = sysRoleService.generateDefaultRoles(company.getId());
|
|
|
- //创建企业负责人账号
|
|
|
- Long id = SnowFlake.nextId();
|
|
|
- User manager = new User()
|
|
|
- .setId(id.toString())
|
|
|
- .setRoleId(smanager.getId())
|
|
|
- .setRoleName(smanager.getRolename())
|
|
|
- .setName("sysadmin")
|
|
|
- .setPhone("sysadmin@"+dcFirst+"."+dcSecond)
|
|
|
- .setPassword(MD5Util.getPassword("000000"))
|
|
|
- .setColor(ColorUtil.randomColor())
|
|
|
- .setCompanyId(company.getId());
|
|
|
- userMapper.insert(manager);
|
|
|
- System.out.println("生成超级管理员:sysadmin");
|
|
|
- //生成项目的成本基线默认条目
|
|
|
- String[] array = Constant.DEFAULT_BASE_COST_ITEMS;
|
|
|
- for (String baseItem : array) {
|
|
|
- ProjectBasecostSetting setting = new ProjectBasecostSetting();
|
|
|
- setting.setName(baseItem);
|
|
|
- setting.setCompanyId(company.getId());
|
|
|
- projectBasecostSettingMapper.insert(setting);
|
|
|
- }
|
|
|
- //生成费用报销默认条目
|
|
|
- String[] expenseTypes = Constant.EXPENSE_TYPES;
|
|
|
- List<String> commonly = new ArrayList<>();
|
|
|
- commonly.add("材料费");
|
|
|
- //commonly.add(MessageUtils.message("entry.materialCost"));
|
|
|
- commonly.add("办公用品");
|
|
|
- //commonly.add(MessageUtils.message("entry.workCost"));
|
|
|
- commonly.add("培训费");
|
|
|
- //commonly.add(MessageUtils.message("entry.trainCost"));
|
|
|
- commonly.add("打印费");
|
|
|
- //commonly.add(MessageUtils.message("entry.printCost"));
|
|
|
- commonly.add("快递费");
|
|
|
- //commonly.add(MessageUtils.message("entry.expressCost"));
|
|
|
- commonly.add("制作费");
|
|
|
- //commonly.add(MessageUtils.message("entry.makeCost"));
|
|
|
- commonly.add("律师费");
|
|
|
- //commonly.add(MessageUtils.message("entry.lawyerCost"));
|
|
|
- commonly.add("水费");
|
|
|
- //commonly.add(MessageUtils.message("entry.waterCost"));
|
|
|
- commonly.add("电费");
|
|
|
- //commonly.add(MessageUtils.message("entry.electricCost"));
|
|
|
- commonly.add("团建费");
|
|
|
- //commonly.add(MessageUtils.message("entry.leagueCost"));
|
|
|
- commonly.add("其他");
|
|
|
- //commonly.add(MessageUtils.message("entry.other"));
|
|
|
- List<String> travel = new ArrayList<>();
|
|
|
- travel.add("城市间交通费");
|
|
|
- //travel.add(MessageUtils.message("entry.cityTrafficCost"));
|
|
|
- travel.add("住宿费");
|
|
|
- //travel.add(MessageUtils.message("entry.liveCost"));
|
|
|
- travel.add("伙食补助费");
|
|
|
- //travel.add(MessageUtils.message("entry.eatCost"));
|
|
|
- travel.add("市内交通费");
|
|
|
- //travel.add(MessageUtils.message("entry.insideCityCost"));
|
|
|
- travel.add("其他差旅费");
|
|
|
- //travel.add(MessageUtils.message("entry.otherLiveTraCost"));
|
|
|
- List<String> outsource = new ArrayList<>();
|
|
|
- outsource.add("项目外包费");
|
|
|
- //outsource.add(MessageUtils.message("entry.projectCost"));
|
|
|
- outsource.add("劳务外包费");
|
|
|
- //outsource.add(MessageUtils.message("entry.labourCost"));
|
|
|
- outsource.add("其他外包费");
|
|
|
- //outsource.add(MessageUtils.message("entry.OtherOutsourceCost"));
|
|
|
- List<ExpenseType> expenseTypeList=new ArrayList<>();
|
|
|
- List<ExpenseMainType> expenseMainTypes=new ArrayList<>();
|
|
|
- ExpenseMainType expenseMainType=new ExpenseMainType();
|
|
|
- expenseMainType.setName("一般费用");
|
|
|
- expenseMainType.setCompanyId(company.getId());
|
|
|
- ExpenseMainType expenseMainType1=new ExpenseMainType();
|
|
|
- expenseMainType1.setName("差旅费用");
|
|
|
- expenseMainType1.setCompanyId(company.getId());
|
|
|
- ExpenseMainType expenseMainType2=new ExpenseMainType();
|
|
|
- expenseMainType2.setName("外包费用");
|
|
|
- expenseMainType2.setCompanyId(company.getId());
|
|
|
- expenseMainTypes.add(expenseMainType);
|
|
|
- expenseMainTypes.add(expenseMainType1);
|
|
|
- expenseMainTypes.add(expenseMainType2);
|
|
|
- expenseMainTypeService.saveBatch(expenseMainTypes);
|
|
|
- for (String expenseType : expenseTypes) {
|
|
|
- ExpenseType item=new ExpenseType();
|
|
|
- item.setCompanyId(company.getId());
|
|
|
- item.setTypeName(expenseType);
|
|
|
- if(commonly.contains(expenseType)){
|
|
|
- item.setMainType(expenseMainType.getId());
|
|
|
- }
|
|
|
- if(travel.contains(expenseType)){
|
|
|
- item.setMainType(expenseMainType1.getId());
|
|
|
- }
|
|
|
- if(outsource.contains(expenseType)){
|
|
|
- item.setMainType(expenseMainType2.getId());
|
|
|
- }
|
|
|
- expenseTypeList.add(item);
|
|
|
- }
|
|
|
- expenseTypeService.saveBatch(expenseTypeList);
|
|
|
- //todo: 生成初始测试项目及任务
|
|
|
- Project project=new Project();
|
|
|
- project.setCompanyId(company.getId());
|
|
|
- project.setInchargerId(manager.getId());
|
|
|
- project.setInchargerName(manager.getName());
|
|
|
- project.setCreatorId(manager.getId());
|
|
|
- project.setCreatorName(manager.getName());
|
|
|
- project.setCreateDate(LocalDate.now());
|
|
|
- project.setProjectCode("example");
|
|
|
- project.setProjectName("示例项目");
|
|
|
- //设置为公共项目,这样测试的用户都能填报
|
|
|
- project.setIsPublic(1);
|
|
|
- projectMapper.insert(project);
|
|
|
- //todo: 生成初始项目相关日报审核人
|
|
|
- ProjectAuditor projectAuditor=new ProjectAuditor();
|
|
|
- projectAuditor.setAuditorId(manager.getId());
|
|
|
- projectAuditor.setAuditorName(manager.getName());
|
|
|
- projectAuditor.setProjectId(project.getId());
|
|
|
- projectAuditorMapper.insert(projectAuditor);
|
|
|
- //todo: 生成项目报表服务默认条目
|
|
|
- Integer[] arrayInteger = new Integer[]{1, 2, 3, 4, 7};
|
|
|
- for (Integer integerItem : arrayInteger) {
|
|
|
- CompanyReport companyReport = new CompanyReport();
|
|
|
- companyReport.setCompanyId(company.getId());
|
|
|
- companyReport.setReportFormId(integerItem);
|
|
|
- companyReportMapper.insert(companyReport);
|
|
|
- }
|
|
|
- //todo: 生成初始项目相关示例任务分组/任务阶段以及示例任务
|
|
|
- TaskGroup taskGroup = new TaskGroup();
|
|
|
- taskGroup.setProjectId(project.getId())
|
|
|
- .setInchargerId(manager.getId())
|
|
|
- .setName("项目阶段");
|
|
|
- taskGroupMapper.insert(taskGroup);
|
|
|
- Stages stage = new Stages();
|
|
|
- stage.setGroupId(taskGroup.getId());
|
|
|
- stage.setSequence(1);
|
|
|
- stage.setProjectId(project.getId());
|
|
|
- stage.setStagesName("工作开展");
|
|
|
- stagesMapper.insert(stage);
|
|
|
- Task task=new Task();
|
|
|
-// Integer oneDayHours = 8;
|
|
|
-// task.setCreateDate(LocalDate.now());
|
|
|
-// task.setProjectId(project.getId());
|
|
|
-// task.setCompanyId(company.getId());
|
|
|
-// task.setCreaterId(manager.getId());
|
|
|
-// task.setCreaterName(manager.getName());
|
|
|
-// task.setCreatorColor(manager.getColor());
|
|
|
-// task.setExecutorId(manager.getId());
|
|
|
-// task.setExecutorColor(manager.getColor());
|
|
|
-// task.setExecutorName(manager.getName());
|
|
|
-// task.setPlanHours(oneDayHours);
|
|
|
-// task.setStagesId(stage.getId());
|
|
|
-// task.setGroupId(taskGroup.getId());
|
|
|
-// task.setSeq(0);
|
|
|
-// task.setName("示例任务");
|
|
|
- taskMapper.insert(task);
|
|
|
- //任务执行人表也要插入,不然会导致编辑任务的时候执行人为空
|
|
|
- TaskExecutor executor = new TaskExecutor();
|
|
|
- executor.setTaskId(task.getId());
|
|
|
-// executor.setPlanHours(oneDayHours);
|
|
|
- executor.setProjectId(project.getId());
|
|
|
- executor.setExecutorId(manager.getId());
|
|
|
- executor.setExecutorColor(manager.getColor());
|
|
|
- executor.setExecutorName(manager.getName());
|
|
|
- taskExecutorMapper.insert(executor);
|
|
|
- SysRole role = sysRoleMapper.selectOne(new QueryWrapper<SysRole>().eq("company_id", company.getId()).eq("rolename","普通员工"));
|
|
|
- List<JSONObject> deptArrays = ldapGetOU();
|
|
|
- for (JSONObject dept : deptArrays) {
|
|
|
- Department department=new Department();
|
|
|
- department.setDepartmentName(dept.getString("name"))
|
|
|
- .setCompanyId(company.getId());
|
|
|
- departmentMapper.insert(department);
|
|
|
- }
|
|
|
- List<Department> departmentList = departmentMapper.selectList(new QueryWrapper<Department>().eq("company_id", company.getId()));
|
|
|
- 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", company.getId()));
|
|
|
- if(one!=null&&Optional.of(one).isPresent()){
|
|
|
- first.get().setSuperiorId(one.getDepartmentId());
|
|
|
- }
|
|
|
- }
|
|
|
- departmentMapper.updateById(first.get());
|
|
|
- }
|
|
|
- }
|
|
|
- List<JSONObject> userArrays = getUser();
|
|
|
- Integer[] ints = {514, 546, 66050, 66080, 66082};
|
|
|
- List<Integer> disable = Arrays.asList(ints);
|
|
|
- for (JSONObject user : userArrays) {
|
|
|
- if(disable.contains(user.getIntValue("userAccountControl"))){
|
|
|
- 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(company.getId())
|
|
|
- .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", company.getId()));
|
|
|
- if(one!=null){
|
|
|
- u.setDepartmentId(one.getDepartmentId()).setDepartmentName(one.getDepartmentName()).setDepartmentCascade(convertDepartmentIdToCascade(one.getDepartmentId(),departmentList));
|
|
|
- }
|
|
|
- }
|
|
|
- userMapper.insert(u);
|
|
|
- }
|
|
|
- return msg;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public HttpRespMsg syncDeptWithAD(HttpServletRequest request) throws Exception {
|
|
|
- Integer companyId = userMapper.selectById(request.getHeader("token")).getCompanyId();
|
|
|
- SysRole role = sysRoleMapper.selectOne(new QueryWrapper<SysRole>().eq("company_id",companyId).eq("rolename","普通员工"));
|
|
|
- List<Department> departmentList = departmentMapper.selectList(new QueryWrapper<Department>().eq("company_id",companyId));
|
|
|
- List<User> userList = userMapper.selectList(new QueryWrapper<User>().eq("company_id", companyId));
|
|
|
- List<JSONObject> deptArrays = ldapGetOU();
|
|
|
- for (JSONObject dept : deptArrays) {
|
|
|
- if(departmentList.stream().anyMatch(dl->dl.getDepartmentName().equals(dept.getString("name")))){
|
|
|
- continue;
|
|
|
- }
|
|
|
- Department department=new Department();
|
|
|
- department.setDepartmentName(dept.getString("name"))
|
|
|
- .setCompanyId(companyId);
|
|
|
- departmentMapper.insert(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 = 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()){
|
|
|
- optional.get().setIsActive(0);
|
|
|
- userMapper.updateById(optional.get());
|
|
|
- }
|
|
|
- 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(companyId)
|
|
|
- .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",companyId));
|
|
|
- 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);
|
|
|
- }
|
|
|
- }
|
|
|
- return new HttpRespMsg();
|
|
|
- }
|
|
|
- public LdapContext adLogin() {
|
|
|
-
|
|
|
- LdapContext ldapContext = null;
|
|
|
- Hashtable<String, Object> env = new Hashtable<String, Object>();
|
|
|
- env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
|
|
|
- //验证类型
|
|
|
- env.put(Context.SECURITY_AUTHENTICATION, "simple");
|
|
|
- //用户名称,cn,ou,dc 分别:用户,组,域
|
|
|
- env.put(Context.SECURITY_PRINCIPAL,userName);
|
|
|
- //用户密码 cn 的密码
|
|
|
- env.put(Context.SECURITY_CREDENTIALS,passWord);
|
|
|
- //url 格式:协议://ip:端口/组,域 ,直接连接到域或者组上面
|
|
|
- env.put(Context.PROVIDER_URL,ldapUrl);
|
|
|
-// //协议
|
|
|
-// env.put(Context.SECURITY_PROTOCOL, "ssl");
|
|
|
-// env.put("java.naming.ldap.factory.socket", "org.utils.ad.DummySSLSocketFactory");
|
|
|
- //objectGUID 转换,很关键
|
|
|
- env.put("java.naming.ldap.attributes.binary","objectGUID");
|
|
|
- try {
|
|
|
- Control[] sortConnCtls = new SortControl[1];
|
|
|
- sortConnCtls[0] = new SortControl("sAMAccountName", Control.CRITICAL);
|
|
|
- ldapContext = new InitialLdapContext(env, sortConnCtls);
|
|
|
- } catch (IOException | NamingException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- return ldapContext;
|
|
|
- }
|
|
|
-
|
|
|
- private String getObjectGUID(byte[] GUID){
|
|
|
- String strGUID = "";
|
|
|
- String byteGUID = "";
|
|
|
- for (int c=0;c<GUID.length;c++) {
|
|
|
- byteGUID = byteGUID + "\\" + AddLeadingZero((int)GUID[c] & 0xFF);
|
|
|
- }
|
|
|
- strGUID = strGUID + AddLeadingZero((int)GUID[3] & 0xFF);
|
|
|
- strGUID = strGUID + AddLeadingZero((int)GUID[2] & 0xFF);
|
|
|
- strGUID = strGUID + AddLeadingZero((int)GUID[1] & 0xFF);
|
|
|
- strGUID = strGUID + AddLeadingZero((int)GUID[0] & 0xFF);
|
|
|
- strGUID = strGUID + "-";
|
|
|
- strGUID = strGUID + AddLeadingZero((int)GUID[5] & 0xFF);
|
|
|
- strGUID = strGUID + AddLeadingZero((int)GUID[4] & 0xFF);
|
|
|
- strGUID = strGUID + "-";
|
|
|
- strGUID = strGUID + AddLeadingZero((int)GUID[7] & 0xFF);
|
|
|
- strGUID = strGUID + AddLeadingZero((int)GUID[6] & 0xFF);
|
|
|
- strGUID = strGUID + "-";
|
|
|
- strGUID = strGUID + AddLeadingZero((int)GUID[8] & 0xFF);
|
|
|
- strGUID = strGUID + AddLeadingZero((int)GUID[9] & 0xFF);
|
|
|
- strGUID = strGUID + "-";
|
|
|
- strGUID = strGUID + AddLeadingZero((int)GUID[10] & 0xFF);
|
|
|
- strGUID = strGUID + AddLeadingZero((int)GUID[11] & 0xFF);
|
|
|
- strGUID = strGUID + AddLeadingZero((int)GUID[12] & 0xFF);
|
|
|
- strGUID = strGUID + AddLeadingZero((int)GUID[13] & 0xFF);
|
|
|
- strGUID = strGUID + AddLeadingZero((int)GUID[14] & 0xFF);
|
|
|
- strGUID = strGUID + AddLeadingZero((int)GUID[15] & 0xFF);
|
|
|
- return strGUID;
|
|
|
- }
|
|
|
-
|
|
|
- private static String AddLeadingZero(int k) {
|
|
|
- return (k <= 0xF) ? "0" + Integer.toHexString(k) : Integer
|
|
|
- .toHexString(k);
|
|
|
- }
|
|
|
}
|