Commit b44c9801 authored by zjy's avatar zjy

user/role/tright 7.13

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