Merge pull request #25 from dibo-software/develop

Develop
This commit is contained in:
Mazc 2019-08-13 11:27:12 +08:00 committed by GitHub
commit 452c995868
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 83 additions and 42 deletions

View File

@ -5,9 +5,10 @@
</p>
# diboot-v2
diboot 2.0版本项目,实现: diboot-core全新内核 + diboot-components-*基础组件 + diboot-devtools代码生成器。
diboot 2.0版本项目,实现: diboot-core全新内核 + diboot-components-*基础组件 + diboot-devtools代码生成平台。
### 技术交流QQ群: 731690096
## ** diboot-core: 精简优化内核
## 一、 diboot-core: 精简优化内核
全新精简内核,主要实现<font color="red">单表CRUD无SQL 和 多表关联查询绑定的无SQL</font>实现方案,并提供其他常用开发场景的简单封装。
### 单表CRUD无SQL
@ -20,13 +21,13 @@ diboot 2.0版本项目,实现: diboot-core全新内核 + diboot-components-*
##### 3. @BindEntity 注解自动绑定单个其他表实体Entity
##### 4. @BindEntityList 注解自动绑定其他表实体集合List<Entity>
具体请查看: [diboot-core 注解自动绑定多表关联](https://github.com/dibo-software/diboot-v2/tree/master/diboot-core "注解自动绑定多表关联").
具体请查看: [diboot-core README](https://github.com/dibo-software/diboot-v2/tree/master/diboot-core "注解自动绑定多表关联").
> .
## ** diboot-shiro: 基于RBAC+Shiro的权限认证模块
## 二、 diboot-shiro: 基于RBAC+Shiro的权限认证模块
RBAC的角色权限+基于Shiro的细粒度权限控制
### 1、@AuthorizationPrefix
@ -70,10 +71,7 @@ diboot.shiro.cache.cache-way=memory
调用该类autoStorage传入spring上下文参数使用参考diboot-example 中ExampleListener类
## ** diboot-devtools 代码生成工具
## 三、 diboot-devtools 代码生成工具
> 比 1.x 版本更强大的代码生成工具 ...
...
## 技术支持
您可以通过加入QQ群获取相关的技术支持。群号: 731690096
...

View File

@ -1,11 +1,12 @@
# diboot-core: 全新优化内核
主要实现:
1. 多表关联的自动绑定, 实现单表CRUD和多表关联的无SQL化
2. 提供其他常用开发场景的最佳实践封装。
1. 单表CRUD和多表关联查询的无SQL化
2. Entity/DTO自动转换为QueryWrapper@BindQuery注解绑定字段参数对应的查询条件无注解默认映射为等于=条件)
3. 提供其他常用开发场景的最佳实践封装。
## ** 一. 单表CRUD无SQL
> 依赖Mybatis-Plus实现Mybatis-Plus具备通用Mapper方案和灵活的查询构造器
## ** 二. 多表关联查询无SQL适用于大多数场景,拆分成单表查询自动实现结果绑定
> 依赖Mybatis-plus实现Mybatis-plus具备通用Mapper方案和灵活的查询构造器
## ** 二. 多表关联查询无SQL通过注解绑定关联,自动拆分成单表查询并绑定结果
> 通过注解实现多数场景下的关联查询无SQL
### 1. 注解自动绑定数据字典(自定义枚举)的显示值Label
~~~java
@ -43,21 +44,22 @@ private List<Department> children;
private List<Role> roleList;
~~~
## ** 三. 使用方式
## ** 三. 注解绑定关联的使用方式
### 1. 引入依赖
Gradle:
~~~gradle
compile("com.diboot:diboot-core:2.0.1")
compile("com.diboot:diboot-core-spring-boot-starter:2.0.2")
~~~
或Maven
~~~xml
<dependency>
<groupId>com.diboot</groupId>
<artifactId>diboot-core</artifactId>
<version>2.0.1</version>
<artifactId>diboot-core-spring-boot-starter</artifactId>
<version>2.0.2</version>
</dependency>
~~~
> 注: @BindDict注解需要依赖dictionary表初始化SQL需执行/META-INF/sql/init-mysql.sql
> 注: @BindDict注解需要依赖dictionary表,可配置参数 diboot.core.init-sql=true 初次启动时starter会自动安装 init-{db}.sql。
如不支持自动安装的数据库,需手动执行 diboot-core-*.jar/META-INF/sql/init-{db}.sql 。
### 2. 定义你的Service继承diboot的BaseService或Mybatis-plus的ISerivice及Mapper
### 3. 使用注解绑定:
@ -74,4 +76,34 @@ RelationsBinder.bind(voList);
List<MyUserVO> voList = RelationsBinder.convertAndBind(userList, MyUserVO.class);
~~~
## 四. 样例参考 - [diboot-core-example](https://github.com/dibo-software/diboot-v2-example/tree/master/diboot-core-example)
## ** 四. Entity/DTO自动转换为QueryWrapper的使用方式
### 1. Entity/DTO中声明映射查询条件
示例代码:
~~~java
public class UserDTO{
// 无@BindQuery注解默认会映射为=条件
private Long gender;
// 有注解,映射为注解指定条件
@BindQuery(comparison = Comparison.LIKE)
private String realname;
//... getter, setter
}
~~~
### 2. 调用QueryBuilder.toQueryWrapper(entityOrDto)进行转换
~~~java
/**
* url参数示例: /list?gender=M&realname=张
* 将映射为 queryWrapper.eq("gender", "M").like("realname", "张")
*/
@GetMapping("/list")
public JsonResult getVOList(UserDto userDto) throws Exception{
//调用super.buildQueryWrapper(entityOrDto) 或者直接调用 QueryBuilder.toQueryWrapper(entityOrDto) 进行转换
QueryWrapper<User> queryWrapper = super.buildQueryWrapper(userDto);
//... 查询list
return new JsonResult(Status.OK, list);
}
~~~
## 五. 样例参考 - [diboot-core-example](https://github.com/dibo-software/diboot-v2-example/tree/master/diboot-core-example)

View File

@ -1,7 +1,8 @@
package com.diboot.example.config;
import com.diboot.example.entity.Department;
import com.diboot.example.entity.Organization;
import com.diboot.example.vo.DepartmentVO;
import com.diboot.example.vo.OrganizationVO;
import com.diboot.example.vo.PositionVO;
import java.util.HashMap;
import java.util.Map;
@ -14,19 +15,27 @@ public class Cons {
* 树图标常量
* */
public static enum TREE_ICON_LEVEL{
ONE,
TWO
ONE, //一级图标
TWO //二级图标
}
public static Map<String, Map<String, String>> ICON = new HashMap(){{
put(Organization.class.getSimpleName(), new HashMap(){{
put(TREE_ICON_LEVEL.ONE.name(), "");
put(TREE_ICON_LEVEL.TWO.name(), "");
//组织
put(OrganizationVO.class.getSimpleName(), new HashMap(){{
put(TREE_ICON_LEVEL.ONE.name(), "gold");
put(TREE_ICON_LEVEL.TWO.name(), "bank");
}}
);
put(Department.class.getSimpleName(), new HashMap(){{
put(TREE_ICON_LEVEL.ONE.name(), "");
put(TREE_ICON_LEVEL.TWO.name(), "");
//部门
put(DepartmentVO.class.getSimpleName(), new HashMap(){{
put(TREE_ICON_LEVEL.ONE.name(), "gold");
put(TREE_ICON_LEVEL.TWO.name(), "bank");
}}
);
//职位
put(PositionVO.class.getSimpleName(), new HashMap(){{
put(TREE_ICON_LEVEL.ONE.name(), "gold");
put(TREE_ICON_LEVEL.TWO.name(), "bank");
}}
);
}};

View File

@ -54,12 +54,16 @@ public class EmployeeServiceImpl extends BaseServiceImpl<EmployeeMapper, Employe
.eq(Department::getOrgId, orgId);
List<Department> deptList = departmentService.getEntityList(queryWrapper);
List<Long> deptIdList = getIdList(deptList);
if(V.isEmpty(deptIdList)){
return null;
}
queryWrapper = new LambdaQueryWrapper<EmployeePositionDepartment>()
.in(EmployeePositionDepartment::getDepartmentId, deptIdList);
List<EmployeePositionDepartment> epdList = employeePositionDepartmentService.getEntityList(queryWrapper);
List<Long> empIdList = getIdList(epdList, "getEmployeeId");
if(V.isEmpty(empIdList)){
return null;
}
wrapper.lambda().in(Employee::getId, empIdList);
List<Employee> empList = super.getEntityList(wrapper, pagination);
List<EmployeeVO> voList = RelationsBinder.convertAndBind(empList, EmployeeVO.class);

View File

@ -197,6 +197,9 @@ public class PositionServiceImpl extends BaseServiceImpl<PositionMapper, Positio
deptIdList.add(dept.getId());
}
}
if(V.isEmpty(deptIdList)){
return null;
}
//获取部门-职位对应信息
wrapper = new LambdaQueryWrapper<PositionDepartment>()
.in(PositionDepartment::getDepartmentId, deptIdList);
@ -207,6 +210,9 @@ public class PositionServiceImpl extends BaseServiceImpl<PositionMapper, Positio
positionIdList.add(pd.getPositionId());
}
}
if(V.isEmpty(positionIdList)){
return null;
}
//获取职位
List<Position> positionList = super.getEntityListByIds(positionIdList);
List<PositionVO> volist = RelationsBinder.convertAndBind(positionList, PositionVO.class);

View File

@ -27,12 +27,4 @@ public class DepartmentVO extends Department {
private List<DepartmentVO> children;
// 直接关联Entity
/*@BindEntity(entity = Organization.class, condition="this.org_id=id")
private Organization organization;*/
// 直接关联多个Entity
/*@BindEntityList(entity = Department.class, condition = "this.id=parent_id")
private List<Department> children;*/
}

View File

@ -19,10 +19,10 @@ public class EmployeeVO extends Employee {
@BindDict(type="GENDER", field="gender")
private String genderLabel;
@BindEntity(entity = Department.class, condition = "this.id = if_employee_position_department.employee_id AND if_employee_position_department.department_id = id")
@BindEntity(entity = Department.class, condition = "this.id = if_employee_position_department.employee_id AND if_employee_position_department.department_id = id AND if_employee_position_department.deleted = 0")
private Department department;
@BindEntity(entity = Position.class, condition = "this.id = if_employee_position_department.employee_id AND if_employee_position_department.position_id = id")
@BindEntity(entity = Position.class, condition = "this.id = if_employee_position_department.employee_id AND if_employee_position_department.position_id = id AND if_employee_position_department.deleted = 0")
private Position position;
private EmployeePositionDepartment empPosiDept;

View File

@ -27,7 +27,7 @@ public class PositionVO extends Position {
@BindEntity(entity = Position.class, condition = "this.parent_id = id")
private Position parentPosition;
@BindEntityList(entity = Department.class, condition = "this.id = if_position_department.position_id AND if_position_department.department_id = id")
@BindEntityList(entity = Department.class, condition = "this.id = if_position_department.position_id AND if_position_department.department_id = id AND if_position_department.deleted = 0")
private List<Department> departmentList;
private List<PositionVO> children;