|
@@ -15,6 +15,7 @@ import com.huimv.admin.mapper.MenuMapper;
|
|
import com.huimv.admin.service.IAuthorizeService;
|
|
import com.huimv.admin.service.IAuthorizeService;
|
|
import com.huimv.admin.common.utils.Result;
|
|
import com.huimv.admin.common.utils.Result;
|
|
import com.huimv.admin.common.utils.ResultCode;
|
|
import com.huimv.admin.common.utils.ResultCode;
|
|
|
|
+import com.huimv.admin.service.IGroupMenuService;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
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;
|
|
@@ -32,6 +33,8 @@ public class AuthorizeServiceImpl implements IAuthorizeService {
|
|
@Autowired
|
|
@Autowired
|
|
GroupMenuMapper groupMenuMapper;
|
|
GroupMenuMapper groupMenuMapper;
|
|
@Autowired
|
|
@Autowired
|
|
|
|
+ IGroupMenuService groupMenuService;
|
|
|
|
+ @Autowired
|
|
private MenuMapper menuMapper;
|
|
private MenuMapper menuMapper;
|
|
@Autowired
|
|
@Autowired
|
|
private FarmMapper farmMapper;
|
|
private FarmMapper farmMapper;
|
|
@@ -73,65 +76,55 @@ public class AuthorizeServiceImpl implements IAuthorizeService {
|
|
* Step1:先删除原先的权限组关联菜单数据;
|
|
* Step1:先删除原先的权限组关联菜单数据;
|
|
* Step2:再添加新的账号权限组关联菜单数据;
|
|
* Step2:再添加新的账号权限组关联菜单数据;
|
|
*/
|
|
*/
|
|
- QueryWrapper<GroupMenu> queryWrapper = new QueryWrapper<>();
|
|
|
|
- queryWrapper.eq(StringUtils.isNotBlank(groupId),"group_id",groupId);
|
|
|
|
- groupMenuMapper.delete(queryWrapper);
|
|
|
|
- if (com.baomidou.mybatisplus.core.toolkit.StringUtils.isNotBlank(menuIds)) {
|
|
|
|
|
|
+ groupMenuMapper.removeGroupMenu(groupId);
|
|
|
|
+ if (StringUtils.isNotBlank(menuIds)){
|
|
String[] menuIdsArray = menuIds.split(",");
|
|
String[] menuIdsArray = menuIds.split(",");
|
|
String[] split = isAll.split(",");
|
|
String[] split = isAll.split(",");
|
|
- boolean isAlla = StringUtils.isNotBlank(isAll);
|
|
|
|
|
|
+
|
|
|
|
+ List<GroupMenu> list = new ArrayList();
|
|
for (int a = 0; a < menuIdsArray.length; a++) {
|
|
for (int a = 0; a < menuIdsArray.length; a++) {
|
|
GroupMenu groupMenu = new GroupMenu();
|
|
GroupMenu groupMenu = new GroupMenu();
|
|
groupMenu.setGroupId(Integer.parseInt(groupId));
|
|
groupMenu.setGroupId(Integer.parseInt(groupId));
|
|
groupMenu.setMenuId(Integer.parseInt(menuIdsArray[a]));
|
|
groupMenu.setMenuId(Integer.parseInt(menuIdsArray[a]));
|
|
- if (isAlla){
|
|
|
|
|
|
+ list.add(groupMenu);
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isNotBlank(isAll)){
|
|
|
|
+ for (GroupMenu groupMenu : list) {
|
|
for (String s : split) {
|
|
for (String s : split) {
|
|
- if (groupMenu.getMenuId() == Integer.parseInt(s)) {
|
|
|
|
|
|
+ if (groupMenu.getMenuId()== Integer.parseInt(s)){
|
|
groupMenu.setIsAll(1);
|
|
groupMenu.setIsAll(1);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- groupMenuMapper.insert(groupMenu);
|
|
|
|
}
|
|
}
|
|
|
|
+ groupMenuService.saveBatch(list);
|
|
}
|
|
}
|
|
- return ResultUtil.getResult(1);
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ return new Result(10000, "保存权限组关联菜单成功", true);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public Result getMenuByGroup(Map paramsMap) {
|
|
public Result getMenuByGroup(Map paramsMap) {
|
|
- String groupId = (String) paramsMap.get("groupId");
|
|
|
|
- String isAll = (String)paramsMap.get("isAll");
|
|
|
|
- String[] isAllArray = isAll.split(",");
|
|
|
|
- String menuIds = (String)paramsMap.get("menuIds");
|
|
|
|
- String[] menuArray = menuIds.split(",");
|
|
|
|
- // 过滤上级菜单id
|
|
|
|
- List<String> menuList = new ArrayList();
|
|
|
|
- for(int a=0;a<menuArray.length;a++){
|
|
|
|
- boolean isExist = false;
|
|
|
|
- for(int b=0;b<isAllArray.length;b++){
|
|
|
|
- if(menuArray[a].trim().equalsIgnoreCase(isAllArray[b])){
|
|
|
|
- isExist = true;
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if(!isExist){
|
|
|
|
- menuList.add(menuArray[a]);
|
|
|
|
- }
|
|
|
|
|
|
+ String groupId = (String)paramsMap.get("groupId");
|
|
|
|
+ QueryWrapper<GroupMenu> groupMenuQueryWrapper = new QueryWrapper<>();
|
|
|
|
+ groupMenuQueryWrapper.eq("group_id",groupId);
|
|
|
|
+ groupMenuQueryWrapper.eq("is_all",0);
|
|
|
|
+ List<GroupMenu> groupMenuEntityList = groupMenuMapper.selectList(groupMenuQueryWrapper);
|
|
|
|
+ if (groupMenuEntityList.size() == 0) {
|
|
|
|
+ return new Result(10005, "当前权限组暂未关联任何菜单.", false);
|
|
}
|
|
}
|
|
- //-- 删除权限组绑定才菜单 --//
|
|
|
|
- QueryWrapper<GroupMenu> queryWrapper = new QueryWrapper<>();
|
|
|
|
- queryWrapper.eq(StringUtils.isNotBlank(groupId),"group_id",groupId);
|
|
|
|
- groupMenuMapper.delete(queryWrapper);
|
|
|
|
- //-- 新增权限组绑定菜单 --//
|
|
|
|
- int rows = 0;
|
|
|
|
- for(int a=0;a<menuList.size();a++){
|
|
|
|
- GroupMenu newGroupMenu = new GroupMenu();
|
|
|
|
- newGroupMenu.setGroupId(Integer.parseInt(groupId));
|
|
|
|
- newGroupMenu.setMenuId(Integer.parseInt(menuList.get(a)));
|
|
|
|
- rows += groupMenuMapper.insert(newGroupMenu);
|
|
|
|
|
|
+ StringBuilder stringBuffer = new StringBuilder();
|
|
|
|
+
|
|
|
|
+ for (GroupMenu groupMenu : groupMenuEntityList) {
|
|
|
|
+
|
|
|
|
+ stringBuffer.append(groupMenu.getMenuId());
|
|
|
|
+ stringBuffer.append(",");
|
|
|
|
+
|
|
}
|
|
}
|
|
- return ResultUtil.getResult(rows);
|
|
|
|
|
|
+ stringBuffer.deleteCharAt(stringBuffer.length()-1);
|
|
|
|
+ return new Result(ResultCode.SUCCESS, stringBuffer.toString());
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -146,19 +139,22 @@ public class AuthorizeServiceImpl implements IAuthorizeService {
|
|
List<String> list = Arrays.asList(farmMenu);
|
|
List<String> list = Arrays.asList(farmMenu);
|
|
QueryWrapper<GroupMenu> queryWrapper = new QueryWrapper<>();
|
|
QueryWrapper<GroupMenu> queryWrapper = new QueryWrapper<>();
|
|
queryWrapper.eq(StringUtils.isNotBlank(groupId),"group_id",groupId);
|
|
queryWrapper.eq(StringUtils.isNotBlank(groupId),"group_id",groupId);
|
|
- queryWrapper.in("group_id",list);
|
|
|
|
- List<GroupMenu> sysGroupMenuList = groupMenuMapper.selectList(queryWrapper);
|
|
|
|
- if(sysGroupMenuList.size() == 0){
|
|
|
|
- return new Result(ConstUtil.ERR_MYMENU_EMPTY_CODE,ConstUtil.ERR_MYMENU_EMPTY_INFO,false);
|
|
|
|
|
|
+ queryWrapper.in("menu_id",list);
|
|
|
|
+// queryWrapper.eq("is_all",0);
|
|
|
|
+ List<GroupMenu> groupMenuEntityList = groupMenuMapper.selectList(queryWrapper);
|
|
|
|
+ if (groupMenuEntityList.size() == 0) {
|
|
|
|
+ return new Result(10005, "当前权限组暂未关联任何菜单.", false);
|
|
}
|
|
}
|
|
- StringBuilder menuIdSb = new StringBuilder();
|
|
|
|
- for(GroupMenu groupMenu:sysGroupMenuList){
|
|
|
|
- menuIdSb.append(groupMenu.getMenuId());
|
|
|
|
- if(menuIdSb.length()>0){
|
|
|
|
- menuIdSb.append(",");
|
|
|
|
- }
|
|
|
|
|
|
+ StringBuilder stringBuffer = new StringBuilder();
|
|
|
|
+
|
|
|
|
+ for (GroupMenu groupMenu : groupMenuEntityList) {
|
|
|
|
+
|
|
|
|
+ stringBuffer.append(groupMenu.getMenuId());
|
|
|
|
+ stringBuffer.append(",");
|
|
|
|
+
|
|
}
|
|
}
|
|
- return new Result(ResultCode.SUCCESS,menuIdSb.toString());
|
|
|
|
|
|
+ stringBuffer.deleteCharAt(stringBuffer.length()-1);
|
|
|
|
+ return new Result(ResultCode.SUCCESS, stringBuffer.toString());
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -205,16 +201,22 @@ public class AuthorizeServiceImpl implements IAuthorizeService {
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public List getMyMenuAll(String accountName) {
|
|
|
|
|
|
+ public List getMyMenuAll(String accountName,String farmId) {
|
|
if ("1".equals(accountName)){
|
|
if ("1".equals(accountName)){
|
|
List<Menu> menus = menuMapper.selectList(new QueryWrapper<Menu>().orderByAsc("sort"));
|
|
List<Menu> menus = menuMapper.selectList(new QueryWrapper<Menu>().orderByAsc("sort"));
|
|
return menus;
|
|
return menus;
|
|
}
|
|
}
|
|
- return menuMapper.getMyMenu(accountName);
|
|
|
|
|
|
+ Farm farm = farmMapper.selectById(farmId);
|
|
|
|
+ String farmMenu = farm.getFarmMenu();
|
|
|
|
+ String[] farmMenus = farmMenu.split(",");
|
|
|
|
+// List<String> farmMenus = Arrays.asList(farmMenu);
|
|
|
|
+ return menuMapper.getMyMenu(accountName,farmMenus);
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public List<String> getMyButton(Integer userId) {
|
|
|
|
|
|
+ public List<String> getMyButton(Integer userId, Integer farmId) {
|
|
|
|
+ Farm farm = farmMapper.selectById(farmId);
|
|
|
|
+ String farmMenu = farm.getFarmMenu();
|
|
if (userId == 1){
|
|
if (userId == 1){
|
|
List<Menu> menus = menuMapper.selectList(null);
|
|
List<Menu> menus = menuMapper.selectList(null);
|
|
List<String> list = new ArrayList<>();
|
|
List<String> list = new ArrayList<>();
|
|
@@ -223,7 +225,8 @@ public class AuthorizeServiceImpl implements IAuthorizeService {
|
|
}
|
|
}
|
|
return list;
|
|
return list;
|
|
}
|
|
}
|
|
- return menuMapper.getMyButton(userId);
|
|
|
|
|
|
+ String[] menus = farmMenu.split(",");
|
|
|
|
+ return menuMapper.getMyButton(userId,menus);
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|