Commit 26c85420 authored by 赵啸非's avatar 赵啸非

添加菜单资源配置

parent 2a223ab3
......@@ -16,6 +16,7 @@ import com.mortals.framework.service.ICRUDService;
import com.mortals.xhx.base.system.resource.model.ResourceEntity;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
......@@ -49,4 +50,8 @@ public interface ResourceService extends ICRUDService<ResourceEntity,Long> {
Rest<String> refreshResourceUrl(String packageName, Context context);
Map<String, List<ResourceEntity>> group(Long roleId, Context context);
}
\ No newline at end of file
......@@ -23,6 +23,7 @@ import com.mortals.xhx.base.system.resource.service.ResourceService;
import com.mortals.xhx.base.system.role.model.RoleAuthEntity;
import com.mortals.xhx.base.system.role.model.RoleAuthQuery;
import com.mortals.xhx.base.system.role.service.RoleAuthService;
import com.mortals.xhx.common.code.YesNoEnum;
import com.mortals.xhx.common.key.RedisKey;
import com.mortals.xhx.common.utils.ControllerScanUtil;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -68,7 +69,7 @@ public class ResourceServiceImpl extends AbstractCRUDServiceImpl<ResourceDao, Re
continue;
}
urls.add(url);
// url = url.replaceAll(",", ",");
// url = url.replaceAll(",", ",");
}
return urls;
}
......@@ -128,6 +129,30 @@ public class ResourceServiceImpl extends AbstractCRUDServiceImpl<ResourceDao, Re
return Rest.ok();
}
@Override
public Map<String, List<ResourceEntity>> group(Long roleId, Context context) {
if (!ObjectUtils.isEmpty(roleId)) {
List<RoleAuthEntity> roleAuthEntities = roleAuthService.find(new RoleAuthQuery().roleId(roleId));
Set<Long> collect = roleAuthEntities.stream()
.filter(f -> f.getMenuId() == null)
.map(m -> m.getResourceId())
.collect(Collectors.toSet());
Map<String, List<ResourceEntity>> group = this.find(new ResourceQuery(), context).stream()
.map(m -> {
if (collect.contains(m.getId())) {
m.setChecked(YesNoEnum.YES.getValue());
}
return m;
})
.collect(Collectors.groupingBy(x -> x.getGroupName()));
return group;
}
Map<String, List<ResourceEntity>> group = this.find(new ResourceQuery(), context).stream()
.collect(Collectors.groupingBy(x -> x.getGroupName()));
return group;
}
private void saveUpdateResourceEntity(Context context, Map<String, List<ResourceEntity>> localResourceMap, ResourceEntity resourceEntity) {
//查找 本地是否已经存在了
List<ResourceEntity> tempResourceList = localResourceMap.getOrDefault(resourceEntity.getUrl(), new ArrayList<>());
......
......@@ -101,26 +101,8 @@ public class ResourceController extends BaseCRUDJsonBodyMappingController<Resour
Map<String, Object> model = new HashMap<>();
String busiDesc = "查询" + this.getModuleDesc() + "子节点";
try {
if (!ObjectUtils.isEmpty(query.getRoleId())) {
List<RoleAuthEntity> roleAuthEntities = roleAuthService.find(new RoleAuthQuery().roleId(query.getRoleId()));
Set<Long> collect = roleAuthEntities.stream()
.filter(f -> f.getMenuId() == null)
.map(m -> m.getResourceId())
.collect(Collectors.toSet());
Map<String, List<ResourceEntity>> group = this.service.find(new ResourceQuery(), getContext()).stream()
.map(m -> {
if (collect.contains(m.getId())) {
m.setChecked(YesNoEnum.YES.getValue());
}
return m;
})
.collect(Collectors.groupingBy(x -> x.getGroupName()));
model.put(KEY_RESULT_DATA, group);
}else{
Map<String, List<ResourceEntity>> group = this.service.find(new ResourceQuery(), getContext()).stream()
.collect(Collectors.groupingBy(x -> x.getGroupName()));
model.put(KEY_RESULT_DATA, group);
}
Map<String, List<ResourceEntity>> group = this.service.group(query.getRoleId(), getContext());
model.put(KEY_RESULT_DATA, group);
ret.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS);
ret.put(KEY_RESULT_DATA, model);
recordSysLog(request, busiDesc + "【成功】");
......
......@@ -3,15 +3,23 @@ package com.mortals.xhx.base.system.role.web;
import com.alibaba.fastjson.JSONObject;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.base.system.resource.model.ResourceEntity;
import com.mortals.xhx.base.system.resource.service.ResourceService;
import com.mortals.xhx.base.system.role.model.RoleAuthEntity;
import com.mortals.xhx.base.system.role.model.RoleAuthQuery;
import com.mortals.xhx.base.system.role.service.RoleAuthService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 角色资源权限
*
......@@ -23,6 +31,9 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping("role/auth")
public class RoleAuthController extends BaseCRUDJsonBodyMappingController<RoleAuthService, RoleAuthEntity, Long> {
@Autowired
private ResourceService resourceService;
public RoleAuthController() {
super.setModuleDesc("角色资源权限");
}
......@@ -33,7 +44,7 @@ public class RoleAuthController extends BaseCRUDJsonBodyMappingController<RoleAu
@PostMapping(value = "distributionSource")
public String distributionSource(@RequestBody RoleAuthQuery query) {
try {
service.doDistributionSource(query,this.getContext());
service.doDistributionSource(query, this.getContext());
JSONObject ret = new JSONObject();
ret.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS);
return ret.toJSONString();
......@@ -52,7 +63,7 @@ public class RoleAuthController extends BaseCRUDJsonBodyMappingController<RoleAu
@PostMapping(value = "distributionMenu")
public String distributionMenu(@RequestBody RoleAuthQuery query) {
try {
service.doDistributionMenu(query,this.getContext());
service.doDistributionMenu(query, this.getContext());
JSONObject ret = new JSONObject();
ret.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS);
return ret.toJSONString();
......@@ -67,17 +78,18 @@ public class RoleAuthController extends BaseCRUDJsonBodyMappingController<RoleAu
/**
* 根据色编辑菜单
* 根据色编辑菜单
*/
@ApiOperation(value = "根据角色编辑菜单")
@PostMapping(value = "editMenu")
public String editMenu(@RequestBody RoleAuthQuery query) {
try {
service.editMenu(query,this.getContext());
service.editMenu(query, this.getContext());
JSONObject ret = new JSONObject();
ret.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS);
return ret.toJSONString();
} catch (Exception e) {
log.error("分配角色资源错误", e);
log.error("角色编辑菜单错误", e);
JSONObject ret = new JSONObject();
ret.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE);
ret.put(KEY_RESULT_MSG, super.convertException(e));
......@@ -85,4 +97,27 @@ public class RoleAuthController extends BaseCRUDJsonBodyMappingController<RoleAu
}
}
/**
* 根据角色编辑资源
*/
@ApiOperation(value = "根据角色编辑资源")
@PostMapping(value = "editResource")
public String editResource(@RequestBody RoleAuthQuery query) {
JSONObject ret = new JSONObject();
Map<String, Object> model = new HashMap<>();
try {
Map<String, List<ResourceEntity>> group = resourceService.group(query.getRoleId(), getContext());
model.put(KEY_RESULT_DATA, group);
ret.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS);
ret.put(KEY_RESULT_DATA, model);
ret.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS);
return ret.toJSONString();
} catch (Exception e) {
log.error("角色编辑资源错误", e);
ret.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE);
ret.put(KEY_RESULT_MSG, super.convertException(e));
return ret.toJSONString();
}
}
}
\ No newline at end of file
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