|
@@ -0,0 +1,82 @@
|
|
|
+package com.sd.framework.util.sql;
|
|
|
+
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.sql.SqlInjectionUtils;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+public class ApplyFun<R> {
|
|
|
+
|
|
|
+ private final Sql<R> sql;
|
|
|
+ private final List<Object> list = new ArrayList<>();
|
|
|
+ public ApplyFun(Sql<R> sql) {
|
|
|
+ this.sql = sql;
|
|
|
+ }
|
|
|
+
|
|
|
+ public <K, V> ApplyFun<R> arguments(SFunction<K, V> function) {
|
|
|
+ list.add(sql.getSqlFieldName(function));
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+ public <K, V> ApplyFun<R> arguments(String alias, SFunction<K, V> function) {
|
|
|
+ list.add(sql.getSqlFieldName(alias, function));
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+ public ApplyFun<R> arguments(String value) {
|
|
|
+ boolean check = SqlInjectionUtils.check(value);
|
|
|
+ if (check) {
|
|
|
+ throw new RuntimeException("sql注入非法字符");
|
|
|
+ }
|
|
|
+ list.add("'" + value + "'");
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+ public ApplyFun<R> arguments(Integer value) {
|
|
|
+ list.add(value);
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+ public ApplyFun<R> arguments(Long value) {
|
|
|
+ list.add(value);
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+ public ApplyFun<R> arguments(Double value) {
|
|
|
+ list.add(value);
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+ public ApplyFun<R> arguments(Float value) {
|
|
|
+ list.add(value);
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+ public ApplyFun<R> arguments(BigDecimal value) {
|
|
|
+ list.add(value);
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+ public ApplyFun<R> arguments(Date value) {
|
|
|
+ list.add(DateUtil.formatDateTime(value));
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+ public ApplyFun<R> arguments(Date value, String format) {
|
|
|
+ list.add(DateUtil.format(value, format));
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected Object[] getObjects() {
|
|
|
+ Object[] objects = new Object[list.size()];
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
+ objects[i] = list.get(i);
|
|
|
+ }
|
|
|
+ return objects;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|