From a074300a79fc6722064f16b647dc411106c64423 Mon Sep 17 00:00:00 2001 From: zhouhao Date: Fri, 22 Jun 2018 15:59:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0sql=E6=9D=A1=E4=BB=B6?= =?UTF-8?q?=E5=AF=B9parent=E7=9A=84=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hsweb-system-organizational/README.md | 24 +-- .../terms/CustomSqlTermConfiguration.java | 161 ++++++++++++++++-- .../simple/terms/InServiceTreeInSqlTerm.java | 7 +- .../simple/terms/UserInDepartmentSqlTerm.java | 5 +- .../simple/terms/UserInDistSqlTerm.java | 5 +- .../simple/terms/UserInOrgSqlTerm.java | 9 +- .../simple/terms/UserInPositionSqlTerm.java | 4 +- .../simple/terms/UserInSqlTerm.java | 45 ++++- 8 files changed, 214 insertions(+), 46 deletions(-) diff --git a/hsweb-system/hsweb-system-organizational/README.md b/hsweb-system/hsweb-system-organizational/README.md index 108507a13..5c176dfba 100644 --- a/hsweb-system/hsweb-system-organizational/README.md +++ b/hsweb-system/hsweb-system-organizational/README.md @@ -13,17 +13,17 @@ createQuery().where("orgId","org-child-in","1234").list(); ``` -1. dist-child`(-not)`-in : 参数`(不)`在指定的行政区域以及子节点中 -2. org-child`(-not)`-in : 参数`(不)`在指定的机构以及子节点中 -3. dept-child`(-not)`-in: 参数`(不)`在指定的部门以及子节点中 -3. pos-child`(-not)`-in: 参数`(不)`在指定的岗位以及子节点中 -4. user`(-not)`-in-position`(-child)`: 用户ID`(不)`在岗位中`(包含子级岗位)` -5. user`(-not)`-in-department`(-child)`: 用户ID`(不)`在部门中`(包含子级岗位)` -6. user`(-not)`-in-org`(-child)`: 用户ID`(不)`在机构中`(包含子级岗位)` -7. user`(-not)`-in-dist`(-child)`: 用户ID`(不)`在行政区域中`(包含子级岗位)` -8. person`(-not)`-in-position`(-child)`: 人员ID`(不)`在岗位中`(包含子级岗位)` -9. person`(-not)`-in-department`(-child)`: 人员ID`(不)`在部门中`(包含子级岗位)` -10. person`(-not)`-in-org`(-child)`: 人员ID`(不)`在机构中`(包含子级岗位)` -11. person`(-not)`-in-dist`(-child)`: 人员ID`(不)`在行政区域中`(包含子级岗位)` +1. dist-child`(-parent)``(-not)`-in : 参数`(不)`在指定的行政区域以及子(父)节点中 +2. org-child`(-parent)``(-not)`-in : 参数`(不)`在指定的机构以及子(父)节点中 +3. dept-child`(-parent)``(-not)`-in: 参数`(不)`在指定的部门以及子(父)节点中 +3. pos-child`(-parent)``(-not)`-in: 参数`(不)`在指定的岗位以及子(父)节点中 +4. user`(-not)`-in-position`(-child)(-parent)`: 用户ID`(不)`在岗位中`(包含子级(父级)岗位)` +5. user`(-not)`-in-department`(-child)(-parent)`: 用户ID`(不)`在部门中`(包含子级(父级)岗位)` +6. user`(-not)`-in-org`(-child)(-parent)`: 用户ID`(不)`在机构中`(包含子级(父级)岗位)` +7. user`(-not)`-in-dist`(-child)(-parent)`: 用户ID`(不)`在行政区域中`(包含子级(父级)岗位)` +8. person`(-not)`-in-position`(-child)(-parent)`: 人员ID`(不)`在岗位中`(包含子级(父级)岗位)` +9. person`(-not)`-in-department`(-child)(-parent)`: 人员ID`(不)`在部门中`(包含子级(父级)岗位)` +10. person`(-not)`-in-org`(-child)(-parent)`: 人员ID`(不)`在机构中`(包含子级(父级)岗位)` +11. person`(-not)`-in-dist`(-child)(-parent)`: 人员ID`(不)`在行政区域中`(包含子级(父级)岗位)` 注意: 括号中的内容是可选的 \ No newline at end of file diff --git a/hsweb-system/hsweb-system-organizational/hsweb-system-organizational-local/src/main/java/org/hswebframework/web/service/organizational/simple/terms/CustomSqlTermConfiguration.java b/hsweb-system/hsweb-system-organizational/hsweb-system-organizational-local/src/main/java/org/hswebframework/web/service/organizational/simple/terms/CustomSqlTermConfiguration.java index 21293d2ae..97e5ba90e 100644 --- a/hsweb-system/hsweb-system-organizational/hsweb-system-organizational-local/src/main/java/org/hswebframework/web/service/organizational/simple/terms/CustomSqlTermConfiguration.java +++ b/hsweb-system/hsweb-system-organizational/hsweb-system-organizational-local/src/main/java/org/hswebframework/web/service/organizational/simple/terms/CustomSqlTermConfiguration.java @@ -14,70 +14,105 @@ import org.springframework.context.annotation.Configuration; @Configuration public class CustomSqlTermConfiguration { + //======================================================================= @Bean public InServiceTreeInSqlTerm distInSqlTerm(DistrictService districtService) { - return new InServiceTreeInSqlTerm<>(districtService, "dist", "s_district", false); + return new InServiceTreeInSqlTerm<>(districtService, "dist", "s_district", false, false); + } + + @Bean + public InServiceTreeInSqlTerm distInSqlTermParent(DistrictService districtService) { + return new InServiceTreeInSqlTerm<>(districtService, "dist", "s_district", false, true); } @Bean public InServiceTreeInSqlTerm distNotInSqlTerm(DistrictService districtService) { - return new InServiceTreeInSqlTerm<>(districtService, "dist", "s_district", true); + return new InServiceTreeInSqlTerm<>(districtService, "dist", "s_district", true, false); } + @Bean + public InServiceTreeInSqlTerm distNotInSqlTermParent(DistrictService districtService) { + return new InServiceTreeInSqlTerm<>(districtService, "dist", "s_district", true, true); + } + + //======================================================================= @Bean public InServiceTreeInSqlTerm orgInSqlTerm(OrganizationalService organizationalService) { - return new InServiceTreeInSqlTerm<>(organizationalService, "org", "s_organization", false); + return new InServiceTreeInSqlTerm<>(organizationalService, "org", "s_organization", false, false); } @Bean public InServiceTreeInSqlTerm orgNotInSqlTerm(OrganizationalService organizationalService) { - return new InServiceTreeInSqlTerm<>(organizationalService, "org", "s_organization", true); + return new InServiceTreeInSqlTerm<>(organizationalService, "org", "s_organization", true, false); } + @Bean + public InServiceTreeInSqlTerm orgInSqlTermParent(OrganizationalService organizationalService) { + return new InServiceTreeInSqlTerm<>(organizationalService, "org", "s_organization", false, true); + } + + @Bean + public InServiceTreeInSqlTerm orgNotInSqlTermParent(OrganizationalService organizationalService) { + return new InServiceTreeInSqlTerm<>(organizationalService, "org", "s_organization", true, true); + } + + //======================================================================= @Bean public InServiceTreeInSqlTerm departmentInSqlTerm(DepartmentService departmentService) { - return new InServiceTreeInSqlTerm<>(departmentService, "dept", "s_department", false); + return new InServiceTreeInSqlTerm<>(departmentService, "dept", "s_department", false, false); } @Bean public InServiceTreeInSqlTerm departmentNotInSqlTerm(DepartmentService departmentService) { - return new InServiceTreeInSqlTerm<>(departmentService, "dept", "s_department", true); + return new InServiceTreeInSqlTerm<>(departmentService, "dept", "s_department", true, false); } @Bean - public PersonInPositionSqlTerm personInPositionSqlTerm() { - return new PersonInPositionSqlTerm(false); + public InServiceTreeInSqlTerm departmentInSqlTermParent(DepartmentService departmentService) { + return new InServiceTreeInSqlTerm<>(departmentService, "dept", "s_department", false, true); } @Bean - public PersonInPositionSqlTerm personNotInPositionSqlTerm() { - return new PersonInPositionSqlTerm(true); + public InServiceTreeInSqlTerm departmentNotInSqlTermParent(DepartmentService departmentService) { + return new InServiceTreeInSqlTerm<>(departmentService, "dept", "s_department", true, true); } + /*====================================================================================*/ @Bean - public UserInPositionSqlTerm userInPositionSqlTerm(PositionService positionService) { + public UserInSqlTerm userInPositionSqlTerm(PositionService positionService) { return new UserInPositionSqlTerm(false, false, "user-in-position", positionService); } @Bean - public UserInPositionSqlTerm userNotInPositionSqlTerm(PositionService positionService) { + public UserInSqlTerm userNotInPositionSqlTerm(PositionService positionService) { return new UserInPositionSqlTerm(true, false, "user-not-in-position", positionService); } @Bean - public UserInPositionSqlTerm userInPositionChildSqlTerm(PositionService positionService) { + public UserInSqlTerm userInPositionChildSqlTerm(PositionService positionService) { - return new UserInPositionSqlTerm(false, true, "user-in-position-child", positionService); + return new UserInPositionSqlTerm(false, true, "user-in-position-child", positionService).forChild(); } @Bean - public UserInPositionSqlTerm userNotInPositionChildSqlTerm(PositionService positionService) { + public UserInSqlTerm userNotInPositionChildSqlTerm(PositionService positionService) { - return new UserInPositionSqlTerm(true, true, "user-not-in-position-child", positionService); + return new UserInPositionSqlTerm(true, true, "user-not-in-position-child", positionService).forChild(); + } + + @Bean + public UserInSqlTerm userInPositionParentSqlTerm(PositionService positionService) { + + return new UserInPositionSqlTerm(false, true, "user-in-position-parent", positionService).forParent(); + } + + @Bean + public UserInSqlTerm userNotInPositionParentSqlTerm(PositionService positionService) { + return new UserInPositionSqlTerm(true, true, "user-not-in-position-parent", positionService).forParent(); } /*====================================================================================*/ @@ -105,6 +140,18 @@ public class CustomSqlTermConfiguration { return new UserInPositionSqlTerm(true, true, "person-not-in-position-child", positionService).forPerson(); } + @Bean + public UserInSqlTerm personInPositionParentSqlTerm(PositionService positionService) { + + return new UserInPositionSqlTerm(false, true, "person-in-position-parent", positionService).forPerson().forParent(); + } + + @Bean + public UserInSqlTerm personNotInPositionParentSqlTerm(PositionService positionService) { + + return new UserInPositionSqlTerm(true, true, "person-not-in-position-parent", positionService).forPerson().forParent(); + } + /*====================================================================================*/ @Bean public UserInSqlTerm userInDepartmentSqlTerm(DepartmentService departmentService) { @@ -121,13 +168,26 @@ public class CustomSqlTermConfiguration { @Bean public UserInSqlTerm userInDepartmentChildSqlTerm(DepartmentService departmentService) { - return new UserInDepartmentSqlTerm(false, true, "user-in-department-child", departmentService); + return new UserInDepartmentSqlTerm(false, true, "user-in-department-child", departmentService).forChild(); } @Bean public UserInSqlTerm userNotInDepartmentChildSqlTerm(DepartmentService departmentService) { - return new UserInDepartmentSqlTerm(true, true, "user-not-in-department-child", departmentService); + return new UserInDepartmentSqlTerm(true, true, "user-not-in-department-child", departmentService).forChild(); + } + + + @Bean + public UserInSqlTerm userInDepartmentParentSqlTerm(DepartmentService departmentService) { + + return new UserInDepartmentSqlTerm(false, true, "user-in-department-parent", departmentService).forParent(); + } + + @Bean + public UserInSqlTerm userNotInDepartmentParentSqlTerm(DepartmentService departmentService) { + + return new UserInDepartmentSqlTerm(true, true, "user-not-in-department-parent", departmentService).forParent(); } /*====================================================================================*/ @@ -155,6 +215,23 @@ public class CustomSqlTermConfiguration { return new UserInDepartmentSqlTerm(true, true, "person-not-in-department-child", departmentService).forPerson(); } + @Bean + public UserInSqlTerm personInDepartmentParentSqlTerm(DepartmentService departmentService) { + + return new UserInDepartmentSqlTerm(false, true, "person-in-department-parent", departmentService) + .forPerson() + .forParent(); + } + + @Bean + public UserInSqlTerm personNotInDepartmentParentSqlTerm(DepartmentService departmentService) { + + return new UserInDepartmentSqlTerm(true, true, "person-not-in-department-parent", departmentService) + .forPerson() + .forParent(); + } + + /*====================================================================================*/ @Bean public UserInSqlTerm userInOrgSqlTerm(OrganizationalService organizationalService) { @@ -181,6 +258,19 @@ public class CustomSqlTermConfiguration { } + @Bean + public UserInSqlTerm userInOrgParentSqlTerm(OrganizationalService organizationalService) { + + return new UserInOrgSqlTerm(false, true, "user-in-org-parent", organizationalService).forParent(); + } + + @Bean + public UserInSqlTerm userNotInOrgParentSqlTerm(OrganizationalService organizationalService) { + + return new UserInOrgSqlTerm(true, true, "user-not-in-org-parent", organizationalService).forParent(); + } + + /*====================================================================================*/ @Bean public UserInSqlTerm personInOrgSqlTerm(OrganizationalService organizationalService) { @@ -206,6 +296,17 @@ public class CustomSqlTermConfiguration { return new UserInOrgSqlTerm(true, true, "person-not-in-org-child", organizationalService).forPerson(); } + @Bean + public UserInSqlTerm personInOrgParentSqlTerm(OrganizationalService organizationalService) { + + return new UserInOrgSqlTerm(false, true, "person-in-org-parent", organizationalService).forPerson().forParent(); + } + + @Bean + public UserInSqlTerm personNotInOrgParentSqlTerm(OrganizationalService organizationalService) { + + return new UserInOrgSqlTerm(true, true, "person-not-in-org-parent", organizationalService).forPerson().forParent(); + } /*====================================================================================*/ @Bean @@ -232,6 +333,18 @@ public class CustomSqlTermConfiguration { return new UserInDistSqlTerm(true, true, "user-not-in-dist-child", districtService); } + @Bean + public UserInSqlTerm userInDistParentSqlTerm(DistrictService districtService) { + + return new UserInDistSqlTerm(false, true, "user-in-dist-parent", districtService).forParent(); + } + + @Bean + public UserInSqlTerm userNotInDistParentSqlTerm(DistrictService districtService) { + + return new UserInDistSqlTerm(true, true, "user-not-in-dist-parent", districtService).forParent(); + } + /*====================================================================================*/ @Bean public UserInSqlTerm personInDistSqlTerm(DistrictService districtService) { @@ -257,5 +370,17 @@ public class CustomSqlTermConfiguration { return new UserInDistSqlTerm(true, true, "person-not-in-dist-child", districtService).forPerson(); } + @Bean + public UserInSqlTerm personInDistParentSqlTerm(DistrictService districtService) { + + return new UserInDistSqlTerm(false, true, "person-in-dist-parent", districtService).forPerson().forParent(); + } + + @Bean + public UserInSqlTerm personNotInDistParentSqlTerm(DistrictService districtService) { + + return new UserInDistSqlTerm(true, true, "person-not-in-dist-parent", districtService).forPerson().forParent(); + } + } diff --git a/hsweb-system/hsweb-system-organizational/hsweb-system-organizational-local/src/main/java/org/hswebframework/web/service/organizational/simple/terms/InServiceTreeInSqlTerm.java b/hsweb-system/hsweb-system-organizational/hsweb-system-organizational-local/src/main/java/org/hswebframework/web/service/organizational/simple/terms/InServiceTreeInSqlTerm.java index 7b07082e4..632b4c5ef 100644 --- a/hsweb-system/hsweb-system-organizational/hsweb-system-organizational-local/src/main/java/org/hswebframework/web/service/organizational/simple/terms/InServiceTreeInSqlTerm.java +++ b/hsweb-system/hsweb-system-organizational/hsweb-system-organizational-local/src/main/java/org/hswebframework/web/service/organizational/simple/terms/InServiceTreeInSqlTerm.java @@ -18,8 +18,11 @@ public class InServiceTreeInSqlTerm extends TreeStructureSqlTermCustomer { private String tableName; - public InServiceTreeInSqlTerm(QueryService, PK> service, String prefix, String tableName, boolean not) { - super(prefix + "-child-" + (not ? "not-" : "") + "in", not); + public InServiceTreeInSqlTerm(QueryService, PK> service, + String prefix, + String tableName, + boolean not, boolean parent) { + super(prefix + "-" + (parent ? "parent" : "child") + "-" + (not ? "not-" : "") + "in", not, parent); this.treeService = service; this.tableName = tableName; } diff --git a/hsweb-system/hsweb-system-organizational/hsweb-system-organizational-local/src/main/java/org/hswebframework/web/service/organizational/simple/terms/UserInDepartmentSqlTerm.java b/hsweb-system/hsweb-system-organizational/hsweb-system-organizational-local/src/main/java/org/hswebframework/web/service/organizational/simple/terms/UserInDepartmentSqlTerm.java index 033281b95..d03fa2664 100644 --- a/hsweb-system/hsweb-system-organizational/hsweb-system-organizational-local/src/main/java/org/hswebframework/web/service/organizational/simple/terms/UserInDepartmentSqlTerm.java +++ b/hsweb-system/hsweb-system-organizational/hsweb-system-organizational-local/src/main/java/org/hswebframework/web/service/organizational/simple/terms/UserInDepartmentSqlTerm.java @@ -3,6 +3,7 @@ package org.hswebframework.web.service.organizational.simple.terms; import org.hswebframework.ezorm.core.param.Term; import org.hswebframework.ezorm.rdb.meta.RDBColumnMetaData; import org.hswebframework.ezorm.rdb.render.SqlAppender; +import org.hswebframework.ezorm.rdb.render.dialect.Dialect; import org.hswebframework.ezorm.rdb.render.dialect.term.BoostTermTypeMapper; import org.hswebframework.web.dao.mybatis.mapper.ChangedTermValue; import org.hswebframework.web.service.organizational.DepartmentService; @@ -35,6 +36,8 @@ public class UserInDepartmentSqlTerm extends UserInSqlTerm { public SqlAppender accept(String wherePrefix, Term term, RDBColumnMetaData column, String tableAlias) { ChangedTermValue termValue = createChangedTermValue(term); + Dialect dialect=column.getTableMetaData().getDatabaseMetaData().getDialect(); + SqlAppender appender = new SqlAppender(); appender.addSpc(not ? "not" : "", "exists(select 1 from s_person_position _tmp,s_position _pos,s_person _person"); if (isChild()) { @@ -49,7 +52,7 @@ public class UserInDepartmentSqlTerm extends UserInSqlTerm { List positionIdList = BoostTermTypeMapper.convertList(column, termValue.getOld()); if (!positionIdList.isEmpty()) { appender.addSpc("and"); - termValue.setValue(appendCondition(positionIdList, wherePrefix, appender, "_pos.department_id")); + termValue.setValue(appendCondition(positionIdList, wherePrefix, appender, "_pos.department_id",dialect)); } appender.add(")"); diff --git a/hsweb-system/hsweb-system-organizational/hsweb-system-organizational-local/src/main/java/org/hswebframework/web/service/organizational/simple/terms/UserInDistSqlTerm.java b/hsweb-system/hsweb-system-organizational/hsweb-system-organizational-local/src/main/java/org/hswebframework/web/service/organizational/simple/terms/UserInDistSqlTerm.java index 884b7fccc..a561d7c95 100644 --- a/hsweb-system/hsweb-system-organizational/hsweb-system-organizational-local/src/main/java/org/hswebframework/web/service/organizational/simple/terms/UserInDistSqlTerm.java +++ b/hsweb-system/hsweb-system-organizational/hsweb-system-organizational-local/src/main/java/org/hswebframework/web/service/organizational/simple/terms/UserInDistSqlTerm.java @@ -3,10 +3,10 @@ package org.hswebframework.web.service.organizational.simple.terms; import org.hswebframework.ezorm.core.param.Term; import org.hswebframework.ezorm.rdb.meta.RDBColumnMetaData; import org.hswebframework.ezorm.rdb.render.SqlAppender; +import org.hswebframework.ezorm.rdb.render.dialect.Dialect; import org.hswebframework.ezorm.rdb.render.dialect.term.BoostTermTypeMapper; import org.hswebframework.web.dao.mybatis.mapper.ChangedTermValue; import org.hswebframework.web.service.organizational.DistrictService; -import org.hswebframework.web.service.organizational.PositionService; import java.util.List; @@ -35,6 +35,7 @@ public class UserInDistSqlTerm extends UserInSqlTerm { @Override public SqlAppender accept(String wherePrefix, Term term, RDBColumnMetaData column, String tableAlias) { ChangedTermValue termValue = createChangedTermValue(term); + Dialect dialect=column.getTableMetaData().getDatabaseMetaData().getDialect(); SqlAppender appender = new SqlAppender(); appender.addSpc(not ? "not" : "", "exists(select 1 from s_person_position _tmp,s_position _pos,s_person _person,s_department _dept,s_organization _org"); @@ -49,7 +50,7 @@ public class UserInDistSqlTerm extends UserInSqlTerm { List positionIdList = BoostTermTypeMapper.convertList(column, termValue.getOld()); if (!positionIdList.isEmpty()) { appender.addSpc("and"); - termValue.setValue(appendCondition(positionIdList, wherePrefix, appender, "_org.district_id")); + termValue.setValue(appendCondition(positionIdList, wherePrefix, appender, "_org.district_id",dialect)); } appender.add(")"); diff --git a/hsweb-system/hsweb-system-organizational/hsweb-system-organizational-local/src/main/java/org/hswebframework/web/service/organizational/simple/terms/UserInOrgSqlTerm.java b/hsweb-system/hsweb-system-organizational/hsweb-system-organizational-local/src/main/java/org/hswebframework/web/service/organizational/simple/terms/UserInOrgSqlTerm.java index f3a8704e5..9edb74e21 100644 --- a/hsweb-system/hsweb-system-organizational/hsweb-system-organizational-local/src/main/java/org/hswebframework/web/service/organizational/simple/terms/UserInOrgSqlTerm.java +++ b/hsweb-system/hsweb-system-organizational/hsweb-system-organizational-local/src/main/java/org/hswebframework/web/service/organizational/simple/terms/UserInOrgSqlTerm.java @@ -3,10 +3,10 @@ package org.hswebframework.web.service.organizational.simple.terms; import org.hswebframework.ezorm.core.param.Term; import org.hswebframework.ezorm.rdb.meta.RDBColumnMetaData; import org.hswebframework.ezorm.rdb.render.SqlAppender; +import org.hswebframework.ezorm.rdb.render.dialect.Dialect; import org.hswebframework.ezorm.rdb.render.dialect.term.BoostTermTypeMapper; import org.hswebframework.web.dao.mybatis.mapper.ChangedTermValue; import org.hswebframework.web.service.organizational.OrganizationalService; -import org.hswebframework.web.service.organizational.PositionService; import java.util.List; @@ -21,7 +21,7 @@ public class UserInOrgSqlTerm extends UserInSqlTerm { private boolean not; - public UserInOrgSqlTerm(boolean not,boolean child, String term, OrganizationalService service) { + public UserInOrgSqlTerm(boolean not, boolean child, String term, OrganizationalService service) { super(term, service); setChild(child); this.not = not; @@ -35,6 +35,7 @@ public class UserInOrgSqlTerm extends UserInSqlTerm { @Override public SqlAppender accept(String wherePrefix, Term term, RDBColumnMetaData column, String tableAlias) { ChangedTermValue termValue = createChangedTermValue(term); + Dialect dialect = column.getTableMetaData().getDatabaseMetaData().getDialect(); SqlAppender appender = new SqlAppender(); appender.addSpc(not ? "not" : "", "exists(select 1 from s_person_position _tmp,s_position _pos,s_department _dept,s_person _person"); @@ -42,14 +43,14 @@ public class UserInOrgSqlTerm extends UserInSqlTerm { appender.addSpc(",s_organization _org"); } appender.addSpc("where _person.u_id=_tmp.person_id and _tmp.position_id = _pos.u_id and _person.u_id=_tmp.person_id and _dept.u_id=_pos.department_id" - , "and", createColumnName(column, tableAlias), "=", isForPerson() ? "_tmp.person_id" : "_person.user_id"); + , "and", createColumnName(column, tableAlias), "=", isForPerson() ? "_tmp.person_id" : "_person.user_id"); if (isChild()) { appender.addSpc("and _org.u_id=_dept.org_id"); } List positionIdList = BoostTermTypeMapper.convertList(column, termValue.getOld()); if (!positionIdList.isEmpty()) { appender.addSpc("and"); - termValue.setValue(appendCondition(positionIdList, wherePrefix, appender, "_dept.org_id")); + termValue.setValue(appendCondition(positionIdList, wherePrefix, appender, "_dept.org_id", dialect)); } appender.add(")"); diff --git a/hsweb-system/hsweb-system-organizational/hsweb-system-organizational-local/src/main/java/org/hswebframework/web/service/organizational/simple/terms/UserInPositionSqlTerm.java b/hsweb-system/hsweb-system-organizational/hsweb-system-organizational-local/src/main/java/org/hswebframework/web/service/organizational/simple/terms/UserInPositionSqlTerm.java index 29b9a77c0..29fbfb4ff 100644 --- a/hsweb-system/hsweb-system-organizational/hsweb-system-organizational-local/src/main/java/org/hswebframework/web/service/organizational/simple/terms/UserInPositionSqlTerm.java +++ b/hsweb-system/hsweb-system-organizational/hsweb-system-organizational-local/src/main/java/org/hswebframework/web/service/organizational/simple/terms/UserInPositionSqlTerm.java @@ -3,6 +3,7 @@ package org.hswebframework.web.service.organizational.simple.terms; import org.hswebframework.ezorm.core.param.Term; import org.hswebframework.ezorm.rdb.meta.RDBColumnMetaData; import org.hswebframework.ezorm.rdb.render.SqlAppender; +import org.hswebframework.ezorm.rdb.render.dialect.Dialect; import org.hswebframework.ezorm.rdb.render.dialect.term.BoostTermTypeMapper; import org.hswebframework.web.dao.mybatis.mapper.ChangedTermValue; import org.hswebframework.web.service.organizational.PositionService; @@ -34,6 +35,7 @@ public class UserInPositionSqlTerm extends UserInSqlTerm { @Override public SqlAppender accept(String wherePrefix, Term term, RDBColumnMetaData column, String tableAlias) { ChangedTermValue termValue = createChangedTermValue(term); + Dialect dialect=column.getTableMetaData().getDatabaseMetaData().getDialect(); SqlAppender appender = new SqlAppender(); appender.addSpc(not ? "not" : "", "exists(select 1 from s_person_position _tmp"); @@ -55,7 +57,7 @@ public class UserInPositionSqlTerm extends UserInSqlTerm { List positionIdList = BoostTermTypeMapper.convertList(column, termValue.getOld()); if (!positionIdList.isEmpty()) { appender.addSpc("and"); - termValue.setValue(appendCondition(positionIdList, wherePrefix, appender, "_tmp.position_id")); + termValue.setValue(appendCondition(positionIdList, wherePrefix, appender, "_tmp.position_id",dialect)); } appender.add(")"); diff --git a/hsweb-system/hsweb-system-organizational/hsweb-system-organizational-local/src/main/java/org/hswebframework/web/service/organizational/simple/terms/UserInSqlTerm.java b/hsweb-system/hsweb-system-organizational/hsweb-system-organizational-local/src/main/java/org/hswebframework/web/service/organizational/simple/terms/UserInSqlTerm.java index 849393c3e..572b2e580 100644 --- a/hsweb-system/hsweb-system-organizational/hsweb-system-organizational-local/src/main/java/org/hswebframework/web/service/organizational/simple/terms/UserInSqlTerm.java +++ b/hsweb-system/hsweb-system-organizational/hsweb-system-organizational-local/src/main/java/org/hswebframework/web/service/organizational/simple/terms/UserInSqlTerm.java @@ -2,14 +2,16 @@ package org.hswebframework.web.service.organizational.simple.terms; import lombok.Getter; import lombok.Setter; -import org.hswebframework.ezorm.core.param.Term; -import org.hswebframework.ezorm.rdb.meta.RDBColumnMetaData; +import lombok.extern.slf4j.Slf4j; import org.hswebframework.ezorm.rdb.render.SqlAppender; -import org.hswebframework.ezorm.rdb.render.dialect.term.BoostTermTypeMapper; +import org.hswebframework.ezorm.rdb.render.dialect.Dialect; +import org.hswebframework.ezorm.rdb.render.dialect.RenderPhase; +import org.hswebframework.ezorm.rdb.render.dialect.function.SqlFunction; import org.hswebframework.web.commons.entity.TreeSupportEntity; import org.hswebframework.web.dao.mybatis.mapper.AbstractSqlTermCustomer; import org.hswebframework.web.service.QueryService; +import java.util.Arrays; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; @@ -21,12 +23,18 @@ import java.util.stream.Collectors; * @author zhouhao * @since 3.0.0-RC */ +@Slf4j public abstract class UserInSqlTerm extends AbstractSqlTermCustomer { @Setter @Getter private boolean child; + + @Getter + @Setter + private boolean parent; + @Getter @Setter private boolean forPerson; @@ -34,6 +42,16 @@ public abstract class UserInSqlTerm extends AbstractSqlTermCustomer { QueryService, PK> treeService; + public UserInSqlTerm forChild() { + setChild(true); + return this; + } + + public UserInSqlTerm forParent() { + setParent(true); + return this; + } + public UserInSqlTerm forPerson() { this.forPerson = true; return this; @@ -46,14 +64,15 @@ public abstract class UserInSqlTerm extends AbstractSqlTermCustomer { public abstract String getTableName(); - protected Object appendCondition(List values, String wherePrefix, SqlAppender appender, String column) { + + protected Object appendCondition(List values, String wherePrefix, SqlAppender appender, String column, Dialect dialect) { if (!child) { appender.addSpc(column); return super.appendCondition(values, wherePrefix, appender); } else { List paths = getTreePathByTerm(values) .stream() - .map(path -> path.concat("%")) + .map(path -> parent ? path : path.concat("%")) .collect(Collectors.toList()); int len = paths.size(); if (len == 0) { @@ -64,7 +83,21 @@ public abstract class UserInSqlTerm extends AbstractSqlTermCustomer { if (i > 0) { appender.addSpc("or"); } - appender.add(getTableName() + ".path like #{", wherePrefix, ".value.value[", i, "]}"); + if (parent) { + SqlFunction function = dialect.getFunction(SqlFunction.concat); + String concat; + if (function == null) { + concat = getTableName() + ".path"; + log.warn("数据库方言未支持concat函数,你可以调用Dialect.installFunction进行设置!"); + } else { + concat = function.apply(SqlFunction.Param.of(RenderPhase.where, Arrays.asList(getTableName() + ".path", "'%'"))); + } + // aaa-vvv-ccc like aaa% + appender.add("#{", wherePrefix, ".value.value[", i, "]}", " like ", concat); + } else { + appender.add(getTableName(), ".path like #{", wherePrefix, ".value.value[", i, "]}"); + } + } appender.add(")"); }