diff --git a/diboot-core/src/main/java/com/diboot/core/controller/BaseController.java b/diboot-core/src/main/java/com/diboot/core/controller/BaseController.java index e65fdde..dcab3f9 100644 --- a/diboot-core/src/main/java/com/diboot/core/controller/BaseController.java +++ b/diboot-core/src/main/java/com/diboot/core/controller/BaseController.java @@ -59,6 +59,9 @@ public class BaseController { * @return */ public QueryWrapper buildQueryWrapper(DTO entityOrDto) throws Exception{ + if(entityOrDto instanceof HttpServletRequest){ + throw new Exception("参数错误:buildQueryWrapper()参数为Entity/DTO对象!"); + } return QueryBuilder.toQueryWrapper(entityOrDto); } @@ -69,6 +72,9 @@ public class BaseController { * @return */ public LambdaQueryWrapper buildLambdaQueryWrapper(DTO entityOrDto) throws Exception{ + if(entityOrDto instanceof HttpServletRequest){ + throw new Exception("参数错误:buildQueryWrapper()参数为Entity/DTO对象!"); + } return QueryBuilder.toLambdaQueryWrapper(entityOrDto); } diff --git a/diboot-core/src/main/java/com/diboot/core/util/BeanUtils.java b/diboot-core/src/main/java/com/diboot/core/util/BeanUtils.java index aedab92..e8fccea 100644 --- a/diboot-core/src/main/java/com/diboot/core/util/BeanUtils.java +++ b/diboot-core/src/main/java/com/diboot/core/util/BeanUtils.java @@ -244,7 +244,7 @@ public class BeanUtils { String key = null; if(V.isEmpty(fields)){ //未指定字段,以id为key - key = getStringProperty(model, Cons.FieldName.parentId.name()); + key = getStringProperty(model, Cons.FieldName.id.name()); } // 指定了一个字段,以该字段为key,类型同该字段 else if(fields.length == 1){ @@ -306,7 +306,7 @@ public class BeanUtils { */ private static void buildDeeperLevelTree(List parentModels, List allModels){ List deeperLevelModels = new ArrayList(); - Map parentLevelModelMap = convertToStringKeyObjectMap(parentModels); + Map parentLevelModelMap = convertToStringKeyObjectMap(parentModels, Cons.FieldName.id.name()); for(T model : allModels){ Object parentId = getProperty(model, Cons.FieldName.parentId.name()); if(parentLevelModelMap.keySet().contains(String.valueOf(parentId)) && !parentId.equals(model.getId())){ diff --git a/diboot-example/src/main/java/com/diboot/example/controller/SysUserController.java b/diboot-example/src/main/java/com/diboot/example/controller/SysUserController.java index 7b058c6..4a86b92 100644 --- a/diboot-example/src/main/java/com/diboot/example/controller/SysUserController.java +++ b/diboot-example/src/main/java/com/diboot/example/controller/SysUserController.java @@ -58,15 +58,11 @@ public class SysUserController extends BaseCrudRestController { @Autowired private PermissionService permissionService; - @Autowired - private DepartmentService departmentService; - - @GetMapping("/list") @AuthorizationWrapper(value = @RequiresPermissions("list"), name = "列表") public JsonResult getVOList(SysUser sysUser, Pagination pagination, HttpServletRequest request) throws Exception{ QueryWrapper queryWrapper = super.buildQueryWrapper(sysUser); - return super.getVOListWithPaging(queryWrapper, pagination, UserVO.class); + return super.getVOListWithPaging(queryWrapper, pagination, SysUserVO.class); } /*** @@ -157,13 +153,6 @@ public class SysUserController extends BaseCrudRestController { List roleKvList = roleService.getKeyValueList(wrapper); modelMap.put("roleKvList", roleKvList); - //获取部门KV - wrapper = new QueryWrapper() - .lambda() - .select(Department::getName, Department::getId); - List departmentKvList = departmentService.getKeyValueList(wrapper); - modelMap.put("departmentKvList", departmentKvList); - //获取用户状态KV List userStatusKvList = dictionaryService.getKeyValueList(SysUser.USER_STATUS); modelMap.put("userStatusKvList", userStatusKvList); diff --git a/diboot-example/src/main/java/com/diboot/example/service/SysUserService.java b/diboot-example/src/main/java/com/diboot/example/service/SysUserService.java index be4c7db..5a6be9e 100644 --- a/diboot-example/src/main/java/com/diboot/example/service/SysUserService.java +++ b/diboot-example/src/main/java/com/diboot/example/service/SysUserService.java @@ -16,9 +16,6 @@ import java.util.List; */ public interface SysUserService extends BaseService { - //获取列表数据 - List getSysUserList(Wrapper queryWrapper, Pagination pagination); - //获取详细 SysUserVO getSysUser(Long id); diff --git a/diboot-example/src/main/java/com/diboot/example/service/impl/SysUserServiceImpl.java b/diboot-example/src/main/java/com/diboot/example/service/impl/SysUserServiceImpl.java index 4de2bda..7fd5e03 100644 --- a/diboot-example/src/main/java/com/diboot/example/service/impl/SysUserServiceImpl.java +++ b/diboot-example/src/main/java/com/diboot/example/service/impl/SysUserServiceImpl.java @@ -38,25 +38,6 @@ public class SysUserServiceImpl extends BaseServiceImpl @Autowired private UserRoleService userRoleService; - @Override - public List getSysUserList(Wrapper queryWrapper, Pagination pagination) { - List sysUserList = super.getEntityList(queryWrapper, pagination); - List sysUserVOList = RelationsBinder.convertAndBind(sysUserList, SysUserVO.class); - if(V.notEmpty(sysUserVOList)){ - for(SysUserVO sysUserVO : sysUserVOList){ - List roleList = sysUserVO.getRoleList(); - if(V.notEmpty(roleList)){ - List roleNameList = new ArrayList(); - for(Role role : roleList){ - roleNameList.add(role.getName()); - } - sysUserVO.setRoleNameList(roleNameList); - } - } - } - return sysUserVOList; - } - @Override public SysUserVO getSysUser(Long id) { SysUserVO sysUserVO = super.getViewObject(id, SysUserVO.class); diff --git a/diboot-example/src/main/java/com/diboot/example/vo/SysUserVO.java b/diboot-example/src/main/java/com/diboot/example/vo/SysUserVO.java index 638cffb..45d4a16 100644 --- a/diboot-example/src/main/java/com/diboot/example/vo/SysUserVO.java +++ b/diboot-example/src/main/java/com/diboot/example/vo/SysUserVO.java @@ -21,9 +21,6 @@ public class SysUserVO extends SysUser { private static final long serialVersionUID = 5921846275434221060L; - @BindField(entity=Department.class, field="name", condition="this.department_id=id") - private String departmentName; - @BindDict(type="GENDER", field="gender") private String genderLabel; @@ -36,7 +33,4 @@ public class SysUserVO extends SysUser { @TableField(exist = false) private List roleIdList; - @TableField(exist = false) - private List roleNameList; - } \ No newline at end of file diff --git a/diboot-shiro/src/main/java/com/diboot/shiro/controller/PermissionController.java b/diboot-shiro/src/main/java/com/diboot/shiro/controller/PermissionController.java index 95a78ee..7ab4101 100644 --- a/diboot-shiro/src/main/java/com/diboot/shiro/controller/PermissionController.java +++ b/diboot-shiro/src/main/java/com/diboot/shiro/controller/PermissionController.java @@ -39,20 +39,6 @@ public class PermissionController extends BaseCrudRestController { @Autowired private PermissionService permissionService; - /*** - * 查询Entity - * @param id ID - * @return - * @throws Exception - */ - @GetMapping("/{id}") - @AuthorizationWrapper(value = @RequiresPermissions("read"), name = "读取") - public JsonResult getModel(@PathVariable("id")Long id, HttpServletRequest request) - throws Exception{ - PermissionVO vo = permissionService.getViewObject(id, PermissionVO.class); - return new JsonResult(vo); - } - /*** * 查询ViewObject的分页数据 (此为非继承的自定义使用案例,更简化的调用父类案例请参考UserController) *

@@ -71,6 +57,20 @@ public class PermissionController extends BaseCrudRestController { return new JsonResult(Status.OK, entityList).bindPagination(pagination); } + /*** + * 查询Entity + * @param id ID + * @return + * @throws Exception + */ + @GetMapping("/{id}") + @AuthorizationWrapper(value = @RequiresPermissions("read"), name = "读取") + public JsonResult getModel(@PathVariable("id")Long id, HttpServletRequest request) + throws Exception{ + PermissionVO vo = permissionService.getViewObject(id, PermissionVO.class); + return new JsonResult(vo); + } + /*** * 创建Entity * @return diff --git a/diboot-shiro/src/main/java/com/diboot/shiro/controller/RoleController.java b/diboot-shiro/src/main/java/com/diboot/shiro/controller/RoleController.java index 92c9b54..49fd4e3 100644 --- a/diboot-shiro/src/main/java/com/diboot/shiro/controller/RoleController.java +++ b/diboot-shiro/src/main/java/com/diboot/shiro/controller/RoleController.java @@ -50,8 +50,8 @@ public class RoleController extends BaseCrudRestController { @GetMapping("/list") @AuthorizationWrapper(value = @RequiresPermissions("list"), name = "列表") @AuthorizationCache - public JsonResult getVOList(HttpServletRequest request, Pagination pagination) throws Exception{ - QueryWrapper queryWrapper = buildQueryWrapper(request); + public JsonResult getVOList(Role role, Pagination pagination, HttpServletRequest request) throws Exception{ + QueryWrapper queryWrapper = super.buildQueryWrapper(role); // 获取结果 List voList = roleService.getRoleList(queryWrapper, pagination); // 返回结果