|
|
@@ -7,6 +7,7 @@ import java.util.stream.Stream;
|
|
|
import com.dgtly.common.core.domain.Ztree;
|
|
|
import com.dgtly.common.utils.DateUtils;
|
|
|
import com.dgtly.common.utils.StringUtils;
|
|
|
+import com.dgtly.common.utils.UserIdentityUtil;
|
|
|
import com.dgtly.system.domain.*;
|
|
|
import com.dgtly.system.mapper.SysUserAuthorRelMapper;
|
|
|
import com.dgtly.system.mapper.SysUserExtMapper;
|
|
|
@@ -15,6 +16,7 @@ import org.springframework.stereotype.Service;
|
|
|
import com.dgtly.system.mapper.SysUserOrderAuthorMapper;
|
|
|
import com.dgtly.system.service.ISysUserOrderAuthorService;
|
|
|
import com.dgtly.common.core.text.Convert;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import static java.util.stream.Collectors.toList;
|
|
|
|
|
|
@@ -25,7 +27,8 @@ import static java.util.stream.Collectors.toList;
|
|
|
* @date 2022-03-22
|
|
|
*/
|
|
|
@Service
|
|
|
-public class SysUserOrderAuthorServiceImpl implements ISysUserOrderAuthorService {
|
|
|
+public class SysUserOrderAuthorServiceImpl implements ISysUserOrderAuthorService
|
|
|
+{
|
|
|
@Autowired
|
|
|
private SysUserOrderAuthorMapper sysUserOrderAuthorMapper;
|
|
|
|
|
|
@@ -37,100 +40,141 @@ public class SysUserOrderAuthorServiceImpl implements ISysUserOrderAuthorService
|
|
|
|
|
|
/**
|
|
|
* 查询权限
|
|
|
- *
|
|
|
+ *
|
|
|
* @param authorId 权限ID
|
|
|
* @return 权限
|
|
|
*/
|
|
|
@Override
|
|
|
- public SysUserOrderAuthor selectSysUserOrderAuthorById(Long authorId) {
|
|
|
+ public SysUserOrderAuthor selectSysUserOrderAuthorById(Long authorId)
|
|
|
+ {
|
|
|
return sysUserOrderAuthorMapper.selectSysUserOrderAuthorById(authorId);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查询权限列表
|
|
|
- *
|
|
|
+ *
|
|
|
* @param sysUserOrderAuthor 权限
|
|
|
* @return 权限
|
|
|
*/
|
|
|
@Override
|
|
|
- public List<SysUserOrderAuthor> selectSysUserOrderAuthorList(SysUserOrderAuthor sysUserOrderAuthor) {
|
|
|
+ public List<SysUserOrderAuthor> selectSysUserOrderAuthorList(SysUserOrderAuthor sysUserOrderAuthor)
|
|
|
+ {
|
|
|
return sysUserOrderAuthorMapper.selectSysUserOrderAuthorList(sysUserOrderAuthor);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 新增权限
|
|
|
- *
|
|
|
+ *
|
|
|
* @param sysUserOrderAuthor 权限
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public int insertSysUserOrderAuthor(SysUserOrderAuthor sysUserOrderAuthor) {
|
|
|
+ public int insertSysUserOrderAuthor(SysUserOrderAuthor sysUserOrderAuthor)
|
|
|
+ {
|
|
|
sysUserOrderAuthor.setCreateTime(DateUtils.getNowDate());
|
|
|
return sysUserOrderAuthorMapper.insertSysUserOrderAuthor(sysUserOrderAuthor);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 修改权限
|
|
|
- *
|
|
|
+ *
|
|
|
* @param sysUserOrderAuthor 权限
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public int updateSysUserOrderAuthor(SysUserOrderAuthor sysUserOrderAuthor) {
|
|
|
+ public int updateSysUserOrderAuthor(SysUserOrderAuthor sysUserOrderAuthor)
|
|
|
+ {
|
|
|
sysUserOrderAuthor.setUpdateTime(DateUtils.getNowDate());
|
|
|
return sysUserOrderAuthorMapper.updateSysUserOrderAuthor(sysUserOrderAuthor);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 删除权限对象
|
|
|
- *
|
|
|
+ *
|
|
|
* @param ids 需要删除的数据ID
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public int deleteSysUserOrderAuthorByIds(String ids) {
|
|
|
+ public int deleteSysUserOrderAuthorByIds(String ids)
|
|
|
+ {
|
|
|
return sysUserOrderAuthorMapper.deleteSysUserOrderAuthorByIds(Convert.toStrArray(ids));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 删除权限信息
|
|
|
- *
|
|
|
+ *
|
|
|
* @param authorId 权限ID
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public int deleteSysUserOrderAuthorById(Long authorId) {
|
|
|
+ public int deleteSysUserOrderAuthorById(Long authorId)
|
|
|
+ {
|
|
|
return sysUserOrderAuthorMapper.deleteSysUserOrderAuthorById(authorId);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public int insertRel(SysUserAuthorRel role) {
|
|
|
+ @Transactional
|
|
|
+ public int insertRel(SysUserAuthorRel role)
|
|
|
+ {
|
|
|
+ /*1、查询所有一级节点*/
|
|
|
+ String identity = "";
|
|
|
+ SysUserExt sysUserExt = new SysUserExt();
|
|
|
+ sysUserExt.setUserId(role.getUserId());
|
|
|
+ for (Long authorId : role.getAuthorIds()){
|
|
|
+ SysUserOrderAuthor sysUserOrderAuthor = sysUserOrderAuthorMapper.selectSysUserOrderAuthorById(authorId);
|
|
|
+ if (sysUserOrderAuthor.getParentId()==1L){
|
|
|
+ if(UserIdentityUtil.UI_DIY_NAME.equals(sysUserOrderAuthor.getAuthorName())){
|
|
|
+ identity+=UserIdentityUtil.UI_DIY+",";
|
|
|
+ }else if(UserIdentityUtil.UI_CW_NAME.equals(sysUserOrderAuthor.getAuthorName())){
|
|
|
+ identity+=UserIdentityUtil.UI_CW+",";
|
|
|
+ }else if(UserIdentityUtil.UI_YSL_NAME.equals(sysUserOrderAuthor.getAuthorName())){
|
|
|
+ identity+=UserIdentityUtil.UI_YSL+",";
|
|
|
+ }else if(UserIdentityUtil.UI_FC_NAME.equals(sysUserOrderAuthor.getAuthorName())){
|
|
|
+ identity+=UserIdentityUtil.UI_FC+",";
|
|
|
+ }else if(UserIdentityUtil.UI_XLS_NAME.equals(sysUserOrderAuthor.getAuthorName())){
|
|
|
+ identity+=UserIdentityUtil.UI_XLS+",";
|
|
|
+ }else if(UserIdentityUtil.UI_SAF_NAME.equals(sysUserOrderAuthor.getAuthorName())){
|
|
|
+ identity+=UserIdentityUtil.UI_SAF+",";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!"".equals(identity)) {
|
|
|
+ sysUserExt.setIdentity(identity.substring(0, identity.length() - 1));
|
|
|
+ }
|
|
|
+ /*判断节点对应身份进行人员身份修改*/
|
|
|
userAuthorRelMapper.deleteSysUserAuthorRelById(role.getUserId());
|
|
|
int rows = 1;
|
|
|
// 新增角色与部门(数据权限)管理
|
|
|
List<SysUserAuthorRel> list = new ArrayList<SysUserAuthorRel>();
|
|
|
- for (Long authorId : role.getAuthorIds()) {
|
|
|
+ for (Long authorId : role.getAuthorIds())
|
|
|
+ {
|
|
|
SysUserAuthorRel rd = new SysUserAuthorRel();
|
|
|
rd.setUserId(role.getUserId());
|
|
|
rd.setAuthorId(authorId);
|
|
|
list.add(rd);
|
|
|
}
|
|
|
- if (list.size() > 0) {
|
|
|
+ if (list.size() > 0)
|
|
|
+ {
|
|
|
rows = userAuthorRelMapper.batchRel(list);
|
|
|
+ if (!"".equals(identity)) {
|
|
|
+ rows = userExtMapper.updateSysUserExt(sysUserExt);
|
|
|
+ }
|
|
|
}
|
|
|
return rows;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查询权限树列表
|
|
|
- *
|
|
|
+ *
|
|
|
* @return 所有权限信息
|
|
|
*/
|
|
|
@Override
|
|
|
- public List<Ztree> selectSysUserOrderAuthorTree() {
|
|
|
+ public List<Ztree> selectSysUserOrderAuthorTree()
|
|
|
+ {
|
|
|
List<SysUserOrderAuthor> sysUserOrderAuthorList = sysUserOrderAuthorMapper.selectSysUserOrderAuthorList(new SysUserOrderAuthor());
|
|
|
List<Ztree> ztrees = new ArrayList<Ztree>();
|
|
|
- for (SysUserOrderAuthor sysUserOrderAuthor : sysUserOrderAuthorList) {
|
|
|
+ for (SysUserOrderAuthor sysUserOrderAuthor : sysUserOrderAuthorList)
|
|
|
+ {
|
|
|
Ztree ztree = new Ztree();
|
|
|
ztree.setId(sysUserOrderAuthor.getAuthorId());
|
|
|
ztree.setpId(sysUserOrderAuthor.getParentId());
|
|
|
@@ -161,23 +205,23 @@ public class SysUserOrderAuthorServiceImpl implements ISysUserOrderAuthorService
|
|
|
}
|
|
|
|
|
|
//把一个List转成树
|
|
|
- static List<Ztree> buildTree(List<Ztree> list, Long pid) {
|
|
|
- List<Ztree> tree = new ArrayList<>();
|
|
|
- for (Ztree node : list) {
|
|
|
- if (Objects.equals(node.getpId(), pid)) {
|
|
|
- tree.add(findChild(node, list));
|
|
|
+ static List<Ztree> buildTree(List<Ztree> list,Long pid){
|
|
|
+ List<Ztree> tree=new ArrayList<>();
|
|
|
+ for(Ztree node:list){
|
|
|
+ if(Objects.equals(node.getpId(),pid)){
|
|
|
+ tree.add(findChild(node,list));
|
|
|
}
|
|
|
}
|
|
|
return tree;
|
|
|
}
|
|
|
|
|
|
- static Ztree findChild(Ztree node, List<Ztree> list) {
|
|
|
- for (Ztree n : list) {
|
|
|
- if (Objects.equals(n.getpId(), node.getId())) {
|
|
|
- if (node.getChildren() == null) {
|
|
|
+ static Ztree findChild(Ztree node, List<Ztree> list){
|
|
|
+ for(Ztree n:list){
|
|
|
+ if(Objects.equals(n.getpId(),node.getId())){
|
|
|
+ if(node.getChildren() == null){
|
|
|
node.setChildren(new ArrayList<Ztree>());
|
|
|
}
|
|
|
- node.getChildren().add(findChild(n, list));
|
|
|
+ node.getChildren().add(findChild(n,list));
|
|
|
}
|
|
|
}
|
|
|
return node;
|
|
|
@@ -185,21 +229,23 @@ public class SysUserOrderAuthorServiceImpl implements ISysUserOrderAuthorService
|
|
|
|
|
|
/**
|
|
|
* 对象转树
|
|
|
- *
|
|
|
* @param sysUserOrderAuthorList
|
|
|
* @return
|
|
|
*/
|
|
|
- public List<Ztree> initTree(List<SysUserOrderAuthor> sysUserOrderAuthorList, List<Long> roleMenuList) {
|
|
|
+ public List<Ztree> initTree(List<SysUserOrderAuthor> sysUserOrderAuthorList, List<Long> roleMenuList)
|
|
|
+ {
|
|
|
List<Ztree> ztrees = new ArrayList<Ztree>();
|
|
|
boolean isCheck = StringUtils.isNotNull(roleMenuList);
|
|
|
- for (SysUserOrderAuthor menu : sysUserOrderAuthorList) {
|
|
|
+ for (SysUserOrderAuthor menu : sysUserOrderAuthorList)
|
|
|
+ {
|
|
|
Ztree ztree = new Ztree();
|
|
|
ztree.setId(menu.getAuthorId());
|
|
|
ztree.setpId(menu.getParentId());
|
|
|
ztree.setName(menu.getAuthorName());
|
|
|
ztree.setTitle(menu.getAuthorName());
|
|
|
ztree.setCode(menu.getCode());
|
|
|
- if (isCheck) {
|
|
|
+ if (isCheck)
|
|
|
+ {
|
|
|
ztree.setChecked(roleMenuList.contains(menu.getAuthorId()));
|
|
|
}
|
|
|
ztree.setOpen(true);
|
|
|
@@ -208,71 +254,88 @@ public class SysUserOrderAuthorServiceImpl implements ISysUserOrderAuthorService
|
|
|
return ztrees;
|
|
|
}
|
|
|
|
|
|
- public void userAuthorTask() {
|
|
|
+ public void userAuthorTask(){
|
|
|
|
|
|
}
|
|
|
|
|
|
- public void getAuthorByLevel() {
|
|
|
+ public void getAuthorByLevel(){
|
|
|
List<SysUserOrderAuthor> list = sysUserOrderAuthorMapper.selectSysUserOrderAuthorList(new SysUserOrderAuthor());
|
|
|
List<Long> ids = new ArrayList<>();
|
|
|
getParentAuthor(ids, list, 8l);
|
|
|
System.out.println(ids);
|
|
|
}
|
|
|
|
|
|
- public void getParentAuthor(List<Long> ids, List<SysUserOrderAuthor> list, Long id) {
|
|
|
+ public void getParentAuthor(List<Long> ids, List<SysUserOrderAuthor> list, Long id){
|
|
|
for (SysUserOrderAuthor sysUserOrderAuthor : list) {
|
|
|
Long itemId = sysUserOrderAuthor.getAuthorId();
|
|
|
- if (itemId.equals(0l)) {
|
|
|
+ if(itemId.equals(0l)){
|
|
|
ids.add(itemId);
|
|
|
- } else if (itemId.equals(id)) {
|
|
|
+ }else if(itemId.equals(id)){
|
|
|
ids.add(itemId);
|
|
|
- getParentAuthor(ids, list, sysUserOrderAuthor.getParentId());
|
|
|
+ getParentAuthor(ids, list , sysUserOrderAuthor.getParentId());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void initUserAuthor() {
|
|
|
- List<SysUserOrderAuthor> userOrderAuthorList = new ArrayList<>();
|
|
|
- List<SysUserOrderAuthor> userOrderAuthorDiyList = sysUserOrderAuthorMapper.selectAuthorIdByCode("tuc_diy");
|
|
|
- List<SysUserOrderAuthor> userOrderAuthorCwList = sysUserOrderAuthorMapper.selectAuthorIdByCode("tuc_cw");
|
|
|
- List<SysUserOrderAuthor> userOrderAuthorYSLList = sysUserOrderAuthorMapper.selectAuthorIdByCode("YSL");
|
|
|
+ List<SysUserOrderAuthor> userOrderAuthorList=new ArrayList<>();
|
|
|
+ List<SysUserOrderAuthor> userOrderAuthorDiyList=sysUserOrderAuthorMapper.selectAuthorIdByCode("tuc_diy");
|
|
|
+ List<SysUserOrderAuthor> userOrderAuthorCwList=sysUserOrderAuthorMapper.selectAuthorIdByCode("tuc_cw");
|
|
|
+ List<SysUserOrderAuthor> userOrderAuthorYSLList=sysUserOrderAuthorMapper.selectAuthorIdByCode("YSL");
|
|
|
userExtMapper.selectUserExtList().forEach(sysUserExt -> {
|
|
|
- String sales = sysUserExt.getSalesLevel();
|
|
|
- if (sales == null) {
|
|
|
- sales = "diy_level";
|
|
|
+ String sales=sysUserExt.getSalesLevel();
|
|
|
+ if(sales==null){
|
|
|
+ sales="diy_level";
|
|
|
}
|
|
|
int index = sales.indexOf("_");
|
|
|
- String intNumber = sales.substring(0, index);
|
|
|
- if (intNumber.equals("cw")) {
|
|
|
- userOrderAuthorList.clear();
|
|
|
+ String intNumber = sales.substring(0,index);
|
|
|
+ if(intNumber.equals("cw")){
|
|
|
userOrderAuthorList.addAll(userOrderAuthorCwList);
|
|
|
- } else if (intNumber.equals("diy")) {
|
|
|
- userOrderAuthorList.clear();
|
|
|
+ }else if(intNumber.equals("diy")){
|
|
|
userOrderAuthorList.addAll(userOrderAuthorDiyList);
|
|
|
- } else if (intNumber.equals("ysl")) {
|
|
|
- userOrderAuthorList.clear();
|
|
|
+ }else if(intNumber.equals("ysl")){
|
|
|
userOrderAuthorList.addAll(userOrderAuthorYSLList);
|
|
|
}
|
|
|
- List<SysUserAuthorRel> user = userAuthorRelMapper.selectSysUserAuthorRelListById(sysUserExt.getUserId());
|
|
|
- if (user.size() == 0) {
|
|
|
- SysUserAuthorRel role = new SysUserAuthorRel();
|
|
|
- role.setUserId(sysUserExt.getUserId());
|
|
|
- role.setAuthorId(userOrderAuthorList.get(0).getParentId());
|
|
|
- userAuthorRelMapper.insertSysUserAuthorRel(role);
|
|
|
- List<SysUserOrderAuthor> OrderAuthorList = sysUserOrderAuthorMapper.selectAuthorIdByParentId(userOrderAuthorList.get(0).getParentId());
|
|
|
- if (OrderAuthorList.size() > 0) {
|
|
|
- for (SysUserOrderAuthor sys : OrderAuthorList
|
|
|
- ) {
|
|
|
- SysUserAuthorRel roleUser = new SysUserAuthorRel();
|
|
|
- roleUser.setUserId(sysUserExt.getUserId());
|
|
|
- roleUser.setAuthorId(sys.getAuthorId());
|
|
|
- userAuthorRelMapper.insertSysUserAuthorRel(roleUser);
|
|
|
+ List<SysUserOrderAuthor> ordList=new ArrayList<>();
|
|
|
+ for (int i = 0; i < userOrderAuthorList.size(); i++) {
|
|
|
+ if( !userOrderAuthorList.get(i).getAuthorId().equals(userOrderAuthorList.get(0).getParentId())){
|
|
|
+ if(i==0){
|
|
|
+ List<SysUserAuthorRel> user=userAuthorRelMapper.selectSysUserAuthorRelListById(sysUserExt.getUserId());
|
|
|
+ if(user.size()>0){
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ SysUserOrderAuthor userOrderAuthor=new SysUserOrderAuthor();
|
|
|
+ userOrderAuthor.setAuthorId(userOrderAuthorList.get(0).getParentId());
|
|
|
+ userOrderAuthor.setParentId(userOrderAuthorList.get(0).getParentId());
|
|
|
+ ordList.add(userOrderAuthor);
|
|
|
+ ordList.removeAll(userOrderAuthorList);
|
|
|
+ ordList.addAll(userOrderAuthorList);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<SysUserOrderAuthor> OrderAuthorList= sysUserOrderAuthorMapper.selectAuthorIdByParentId(userOrderAuthorList.get(i).getAuthorId());
|
|
|
+ if(OrderAuthorList.size()>0){
|
|
|
+ HashSet<SysUserOrderAuthor> set = new HashSet<>(ordList);
|
|
|
+ ordList.clear();
|
|
|
+ set.addAll(OrderAuthorList);
|
|
|
+ ArrayList list=new ArrayList<>(set);
|
|
|
+ ordList.addAll(list);
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ continue;
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
+ if(ordList.size()>0){
|
|
|
+ ordList.forEach(author->{
|
|
|
+ SysUserAuthorRel role=new SysUserAuthorRel();
|
|
|
+ role.setUserId(sysUserExt.getUserId());
|
|
|
+ role.setAuthorId(author.getAuthorId());
|
|
|
+ userAuthorRelMapper.insertSysUserAuthorRel(role);
|
|
|
+ });
|
|
|
+ }
|
|
|
});
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
-}
|
|
|
|
|
|
}
|