Commit 597cce4f authored by 赵啸非's avatar 赵啸非

修改部分权限

parent 694557ea
/**
* 文件:ResourceController.java
* 版本:1.0.0
* 日期:
* Copyright ®
* All right reserved.
*/
package com.mortals.xhx.base.system.resource.web;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.alibaba.fastjson.JSONObject;
import com.mortals.framework.common.IBaseEnum;
import com.mortals.framework.common.code.UserType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.alibaba.fastjson.JSONObject;
import com.mortals.framework.model.Context;
import com.mortals.framework.web.BaseCRUDJsonMappingController;
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.common.code.AuthType;
import com.mortals.xhx.common.code.SourceType;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.Map;
/**
* <p>Title: 资源信息</p>
* <p>Description: ResourceController </p>
* <p>Copyright: Copyright &reg; </p>
* <p>Company: </p>
* @author
* @version 1.0.0
* 资源信息
*
* @author: zxfei
* @date: 2022/5/7 15:27
*/
@Slf4j
@RestController
@RequestMapping("resource")
public class ResourceController extends BaseCRUDJsonMappingController<ResourceService,ResourceForm,ResourceEntity,Long> {
public class ResourceController extends BaseCRUDJsonBodyMappingController<ResourceService,ResourceEntity,Long> {
public ResourceController(){
super.setFormClass(ResourceForm.class);
super.setModuleDesc("资源信息");
}
@Override
protected void init(HttpServletRequest request, HttpServletResponse response, ResourceForm form,
Map<String, Object> model, Context context) {
protected void init(Map<String, Object> model, Context context) {
Map<String, Object> statsus = new HashMap<String, Object>();
statsus.put("authType", AuthType.getEnumMap());
statsus.put("sourceType", SourceType.getEnumMap());
......@@ -57,7 +44,6 @@ public class ResourceController extends BaseCRUDJsonMappingController<ResourceSe
statsus.put("userType", UserType.findByValue(getCurUser().getUserType()));
}
model.put(KEY_RESULT_DICT, statsus);
super.init(request, response, form, model, context);
}
/**
......
/**
* 文件:RoleAuthController.java
* 版本:1.0.0
* 日期:
* Copyright &reg;
* All right reserved.
*/
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.role.model.RoleAuthEntity;
import com.mortals.xhx.base.system.role.model.RoleAuthQuery;
import com.mortals.xhx.base.system.role.service.RoleAuthService;
import lombok.extern.slf4j.Slf4j;
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 com.mortals.framework.web.BaseCRUDJsonMappingController;
import com.mortals.xhx.base.system.role.model.RoleAuthEntity;
import com.mortals.xhx.base.system.role.service.RoleAuthService;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* <p>Title: 角色资源权限</p>
* <p>Description: RoleAuthController </p>
* <p>Copyright: Copyright &reg; </p>
* <p>Company: </p>
* @author
* @version 1.0.0
* 角色资源权限
*
* @author: zxfei
* @date: 2022/5/7 15:19
*/
@Slf4j
@RestController
@RequestMapping("role/auth")
public class RoleAuthController extends BaseCRUDJsonMappingController<RoleAuthService,RoleAuthForm,RoleAuthEntity,Long> {
public class RoleAuthController extends BaseCRUDJsonBodyMappingController<RoleAuthService, RoleAuthEntity, Long> {
public RoleAuthController() {
super.setModuleDesc("角色资源权限");
}
public RoleAuthController(){
super.setFormClass(RoleAuthForm.class);
super.setModuleDesc("角色资源权限");
}
/**
* 分配资源
*/
@PostMapping(value = "distributionSource")
public String distributionUser(@RequestBody RoleAuthQuery query) {
try {
service.doDistributionSource(query);
JSONObject ret = new JSONObject();
ret.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS);
return ret.toJSONString();
} catch (Exception e) {
log.error("分配角色资源错误", e);
JSONObject ret = new JSONObject();
ret.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE);
ret.put(KEY_RESULT_MSG, super.convertException(e));
return ret.toJSONString();
}
}
/**
* 分配资源
*/
@PostMapping(value = "distributionSource")
public String distributionUser(HttpServletRequest request, HttpServletResponse response, RoleAuthForm form) {
try {
service.doDistributionSource(form.getQuery());
JSONObject ret = new JSONObject();
ret.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS);
return ret.toJSONString();
} catch (Exception e) {
log.error("分配角色资源错误", e);
JSONObject ret = new JSONObject();
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
/**
* 文件:RoleController.java
* 版本:1.0.0
* 日期:
* Copyright &reg;
* All right reserved.
*/
package com.mortals.xhx.base.system.role.web;
......@@ -12,34 +5,28 @@ import com.alibaba.fastjson.JSONObject;
import com.mortals.framework.common.IBaseEnum;
import com.mortals.framework.common.code.UserType;
import com.mortals.framework.model.Context;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
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 com.mortals.framework.web.BaseCRUDJsonMappingController;
import com.mortals.xhx.base.system.role.model.RoleEntity;
import com.mortals.xhx.base.system.role.model.RoleUserEntity;
import com.mortals.xhx.base.system.role.service.RoleService;
import com.mortals.xhx.base.system.role.service.RoleUserService;
import com.mortals.xhx.common.code.RoleType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* <p>Title: 角色信息</p>
* <p>Description: RoleController </p>
* <p>Copyright: Copyright &reg; </p>
* <p>Company: </p>
* @author
* @version 1.0.0
* 角色信息
*
* @author: zxfei
* @date: 2022/5/7 15:15
*/
@RestController
@RequestMapping("role")
......@@ -49,23 +36,29 @@ public class RoleController extends BaseCRUDJsonBodyMappingController<RoleServic
private RoleUserService roleUserService;
public RoleController(){
super.setFormClass(RoleForm.class);
super.setModuleDesc("角色信息");
}
@Override
protected void init(Map<String, Object> model, Context context) {
this.addDict(model,"userType", IBaseEnum.getEnumMap(UserType.class));
this.addDict(model,"roleType", RoleType.getEnumMap());
super.init(model, context);
Map<String, Object> status = new HashMap<>();
status.put("userType", IBaseEnum.getEnumMap(UserType.class));
status.put("roleType", RoleType.getEnumMap());
model.put(KEY_RESULT_DICT, status);
}
/**
* 根据用户id获取角色名称
* @param userId
* @return
*/
@PostMapping("roleNameByUserId")
public String getRoleNameByUserId(@RequestBody RoleUserEntity query) {
public String getRoleNameByUserId(@RequestParam(value = "userId") Long userId) {
try{
JSONObject ret = new JSONObject();
RoleUserEntity roleUserEntity = new RoleUserEntity();
roleUserEntity.setUserId(query.getUserId());
roleUserEntity.setUserId(userId);
List<RoleUserEntity> find = roleUserService.find(roleUserEntity, new Context());
List<RoleEntity> model = new ArrayList<>();
if(find.size() > 0){
......
/**
* 文件:RoleUserController.java
* 版本:1.0.0
* 日期:
* Copyright &reg;
* All right reserved.
*/
package com.mortals.xhx.base.system.role.web;
import com.alibaba.fastjson.JSONObject;
......@@ -14,23 +7,22 @@ import com.mortals.framework.ap.SysConstains;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.BaseEntityLong;
import com.mortals.framework.model.Context;
import org.apache.commons.beanutils.MethodUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.mortals.framework.web.BaseCRUDJsonMappingController;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.base.system.role.model.RoleEntity;
import com.mortals.xhx.base.system.role.model.RoleUserEntity;
import com.mortals.xhx.base.system.role.model.RoleUserQuery;
import com.mortals.xhx.base.system.role.service.RoleService;
import com.mortals.xhx.base.system.role.service.RoleUserService;
import com.mortals.xhx.base.system.user.model.UserEntity;
import com.mortals.xhx.base.system.user.model.UserQuery;
import com.mortals.xhx.base.system.user.service.UserService;
import org.apache.commons.beanutils.MethodUtils;
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 javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -38,29 +30,49 @@ import java.util.Set;
import java.util.stream.Collectors;
/**
* <p>Title: 角色用户</p>
* <p>Description: RoleUserController </p>
* <p>Copyright: Copyright &reg; </p>
* <p>Company: </p>
* @author
* @version 1.0.0
* 角色用户
*
* @author: zxfei
* @date: 2022/5/7 15:15
*/
@RestController
@RequestMapping("role/user")
public class RoleUserController extends BaseCRUDJsonMappingController<RoleUserService,RoleUserForm,RoleUserEntity,Long> {
public class RoleUserController extends BaseCRUDJsonBodyMappingController<RoleUserService, RoleUserEntity, Long> {
@Autowired
private RoleService roleService;
@Autowired
private UserService userService;
public RoleUserController() {
super.setModuleDesc("角色用户");
}
@Autowired
private RoleService roleService;
@Autowired
private UserService userService;
@Override
protected void init(Map<String, Object> model, Context context) {
Map<String, Object> status = new HashMap<>(3);
status.put("roleId", roleService.find(new RoleEntity(), null).stream()
.collect(Collectors.toMap(e -> e.getId().toString(), RoleEntity::getName)));
List<RoleUserEntity> roleUserList = (List<RoleUserEntity>) model.get(SysConstains.RESULT_KEY);
if (roleUserList != null && roleUserList.size() > 0) {
List<Long> userIdsList = roleUserList.stream().map(RoleUserEntity::getUserId).collect(Collectors.toList());
List<UserEntity> userEntityList = userService.find(getQuery(UserQuery.class,
Sets.newHashSet("id", "realName", "loginName"), userIdsList.toArray(new Long[userIdsList.size()])), null);
if (userEntityList != null) {
status.put("userReNameMap",
userEntityList.stream().collect(Collectors.toMap(e -> e.getId().toString(), UserEntity::getRealName)));
status.put("userId",
userEntityList.stream().collect(Collectors.toMap(e -> e.getId().toString(), UserEntity::getLoginName)));
}
}
model.put(KEY_RESULT_DICT, status);
}
public RoleUserController(){
super.setFormClass(RoleUserForm.class);
super.setModuleDesc("角色用户");
}
/**
/**
* 获取查询对象,限制查询返回的结果只包含ID和名称
*
* @param IdList
* @return
*/
......@@ -79,65 +91,42 @@ public class RoleUserController extends BaseCRUDJsonMappingController<RoleUserSe
}
}
@SuppressWarnings("unchecked")
@Override
protected void init(HttpServletRequest request, HttpServletResponse response, RoleUserForm form, Map<String, Object> model, Context context) {
Map<String, Object> status = new HashMap<>(3);
status.put("roleId", roleService.find(new RoleEntity(), null).stream()
.collect(Collectors.toMap(e -> e.getId().toString(), RoleEntity::getName)));
List<RoleUserEntity> roleUserList = (List<RoleUserEntity>) model.get(SysConstains.RESULT_KEY);
if(roleUserList!=null && roleUserList.size()>0) {
List<Long> userIdsList = roleUserList.stream().map(RoleUserEntity::getUserId).collect(Collectors.toList());
List<UserEntity> userEntityList = userService.find(getQuery(UserQuery.class,
Sets.newHashSet("id", "realName","loginName"), userIdsList.toArray(new Long[userIdsList.size()])), null);
if(userEntityList!=null) {
status.put("userReNameMap",
userEntityList.stream().collect(Collectors.toMap(e -> e.getId().toString(), UserEntity::getRealName)));
status.put("userId",
userEntityList.stream().collect(Collectors.toMap(e -> e.getId().toString(), UserEntity::getLoginName)));
}
}
model.put(KEY_RESULT_DICT, status);
super.init(request, response, form, model, context);
}
/**
* 分配用户
*/
@PostMapping(value = "distributionUser")
public String distributionUser(HttpServletRequest request, HttpServletResponse response, RoleUserForm form) {
try {
service.doDistributionUser(form.getQuery());
JSONObject ret = new JSONObject();
ret.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS);
return ret.toJSONString();
} catch (Exception e) {
log.error("分配用户错误", e);
JSONObject ret = new JSONObject();
ret.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE);
ret.put(KEY_RESULT_MSG, super.convertException(e));
return ret.toJSONString();
}
}
/**
* 分配用户
*/
@PostMapping(value = "distributionUser")
public String distributionUser(@RequestBody RoleUserQuery query) {
try {
service.doDistributionUser(query);
JSONObject ret = new JSONObject();
ret.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS);
return ret.toJSONString();
} catch (Exception e) {
log.error("分配用户错误", e);
JSONObject ret = new JSONObject();
ret.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE);
ret.put(KEY_RESULT_MSG, super.convertException(e));
return ret.toJSONString();
}
}
/**
* 分配角色
*/
@PostMapping(value = "distributionRole")
public String distributionRole(HttpServletRequest request, HttpServletResponse response, RoleUserForm form) {
try {
service.doDistributionRole(form.getQuery());
JSONObject ret = new JSONObject();
ret.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS);
return ret.toJSONString();
} catch (Exception e) {
log.error("分配角色错误", e);
JSONObject ret = new JSONObject();
ret.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE);
ret.put(KEY_RESULT_MSG, super.convertException(e));
return ret.toJSONString();
}
}
/**
* 分配角色
*/
@PostMapping(value = "distributionRole")
public String distributionRole(@RequestBody RoleUserQuery query) {
try {
service.doDistributionRole(query);
JSONObject ret = new JSONObject();
ret.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS);
return ret.toJSONString();
} catch (Exception e) {
log.error("分配角色错误", e);
JSONObject ret = new JSONObject();
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