Merge pull request #4 from dibo-software/develop
修复升级Mybatis-plus后绑定Metadata元数据失效的问题
This commit is contained in:
commit
a28c3533db
|
@ -118,9 +118,9 @@ public class EntityListBinder<T> extends EntityBinder<T> {
|
|||
}
|
||||
|
||||
private void bindingResult(String fkName, List<T> list) {
|
||||
Map<Object, List<T>> valueEntityListMap = new HashMap<>(list.size());
|
||||
Map<String, List<T>> valueEntityListMap = new HashMap<>(list.size());
|
||||
for(T entity : list){
|
||||
Object keyValue = BeanUtils.getProperty(entity, fkName);
|
||||
String keyValue = BeanUtils.getStringProperty(entity, fkName);
|
||||
List<T> entityList = valueEntityListMap.get(keyValue);
|
||||
if(entityList == null){
|
||||
entityList = new ArrayList<>();
|
||||
|
|
|
@ -95,36 +95,26 @@ public class FieldBinder<T> extends BaseBinder<T> {
|
|||
return;
|
||||
}
|
||||
// 将结果list转换成map
|
||||
Map<Object, Map<String, Object>> referencedEntityPk2DataMap = new HashMap<>(mapList.size());
|
||||
Map<String, Map<String, Object>> referencedEntityPk2DataMap = new HashMap<>(mapList.size());
|
||||
// 转换列名为字段名(MyBatis-plus的getMapList结果会将列名转成驼峰式)
|
||||
String referencedEntityPkFieldName = S.toLowerCaseCamel(referencedEntityPkName);
|
||||
for(Map<String, Object> map : mapList){
|
||||
if(map.get(referencedEntityPkName) != null){
|
||||
Object pkVal = map.get(referencedEntityPkName);
|
||||
// 将数字类型转换成字符串,以便解决类型不一致的问题
|
||||
Object formatPkVal = getFormatKey(pkVal);
|
||||
referencedEntityPk2DataMap.put(formatPkVal, map);
|
||||
Object pkVal = map.get(referencedEntityPkFieldName);
|
||||
if(pkVal != null){
|
||||
referencedEntityPk2DataMap.put(String.valueOf(pkVal), map);
|
||||
}
|
||||
}
|
||||
// 遍历list并赋值
|
||||
for(Object annoObject : annoObjectList){
|
||||
Object annoObjectId = BeanUtils.getProperty(annoObject, annoObjectFkFieldName);
|
||||
// 将数字类型转换成字符串,以便解决类型不一致的问题
|
||||
Object formatAnnoObjectId = getFormatKey(annoObjectId);
|
||||
Map<String, Object> relationMap = referencedEntityPk2DataMap.get(formatAnnoObjectId);
|
||||
String annoObjectId = BeanUtils.getStringProperty(annoObject, annoObjectFkFieldName);
|
||||
Map<String, Object> relationMap = referencedEntityPk2DataMap.get(annoObjectId);
|
||||
if(relationMap != null){
|
||||
for(int i = 0; i< annoObjectSetterPropNameList.size(); i++){
|
||||
BeanUtils.setProperty(annoObject, annoObjectSetterPropNameList.get(i), relationMap.get(referencedGetterColumnNameList.get(i)));
|
||||
BeanUtils.setProperty(annoObject, annoObjectSetterPropNameList.get(i), relationMap.get(S.toLowerCaseCamel(referencedGetterColumnNameList.get(i))));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取统一定义的key(避免Mybatis自动转换BigInteger和Long的差异问题)
|
||||
*/
|
||||
private Object getFormatKey(Object annoObjectId){
|
||||
if(annoObjectId instanceof BigInteger || annoObjectId instanceof Long || annoObjectId instanceof Integer) {
|
||||
return String.valueOf(annoObjectId);
|
||||
}
|
||||
return annoObjectId;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,6 @@ public class DepartmentVO extends Department {
|
|||
@BindField(entity = Department.class, field = "name", condition = "parent_id=id")
|
||||
private String parentName;
|
||||
|
||||
//TODO 该绑定未生效,待检查
|
||||
@BindEntityList(entity = Department.class, condition = "id=parent_id")
|
||||
private List<Department> children;
|
||||
|
||||
|
|
|
@ -31,11 +31,11 @@ public class UserVO extends User {
|
|||
private Department department;
|
||||
|
||||
// 支持级联字段关联
|
||||
//@BindField(entity = Organization.class, field="name", condition="this.departmentId=Department.id AND Department.orgId=id")
|
||||
@BindField(entity = Organization.class, field="name", condition="this.department_id=department.id AND department.org_id=id")
|
||||
private String orgName;
|
||||
|
||||
// 通过中间表关联
|
||||
@BindEntity(entity = Organization.class, condition = "this.department_id=department.id AND department.org_id=id AND department.deleted=0") // AND deleted=0
|
||||
@BindEntity(entity = Organization.class, condition = "this.department_id=department.id AND department.org_id=id") // AND deleted=0
|
||||
private Organization organization;
|
||||
|
||||
// 支持多-多Entity实体关联
|
||||
|
|
|
@ -74,17 +74,16 @@ create table user_role
|
|||
|
||||
-- 初始化样例数据
|
||||
INSERT INTO department (id, parent_id, org_id, name, code)
|
||||
VALUES (10001, 0, 100001, '研发部', 'DEV'), (10002, 10001, 100001, '开发组', 'DEVT'), (10003, 10001, 100001, '测试组', 'TST');
|
||||
VALUES (10001, 0, 100001, '产品部', 'PROD'), (10002, 10001, 100001, '研发组', 'DEV'), (10003, 10001, 100001, '测试组', 'TST');
|
||||
|
||||
INSERT INTO metadata (id, parent_id, type, item_name, item_value, comment, extdata, sort_id, `system`, editable)
|
||||
VALUES (1, 0, 'GENDER', '性别', null, '', null, 99, 1, 1), (2, 1, 'GENDER', '男', 'M', null, null, 99, 1, 0), (3, 1, 'GENDER', '女', 'F', null, null, 99, 1, 0);
|
||||
|
||||
INSERT INTO organization (id, parent_id, name, telphone, address)
|
||||
VALUES (100000, 0, '帝博集团', '0512-12345678', '江苏苏州'), (100001, 100000, '苏州帝博', '0512-62988949', '江苏苏州');
|
||||
INSERT INTO organization (id, parent_id, name, telphone, address) VALUES (100001, 0, '苏州帝博', '0512-62988949', '江苏苏州');
|
||||
|
||||
INSERT INTO role (id, name, code) VALUES (101, '管理员', 'ADMIN'), (102, '操作员', 'OPERATOR'), (103, '只读用户', 'READ'), (104, '项目经理', 'PM');
|
||||
INSERT INTO role (id, name, code) VALUES (101, '管理员', 'ADMIN'), (102, '操作员', 'OPERATOR');
|
||||
|
||||
INSERT INTO user (id, department_id, username, gender)
|
||||
VALUES (1001, 10002, '张三', 'M'), (1002, 10002, '李四', 'F'), (1003, 10003, '王五', 'M'), (1004, 10001, '马六', 'M');
|
||||
VALUES (1001, 10002, '张三', 'M'), (1002, 10002, '李四', 'F');
|
||||
|
||||
INSERT INTO user_role (user_id, role_id) VALUES (1001, 101),(1001, 102),(1003, 102),(1003, 103);
|
||||
INSERT INTO user_role (user_id, role_id) VALUES (1001, 101),(1001, 102),(1002, 102);
|
Loading…
Reference in New Issue