mirror of https://gitee.com/stylefeng/roses
【8.0.1】【db】更新一个获取最大数的方法
parent
e52abc7c41
commit
a6769cbda0
|
@ -74,4 +74,12 @@ public interface DbOperatorApi {
|
||||||
*/
|
*/
|
||||||
Set<Long> findSubListByParentId(String tableName, String parentIdsFieldName, String keyFieldName, Long keyFieldValue);
|
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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,7 @@ import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
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());
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue