1、修改获取金宏数据库中用户名和地区信息,将 JhUserTask和JhDeptTask删除,改为在SysUserController中分别通过/getDeptInfoFromJH和/getUserInfoFromJH手动调用。

This commit is contained in:
yitonglei 2022-06-21 15:37:24 +08:00
parent fbdd40e9f4
commit 55a304519f
4 changed files with 14 additions and 262 deletions

View File

@ -1,187 +0,0 @@
package io.renren.modules.job.task;
import io.renren.common.utils.JhlDAPTool;
import io.renren.modules.sys.dao.SysDeptDao;
import io.renren.modules.sys.entity.SysDeptEntity;
import io.renren.modules.sys.enums.JhDeptEnum;
import io.renren.modules.sys.service.impl.SysUserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.naming.ldap.LdapContext;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* 自动获取金宏服务器上部门信息并保存到sys_dept
* ytl 2022-06-07
*/
@Component("jhDeptTask")
public class JhDeptTask implements ITask{
@Autowired
private JhlDAPTool jhlDAPTool;
@Autowired
private SysUserServiceImpl sysUserService;
@Autowired
private SysDeptDao sysDeptDao;
@Override
public void run(String params) {
List<Map> deptList = JhDeptEnum.getAllToList();
int size = deptList.size();
try{
for (int n = 0; n < size; n++) {
Map map1 = deptList.get(n);
Set<String> set = map1.keySet();
String mName = "";
for(String s:set){
mName = s;
}
String key = mName;//区名即墨区
String[] ouStr = (String[])map1.get(key);
for(String ou:ouStr){
String OU = ou+","+"OU="+mName;
LdapContext ldapContext = jhlDAPTool.LDAP_connect(OU);
List<Map<String,Object>> lists = jhlDAPTool.readLdap(ldapContext,"(&(OU=*)(ou=*)(!(sAMAccountType=*))(instanceType=4))");
//Iterator<Map<String,Object>> iterator = lists.iterator();
//给pid pids赋值
if (lists.size() > 0) {
lists.forEach(dept->{//1.遍历每一个map
String namespace = dept.get("namespace").toString();
//OU=地税局分局,OU=驻区单位,OU=新市北区,DC=qd,DC=gov,DC=cn
String[] namespaces = namespace.split(",");
//判断namespaces的长度
for(int i=1;i<namespaces.length-3;i++) {//遍历每一个map的namespace
String dName = namespaces[i].split("=")[1];//具体的上级部门名称
int c = i;
for (int j = 0; j < lists.size(); j++) {
Map<String, Object> map = new HashMap<>();
if (dName.equals(lists.get(j).get("name").toString())) {
String id = lists.get(j).get("id").toString();
String pidsOld = dept.get("pids").toString() == ""? "" : (dept.get("pids").toString() + ",");
if (c == 1) {
dept.put("pid", id);
dept.put("pids", pidsOld + id);
} else {
dept.put("pids", pidsOld + id);
}
break;
}
}
}
});
//给district和type赋值
String districtName,type;
Long distict;
switch (key){
case "新市北区":
districtName = "市北区";
distict = sysUserService.getDistict(districtName);
lists.forEach(l->{
l.put("district",distict);
String name = l.get("name").toString();
if(name.contains("企业") || name.contains("集团") || name.contains("公司")){
l.put("type",4);
}else{
l.put("type",3);
}
});
break;
case "青岛市级":
districtName = "青岛市";
distict = sysUserService.getDistict(districtName);
lists.forEach(l->{
l.put("district",distict);
l.put("type",2);
});
break;
case "莱西市用户":
districtName = "莱西市";
distict = sysUserService.getDistict(districtName);
lists.forEach(l->{
l.put("district",distict);
String name = l.get("name").toString();
if(name.contains("企业") || name.contains("集团") || name.contains("公司")){
l.put("type",4);
}else{
l.put("type",3);
}
});
break;
case "黄岛区":
districtName = "西海岸新区";
distict = sysUserService.getDistict(districtName);
lists.forEach(l->{
l.put("district",distict);
String name = l.get("name").toString();
if(name.contains("企业") || name.contains("集团") || name.contains("公司")){
l.put("type",4);
}else{
l.put("type",3);
}
});
break;
case "市直企业":
distict = sysUserService.getDistict("青岛市");
lists.forEach(l->{
l.put("district",distict);
l.put("type",4);
});
break;
case "市直机关":
distict = sysUserService.getDistict("青岛市");
lists.forEach(l->{
l.put("district",distict);
l.put("type",2);
});
break;
case "驻青单位":
distict = sysUserService.getDistict("山东省");
lists.forEach(l->{
l.put("district",distict);
l.put("type",1);
});
break;
default:
distict = sysUserService.getDistict(mName);
lists.forEach(l->{
l.put("district",distict);
String name = l.get("name").toString();
if(name.contains("企业") || name.contains("集团") || name.contains("公司")){
l.put("type",4);
}else{
l.put("type",3);
}
});
}
lists.forEach(list->{//如果有该ID和name目前暂不处理可以打印出来否则插入
SysDeptEntity dept = sysDeptDao.getById(Long.valueOf(list.get("id").toString()));
SysDeptEntity deptNew = new SysDeptEntity();
deptNew.setName(list.get("name").toString());
deptNew.setId(Long.valueOf(list.get("id").toString()));
deptNew.setPid(Long.valueOf(list.get("pid").toString()));
deptNew.setPids(list.get("pids").toString());
deptNew.setDistrict(Long.valueOf(list.get("district").toString()));
deptNew.setType(Integer.parseInt(list.get("type").toString()));
if(dept == null){
System.out.println("deptname->"+deptNew.getName());
sysDeptDao.insert(deptNew);
}
});
}
}
}
}catch (Exception e){
e.printStackTrace();
}
}
}

View File

@ -1,75 +0,0 @@
package io.renren.modules.job.task;
import io.renren.common.utils.JhlDAPTool;
import io.renren.modules.sys.dao.SysUserDao;
import io.renren.modules.sys.entity.SysUserEntity;
import io.renren.modules.sys.enums.JhDeptsEnum;
import io.renren.modules.sys.service.impl.SysUserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.naming.ldap.LdapContext;
import java.util.List;
import java.util.Map;
/**
* 自动获取金宏服务器上用户信息并保存到sys_user
* ytl 2022-06-07
*/
@Component("jhUserTask")
public class JhUserTask implements ITask{
@Autowired
private JhlDAPTool jhlDAPTool;
@Autowired
private SysUserServiceImpl sysUserService;
@Autowired
private SysUserDao sysUserDao;
@Override
public void run(String params) {
List<Map> deptList = JhDeptsEnum.getAllToList();
int size = deptList.size();
try {
for (int i = 1; i <= size; i++) {
LdapContext ldapContext = jhlDAPTool.LDAP_connect(deptList.get(i - 1).get(String.valueOf(i)).toString());
List<Map> maps = jhlDAPTool.readLdap(ldapContext);
if (maps.size() > 0) {
maps.forEach(m -> {
//根据username判断
if (m.get(("username")) != null) {
String userName = m.get("username").toString();
SysUserEntity user = sysUserDao.getUserByName(userName);
if (user == null) {//用户表中没有该用户插入
SysUserEntity newUser = new SysUserEntity();
newUser.setUsername(userName);
newUser.setSuperAdmin(0);
newUser.setId(Long.valueOf(m.get("id") == null ? "0":m.get("id").toString()));
newUser.setGuid(m.get("guid") == null ? "":m.get("guid").toString());
newUser.setRealName(m.get("real_name") == null ? "" : m.get("real_name").toString());
newUser.setEmail(m.get("email") == null ? "" : m.get("email").toString());
newUser.setMobile(m.get("mobile") == null ? "" : m.get("mobile").toString());
newUser.setStatus(1);//账号状态 1正常 0停用
//给dept_id赋值
String deptNames = m.get("distinguishedName") == null ? "" : m.get("distinguishedName").toString();
if (deptNames == null) {
newUser.setDeptId(0L);
} else {
String[] deptArray = deptNames.split(",");
String dept, deptFather;
dept = deptArray[1];
deptFather = deptArray[2];
long id = sysUserService.getDeptId(dept.substring(3, dept.length()), deptFather.substring(3, deptFather.length()));
newUser.setDeptId(id);
sysUserDao.insert(newUser);
}
}
}
});
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@ -162,4 +162,16 @@ public class SysUserController {
ExcelUtils.exportExcelToTarget(response, null, "用户管理", list, SysUserExcel.class); ExcelUtils.exportExcelToTarget(response, null, "用户管理", list, SysUserExcel.class);
} }
@GetMapping("getDeptInfoFromJH")
@ApiOperation("从金宏获取行政区划信息并保存到表中")
public Result getDeptInfoFromJH(){
return sysUserService.getDeptInfoFromJH();
}
@GetMapping("getUserInfoFromJH")
@ApiOperation("从金宏获取用户信息并保存到表中")
public Result getUserInfoFromJH() {
return sysUserService.getUserInfoFromJH();
}
} }

View File

@ -384,6 +384,8 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserDao, SysUserEntit
SysUserEntity newUser = new SysUserEntity(); SysUserEntity newUser = new SysUserEntity();
newUser.setUsername(userName); newUser.setUsername(userName);
newUser.setSuperAdmin(0); newUser.setSuperAdmin(0);
newUser.setGuid(m.get("guid") == null ? "":m.get("guid").toString());
newUser.setId(Long.valueOf(m.get("id") == null ? "0":m.get("id").toString()));
newUser.setRealName(m.get("real_name") == null ?"":m.get("real_name").toString()); newUser.setRealName(m.get("real_name") == null ?"":m.get("real_name").toString());
newUser.setEmail(m.get("email") == null ?"":m.get("email").toString()); newUser.setEmail(m.get("email") == null ?"":m.get("email").toString());
newUser.setMobile(m.get("mobile") == null ?"":m.get("mobile").toString()); newUser.setMobile(m.get("mobile") == null ?"":m.get("mobile").toString());