【8.0.1】【db】更新一个获取最大数的方法

pull/57/head
fengshuonan 2023-10-29 16:53:06 +08:00
parent e52abc7c41
commit a6769cbda0
2 changed files with 23 additions and 0 deletions

View File

@ -74,4 +74,12 @@ public interface DbOperatorApi {
*/
Set<Long> findSubListByParentId(String tableName, String parentIdsFieldName, String keyFieldName, Long keyFieldValue);
/**
*
*
* @author fengshuonan
* @since 2023/10/29 16:07
*/
Long getMaxSortByTableName(String tableName, String fieldName);
}

View File

@ -35,6 +35,7 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
@ -75,4 +76,18 @@ public class DbOperatorImpl implements DbOperatorApi {
return subIds.stream().map(i -> Long.valueOf(i.toString())).collect(Collectors.toSet());
}
@Override
public Long getMaxSortByTableName(String tableName, String fieldName) {
String tempFieldName = "maxSort";
String sqlTemplate = "select max({}) as {} from {}";
String sql = StrUtil.format(sqlTemplate, fieldName, tempFieldName, tableName);
Map<String, Object> oneResult = SqlRunner.db().selectOne(sql);
Object maxSort = oneResult.get(tempFieldName);
return Convert.toLong(maxSort);
}
}