Commit b44c9801 authored by zjy's avatar zjy

user/role/tright 7.13

parent b9c15408
package com.pangding.web.authority.service.impl; package com.pangding.web.authority.service.impl;
import com.pangding.web.authority.dao.RoleAuthorityDao; import com.pangding.web.authority.dao.*;
import com.pangding.web.authority.dao.AuthorityDao;
import com.pangding.web.authority.dao.UserDao;
import com.pangding.web.authority.dao.UserRoleDao;
import com.pangding.web.authority.util.RoleConstant; import com.pangding.web.authority.util.RoleConstant;
import com.pangding.web.authority.vo.reqvo.*; import com.pangding.web.authority.vo.reqvo.*;
import com.pangding.web.authority.service.AuthorityService; import com.pangding.web.authority.service.AuthorityService;
...@@ -20,8 +17,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -20,8 +17,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList; import java.util.*;
import java.util.List;
/** /**
* @author zhangjinyao * @author zhangjinyao
...@@ -37,6 +33,10 @@ public class AuthorityServiceImpl implements AuthorityService { ...@@ -37,6 +33,10 @@ public class AuthorityServiceImpl implements AuthorityService {
UserDao userDaoImpl; UserDao userDaoImpl;
@Autowired @Autowired
UserRoleDao userRoleDaoImpl; UserRoleDao userRoleDaoImpl;
@Autowired
private RegisterServiceImpl registerServiceImpl;
@Autowired
private RoleDao roleDaoImpl;
/** /**
* 保存authorityVo对象数据 * 保存authorityVo对象数据
...@@ -248,31 +248,67 @@ public class AuthorityServiceImpl implements AuthorityService { ...@@ -248,31 +248,67 @@ public class AuthorityServiceImpl implements AuthorityService {
@Override @Override
public AuthorityListResVo getListByLevel(AuthorityListReqVo reqVo) { public AuthorityListResVo getListByLevel(AuthorityListReqVo reqVo) {
List<AuthorityVo> parentList = authorityDao.getLevelOne(reqVo); RoleGetReqVo roleGetReqVo = new RoleGetReqVo();
if (null == parentList || parentList.isEmpty()){ roleGetReqVo.setCompanyId(reqVo.getCompanyId());
throw new CodeException("暂无一级权限,请添加"); roleGetReqVo.setIsAdmin(1);
RoleVo roleVo = roleDaoImpl.load(roleGetReqVo,RoleVo.class);
if (roleVo == null){
throw new CodeException("该公司用户未设置管理员角色");
} }
List<AuthorityListByLevelResVo> resVoList = new ArrayList(); Set authorityIdSet = new HashSet();
for (AuthorityVo authorityVo:parentList) {
AuthorityListByLevelResVo resVo = new AuthorityListByLevelResVo(); RoleAuthorityGetReqVo roleAuthorityGetReqVo = new RoleAuthorityGetReqVo();
ObjectHelper.writeWithFrom(resVo,authorityVo); roleAuthorityGetReqVo.setRoleId(roleVo.getId());
List<AuthorityListByLevelResVo> childList = getChildList(authorityVo.getId()); List<RoleAuthorityVo> roleAuthorityVoList = roleAuthorityDao.loadList(roleAuthorityGetReqVo,RoleAuthorityVo.class);
resVo.setChildList(childList); for (RoleAuthorityVo roleAuthorityVo:roleAuthorityVoList) {
resVoList.add(resVo); authorityIdSet.add(roleAuthorityVo.getAuthorityId());
} }
/*返回对象*/ List<String> authorityIdList = new ArrayList<>();
Object[] objs = authorityIdSet.toArray();
for (Object obj:objs) {
authorityIdList.add((String) obj);
}
List<AuthorityVo> levelOneList = new ArrayList();
for (int i = 0; i < authorityIdList.size(); i++) {
AuthorityGetReqVo authorityGetReqVo = new AuthorityGetReqVo();
authorityGetReqVo.setId(authorityIdList.get(i));
AuthorityVo authorityVo = authorityDao.load(authorityGetReqVo,AuthorityVo.class);
if (null == authorityVo.getPid() || authorityVo.getPid().isEmpty()){
levelOneList.add(authorityVo);
authorityIdList.set(i,"");
}
}
List<String> authorityIds = new ArrayList<>();
for (int i = 0; i < authorityIdList.size(); i++) {
if (!"".equals(authorityIdList.get(i))){
authorityIds.add(authorityIdList.get(i));
}
}
Collections.sort(levelOneList);
if (levelOneList.isEmpty()){
throw new CodeException("该用户暂无权限,请添加");
}
List<AuthorityListByLevelResVo> authorityListByLevel = new ArrayList<>();
for (AuthorityVo authorityVo:levelOneList) {
AuthorityListByLevelResVo resVo1 = new AuthorityListByLevelResVo();
ObjectHelper.writeWithFrom(resVo1,authorityVo);
List<AuthorityListByLevelResVo> childList = registerServiceImpl.getChildList(authorityVo,authorityIds);
resVo1.setChildList(childList);
authorityListByLevel.add(resVo1);
}
Collections.sort(authorityListByLevel);
AuthorityListResVo authorityListResVo = new AuthorityListResVo(); AuthorityListResVo authorityListResVo = new AuthorityListResVo();
authorityListResVo.setAuthorityListByLevel(resVoList); authorityListResVo.setAuthorityListByLevel(authorityListByLevel);
/*若roleId存在,则需要返回该角色拥有的权限列表*/ /*若roleId存在,则需要返回该角色拥有的权限列表*/
if (null != reqVo.getRoleId() && !reqVo.getRoleId().isEmpty()){ if (null != reqVo.getRoleId() && !reqVo.getRoleId().isEmpty()){
RoleAuthorityGetReqVo roleAuthorityGetReqVo = new RoleAuthorityGetReqVo(); RoleAuthorityGetReqVo roleAuthorityGetReqVo1 = new RoleAuthorityGetReqVo();
roleAuthorityGetReqVo.setRoleId(reqVo.getRoleId()); roleAuthorityGetReqVo1.setRoleId(reqVo.getRoleId());
List<RoleAuthorityVo> roleAuthorityVoList = roleAuthorityDao.loadList(roleAuthorityGetReqVo,RoleAuthorityVo.class); List<RoleAuthorityVo> roleAuthorityVos = roleAuthorityDao.loadList(roleAuthorityGetReqVo1,RoleAuthorityVo.class);
List<AuthorityVo> authorityVoList = new ArrayList<>(); List<AuthorityVo> authorityVoList = new ArrayList<>();
if (null != roleAuthorityVoList && !roleAuthorityVoList.isEmpty()){ if (null != roleAuthorityVos && !roleAuthorityVos.isEmpty()){
for (RoleAuthorityVo roleAuthorityVo:roleAuthorityVoList) { for (RoleAuthorityVo roleAuthorityVo:roleAuthorityVos) {
AuthorityGetReqVo getReqVo = new AuthorityGetReqVo(); AuthorityGetReqVo getReqVo = new AuthorityGetReqVo();
getReqVo.setId(roleAuthorityVo.getAuthorityId()); getReqVo.setId(roleAuthorityVo.getAuthorityId());
AuthorityVo authorityVo = authorityDao.load(getReqVo,AuthorityVo.class); AuthorityVo authorityVo = authorityDao.load(getReqVo,AuthorityVo.class);
...@@ -306,10 +342,10 @@ public class AuthorityServiceImpl implements AuthorityService { ...@@ -306,10 +342,10 @@ public class AuthorityServiceImpl implements AuthorityService {
@Override @Override
public List<AuthorityListByLevelResVo> getCompanyAuthority(CompanyAuthorityReqVo reqVo) { public List<AuthorityListByLevelResVo> getCompanyAuthority(CompanyAuthorityReqVo reqVo) {
UserGetSuperAdminReqVo userGetSuperAdminReqVo = new UserGetSuperAdminReqVo(); UserGetReqVo userGetReqVo = new UserGetReqVo();
userGetSuperAdminReqVo.setCompanyId(reqVo.getCompanyId()); userGetReqVo.setCompanyId(reqVo.getCompanyId());
userGetSuperAdminReqVo.setAdminRoleId(RoleConstant.SUPER_ADMIN_ROLE_ID); userGetReqVo.setIsFirst(1);
UserVo superAdmin = userDaoImpl.getAdmin(userGetSuperAdminReqVo); UserVo superAdmin = userDaoImpl.load(userGetReqVo,UserVo.class);
if (null == superAdmin){ if (null == superAdmin){
throw new CodeException("暂无超级管理员"); throw new CodeException("暂无超级管理员");
} }
......
...@@ -96,13 +96,13 @@ public class CompanyServiceImpl implements CompanyService { ...@@ -96,13 +96,13 @@ public class CompanyServiceImpl implements CompanyService {
public CompanyResVo pdGetDetail(CompanyGetReqVo reqVo) { public CompanyResVo pdGetDetail(CompanyGetReqVo reqVo) {
CompanyResVo resVo = getDetail(reqVo); CompanyResVo resVo = getDetail(reqVo);
/*获取用户表信息*/ /*获取用户表信息*/
/*UserGetSuperAdminReqVo req = new UserGetSuperAdminReqVo(); UserGetReqVo userGetReqVo = new UserGetReqVo();
req.setCompanyId(reqVo.getId()); userGetReqVo.setIsFirst(1);
req.setAdminRoleId(RoleConstant.ADMIN_ROLE_ID); userGetReqVo.setCompanyId(reqVo.getId());
UserVo userVo = userDaoImpl.getAdmin(req); UserVo userVo = userDaoImpl.load(userGetReqVo,UserVo.class);
if (null != userVo) { if (null != userVo) {
resVo.setUserVo(userVo); resVo.setUserVo(userVo);
}*/ }
return resVo; return resVo;
} }
...@@ -268,14 +268,6 @@ public class CompanyServiceImpl implements CompanyService { ...@@ -268,14 +268,6 @@ public class CompanyServiceImpl implements CompanyService {
userServiceImpl.checkPhone(userVo); userServiceImpl.checkPhone(userVo);
userDaoImpl.create(userVo); userDaoImpl.create(userVo);
/*将该用户设置为超级管理员*/
UserRoleVo userRoleVo = new UserRoleVo();
userRoleVo.setId(StringHelper.getNewID());
userRoleVo.setUserId(userVo.getId());
userRoleVo.setRoleId(RoleConstant.SUPER_ADMIN_ROLE_ID);
userRoleDaoImpl.create(userRoleVo);
resVo.setUserId(userVo.getId()); resVo.setUserId(userVo.getId());
return resVo; return resVo;
......
...@@ -115,23 +115,9 @@ public class DataServiceImpl implements DataService { ...@@ -115,23 +115,9 @@ public class DataServiceImpl implements DataService {
UserVo userVo1 = userDaoImpl.load(userGetReqVo,UserVo.class); UserVo userVo1 = userDaoImpl.load(userGetReqVo,UserVo.class);
if (null == userVo1){ if (null == userVo1){
userDaoImpl.create(userVo); userDaoImpl.create(userVo);
/*给用户分配管理员角色*/
UserRoleVo userRoleVo = new UserRoleVo();
userRoleVo.setUserId(userVo.getId());
userRoleVo.setRoleId(RoleConstant.ADMIN_ROLE_ID);
userRoleDaoImpl.create(userRoleVo);
}else{ }else{
userVo.setId(userVo1.getId()); userVo.setId(userVo1.getId());
userDaoImpl.update(userVo); userDaoImpl.update(userVo);
/*给用户分配管理员角色*/
UserRoleVo userRoleVo = new UserRoleVo();
userRoleVo.setUserId(userVo1.getId());
userRoleVo.setRoleId(RoleConstant.ADMIN_ROLE_ID);
UserRoleVo userRoleVo1 = userRoleDaoImpl.load(userRoleVo,UserRoleVo.class);
if (null == userRoleVo1){
userRoleVo.setId(StringHelper.getNewID());
userRoleDaoImpl.create(userRoleVo);
}
} }
/*保存公司扩展表*/ /*保存公司扩展表*/
......
...@@ -118,6 +118,7 @@ public class RegisterServiceImpl implements RegisterService { ...@@ -118,6 +118,7 @@ public class RegisterServiceImpl implements RegisterService {
userVo.setId(StringHelper.getNewID()); userVo.setId(StringHelper.getNewID());
userVo.setRemark(password); userVo.setRemark(password);
userVo.setCompanyId(companyId); userVo.setCompanyId(companyId);
userVo.setIsFirst(1);
userDaoImpl.create(userVo); userDaoImpl.create(userVo);
/*保存公司*/ /*保存公司*/
...@@ -462,7 +463,7 @@ public class RegisterServiceImpl implements RegisterService { ...@@ -462,7 +463,7 @@ public class RegisterServiceImpl implements RegisterService {
return resVo; return resVo;
} }
private List<AuthorityListByLevelResVo> getChildList(AuthorityVo authorityVo,List<String> authorityIds){ public List<AuthorityListByLevelResVo> getChildList(AuthorityVo authorityVo,List<String> authorityIds){
List<AuthorityListByLevelResVo> resVoList = new ArrayList<>(); List<AuthorityListByLevelResVo> resVoList = new ArrayList<>();
for (int i = 0;i<authorityIds.size();i++) { for (int i = 0;i<authorityIds.size();i++) {
AuthorityGetReqVo authorityGetReqVo = new AuthorityGetReqVo(); AuthorityGetReqVo authorityGetReqVo = new AuthorityGetReqVo();
......
...@@ -20,9 +20,20 @@ public class RoleVo extends BaseVo { ...@@ -20,9 +20,20 @@ public class RoleVo extends BaseVo {
private String remark; private String remark;
@TableAnnotation("is_admin")
private Integer isAdmin;
@TableAnnotation("company_id") @TableAnnotation("company_id")
private String companyId; private String companyId;
public Integer getIsAdmin() {
return isAdmin;
}
public void setIsAdmin(Integer isAdmin) {
this.isAdmin = isAdmin;
}
public String getCompanyId() { public String getCompanyId() {
return companyId; return companyId;
} }
......
...@@ -44,6 +44,17 @@ public class UserVo extends BaseVo implements InitDao { ...@@ -44,6 +44,17 @@ public class UserVo extends BaseVo implements InitDao {
private String email; private String email;
@TableAnnotation("is_first")
private Integer isFirst;
public Integer getIsFirst() {
return isFirst;
}
public void setIsFirst(Integer isFirst) {
this.isFirst = isFirst;
}
public String getName() { public String getName() {
return name; return name;
} }
......
...@@ -13,6 +13,16 @@ public class AuthorityListReqVo { ...@@ -13,6 +13,16 @@ public class AuthorityListReqVo {
private Integer attribute; private Integer attribute;
private String companyId;
public String getCompanyId() {
return companyId;
}
public void setCompanyId(String companyId) {
this.companyId = companyId;
}
public Integer getAttribute() { public Integer getAttribute() {
return attribute; return attribute;
} }
......
...@@ -11,6 +11,26 @@ public class RoleGetReqVo { ...@@ -11,6 +11,26 @@ public class RoleGetReqVo {
private String name; private String name;
private String CompanyId;
private Integer isAdmin;
public String getCompanyId() {
return CompanyId;
}
public void setCompanyId(String companyId) {
CompanyId = companyId;
}
public Integer getIsAdmin() {
return isAdmin;
}
public void setIsAdmin(Integer isAdmin) {
this.isAdmin = isAdmin;
}
public String getReqId() { public String getReqId() {
return reqId; return reqId;
} }
......
...@@ -18,6 +18,16 @@ public class UserGetReqVo { ...@@ -18,6 +18,16 @@ public class UserGetReqVo {
private String phone; private String phone;
private Integer isFirst;
public Integer getIsFirst() {
return isFirst;
}
public void setIsFirst(Integer isFirst) {
this.isFirst = isFirst;
}
public String getReqId() { public String getReqId() {
return reqId; return reqId;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment