提交 76b38834 编写于 作者: sq3536's avatar sq3536

id初始化

上级 7cc1cbb5
...@@ -2,8 +2,12 @@ package cn.ibizlab.core.extensions.aspect; ...@@ -2,8 +2,12 @@ package cn.ibizlab.core.extensions.aspect;
import cn.ibizlab.core.extensions.mapping.IBZEmp2UserMapping; import cn.ibizlab.core.extensions.mapping.IBZEmp2UserMapping;
import cn.ibizlab.core.extensions.service.OUModelService; import cn.ibizlab.core.extensions.service.OUModelService;
import cn.ibizlab.core.ou.domain.IBZDepartment;
import cn.ibizlab.core.ou.domain.IBZEmployee; import cn.ibizlab.core.ou.domain.IBZEmployee;
import cn.ibizlab.core.ou.domain.IBZOrganization;
import cn.ibizlab.core.ou.service.IIBZDepartmentService;
import cn.ibizlab.core.ou.service.IIBZEmployeeService; import cn.ibizlab.core.ou.service.IIBZEmployeeService;
import cn.ibizlab.core.ou.service.IIBZOrganizationService;
import cn.ibizlab.util.domain.IBZUSER; import cn.ibizlab.util.domain.IBZUSER;
import cn.ibizlab.util.errors.BadRequestAlertException; import cn.ibizlab.util.errors.BadRequestAlertException;
import cn.ibizlab.util.service.IBZUSERService; import cn.ibizlab.util.service.IBZUSERService;
...@@ -31,6 +35,14 @@ public class IBZEmp2UserAspect ...@@ -31,6 +35,14 @@ public class IBZEmp2UserAspect
@Lazy @Lazy
private IBZUSERService ibzuserService; private IBZUSERService ibzuserService;
@Autowired
@Lazy
private IIBZDepartmentService iibzDepartmentService;
@Autowired
@Lazy
private IIBZOrganizationService iibzOrganizationService;
@Autowired @Autowired
@Lazy @Lazy
private IBZEmp2UserMapping ibzEmp2UserMapping; private IBZEmp2UserMapping ibzEmp2UserMapping;
...@@ -43,11 +55,24 @@ public class IBZEmp2UserAspect ...@@ -43,11 +55,24 @@ public class IBZEmp2UserAspect
@Before(value = "execution(* cn.ibizlab.core.ou.service.IIBZEmployeeService.creat*(..))") @Before(value = "execution(* cn.ibizlab.core.ou.service.IIBZEmployeeService.creat*(..))")
public void BeforeCreateEmp(JoinPoint point) throws Exception { public void BeforeCreateEmp(JoinPoint point) throws Exception {
prepareEmp(point); beforeSaveEmp(point);
} }
@Before(value = "execution(* cn.ibizlab.core.ou.service.IIBZEmployeeService.updat*(..))") @Before(value = "execution(* cn.ibizlab.core.ou.service.IIBZEmployeeService.updat*(..))")
public void BeforeUpdateEmp(JoinPoint point) throws Exception { public void BeforeUpdateEmp(JoinPoint point) throws Exception {
prepareEmp(point); beforeSaveEmp(point);
}
@Before(value = "execution(* cn.ibizlab.core.ou.service.IIBZEmployeeService.sav*(..))")
public void BeforeSaveEmp(JoinPoint point) throws Exception {
beforeSaveEmp(point);
}
@Before(value = "execution(* cn.ibizlab.core.ou.service.IIBZEmployeeService.creat*(..))")
public void BeforeCreateDept(JoinPoint point) throws Exception {
beforeSaveDept(point);
}
@Before(value = "execution(* cn.ibizlab.core.ou.service.IIBZEmployeeService.sav*(..))")
public void BeforeSaveDept(JoinPoint point) throws Exception {
beforeSaveDept(point);
} }
@After(value = "execution(* cn.ibizlab.core.ou.service.IIBZEmployeeService.creat*(..))") @After(value = "execution(* cn.ibizlab.core.ou.service.IIBZEmployeeService.creat*(..))")
...@@ -75,7 +100,7 @@ public class IBZEmp2UserAspect ...@@ -75,7 +100,7 @@ public class IBZEmp2UserAspect
initPwd(point); initPwd(point);
} }
private void prepareEmp(JoinPoint point) private void beforeSaveEmp(JoinPoint point)
{ {
Object[] args = point.getArgs(); Object[] args = point.getArgs();
if (args.length > 0) if (args.length > 0)
...@@ -83,57 +108,88 @@ public class IBZEmp2UserAspect ...@@ -83,57 +108,88 @@ public class IBZEmp2UserAspect
Object obj = args[0]; Object obj = args[0];
if(obj instanceof IBZEmployee) if(obj instanceof IBZEmployee)
{ {
IBZEmployee emp= ((IBZEmployee)obj); prepareEmp((IBZEmployee)obj);
String userName=emp.getUsername(); }
if(StringUtils.isEmpty(userName)) else if (obj instanceof List)
{ {
if(!StringUtils.isEmpty(emp.getDomains())) List<IBZEmployee> list=(List<IBZEmployee>)obj;
userName= emp.getLoginname()+"|"+emp.getDomains(); for(IBZEmployee emp:list)
else
userName = emp.getLoginname();
emp.setUsername(userName);
}
String password = emp.getPassword();
if(StringUtils.isEmpty(password))
{ {
password=defaultPasswd; prepareEmp(emp);
if(pwencrymode==1)
password = DigestUtils.md5DigestAsHex(password.getBytes());
else if(pwencrymode==2)
password = DigestUtils.md5DigestAsHex(String.format("%1$s||%2$s", userName, password).getBytes());
emp.setPassword(password);
} }
}
}
}
private void beforeSaveDept(JoinPoint point)
{
Object[] args = point.getArgs();
if (args.length > 0)
{
Object obj = args[0];
if(obj instanceof IBZDepartment)
{
prepareDept((IBZDepartment)obj);
} }
else if (obj instanceof List) else if (obj instanceof List)
{ {
List<IBZEmployee> list=(List<IBZEmployee>)obj; List<IBZDepartment> list=(List<IBZDepartment>)obj;
for(IBZEmployee emp:list) for(IBZDepartment dept:list)
{ {
String userName=emp.getUsername(); prepareDept(dept);
if(StringUtils.isEmpty(userName))
{
if(!StringUtils.isEmpty(emp.getDomains()))
userName= emp.getLoginname()+"|"+emp.getDomains();
else
userName = emp.getLoginname();
emp.setUsername(userName);
}
String password = emp.getPassword();
if(StringUtils.isEmpty(password))
{
password=defaultPasswd;
if(pwencrymode==1)
password = DigestUtils.md5DigestAsHex(password.getBytes());
else if(pwencrymode==2)
password = DigestUtils.md5DigestAsHex(String.format("%1$s||%2$s", userName, password).getBytes());
emp.setPassword(password);
}
} }
} }
} }
} }
private void prepareEmp(IBZEmployee emp)
{
String userName=emp.getUsername();
if(StringUtils.isEmpty(emp.getUserid())&&(!StringUtils.isEmpty(emp.getUsercode()))&&(!StringUtils.isEmpty(emp.getOrgid())))
{
emp.setUserid(emp.getOrgid()+"-"+emp.getUsercode());
}
if(StringUtils.isEmpty(emp.getOrgcode())&&(!StringUtils.isEmpty(emp.getOrgid())))
{
IBZOrganization org=iibzOrganizationService.get(emp.getOrgid());
emp.setOrgcode(org.getOrgcode());
emp.setOrgname(org.getOrgname());
}
if(StringUtils.isEmpty(emp.getMdeptcode())&&(!StringUtils.isEmpty(emp.getMdeptid())))
{
IBZDepartment dept=iibzDepartmentService.get(emp.getMdeptid());
emp.setMdeptcode(dept.getDeptcode());
emp.setMdeptname(dept.getDeptname());
emp.setBcode(dept.getBcode());
}
if(StringUtils.isEmpty(userName))
{
if(!StringUtils.isEmpty(emp.getDomains()))
userName= emp.getLoginname()+"|"+emp.getDomains();
else
userName = emp.getLoginname();
emp.setUsername(userName);
}
String password = emp.getPassword();
if(StringUtils.isEmpty(password))
{
password=defaultPasswd;
if(pwencrymode==1)
password = DigestUtils.md5DigestAsHex(password.getBytes());
else if(pwencrymode==2)
password = DigestUtils.md5DigestAsHex(String.format("%1$s||%2$s", userName, password).getBytes());
emp.setPassword(password);
}
}
private void prepareDept(IBZDepartment dept)
{
if (StringUtils.isEmpty(dept.getDeptid()) && (!StringUtils.isEmpty(dept.getDeptcode())) && (!StringUtils.isEmpty(dept.getOrgid())))
{
dept.setDeptid(dept.getOrgid() + dept.getDeptcode());
}
}
private void saveUser(JoinPoint point) private void saveUser(JoinPoint point)
{ {
Object[] args = point.getArgs(); Object[] args = point.getArgs();
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册