diff --git a/build.gradle b/build.gradle index a349c5c..4c2cbc9 100644 --- a/build.gradle +++ b/build.gradle @@ -55,7 +55,7 @@ uploadArchives { authentication(userName: NEXUS_USERNAME, password: NEXUS_PASSWORD) } pom.project { - version '2.1.34' + version '2.1.36' artifactId ARTIFACT_Id groupId GROUP_ID packaging TYPE diff --git a/src/main/java/com/taover/repository/CustomJdbcTemplateWrapperTenant.java b/src/main/java/com/taover/repository/CustomJdbcTemplateWrapperTenant.java index ca10690..c23f142 100644 --- a/src/main/java/com/taover/repository/CustomJdbcTemplateWrapperTenant.java +++ b/src/main/java/com/taover/repository/CustomJdbcTemplateWrapperTenant.java @@ -296,9 +296,8 @@ public class CustomJdbcTemplateWrapperTenant impleme } @Override - public T findEntityByCondition(List condition) throws NotFoundException, MultiRowException, NoContainTenantException { - this.checkTenantInfoFromCondition(condition); - List tempList = findListByCondition(condition); + public T findEntityByCondition(List condition, Long tenantId) throws NotFoundException, MultiRowException, NoContainTenantException { + List tempList = findListByCondition(condition, tenantId); if(tempList == null || tempList.size() == 0){ throw new NotFoundException(); } @@ -309,22 +308,9 @@ public class CustomJdbcTemplateWrapperTenant impleme } } - private void checkTenantInfoFromCondition(List condition) throws NoContainTenantException{ - for(Object[] item: condition) { - if(item == null || item.length == 0) { - continue; - } - if(item[0].toString().contains("tenant_id")) { - return; - } - } - throw new NoContainTenantException(); - } - @Override - public T findEntityBySql(String sqlCondition) throws NotFoundException, MultiRowException, NoContainTenantException { - this.checkTenantInfoFromSql(sqlCondition); - List tempList = findListBySql(sqlCondition); + public T findEntityBySql(String sqlCondition, Long tenantId) throws NotFoundException, MultiRowException { + List tempList = findListBySql(sqlCondition, tenantId); if(tempList == null || tempList.size() == 0){ throw new NotFoundException(); } @@ -334,53 +320,41 @@ public class CustomJdbcTemplateWrapperTenant impleme throw new MultiRowException(); } } - - private void checkTenantInfoFromSql(String sqlCondition) throws NoContainTenantException{ - if(sqlCondition.contains("tenant_id")) { - return; - }else { - throw new NoContainTenantException(); - } - } - + @Override - public List findListByCondition(List condition) throws NoContainTenantException { - return findListByCondition(condition, null); + public List findListByCondition(List condition, Long tenantId){ + return findListByCondition(condition, null, tenantId); } @Override - public List findListByCondition(List condition, String sortCondition) throws NoContainTenantException { - this.checkTenantInfoFromCondition(condition); + public List findListByCondition(List condition, String sortCondition, Long tenantId){ StringBuffer sql = new StringBuffer("SELECT "+this.tableFieldNameListGapWithComma+" FROM "+this.getTableSql()); - StringBuffer pql = new StringBuffer(sql.toString()); List list = new ArrayList(); - this.appendWhereCondition(sql, pql, list, condition); + condition.add(new Object[] {"tenant_id", "=", tenantId}); + this.appendWhereCondition(sql, new StringBuffer(), list, condition); if(sortCondition != null && !sortCondition.equals("")){ sql.append(" " + sortCondition + " "); - pql.append(" " + sortCondition + " "); } return (List)jdbcTemplateWrite.query(sql.toString(), this.customJdbcTemplateRowMapper, list.toArray()); } @Override - public List findListBySql(String sqlCondition) throws NoContainTenantException { - this.checkTenantInfoFromSql(sqlCondition); - StringBuffer sql = new StringBuffer("SELECT "+this.tableFieldNameListGapWithComma+" FROM "+this.getTableSql()+" WHERE " + sqlCondition); + public List findListBySql(String sqlCondition, Long tenantId){ + StringBuffer sql = new StringBuffer("SELECT "+this.tableFieldNameListGapWithComma+" FROM "+this.getTableSql()+" WHERE tenant_id="+tenantId + " and " + sqlCondition); return (List)jdbcTemplateWrite.query(sql.toString(), this.customJdbcTemplateRowMapper); } @Override - public Map findPageByCondition(List condition, int page, int pageSize) throws NoContainTenantException { - return findPageByCondition(condition, null , page, pageSize); + public Map findPageByCondition(List condition, int page, int pageSize, Long tenantId){ + return findPageByCondition(condition, null , page, pageSize, tenantId); } @Override - public Map findPageByCondition(List condition, String sortCondition, int page, int pageSize) throws NoContainTenantException { - this.checkTenantInfoFromCondition(condition); + public Map findPageByCondition(List condition, String sortCondition, int page, int pageSize, Long tenantId){ StringBuffer sql = new StringBuffer("SELECT "+this.tableFieldNameListGapWithComma+" FROM "+this.getTableSql()); StringBuffer pql = new StringBuffer(sql.toString()); StringBuffer sqlCount = new StringBuffer("SELECT COUNT(1) rowCount FROM "+this.getTableSql()); - + condition.add(new Object[] {"tenant_id", "=", tenantId}); List count_list = new ArrayList(); List page_list = new ArrayList(); this.appendWhereConditionForCount(sqlCount, condition); @@ -404,10 +378,9 @@ public class CustomJdbcTemplateWrapperTenant impleme } @Override - public Map findPageBySql(String sqlCondition, int page, int pageSize) throws NoContainTenantException { - this.checkTenantInfoFromSql(sqlCondition); - StringBuffer sql = new StringBuffer("SELECT "+this.tableFieldNameListGapWithComma+" FROM "+this.getTableSql()+" WHERE " + sqlCondition ); - StringBuffer sqlCount = new StringBuffer("SELECT count(1) rowCount FROM "+this.getTableSql()+" WHERE " + sqlCondition); + public Map findPageBySql(String sqlCondition, int page, int pageSize, Long tenantId){ + StringBuffer sql = new StringBuffer("SELECT "+this.tableFieldNameListGapWithComma+" FROM "+this.getTableSql()+" WHERE tenant_id=" + tenantId + " and " + sqlCondition ); + StringBuffer sqlCount = new StringBuffer("SELECT count(1) rowCount FROM "+this.getTableSql()+" WHERE tenant_id=" + tenantId + " and " + sqlCondition); sql.append(" limit ?, ?"); List page_list = new ArrayList(); page_list.add((page - 1) * pageSize); @@ -498,35 +471,34 @@ public class CustomJdbcTemplateWrapperTenant impleme } @Override - public int deleteEntityByCondition(List condition) throws NoContainTenantException { + public int deleteEntityByCondition(List condition, Long tenantId){ if (null == condition || condition.size() == 0) { throw new RuntimeException("params[condition] is empty"); } - this.checkTenantInfoFromCondition(condition); List list = new ArrayList(); StringBuffer sql = new StringBuffer("DELETE FROM "+this.getTableSql()+""); StringBuffer pql = new StringBuffer(sql.toString()); + condition.add(new Object[] {"tenant_id", "=", tenantId}); this.appendWhereCondition(sql, pql, list, condition); return jdbcTemplateWrite.update( sql.toString(), list.toArray()); } @Override - public int deleteEntityBySql(String sqlCondition) throws NoContainTenantException { + public int deleteEntityBySql(String sqlCondition, Long tenantId){ if("".equals(sqlCondition.trim())) { throw new RuntimeException("params[sqlCondition] is empty"); } - this.checkTenantInfoFromSql(sqlCondition); - return jdbcTemplateWrite.update( "DELETE FROM "+this.getTableSql()+" WHERE " + sqlCondition); + return jdbcTemplateWrite.update( "DELETE FROM "+this.getTableSql()+" WHERE tenant_id="+tenantId + " and " + sqlCondition); } @Override - public int deleteEntityList(List idList, Long tenantId) throws NoContainTenantException { + public int deleteEntityList(List idList, Long tenantId){ StringBuffer idSb = new StringBuffer(); for(ID id: idList) { idSb.append(id); } - return this.deleteEntityBySql(this.idTableFieldName + " in ("+idSb.toString().substring(0, idSb.length()-1)+") and tenant_id="+tenantId); + return this.deleteEntityBySql(this.idTableFieldName + " in ("+idSb.toString().substring(0, idSb.length()-1)+") and tenant_id="+tenantId, tenantId); } @Override @@ -550,20 +522,20 @@ public class CustomJdbcTemplateWrapperTenant impleme } @Override - public int updateEntityByCondition(List updateObj, List condition) throws NoContainTenantException { + public int updateEntityByCondition(List updateObj, List condition, Long tenantId){ if (null == updateObj || updateObj.size() == 0) { throw new RuntimeException("params[updateObj] is empty"); } if (null == condition || condition.size() == 0) { throw new RuntimeException("params[condition] is empty"); } - this.checkTenantInfoFromCondition(condition); StringBuffer sql = new StringBuffer("UPDATE "+this.getTableSql()+" SET"); StringBuffer pql = new StringBuffer(sql.toString()); List list = new ArrayList(); this.appendSetSql(sql, pql, list, updateObj); + condition.add(new Object[] {"tenant_id", "=", tenantId}); StringBuffer where = new StringBuffer(""); StringBuffer pwhere = new StringBuffer(""); this.appendWhereCondition(where, pwhere, list, condition); @@ -573,38 +545,36 @@ public class CustomJdbcTemplateWrapperTenant impleme } @Override - public int updateEntityBySql(List updateObj, String sqlCondition) throws NoContainTenantException { + public int updateEntityBySql(List updateObj, String sqlCondition, Long tenantId){ if (null == updateObj || updateObj.size() == 0) { throw new RuntimeException("params[updateObj] is empty"); } if ("".equals(sqlCondition)) { throw new RuntimeException("params[sqlCondition] is empty"); } - this.checkTenantInfoFromSql(sqlCondition); StringBuffer sql = new StringBuffer("UPDATE "+this.getTableSql()+" SET"); StringBuffer pql = new StringBuffer(sql.toString()); List list = new ArrayList(); this.appendSetSql(sql, pql, list, updateObj); - String updateSql = sql.toString().substring(0, sql.length()-1) + " WHERE "+sqlCondition; + String updateSql = sql.toString().substring(0, sql.length()-1) + " WHERE tenant_id="+tenantId+" and "+sqlCondition; return jdbcTemplateWrite.update(updateSql, list.toArray()); } @Override - public Map getPageData(String coreSql, String orderByPartSql, Integer page, Integer pageSize) throws NoContainTenantException { - this.checkTenantInfoFromSql(coreSql); + public Map getPageData(String coreSql, String orderByPartSql, Integer page, Integer pageSize, Long tenantId){ try { String[] splitedSql = UtilsSql.splitCoreSql(coreSql); - return this.getPageData(splitedSql[0], splitedSql[1], orderByPartSql, page, pageSize); + return this.getPageData(splitedSql[0], splitedSql[1], orderByPartSql, page, pageSize, tenantId); }catch (Exception e) { return UtilsSql.createPage(page, pageSize, 0, new ArrayList()); } } @Override - public Map getPageData(String selectSql, String fromAndWhereSql, String orderByPartSql, Integer page, Integer pageSize) throws NoContainTenantException { - this.checkTenantInfoFromSql(fromAndWhereSql); + public Map getPageData(String selectSql, String fromAndWhereSql, String orderByPartSql, Integer page, Integer pageSize, Long tenantId){ + fromAndWhereSql = fromAndWhereSql + " and tenant_id="+tenantId; //构造查询语句 String querySql = selectSql+" "+fromAndWhereSql+" "+orderByPartSql+" "+UtilsSql.getLimitCondition(page, pageSize); diff --git a/src/main/java/com/taover/repository/JdbcRepositoryWrapperTenant.java b/src/main/java/com/taover/repository/JdbcRepositoryWrapperTenant.java index 7e828cb..f5e0125 100644 --- a/src/main/java/com/taover/repository/JdbcRepositoryWrapperTenant.java +++ b/src/main/java/com/taover/repository/JdbcRepositoryWrapperTenant.java @@ -27,40 +27,40 @@ public interface JdbcRepositoryWrapperTenant { * Object[]数组长度是3 * Object[], 第一个参数是列名,第二个参数是操作符,第三个参数是查询条件的值。 */ - public T findEntityByCondition(List condition) throws NotFoundException,MultiRowException,NoContainTenantException; + public T findEntityByCondition(List condition, Long tenantId) throws NotFoundException,MultiRowException,NoContainTenantException; /** * 根据条件sql查询 * sqlCondition 为where 后面的条件。 */ - public T findEntityBySql(String sqlCondition) throws NotFoundException,MultiRowException,NoContainTenantException; + public T findEntityBySql(String sqlCondition, Long tenantId) throws NotFoundException,MultiRowException,NoContainTenantException; /** * 根据条件List查询 * Object[]数组长度是3 * Object[], 第一个参数是列名,第二个参数是操作符,第三个参数是查询条件的值。 */ - public List findListByCondition(List condition) throws NoContainTenantException; + public List findListByCondition(List condition, Long tenantId); /** * 根据条件List查询 * Object[]数组长度是3 * Object[], 第一个参数是列名,第二个参数是操作符,第三个参数是查询条件的值。 */ - public List findListByCondition(List condition, String sortCondition) throws NoContainTenantException; + public List findListByCondition(List condition, String sortCondition, Long tenantId); /** * 根据条件sql查询 * sqlCondition 为where 后面的条件。 */ - public List findListBySql(String sqlCondition) throws NoContainTenantException; + public List findListBySql(String sqlCondition, Long tenantId); /** * 按条件分页查询 * Object[]数组长度是3 * Object[], 第一个参数是列名,第二个参数是操作符,第三个参数是查询条件的值。 */ - public Map findPageByCondition(List condition, int page, int pageSize) throws NoContainTenantException; + public Map findPageByCondition(List condition, int page, int pageSize, Long tenantId); /** * 按条件分页查询 @@ -69,12 +69,12 @@ public interface JdbcRepositoryWrapperTenant { * boolean isUseCache, 是否用缓存,默认用。 * boolean isAddCache, 是否添加缓存,默认添加。 */ - public Map findPageByCondition(List condition, String sortCondition, int page, int pageSize) throws NoContainTenantException; + public Map findPageByCondition(List condition, String sortCondition, int page, int pageSize, Long tenantId); /** * 按sql分页查询, sqlCondition为where 后条件sql */ - public Map findPageBySql(String sqlCondition, int page, int pageSize) throws NoContainTenantException; + public Map findPageBySql(String sqlCondition, int page, int pageSize, Long tenantId); /** * 添加 @@ -97,20 +97,20 @@ public interface JdbcRepositoryWrapperTenant { * Object[]数组长度是3 * Object[], 第一个参数是列名,第二个参数是操作符,第三个参数是查询条件的值。 */ - public int deleteEntityByCondition(List condition) throws NoContainTenantException; + public int deleteEntityByCondition(List condition, Long tenantId); /** * 删除按condition条件 * 建议使用deleteTByCondition(List condition), 如果removeTByCondition(List condition)满足不了where条件可以使用此方法。 * condition为where后面的条件,condition不能为空。 */ - public int deleteEntityBySql(String sqlCondition) throws NoContainTenantException; + public int deleteEntityBySql(String sqlCondition, Long tenantId); /** * 根据list对象逐个删除。 * @throws NoContainTenantException */ - public int deleteEntityList(List idList, Long tenantId) throws NoContainTenantException; + public int deleteEntityList(List idList, Long tenantId); /** * 根据ID修改指定的值 @@ -121,13 +121,13 @@ public interface JdbcRepositoryWrapperTenant { * List updateObj 要修改成的值,数组长度为2,第一个值为列名,第二个值是要改成的值。 * List condition 修改的条件, 数组长度是3, 第一个参数是列名,第二个参数是操作符,第三个参数是查询条件的值。 */ - public int updateEntityByCondition(List updateObj, List condition) throws NoContainTenantException; + public int updateEntityByCondition(List updateObj, List condition, Long tenantId); /** * List updateObj 要修改成的值,数组长度为2,第一个值为列名,第二个值是要改成的值。 * String sqlCondition 修改的条件。 */ - public int updateEntityBySql(List updateObj, String sqlCondition) throws NoContainTenantException; + public int updateEntityBySql(List updateObj, String sqlCondition, Long tenantId); /** * 获取分页数据 @@ -137,7 +137,7 @@ public interface JdbcRepositoryWrapperTenant { * @param pageSize * @return */ - public Map getPageData(String coreSql, String orderByPartSql, Integer page, Integer pageSize) throws NoContainTenantException; + public Map getPageData(String coreSql, String orderByPartSql, Integer page, Integer pageSize, Long tenantId); /** * 获取分页数据 @@ -148,5 +148,5 @@ public interface JdbcRepositoryWrapperTenant { * @param pageSize * @return */ - public Map getPageData(String selectSql, String fromAndWhereSql, String orderByPartSql, Integer page, Integer pageSize) throws NoContainTenantException; + public Map getPageData(String selectSql, String fromAndWhereSql, String orderByPartSql, Integer page, Integer pageSize, Long tenantId); } -- libgit2 0.21.2