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

id初始化

上级 7cc1cbb5
......@@ -2,8 +2,12 @@ package cn.ibizlab.core.extensions.aspect;
import cn.ibizlab.core.extensions.mapping.IBZEmp2UserMapping;
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.IBZOrganization;
import cn.ibizlab.core.ou.service.IIBZDepartmentService;
import cn.ibizlab.core.ou.service.IIBZEmployeeService;
import cn.ibizlab.core.ou.service.IIBZOrganizationService;
import cn.ibizlab.util.domain.IBZUSER;
import cn.ibizlab.util.errors.BadRequestAlertException;
import cn.ibizlab.util.service.IBZUSERService;
......@@ -31,6 +35,14 @@ public class IBZEmp2UserAspect
@Lazy
private IBZUSERService ibzuserService;
@Autowired
@Lazy
private IIBZDepartmentService iibzDepartmentService;
@Autowired
@Lazy
private IIBZOrganizationService iibzOrganizationService;
@Autowired
@Lazy
private IBZEmp2UserMapping ibzEmp2UserMapping;
......@@ -43,11 +55,24 @@ public class IBZEmp2UserAspect
@Before(value = "execution(* cn.ibizlab.core.ou.service.IIBZEmployeeService.creat*(..))")
public void BeforeCreateEmp(JoinPoint point) throws Exception {
prepareEmp(point);
beforeSaveEmp(point);
}
@Before(value = "execution(* cn.ibizlab.core.ou.service.IIBZEmployeeService.updat*(..))")
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*(..))")
......@@ -75,7 +100,7 @@ public class IBZEmp2UserAspect
initPwd(point);
}
private void prepareEmp(JoinPoint point)
private void beforeSaveEmp(JoinPoint point)
{
Object[] args = point.getArgs();
if (args.length > 0)
......@@ -83,57 +108,88 @@ public class IBZEmp2UserAspect
Object obj = args[0];
if(obj instanceof IBZEmployee)
{
IBZEmployee emp= ((IBZEmployee)obj);
String userName=emp.getUsername();
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))
prepareEmp((IBZEmployee)obj);
}
else if (obj instanceof List)
{
List<IBZEmployee> list=(List<IBZEmployee>)obj;
for(IBZEmployee emp:list)
{
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);
prepareEmp(emp);
}
}
}
}
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)
{
List<IBZEmployee> list=(List<IBZEmployee>)obj;
for(IBZEmployee emp:list)
List<IBZDepartment> list=(List<IBZDepartment>)obj;
for(IBZDepartment dept:list)
{
String userName=emp.getUsername();
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);
}
prepareDept(dept);
}
}
}
}
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)
{
Object[] args = point.getArgs();
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册