jinpengyong
2023-08-25 f9f8f90ac63d6ce3274410d3721b173f40db6e41
screen-manage/src/main/java/com/moral/api/service/impl/ManageRoleMenuServiceImpl.java
@@ -13,17 +13,17 @@
import com.moral.api.util.LogUtils;
import com.moral.constant.Constants;
import com.moral.constant.ResponseCodeEnum;
import com.moral.util.TokenUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
/**
 * <p>
@@ -45,12 +45,19 @@
    @Autowired(required = false)
    private ManageRoleMapper manageRoleMapper;
    @Autowired
    LogUtils logUtils;
    @Override
    @Transactional
    public Map<String, Object> updateRoleMenu(List list, int id) {
    public Map<String, Object> updateRoleMenu(List menuList, int id) {
        //补充父菜单
        List supplementList = new ArrayList();
        supplementList.addAll(menuList);
        for (int i=0;i<supplementList.size();i++) {
            supplementList.addAll(supplementParentMenus(Integer.parseInt(supplementList.get(i).toString())));
        }
        LinkedHashSet<Object> hashSet = new LinkedHashSet<>(supplementList);
        ArrayList<Object> list = new ArrayList<>(hashSet);
        //return null;
        Map<String,Object> resultMap = new HashMap<>();
        List<ManageMenu> manageMenusOld = manageMenuMapper.getManageMenuByRoleId(id);
        QueryWrapper<ManageRoleMenu> wrapper = new QueryWrapper();
@@ -88,7 +95,6 @@
                    continue;
                }
                updateList.add(manageRoleMenu.get("menu_id"));
                System.out.println("++++++++++++++"+updateList);
            }
            List insertList = new ArrayList();
            for (Object temp:list) {
@@ -118,6 +124,8 @@
                manageRoleMenuMapper.insertBatch(mapList);
            }
        }
        //注销token
        TokenUtils.destoryToken(id);
        List<ManageMenu> manageMenusNew = manageMenuMapper.getManageMenuByRoleId(id);
        List manageMenuOldList = new ArrayList();
        List manageMenuNewList = new ArrayList();
@@ -139,9 +147,26 @@
            manageMenuNewList.add("空");
        }
        content = content+"菜单:"+manageMenuOldList+"->"+manageMenuNewList+";";
        logUtils.saveOperationForManage(request,content,Constants.UPDATE_OPERATE_TYPE);
        LogUtils.saveOperationForManage(request,content,Constants.UPDATE_OPERATE_TYPE);
        resultMap.put("code",ResponseCodeEnum.SUCCESS.getCode());
        resultMap.put("msg",ResponseCodeEnum.SUCCESS.getMsg());
        return resultMap;
    }
    /**
     * @Description: 补充父菜单
     * @Param: [list, menuId]list:menuId集合
     * @return: void
     * @Author: 李子杰
     * @Date: 2021/4/7
     */
    private List supplementParentMenus(int menuId) {
        List list = new ArrayList();
        ManageMenu manageMenu = manageMenuMapper.getManageMenuById(menuId);
        if (manageMenu.getParentId()!=0){
            list.add(manageMenu.getParentId());
            list.addAll(supplementParentMenus(manageMenu.getParentId()));
        }
        return list;
    }
}