use of com.chao.cloud.common.extra.mybatis.common.ApplySql in project chao-cloud by chaojunzi.
the class MybatisUtil method parseApplySql.
/**
* 解析{@link ApplySql}
*
* @param <T> 实体类类型
* @param wrapper 构造条件
* @param v ApplySql->实体类型
*/
static <T> void parseApplySql(AbstractWrapper<T, ?, ?> wrapper, Object v) {
if (v instanceof ApplySql) {
ApplySql as = (ApplySql) v;
ApplySqlSegment normalSegment = as.getNormalSegment();
List<String> groupByList = as.getGroupByList();
List<String> orderByList = as.getOrderByList();
ApplySqlSegment havingSegment = as.getHavingSegment();
// 自定义sql
if (normalSegment != null) {
wrapper.apply(normalSegment.getSqlSegment(), getValueArray(normalSegment.getValueList()));
}
Method doItMethod = ReflectUtil.getMethodByName(wrapper.getClass(), SqlTemplate.DO_IT.getTemplate());
// group by
if (CollUtil.isNotEmpty(groupByList)) {
ISqlSegment seg = () -> CollUtil.join(groupByList, StrUtil.COMMA);
ReflectUtil.invoke(wrapper, doItMethod, true, new ISqlSegment[] { SqlKeyword.GROUP_BY, seg });
}
// having
if (havingSegment != null) {
wrapper.having(havingSegment.getSqlSegment(), getValueArray(havingSegment.getValueList()));
}
// order by
if (CollUtil.isNotEmpty(orderByList)) {
ISqlSegment seg = () -> CollUtil.join(orderByList, StrUtil.COMMA);
ReflectUtil.invoke(wrapper, doItMethod, true, new ISqlSegment[] { SqlKeyword.ORDER_BY, seg });
}
}
}
Aggregations