java SDK对接金蝶数据包装类(仅查询)
Posted £漫步 云端彡
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java SDK对接金蝶数据包装类(仅查询)相关的知识,希望对你有一定的参考价值。
java SDK对接金蝶
-
如果是Maven管理,可以在pom.xml中加入如下依赖:
<!-- 金蝶云对接 --> <dependency> <groupId>com.kingdee</groupId> <artifactId>k3cloud-webapi</artifactId> <version>1.0.0</version> <scope>system</scope> <!-- jar包存放的位置 --> <systemPath>$project.basedir/lib/k3cloud-webapi-sdk7.9.2.jar</systemPath> </dependency>
-
起步配置有官方教程:查看官方指南
-
官网只提供了一些查询数据方法。对于java代码来说写起来很不舒服。下面我做了一些工具类。
3.1 序列化SFunction<T, R>@FunctionalInterface public interface SFunction<T, R> extends Function<T, R>, Serializable
3.2 条件过滤构建器FilterRuleBuilder,类比mybatis
public class FilterRuleBuilder public FilterRuleBuilder() /** * 查询参数构造器 */ protected List<String> fieldKeys = new ArrayList<>(); /** * 过滤条件构造器 */ protected StringBuilder filterStrBuilder = new StringBuilder(); /** * 排序规则条件构造器 */ protected StringBuilder orderBuilder = new StringBuilder(); /** * 返回总行数 */ protected int TopRowCount = 0; /** * 开始行索引 */ protected int StartRow = 0; /** * 最大行数 */ protected int Limit = 0; protected final String LOGIC_AND = " AND "; protected final String LOGIC_OR = " OR "; /** * 逻辑关系,默认and */ protected String logic = LOGIC_AND; /** * 获取查询字段 * * @return */ public List<String> getFieldKeys() return this.fieldKeys; /** * 切换and逻辑 * * @return */ public FilterRuleBuilder and() this.logic = LOGIC_AND; return this; /** * 列表查询字段 * * @param fieldKeys * @return */ public FilterRuleBuilder select(List<String> fieldKeys) this.fieldKeys = fieldKeys; return this; /** * 查询具体类的所有字段:所有子字段用下划线代替,例如:FDocumentStatus.FCaption ==》FDocumentStatus_FCaption * * @param cls * @return */ public FilterRuleBuilder selectAllFiled(Class cls) Field[] fields = cls.getDeclaredFields(); for (Field field : fields) String fieldName = field.getName().replace("_", "."); select(fieldName); return this; /** * 添加查询字段 * * @param fieldKey * @return */ public FilterRuleBuilder select(String fieldKey) fieldKeys.add(fieldKey); return this; /** * 添加多个查询字段 * * @param fieldKeys * @return */ public FilterRuleBuilder select(String... fieldKeys) for (String fieldKey : fieldKeys) select(fieldKey); return this; /** * 多字段排序 * * @param fieldNames * @return */ public FilterRuleBuilder orderBy(boolean isDesc, String... fieldNames) // 不为空加逻辑关系 if (orderBuilder.length() != 0) orderBuilder.append(","); for (String fieldName : fieldNames) if (isDesc) orderBuilder.append(String.format("%s DESC,", fieldName)); else orderBuilder.append(String.format("%s ASC,", fieldName)); // 删除最后一个字符 orderBuilder.deleteCharAt(orderBuilder.length() - 1); return this; /** * 正序排序 * * @param fieldName * @return */ public FilterRuleBuilder orderByAsc(String fieldName) // 不为空加逻辑关系 if (orderBuilder.length() != 0) orderBuilder.append(","); orderBuilder.append(String.format("%s ASC", fieldName)); return this; /** * 倒序排序 * * @param fieldName * @return */ public FilterRuleBuilder orderByDesc(String fieldName) // 不为空加逻辑关系 if (orderBuilder.length() != 0) orderBuilder.append(","); orderBuilder.append(String.format("%s DESC", fieldName)); return this; /** * 切换or逻辑 * * @return */ public FilterRuleBuilder or() logic = LOGIC_OR; return this; /** * 等于构造 * * @param fieldName * @param value * @return */ public FilterRuleBuilder eq(String fieldName, Object value) // 不为空加逻辑关系 if (filterStrBuilder.length() != 0) filterStrBuilder.append(logic); // 字母或数字要加引号 if (value instanceof String || value instanceof Date) filterStrBuilder.append(String.format("(%s = '%s')", fieldName, value)); else filterStrBuilder.append(String.format("(%s = %s)", fieldName, value)); return this; /** * 不等于构造 * * @param fieldName * @param value * @return */ public FilterRuleBuilder ne(String fieldName, Object value) // 不为空加逻辑关系 if (filterStrBuilder.length() != 0) filterStrBuilder.append(logic); // 字母或数字要加引号 if (value instanceof String || value instanceof Date) filterStrBuilder.append(String.format("(%s <> '%s')", fieldName, value)); else filterStrBuilder.append(String.format("(%s <> %s)", fieldName, value)); return this; /** * 小于构造 * * @param fieldName * @param value * @return */ public FilterRuleBuilder lt(String fieldName, Object value) // 不为空加逻辑关系 if (filterStrBuilder.length() != 0) filterStrBuilder.append(logic); // 字母或数字要加引号 if (value instanceof String || value instanceof Date) filterStrBuilder.append(String.format("(%s < '%s')", fieldName, value)); else filterStrBuilder.append(String.format("(%s < %s)", fieldName, value)); return this; /** * 大于构造 * * @param fieldName * @param value * @return */ public FilterRuleBuilder gt(String fieldName, Object value) // 不为空加逻辑关系 if (filterStrBuilder.length() != 0) filterStrBuilder.append(logic); // 字母或数字要加引号 if (value instanceof String || value instanceof Date) filterStrBuilder.append(String.format("(%s > '%s')", fieldName, value)); else filterStrBuilder.append(String.format("(%s > %s)", fieldName, value)); return this; /** * 小于等于构造 * * @param fieldName * @param value * @return */ public FilterRuleBuilder le(String fieldName, Object value) // 不为空加逻辑关系 if (filterStrBuilder.length() != 0) filterStrBuilder.append(logic); // 字母或数字要加引号 if (value instanceof String || value instanceof Date) filterStrBuilder.append(String.format("(%s <= '%s')", fieldName, value)); else filterStrBuilder.append(String.format("(%s <= %s)", fieldName, value)); return this; /** * 大于等于构造 * * @param fieldName * @param value * @return */ public FilterRuleBuilder ge(String fieldName, Object value) // 不为空加逻辑关系 if (filterStrBuilder.length() != 0) filterStrBuilder.append(logic); // 字母或数字要加引号 if (value instanceof String || value instanceof Date) filterStrBuilder.append(String.format("(%s >= '%s')", fieldName, value)); else filterStrBuilder.append(String.format("(%s >= %s)", fieldName, value)); return this; /** * 模糊=构造 * * @param fieldName * @param value * @return */ public FilterRuleBuilder like(String fieldName, Object value) // 不为空加逻辑关系 if (filterStrBuilder.length() != 0) filterStrBuilder.append(logic); // 字母或数字要加引号 if (value instanceof String || value instanceof Date) filterStrBuilder.append("(" + fieldName + " LIKE '%" + value + "%')"); return this; /** * 模糊<>构造 * * @param fieldName * @param value * @return */ public FilterRuleBuilder notLike(String fieldName, Object value) // 不为空加逻辑关系 if (filterStrBuilder.length() != 0) filterStrBuilder.append(logic); // 字母或数字要加引号 if (value instanceof String || value instanceof Date) filterStrBuilder.append("(" + fieldName + " NOT LIKE '%" + value + "%')"); return this; /** * 模糊Left构造 * * @param fieldName * @param value * @return */ public FilterRuleBuilder likeLeft(String fieldName, Object value) // 不为空加逻辑关系 if (filterStrBuilder.length() != 0) filterStrBuilder.append(logic); // 字母或数字要加引号 if (value instanceof String || value instanceof Date) filterStrBuilder.append("(" + fieldName + " LIKE '%" + value + "')"); return this; /** * 模糊Right构造 * * @param fieldName * @param value * @return */ public FilterRuleBuilder likeRight(String fieldName, Object value) // 不为空加逻辑关系 if (filterStrBuilder.length() != 0) filterStrBuilder.append(logic); // 字母或数字要加引号 if (value instanceof String || value instanceof Date) filterStrBuilder.append("(" + fieldName + " LIKE '" + value + "%')"); return this; /** * between 连接 * * @param fieldName * @param startVal * @param endVal * @return */ public FilterRuleBuilder between(String fieldName, Object startVal, Object endVal) // 不为空加逻辑关系 if (filterStrBuilder.length() != 0) filterStrBuilder.append(logic); // 字母或数字要加引号 if (startVal instanceof String || startVal instanceof Date) filterStrBuilder.append(String.format("(%s BETWEEN '%s'", fieldName, startVal)); else filterStrBuilder.append(String.format("(%s BETWEEN %s", fieldName, startVal)); if (endVal instanceof String || endVal instanceof Date) filterStrBuilder.append(String.format(" AND '%s')", endVal)); else filterStrBuilder.append(String.format(" AND '%s')", endVal)); return this; /** * netBetween 连接 * * @param fieldName * @param startVal * @param endVal * @return */ public FilterRuleBuilder notBetween(String fieldName, Object startVal, Object endVal) // 不为空加逻辑关系 if (filterStrBuilder.length() != 0) filterStrBuilder.append(logic); // 字母或数字要加引号 if (startVal instanceof String || startVal instanceof Date) filterStrBuilder.append(String.format("(%s NOT BETWEEN '%s'", fieldName, startVal)); else filterStrBuilder.append(String.format("(%s NOT BETWEEN %s", fieldName, startVal)); if (endVal instanceof String || endVal instanceof Date) filterStrBuilder.append(String.format(" AND '%s')", endVal)); else filterStrBuilder.append(String.format(" AND '%s')", endVal)); return this; /** * 为空构造 * * @param fieldName * @return */ public FilterRuleBuilder isNull(String fieldName) // 不为空加逻辑关系 if (filterStrBuilder.length() != 0)
以上是关于java SDK对接金蝶数据包装类(仅查询)的主要内容,如果未能解决你的问题,请参考以下文章