From 55a304519fdff15716ddabc449fbbfe792795a19 Mon Sep 17 00:00:00 2001 From: yitonglei Date: Tue, 21 Jun 2022 15:37:24 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E4=BF=AE=E6=94=B9=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E9=87=91=E5=AE=8F=E6=95=B0=E6=8D=AE=E5=BA=93=E4=B8=AD=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E5=90=8D=E5=92=8C=E5=9C=B0=E5=8C=BA=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=EF=BC=8C=E5=B0=86=20JhUserTask=E5=92=8CJhDeptTask=E5=88=A0?= =?UTF-8?q?=E9=99=A4=EF=BC=8C=E6=94=B9=E4=B8=BA=E5=9C=A8SysUserController?= =?UTF-8?q?=E4=B8=AD=E5=88=86=E5=88=AB=E9=80=9A=E8=BF=87/getDeptInfoFromJH?= =?UTF-8?q?=E5=92=8C/getUserInfoFromJH=E6=89=8B=E5=8A=A8=E8=B0=83=E7=94=A8?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../renren/modules/job/task/JhDeptTask.java | 187 ------------------ .../renren/modules/job/task/JhUserTask.java | 75 ------- .../sys/controller/SysUserController.java | 12 ++ .../sys/service/impl/SysUserServiceImpl.java | 2 + 4 files changed, 14 insertions(+), 262 deletions(-) delete mode 100644 renren-admin/src/main/java/io/renren/modules/job/task/JhDeptTask.java delete mode 100644 renren-admin/src/main/java/io/renren/modules/job/task/JhUserTask.java diff --git a/renren-admin/src/main/java/io/renren/modules/job/task/JhDeptTask.java b/renren-admin/src/main/java/io/renren/modules/job/task/JhDeptTask.java deleted file mode 100644 index d5a36251..00000000 --- a/renren-admin/src/main/java/io/renren/modules/job/task/JhDeptTask.java +++ /dev/null @@ -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 deptList = JhDeptEnum.getAllToList(); - int size = deptList.size(); - - try{ - for (int n = 0; n < size; n++) { - - Map map1 = deptList.get(n); - Set 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> lists = jhlDAPTool.readLdap(ldapContext,"(&(OU=*)(ou=*)(!(sAMAccountType=*))(instanceType=4))"); - //Iterator> 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 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(); - } - } -} diff --git a/renren-admin/src/main/java/io/renren/modules/job/task/JhUserTask.java b/renren-admin/src/main/java/io/renren/modules/job/task/JhUserTask.java deleted file mode 100644 index ec223dd8..00000000 --- a/renren-admin/src/main/java/io/renren/modules/job/task/JhUserTask.java +++ /dev/null @@ -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 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 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(); - } - } -} diff --git a/renren-admin/src/main/java/io/renren/modules/sys/controller/SysUserController.java b/renren-admin/src/main/java/io/renren/modules/sys/controller/SysUserController.java index c864c2c0..99efc1a3 100644 --- a/renren-admin/src/main/java/io/renren/modules/sys/controller/SysUserController.java +++ b/renren-admin/src/main/java/io/renren/modules/sys/controller/SysUserController.java @@ -162,4 +162,16 @@ public class SysUserController { 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(); + } } \ No newline at end of file diff --git a/renren-admin/src/main/java/io/renren/modules/sys/service/impl/SysUserServiceImpl.java b/renren-admin/src/main/java/io/renren/modules/sys/service/impl/SysUserServiceImpl.java index 220d0998..666e44e3 100644 --- a/renren-admin/src/main/java/io/renren/modules/sys/service/impl/SysUserServiceImpl.java +++ b/renren-admin/src/main/java/io/renren/modules/sys/service/impl/SysUserServiceImpl.java @@ -384,6 +384,8 @@ public class SysUserServiceImpl extends BaseServiceImpl