Merge branch 'dev'
This commit is contained in:
commit
8f6b530a0d
5
pom.xml
5
pom.xml
|
@ -195,7 +195,8 @@
|
|||
<repository>
|
||||
<id>public</id>
|
||||
<name>aliyun nexus</name>
|
||||
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
|
||||
<!-- <url>https://maven.aliyun.com/repository/central</url>-->
|
||||
<url>https://repo1.maven.org/maven2/</url>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
</releases>
|
||||
|
@ -205,7 +206,7 @@
|
|||
<pluginRepository>
|
||||
<id>public</id>
|
||||
<name>aliyun nexus</name>
|
||||
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
|
||||
<url>https://maven.aliyun.com/repository/central</url>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
</releases>
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
<properties>
|
||||
<quartz.version>2.3.0</quartz.version>
|
||||
<shiro.version>1.6.0</shiro.version>
|
||||
<shiro.version>1.10.0</shiro.version>
|
||||
<captcha.version>1.6.2</captcha.version>
|
||||
<easyexcel.version>2.2.6</easyexcel.version>
|
||||
<qiniu.version>7.2.27</qiniu.version>
|
||||
|
|
|
@ -1,9 +1,14 @@
|
|||
package io.renren.modules.gateway.controller;
|
||||
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.poi.excel.ExcelUtil;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.google.common.collect.Lists;
|
||||
import io.renren.common.utils.ExcelUtils;
|
||||
import io.renren.common.utils.JhlDAPTool;
|
||||
import io.renren.modules.gateway.dao.ApiCountHistoryDao;
|
||||
import io.renren.modules.gateway.entity.ApiCountHistoryEntity;
|
||||
import io.renren.modules.gateway.service.MonitorServiceV2;
|
||||
|
@ -17,8 +22,11 @@ import io.renren.modules.resource.entity.AttrEntity;
|
|||
import io.renren.modules.resource.entity.ResourceEntity;
|
||||
import io.renren.modules.sys.dao.SysDeptDao;
|
||||
import io.renren.modules.sys.entity.SysDeptEntity;
|
||||
import io.renren.modules.sys.enums.JhDeptEnum;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -28,7 +36,14 @@ import org.springframework.web.bind.annotation.GetMapping;
|
|||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.directory.SearchResult;
|
||||
import javax.naming.ldap.LdapContext;
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
|
@ -66,6 +81,9 @@ public class MonitorControllerV2 {
|
|||
@Autowired
|
||||
private ApiCountHistoryDao apiCountHistoryDao;
|
||||
|
||||
@Autowired
|
||||
private JhlDAPTool jhlDAPTool;
|
||||
|
||||
@Autowired
|
||||
private SysNoticeServiceImpl sysNoticeService;
|
||||
@Autowired
|
||||
|
@ -338,4 +356,45 @@ public class MonitorControllerV2 {
|
|||
return monitorService.fileCode(code);
|
||||
}
|
||||
|
||||
@Data
|
||||
static public class Org{
|
||||
@ExcelProperty("名称")
|
||||
String orgName;
|
||||
}
|
||||
|
||||
@GetMapping("/exportYaweiOrg")
|
||||
public void exportYaweiOrg(HttpServletResponse response) throws Exception {
|
||||
|
||||
List<Map> deptList = JhDeptEnum.getAllToList();
|
||||
LinkedList<Org> all = new LinkedList<>();
|
||||
for (Map map : deptList) {
|
||||
String key = (String) map.keySet().iterator().next();
|
||||
if (StringUtils.isBlank(key)) {
|
||||
continue;
|
||||
}
|
||||
String filter = "(&(objectClass=organizationalUnit))";
|
||||
List<SearchResult> results = jhlDAPTool.query("OU=" + key, filter, new String[]{"distinguishedName"});
|
||||
results.stream().forEach(relult -> {
|
||||
try {
|
||||
String origStr = (String) relult.getAttributes().get("distinguishedName").get();
|
||||
String[] orgs = origStr.split(",");
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (int i = orgs.length -3-1; i >= 0; i--) {
|
||||
builder.append("/" + orgs[i].replace("OU=",""));
|
||||
}
|
||||
Org org = new Org();
|
||||
org.setOrgName(builder.toString());
|
||||
all.add(org);
|
||||
} catch (NamingException e) {
|
||||
log.error("ldap解析错误:", e);
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// ExcelUtil.getWriter().write(all, false);
|
||||
|
||||
ExcelUtils.exportExcelToTarget(response, "org","all", all, Org.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package io.renren.common.utils;
|
||||
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
|
@ -16,6 +17,7 @@ import java.util.*;
|
|||
* 通过该类完成金宏系统中 部门和用户名信息的提取
|
||||
*/
|
||||
@Component
|
||||
@Log4j2
|
||||
public class JhlDAPTool {
|
||||
private String URL = "ldap://15.72.158.50:389/";
|
||||
private String BASEDN = "DC=qd,DC=gov,DC=cn";//指定从哪里开始搜索,从上往下推
|
||||
|
@ -290,4 +292,40 @@ public class JhlDAPTool {
|
|||
return (cookie == null) ? new byte[0] : cookie;
|
||||
}
|
||||
|
||||
public List<SearchResult> query(String name, String filter, String[] returnAttr) {
|
||||
|
||||
Hashtable<String, String> env = new Hashtable<String, String>();
|
||||
env.put(Context.INITIAL_CONTEXT_FACTORY, FACTORY);
|
||||
env.put(Context.PROVIDER_URL, URL +BASEDN);
|
||||
env.put(Context.SECURITY_AUTHENTICATION, "simple");
|
||||
env.put(Context.SECURITY_PRINCIPAL, username); // 管理员
|
||||
env.put(Context.SECURITY_CREDENTIALS, password); // 管理员密码
|
||||
env.put("java.naming.ldap.attributes.binary","objectGUID");
|
||||
LinkedList<SearchResult> all = new LinkedList<>();
|
||||
try {
|
||||
InitialLdapContext ctx = new InitialLdapContext(env, connCtls);
|
||||
byte[] cookie = null;
|
||||
SearchControls searchControls = new SearchControls();//搜索控件
|
||||
if (returnAttr != null) {
|
||||
searchControls.setReturningAttributes(returnAttr);
|
||||
}
|
||||
searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);//搜索范围,1只搜索指定命名对象的一个级别,这是缺省值,2以指定命名对象为根结点的整棵树 SearchControls.SUBTREE_SCOPE
|
||||
|
||||
ctx.setRequestControls(new Control[]{new PagedResultsControl(50, Control.CRITICAL)});
|
||||
NamingEnumeration<SearchResult> answer = ctx.search(name, filter, searchControls);
|
||||
while (answer.hasMore()) {
|
||||
SearchResult result = (SearchResult) answer.next();
|
||||
all.add(result);
|
||||
}
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("ldap错误", e);
|
||||
return null;
|
||||
}finally {
|
||||
closeContext();
|
||||
}
|
||||
return all;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue